codebase-snapshot 0.9.15 → 0.9.17
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 +102 -0
- package/README.md +1 -1
- package/SECURITY.md +41 -0
- package/dist/bin.js +2021 -615
- package/dist/{chunk-JL4VDGXL.js → chunk-IIP43I7C.js} +1762 -444
- package/dist/{chunk-AU2VNTUU.js → chunk-S4367K5X.js} +97 -24
- package/dist/cli.cjs +2039 -637
- package/dist/cli.d.cts +1 -11
- package/dist/cli.d.ts +1 -11
- package/dist/cli.js +16 -5
- package/dist/index.cjs +1755 -438
- package/dist/index.d.cts +97 -8
- package/dist/index.d.ts +97 -8
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +1760 -340
- package/dist/mcp.d.cts +7 -0
- package/dist/mcp.d.ts +7 -0
- package/dist/mcp.js +2 -2
- package/dist/{types-DIX6zWSt.d.cts → types-KbJvBjmV.d.cts} +46 -1
- package/dist/{types-DIX6zWSt.d.ts → types-KbJvBjmV.d.ts} +46 -1
- package/docs/cli.md +14 -9
- package/docs/configuration.md +16 -1
- package/docs/mcp.md +17 -7
- package/docs/output.md +3 -3
- package/docs/vs-gitingest.md +6 -2
- package/package.json +5 -4
package/dist/mcp.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var fs9 = require('fs');
|
|
4
4
|
var path10 = require('path');
|
|
5
5
|
var crypto2 = require('crypto');
|
|
6
6
|
var module$1 = require('module');
|
|
7
7
|
var url = require('url');
|
|
8
8
|
var childProcess = require('child_process');
|
|
9
|
+
var worker_threads = require('worker_threads');
|
|
9
10
|
var async_hooks = require('async_hooks');
|
|
10
11
|
require('os');
|
|
11
12
|
var ts = require('typescript');
|
|
12
|
-
var worker_threads = require('worker_threads');
|
|
13
13
|
|
|
14
14
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -32,7 +32,7 @@ function _interopNamespace(e) {
|
|
|
32
32
|
return Object.freeze(n);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
var
|
|
35
|
+
var fs9__namespace = /*#__PURE__*/_interopNamespace(fs9);
|
|
36
36
|
var path10__namespace = /*#__PURE__*/_interopNamespace(path10);
|
|
37
37
|
var crypto2__namespace = /*#__PURE__*/_interopNamespace(crypto2);
|
|
38
38
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
@@ -62,6 +62,13 @@ var ERROR_CODES = {
|
|
|
62
62
|
* invent a partial one.
|
|
63
63
|
*/
|
|
64
64
|
resourceTooLarge: -32e3,
|
|
65
|
+
/**
|
|
66
|
+
* The server is at its concurrency limit.
|
|
67
|
+
*
|
|
68
|
+
* Implementation-defined range, like `resourceTooLarge`. A typed error rather than silent
|
|
69
|
+
* queueing or a dropped request: the caller can retry, and knows why.
|
|
70
|
+
*/
|
|
71
|
+
overloaded: -32001,
|
|
65
72
|
unsupportedProtocolVersion: -32022
|
|
66
73
|
};
|
|
67
74
|
var METHOD = {
|
|
@@ -248,9 +255,9 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
248
255
|
]);
|
|
249
256
|
function readSmallFile(fullPath) {
|
|
250
257
|
try {
|
|
251
|
-
const stats =
|
|
258
|
+
const stats = fs9__namespace.statSync(fullPath);
|
|
252
259
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
253
|
-
return
|
|
260
|
+
return fs9__namespace.readFileSync(fullPath, "utf8");
|
|
254
261
|
} catch {
|
|
255
262
|
return null;
|
|
256
263
|
}
|
|
@@ -316,7 +323,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
316
323
|
function childDirectories(cwd, parent) {
|
|
317
324
|
let entries;
|
|
318
325
|
try {
|
|
319
|
-
entries =
|
|
326
|
+
entries = fs9__namespace.readdirSync(path10__namespace.join(cwd, parent), { withFileTypes: true });
|
|
320
327
|
} catch {
|
|
321
328
|
return [];
|
|
322
329
|
}
|
|
@@ -351,10 +358,10 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
351
358
|
function scanWorkspacePackages(cwd, patterns) {
|
|
352
359
|
const files = /* @__PURE__ */ new Set();
|
|
353
360
|
const dependencies = /* @__PURE__ */ new Set();
|
|
354
|
-
for (const
|
|
355
|
-
const full = path10__namespace.join(cwd,
|
|
361
|
+
for (const relative9 of workspacePackageDirs(cwd, patterns)) {
|
|
362
|
+
const full = path10__namespace.join(cwd, relative9);
|
|
356
363
|
try {
|
|
357
|
-
for (const entry of
|
|
364
|
+
for (const entry of fs9__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
358
365
|
} catch {
|
|
359
366
|
}
|
|
360
367
|
const raw = readSmallFile(path10__namespace.join(full, "package.json"));
|
|
@@ -367,7 +374,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
367
374
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
368
375
|
function isToolOwnedDirectory(dir) {
|
|
369
376
|
try {
|
|
370
|
-
return
|
|
377
|
+
return fs9__namespace.statSync(dir).isDirectory() && fs9__namespace.existsSync(path10__namespace.join(dir, SNAPSHOT_MARKER));
|
|
371
378
|
} catch {
|
|
372
379
|
return false;
|
|
373
380
|
}
|
|
@@ -382,7 +389,7 @@ function countMarkdownFiles(cwd) {
|
|
|
382
389
|
directoriesSeen += 1;
|
|
383
390
|
let entries;
|
|
384
391
|
try {
|
|
385
|
-
entries =
|
|
392
|
+
entries = fs9__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
386
393
|
} catch {
|
|
387
394
|
continue;
|
|
388
395
|
}
|
|
@@ -404,7 +411,7 @@ function buildPresetContext(cwd) {
|
|
|
404
411
|
const files = /* @__PURE__ */ new Set();
|
|
405
412
|
const dirs = /* @__PURE__ */ new Set();
|
|
406
413
|
try {
|
|
407
|
-
for (const entry of
|
|
414
|
+
for (const entry of fs9__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
408
415
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
409
416
|
else if (entry.isFile()) files.add(entry.name);
|
|
410
417
|
}
|
|
@@ -1279,7 +1286,10 @@ var ASSIGN = String.raw`(?<![=!<>])[:=](?!=)`;
|
|
|
1279
1286
|
var NOT_AFTER_QUOTE = String.raw`(?<!["'])`;
|
|
1280
1287
|
var NOT_A_NAMESPACED_IDENTIFIER = String.raw`(?![a-z][a-z0-9]*(?:\.[a-z][a-z0-9-]*)+/)`;
|
|
1281
1288
|
var QUOTED_CREDENTIAL_KEY = `["'](?!id[-_]token["'])[A-Za-z0-9_$-]{0,64}${STRONG_CREDENTIAL_NAME}["']`;
|
|
1282
|
-
|
|
1289
|
+
function quotedValueFor(delimiterGroup) {
|
|
1290
|
+
return "((?:(?!\\" + delimiterGroup + String.raw`)[^\\\n]|\\\\["'](?=[A-Za-z0-9_])|\\.){1,512})`;
|
|
1291
|
+
}
|
|
1292
|
+
var QUOTED_VALUE = quotedValueFor(1);
|
|
1283
1293
|
var UNQUOTED_STRONG_NAME = `(?<!id[-_])${STRONG_CREDENTIAL_NAME}`;
|
|
1284
1294
|
var CREDENTIAL_KEY_TAIL = new RegExp(`(?:${STRONG_CREDENTIAL_NAME})$`, "i");
|
|
1285
1295
|
var DEFAULT_SECRET_PATTERNS = [
|
|
@@ -1433,7 +1443,7 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1433
1443
|
// consumes the flag so the match is the credential alone.
|
|
1434
1444
|
// - An Azure SAS link authenticates with `?sig=`; the signature *is* the credential.
|
|
1435
1445
|
rule: "uri-credentials",
|
|
1436
|
-
pattern: /\/\/[^\s:/@"'`;()<>,]{0,128}:[^\s:/@"'`;()<>,]{1,256}@[^\s/"'`;()<>,]{1,256}|(?<=(?:^|[\s;|&(])--?u(?:ser)?[ \t=]{1,8})["']?[
|
|
1446
|
+
pattern: /\/\/[^\s:/@"'`;()<>,]{0,128}:[^\s:/@"'`;()<>,]{1,256}@[^\s/"'`;()<>,]{1,256}|(?<=(?:^|[\s;|&(])--?u(?:ser)?[ \t=]{1,8})["']?[A-Za-z0-9._~-][A-Za-z0-9._~-]{0,127}:[^\s"'%$()+]{1,256}["']?|(?<=[?&])sig=[A-Za-z0-9%._=~-]{20,300}(?![A-Za-z0-9%._=~-])/
|
|
1437
1447
|
},
|
|
1438
1448
|
{
|
|
1439
1449
|
// The host tail stops at quotes, `;`, `)`, `<`, `>` and `,`: an unbounded
|
|
@@ -1545,7 +1555,7 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1545
1555
|
// rendering of textual userinfo mixes cases, while the prose the earlier rules were
|
|
1546
1556
|
// protecting (`Bearer authentication`) is a lowercase word.
|
|
1547
1557
|
rule: "authorization-header",
|
|
1548
|
-
pattern: /(?<=
|
|
1558
|
+
pattern: /(?<=[Aa]uthorization["']?\s*[:=]\s*["']?[A-Za-z][A-Za-z0-9._~+/-]{0,31}\s{1,8})(?:[A-Za-z0-9_.+/-]{0,31}[0-9][A-Za-z0-9_.+/-]{0,1024}|[A-Za-z0-9_.+/-]{32,1024}|[A-Za-z0-9_.+/-]{8,1024}={1,2}|(?=[A-Za-z0-9_.+/-]{0,1023}[A-Z])(?=[A-Za-z0-9_.+/-]{0,1023}[a-z])[A-Za-z0-9_.+/-]{12,1024})(?![A-Za-z0-9_.+/=-])/
|
|
1549
1559
|
},
|
|
1550
1560
|
{
|
|
1551
1561
|
// Broader names than before (`apiKey`, `clientSecret`, `privateKey` were
|
|
@@ -1572,7 +1582,9 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1572
1582
|
// between the braces to mask, and `isTemplateInterpolation` keeps such a value readable.
|
|
1573
1583
|
rule: "interpolation-fallback-secret",
|
|
1574
1584
|
pattern: new RegExp(
|
|
1575
|
-
|
|
1585
|
+
// The operator set deliberately omits `?`: `${VAR:?message}` is an error message in shell
|
|
1586
|
+
// and Compose, not a fallback value, and masking it hid the sentence a user is meant to read.
|
|
1587
|
+
`(?:["']${STRONG_CREDENTIAL_NAME}["']|${NOT_AFTER_QUOTE}${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}["'\`]?\\$\\{[A-Za-z_][A-Za-z0-9_]*:?[-=+]([^}"'\`\\r\\n]{2,512})\\}["'\`]?`,
|
|
1576
1588
|
"i"
|
|
1577
1589
|
),
|
|
1578
1590
|
valueGroup: 1
|
|
@@ -1621,19 +1633,15 @@ function compilePattern(rule, pattern, valueGroup) {
|
|
|
1621
1633
|
if (pattern instanceof RegExp) {
|
|
1622
1634
|
const flags = new Set(pattern.flags.replace(/[gy]/g, "").split(""));
|
|
1623
1635
|
if (valueGroup !== void 0) flags.add("d");
|
|
1624
|
-
return
|
|
1625
|
-
rule,
|
|
1626
|
-
pattern: new RegExp(pattern.source, [...flags].join("")),
|
|
1627
|
-
...valueGroup === void 0 ? {} : { valueGroup }
|
|
1628
|
-
};
|
|
1636
|
+
return checkedPattern(rule, new RegExp(pattern.source, [...flags].join("")), valueGroup);
|
|
1629
1637
|
}
|
|
1630
1638
|
if (typeof pattern === "string") {
|
|
1631
1639
|
try {
|
|
1632
|
-
return
|
|
1640
|
+
return checkedPattern(
|
|
1633
1641
|
rule,
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1642
|
+
new RegExp(pattern, valueGroup === void 0 ? "i" : "id"),
|
|
1643
|
+
valueGroup
|
|
1644
|
+
);
|
|
1637
1645
|
} catch (err) {
|
|
1638
1646
|
throw new Error(
|
|
1639
1647
|
`Invalid regular expression for secret rule "${rule}": ${err.message}`
|
|
@@ -1644,6 +1652,19 @@ function compilePattern(rule, pattern, valueGroup) {
|
|
|
1644
1652
|
`Secret rule "${rule}" has a pattern that is neither a RegExp nor a string (received ${describeValue(pattern)}).`
|
|
1645
1653
|
);
|
|
1646
1654
|
}
|
|
1655
|
+
function checkedPattern(rule, compiled, valueGroup) {
|
|
1656
|
+
const stateless = new RegExp(compiled.source, compiled.flags.replace(/[gy]/g, ""));
|
|
1657
|
+
if (stateless.test("")) {
|
|
1658
|
+
throw new Error(
|
|
1659
|
+
`Secret rule "${rule}" can match the empty string. Every alternative must require at least one character, or the scan cannot advance past a match.`
|
|
1660
|
+
);
|
|
1661
|
+
}
|
|
1662
|
+
return {
|
|
1663
|
+
rule,
|
|
1664
|
+
pattern: compiled,
|
|
1665
|
+
...valueGroup === void 0 ? {} : { valueGroup }
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1647
1668
|
function compileSecretRules(rules) {
|
|
1648
1669
|
if (!Array.isArray(rules)) {
|
|
1649
1670
|
throw new Error(
|
|
@@ -1700,6 +1721,193 @@ function toGlobal(rule) {
|
|
|
1700
1721
|
}
|
|
1701
1722
|
var LINE_BREAK = /(\r\n|\n|\r)/;
|
|
1702
1723
|
var LINE_TERMINATOR = /\r\n|\n|\r/g;
|
|
1724
|
+
function isOpeningQuote(line, index) {
|
|
1725
|
+
const code = line.charCodeAt(index);
|
|
1726
|
+
if (code === 96) return true;
|
|
1727
|
+
if (code !== 34 && code !== 39) return false;
|
|
1728
|
+
return index === 0 || !/[A-Za-z0-9]/.test(line[index - 1]);
|
|
1729
|
+
}
|
|
1730
|
+
function quoteStates(line) {
|
|
1731
|
+
const states = new Uint8Array(line.length + 1);
|
|
1732
|
+
let quote = 0;
|
|
1733
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1734
|
+
states[index] = quote;
|
|
1735
|
+
const code = line.charCodeAt(index);
|
|
1736
|
+
if (quote === 0) {
|
|
1737
|
+
if (isOpeningQuote(line, index)) quote = code;
|
|
1738
|
+
} else if (code === 92) {
|
|
1739
|
+
if (index + 1 < line.length) {
|
|
1740
|
+
index += 1;
|
|
1741
|
+
states[index] = quote;
|
|
1742
|
+
}
|
|
1743
|
+
} else if (code === quote) {
|
|
1744
|
+
quote = 0;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
states[line.length] = quote;
|
|
1748
|
+
return states;
|
|
1749
|
+
}
|
|
1750
|
+
function quoteStateFor(line, context) {
|
|
1751
|
+
if (context.quoteAt === void 0) context.quoteAt = quoteStates(line);
|
|
1752
|
+
return context.quoteAt;
|
|
1753
|
+
}
|
|
1754
|
+
function quoteStateAfter(text, quote, end = text.length) {
|
|
1755
|
+
for (let index = 0; index < end; index += 1) {
|
|
1756
|
+
const code = text.charCodeAt(index);
|
|
1757
|
+
if (quote === 0) {
|
|
1758
|
+
if (isOpeningQuote(text, index)) quote = code;
|
|
1759
|
+
} else if (code === 92) {
|
|
1760
|
+
index += 1;
|
|
1761
|
+
} else if (code === quote) {
|
|
1762
|
+
quote = 0;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
return quote;
|
|
1766
|
+
}
|
|
1767
|
+
function commentStartFor(line, context) {
|
|
1768
|
+
if (context.commentStart !== void 0) return context.commentStart;
|
|
1769
|
+
const quotes = quoteStateFor(line, context);
|
|
1770
|
+
let start = line.length;
|
|
1771
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1772
|
+
if (line.charCodeAt(index) !== 35 || quotes[index] !== 0) continue;
|
|
1773
|
+
if (index === 0 || /\s/.test(line[index - 1])) {
|
|
1774
|
+
start = index;
|
|
1775
|
+
break;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
context.commentStart = start;
|
|
1779
|
+
return start;
|
|
1780
|
+
}
|
|
1781
|
+
function commandSeparatorsFor(line, context) {
|
|
1782
|
+
if (context.commandSeparators !== void 0) return context.commandSeparators;
|
|
1783
|
+
const quotes = quoteStateFor(line, context);
|
|
1784
|
+
const separators = [];
|
|
1785
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1786
|
+
if (quotes[index] !== 0) continue;
|
|
1787
|
+
const ch = line[index];
|
|
1788
|
+
const spaced = index > 0 && /\s/.test(line[index - 1]) || index + 1 < line.length && /\s/.test(line[index + 1]);
|
|
1789
|
+
if (ch === "&" || ch === "|") {
|
|
1790
|
+
if (line[index + 1] === ch) {
|
|
1791
|
+
const after = index + 2;
|
|
1792
|
+
const doubleSpaced = spaced || after >= line.length || /\s/.test(line[after]);
|
|
1793
|
+
if (doubleSpaced) separators.push(index);
|
|
1794
|
+
index += 1;
|
|
1795
|
+
} else if (spaced) {
|
|
1796
|
+
separators.push(index);
|
|
1797
|
+
}
|
|
1798
|
+
} else if ((ch === ";" || ch === ">" || ch === "<") && spaced) {
|
|
1799
|
+
separators.push(index);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
context.commandSeparators = separators;
|
|
1803
|
+
return separators;
|
|
1804
|
+
}
|
|
1805
|
+
function lineValueEnd(line, start, context) {
|
|
1806
|
+
const comment = commentStartFor(line, context);
|
|
1807
|
+
let end = comment > start ? comment : line.length;
|
|
1808
|
+
for (const separator of commandSeparatorsFor(line, context)) {
|
|
1809
|
+
if (separator > start && separator < end) {
|
|
1810
|
+
end = separator;
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
while (end > start && /\s/.test(line[end - 1])) end -= 1;
|
|
1815
|
+
return end;
|
|
1816
|
+
}
|
|
1817
|
+
function hasStructuralQuote(line) {
|
|
1818
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1819
|
+
const ch = line[index];
|
|
1820
|
+
if (ch !== '"' && ch !== "'" && ch !== "`") continue;
|
|
1821
|
+
if (ch === "'" && index > 0 && /[A-Za-z0-9]/.test(line[index - 1])) continue;
|
|
1822
|
+
let backslashes = 0;
|
|
1823
|
+
for (let before2 = index - 1; before2 >= 0 && line[before2] === "\\"; before2 -= 1) backslashes += 1;
|
|
1824
|
+
if (backslashes % 2 === 1) continue;
|
|
1825
|
+
let before = index - 1;
|
|
1826
|
+
while (before >= 0 && (line[before] === " " || line[before] === " ")) before -= 1;
|
|
1827
|
+
if (before < 0 || "+,=:([{".includes(line[before])) return true;
|
|
1828
|
+
}
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1831
|
+
function maskRawPemLine(line) {
|
|
1832
|
+
if (line.trim() === "") return line;
|
|
1833
|
+
const leading = /^[ \t]*(?:#|\/\/|;)?[ \t]*/.exec(line)?.[0] ?? "";
|
|
1834
|
+
let rest = line.slice(leading.length);
|
|
1835
|
+
const trailing = /[ \t]*(?:[,;\\+])?[ \t]*$/.exec(rest)?.[0] ?? "";
|
|
1836
|
+
rest = rest.slice(0, rest.length - trailing.length);
|
|
1837
|
+
return leading + (rest.length > 0 ? PEM_REDACTION_MARKER : "") + trailing;
|
|
1838
|
+
}
|
|
1839
|
+
function skeletonisePemLine(line, initialQuote) {
|
|
1840
|
+
const hasQuote = line.includes('"') || line.includes("'") || line.includes("`");
|
|
1841
|
+
const structural = initialQuote !== 0 || hasQuote && (hasStructuralQuote(line) || /-----BEGIN|-----END/.test(line));
|
|
1842
|
+
if (!structural) return { text: maskRawPemLine(line), quote: initialQuote };
|
|
1843
|
+
let out = "";
|
|
1844
|
+
let quote = initialQuote;
|
|
1845
|
+
let masking = false;
|
|
1846
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
1847
|
+
const code = line.charCodeAt(index);
|
|
1848
|
+
if (quote === 0) {
|
|
1849
|
+
if (isOpeningQuote(line, index)) {
|
|
1850
|
+
quote = code;
|
|
1851
|
+
masking = false;
|
|
1852
|
+
}
|
|
1853
|
+
out += line[index];
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
if (code === 92) {
|
|
1857
|
+
masking = false;
|
|
1858
|
+
out += line[index];
|
|
1859
|
+
if (index + 1 < line.length) {
|
|
1860
|
+
out += line[index + 1];
|
|
1861
|
+
index += 1;
|
|
1862
|
+
}
|
|
1863
|
+
continue;
|
|
1864
|
+
}
|
|
1865
|
+
if (code === quote) {
|
|
1866
|
+
masking = false;
|
|
1867
|
+
quote = 0;
|
|
1868
|
+
out += line[index];
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
if (!masking) {
|
|
1872
|
+
out += PEM_REDACTION_MARKER;
|
|
1873
|
+
masking = true;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
return { text: out, quote };
|
|
1877
|
+
}
|
|
1878
|
+
function lineSpanAt(text, start, end) {
|
|
1879
|
+
let lineStart = start;
|
|
1880
|
+
while (lineStart > 0 && text[lineStart - 1] !== "\n" && text[lineStart - 1] !== "\r") {
|
|
1881
|
+
lineStart -= 1;
|
|
1882
|
+
}
|
|
1883
|
+
let lineEnd = end;
|
|
1884
|
+
while (lineEnd < text.length && text[lineEnd] !== "\n" && text[lineEnd] !== "\r") lineEnd += 1;
|
|
1885
|
+
if (lineEnd < text.length) {
|
|
1886
|
+
lineEnd += text[lineEnd] === "\r" && text[lineEnd + 1] === "\n" ? 2 : 1;
|
|
1887
|
+
}
|
|
1888
|
+
return { start: lineStart, end: lineEnd };
|
|
1889
|
+
}
|
|
1890
|
+
function redactPemSpan(text, matchStart, matchEnd) {
|
|
1891
|
+
const span = lineSpanAt(text, matchStart, matchEnd);
|
|
1892
|
+
const segments = text.slice(span.start, span.end).split(LINE_BREAK);
|
|
1893
|
+
let quote = quoteStateAfter(text, 0, matchStart);
|
|
1894
|
+
let cursor = span.start;
|
|
1895
|
+
for (let index = 0; index < segments.length; index += 2) {
|
|
1896
|
+
const line = segments[index];
|
|
1897
|
+
const lineStart = cursor;
|
|
1898
|
+
const lineEnd = lineStart + line.length;
|
|
1899
|
+
cursor = lineEnd + (index + 1 < segments.length ? segments[index + 1].length : 0);
|
|
1900
|
+
const from = Math.max(lineStart, matchStart);
|
|
1901
|
+
const to = Math.min(lineEnd, matchEnd);
|
|
1902
|
+
if (from >= to) continue;
|
|
1903
|
+
const localFrom = from - lineStart;
|
|
1904
|
+
const localTo = to - lineStart;
|
|
1905
|
+
const result = skeletonisePemLine(line.slice(localFrom, localTo), quote);
|
|
1906
|
+
segments[index] = line.slice(0, localFrom) + result.text + line.slice(localTo);
|
|
1907
|
+
quote = result.quote;
|
|
1908
|
+
}
|
|
1909
|
+
return { replacement: segments.join(""), start: span.start, end: span.end };
|
|
1910
|
+
}
|
|
1703
1911
|
var COMPILED_RULES = /* @__PURE__ */ new WeakMap();
|
|
1704
1912
|
function compiledRuleFor(rule) {
|
|
1705
1913
|
let compiled = COMPILED_RULES.get(rule);
|
|
@@ -1714,22 +1922,30 @@ function compiledRuleFor(rule) {
|
|
|
1714
1922
|
return compiled;
|
|
1715
1923
|
}
|
|
1716
1924
|
function scanAndRedactSecrets(content, rules, filePath) {
|
|
1717
|
-
const
|
|
1925
|
+
const findingsByLine = /* @__PURE__ */ new Map();
|
|
1926
|
+
const recordFinding = (line, rulesForLine) => {
|
|
1927
|
+
let entry = findingsByLine.get(line);
|
|
1928
|
+
if (entry === void 0) {
|
|
1929
|
+
entry = /* @__PURE__ */ new Set();
|
|
1930
|
+
findingsByLine.set(line, entry);
|
|
1931
|
+
}
|
|
1932
|
+
for (const rule of rulesForLine) entry.add(rule);
|
|
1933
|
+
};
|
|
1718
1934
|
let redacted = content;
|
|
1719
1935
|
for (const blockPattern of [PEM_BLOCK_PATTERN, PEM_UNTERMINATED_PATTERN]) {
|
|
1720
1936
|
blockPattern.lastIndex = 0;
|
|
1721
1937
|
let match;
|
|
1722
1938
|
while ((match = blockPattern.exec(redacted)) !== null) {
|
|
1723
1939
|
if (match[0].length === 0) {
|
|
1724
|
-
blockPattern.lastIndex
|
|
1940
|
+
blockPattern.lastIndex = advanceStringIndex(redacted, match.index, blockPattern.unicode);
|
|
1725
1941
|
continue;
|
|
1726
1942
|
}
|
|
1727
|
-
const
|
|
1728
|
-
const line = (
|
|
1729
|
-
const
|
|
1730
|
-
|
|
1731
|
-
redacted =
|
|
1732
|
-
blockPattern.lastIndex =
|
|
1943
|
+
const matchEnd = match.index + match[0].length;
|
|
1944
|
+
const line = (redacted.slice(0, match.index).match(LINE_TERMINATOR) ?? []).length + 1;
|
|
1945
|
+
const span = redactPemSpan(redacted, match.index, matchEnd);
|
|
1946
|
+
recordFinding(line, ["private-key-block"]);
|
|
1947
|
+
redacted = redacted.slice(0, span.start) + span.replacement + redacted.slice(span.end);
|
|
1948
|
+
blockPattern.lastIndex = span.start + span.replacement.length;
|
|
1733
1949
|
}
|
|
1734
1950
|
}
|
|
1735
1951
|
const compiled = rules.map(compiledRuleFor);
|
|
@@ -1740,17 +1956,38 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
1740
1956
|
if (line.length > 0) {
|
|
1741
1957
|
const spans = [];
|
|
1742
1958
|
const matchedRules = /* @__PURE__ */ new Set();
|
|
1959
|
+
const context = {};
|
|
1743
1960
|
for (const { rule, pattern, valueGroup } of compiled) {
|
|
1744
1961
|
pattern.lastIndex = 0;
|
|
1745
1962
|
let match;
|
|
1746
1963
|
while ((match = pattern.exec(line)) !== null) {
|
|
1747
1964
|
if (match[0].length === 0) {
|
|
1748
|
-
pattern.lastIndex
|
|
1965
|
+
pattern.lastIndex = advanceStringIndex(line, match.index, pattern.unicode);
|
|
1749
1966
|
continue;
|
|
1750
1967
|
}
|
|
1751
1968
|
const group = valueGroup === void 0 ? void 0 : match.indices?.[valueGroup];
|
|
1969
|
+
const candidate = group ? line.slice(group[0], group[1]) : line.slice(match.index, match.index + match[0].length);
|
|
1970
|
+
if (isPlaceholderValue(candidate)) continue;
|
|
1971
|
+
if (group && isUnquotedValue(line, group[0]) && isSourceCodeFile(filePath) && (quoteStateFor(line, context)[match.index] ?? 0) === 0) {
|
|
1972
|
+
continue;
|
|
1973
|
+
}
|
|
1974
|
+
if (group && /^\$[({A-Za-z_]/.test(line.slice(group[0], group[1])) && (isAssignmentFile(filePath) || isUnquotedValue(line, group[0]))) {
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
if (rule === "credential-assignment-weak" && group) {
|
|
1978
|
+
let before = match.index - 1;
|
|
1979
|
+
while (before >= 0 && (line[before] === " " || line[before] === " ")) before -= 1;
|
|
1980
|
+
if (before >= 0 && (line[before] === "?" || line[before] === ":")) continue;
|
|
1981
|
+
const keyText = line.slice(match.index, group[0]).replace(/["'\s:=]+/g, " ").trim();
|
|
1982
|
+
if (/^(?:PASS|FAIL)$/i.test(keyText) && /^[A-Z]{2,}$/.test(line.slice(group[0], group[1]))) {
|
|
1983
|
+
continue;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1752
1986
|
if (group && isSelfNamingConstant(line, group[0], group[1])) continue;
|
|
1753
|
-
if (
|
|
1987
|
+
if (group && !isUnquotedValue(line, group[0]) && /["'`]\s*\+\s*|\s*\+\s*["'`]/.test(line.slice(group[0], group[1]))) {
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
if (valueGroup !== void 0 && startsInsideStringLiteral(line, match.index, group?.[0], context, filePath)) {
|
|
1754
1991
|
continue;
|
|
1755
1992
|
}
|
|
1756
1993
|
if (group && isUnquotedValue(line, group[0]) && isDeclaredBinding(line, match.index, filePath)) {
|
|
@@ -1776,7 +2013,12 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
1776
2013
|
if (wholeValue) {
|
|
1777
2014
|
spans.push({
|
|
1778
2015
|
start: group[0],
|
|
1779
|
-
|
|
2016
|
+
// A passphrase contains spaces: `DB_PASSWORD=correct horse battery staple` used to
|
|
2017
|
+
// stop at the first one and emit the rest beside the marker. Stop at the end of
|
|
2018
|
+
// the value, a trailing comment, or a shell operator instead. The rule's own end
|
|
2019
|
+
// is not used: the colon form's value pattern includes the spaces before a
|
|
2020
|
+
// trailing `# comment`, and masking them welds the comment to the marker.
|
|
2021
|
+
end: lineValueEnd(line, group[0], context),
|
|
1780
2022
|
rule
|
|
1781
2023
|
});
|
|
1782
2024
|
matchedRules.add(rule);
|
|
@@ -1789,14 +2031,153 @@ function scanAndRedactSecrets(content, rules, filePath) {
|
|
|
1789
2031
|
matchedRules.add(rule);
|
|
1790
2032
|
}
|
|
1791
2033
|
}
|
|
2034
|
+
for (const span of concatenatedCredentialSpans(line)) {
|
|
2035
|
+
spans.push(span);
|
|
2036
|
+
matchedRules.add(span.rule);
|
|
2037
|
+
}
|
|
1792
2038
|
if (spans.length > 0) {
|
|
1793
|
-
|
|
1794
|
-
|
|
2039
|
+
const maskedLine = applySpans(line, spans);
|
|
2040
|
+
if (!quotesAreBalanced(line) || quotesAreBalanced(maskedLine)) {
|
|
2041
|
+
recordFinding(lineNumber, matchedRules);
|
|
2042
|
+
segments[index] = maskedLine;
|
|
2043
|
+
}
|
|
1795
2044
|
}
|
|
1796
2045
|
}
|
|
1797
2046
|
if (index + 1 < segments.length) lineNumber += 1;
|
|
1798
2047
|
}
|
|
1799
|
-
|
|
2048
|
+
let finalText = segments.join("");
|
|
2049
|
+
finalText = redactStructuredValues(finalText, filePath, recordFinding);
|
|
2050
|
+
finalText = redactDockerfileEnv(finalText, filePath, recordFinding);
|
|
2051
|
+
const findings = [...findingsByLine.entries()].sort(([left], [right]) => left - right).map(([line, rulesForLine]) => ({
|
|
2052
|
+
rules: [...rulesForLine],
|
|
2053
|
+
line,
|
|
2054
|
+
path: filePath
|
|
2055
|
+
}));
|
|
2056
|
+
return { redacted: finalText, findings };
|
|
2057
|
+
}
|
|
2058
|
+
function advanceStringIndex(text, index, unicode) {
|
|
2059
|
+
if (!unicode) return index + 1;
|
|
2060
|
+
const first = text.charCodeAt(index);
|
|
2061
|
+
if (first >= 55296 && first <= 56319) {
|
|
2062
|
+
const second = text.charCodeAt(index + 1);
|
|
2063
|
+
if (second >= 56320 && second <= 57343) return index + 2;
|
|
2064
|
+
}
|
|
2065
|
+
return index + 1;
|
|
2066
|
+
}
|
|
2067
|
+
var STRUCTURED_FILE = /\.(?:json|jsonc|json5|ya?ml|toml|ini|conf|cfg|properties|env|tf|tfvars)$/i;
|
|
2068
|
+
var STRUCTURED_BASENAME = /^(?:\.env(?:\.[^/]*)?|docker-compose(?:\.[^/]*)?|compose(?:\.[^/]*)?)$/i;
|
|
2069
|
+
function isStructuredFile(filePath) {
|
|
2070
|
+
if (filePath === void 0) return false;
|
|
2071
|
+
const normalised = filePath.replace(/\\/g, "/");
|
|
2072
|
+
if (STRUCTURED_FILE.test(normalised)) return true;
|
|
2073
|
+
return STRUCTURED_BASENAME.test(normalised.slice(normalised.lastIndexOf("/") + 1));
|
|
2074
|
+
}
|
|
2075
|
+
function isDockerfile(filePath) {
|
|
2076
|
+
if (filePath === void 0) return false;
|
|
2077
|
+
const normalised = filePath.replace(/\\/g, "/");
|
|
2078
|
+
return /^(?:Dockerfile|[^/]*\.dockerfile)$/i.test(
|
|
2079
|
+
normalised.slice(normalised.lastIndexOf("/") + 1)
|
|
2080
|
+
);
|
|
2081
|
+
}
|
|
2082
|
+
function maskLineContent(line) {
|
|
2083
|
+
if (line.trim() === "") return line;
|
|
2084
|
+
const indent = /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
2085
|
+
return `${indent}${REDACTION_MARKER}`;
|
|
2086
|
+
}
|
|
2087
|
+
function maskValueLine(line) {
|
|
2088
|
+
if (line.trim() === "") return line;
|
|
2089
|
+
const indent = /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
2090
|
+
const content = line.slice(indent.length);
|
|
2091
|
+
const quoted = /^(["'`])(.*)\1([,;]?[ \t]*)$/.exec(content);
|
|
2092
|
+
if (quoted !== null) {
|
|
2093
|
+
return `${indent}${quoted[1]}${REDACTION_MARKER}${quoted[1]}${quoted[3] ?? ""}`;
|
|
2094
|
+
}
|
|
2095
|
+
return `${indent}${REDACTION_MARKER}`;
|
|
2096
|
+
}
|
|
2097
|
+
var STRUCTURED_KEY = /^([ \t]*)["']?([A-Za-z0-9_$.-]{1,128})["']?[ \t]*([:=])[ \t]*(.*)$/;
|
|
2098
|
+
var BLOCK_SCALAR = /^[|>][+-]?\d*[ \t]*(?:#.*)?$/;
|
|
2099
|
+
function redactStructuredValues(text, filePath, recordFinding) {
|
|
2100
|
+
if (!isStructuredFile(filePath)) return text;
|
|
2101
|
+
const segments = text.split(LINE_BREAK);
|
|
2102
|
+
for (let index = 0; index < segments.length; index += 2) {
|
|
2103
|
+
const line = segments[index];
|
|
2104
|
+
if (line === void 0 || line.length === 0) continue;
|
|
2105
|
+
const match = STRUCTURED_KEY.exec(line);
|
|
2106
|
+
if (match === null) continue;
|
|
2107
|
+
const key = match[2] ?? "";
|
|
2108
|
+
if (!CREDENTIAL_KEY_TAIL.test(key)) continue;
|
|
2109
|
+
const baseIndent = (match[1] ?? "").length;
|
|
2110
|
+
const rest = (match[4] ?? "").trim();
|
|
2111
|
+
if (BLOCK_SCALAR.test(rest)) {
|
|
2112
|
+
let cursor2 = index + 2;
|
|
2113
|
+
let masked2 = false;
|
|
2114
|
+
while (cursor2 < segments.length) {
|
|
2115
|
+
const body = segments[cursor2] ?? "";
|
|
2116
|
+
if (body.trim() !== "") {
|
|
2117
|
+
const indent = (/^[ \t]*/.exec(body)?.[0] ?? "").length;
|
|
2118
|
+
if (indent <= baseIndent) break;
|
|
2119
|
+
segments[cursor2] = maskLineContent(body);
|
|
2120
|
+
masked2 = true;
|
|
2121
|
+
}
|
|
2122
|
+
cursor2 += 2;
|
|
2123
|
+
}
|
|
2124
|
+
if (masked2) recordFinding(index / 2 + 1, ["credential-block-scalar"]);
|
|
2125
|
+
continue;
|
|
2126
|
+
}
|
|
2127
|
+
if (rest !== "") continue;
|
|
2128
|
+
let cursor = index + 2;
|
|
2129
|
+
while (cursor < segments.length && (segments[cursor] ?? "").trim() === "") cursor += 2;
|
|
2130
|
+
const firstValue = segments[cursor];
|
|
2131
|
+
if (firstValue === void 0) continue;
|
|
2132
|
+
const valueIndent = (/^[ \t]*/.exec(firstValue)?.[0] ?? "").length;
|
|
2133
|
+
if (valueIndent <= baseIndent) continue;
|
|
2134
|
+
let masked = false;
|
|
2135
|
+
while (cursor < segments.length) {
|
|
2136
|
+
const body = segments[cursor] ?? "";
|
|
2137
|
+
if (body.trim() !== "") {
|
|
2138
|
+
const indent = (/^[ \t]*/.exec(body)?.[0] ?? "").length;
|
|
2139
|
+
if (indent < valueIndent) break;
|
|
2140
|
+
segments[cursor] = maskValueLine(body);
|
|
2141
|
+
masked = true;
|
|
2142
|
+
}
|
|
2143
|
+
cursor += 2;
|
|
2144
|
+
}
|
|
2145
|
+
if (masked) recordFinding(index / 2 + 1, ["credential-multiline-value"]);
|
|
2146
|
+
}
|
|
2147
|
+
return segments.join("");
|
|
2148
|
+
}
|
|
2149
|
+
var DOCKERFILE_ENV = /^([ \t]*ENV[ \t]+)([A-Za-z_][A-Za-z0-9_]*)([ \t]+)(\S.*)$/;
|
|
2150
|
+
function redactDockerfileEnv(text, filePath, recordFinding) {
|
|
2151
|
+
if (!isDockerfile(filePath)) return text;
|
|
2152
|
+
const segments = text.split(LINE_BREAK);
|
|
2153
|
+
for (let index = 0; index < segments.length; index += 2) {
|
|
2154
|
+
const line = segments[index];
|
|
2155
|
+
if (line === void 0) continue;
|
|
2156
|
+
const match = DOCKERFILE_ENV.exec(line);
|
|
2157
|
+
if (match === null) continue;
|
|
2158
|
+
if (!CREDENTIAL_KEY_TAIL.test(match[2] ?? "")) continue;
|
|
2159
|
+
const value = match[4] ?? "";
|
|
2160
|
+
if (value.startsWith("=")) continue;
|
|
2161
|
+
segments[index] = `${match[1]}${match[2]}${match[3]}${REDACTION_MARKER}`;
|
|
2162
|
+
recordFinding(index / 2 + 1, ["dockerfile-env-secret"]);
|
|
2163
|
+
}
|
|
2164
|
+
return segments.join("");
|
|
2165
|
+
}
|
|
2166
|
+
var CONCATENATED_CREDENTIAL = new RegExp(
|
|
2167
|
+
"([A-Za-z0-9_$.-]{0,64}(?:password|passwd|passphrase|pwd|api[_-]?key|api[_-]?secret|access[_-]?key|secret[_-]?access[_-]?key|secret[_-]?key|client[_-]?secret[_-]?key|client[_-]?secret|private[_-]?key|access[_-]?token|refresh[_-]?token|auth[_-]?token|session[_-]?token|session[_-]?key|secret|token))\\s*=\\s*(?<=[=:]\\s{0,8})([\"'`])\\s*\\+\\s*([\"'`])((?:(?!\\3)[^\\\\\\n]|\\\\.){1,512})\\3",
|
|
2168
|
+
"gid"
|
|
2169
|
+
);
|
|
2170
|
+
function concatenatedCredentialSpans(line) {
|
|
2171
|
+
const spans = [];
|
|
2172
|
+
CONCATENATED_CREDENTIAL.lastIndex = 0;
|
|
2173
|
+
let match;
|
|
2174
|
+
while ((match = CONCATENATED_CREDENTIAL.exec(line)) !== null) {
|
|
2175
|
+
const group = match.indices?.[4];
|
|
2176
|
+
if (group !== void 0) {
|
|
2177
|
+
spans.push({ start: group[0], end: group[1], rule: "credential-concatenation" });
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
return spans;
|
|
1800
2181
|
}
|
|
1801
2182
|
var TOKEN_CHARS_LEFT = /[A-Za-z0-9_+/-]/;
|
|
1802
2183
|
var TOKEN_CHARS_RIGHT = /[A-Za-z0-9_+/=-]/;
|
|
@@ -1814,13 +2195,20 @@ function expandOverToken(line, start, end) {
|
|
|
1814
2195
|
while (right < line.length && TOKEN_CHARS_RIGHT.test(line[right])) right += 1;
|
|
1815
2196
|
return { start: left, end: right };
|
|
1816
2197
|
}
|
|
1817
|
-
function startsInsideStringLiteral(line, matchIndex, valueStart) {
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
if (before !== '"' && before !== "'" && before !== "`") return false;
|
|
2198
|
+
function startsInsideStringLiteral(line, matchIndex, valueStart, context, filePath) {
|
|
2199
|
+
const quote = quoteStateFor(line, context)[matchIndex] ?? 0;
|
|
2200
|
+
if (quote === 0) return false;
|
|
2201
|
+
if (quote === 96 && /\.(?:md|mdx)$/i.test(filePath ?? "")) return true;
|
|
1822
2202
|
if (valueStart === void 0) return true;
|
|
1823
|
-
|
|
2203
|
+
for (let index = matchIndex; index < valueStart; index += 1) {
|
|
2204
|
+
const code = line.charCodeAt(index);
|
|
2205
|
+
if (code === 92) {
|
|
2206
|
+
index += 1;
|
|
2207
|
+
} else if (code === quote) {
|
|
2208
|
+
return true;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
return false;
|
|
1824
2212
|
}
|
|
1825
2213
|
function isTemplateInterpolation(line, start, end) {
|
|
1826
2214
|
if (line[start] !== "$" || line[start + 1] !== "{" || line[end - 1] !== "}") {
|
|
@@ -1848,6 +2236,40 @@ function isSelfNamingConstant(line, start, end) {
|
|
|
1848
2236
|
}
|
|
1849
2237
|
return line.endsWith(value, index);
|
|
1850
2238
|
}
|
|
2239
|
+
var SOURCE_CODE_FILE = /\.(?:[cm]?[jt]sx?)$/i;
|
|
2240
|
+
function isSourceCodeFile(filePath) {
|
|
2241
|
+
return filePath !== void 0 && SOURCE_CODE_FILE.test(filePath.replace(/\\/g, "/"));
|
|
2242
|
+
}
|
|
2243
|
+
var PLACEHOLDER_PATTERNS = [
|
|
2244
|
+
/^<[^>]*>?$/,
|
|
2245
|
+
/^\.{3,}$/,
|
|
2246
|
+
/^(?:x{4,}|X{4,}|\*{3,})$/,
|
|
2247
|
+
/^(?:replace|change)[-_ ]?me(?:[-_ ].*)?$/i,
|
|
2248
|
+
/^your[-_ ].*$/i,
|
|
2249
|
+
/^(?:example|sample)(?:[-_ ].*)?$/i
|
|
2250
|
+
];
|
|
2251
|
+
function isPlaceholderValue(value) {
|
|
2252
|
+
const trimmed = value.trim().replace(/^["'`]+/, "").replace(/["'`]+$/, "");
|
|
2253
|
+
if (trimmed.length === 0) return false;
|
|
2254
|
+
if (PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
|
|
2255
|
+
return trimmed.includes("...") || /^<[^>]*$/.test(trimmed);
|
|
2256
|
+
}
|
|
2257
|
+
function quotesAreBalanced(text) {
|
|
2258
|
+
let single = 0;
|
|
2259
|
+
let double = 0;
|
|
2260
|
+
let backtick = 0;
|
|
2261
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
2262
|
+
const char = text[index];
|
|
2263
|
+
if (char === "\\") {
|
|
2264
|
+
index += 1;
|
|
2265
|
+
continue;
|
|
2266
|
+
}
|
|
2267
|
+
if (char === '"') double += 1;
|
|
2268
|
+
else if (char === "'") single += 1;
|
|
2269
|
+
else if (char === "`") backtick += 1;
|
|
2270
|
+
}
|
|
2271
|
+
return double % 2 === 0 && single % 2 === 0 && backtick % 2 === 0;
|
|
2272
|
+
}
|
|
1851
2273
|
function assignmentAround(line, valueStart) {
|
|
1852
2274
|
let index = valueStart;
|
|
1853
2275
|
while (index > 0 && (line[index - 1] === " " || line[index - 1] === " ")) index -= 1;
|
|
@@ -1917,6 +2339,16 @@ function applySpans(line, spans) {
|
|
|
1917
2339
|
return out;
|
|
1918
2340
|
}
|
|
1919
2341
|
|
|
2342
|
+
// src/version.ts
|
|
2343
|
+
var GENERATOR_NAME = "codebase-snapshot";
|
|
2344
|
+
var GENERATOR_VERSION = "0.9.17";
|
|
2345
|
+
var SCHEMA_VERSION = "3.0.0";
|
|
2346
|
+
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2347
|
+
function isOurGeneratorName(name) {
|
|
2348
|
+
if (typeof name !== "string") return false;
|
|
2349
|
+
return name === GENERATOR_NAME || LEGACY_GENERATOR_NAMES.includes(name);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
1920
2352
|
// src/scanner/files.ts
|
|
1921
2353
|
function isDiscoveryMode(value) {
|
|
1922
2354
|
return value === "auto" || value === "git" || value === "walk";
|
|
@@ -1926,7 +2358,7 @@ var PRESET_IGNORES = new Set(
|
|
|
1926
2358
|
);
|
|
1927
2359
|
function readLinkTarget(linkPath, fallback) {
|
|
1928
2360
|
try {
|
|
1929
|
-
return
|
|
2361
|
+
return fs9__namespace.readlinkSync(linkPath);
|
|
1930
2362
|
} catch {
|
|
1931
2363
|
return fallback;
|
|
1932
2364
|
}
|
|
@@ -1941,8 +2373,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
1941
2373
|
};
|
|
1942
2374
|
}
|
|
1943
2375
|
function isInside(root, candidate) {
|
|
1944
|
-
const
|
|
1945
|
-
return
|
|
2376
|
+
const relative9 = path10__namespace.relative(root, candidate);
|
|
2377
|
+
return relative9 === "" || !relative9.startsWith(`..${path10__namespace.sep}`) && relative9 !== ".." && !path10__namespace.isAbsolute(relative9);
|
|
1946
2378
|
}
|
|
1947
2379
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
1948
2380
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -2003,10 +2435,10 @@ var DEFAULT_IGNORED_FILES = [
|
|
|
2003
2435
|
"bun.lockb",
|
|
2004
2436
|
"composer.lock"
|
|
2005
2437
|
];
|
|
2006
|
-
var SENSITIVE_BASENAME = /^(?:\.env(?:[._-][A-Za-z0-9_-]*)*|\.env(?:backup|bak|old|orig|copy|save)|\.envrc|\.npmrc(?:\.[A-Za-z0-9_-]+)?|\.yarnrc(?:\.yml)?|\.netrc(?:\.[A-Za-z0-9_-]+)?|\.git-credentials|\.htpasswd|\.pgpass|\.vault-token|vault[-_]agent[-_]token|id_[a-z0-9_]+(?:\.[A-Za-z0-9_-]+)?|credentials(?:\.(?:json|ya?ml|toml))?|service[-_]?account(?:\.[a-z0-9_-]+)*\.json|secrets?\.(?:json|ya?ml|toml)|env|[A-Za-z0-9_-]{1,64}\.env)$/i;
|
|
2007
|
-
var SENSITIVE_PATH = /(?:^|\/)\.(?:aws|ssh|gnupg)\/|(?:^|\/)\.docker\/config\.json$|(?:^|\/)\.kube\/config$/i;
|
|
2438
|
+
var SENSITIVE_BASENAME = /^(?:\.env(?:[._-][A-Za-z0-9_-]*)*|\.env(?:backup|bak|old|orig|copy|save)|\.envrc|\.npmrc(?:\.[A-Za-z0-9_-]+)?|\.yarnrc(?:\.yml)?|\.netrc(?:\.[A-Za-z0-9_-]+)?|\.git-credentials|\.htpasswd|\.pgpass|\.pypirc|\.vault-token|vault[-_]agent[-_]token|\.composer-auth\.json|auth\.json|application_default_credentials\.json|id_[a-z0-9_]+(?:\.[A-Za-z0-9_-]+)?|credentials(?:\.(?:json|ya?ml|toml))?|service[-_]?account(?:\.[a-z0-9_-]+)*\.json|secrets?\.(?:json|ya?ml|toml)|env|[A-Za-z0-9_-]{1,64}\.env)$/i;
|
|
2439
|
+
var SENSITIVE_PATH = /(?:^|\/)\.(?:aws|ssh|gnupg)\/|(?:^|\/)\.docker\/config\.json$|(?:^|\/)\.kube\/config$|(?:^|\/)\.config\/gcloud\/|(?:^|\/)\.composer\/|(?:^|\/)\.terraform\/credentials\.tfrc\.json$/i;
|
|
2008
2440
|
var SENSITIVE_EXT = /\.(?:pem|key|p12|pfx|jks|keystore|ppk|asc|kdbx|tfstate|tfvars)$/i;
|
|
2009
|
-
var TEMPLATE_SUFFIX =
|
|
2441
|
+
var TEMPLATE_SUFFIX = /^(.*)\.(?:example|sample|template|dist)(\.[A-Za-z0-9_-]+)?$/i;
|
|
2010
2442
|
var BACKUP_SUFFIX = /(?:~|\.(?:bak|backup|old|orig|save|copy|swp|swo|tmp|part))$/i;
|
|
2011
2443
|
function normaliseName(name) {
|
|
2012
2444
|
let normalised = name.trim().replace(/[. ]+$/, "");
|
|
@@ -2022,12 +2454,16 @@ function isSensitivePath(relativePath) {
|
|
|
2022
2454
|
const posixPath = relativePath.replace(/\\/g, "/");
|
|
2023
2455
|
const raw = posixPath.split("/").pop() ?? posixPath;
|
|
2024
2456
|
const base = normaliseName(raw);
|
|
2025
|
-
if (
|
|
2026
|
-
const stripped = base.replace(new RegExp(TEMPLATE_SUFFIX.source, "gi"), "");
|
|
2027
|
-
if (matchesSensitiveList(posixPath, stripped)) return false;
|
|
2028
|
-
}
|
|
2457
|
+
if (templateOfCredentialFile(posixPath, base)) return false;
|
|
2029
2458
|
return matchesSensitiveList(posixPath, base);
|
|
2030
2459
|
}
|
|
2460
|
+
function templateOfCredentialFile(posixPath, base) {
|
|
2461
|
+
const match = TEMPLATE_SUFFIX.exec(base);
|
|
2462
|
+
if (match === null) return null;
|
|
2463
|
+
const stripped = `${match[1] ?? ""}${match[2] ?? ""}`;
|
|
2464
|
+
if (SENSITIVE_EXT.test(stripped)) return null;
|
|
2465
|
+
return matchesSensitiveList(posixPath, stripped) ? stripped : null;
|
|
2466
|
+
}
|
|
2031
2467
|
var GLOBAL_PATTERNS = /* @__PURE__ */ new WeakMap();
|
|
2032
2468
|
var GLOB_REGEX_CACHE = /* @__PURE__ */ new Map();
|
|
2033
2469
|
var GITIGNORE_REGEX_CACHE = /* @__PURE__ */ new Map();
|
|
@@ -2059,7 +2495,7 @@ function findSecretInPath(relativePath, extraRules) {
|
|
|
2059
2495
|
let match;
|
|
2060
2496
|
while ((match = scan.exec(posixPath)) !== null) {
|
|
2061
2497
|
if (match[0].length === 0) {
|
|
2062
|
-
scan.lastIndex
|
|
2498
|
+
scan.lastIndex = advanceStringIndex(posixPath, match.index, scan.unicode);
|
|
2063
2499
|
continue;
|
|
2064
2500
|
}
|
|
2065
2501
|
spans.push({ start: match.index, end: match.index + match[0].length });
|
|
@@ -2120,11 +2556,14 @@ function globBodyToRegExp(body, allowBraces) {
|
|
|
2120
2556
|
if (char === "*") {
|
|
2121
2557
|
if (body[i + 1] === "*") {
|
|
2122
2558
|
i += 1;
|
|
2123
|
-
|
|
2559
|
+
const startsSegment = i - 2 < 0 || body[i - 2] === "/";
|
|
2560
|
+
if (startsSegment && body[i + 1] === "/") {
|
|
2124
2561
|
i += 1;
|
|
2125
|
-
out += "(
|
|
2126
|
-
} else {
|
|
2562
|
+
out += "(?:[^/]+/)*";
|
|
2563
|
+
} else if (startsSegment && i + 1 === body.length) {
|
|
2127
2564
|
out += ".*";
|
|
2565
|
+
} else {
|
|
2566
|
+
out += "[^/]*";
|
|
2128
2567
|
}
|
|
2129
2568
|
} else {
|
|
2130
2569
|
out += "[^/]*";
|
|
@@ -2196,7 +2635,7 @@ function readGitignoreRules(dir) {
|
|
|
2196
2635
|
const gitignorePath = path10__namespace.join(dir, ".gitignore");
|
|
2197
2636
|
let raw;
|
|
2198
2637
|
try {
|
|
2199
|
-
raw =
|
|
2638
|
+
raw = fs9__namespace.readFileSync(gitignorePath, "utf8");
|
|
2200
2639
|
} catch {
|
|
2201
2640
|
return [];
|
|
2202
2641
|
}
|
|
@@ -2369,10 +2808,49 @@ function listIgnoredPaths(cwd) {
|
|
|
2369
2808
|
}
|
|
2370
2809
|
function hasSnapshotMarker(target) {
|
|
2371
2810
|
try {
|
|
2372
|
-
return
|
|
2811
|
+
return fs9__namespace.statSync(target).isDirectory() && fs9__namespace.existsSync(path10__namespace.join(target, ".codebase-snapshot"));
|
|
2812
|
+
} catch {
|
|
2813
|
+
return false;
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
2817
|
+
function isToolOwnedDirectory2(dir) {
|
|
2818
|
+
let raw;
|
|
2819
|
+
try {
|
|
2820
|
+
raw = fs9__namespace.readFileSync(path10__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
2373
2821
|
} catch {
|
|
2374
2822
|
return false;
|
|
2375
2823
|
}
|
|
2824
|
+
let parsed;
|
|
2825
|
+
try {
|
|
2826
|
+
parsed = JSON.parse(raw);
|
|
2827
|
+
} catch {
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
2831
|
+
const marker = parsed;
|
|
2832
|
+
if (marker.generator !== GENERATOR_NAME || marker.state !== "complete" || typeof marker.id !== "string" || !Array.isArray(marker.files)) {
|
|
2833
|
+
return false;
|
|
2834
|
+
}
|
|
2835
|
+
const accounted = /* @__PURE__ */ new Set();
|
|
2836
|
+
for (const item of marker.files) {
|
|
2837
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return false;
|
|
2838
|
+
const entry = item.path;
|
|
2839
|
+
if (typeof entry !== "string" || entry.length === 0) return false;
|
|
2840
|
+
const parts = entry.split("/");
|
|
2841
|
+
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
2842
|
+
accounted.add(parts.slice(0, depth).join("/"));
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
let entries;
|
|
2846
|
+
try {
|
|
2847
|
+
entries = fs9__namespace.readdirSync(dir);
|
|
2848
|
+
} catch {
|
|
2849
|
+
return false;
|
|
2850
|
+
}
|
|
2851
|
+
return entries.every(
|
|
2852
|
+
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) || accounted.has(entry)
|
|
2853
|
+
);
|
|
2376
2854
|
}
|
|
2377
2855
|
function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
2378
2856
|
const markers = /* @__PURE__ */ new Map();
|
|
@@ -2383,7 +2861,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
|
2383
2861
|
const prefix = parts.slice(0, depth).join("/");
|
|
2384
2862
|
let hasMarker = markers.get(prefix);
|
|
2385
2863
|
if (hasMarker === void 0) {
|
|
2386
|
-
hasMarker =
|
|
2864
|
+
hasMarker = isToolOwnedDirectory2(path10__namespace.join(cwd, prefix));
|
|
2387
2865
|
markers.set(prefix, hasMarker);
|
|
2388
2866
|
}
|
|
2389
2867
|
if (hasMarker) return true;
|
|
@@ -2398,7 +2876,7 @@ function makeLinkProbe() {
|
|
|
2398
2876
|
let known = cache.get(absolutePath);
|
|
2399
2877
|
if (known === void 0) {
|
|
2400
2878
|
try {
|
|
2401
|
-
known =
|
|
2879
|
+
known = fs9__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
2402
2880
|
} catch {
|
|
2403
2881
|
known = false;
|
|
2404
2882
|
}
|
|
@@ -2411,7 +2889,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
2411
2889
|
const isLink = makeLinkProbe();
|
|
2412
2890
|
let rootReal = cwd;
|
|
2413
2891
|
try {
|
|
2414
|
-
rootReal =
|
|
2892
|
+
rootReal = fs9__namespace.realpathSync(cwd);
|
|
2415
2893
|
} catch {
|
|
2416
2894
|
}
|
|
2417
2895
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -2439,7 +2917,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
2439
2917
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
2440
2918
|
let targetReal = null;
|
|
2441
2919
|
try {
|
|
2442
|
-
targetReal =
|
|
2920
|
+
targetReal = fs9__namespace.realpathSync(absolute);
|
|
2443
2921
|
} catch {
|
|
2444
2922
|
targetReal = null;
|
|
2445
2923
|
}
|
|
@@ -2457,7 +2935,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
2457
2935
|
}
|
|
2458
2936
|
let stats = null;
|
|
2459
2937
|
try {
|
|
2460
|
-
stats =
|
|
2938
|
+
stats = fs9__namespace.statSync(absolute);
|
|
2461
2939
|
} catch {
|
|
2462
2940
|
stats = null;
|
|
2463
2941
|
}
|
|
@@ -2545,7 +3023,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
2545
3023
|
"Discovery mode is `git`, but git could not list this directory's files. Run inside a working repository, or pass --discovery walk (or auto) to scan the tree directly."
|
|
2546
3024
|
);
|
|
2547
3025
|
}
|
|
2548
|
-
if (
|
|
3026
|
+
if (fs9__namespace.existsSync(path10__namespace.join(cwd, ".git"))) {
|
|
2549
3027
|
throw new Error(
|
|
2550
3028
|
"This directory is a git repository, but git could not list its files. A plain walk honours .gitignore files, but git also applies .git/info/exclude and your global excludes file, includes files that are tracked although a .gitignore now matches them, and treats a submodule as a single entry. Fix the repository (git status should work), run outside git, or pass --discovery walk to accept those differences."
|
|
2551
3029
|
);
|
|
@@ -2555,6 +3033,15 @@ function collectFiles(cwd, options = {}) {
|
|
|
2555
3033
|
for (const record of walked.skipped) skipped.push(record);
|
|
2556
3034
|
}
|
|
2557
3035
|
}
|
|
3036
|
+
const extraPaths = (options.extraPaths ?? []).map((entry) => entry.replace(/\\/g, "/"));
|
|
3037
|
+
if (extraPaths.length > 0) {
|
|
3038
|
+
const known = new Set(candidates);
|
|
3039
|
+
for (const extra of extraPaths) {
|
|
3040
|
+
if (extra.length === 0 || known.has(extra)) continue;
|
|
3041
|
+
known.add(extra);
|
|
3042
|
+
candidates.push(extra);
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
2558
3045
|
const files = candidates.filter((file) => {
|
|
2559
3046
|
if (isToolOwned(file)) return false;
|
|
2560
3047
|
const ignored = defaultIgnoreReason(file, toolDirNames);
|
|
@@ -2604,7 +3091,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
2604
3091
|
}
|
|
2605
3092
|
function rootRealFor(root) {
|
|
2606
3093
|
try {
|
|
2607
|
-
return
|
|
3094
|
+
return fs9__namespace.realpathSync(root);
|
|
2608
3095
|
} catch {
|
|
2609
3096
|
return root;
|
|
2610
3097
|
}
|
|
@@ -2624,7 +3111,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
2624
3111
|
];
|
|
2625
3112
|
let entries;
|
|
2626
3113
|
try {
|
|
2627
|
-
entries =
|
|
3114
|
+
entries = fs9__namespace.readdirSync(current, { withFileTypes: true });
|
|
2628
3115
|
} catch {
|
|
2629
3116
|
results.skipped.push({
|
|
2630
3117
|
path: relativeToBase(current),
|
|
@@ -2680,14 +3167,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
2680
3167
|
if (entry.isSymbolicLink()) {
|
|
2681
3168
|
let targetReal;
|
|
2682
3169
|
try {
|
|
2683
|
-
targetReal =
|
|
3170
|
+
targetReal = fs9__namespace.realpathSync(fullPath);
|
|
2684
3171
|
} catch {
|
|
2685
3172
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
2686
3173
|
continue;
|
|
2687
3174
|
}
|
|
2688
3175
|
let stats;
|
|
2689
3176
|
try {
|
|
2690
|
-
stats =
|
|
3177
|
+
stats = fs9__namespace.statSync(fullPath);
|
|
2691
3178
|
} catch {
|
|
2692
3179
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
2693
3180
|
continue;
|
|
@@ -2717,6 +3204,15 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
2717
3204
|
});
|
|
2718
3205
|
continue;
|
|
2719
3206
|
}
|
|
3207
|
+
const targetRelative = path10__namespace.relative(rootReal, targetReal).split(path10__namespace.sep).join("/");
|
|
3208
|
+
if (isSensitivePath(targetRelative)) {
|
|
3209
|
+
results.skipped.push({
|
|
3210
|
+
path: relPath,
|
|
3211
|
+
reason: "sensitive-file",
|
|
3212
|
+
detail: "link target is a credential-bearing file; not followed"
|
|
3213
|
+
});
|
|
3214
|
+
continue;
|
|
3215
|
+
}
|
|
2720
3216
|
isDirectory = false;
|
|
2721
3217
|
isFile = true;
|
|
2722
3218
|
}
|
|
@@ -3016,17 +3512,34 @@ function readConfigExport(exported, file) {
|
|
|
3016
3512
|
assertKnownConfigKeys(exported, file);
|
|
3017
3513
|
return exported;
|
|
3018
3514
|
}
|
|
3019
|
-
var
|
|
3515
|
+
var lastModuleConfig = null;
|
|
3516
|
+
function moduleConfigKey(fullPath) {
|
|
3517
|
+
try {
|
|
3518
|
+
return crypto2.createHash("sha256").update(fs9__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
3519
|
+
} catch {
|
|
3520
|
+
try {
|
|
3521
|
+
const stats = fs9__namespace.statSync(fullPath);
|
|
3522
|
+
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
3523
|
+
} catch {
|
|
3524
|
+
return "unreadable";
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3020
3528
|
async function importConfigModule(fullPath) {
|
|
3529
|
+
const key = moduleConfigKey(fullPath);
|
|
3530
|
+
if (lastModuleConfig !== null && lastModuleConfig.path === fullPath && lastModuleConfig.key === key) {
|
|
3531
|
+
return lastModuleConfig.exports;
|
|
3532
|
+
}
|
|
3021
3533
|
try {
|
|
3022
3534
|
const requireFromConfig = module$1.createRequire(fullPath);
|
|
3023
3535
|
delete requireFromConfig.cache[requireFromConfig.resolve(fullPath)];
|
|
3024
3536
|
} catch {
|
|
3025
3537
|
}
|
|
3026
3538
|
const url$1 = url.pathToFileURL(fullPath);
|
|
3027
|
-
|
|
3028
|
-
url$1.
|
|
3029
|
-
|
|
3539
|
+
url$1.searchParams.set("codebaseSnapshotLoad", key);
|
|
3540
|
+
const loaded = await import(url$1.href);
|
|
3541
|
+
lastModuleConfig = { path: fullPath, key, exports: loaded };
|
|
3542
|
+
return loaded;
|
|
3030
3543
|
}
|
|
3031
3544
|
function attachConfigDir(config, filePath) {
|
|
3032
3545
|
if (typeof config === "object" && config !== null) {
|
|
@@ -3038,15 +3551,25 @@ function attachConfigDir(config, filePath) {
|
|
|
3038
3551
|
}
|
|
3039
3552
|
return config;
|
|
3040
3553
|
}
|
|
3041
|
-
async function loadConfigFileDetailed(cwd) {
|
|
3554
|
+
async function loadConfigFileDetailed(cwd, options = {}) {
|
|
3042
3555
|
const warnings = [];
|
|
3043
3556
|
const errors = [];
|
|
3557
|
+
const configDirectories = [];
|
|
3044
3558
|
for (const filename of CONFIG_FILENAMES) {
|
|
3045
3559
|
const fullPath = path10__namespace.join(cwd, filename);
|
|
3046
|
-
|
|
3560
|
+
let candidateStats = null;
|
|
3561
|
+
try {
|
|
3562
|
+
candidateStats = fs9__namespace.statSync(fullPath);
|
|
3563
|
+
} catch {
|
|
3564
|
+
if (!fs9__namespace.existsSync(fullPath)) continue;
|
|
3565
|
+
}
|
|
3566
|
+
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
3567
|
+
configDirectories.push(fullPath);
|
|
3568
|
+
continue;
|
|
3569
|
+
}
|
|
3047
3570
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
3048
3571
|
try {
|
|
3049
|
-
const config = parseJsonish(
|
|
3572
|
+
const config = parseJsonish(fs9__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
3050
3573
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
3051
3574
|
throw new Error(
|
|
3052
3575
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -3062,6 +3585,12 @@ async function loadConfigFileDetailed(cwd) {
|
|
|
3062
3585
|
continue;
|
|
3063
3586
|
}
|
|
3064
3587
|
}
|
|
3588
|
+
if (options.allowExecutableConfig === false) {
|
|
3589
|
+
const message = `${fullPath} was not loaded: it is an executable config, and this server does not run repository code. Export the same settings from snapshot.config.json instead.`;
|
|
3590
|
+
warnings.push(message);
|
|
3591
|
+
errors.push(message);
|
|
3592
|
+
continue;
|
|
3593
|
+
}
|
|
3065
3594
|
if (filename.endsWith(".ts") && !supportsTypeScriptImports()) {
|
|
3066
3595
|
warnings.push(
|
|
3067
3596
|
`${fullPath} was ignored: loading a .ts config needs Node >= 22.6 (running ${process.versions.node}). Use snapshot.config.mjs, .cjs or .json instead.`
|
|
@@ -3081,9 +3610,9 @@ async function loadConfigFileDetailed(cwd) {
|
|
|
3081
3610
|
}
|
|
3082
3611
|
}
|
|
3083
3612
|
const pkgJsonPath = path10__namespace.join(cwd, "package.json");
|
|
3084
|
-
if (
|
|
3613
|
+
if (fs9__namespace.existsSync(pkgJsonPath)) {
|
|
3085
3614
|
try {
|
|
3086
|
-
const parsed = parseJsonish(
|
|
3615
|
+
const parsed = parseJsonish(fs9__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
3087
3616
|
const snapshotKey = parsed.snapshot;
|
|
3088
3617
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
3089
3618
|
assertKnownConfigKeys(
|
|
@@ -3109,6 +3638,11 @@ async function loadConfigFileDetailed(cwd) {
|
|
|
3109
3638
|
errors.push(message);
|
|
3110
3639
|
}
|
|
3111
3640
|
}
|
|
3641
|
+
if (configDirectories.length > 0) {
|
|
3642
|
+
warnings.push(
|
|
3643
|
+
`${configDirectories.join(", ")} ${configDirectories.length === 1 ? "is a directory" : "are directories"}, not a configuration file; no configuration was read from ${configDirectories.length === 1 ? "it" : "them"}.`
|
|
3644
|
+
);
|
|
3645
|
+
}
|
|
3112
3646
|
return { config: null, file: null, warnings, errors };
|
|
3113
3647
|
}
|
|
3114
3648
|
var MIN_MAX_PART_BYTES = 4096;
|
|
@@ -3277,11 +3811,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
3277
3811
|
const patterns = [];
|
|
3278
3812
|
for (const dir of [outDir, tmpDir]) {
|
|
3279
3813
|
const absolute = path10__namespace.resolve(cwd, dir);
|
|
3280
|
-
const
|
|
3281
|
-
if (!
|
|
3814
|
+
const relative9 = path10__namespace.relative(cwd, absolute);
|
|
3815
|
+
if (!relative9 || relative9 === ".." || relative9.startsWith(`..${path10__namespace.sep}`) || path10__namespace.isAbsolute(relative9)) {
|
|
3282
3816
|
continue;
|
|
3283
3817
|
}
|
|
3284
|
-
patterns.push(`${
|
|
3818
|
+
patterns.push(`${relative9.replace(/\\/g, "/")}/**`);
|
|
3285
3819
|
}
|
|
3286
3820
|
return patterns;
|
|
3287
3821
|
}
|
|
@@ -3412,10 +3946,10 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
3412
3946
|
}
|
|
3413
3947
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
3414
3948
|
const resolved = path10__namespace.resolve(candidate);
|
|
3415
|
-
if (!
|
|
3949
|
+
if (!fs9__namespace.existsSync(resolved)) {
|
|
3416
3950
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
3417
3951
|
}
|
|
3418
|
-
if (!
|
|
3952
|
+
if (!fs9__namespace.statSync(resolved).isDirectory()) {
|
|
3419
3953
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
3420
3954
|
}
|
|
3421
3955
|
return resolved;
|
|
@@ -3665,6 +4199,13 @@ function configDigest(config) {
|
|
|
3665
4199
|
// moving `{ name: "api", match: "src/api/**" }` to `"src/v2/**"` produced the same
|
|
3666
4200
|
// digest, so `validate` reported "valid and up to date" for a snapshot whose files
|
|
3667
4201
|
// had all been reclassified — and per-layer budgets applied to different files.
|
|
4202
|
+
// A function matcher's `String()` is its source, not its closure: two functions with the same
|
|
4203
|
+
// body but different captured values digest identically. That cannot be fixed by hashing, so
|
|
4204
|
+
// the digest records that executable matchers are present and `validate` says the digest does
|
|
4205
|
+
// not cover their closure, instead of claiming a equality it cannot prove.
|
|
4206
|
+
executableMatchers: [...config.layers, ...config.kinds].some(
|
|
4207
|
+
(rule) => typeof rule.match === "function"
|
|
4208
|
+
),
|
|
3668
4209
|
layers: config.layers.map((layer2) => ({ name: layer2.name, match: String(layer2.match) })),
|
|
3669
4210
|
kinds: config.kinds.map((kind) => ({ kind: kind.kind, match: String(kind.match) })),
|
|
3670
4211
|
// How files are enumerated decides what is in the snapshot at all.
|
|
@@ -4226,9 +4767,9 @@ var rubyProfile = {
|
|
|
4226
4767
|
eachLine(content, (line) => {
|
|
4227
4768
|
const trimmed = line.trim();
|
|
4228
4769
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
4229
|
-
const
|
|
4230
|
-
if (
|
|
4231
|
-
summary.imports.push(`./${
|
|
4770
|
+
const relative9 = REQUIRE_RELATIVE.exec(trimmed);
|
|
4771
|
+
if (relative9) {
|
|
4772
|
+
summary.imports.push(`./${relative9[1]}`);
|
|
4232
4773
|
return;
|
|
4233
4774
|
}
|
|
4234
4775
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -4328,6 +4869,16 @@ var ROUTE_HANDLER_NAMES = /* @__PURE__ */ new Set([
|
|
|
4328
4869
|
"HEAD",
|
|
4329
4870
|
"OPTIONS"
|
|
4330
4871
|
]);
|
|
4872
|
+
var ROUTE_RECEIVERS = /* @__PURE__ */ new Set(["app", "router", "server", "fastify", "api", "route"]);
|
|
4873
|
+
var ROUTE_REGISTRATION_VERBS = /* @__PURE__ */ new Set([
|
|
4874
|
+
"get",
|
|
4875
|
+
"post",
|
|
4876
|
+
"put",
|
|
4877
|
+
"delete",
|
|
4878
|
+
"patch",
|
|
4879
|
+
"head",
|
|
4880
|
+
"options"
|
|
4881
|
+
]);
|
|
4331
4882
|
function bindingNames(name, into) {
|
|
4332
4883
|
if (ts__default.default.isIdentifier(name)) {
|
|
4333
4884
|
into.push(name.text);
|
|
@@ -4338,6 +4889,53 @@ function bindingNames(name, into) {
|
|
|
4338
4889
|
bindingNames(element.name, into);
|
|
4339
4890
|
}
|
|
4340
4891
|
}
|
|
4892
|
+
function objectLiteralNames(node) {
|
|
4893
|
+
const names = [];
|
|
4894
|
+
for (const property of node.properties) {
|
|
4895
|
+
if (ts__default.default.isShorthandPropertyAssignment(property)) {
|
|
4896
|
+
names.push(property.name.text);
|
|
4897
|
+
continue;
|
|
4898
|
+
}
|
|
4899
|
+
if (!ts__default.default.isPropertyAssignment(property)) continue;
|
|
4900
|
+
const name = property.name;
|
|
4901
|
+
if (ts__default.default.isIdentifier(name) || ts__default.default.isStringLiteral(name) || ts__default.default.isNumericLiteral(name)) {
|
|
4902
|
+
names.push(name.text);
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
return names;
|
|
4906
|
+
}
|
|
4907
|
+
function cjsExportedNames(expression) {
|
|
4908
|
+
const left = expression.left;
|
|
4909
|
+
if (!ts__default.default.isPropertyAccessExpression(left)) return null;
|
|
4910
|
+
const isModuleExports = left.name.text === "exports" && ts__default.default.isIdentifier(left.expression) && left.expression.text === "module";
|
|
4911
|
+
if (isModuleExports) {
|
|
4912
|
+
const right = expression.right;
|
|
4913
|
+
if (ts__default.default.isObjectLiteralExpression(right)) return objectLiteralNames(right);
|
|
4914
|
+
if (ts__default.default.isIdentifier(right)) return [right.text];
|
|
4915
|
+
return [];
|
|
4916
|
+
}
|
|
4917
|
+
if (ts__default.default.isIdentifier(left.expression) && left.expression.text === "exports") {
|
|
4918
|
+
return [left.name.text];
|
|
4919
|
+
}
|
|
4920
|
+
const parent = left.expression;
|
|
4921
|
+
if (ts__default.default.isPropertyAccessExpression(parent) && parent.name.text === "exports" && ts__default.default.isIdentifier(parent.expression) && parent.expression.text === "module") {
|
|
4922
|
+
return [left.name.text];
|
|
4923
|
+
}
|
|
4924
|
+
return null;
|
|
4925
|
+
}
|
|
4926
|
+
function countSyntacticErrors(fileName, content) {
|
|
4927
|
+
const result = ts__default.default.transpileModule(content, {
|
|
4928
|
+
fileName,
|
|
4929
|
+
compilerOptions: {
|
|
4930
|
+
target: ts__default.default.ScriptTarget.Latest,
|
|
4931
|
+
module: ts__default.default.ModuleKind.ESNext
|
|
4932
|
+
},
|
|
4933
|
+
reportDiagnostics: true
|
|
4934
|
+
});
|
|
4935
|
+
return (result.diagnostics ?? []).filter(
|
|
4936
|
+
(diagnostic) => diagnostic.category === ts__default.default.DiagnosticCategory.Error
|
|
4937
|
+
).length;
|
|
4938
|
+
}
|
|
4341
4939
|
function summarizeTypeScriptSource(relativePath, content) {
|
|
4342
4940
|
const summary = {
|
|
4343
4941
|
directives: [],
|
|
@@ -4355,16 +4953,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4355
4953
|
routeHandlers: []
|
|
4356
4954
|
};
|
|
4357
4955
|
const lowerPath = relativePath.toLowerCase();
|
|
4358
|
-
const
|
|
4956
|
+
const scriptKind = /.tsx$/.test(lowerPath) ? ts__default.default.ScriptKind.TSX : /.jsx$/.test(lowerPath) ? ts__default.default.ScriptKind.JSX : /.(?:js|mjs|cjs)$/.test(lowerPath) ? ts__default.default.ScriptKind.JS : ts__default.default.ScriptKind.TS;
|
|
4359
4957
|
const sourceFile = ts__default.default.createSourceFile(
|
|
4360
4958
|
relativePath,
|
|
4361
4959
|
content,
|
|
4362
4960
|
ts__default.default.ScriptTarget.Latest,
|
|
4363
4961
|
/* setParentNodes */
|
|
4364
4962
|
false,
|
|
4365
|
-
|
|
4963
|
+
scriptKind
|
|
4366
4964
|
);
|
|
4367
|
-
const
|
|
4965
|
+
const parsedDiagnostics = sourceFile.parseDiagnostics;
|
|
4966
|
+
const parseErrors = Array.isArray(parsedDiagnostics) ? parsedDiagnostics.filter((diagnostic) => diagnostic.category === ts__default.default.DiagnosticCategory.Error).length : countSyntacticErrors(relativePath, content);
|
|
4368
4967
|
if (parseErrors > 0) summary.parseErrors = parseErrors;
|
|
4369
4968
|
for (const statement of sourceFile.statements) {
|
|
4370
4969
|
if (ts__default.default.isExpressionStatement(statement) && ts__default.default.isStringLiteral(statement.expression)) {
|
|
@@ -4421,6 +5020,7 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4421
5020
|
if (/^use[A-Z0-9]/.test(name)) summary.hooks.push(name);
|
|
4422
5021
|
if (/^[A-Z]/.test(name) && rendersJsx(node)) summary.reactComponents.push(name);
|
|
4423
5022
|
};
|
|
5023
|
+
const cjsExports = [];
|
|
4424
5024
|
const stack = [sourceFile];
|
|
4425
5025
|
while (stack.length > 0) {
|
|
4426
5026
|
const node = stack.pop();
|
|
@@ -4437,6 +5037,10 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4437
5037
|
const isRequire = ts__default.default.isIdentifier(node.expression) && node.expression.text === "require";
|
|
4438
5038
|
if (isDynamicImport || isRequire) summary.imports.push(firstArgument.text);
|
|
4439
5039
|
}
|
|
5040
|
+
const callee = node.expression;
|
|
5041
|
+
if (ts__default.default.isPropertyAccessExpression(callee) && ts__default.default.isIdentifier(callee.expression) && ROUTE_RECEIVERS.has(callee.expression.text) && ROUTE_REGISTRATION_VERBS.has(callee.name.text.toLowerCase()) && firstArgument !== void 0 && ts__default.default.isStringLiteral(firstArgument)) {
|
|
5042
|
+
summary.routeHandlers.push(callee.name.text.toUpperCase());
|
|
5043
|
+
}
|
|
4440
5044
|
}
|
|
4441
5045
|
if (ts__default.default.isExportDeclaration(node)) {
|
|
4442
5046
|
if (node.moduleSpecifier && ts__default.default.isStringLiteral(node.moduleSpecifier)) {
|
|
@@ -4454,6 +5058,10 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4454
5058
|
}
|
|
4455
5059
|
}
|
|
4456
5060
|
}
|
|
5061
|
+
if (ts__default.default.isExpressionStatement(node) && ts__default.default.isBinaryExpression(node.expression) && node.expression.operatorToken.kind === ts__default.default.SyntaxKind.EqualsToken) {
|
|
5062
|
+
const cjsNames = cjsExportedNames(node.expression);
|
|
5063
|
+
if (cjsNames !== null) cjsExports.push(...cjsNames);
|
|
5064
|
+
}
|
|
4457
5065
|
if (ts__default.default.isExportAssignment(node)) {
|
|
4458
5066
|
summary.exports.push("default");
|
|
4459
5067
|
if (rendersJsx(node.expression)) summary.reactComponents.push("default");
|
|
@@ -4517,6 +5125,10 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
4517
5125
|
stack.push(children[index]);
|
|
4518
5126
|
}
|
|
4519
5127
|
}
|
|
5128
|
+
if (cjsExports.length > 0) {
|
|
5129
|
+
summary.exportsKind = summary.exports.length > 0 ? "mixed" : "cjs";
|
|
5130
|
+
summary.exports.push(...cjsExports);
|
|
5131
|
+
}
|
|
4520
5132
|
const dedupeSorted2 = (values) => Array.from(new Set(values)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
4521
5133
|
summary.directives = dedupeSorted2(summary.directives);
|
|
4522
5134
|
summary.imports = dedupeSorted2(summary.imports);
|
|
@@ -4969,13 +5581,13 @@ function isBinaryFile(absolutePath) {
|
|
|
4969
5581
|
if (isBinaryExtension(absolutePath)) return true;
|
|
4970
5582
|
let fd;
|
|
4971
5583
|
try {
|
|
4972
|
-
fd =
|
|
5584
|
+
fd = fs9__namespace.openSync(absolutePath, "r");
|
|
4973
5585
|
const buffer = Buffer.alloc(CHUNK);
|
|
4974
5586
|
let sample;
|
|
4975
5587
|
let position = 0;
|
|
4976
5588
|
while (position < BINARY_SCAN_BYTES) {
|
|
4977
5589
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
4978
|
-
const bytesRead =
|
|
5590
|
+
const bytesRead = fs9__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
4979
5591
|
if (bytesRead === 0) return false;
|
|
4980
5592
|
const chunk = buffer.subarray(0, bytesRead);
|
|
4981
5593
|
if (sample === void 0) {
|
|
@@ -4993,7 +5605,7 @@ function isBinaryFile(absolutePath) {
|
|
|
4993
5605
|
} finally {
|
|
4994
5606
|
if (fd !== void 0) {
|
|
4995
5607
|
try {
|
|
4996
|
-
|
|
5608
|
+
fs9__namespace.closeSync(fd);
|
|
4997
5609
|
} catch {
|
|
4998
5610
|
}
|
|
4999
5611
|
}
|
|
@@ -5015,9 +5627,9 @@ function importsOfText(relativePath, text) {
|
|
|
5015
5627
|
function importsOfFile(relativePath, absolutePath) {
|
|
5016
5628
|
let buffer;
|
|
5017
5629
|
try {
|
|
5018
|
-
const stats =
|
|
5630
|
+
const stats = fs9__namespace.statSync(absolutePath);
|
|
5019
5631
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
5020
|
-
buffer =
|
|
5632
|
+
buffer = fs9__namespace.readFileSync(absolutePath);
|
|
5021
5633
|
} catch {
|
|
5022
5634
|
return [];
|
|
5023
5635
|
}
|
|
@@ -5278,6 +5890,169 @@ function inlineCode(value) {
|
|
|
5278
5890
|
const needsPadding = escaped.startsWith("`") || escaped.endsWith("`");
|
|
5279
5891
|
return `${fence}${needsPadding ? ` ${escaped} ` : escaped}${fence}`;
|
|
5280
5892
|
}
|
|
5893
|
+
function tableCell(value) {
|
|
5894
|
+
return escapeControls(value).replace(/\|/g, "\\|").replace(/\r\n?|\n/g, " ");
|
|
5895
|
+
}
|
|
5896
|
+
function codeCell(value) {
|
|
5897
|
+
return inlineCode(tableCell(value));
|
|
5898
|
+
}
|
|
5899
|
+
function formatNumber(value) {
|
|
5900
|
+
return value.toLocaleString("en-US");
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5903
|
+
// src/generator/audit.ts
|
|
5904
|
+
function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
5905
|
+
const mask = (value) => escapeControls(findSecretInPath(value, secretRules)?.masked ?? value);
|
|
5906
|
+
const code = (value) => codeCell(mask(value));
|
|
5907
|
+
const lines = [
|
|
5908
|
+
"# Codebase Health & Security Audit",
|
|
5909
|
+
"",
|
|
5910
|
+
`**Generated:** ${manifest.generatedAt} `,
|
|
5911
|
+
`**Git Branch:** ${inlineCode(escapeControls(manifest.git.branch))} (\`${manifest.git.commit.slice(0, 8)}\`${manifest.git.isDirty ? " - dirty" : ""}) `,
|
|
5912
|
+
`**Total Files:** ${formatNumber(manifest.counts.totalFiles)} `,
|
|
5913
|
+
`**Source Lines:** ${formatNumber(manifest.counts.totalLines)} `,
|
|
5914
|
+
`**Emitted Lines:** ${formatNumber(manifest.totals.emittedLines ?? manifest.counts.totalLines)} `,
|
|
5915
|
+
`**Total Size:** ${(manifest.counts.totalSizeBytes / (1024 * 1024)).toFixed(2)} MiB `,
|
|
5916
|
+
// This counts the bytes that were *emitted* after redaction, not the bytes
|
|
5917
|
+
// that were masked: calling it "redacted bytes" made a repository with zero
|
|
5918
|
+
// secrets report a non-zero redacted-byte figure directly above "no secrets
|
|
5919
|
+
// detected". The number of masked lines is reported in section 1 instead.
|
|
5920
|
+
`**Emitted Content Bytes:** ${formatNumber(manifest.totals.totalContentBytes)} `,
|
|
5921
|
+
"",
|
|
5922
|
+
"## 1. Security Scan & Redaction",
|
|
5923
|
+
"",
|
|
5924
|
+
"Matched values are replaced in place in `parts/*.md`; no excerpt of a matched",
|
|
5925
|
+
"line is reproduced in this report or anywhere else in the snapshot.",
|
|
5926
|
+
""
|
|
5927
|
+
];
|
|
5928
|
+
if (secretFindings.length === 0) {
|
|
5929
|
+
lines.push("\u2705 **No secret-like patterns detected.** Clean security scan.", "");
|
|
5930
|
+
} else {
|
|
5931
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
5932
|
+
for (const finding of secretFindings) {
|
|
5933
|
+
for (const rule of finding.rules) byRule.set(rule, (byRule.get(rule) ?? 0) + 1);
|
|
5934
|
+
}
|
|
5935
|
+
lines.push(
|
|
5936
|
+
`\u26A0\uFE0F **${formatNumber(secretFindings.length)} line(s) contain values that were redacted:**`,
|
|
5937
|
+
"",
|
|
5938
|
+
"| File | Line | Rules |",
|
|
5939
|
+
"| :--- | ---: | :--- |"
|
|
5940
|
+
);
|
|
5941
|
+
for (const finding of secretFindings) {
|
|
5942
|
+
lines.push(
|
|
5943
|
+
`| ${code(finding.path ?? "unknown")} | ${finding.line} | ${finding.rules.map(code).join(", ")} |`
|
|
5944
|
+
);
|
|
5945
|
+
}
|
|
5946
|
+
lines.push("", "### Matches by rule", "", "| Rule | Lines |", "| :--- | ---: |");
|
|
5947
|
+
for (const [rule, count] of Array.from(byRule.entries()).sort((a, b) => b[1] - a[1])) {
|
|
5948
|
+
lines.push(`| ${code(rule)} | ${count} |`);
|
|
5949
|
+
}
|
|
5950
|
+
lines.push("");
|
|
5951
|
+
}
|
|
5952
|
+
const parseIssues = manifest.files.filter(
|
|
5953
|
+
(file) => file.summary !== void 0 && typeof file.summary === "object" && "parseErrors" in file.summary && typeof file.summary.parseErrors === "number" && file.summary.parseErrors > 0
|
|
5954
|
+
);
|
|
5955
|
+
const unparsedPreviews = manifest.files.filter(
|
|
5956
|
+
(file) => file.summary === void 0 && (file.isPreviewTruncated === true || file.isLarge === true)
|
|
5957
|
+
).length;
|
|
5958
|
+
lines.push("## 2. Parse & AST Diagnostics", "");
|
|
5959
|
+
if (parseIssues.length === 0) {
|
|
5960
|
+
if (unparsedPreviews > 0) {
|
|
5961
|
+
lines.push(
|
|
5962
|
+
`\u2705 No parse errors among the files that were parsed; ${formatNumber(unparsedPreviews)} file(s) were previewed or too large to parse and produced no structural summary.`,
|
|
5963
|
+
""
|
|
5964
|
+
);
|
|
5965
|
+
} else {
|
|
5966
|
+
lines.push("\u2705 Every parsed file produced a complete structural summary.", "");
|
|
5967
|
+
}
|
|
5968
|
+
} else {
|
|
5969
|
+
lines.push(
|
|
5970
|
+
`${parseIssues.length} file(s) produced an incomplete summary:`,
|
|
5971
|
+
"",
|
|
5972
|
+
"| File | Parse Errors |",
|
|
5973
|
+
"| :--- | ---: |"
|
|
5974
|
+
);
|
|
5975
|
+
for (const file of parseIssues) {
|
|
5976
|
+
const errors = file.summary.parseErrors;
|
|
5977
|
+
lines.push(`| ${code(file.relativePath)} | ${errors} |`);
|
|
5978
|
+
}
|
|
5979
|
+
lines.push(
|
|
5980
|
+
"",
|
|
5981
|
+
"A parse error here means the summary is incomplete, not that the file is excluded \u2014",
|
|
5982
|
+
"the content is still in the parts.",
|
|
5983
|
+
""
|
|
5984
|
+
);
|
|
5985
|
+
}
|
|
5986
|
+
lines.push("## 3. Large Files Analysis", "");
|
|
5987
|
+
const largeFiles = manifest.files.filter((file) => file.isLarge);
|
|
5988
|
+
const truncatedFiles = manifest.files.filter((file) => file.isPreviewTruncated);
|
|
5989
|
+
const affected = manifest.files.filter((file) => file.isLarge || file.isPreviewTruncated);
|
|
5990
|
+
if (affected.length === 0) {
|
|
5991
|
+
lines.push("\u2705 No files exceeded the large file budget and none were truncated.", "");
|
|
5992
|
+
} else {
|
|
5993
|
+
lines.push(
|
|
5994
|
+
`Found ${formatNumber(largeFiles.length)} file(s) over the large-file budget (${(manifest.budgets.largeFileBytes / 1024).toFixed(0)} KB) and ${formatNumber(truncatedFiles.length)} file(s) truncated by a budget:`,
|
|
5995
|
+
"",
|
|
5996
|
+
"| File | Size (B) | Source Lines | Included Bytes | Included Lines | Status | Cut by |",
|
|
5997
|
+
"| :--- | ---: | ---: | ---: | ---: | :--- | :--- |"
|
|
5998
|
+
);
|
|
5999
|
+
for (const file of affected) {
|
|
6000
|
+
const status = file.isPreviewTruncated ? "Truncated" : "Full";
|
|
6001
|
+
const cutBy = file.isLarge ? "largeFileBytes" : "maxPartBytes";
|
|
6002
|
+
lines.push(
|
|
6003
|
+
`| ${code(file.relativePath)} | ${file.sizeBytes} | ${file.lines} | ${file.includedBytes} | ${file.includedLines} | ${status} | ${cutBy} |`
|
|
6004
|
+
);
|
|
6005
|
+
}
|
|
6006
|
+
lines.push(
|
|
6007
|
+
"",
|
|
6008
|
+
`Truncated: ${formatNumber(truncatedFiles.length)} of ${formatNumber(manifest.counts.totalFiles)} file(s); every truncated block carries a \`[N lines omitted]\` notice naming its budget.`,
|
|
6009
|
+
""
|
|
6010
|
+
);
|
|
6011
|
+
}
|
|
6012
|
+
lines.push(
|
|
6013
|
+
"## 4. Architecture Layer Distribution",
|
|
6014
|
+
"",
|
|
6015
|
+
"| Layer | File Count | Percentage |",
|
|
6016
|
+
"| :--- | :--- | :--- |"
|
|
6017
|
+
);
|
|
6018
|
+
const totalFiles = manifest.counts.totalFiles || 1;
|
|
6019
|
+
for (const [layer2, count] of Object.entries(manifest.layers).sort(
|
|
6020
|
+
(a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)
|
|
6021
|
+
)) {
|
|
6022
|
+
const pct = (count / totalFiles * 100).toFixed(1);
|
|
6023
|
+
lines.push(`| ${code(layer2)} | ${count} | ${pct}% |`);
|
|
6024
|
+
}
|
|
6025
|
+
lines.push("");
|
|
6026
|
+
lines.push(
|
|
6027
|
+
"## 5. File Kind Distribution",
|
|
6028
|
+
"",
|
|
6029
|
+
"| Kind | File Count | Percentage |",
|
|
6030
|
+
"| :--- | :--- | :--- |"
|
|
6031
|
+
);
|
|
6032
|
+
for (const [kind, count] of Object.entries(manifest.kinds).sort(
|
|
6033
|
+
(a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)
|
|
6034
|
+
)) {
|
|
6035
|
+
const pct = (count / totalFiles * 100).toFixed(1);
|
|
6036
|
+
lines.push(`| ${code(kind)} | ${count} | ${pct}% |`);
|
|
6037
|
+
}
|
|
6038
|
+
lines.push("");
|
|
6039
|
+
lines.push("## 6. Skipped / Non-Text Files", "");
|
|
6040
|
+
if (manifest.skipped.length === 0) {
|
|
6041
|
+
lines.push("No files were skipped.", "");
|
|
6042
|
+
} else {
|
|
6043
|
+
lines.push(
|
|
6044
|
+
`Total skipped: ${manifest.skipped.length}`,
|
|
6045
|
+
"",
|
|
6046
|
+
"| File | Reason | Detail |",
|
|
6047
|
+
"| :--- | :--- | :--- |"
|
|
6048
|
+
);
|
|
6049
|
+
for (const skip of manifest.skipped) {
|
|
6050
|
+
lines.push(`| ${code(skip.path)} | ${code(skip.reason)} | ${tableCell(skip.detail ?? "-")} |`);
|
|
6051
|
+
}
|
|
6052
|
+
lines.push("");
|
|
6053
|
+
}
|
|
6054
|
+
return lines.join("\n");
|
|
6055
|
+
}
|
|
5281
6056
|
var SARIF_VERSION = "2.1.0";
|
|
5282
6057
|
var SARIF_SCHEMA = "https://json.schemastore.org/sarif-2.1.0.json";
|
|
5283
6058
|
var BUILTIN_RULE_IDS = new Map(
|
|
@@ -5389,9 +6164,9 @@ function truncateToBytes(content, maxBytes) {
|
|
|
5389
6164
|
if (maxBytes <= 0) return { content: "", isTruncated: content.length > 0 };
|
|
5390
6165
|
const buffer = Buffer.from(content, "utf8");
|
|
5391
6166
|
if (buffer.length <= maxBytes) return { content, isTruncated: false };
|
|
5392
|
-
let
|
|
5393
|
-
while (
|
|
5394
|
-
return { content:
|
|
6167
|
+
let end = maxBytes;
|
|
6168
|
+
while (end > 0 && (buffer[end] & 192) === 128) end -= 1;
|
|
6169
|
+
return { content: buffer.subarray(0, end).toString("utf8"), isTruncated: true };
|
|
5395
6170
|
}
|
|
5396
6171
|
function truncatePreview(content, headLines, tailLines) {
|
|
5397
6172
|
const normalised = normaliseLineEndings(content);
|
|
@@ -5474,19 +6249,19 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
5474
6249
|
for (const sections of greedyGroups(prepared, budget)) groups.push({ sections, budget });
|
|
5475
6250
|
}
|
|
5476
6251
|
if (groups.length === 0) return [];
|
|
5477
|
-
const
|
|
6252
|
+
const assemblies = /* @__PURE__ */ new Map();
|
|
5478
6253
|
const widthOf = (total) => Math.max(3, String(total).length);
|
|
5479
|
-
const
|
|
5480
|
-
const cached = measurements.get(group);
|
|
6254
|
+
const assemble = (group, index, total) => {
|
|
5481
6255
|
const width = widthOf(total);
|
|
6256
|
+
const cached = assemblies.get(group);
|
|
5482
6257
|
if (cached !== void 0 && cached.index === index && cached.width === width) {
|
|
5483
|
-
return cached.
|
|
6258
|
+
return cached.value;
|
|
5484
6259
|
}
|
|
5485
|
-
const
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
return size;
|
|
6260
|
+
const value = assembleGroup(group, index, total, contentFingerprint);
|
|
6261
|
+
assemblies.set(group, { index, width, value });
|
|
6262
|
+
return value;
|
|
5489
6263
|
};
|
|
6264
|
+
const measure = (group, index, total) => Buffer.byteLength(assemble(group, index, total).content, "utf8");
|
|
5490
6265
|
for (let pass = 0; pass < MAX_SPLIT_PASSES; pass++) {
|
|
5491
6266
|
const total = groups.length;
|
|
5492
6267
|
let oversized = -1;
|
|
@@ -5497,16 +6272,16 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
5497
6272
|
break;
|
|
5498
6273
|
}
|
|
5499
6274
|
}
|
|
5500
|
-
if (oversized === -1) return renderGroups(groups, contentFingerprint);
|
|
6275
|
+
if (oversized === -1) return renderGroups(groups, contentFingerprint, assemble);
|
|
5501
6276
|
const group = groups[oversized];
|
|
5502
6277
|
if (group.sections.length > 1) {
|
|
5503
6278
|
const moved = group.sections.pop();
|
|
5504
6279
|
groups.splice(oversized + 1, 0, { sections: [moved], budget: group.budget });
|
|
5505
|
-
|
|
6280
|
+
assemblies.delete(group);
|
|
5506
6281
|
continue;
|
|
5507
6282
|
}
|
|
5508
6283
|
const [section] = group.sections;
|
|
5509
|
-
if (section === void 0) return renderGroups(groups, contentFingerprint);
|
|
6284
|
+
if (section === void 0) return renderGroups(groups, contentFingerprint, assemble);
|
|
5510
6285
|
const overflow = measure(group, oversized, total) - group.budget;
|
|
5511
6286
|
const currentContent = section.file.content ?? "";
|
|
5512
6287
|
const shrinkTo = Math.max(
|
|
@@ -5523,10 +6298,10 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
5523
6298
|
applyTruncatedContent(section.file, shrunk.content);
|
|
5524
6299
|
section.text = renderFileSection(section.file);
|
|
5525
6300
|
section.byteSize = Buffer.byteLength(section.text, "utf8");
|
|
5526
|
-
|
|
6301
|
+
assemblies.delete(group);
|
|
5527
6302
|
continue;
|
|
5528
6303
|
}
|
|
5529
|
-
const rendered = renderGroups(groups, contentFingerprint);
|
|
6304
|
+
const rendered = renderGroups(groups, contentFingerprint, assemble);
|
|
5530
6305
|
const marker = TRUNCATION_MARKER;
|
|
5531
6306
|
assertBudgetHoldsMarker(group.budget);
|
|
5532
6307
|
const target = Math.max(
|
|
@@ -5540,7 +6315,7 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
5540
6315
|
);
|
|
5541
6316
|
return rendered;
|
|
5542
6317
|
}
|
|
5543
|
-
return renderGroups(groups, contentFingerprint).flatMap(
|
|
6318
|
+
return renderGroups(groups, contentFingerprint, assemble).flatMap(
|
|
5544
6319
|
(part) => enforceBudget([part], part.metadata.budgetBytes)
|
|
5545
6320
|
);
|
|
5546
6321
|
}
|
|
@@ -5714,8 +6489,8 @@ function assembleGroup(group, index, total, contentFingerprint) {
|
|
|
5714
6489
|
for (const section of group.sections) {
|
|
5715
6490
|
section.file.part = filename;
|
|
5716
6491
|
}
|
|
5717
|
-
const layerCounts =
|
|
5718
|
-
const kindCounts =
|
|
6492
|
+
const layerCounts = /* @__PURE__ */ Object.create(null);
|
|
6493
|
+
const kindCounts = /* @__PURE__ */ Object.create(null);
|
|
5719
6494
|
for (const section of group.sections) {
|
|
5720
6495
|
layerCounts[section.file.layer] = (layerCounts[section.file.layer] || 0) + 1;
|
|
5721
6496
|
kindCounts[section.file.kind] = (kindCounts[section.file.kind] || 0) + 1;
|
|
@@ -5750,15 +6525,10 @@ function assembleGroup(group, index, total, contentFingerprint) {
|
|
|
5750
6525
|
const estimatedTokens = estimateTokens(assembled);
|
|
5751
6526
|
return { filename, content: insertTokenLine(assembled, estimatedTokens), estimatedTokens };
|
|
5752
6527
|
}
|
|
5753
|
-
function renderGroups(groups, contentFingerprint) {
|
|
6528
|
+
function renderGroups(groups, contentFingerprint, assemble = (group, index, total) => assembleGroup(group, index, total, contentFingerprint)) {
|
|
5754
6529
|
const total = groups.length;
|
|
5755
6530
|
return groups.map((group, index) => {
|
|
5756
|
-
const { filename, content, estimatedTokens } =
|
|
5757
|
-
group,
|
|
5758
|
-
index,
|
|
5759
|
-
total,
|
|
5760
|
-
contentFingerprint
|
|
5761
|
-
);
|
|
6531
|
+
const { filename, content, estimatedTokens } = assemble(group, index, total);
|
|
5762
6532
|
const byteSize = Buffer.byteLength(content, "utf8");
|
|
5763
6533
|
const sha256 = crypto2__namespace.createHash("sha256").update(content).digest("hex");
|
|
5764
6534
|
const layersCovered = Array.from(new Set(group.sections.map((s) => s.file.layer))).sort();
|
|
@@ -5886,12 +6656,153 @@ function generateMonolithMarkdown(manifest, filesWithContent) {
|
|
|
5886
6656
|
].join("\n");
|
|
5887
6657
|
}
|
|
5888
6658
|
|
|
5889
|
-
// src/generator/
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
6659
|
+
// src/generator/navigation.ts
|
|
6660
|
+
function linkLabel(value) {
|
|
6661
|
+
return tableCell(value.replace(/[\\[\]()]/g, "\\$&"));
|
|
6662
|
+
}
|
|
6663
|
+
function generateNavigation(manifest) {
|
|
6664
|
+
const lines = [
|
|
6665
|
+
"# Codebase Navigation Index",
|
|
6666
|
+
"",
|
|
6667
|
+
"Fast lookup index mapping every file to its snapshot chunk.",
|
|
6668
|
+
"",
|
|
6669
|
+
"## Parts Overview",
|
|
6670
|
+
"",
|
|
6671
|
+
"| Part | File Count | Size (KB) | Layers Covered |",
|
|
6672
|
+
"| :--- | :--- | :--- | :--- |"
|
|
6673
|
+
];
|
|
6674
|
+
for (const part of manifest.parts) {
|
|
6675
|
+
const sizeKb = (part.byteSize / 1024).toFixed(1);
|
|
6676
|
+
lines.push(
|
|
6677
|
+
`| [${part.filename}](../parts/${part.filename}) | ${part.fileCount} | ${sizeKb} KB | ${tableCell(part.layersCovered.join(", "))} |`
|
|
6678
|
+
);
|
|
6679
|
+
}
|
|
6680
|
+
lines.push(
|
|
6681
|
+
"",
|
|
6682
|
+
"## File Directory",
|
|
6683
|
+
"",
|
|
6684
|
+
"| File | Part | Layer | Kind | Lines | Size |",
|
|
6685
|
+
"| :--- | :--- | :--- | :--- | :--- | :--- |"
|
|
6686
|
+
);
|
|
6687
|
+
const filePartMap = /* @__PURE__ */ new Map();
|
|
6688
|
+
for (const part of manifest.parts) {
|
|
6689
|
+
for (const file of part.includedFiles) {
|
|
6690
|
+
filePartMap.set(file.relativePath, part.filename);
|
|
6691
|
+
}
|
|
6692
|
+
}
|
|
6693
|
+
for (const file of manifest.files) {
|
|
6694
|
+
const partFilename = filePartMap.get(file.relativePath) || file.part || "none";
|
|
6695
|
+
const anchor = anchorForPath(file.relativePath);
|
|
6696
|
+
const link = `[${linkLabel(file.relativePath)}](../parts/${partFilename}#${anchor})`;
|
|
6697
|
+
const sizeStr = `${(file.sizeBytes / 1024).toFixed(1)} KB`;
|
|
6698
|
+
lines.push(
|
|
6699
|
+
`| ${link} | ${codeCell(partFilename)} | ${codeCell(file.layer)} | ${codeCell(file.kind)} | ${file.lines} | ${sizeStr} |`
|
|
6700
|
+
);
|
|
6701
|
+
}
|
|
6702
|
+
lines.push("");
|
|
6703
|
+
return lines.join("\n");
|
|
6704
|
+
}
|
|
6705
|
+
|
|
6706
|
+
// src/generator/readme.ts
|
|
6707
|
+
function generateReadme(manifest, artifacts) {
|
|
6708
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
6709
|
+
const reportLinks = [];
|
|
6710
|
+
if (wrote("navigation")) {
|
|
6711
|
+
reportLinks.push(
|
|
6712
|
+
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
6713
|
+
);
|
|
6714
|
+
}
|
|
6715
|
+
if (wrote("projectTree")) {
|
|
6716
|
+
reportLinks.push(
|
|
6717
|
+
"- [reports/project-tree.md](reports/project-tree.md) \u2014 Full visual ASCII directory tree of the repository."
|
|
6718
|
+
);
|
|
6719
|
+
}
|
|
6720
|
+
if (wrote("audit")) {
|
|
6721
|
+
reportLinks.push(
|
|
6722
|
+
"- [reports/audit.md](reports/audit.md) \u2014 Security scan counts, large files report, and architectural breakdown."
|
|
6723
|
+
);
|
|
6724
|
+
}
|
|
6725
|
+
if (wrote("manifest")) {
|
|
6726
|
+
reportLinks.push(
|
|
6727
|
+
"- [manifest.json](manifest.json) \u2014 Complete machine-readable metadata and AST symbol registry."
|
|
6728
|
+
);
|
|
6729
|
+
}
|
|
6730
|
+
if (reportLinks.length === 0) {
|
|
6731
|
+
reportLinks.push(
|
|
6732
|
+
"- Nothing else was written: every other artifact was disabled for this run."
|
|
6733
|
+
);
|
|
6734
|
+
}
|
|
6735
|
+
const lines = [
|
|
6736
|
+
"# Codebase Snapshot",
|
|
6737
|
+
"",
|
|
6738
|
+
"This directory contains a complete, partitioned, and audited snapshot of this codebase, optimized for Large Language Models (LLMs) and automated agents.",
|
|
6739
|
+
"",
|
|
6740
|
+
UNTRUSTED_CONTENT_NOTICE,
|
|
6741
|
+
"",
|
|
6742
|
+
"## Snapshot Metrics",
|
|
6743
|
+
"",
|
|
6744
|
+
`- **Generated At:** \`${manifest.generatedAt}\``,
|
|
6745
|
+
`- **Schema Version:** \`${manifest.schemaVersion}\``,
|
|
6746
|
+
`- **Branch:** ${inlineCode(escapeControls(manifest.git.branch))} (\`${manifest.git.commit.slice(0, 8)}\`${manifest.git.isDirty ? " - dirty" : ""})`,
|
|
6747
|
+
`- **Total Tracked Files:** \`${manifest.counts.totalFiles}\``,
|
|
6748
|
+
`- **Source Lines:** \`${formatNumber(manifest.counts.totalLines)}\``,
|
|
6749
|
+
`- **Emitted Lines:** \`${formatNumber(manifest.totals.emittedLines ?? manifest.counts.totalLines)}\``,
|
|
6750
|
+
`- **Total Size:** \`${(manifest.counts.totalSizeBytes / (1024 * 1024)).toFixed(2)} MiB\``,
|
|
6751
|
+
`- **Emitted Content:** \`${(manifest.totals.totalContentBytes / (1024 * 1024)).toFixed(2)} MiB\``,
|
|
6752
|
+
`- **Part Count:** \`${manifest.counts.partsCount}\` (budget \`${(manifest.budgets.maxPartBytes / 1024).toFixed(0)} KB\` per part)`,
|
|
6753
|
+
`- **Generator:** \`${manifest.generator.name}@${manifest.generator.version}\``,
|
|
6754
|
+
"",
|
|
6755
|
+
"## Documentation & Reports",
|
|
6756
|
+
"",
|
|
6757
|
+
...reportLinks
|
|
6758
|
+
];
|
|
6759
|
+
if (wrote("parts")) {
|
|
6760
|
+
lines.push(
|
|
6761
|
+
"",
|
|
6762
|
+
"## Snapshot Parts",
|
|
6763
|
+
"",
|
|
6764
|
+
"The codebase is partitioned into budget-safe chunks under `parts/` to avoid context window degradation:",
|
|
6765
|
+
"",
|
|
6766
|
+
"| Part | File Count | Size (KB) | Layers Covered |",
|
|
6767
|
+
"| :--- | :--- | :--- | :--- |"
|
|
6768
|
+
);
|
|
6769
|
+
for (const part of manifest.parts) {
|
|
6770
|
+
const sizeKb = (part.byteSize / 1024).toFixed(1);
|
|
6771
|
+
lines.push(
|
|
6772
|
+
`| [${part.filename}](parts/${part.filename}) | ${part.fileCount} | ${sizeKb} KB | ${tableCell(part.layersCovered.join(", "))} |`
|
|
6773
|
+
);
|
|
6774
|
+
}
|
|
6775
|
+
} else {
|
|
6776
|
+
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
6777
|
+
}
|
|
6778
|
+
const readOrder = [];
|
|
6779
|
+
if (wrote("navigation") || wrote("projectTree")) {
|
|
6780
|
+
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
6781
|
+
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
6782
|
+
}
|
|
6783
|
+
if (wrote("parts")) {
|
|
6784
|
+
readOrder.push(
|
|
6785
|
+
`${readOrder.length + 1}. Open only the specific \`parts/part-XXX.md\` file holding the target modules.`
|
|
6786
|
+
);
|
|
6787
|
+
}
|
|
6788
|
+
if (wrote("manifest")) {
|
|
6789
|
+
readOrder.push(
|
|
6790
|
+
`${readOrder.length + 1}. Inspect \`manifest.json\` for precise dependency and AST symbol maps.`
|
|
6791
|
+
);
|
|
6792
|
+
}
|
|
6793
|
+
readOrder.push(
|
|
6794
|
+
`${readOrder.length + 1}. Check \`manifest.validation.status\` before trusting the snapshot; \`snapshot validate\` re-checks it against disk.`
|
|
6795
|
+
);
|
|
6796
|
+
lines.push("", "## AI Agent Ingestion Guide", "", ...readOrder, "");
|
|
6797
|
+
return lines.join("\n");
|
|
6798
|
+
}
|
|
6799
|
+
|
|
6800
|
+
// src/generator/tree.ts
|
|
6801
|
+
var MAX_TREE_LINES = 2e4;
|
|
6802
|
+
var MAX_TREE_DEPTH = 512;
|
|
6803
|
+
function childKeys(node) {
|
|
6804
|
+
return Array.from(node.children.keys()).sort((a, b) => {
|
|
6805
|
+
const aIsDir = node.children.get(a).children.size > 0;
|
|
5895
6806
|
const bIsDir = node.children.get(b).children.size > 0;
|
|
5896
6807
|
if (aIsDir !== bIsDir) return aIsDir ? -1 : 1;
|
|
5897
6808
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -5969,7 +6880,18 @@ function gitPaths(cwd, args) {
|
|
|
5969
6880
|
`Could not list changed files (git ${args.join(" ")}): ${reason}. A changed-files snapshot needs a git working tree and a ref that exists; run \`codebase-snapshot generate\` without --changed-since to scan everything.`
|
|
5970
6881
|
);
|
|
5971
6882
|
}
|
|
5972
|
-
return output.split("\0").
|
|
6883
|
+
return output.split("\0").filter((entry) => entry.length > 0);
|
|
6884
|
+
}
|
|
6885
|
+
function readStagedBlob(cwd, relativePath) {
|
|
6886
|
+
try {
|
|
6887
|
+
return childProcess.execFileSync("git", ["cat-file", "blob", `:${relativePath}`], {
|
|
6888
|
+
cwd,
|
|
6889
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
6890
|
+
maxBuffer: 512 * 1024 * 1024
|
|
6891
|
+
});
|
|
6892
|
+
} catch {
|
|
6893
|
+
return null;
|
|
6894
|
+
}
|
|
5973
6895
|
}
|
|
5974
6896
|
function assertUsableRef(ref) {
|
|
5975
6897
|
if (ref.startsWith("-")) {
|
|
@@ -5980,6 +6902,8 @@ function assertUsableRef(ref) {
|
|
|
5980
6902
|
}
|
|
5981
6903
|
function resolveChangedScope(cwd, request) {
|
|
5982
6904
|
const paths = /* @__PURE__ */ new Set();
|
|
6905
|
+
const stagedPaths = /* @__PURE__ */ new Set();
|
|
6906
|
+
const deletedPaths = /* @__PURE__ */ new Set();
|
|
5983
6907
|
const descriptions = [];
|
|
5984
6908
|
if (request.changedSince !== void 0) {
|
|
5985
6909
|
assertUsableRef(request.changedSince);
|
|
@@ -5988,7 +6912,17 @@ function resolveChangedScope(cwd, request) {
|
|
|
5988
6912
|
"--name-only",
|
|
5989
6913
|
"-z",
|
|
5990
6914
|
"--relative",
|
|
5991
|
-
request.changedSince
|
|
6915
|
+
`${request.changedSince}...HEAD`,
|
|
6916
|
+
"--"
|
|
6917
|
+
])) {
|
|
6918
|
+
paths.add(path14);
|
|
6919
|
+
}
|
|
6920
|
+
for (const path14 of gitPaths(cwd, [
|
|
6921
|
+
"diff",
|
|
6922
|
+
"--name-only",
|
|
6923
|
+
"-z",
|
|
6924
|
+
"--relative",
|
|
6925
|
+
"HEAD",
|
|
5992
6926
|
"--"
|
|
5993
6927
|
])) {
|
|
5994
6928
|
paths.add(path14);
|
|
@@ -6008,10 +6942,22 @@ function resolveChangedScope(cwd, request) {
|
|
|
6008
6942
|
"--"
|
|
6009
6943
|
])) {
|
|
6010
6944
|
paths.add(path14);
|
|
6945
|
+
stagedPaths.add(path14);
|
|
6946
|
+
}
|
|
6947
|
+
for (const path14 of gitPaths(cwd, [
|
|
6948
|
+
"diff",
|
|
6949
|
+
"--cached",
|
|
6950
|
+
"--name-only",
|
|
6951
|
+
"-z",
|
|
6952
|
+
"--relative",
|
|
6953
|
+
"--diff-filter=D",
|
|
6954
|
+
"--"
|
|
6955
|
+
])) {
|
|
6956
|
+
deletedPaths.add(path14);
|
|
6011
6957
|
}
|
|
6012
6958
|
descriptions.push("staged");
|
|
6013
6959
|
}
|
|
6014
|
-
return { paths, detail: descriptions.join(" and ") };
|
|
6960
|
+
return { paths, stagedPaths, deletedPaths, detail: descriptions.join(" and ") };
|
|
6015
6961
|
}
|
|
6016
6962
|
var RELATIVE_SPECIFIER = /^\.{1,2}\//;
|
|
6017
6963
|
var IMPORT_CANDIDATE_SUFFIXES = [
|
|
@@ -6042,34 +6988,88 @@ var PYTHON_EXTENSIONS = /* @__PURE__ */ new Set([".py", ".pyi"]);
|
|
|
6042
6988
|
var RUBY_EXTENSIONS = /* @__PURE__ */ new Set([".rb", ".rake", ".gemspec"]);
|
|
6043
6989
|
var C_EXTENSIONS = /* @__PURE__ */ new Set([".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hxx", ".m", ".mm"]);
|
|
6044
6990
|
var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
6045
|
-
|
|
6991
|
+
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
6992
|
+
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
6993
|
+
function tsconfigPathsFor(cwd) {
|
|
6994
|
+
const configPath = path10__namespace.join(cwd, "tsconfig.json");
|
|
6995
|
+
let stats;
|
|
6996
|
+
try {
|
|
6997
|
+
stats = fs9__namespace.statSync(configPath);
|
|
6998
|
+
} catch (err) {
|
|
6999
|
+
if (err.code === "ENOENT") return null;
|
|
7000
|
+
return null;
|
|
7001
|
+
}
|
|
7002
|
+
const key = `${stats.mtimeMs}:${stats.size}`;
|
|
7003
|
+
const cached = TSCONFIG_CACHE.get(configPath);
|
|
7004
|
+
if (cached !== void 0 && cached.key === key) return cached.value;
|
|
7005
|
+
let value = null;
|
|
7006
|
+
try {
|
|
7007
|
+
const read = ts__default.default.readConfigFile(configPath, ts__default.default.sys.readFile);
|
|
7008
|
+
if (read.error === void 0) {
|
|
7009
|
+
const parsed = ts__default.default.parseJsonConfigFileContent(read.config, ts__default.default.sys, cwd, void 0, configPath);
|
|
7010
|
+
const options = parsed.options;
|
|
7011
|
+
const baseUrl = typeof options.baseUrl === "string" ? repositoryRelative(cwd, options.baseUrl) : null;
|
|
7012
|
+
const rules = [];
|
|
7013
|
+
if (options.paths !== void 0) {
|
|
7014
|
+
for (const [pattern, targets] of Object.entries(options.paths)) {
|
|
7015
|
+
if (!Array.isArray(targets)) continue;
|
|
7016
|
+
rules.push({
|
|
7017
|
+
pattern,
|
|
7018
|
+
targets: targets.map((target) => String(target).replace(/\\/g, "/"))
|
|
7019
|
+
});
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
7022
|
+
if (baseUrl !== null || rules.length > 0) value = { baseUrl, paths: rules };
|
|
7023
|
+
}
|
|
7024
|
+
} catch (err) {
|
|
7025
|
+
value = null;
|
|
7026
|
+
}
|
|
7027
|
+
TSCONFIG_CACHE.set(configPath, { key, value });
|
|
7028
|
+
return value;
|
|
7029
|
+
}
|
|
7030
|
+
function repositoryRelative(cwd, target) {
|
|
7031
|
+
const relative9 = path10__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
7032
|
+
return relative9.length === 0 || !relative9.startsWith("..") && !path10__namespace.isAbsolute(relative9) ? relative9 : null;
|
|
7033
|
+
}
|
|
7034
|
+
function rememberFirst(map, key, value) {
|
|
7035
|
+
if (!map.has(key)) map.set(key, value);
|
|
7036
|
+
}
|
|
7037
|
+
function buildImportResolver(files, options = {}) {
|
|
6046
7038
|
const byPath = /* @__PURE__ */ new Map();
|
|
6047
7039
|
const byPathFolded = /* @__PURE__ */ new Map();
|
|
6048
7040
|
const byStem = /* @__PURE__ */ new Map();
|
|
6049
7041
|
const byStemFolded = /* @__PURE__ */ new Map();
|
|
6050
|
-
const
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
remember(byPath, relativePath, relativePath);
|
|
6056
|
-
remember(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
7042
|
+
const register = (relativePath) => {
|
|
7043
|
+
rememberFirst(byPath, relativePath, relativePath);
|
|
7044
|
+
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7045
|
+
rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
7046
|
+
}
|
|
6057
7047
|
const extension = path10__namespace.posix.extname(relativePath);
|
|
6058
|
-
if (!SOURCE_EXTENSIONS.has(extension))
|
|
7048
|
+
if (!SOURCE_EXTENSIONS.has(extension)) return;
|
|
6059
7049
|
const stem = relativePath.slice(0, -extension.length);
|
|
6060
|
-
|
|
6061
|
-
|
|
7050
|
+
rememberFirst(byStem, stem, relativePath);
|
|
7051
|
+
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7052
|
+
rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
|
|
7053
|
+
}
|
|
6062
7054
|
if (path10__namespace.posix.basename(stem) === "index") {
|
|
6063
7055
|
const directory = path10__namespace.posix.dirname(stem);
|
|
6064
|
-
|
|
6065
|
-
|
|
7056
|
+
rememberFirst(byStem, directory, relativePath);
|
|
7057
|
+
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7058
|
+
rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
|
|
7059
|
+
}
|
|
7060
|
+
}
|
|
7061
|
+
};
|
|
7062
|
+
for (const file of files) register(file.relativePath);
|
|
7063
|
+
if (options.extraPaths !== void 0) {
|
|
7064
|
+
for (const extra of options.extraPaths) {
|
|
7065
|
+
if (!byPath.has(extra)) register(extra);
|
|
6066
7066
|
}
|
|
6067
7067
|
}
|
|
6068
|
-
return { byPath, byPathFolded, byStem, byStemFolded };
|
|
7068
|
+
return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
|
|
6069
7069
|
}
|
|
6070
7070
|
function resolveSpecifier(fromFile, specifier, resolver) {
|
|
6071
7071
|
const extension = path10__namespace.posix.extname(fromFile).toLowerCase();
|
|
6072
|
-
const exact = (key) => resolver.byPath.get(key) ?? resolver.byPathFolded.get(key.toLowerCase()) ?? null;
|
|
7072
|
+
const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
6073
7073
|
const firstOf = (candidates) => {
|
|
6074
7074
|
for (const candidate of candidates) {
|
|
6075
7075
|
const hit = exact(candidate);
|
|
@@ -6077,6 +7077,17 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
6077
7077
|
}
|
|
6078
7078
|
return null;
|
|
6079
7079
|
};
|
|
7080
|
+
const lookupPath = (joined2) => {
|
|
7081
|
+
const direct = exact(joined2);
|
|
7082
|
+
if (direct) return direct;
|
|
7083
|
+
for (const suffix of IMPORT_CANDIDATE_SUFFIXES) {
|
|
7084
|
+
const hit = exact(`${joined2}${suffix}`);
|
|
7085
|
+
if (hit) return hit;
|
|
7086
|
+
}
|
|
7087
|
+
const stem = joined2.replace(/\.(?:js|mjs|cjs|jsx)$/, "");
|
|
7088
|
+
const byStem = (key) => resolver.byStem.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byStemFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
7089
|
+
return byStem(joined2) ?? byStem(stem);
|
|
7090
|
+
};
|
|
6080
7091
|
if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
|
|
6081
7092
|
const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
|
|
6082
7093
|
const rest = specifier.slice(dots).replace(/\./g, "/");
|
|
@@ -6103,19 +7114,43 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
6103
7114
|
);
|
|
6104
7115
|
return firstOf([joined2, `${joined2}.dart`]);
|
|
6105
7116
|
}
|
|
6106
|
-
if (!RELATIVE_SPECIFIER.test(specifier))
|
|
7117
|
+
if (!RELATIVE_SPECIFIER.test(specifier)) {
|
|
7118
|
+
return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
|
|
7119
|
+
}
|
|
6107
7120
|
const joined = path10__namespace.posix.normalize(
|
|
6108
7121
|
path10__namespace.posix.join(path10__namespace.posix.dirname(fromFile), specifier)
|
|
6109
7122
|
);
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
7123
|
+
return lookupPath(joined);
|
|
7124
|
+
}
|
|
7125
|
+
function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
|
|
7126
|
+
const config = resolver.tsconfig;
|
|
7127
|
+
if (!config) return null;
|
|
7128
|
+
for (const rule of config.paths) {
|
|
7129
|
+
const star = rule.pattern.indexOf("*");
|
|
7130
|
+
let captured;
|
|
7131
|
+
if (star === -1) {
|
|
7132
|
+
captured = specifier === rule.pattern ? "" : null;
|
|
7133
|
+
} else {
|
|
7134
|
+
const prefix = rule.pattern.slice(0, star);
|
|
7135
|
+
const suffix = rule.pattern.slice(star + 1);
|
|
7136
|
+
if (specifier.length < prefix.length + suffix.length || !specifier.startsWith(prefix) || !specifier.endsWith(suffix)) {
|
|
7137
|
+
captured = null;
|
|
7138
|
+
} else {
|
|
7139
|
+
captured = specifier.slice(prefix.length, specifier.length - suffix.length);
|
|
7140
|
+
}
|
|
7141
|
+
}
|
|
7142
|
+
if (captured === null) continue;
|
|
7143
|
+
for (const target of rule.targets) {
|
|
7144
|
+
const substituted = target.split("*").join(captured);
|
|
7145
|
+
const base = config.baseUrl === null ? substituted : path10__namespace.posix.join(config.baseUrl, substituted);
|
|
7146
|
+
const hit = lookupPath(path10__namespace.posix.normalize(base));
|
|
7147
|
+
if (hit) return hit;
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
if (config.baseUrl !== null) {
|
|
7151
|
+
return lookupPath(path10__namespace.posix.normalize(path10__namespace.posix.join(config.baseUrl, specifier)));
|
|
6115
7152
|
}
|
|
6116
|
-
|
|
6117
|
-
const byStem = (key) => resolver.byStem.get(key) ?? resolver.byStemFolded.get(key.toLowerCase()) ?? null;
|
|
6118
|
-
return byStem(joined) ?? byStem(stem);
|
|
7153
|
+
return null;
|
|
6119
7154
|
}
|
|
6120
7155
|
function importsChangedFile(importerPath, imports, changedPaths, resolver) {
|
|
6121
7156
|
for (const specifier of imports) {
|
|
@@ -6204,7 +7239,7 @@ function findStagingDirectory(config) {
|
|
|
6204
7239
|
const tmpDir = path10__namespace.resolve(config.cwd, config.tmpDir);
|
|
6205
7240
|
let entries;
|
|
6206
7241
|
try {
|
|
6207
|
-
entries =
|
|
7242
|
+
entries = fs9__namespace.readdirSync(tmpDir);
|
|
6208
7243
|
} catch {
|
|
6209
7244
|
return null;
|
|
6210
7245
|
}
|
|
@@ -6217,8 +7252,8 @@ function describeMissingManifest(config, manifestPath) {
|
|
|
6217
7252
|
const markerPath = path10__namespace.join(outDir, ".codebase-snapshot");
|
|
6218
7253
|
let marker = null;
|
|
6219
7254
|
try {
|
|
6220
|
-
if (
|
|
6221
|
-
const parsed = JSON.parse(
|
|
7255
|
+
if (fs9__namespace.existsSync(markerPath)) {
|
|
7256
|
+
const parsed = JSON.parse(fs9__namespace.readFileSync(markerPath, "utf8"));
|
|
6222
7257
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
6223
7258
|
marker = parsed;
|
|
6224
7259
|
}
|
|
@@ -6255,11 +7290,11 @@ function sha256Hex(buffer) {
|
|
|
6255
7290
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
6256
7291
|
const absolutePath = path10__namespace.join(cwd, relativePath);
|
|
6257
7292
|
try {
|
|
6258
|
-
const stats =
|
|
7293
|
+
const stats = fs9__namespace.statSync(absolutePath);
|
|
6259
7294
|
if (!stats.isFile()) return false;
|
|
6260
7295
|
if (isBinaryExtension(absolutePath)) return false;
|
|
6261
7296
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
6262
|
-
return !decodeText(
|
|
7297
|
+
return !decodeText(fs9__namespace.readFileSync(absolutePath)).binary;
|
|
6263
7298
|
} catch {
|
|
6264
7299
|
return false;
|
|
6265
7300
|
}
|
|
@@ -6290,14 +7325,71 @@ function describeManifestShapeProblem(value) {
|
|
|
6290
7325
|
if (!candidate.totals || typeof candidate.totals !== "object" || Array.isArray(candidate.totals)) {
|
|
6291
7326
|
return 'missing "totals" object';
|
|
6292
7327
|
}
|
|
7328
|
+
const currentSchema = candidate.schemaVersion === SCHEMA_VERSION;
|
|
7329
|
+
if (currentSchema) {
|
|
7330
|
+
const generator = candidate.generator;
|
|
7331
|
+
if (!generator || typeof generator !== "object" || Array.isArray(generator)) {
|
|
7332
|
+
return 'missing "generator" object';
|
|
7333
|
+
}
|
|
7334
|
+
const generatorFields = generator;
|
|
7335
|
+
if (!isOurGeneratorName(generatorFields.name)) {
|
|
7336
|
+
return "`generator.name` is not this generator";
|
|
7337
|
+
}
|
|
7338
|
+
if (typeof generatorFields.version !== "string" || generatorFields.version.trim() === "") {
|
|
7339
|
+
return "`generator.version` must be a non-empty string";
|
|
7340
|
+
}
|
|
7341
|
+
const git = candidate.git;
|
|
7342
|
+
if (!git || typeof git !== "object" || Array.isArray(git)) return 'missing "git" object';
|
|
7343
|
+
const gitFields = git;
|
|
7344
|
+
if (typeof gitFields.branch !== "string") return "`git.branch` must be a string";
|
|
7345
|
+
if (typeof gitFields.commit !== "string") return "`git.commit` must be a string";
|
|
7346
|
+
if (typeof gitFields.isDirty !== "boolean") return "`git.isDirty` must be a boolean";
|
|
7347
|
+
const config = candidate.config;
|
|
7348
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
7349
|
+
return 'missing "config" object';
|
|
7350
|
+
}
|
|
7351
|
+
const budgets = candidate.budgets;
|
|
7352
|
+
if (!budgets || typeof budgets !== "object" || Array.isArray(budgets)) {
|
|
7353
|
+
return 'missing "budgets" object';
|
|
7354
|
+
}
|
|
7355
|
+
for (const key of ["maxPartBytes", "largeFileBytes"]) {
|
|
7356
|
+
const value2 = budgets[key];
|
|
7357
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
7358
|
+
return `\`budgets.${key}\` must be a non-negative integer`;
|
|
7359
|
+
}
|
|
7360
|
+
}
|
|
7361
|
+
if (!candidate.indexes || typeof candidate.indexes !== "object" || Array.isArray(candidate.indexes)) {
|
|
7362
|
+
return 'missing "indexes" object';
|
|
7363
|
+
}
|
|
7364
|
+
if (!candidate.kinds || typeof candidate.kinds !== "object" || Array.isArray(candidate.kinds)) {
|
|
7365
|
+
return 'missing "kinds" object';
|
|
7366
|
+
}
|
|
7367
|
+
}
|
|
6293
7368
|
if (!Array.isArray(candidate.files)) return 'missing "files" array';
|
|
6294
7369
|
for (const entry of candidate.files) {
|
|
6295
7370
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6296
7371
|
return 'a "files" entry is not an object';
|
|
6297
7372
|
}
|
|
6298
|
-
|
|
7373
|
+
const fields = entry;
|
|
7374
|
+
if (typeof fields.relativePath !== "string") {
|
|
6299
7375
|
return 'a "files" entry has no "relativePath"';
|
|
6300
7376
|
}
|
|
7377
|
+
if (!currentSchema) continue;
|
|
7378
|
+
if (typeof fields.part !== "string" || fields.part.length === 0) {
|
|
7379
|
+
return 'a "files" entry records no "part"';
|
|
7380
|
+
}
|
|
7381
|
+
if (typeof fields.hashSha256 !== "string" || !/^[0-9a-f]{64}$/.test(fields.hashSha256)) {
|
|
7382
|
+
return 'a "files" entry "hashSha256" must be a 64-character lowercase sha256 hex digest';
|
|
7383
|
+
}
|
|
7384
|
+
for (const key of ["sizeBytes", "lines"]) {
|
|
7385
|
+
const value2 = fields[key];
|
|
7386
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 0) {
|
|
7387
|
+
return `a "files" entry "${key}" must be a non-negative integer`;
|
|
7388
|
+
}
|
|
7389
|
+
}
|
|
7390
|
+
if (!["full", "preview", "signatures"].includes(String(fields.inclusionMode))) {
|
|
7391
|
+
return 'a "files" entry has an unknown "inclusionMode"';
|
|
7392
|
+
}
|
|
6301
7393
|
}
|
|
6302
7394
|
if (!Array.isArray(candidate.skipped)) return 'missing "skipped" array';
|
|
6303
7395
|
if (!Array.isArray(candidate.parts)) return 'missing "parts" array';
|
|
@@ -6305,13 +7397,28 @@ function describeManifestShapeProblem(value) {
|
|
|
6305
7397
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6306
7398
|
return 'a "parts" entry is not an object';
|
|
6307
7399
|
}
|
|
6308
|
-
const
|
|
7400
|
+
const fields = entry;
|
|
7401
|
+
const filename = fields.filename;
|
|
6309
7402
|
if (typeof filename !== "string" || filename.trim() === "") {
|
|
6310
7403
|
return 'a "parts" entry has no "filename"';
|
|
6311
7404
|
}
|
|
6312
7405
|
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path10__namespace.isAbsolute(filename)) {
|
|
6313
7406
|
return 'a "parts" entry "filename" must be a bare filename inside parts/';
|
|
6314
7407
|
}
|
|
7408
|
+
if (currentSchema) {
|
|
7409
|
+
if (typeof fields.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(fields.sha256)) {
|
|
7410
|
+
return 'a "parts" entry "sha256" must be a 64-character lowercase sha256 hex digest';
|
|
7411
|
+
}
|
|
7412
|
+
if (typeof fields.byteSize !== "number" || !Number.isSafeInteger(fields.byteSize) || fields.byteSize < 0) {
|
|
7413
|
+
return 'a "parts" entry "byteSize" must be a non-negative integer';
|
|
7414
|
+
}
|
|
7415
|
+
if (typeof fields.index !== "number" || !Number.isSafeInteger(fields.index) || fields.index < 1) {
|
|
7416
|
+
return 'a "parts" entry "index" must be a positive integer';
|
|
7417
|
+
}
|
|
7418
|
+
if (!Array.isArray(fields.includedFiles)) {
|
|
7419
|
+
return 'a "parts" entry has no "includedFiles" array';
|
|
7420
|
+
}
|
|
7421
|
+
}
|
|
6315
7422
|
}
|
|
6316
7423
|
if (!candidate.layers || typeof candidate.layers !== "object" || Array.isArray(candidate.layers)) {
|
|
6317
7424
|
return 'missing "layers" object';
|
|
@@ -6322,7 +7429,7 @@ function validateSnapshot(configInput) {
|
|
|
6322
7429
|
assertUsableConfigInput(configInput);
|
|
6323
7430
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
6324
7431
|
const manifestPath = path10__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
6325
|
-
if (!
|
|
7432
|
+
if (!fs9__namespace.existsSync(manifestPath)) {
|
|
6326
7433
|
return {
|
|
6327
7434
|
valid: false,
|
|
6328
7435
|
manifestPresent: false,
|
|
@@ -6333,7 +7440,7 @@ function validateSnapshot(configInput) {
|
|
|
6333
7440
|
}
|
|
6334
7441
|
let manifest;
|
|
6335
7442
|
try {
|
|
6336
|
-
manifest = JSON.parse(
|
|
7443
|
+
manifest = JSON.parse(fs9__namespace.readFileSync(manifestPath, "utf8"));
|
|
6337
7444
|
} catch (err) {
|
|
6338
7445
|
return {
|
|
6339
7446
|
valid: false,
|
|
@@ -6356,6 +7463,19 @@ function validateSnapshot(configInput) {
|
|
|
6356
7463
|
const drift = emptyDrift();
|
|
6357
7464
|
const warnings = [];
|
|
6358
7465
|
const snapshotDir = path10__namespace.resolve(config.cwd, config.outDir);
|
|
7466
|
+
const unreadableSkips = manifest.skipped.filter(
|
|
7467
|
+
(entry) => entry.reason === "missing" || entry.reason === "read-error"
|
|
7468
|
+
);
|
|
7469
|
+
if (unreadableSkips.length > 0) {
|
|
7470
|
+
warnings.push(
|
|
7471
|
+
`${unreadableSkips.length} path(s) could not be read when this snapshot was generated (see manifest.skipped[] with reason "missing" or "read-error"); they are not in the snapshot.`
|
|
7472
|
+
);
|
|
7473
|
+
}
|
|
7474
|
+
if ([...config.layers, ...config.kinds].some((rule) => typeof rule.match === "function")) {
|
|
7475
|
+
warnings.push(
|
|
7476
|
+
"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."
|
|
7477
|
+
);
|
|
7478
|
+
}
|
|
6359
7479
|
const manifestFileMap = /* @__PURE__ */ new Map();
|
|
6360
7480
|
for (const file of manifest.files) {
|
|
6361
7481
|
if (file && typeof file.relativePath === "string") {
|
|
@@ -6418,7 +7538,7 @@ function validateSnapshot(configInput) {
|
|
|
6418
7538
|
// snapshot was reported as drifting.
|
|
6419
7539
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6420
7540
|
(directory) => path10__namespace.relative(config.cwd, path10__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6421
|
-
).filter((
|
|
7541
|
+
).filter((relative9) => relative9.length > 0 && !relative9.startsWith(".."))
|
|
6422
7542
|
});
|
|
6423
7543
|
for (const diskFile of collection.files) {
|
|
6424
7544
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -6443,7 +7563,7 @@ function validateSnapshot(configInput) {
|
|
|
6443
7563
|
}
|
|
6444
7564
|
let diskHash;
|
|
6445
7565
|
try {
|
|
6446
|
-
diskHash = sha256Hex(
|
|
7566
|
+
diskHash = sha256Hex(fs9__namespace.readFileSync(path10__namespace.join(config.cwd, diskFile)));
|
|
6447
7567
|
} catch (err) {
|
|
6448
7568
|
if (err.code === "ENOENT") {
|
|
6449
7569
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -6467,7 +7587,7 @@ function validateSnapshot(configInput) {
|
|
|
6467
7587
|
}
|
|
6468
7588
|
let statFailure = null;
|
|
6469
7589
|
try {
|
|
6470
|
-
|
|
7590
|
+
fs9__namespace.statSync(confined);
|
|
6471
7591
|
} catch (err) {
|
|
6472
7592
|
statFailure = err;
|
|
6473
7593
|
}
|
|
@@ -6502,7 +7622,7 @@ function validateSnapshot(configInput) {
|
|
|
6502
7622
|
}
|
|
6503
7623
|
let buffer;
|
|
6504
7624
|
try {
|
|
6505
|
-
buffer =
|
|
7625
|
+
buffer = fs9__namespace.readFileSync(partPath);
|
|
6506
7626
|
} catch {
|
|
6507
7627
|
drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
|
|
6508
7628
|
continue;
|
|
@@ -6524,24 +7644,85 @@ function validateSnapshot(configInput) {
|
|
|
6524
7644
|
});
|
|
6525
7645
|
}
|
|
6526
7646
|
}
|
|
6527
|
-
const
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
)
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
7647
|
+
const maskDriftPath = (value) => findSecretInPath(value, config.secretRules)?.masked ?? value;
|
|
7648
|
+
const includedByPart = /* @__PURE__ */ new Map();
|
|
7649
|
+
const partIndexes = /* @__PURE__ */ new Set();
|
|
7650
|
+
for (const part of manifest.parts) {
|
|
7651
|
+
if (includedByPart.has(part.filename)) {
|
|
7652
|
+
drift.partIssues.push({
|
|
7653
|
+
part: maskDriftPath(part.filename),
|
|
7654
|
+
issue: "appears more than once in parts[]"
|
|
7655
|
+
});
|
|
7656
|
+
}
|
|
7657
|
+
if (typeof part.index === "number") {
|
|
7658
|
+
if (partIndexes.has(part.index)) {
|
|
7659
|
+
drift.partIssues.push({
|
|
7660
|
+
part: maskDriftPath(part.filename),
|
|
7661
|
+
issue: `reuses part index ${part.index}`
|
|
7662
|
+
});
|
|
7663
|
+
}
|
|
7664
|
+
partIndexes.add(part.index);
|
|
7665
|
+
}
|
|
7666
|
+
const listed = /* @__PURE__ */ new Set();
|
|
7667
|
+
for (const included of part.includedFiles ?? []) {
|
|
7668
|
+
if (typeof included?.relativePath !== "string") continue;
|
|
7669
|
+
if (listed.has(included.relativePath)) {
|
|
7670
|
+
drift.partIssues.push({
|
|
7671
|
+
part: maskDriftPath(part.filename),
|
|
7672
|
+
issue: `lists ${maskDriftPath(included.relativePath)} twice`
|
|
7673
|
+
});
|
|
7674
|
+
}
|
|
7675
|
+
listed.add(included.relativePath);
|
|
7676
|
+
}
|
|
7677
|
+
includedByPart.set(part.filename, listed);
|
|
7678
|
+
if (typeof part.fileCount === "number" && part.fileCount !== listed.size) {
|
|
7679
|
+
drift.partIssues.push({
|
|
7680
|
+
part: maskDriftPath(part.filename),
|
|
7681
|
+
issue: `declares ${part.fileCount} file(s) but lists ${listed.size} in includedFiles`
|
|
7682
|
+
});
|
|
7683
|
+
}
|
|
6536
7684
|
}
|
|
7685
|
+
const filePaths = /* @__PURE__ */ new Set();
|
|
6537
7686
|
for (const file of manifest.files) {
|
|
6538
|
-
if (
|
|
7687
|
+
if (filePaths.has(file.relativePath)) {
|
|
6539
7688
|
drift.partIssues.push({
|
|
6540
|
-
part:
|
|
6541
|
-
issue: `${file.relativePath}
|
|
7689
|
+
part: "(files)",
|
|
7690
|
+
issue: `${maskDriftPath(file.relativePath)} appears more than once in files[]`
|
|
7691
|
+
});
|
|
7692
|
+
continue;
|
|
7693
|
+
}
|
|
7694
|
+
filePaths.add(file.relativePath);
|
|
7695
|
+
if (typeof file.part !== "string" || file.part.length === 0) {
|
|
7696
|
+
drift.partIssues.push({
|
|
7697
|
+
part: "(files)",
|
|
7698
|
+
issue: `${maskDriftPath(file.relativePath)} records no part`
|
|
7699
|
+
});
|
|
7700
|
+
continue;
|
|
7701
|
+
}
|
|
7702
|
+
if (!partNames.has(file.part)) {
|
|
7703
|
+
drift.partIssues.push({
|
|
7704
|
+
part: maskDriftPath(file.part),
|
|
7705
|
+
issue: `${maskDriftPath(file.relativePath)} points at a part that is not in the manifest`
|
|
7706
|
+
});
|
|
7707
|
+
continue;
|
|
7708
|
+
}
|
|
7709
|
+
if (!includedByPart.get(file.part)?.has(file.relativePath)) {
|
|
7710
|
+
drift.partIssues.push({
|
|
7711
|
+
part: maskDriftPath(file.part),
|
|
7712
|
+
issue: `${maskDriftPath(file.relativePath)} is not listed in that part's includedFiles`
|
|
6542
7713
|
});
|
|
6543
7714
|
}
|
|
6544
7715
|
}
|
|
7716
|
+
for (const [partName, listed] of includedByPart) {
|
|
7717
|
+
for (const relativePath of listed) {
|
|
7718
|
+
if (!filePaths.has(relativePath)) {
|
|
7719
|
+
drift.partIssues.push({
|
|
7720
|
+
part: maskDriftPath(partName),
|
|
7721
|
+
issue: `lists ${maskDriftPath(relativePath)}, which the manifest does not`
|
|
7722
|
+
});
|
|
7723
|
+
}
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
6545
7726
|
const maskValue = (value) => findSecretInPath(value, config.secretRules)?.masked ?? value;
|
|
6546
7727
|
const currentExcludes = config.excludePatterns.map(maskValue);
|
|
6547
7728
|
const currentInclude = config.include.map(maskValue);
|
|
@@ -6697,6 +7878,13 @@ function validateSnapshot(configInput) {
|
|
|
6697
7878
|
0
|
|
6698
7879
|
);
|
|
6699
7880
|
expectEqual("counts.totalFiles", counts.totalFiles, manifest.files.length);
|
|
7881
|
+
if (manifest.files.every((file) => typeof file?.lines === "number")) {
|
|
7882
|
+
expectEqual(
|
|
7883
|
+
"counts.totalLines",
|
|
7884
|
+
counts.totalLines,
|
|
7885
|
+
manifest.files.reduce((total, file) => total + file.lines, 0)
|
|
7886
|
+
);
|
|
7887
|
+
}
|
|
6700
7888
|
expectEqual("counts.partsCount", counts.partsCount, manifest.parts.length);
|
|
6701
7889
|
expectEqual("counts.skippedCount", counts.skippedCount, manifest.skipped.length);
|
|
6702
7890
|
expectEqual("counts.totalSizeBytes", counts.totalSizeBytes, sumSourceBytes);
|
|
@@ -6720,6 +7908,37 @@ function validateSnapshot(configInput) {
|
|
|
6720
7908
|
`totals.fullFiles + previewFiles (${totals.fullFiles} + ${totals.previewFiles}) != ${manifest.files.length} files`
|
|
6721
7909
|
);
|
|
6722
7910
|
}
|
|
7911
|
+
const recordedSettingsDigest = manifest.config && typeof manifest.config.digest === "string" ? manifest.config.digest : null;
|
|
7912
|
+
if (recordedSettingsDigest !== null && manifest.files.every((file) => typeof file?.hashSha256 === "string")) {
|
|
7913
|
+
const settingsLine = `settings:${recordedSettingsDigest}`;
|
|
7914
|
+
const currentDefinition = sha256Hex(
|
|
7915
|
+
Buffer.from(
|
|
7916
|
+
[
|
|
7917
|
+
...manifest.files.map(
|
|
7918
|
+
(file) => `${file.relativePath}:${file.hashSha256}:${file.sizeBytes}`
|
|
7919
|
+
),
|
|
7920
|
+
settingsLine
|
|
7921
|
+
].join("\n"),
|
|
7922
|
+
"utf8"
|
|
7923
|
+
)
|
|
7924
|
+
);
|
|
7925
|
+
const legacyDefinition = sha256Hex(
|
|
7926
|
+
Buffer.from(
|
|
7927
|
+
[
|
|
7928
|
+
...manifest.files.map(
|
|
7929
|
+
(file) => `${file.relativePath}:${file.hashSha256}:${file.sizeBytes}:${file.inclusionMode}`
|
|
7930
|
+
),
|
|
7931
|
+
settingsLine
|
|
7932
|
+
].join("\n"),
|
|
7933
|
+
"utf8"
|
|
7934
|
+
)
|
|
7935
|
+
);
|
|
7936
|
+
if (manifest.fingerprint !== currentDefinition && manifest.fingerprint !== legacyDefinition) {
|
|
7937
|
+
totalsMismatches.push(
|
|
7938
|
+
"fingerprint: does not match the files and settings recorded in this manifest"
|
|
7939
|
+
);
|
|
7940
|
+
}
|
|
7941
|
+
}
|
|
6723
7942
|
if (manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
6724
7943
|
totalsMismatches.push(
|
|
6725
7944
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
@@ -6747,26 +7966,49 @@ function validateSnapshot(configInput) {
|
|
|
6747
7966
|
drift.configMismatches.push(`manifest declared itself invalid: ${error}`);
|
|
6748
7967
|
}
|
|
6749
7968
|
}
|
|
6750
|
-
|
|
7969
|
+
const declaredArtifacts = [
|
|
7970
|
+
["README.md", manifest.artifacts?.readme],
|
|
7971
|
+
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
7972
|
+
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
7973
|
+
["reports/audit.md", manifest.artifacts?.audit],
|
|
6751
7974
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
6752
7975
|
["full-codebase.md", manifest.artifacts?.fullMarkdown]
|
|
6753
|
-
]
|
|
7976
|
+
];
|
|
7977
|
+
for (const [key, artifact] of declaredArtifacts) {
|
|
6754
7978
|
if (!artifact) continue;
|
|
6755
|
-
const artifactPath = path10__namespace.join(snapshotDir, key);
|
|
7979
|
+
const artifactPath = path10__namespace.join(snapshotDir, ...key.split("/"));
|
|
7980
|
+
let buffer;
|
|
6756
7981
|
try {
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
drift.partIssues.push({ part: key, issue: "artifact does not match its recorded digest" });
|
|
6760
|
-
}
|
|
7982
|
+
if (!fs9__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
|
|
7983
|
+
buffer = fs9__namespace.readFileSync(artifactPath);
|
|
6761
7984
|
} catch {
|
|
6762
7985
|
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
7986
|
+
continue;
|
|
7987
|
+
}
|
|
7988
|
+
if (sha256Hex(buffer) !== artifact.sha256 || buffer.length !== artifact.byteSize) {
|
|
7989
|
+
drift.partIssues.push({ part: key, issue: "artifact does not match its recorded digest" });
|
|
7990
|
+
continue;
|
|
7991
|
+
}
|
|
7992
|
+
if (key === "reports/navigation.md") {
|
|
7993
|
+
for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
7994
|
+
const target = match[1].split("#")[0];
|
|
7995
|
+
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7996
|
+
const resolved = path10__namespace.resolve(snapshotDir, "reports", target);
|
|
7997
|
+
const relative9 = path10__namespace.relative(snapshotDir, resolved);
|
|
7998
|
+
if (relative9.startsWith("..") || path10__namespace.isAbsolute(relative9) || !fs9__namespace.existsSync(resolved)) {
|
|
7999
|
+
drift.partIssues.push({
|
|
8000
|
+
part: key,
|
|
8001
|
+
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
8002
|
+
});
|
|
8003
|
+
}
|
|
8004
|
+
}
|
|
6763
8005
|
}
|
|
6764
8006
|
}
|
|
6765
8007
|
const sarifArtifact = manifest.artifacts?.sarif;
|
|
6766
8008
|
if (sarifArtifact) {
|
|
6767
8009
|
const sarifKey = "reports/audit.sarif";
|
|
6768
8010
|
try {
|
|
6769
|
-
const buffer =
|
|
8011
|
+
const buffer = fs9__namespace.readFileSync(path10__namespace.join(snapshotDir, "reports", "audit.sarif"));
|
|
6770
8012
|
if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
|
|
6771
8013
|
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
6772
8014
|
}
|
|
@@ -6775,8 +8017,11 @@ function validateSnapshot(configInput) {
|
|
|
6775
8017
|
}
|
|
6776
8018
|
}
|
|
6777
8019
|
if (manifest.git && manifest.git.branch && manifest.git.branch !== config.branch) {
|
|
8020
|
+
const maskBranch = (value) => findSecretInPath(value, config.secretRules)?.masked ?? value;
|
|
8021
|
+
const generatedOn = maskBranch(manifest.git.branch);
|
|
8022
|
+
const configuredAs = maskBranch(config.branch);
|
|
6778
8023
|
warnings.push(
|
|
6779
|
-
`Snapshot was generated on branch "${
|
|
8024
|
+
`Snapshot was generated on branch "${generatedOn}" but the configured branch is "${configuredAs}".`
|
|
6780
8025
|
);
|
|
6781
8026
|
}
|
|
6782
8027
|
const errors = [];
|
|
@@ -6833,15 +8078,6 @@ function validateSnapshot(configInput) {
|
|
|
6833
8078
|
warnings
|
|
6834
8079
|
};
|
|
6835
8080
|
}
|
|
6836
|
-
|
|
6837
|
-
// src/version.ts
|
|
6838
|
-
var GENERATOR_NAME = "codebase-snapshot";
|
|
6839
|
-
var GENERATOR_VERSION = "0.9.15";
|
|
6840
|
-
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
6841
|
-
function isOurGeneratorName(name) {
|
|
6842
|
-
if (typeof name !== "string") return false;
|
|
6843
|
-
return name === GENERATOR_NAME || LEGACY_GENERATOR_NAMES.includes(name);
|
|
6844
|
-
}
|
|
6845
8081
|
function describeMatcher(matcher) {
|
|
6846
8082
|
if (typeof matcher === "string") return matcher;
|
|
6847
8083
|
if (matcher instanceof RegExp) return String(matcher);
|
|
@@ -6853,23 +8089,23 @@ function describeMatcher(matcher) {
|
|
|
6853
8089
|
function normalizeTarget(cwd, target) {
|
|
6854
8090
|
const resolvedCwd = path10__namespace.resolve(cwd);
|
|
6855
8091
|
const absolute = path10__namespace.resolve(resolvedCwd, target);
|
|
6856
|
-
const
|
|
6857
|
-
if (
|
|
8092
|
+
const relative9 = path10__namespace.relative(resolvedCwd, absolute);
|
|
8093
|
+
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${path10__namespace.sep}`) || path10__namespace.isAbsolute(relative9)) {
|
|
6858
8094
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
6859
8095
|
}
|
|
6860
|
-
return { relative:
|
|
8096
|
+
return { relative: relative9.split(path10__namespace.sep).join("/"), outsideRoot: false };
|
|
6861
8097
|
}
|
|
6862
8098
|
function findRuleMatch(rules, relativePath) {
|
|
6863
8099
|
return rules.find(
|
|
6864
8100
|
(rule) => matchRule(relativePath, rule.match)
|
|
6865
8101
|
);
|
|
6866
8102
|
}
|
|
6867
|
-
function findRecordedAncestor(skipped,
|
|
8103
|
+
function findRecordedAncestor(skipped, relative9, maskedPath2) {
|
|
6868
8104
|
let nearest;
|
|
6869
8105
|
for (const record of skipped) {
|
|
6870
8106
|
const ancestorPath = record.path;
|
|
6871
8107
|
if (ancestorPath.length === 0) continue;
|
|
6872
|
-
const isAncestor =
|
|
8108
|
+
const isAncestor = relative9.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
6873
8109
|
if (!isAncestor) continue;
|
|
6874
8110
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
6875
8111
|
}
|
|
@@ -6878,15 +8114,15 @@ function findRecordedAncestor(skipped, relative8, maskedPath2) {
|
|
|
6878
8114
|
function readManifest2(config) {
|
|
6879
8115
|
const manifestPath = path10__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
6880
8116
|
try {
|
|
6881
|
-
return JSON.parse(
|
|
8117
|
+
return JSON.parse(fs9__namespace.readFileSync(manifestPath, "utf8"));
|
|
6882
8118
|
} catch {
|
|
6883
8119
|
return null;
|
|
6884
8120
|
}
|
|
6885
8121
|
}
|
|
6886
8122
|
function explainPath(config, target) {
|
|
6887
8123
|
const normalized = normalizeTarget(config.cwd, target);
|
|
6888
|
-
const
|
|
6889
|
-
const maskedPath2 = findSecretInPath(
|
|
8124
|
+
const relative9 = normalized.relative;
|
|
8125
|
+
const maskedPath2 = findSecretInPath(relative9, config.secretRules)?.masked ?? relative9;
|
|
6890
8126
|
if (normalized.outsideRoot) {
|
|
6891
8127
|
return {
|
|
6892
8128
|
path: maskedPath2,
|
|
@@ -6896,10 +8132,10 @@ function explainPath(config, target) {
|
|
|
6896
8132
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
6897
8133
|
};
|
|
6898
8134
|
}
|
|
6899
|
-
const absolute = path10__namespace.join(config.cwd,
|
|
8135
|
+
const absolute = path10__namespace.join(config.cwd, relative9);
|
|
6900
8136
|
const result = {
|
|
6901
8137
|
path: maskedPath2,
|
|
6902
|
-
exists:
|
|
8138
|
+
exists: fs9__namespace.existsSync(absolute),
|
|
6903
8139
|
included: false
|
|
6904
8140
|
};
|
|
6905
8141
|
const collection = collectFiles(config.cwd, {
|
|
@@ -6914,11 +8150,11 @@ function explainPath(config, target) {
|
|
|
6914
8150
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
6915
8151
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6916
8152
|
(directory) => path10__namespace.relative(config.cwd, path10__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6917
|
-
).filter((
|
|
8153
|
+
).filter((relative10) => relative10.length > 0 && !relative10.startsWith(".."))
|
|
6918
8154
|
});
|
|
6919
|
-
if (!collection.files.includes(
|
|
8155
|
+
if (!collection.files.includes(relative9)) {
|
|
6920
8156
|
const record = collection.skipped.find(
|
|
6921
|
-
(entry2) => entry2.path ===
|
|
8157
|
+
(entry2) => entry2.path === relative9 || entry2.path === maskedPath2
|
|
6922
8158
|
);
|
|
6923
8159
|
if (record) {
|
|
6924
8160
|
result.reason = record.reason;
|
|
@@ -6927,7 +8163,7 @@ function explainPath(config, target) {
|
|
|
6927
8163
|
result.reason = "missing";
|
|
6928
8164
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
6929
8165
|
} else {
|
|
6930
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
8166
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative9, maskedPath2);
|
|
6931
8167
|
if (ancestor) {
|
|
6932
8168
|
result.reason = ancestor.reason;
|
|
6933
8169
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -6947,11 +8183,11 @@ function explainPath(config, target) {
|
|
|
6947
8183
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
6948
8184
|
...config.staged === true ? { staged: true } : {}
|
|
6949
8185
|
});
|
|
6950
|
-
inScope = scope.paths.has(
|
|
8186
|
+
inScope = scope.paths.has(relative9);
|
|
6951
8187
|
if (!inScope && config.withDependents === true) {
|
|
6952
8188
|
inScope = importsChangedFile(
|
|
6953
|
-
|
|
6954
|
-
importsOfFile(
|
|
8189
|
+
relative9,
|
|
8190
|
+
importsOfFile(relative9, absolute),
|
|
6955
8191
|
scope.paths,
|
|
6956
8192
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })))
|
|
6957
8193
|
);
|
|
@@ -6978,7 +8214,7 @@ function explainPath(config, target) {
|
|
|
6978
8214
|
}
|
|
6979
8215
|
let sizeOnDisk = null;
|
|
6980
8216
|
try {
|
|
6981
|
-
sizeOnDisk =
|
|
8217
|
+
sizeOnDisk = fs9__namespace.statSync(absolute).size;
|
|
6982
8218
|
} catch {
|
|
6983
8219
|
sizeOnDisk = null;
|
|
6984
8220
|
}
|
|
@@ -6988,8 +8224,16 @@ function explainPath(config, target) {
|
|
|
6988
8224
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
6989
8225
|
return result;
|
|
6990
8226
|
}
|
|
6991
|
-
if (
|
|
6992
|
-
|
|
8227
|
+
if (fs9__namespace.existsSync(absolute) && fs9__namespace.statSync(absolute).isFile()) {
|
|
8228
|
+
let buffer;
|
|
8229
|
+
try {
|
|
8230
|
+
buffer = fs9__namespace.readFileSync(absolute);
|
|
8231
|
+
} catch (err) {
|
|
8232
|
+
result.included = false;
|
|
8233
|
+
result.reason = "read-error";
|
|
8234
|
+
result.detail = `${err.message} (explain could not read the file; generate records this as a skipped entry)`;
|
|
8235
|
+
return result;
|
|
8236
|
+
}
|
|
6993
8237
|
const decoded = decodeText(buffer);
|
|
6994
8238
|
if (decoded.binary) {
|
|
6995
8239
|
result.included = false;
|
|
@@ -7001,21 +8245,30 @@ function explainPath(config, target) {
|
|
|
7001
8245
|
result.bytes = buffer.length;
|
|
7002
8246
|
result.lines = countLines(text);
|
|
7003
8247
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
7004
|
-
const { findings } = scanAndRedactSecrets(text, config.secretRules,
|
|
8248
|
+
const { findings } = scanAndRedactSecrets(text, config.secretRules, relative9);
|
|
7005
8249
|
result.secretCount = findings.length;
|
|
7006
8250
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
8251
|
+
let inclusionMode = "full";
|
|
8252
|
+
if (config.skeleton === true && isSkeletonizable(relative9)) {
|
|
8253
|
+
const skeleton = skeletonizeTypeScript(text, relative9);
|
|
8254
|
+
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
8255
|
+
}
|
|
8256
|
+
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
8257
|
+
const preview = truncatePreview(text, config.previewHeadLines, config.previewTailLines);
|
|
8258
|
+
inclusionMode = preview.isTruncated ? "preview" : "full";
|
|
8259
|
+
}
|
|
8260
|
+
result.inclusionMode = inclusionMode;
|
|
7007
8261
|
}
|
|
7008
|
-
result.layer = classifyLayer(
|
|
7009
|
-
result.kind = classifyKind(
|
|
7010
|
-
result.language = detectLanguage(
|
|
7011
|
-
const layerRule = findRuleMatch(config.layers,
|
|
8262
|
+
result.layer = classifyLayer(relative9, config.layers);
|
|
8263
|
+
result.kind = classifyKind(relative9, config.kinds);
|
|
8264
|
+
result.language = detectLanguage(relative9);
|
|
8265
|
+
const layerRule = findRuleMatch(config.layers, relative9);
|
|
7012
8266
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
7013
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
8267
|
+
const kindRule = findRuleMatch(config.kinds, relative9);
|
|
7014
8268
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
7015
8269
|
const manifest = readManifest2(config);
|
|
7016
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
8270
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative9) : void 0;
|
|
7017
8271
|
result.part = entry?.part ?? null;
|
|
7018
|
-
result.inclusionMode = entry?.inclusionMode;
|
|
7019
8272
|
return result;
|
|
7020
8273
|
}
|
|
7021
8274
|
function renderExplainText(result) {
|
|
@@ -7133,7 +8386,6 @@ function generateInWorker(cwd, cliOptions) {
|
|
|
7133
8386
|
}
|
|
7134
8387
|
|
|
7135
8388
|
// src/index.ts
|
|
7136
|
-
var SCHEMA_VERSION = "3.0.0";
|
|
7137
8389
|
var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
7138
8390
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
7139
8391
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
@@ -7141,12 +8393,21 @@ var fileDerivationBytes = 0;
|
|
|
7141
8393
|
function takeDerivation(path14, hash, settings) {
|
|
7142
8394
|
const cached = FILE_DERIVATIONS.get(path14);
|
|
7143
8395
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
8396
|
+
FILE_DERIVATIONS.delete(path14);
|
|
8397
|
+
FILE_DERIVATIONS.set(path14, cached);
|
|
7144
8398
|
return cached;
|
|
7145
8399
|
}
|
|
7146
8400
|
function rememberDerivation(path14, hash, settings, derivation) {
|
|
7147
8401
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
7148
8402
|
const bytes = bodyBytes * 2 + 512;
|
|
7149
8403
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
8404
|
+
const previous = FILE_DERIVATIONS.get(path14);
|
|
8405
|
+
if (previous !== void 0) {
|
|
8406
|
+
FILE_DERIVATIONS.delete(path14);
|
|
8407
|
+
fileDerivationBytes -= previous.bytes;
|
|
8408
|
+
} else {
|
|
8409
|
+
FILE_DERIVATIONS.delete(path14);
|
|
8410
|
+
}
|
|
7150
8411
|
while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
|
|
7151
8412
|
const oldest = FILE_DERIVATIONS.keys().next();
|
|
7152
8413
|
if (oldest.done === true) break;
|
|
@@ -7167,11 +8428,12 @@ function deriveFile(relativePath, rawContent, sizeBytes, config) {
|
|
|
7167
8428
|
const lineCount = countLines(rawContent);
|
|
7168
8429
|
const { redacted, findings } = scanAndRedactSecrets(rawContent, config.secretRules, relativePath);
|
|
7169
8430
|
const isLarge = sizeBytes > config.largeFileBytes;
|
|
8431
|
+
const oversizeForSummary = Buffer.byteLength(rawContent, "utf8") > SUMMARY_MAX_SOURCE_BYTES2;
|
|
7170
8432
|
let finalContent = redacted;
|
|
7171
8433
|
let isPreviewTruncated = false;
|
|
7172
8434
|
let includedLines = lineCount;
|
|
7173
8435
|
let inclusionMode = "full";
|
|
7174
|
-
if (config.skeleton === true && isSkeletonizable(relativePath)) {
|
|
8436
|
+
if (config.skeleton === true && isSkeletonizable(relativePath) && !oversizeForSummary) {
|
|
7175
8437
|
const skeleton = skeletonizeTypeScript(redacted, relativePath);
|
|
7176
8438
|
if (skeleton.collapsed > 0) {
|
|
7177
8439
|
finalContent = skeleton.text;
|
|
@@ -7191,7 +8453,7 @@ function deriveFile(relativePath, rawContent, sizeBytes, config) {
|
|
|
7191
8453
|
let summarySkip = null;
|
|
7192
8454
|
let summaryWarning = null;
|
|
7193
8455
|
let dependentImports = null;
|
|
7194
|
-
if (
|
|
8456
|
+
if (oversizeForSummary) {
|
|
7195
8457
|
summarySkip = "oversize";
|
|
7196
8458
|
dependentImports = [];
|
|
7197
8459
|
} else if (isPreviewTruncated && hasStructuralSummary(relativePath)) {
|
|
@@ -7278,8 +8540,8 @@ function retain(items, keep) {
|
|
|
7278
8540
|
}
|
|
7279
8541
|
items.length = write;
|
|
7280
8542
|
}
|
|
7281
|
-
function buildIndexes(files) {
|
|
7282
|
-
const resolver = buildImportResolver(files);
|
|
8543
|
+
function buildIndexes(files, tsconfigPaths) {
|
|
8544
|
+
const resolver = buildImportResolver(files, { tsconfig: tsconfigPaths });
|
|
7283
8545
|
const importerCounts = /* @__PURE__ */ new Map();
|
|
7284
8546
|
const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => {
|
|
7285
8547
|
const summary = file.summary;
|
|
@@ -7413,14 +8675,14 @@ function listEntries(dir) {
|
|
|
7413
8675
|
const walk = (absolute, prefix) => {
|
|
7414
8676
|
let children;
|
|
7415
8677
|
try {
|
|
7416
|
-
children =
|
|
8678
|
+
children = fs9__namespace.readdirSync(absolute, { withFileTypes: true });
|
|
7417
8679
|
} catch {
|
|
7418
8680
|
return;
|
|
7419
8681
|
}
|
|
7420
8682
|
for (const child of children) {
|
|
7421
|
-
const
|
|
7422
|
-
entries.push(
|
|
7423
|
-
if (child.isDirectory()) walk(path10__namespace.join(absolute, child.name),
|
|
8683
|
+
const relative9 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
8684
|
+
entries.push(relative9);
|
|
8685
|
+
if (child.isDirectory()) walk(path10__namespace.join(absolute, child.name), relative9);
|
|
7424
8686
|
}
|
|
7425
8687
|
};
|
|
7426
8688
|
walk(dir, "");
|
|
@@ -7428,12 +8690,12 @@ function listEntries(dir) {
|
|
|
7428
8690
|
}
|
|
7429
8691
|
function readOwnershipMarker(dir) {
|
|
7430
8692
|
const markerPath = path10__namespace.join(dir, OWNERSHIP_MARKER);
|
|
7431
|
-
if (!
|
|
8693
|
+
if (!fs9__namespace.existsSync(markerPath)) {
|
|
7432
8694
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
7433
8695
|
}
|
|
7434
8696
|
let raw;
|
|
7435
8697
|
try {
|
|
7436
|
-
raw =
|
|
8698
|
+
raw = fs9__namespace.readFileSync(markerPath, "utf8");
|
|
7437
8699
|
} catch {
|
|
7438
8700
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
7439
8701
|
}
|
|
@@ -7536,7 +8798,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
7536
8798
|
const full = path10__namespace.join(dir, ...entry.split("/"));
|
|
7537
8799
|
let stats;
|
|
7538
8800
|
try {
|
|
7539
|
-
stats =
|
|
8801
|
+
stats = fs9__namespace.lstatSync(full);
|
|
7540
8802
|
} catch {
|
|
7541
8803
|
return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
|
|
7542
8804
|
}
|
|
@@ -7561,7 +8823,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
7561
8823
|
}
|
|
7562
8824
|
let digest;
|
|
7563
8825
|
try {
|
|
7564
|
-
digest = sha256Hex2(
|
|
8826
|
+
digest = sha256Hex2(fs9__namespace.readFileSync(full));
|
|
7565
8827
|
} catch {
|
|
7566
8828
|
return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
|
|
7567
8829
|
}
|
|
@@ -7583,11 +8845,11 @@ function assessSnapshotDirectory(dir) {
|
|
|
7583
8845
|
};
|
|
7584
8846
|
}
|
|
7585
8847
|
const manifestPath = path10__namespace.join(dir, "manifest.json");
|
|
7586
|
-
const hasManifest =
|
|
8848
|
+
const hasManifest = fs9__namespace.existsSync(manifestPath);
|
|
7587
8849
|
if (hasManifest) {
|
|
7588
8850
|
let raw;
|
|
7589
8851
|
try {
|
|
7590
|
-
raw =
|
|
8852
|
+
raw = fs9__namespace.readFileSync(manifestPath, "utf8");
|
|
7591
8853
|
} catch {
|
|
7592
8854
|
return {
|
|
7593
8855
|
owned: false,
|
|
@@ -7682,7 +8944,7 @@ function containsNoFiles(dir) {
|
|
|
7682
8944
|
const current = pending.pop();
|
|
7683
8945
|
let entries;
|
|
7684
8946
|
try {
|
|
7685
|
-
entries =
|
|
8947
|
+
entries = fs9__namespace.readdirSync(current, { withFileTypes: true });
|
|
7686
8948
|
} catch {
|
|
7687
8949
|
return false;
|
|
7688
8950
|
}
|
|
@@ -7697,13 +8959,13 @@ function containsNoFiles(dir) {
|
|
|
7697
8959
|
return true;
|
|
7698
8960
|
}
|
|
7699
8961
|
function assertReplaceable(target, label, secretRules) {
|
|
7700
|
-
if (!
|
|
7701
|
-
if (!
|
|
8962
|
+
if (!fs9__namespace.existsSync(target)) return;
|
|
8963
|
+
if (!fs9__namespace.statSync(target).isDirectory()) {
|
|
7702
8964
|
throw new Error(
|
|
7703
8965
|
`Refusing to write into ${label} ${target}: it exists but is not a directory.`
|
|
7704
8966
|
);
|
|
7705
8967
|
}
|
|
7706
|
-
const entries =
|
|
8968
|
+
const entries = fs9__namespace.readdirSync(target);
|
|
7707
8969
|
if (entries.length === 0) return;
|
|
7708
8970
|
if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
|
|
7709
8971
|
if (containsNoFiles(target)) return;
|
|
@@ -7723,18 +8985,18 @@ function assertReplaceable(target, label, secretRules) {
|
|
|
7723
8985
|
);
|
|
7724
8986
|
}
|
|
7725
8987
|
function assertStagingRootUsable(tmpDir, secretRules) {
|
|
7726
|
-
if (!
|
|
7727
|
-
if (!
|
|
8988
|
+
if (!fs9__namespace.existsSync(tmpDir)) return;
|
|
8989
|
+
if (!fs9__namespace.statSync(tmpDir).isDirectory()) {
|
|
7728
8990
|
throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
|
|
7729
8991
|
}
|
|
7730
|
-
const entries =
|
|
8992
|
+
const entries = fs9__namespace.readdirSync(tmpDir);
|
|
7731
8993
|
if (entries.length === 0) return;
|
|
7732
8994
|
const foreign = entries.filter((name) => {
|
|
7733
8995
|
const full = path10__namespace.join(tmpDir, name);
|
|
7734
8996
|
if (!name.startsWith(RUN_DIR_PREFIX)) return true;
|
|
7735
8997
|
let stats;
|
|
7736
8998
|
try {
|
|
7737
|
-
stats =
|
|
8999
|
+
stats = fs9__namespace.statSync(full);
|
|
7738
9000
|
} catch {
|
|
7739
9001
|
return true;
|
|
7740
9002
|
}
|
|
@@ -7742,7 +9004,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
7742
9004
|
const { marker } = readOwnershipMarker(full);
|
|
7743
9005
|
if (marker) return false;
|
|
7744
9006
|
try {
|
|
7745
|
-
return
|
|
9007
|
+
return fs9__namespace.readdirSync(full).length > 0;
|
|
7746
9008
|
} catch {
|
|
7747
9009
|
return true;
|
|
7748
9010
|
}
|
|
@@ -7793,6 +9055,13 @@ function generateSnapshot(configInput, options) {
|
|
|
7793
9055
|
assertUsableConfigInput(configInput);
|
|
7794
9056
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
7795
9057
|
const gitInfo = getGitInfo(config.cwd, config.branch);
|
|
9058
|
+
const changedScope = config.changedSince !== void 0 || config.staged === true ? resolveChangedScope(config.cwd, {
|
|
9059
|
+
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
9060
|
+
...config.staged === true ? { staged: true } : {}
|
|
9061
|
+
}) : null;
|
|
9062
|
+
const changedPaths = changedScope === null ? null : new Set(changedScope.paths);
|
|
9063
|
+
const stagedPaths = changedScope?.stagedPaths ?? /* @__PURE__ */ new Set();
|
|
9064
|
+
const stagedDeletedPaths = changedScope?.deletedPaths ?? /* @__PURE__ */ new Set();
|
|
7796
9065
|
const collection = collectFiles(config.cwd, {
|
|
7797
9066
|
includePatterns: config.include,
|
|
7798
9067
|
excludePatterns: [...config.excludePatterns, ...config.presetExclude],
|
|
@@ -7804,13 +9073,11 @@ function generateSnapshot(configInput, options) {
|
|
|
7804
9073
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
7805
9074
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7806
9075
|
(directory) => path10__namespace.relative(config.cwd, path10__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7807
|
-
).filter((
|
|
9076
|
+
).filter((relative9) => relative9.length > 0 && !relative9.startsWith("..")),
|
|
9077
|
+
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
9078
|
+
// lists the working tree, so those paths would never reach the scan at all.
|
|
9079
|
+
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
7808
9080
|
});
|
|
7809
|
-
const changedScope = config.changedSince !== void 0 || config.staged === true ? resolveChangedScope(config.cwd, {
|
|
7810
|
-
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
7811
|
-
...config.staged === true ? { staged: true } : {}
|
|
7812
|
-
}) : null;
|
|
7813
|
-
const changedPaths = changedScope === null ? null : new Set(changedScope.paths);
|
|
7814
9081
|
const unchangedPaths = [];
|
|
7815
9082
|
const candidateFiles = changedPaths !== null && config.withDependents !== true ? collection.files.filter((relativePath) => {
|
|
7816
9083
|
if (changedPaths.has(relativePath)) return true;
|
|
@@ -7832,45 +9099,92 @@ function generateSnapshot(configInput, options) {
|
|
|
7832
9099
|
const oversizeSummaryPaths = [];
|
|
7833
9100
|
const previewSummaryPaths = [];
|
|
7834
9101
|
const skippedSummaryImports = /* @__PURE__ */ new Map();
|
|
7835
|
-
const layerCounts =
|
|
7836
|
-
const kindCounts =
|
|
9102
|
+
const layerCounts = /* @__PURE__ */ Object.create(null);
|
|
9103
|
+
const kindCounts = /* @__PURE__ */ Object.create(null);
|
|
7837
9104
|
let totalLines = 0;
|
|
7838
9105
|
let totalSizeBytes = 0;
|
|
7839
9106
|
let largeFileCount = 0;
|
|
7840
9107
|
for (const relativePath of candidateFiles) {
|
|
7841
9108
|
const absolutePath = path10__namespace.join(config.cwd, relativePath);
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
9109
|
+
const fromIndex = stagedPaths.has(relativePath);
|
|
9110
|
+
let buffer;
|
|
9111
|
+
let sizeBytes;
|
|
9112
|
+
if (fromIndex && stagedDeletedPaths.has(relativePath)) {
|
|
9113
|
+
skipped.push({
|
|
9114
|
+
path: relativePath,
|
|
9115
|
+
reason: "deleted",
|
|
9116
|
+
detail: "staged for deletion; it is not part of the next commit"
|
|
9117
|
+
});
|
|
9118
|
+
continue;
|
|
9119
|
+
}
|
|
9120
|
+
if (fromIndex) {
|
|
9121
|
+
const staged = readStagedBlob(config.cwd, relativePath);
|
|
9122
|
+
if (staged === null) {
|
|
9123
|
+
skipped.push({
|
|
9124
|
+
path: relativePath,
|
|
9125
|
+
reason: "deleted",
|
|
9126
|
+
detail: "staged path has no blob in the index; it is not part of the next commit"
|
|
9127
|
+
});
|
|
9128
|
+
continue;
|
|
9129
|
+
}
|
|
9130
|
+
if (isBinaryExtension(absolutePath)) {
|
|
9131
|
+
skipped.push({ path: relativePath, reason: "binary", detail: `Size: ${staged.length} B` });
|
|
9132
|
+
continue;
|
|
9133
|
+
}
|
|
9134
|
+
buffer = staged;
|
|
9135
|
+
sizeBytes = staged.length;
|
|
9136
|
+
} else {
|
|
9137
|
+
let stats;
|
|
9138
|
+
try {
|
|
9139
|
+
stats = fs9__namespace.statSync(absolutePath);
|
|
9140
|
+
if (!stats.isFile()) {
|
|
9141
|
+
const nestedRepository = stats.isDirectory() && fs9__namespace.existsSync(path10__namespace.join(absolutePath, ".git"));
|
|
9142
|
+
skipped.push(
|
|
9143
|
+
nestedRepository ? {
|
|
9144
|
+
path: relativePath,
|
|
9145
|
+
reason: "nested-repository",
|
|
9146
|
+
detail: "a directory belonging to another repository (nested checkout or submodule); its contents are not scanned"
|
|
9147
|
+
} : { path: relativePath, reason: "not-file" }
|
|
9148
|
+
);
|
|
9149
|
+
continue;
|
|
9150
|
+
}
|
|
9151
|
+
} catch (err) {
|
|
9152
|
+
const code = err.code;
|
|
9153
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
9154
|
+
skipped.push({
|
|
7849
9155
|
path: relativePath,
|
|
7850
|
-
reason: "
|
|
7851
|
-
detail: "
|
|
7852
|
-
}
|
|
7853
|
-
|
|
9156
|
+
reason: "missing",
|
|
9157
|
+
detail: "tracked but absent from disk (deleted without staging)"
|
|
9158
|
+
});
|
|
9159
|
+
} else {
|
|
9160
|
+
skipped.push({
|
|
9161
|
+
path: relativePath,
|
|
9162
|
+
reason: "read-error",
|
|
9163
|
+
detail: String(err.message).replace(/\s+/g, " ")
|
|
9164
|
+
});
|
|
9165
|
+
}
|
|
7854
9166
|
continue;
|
|
7855
9167
|
}
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
9168
|
+
if (isBinaryExtension(absolutePath)) {
|
|
9169
|
+
skipped.push({ path: relativePath, reason: "binary", detail: `Size: ${stats.size} B` });
|
|
9170
|
+
continue;
|
|
9171
|
+
}
|
|
9172
|
+
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) {
|
|
9173
|
+
skipped.push({ path: relativePath, reason: "binary", detail: `Size: ${stats.size} B` });
|
|
9174
|
+
continue;
|
|
9175
|
+
}
|
|
9176
|
+
try {
|
|
9177
|
+
buffer = fs9__namespace.readFileSync(absolutePath);
|
|
9178
|
+
} catch (err) {
|
|
9179
|
+
const code = err.code;
|
|
9180
|
+
skipped.push({
|
|
9181
|
+
path: relativePath,
|
|
9182
|
+
reason: code === "ENOENT" || code === "ENOTDIR" ? "missing" : "read-error",
|
|
9183
|
+
detail: String(err.message).replace(/\s+/g, " ")
|
|
9184
|
+
});
|
|
9185
|
+
continue;
|
|
9186
|
+
}
|
|
9187
|
+
sizeBytes = stats.size;
|
|
7874
9188
|
}
|
|
7875
9189
|
let decoded;
|
|
7876
9190
|
try {
|
|
@@ -7879,7 +9193,7 @@ function generateSnapshot(configInput, options) {
|
|
|
7879
9193
|
skipped.push({
|
|
7880
9194
|
path: relativePath,
|
|
7881
9195
|
reason: "read-error",
|
|
7882
|
-
detail: `Size: ${
|
|
9196
|
+
detail: `Size: ${sizeBytes} B; could not be decoded: ${err.message}`.replace(
|
|
7883
9197
|
/\s+/g,
|
|
7884
9198
|
" "
|
|
7885
9199
|
)
|
|
@@ -7890,13 +9204,13 @@ function generateSnapshot(configInput, options) {
|
|
|
7890
9204
|
skipped.push({
|
|
7891
9205
|
path: relativePath,
|
|
7892
9206
|
reason: "binary",
|
|
7893
|
-
detail: `Size: ${
|
|
9207
|
+
detail: `Size: ${sizeBytes} B; ${decoded.binaryReason ?? "binary content"}`
|
|
7894
9208
|
});
|
|
7895
9209
|
continue;
|
|
7896
9210
|
}
|
|
7897
9211
|
const hashSha256 = sha256Hex2(buffer);
|
|
7898
9212
|
const rawContent = decoded.text;
|
|
7899
|
-
totalSizeBytes +=
|
|
9213
|
+
totalSizeBytes += sizeBytes;
|
|
7900
9214
|
if (decoded.encoding !== "utf-8") {
|
|
7901
9215
|
encodingNotes.push({
|
|
7902
9216
|
path: relativePath,
|
|
@@ -7910,7 +9224,7 @@ function generateSnapshot(configInput, options) {
|
|
|
7910
9224
|
bump(layerCounts, layer2);
|
|
7911
9225
|
bump(kindCounts, kind);
|
|
7912
9226
|
const derivation = takeDerivation(absolutePath, hashSha256, derivationKey) ?? (() => {
|
|
7913
|
-
const fresh = deriveFile(relativePath, rawContent,
|
|
9227
|
+
const fresh = deriveFile(relativePath, rawContent, sizeBytes, config);
|
|
7914
9228
|
rememberDerivation(absolutePath, hashSha256, derivationKey, fresh);
|
|
7915
9229
|
return fresh;
|
|
7916
9230
|
})();
|
|
@@ -7931,7 +9245,7 @@ function generateSnapshot(configInput, options) {
|
|
|
7931
9245
|
}
|
|
7932
9246
|
files.push({
|
|
7933
9247
|
relativePath,
|
|
7934
|
-
sizeBytes
|
|
9248
|
+
sizeBytes,
|
|
7935
9249
|
lines: lineCount,
|
|
7936
9250
|
hashSha256,
|
|
7937
9251
|
part: "",
|
|
@@ -7952,7 +9266,10 @@ function generateSnapshot(configInput, options) {
|
|
|
7952
9266
|
}
|
|
7953
9267
|
if (changedScope !== null && changedPaths !== null && config.withDependents === true) {
|
|
7954
9268
|
const keep = new Set(changedPaths);
|
|
7955
|
-
const resolver = buildImportResolver(files
|
|
9269
|
+
const resolver = buildImportResolver(files, {
|
|
9270
|
+
extraPaths: changedPaths,
|
|
9271
|
+
tsconfig: tsconfigPathsFor(config.cwd)
|
|
9272
|
+
});
|
|
7956
9273
|
for (const file of files) {
|
|
7957
9274
|
const fileImports = isSourceSummary(file.summary) ? file.summary.imports : skippedSummaryImports.get(file.relativePath) ?? [];
|
|
7958
9275
|
if (fileImports.length === 0) continue;
|
|
@@ -8046,7 +9363,7 @@ function generateSnapshot(configInput, options) {
|
|
|
8046
9363
|
const fingerprint = sha256Hex2(
|
|
8047
9364
|
[
|
|
8048
9365
|
...files.map(
|
|
8049
|
-
(file) => `${file.relativePath}:${file.hashSha256}:${file.sizeBytes}
|
|
9366
|
+
(file) => `${file.relativePath}:${file.hashSha256}:${file.sizeBytes}`
|
|
8050
9367
|
),
|
|
8051
9368
|
`settings:${configDigest(config)}`
|
|
8052
9369
|
].join("\n")
|
|
@@ -8133,6 +9450,8 @@ function generateSnapshot(configInput, options) {
|
|
|
8133
9450
|
skippedFiles: skipped.length,
|
|
8134
9451
|
totalSourceBytes: totalSizeBytes,
|
|
8135
9452
|
totalContentBytes,
|
|
9453
|
+
sourceLines: totalLines,
|
|
9454
|
+
emittedLines: files.reduce((total, file) => total + file.includedLines, 0),
|
|
8136
9455
|
// The parts are what a model is handed, so the estimate is over the parts rather than
|
|
8137
9456
|
// over the sources: previews and the byte budget both shrink the number.
|
|
8138
9457
|
estimatedTokens: parts.reduce((total, part) => total + part.metadata.estimatedTokens, 0),
|
|
@@ -8151,7 +9470,7 @@ function generateSnapshot(configInput, options) {
|
|
|
8151
9470
|
},
|
|
8152
9471
|
layers: layerCounts,
|
|
8153
9472
|
kinds: kindCounts,
|
|
8154
|
-
indexes: buildIndexes(files),
|
|
9473
|
+
indexes: buildIndexes(files, tsconfigPathsFor(config.cwd)),
|
|
8155
9474
|
parts: parts.map((part) => part.metadata),
|
|
8156
9475
|
files: files.map((file) => {
|
|
8157
9476
|
const { content: _content, ...rest } = file;
|
|
@@ -8168,6 +9487,23 @@ function generateSnapshot(configInput, options) {
|
|
|
8168
9487
|
);
|
|
8169
9488
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
8170
9489
|
}
|
|
9490
|
+
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes <= config.maxPartBytes) {
|
|
9491
|
+
manifest.warnings.push(
|
|
9492
|
+
`${files.filter((file) => file.isPreviewTruncated).length} file(s) were previewed because largeFileBytes (${config.largeFileBytes} B) is not above maxPartBytes (${config.maxPartBytes} B). Raise largeFileBytes if a whole file is wanted.`
|
|
9493
|
+
);
|
|
9494
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
9495
|
+
}
|
|
9496
|
+
if (config.maxPartTokens !== void 0) {
|
|
9497
|
+
const overTokenBudget = parts.filter(
|
|
9498
|
+
(part) => part.metadata.estimatedTokens > (config.maxPartTokens ?? 0)
|
|
9499
|
+
);
|
|
9500
|
+
if (overTokenBudget.length > 0) {
|
|
9501
|
+
manifest.warnings.push(
|
|
9502
|
+
`${overTokenBudget.length} part(s) exceed the estimated token ceiling of ${config.maxPartTokens}: the partitioner enforces the equivalent byte budget (tokens \xD7 4), and estimatedTokens is an estimate, not a hard bound.`
|
|
9503
|
+
);
|
|
9504
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
9505
|
+
}
|
|
9506
|
+
}
|
|
8171
9507
|
if (secretFindings.length > 0 && !config.artifacts.audit) {
|
|
8172
9508
|
manifest.warnings.push(
|
|
8173
9509
|
`${secretFindings.length} line(s) contain redacted values; reports/audit.md is disabled, so the per-line detail was not written.`
|
|
@@ -8196,6 +9532,18 @@ function generateSnapshot(configInput, options) {
|
|
|
8196
9532
|
sha256: sha256Hex2(sarifText)
|
|
8197
9533
|
};
|
|
8198
9534
|
}
|
|
9535
|
+
const artifacts = config.artifacts;
|
|
9536
|
+
const artifactRecord = (text) => ({
|
|
9537
|
+
byteSize: Buffer.byteLength(text, "utf8"),
|
|
9538
|
+
sha256: sha256Hex2(text)
|
|
9539
|
+
});
|
|
9540
|
+
const navigationText = artifacts.navigation ? generateNavigation(manifest) : null;
|
|
9541
|
+
if (navigationText !== null) manifest.artifacts.navigation = artifactRecord(navigationText);
|
|
9542
|
+
const auditText = artifacts.audit ? generateAuditReport(manifest, secretFindings, config.secretRules) : null;
|
|
9543
|
+
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
9544
|
+
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
9545
|
+
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
9546
|
+
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
8199
9547
|
if (config.includeMonolith) {
|
|
8200
9548
|
const fullFiles = files.map((file) => {
|
|
8201
9549
|
const content = fullContents.get(file.relativePath) ?? "";
|
|
@@ -8208,24 +9556,31 @@ function generateSnapshot(configInput, options) {
|
|
|
8208
9556
|
includedLines: countLines(content)
|
|
8209
9557
|
};
|
|
8210
9558
|
});
|
|
8211
|
-
const
|
|
8212
|
-
const
|
|
8213
|
-
if (
|
|
9559
|
+
const bodyBytes = fullFiles.reduce((total, file) => total + file.includedBytes, 0);
|
|
9560
|
+
const definitelyTooLarge = config.maxMonolithBytes !== null && bodyBytes > config.maxMonolithBytes;
|
|
9561
|
+
if (definitelyTooLarge) {
|
|
9562
|
+
const reason = `their bodies total ${bodyBytes} B, which already exceeds maxMonolithBytes ${config.maxMonolithBytes ?? 0} B`;
|
|
9563
|
+
manifest.warnings.push(`full-codebase.md skipped: ${reason}`);
|
|
9564
|
+
manifest.warnings.push(`full-codebase.json skipped: ${reason}`);
|
|
9565
|
+
}
|
|
9566
|
+
const markdown = definitelyTooLarge ? null : generateMonolithMarkdown(manifest, fullFiles);
|
|
9567
|
+
const markdownBytes = markdown === null ? 0 : Buffer.byteLength(markdown, "utf8");
|
|
9568
|
+
if (markdown !== null && (!config.maxMonolithBytes || markdownBytes <= config.maxMonolithBytes)) {
|
|
8214
9569
|
manifest.artifacts.fullMarkdown = {
|
|
8215
9570
|
byteSize: markdownBytes,
|
|
8216
9571
|
sha256: sha256Hex2(markdown)
|
|
8217
9572
|
};
|
|
8218
|
-
} else {
|
|
9573
|
+
} else if (!definitelyTooLarge) {
|
|
8219
9574
|
manifest.warnings.push(
|
|
8220
9575
|
`full-codebase.md skipped: ${markdownBytes} B exceeds maxMonolithBytes ${config.maxMonolithBytes} B`
|
|
8221
9576
|
);
|
|
8222
9577
|
}
|
|
8223
9578
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
8224
|
-
const json = generateMonolithJson(manifest, fullFiles);
|
|
8225
|
-
const jsonBytes = Buffer.byteLength(json, "utf8");
|
|
8226
|
-
if (!config.maxMonolithBytes || jsonBytes <= config.maxMonolithBytes) {
|
|
9579
|
+
const json = definitelyTooLarge ? null : generateMonolithJson(manifest, fullFiles);
|
|
9580
|
+
const jsonBytes = json === null ? 0 : Buffer.byteLength(json, "utf8");
|
|
9581
|
+
if (json !== null && (!config.maxMonolithBytes || jsonBytes <= config.maxMonolithBytes)) {
|
|
8227
9582
|
manifest.artifacts.fullJson = { byteSize: jsonBytes, sha256: sha256Hex2(json) };
|
|
8228
|
-
} else {
|
|
9583
|
+
} else if (!definitelyTooLarge) {
|
|
8229
9584
|
manifest.warnings.push(
|
|
8230
9585
|
`full-codebase.json skipped: ${jsonBytes} B exceeds maxMonolithBytes ${config.maxMonolithBytes} B`
|
|
8231
9586
|
);
|
|
@@ -8233,7 +9588,6 @@ function generateSnapshot(configInput, options) {
|
|
|
8233
9588
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
8234
9589
|
}
|
|
8235
9590
|
const { outDir, tmpDir } = resolveSafeOutputDirs(config);
|
|
8236
|
-
const { artifacts } = config;
|
|
8237
9591
|
assertReplaceable(outDir, "outDir", config.secretRules);
|
|
8238
9592
|
assertStagingRootUsable(tmpDir, config.secretRules);
|
|
8239
9593
|
{
|
|
@@ -8350,7 +9704,7 @@ function foldForComparison(value) {
|
|
|
8350
9704
|
function canonicalPath(value) {
|
|
8351
9705
|
const absolute = path10__namespace.resolve(value);
|
|
8352
9706
|
try {
|
|
8353
|
-
return
|
|
9707
|
+
return fs9__namespace.realpathSync(absolute);
|
|
8354
9708
|
} catch {
|
|
8355
9709
|
return absolute;
|
|
8356
9710
|
}
|
|
@@ -8363,7 +9717,7 @@ function isInside2(parent, child) {
|
|
|
8363
9717
|
function resolveThroughExistingAncestor(target) {
|
|
8364
9718
|
let existing = target;
|
|
8365
9719
|
const missing = [];
|
|
8366
|
-
while (!
|
|
9720
|
+
while (!fs9__namespace.existsSync(existing)) {
|
|
8367
9721
|
missing.unshift(path10__namespace.basename(existing));
|
|
8368
9722
|
const parent = path10__namespace.dirname(existing);
|
|
8369
9723
|
if (parent === existing) break;
|
|
@@ -8380,7 +9734,7 @@ function resolveRoot(requested, context) {
|
|
|
8380
9734
|
const absolute = path10__namespace.resolve(context.cwd, wanted);
|
|
8381
9735
|
let stats;
|
|
8382
9736
|
try {
|
|
8383
|
-
stats =
|
|
9737
|
+
stats = fs9__namespace.statSync(absolute);
|
|
8384
9738
|
} catch {
|
|
8385
9739
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
8386
9740
|
}
|
|
@@ -8397,8 +9751,8 @@ function resolveRoot(requested, context) {
|
|
|
8397
9751
|
message: `"${wanted}" resolves outside the directories this server may read (${shown}). The server reads the directory it was started for; restart it with --cwd <directory> to serve a different repository.`
|
|
8398
9752
|
};
|
|
8399
9753
|
}
|
|
8400
|
-
async function openWorkspace(root, overrides = {}, allowedRoots) {
|
|
8401
|
-
const loaded = await loadConfigFileDetailed(root);
|
|
9754
|
+
async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
9755
|
+
const loaded = await loadConfigFileDetailed(root, options);
|
|
8402
9756
|
if (loaded.errors.length > 0) {
|
|
8403
9757
|
return {
|
|
8404
9758
|
ok: false,
|
|
@@ -8462,6 +9816,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots) {
|
|
|
8462
9816
|
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
8463
9817
|
}
|
|
8464
9818
|
}
|
|
9819
|
+
var MANIFEST_CACHE_LIMIT = 8;
|
|
8465
9820
|
var manifestCache = /* @__PURE__ */ new Map();
|
|
8466
9821
|
function manifestPathFor(workspace) {
|
|
8467
9822
|
return path10__namespace.resolve(workspace.root, workspace.config.outDir, "manifest.json");
|
|
@@ -8470,8 +9825,20 @@ function partPathFor(workspace, filename) {
|
|
|
8470
9825
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
8471
9826
|
const partsDir = path10__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
8472
9827
|
const resolved = path10__namespace.resolve(partsDir, filename);
|
|
8473
|
-
const
|
|
8474
|
-
if (
|
|
9828
|
+
const relative9 = path10__namespace.relative(partsDir, resolved);
|
|
9829
|
+
if (relative9.length === 0 || relative9.includes(path10__namespace.sep) || relative9.includes("/") || relative9.includes("\\") || path10__namespace.isAbsolute(relative9)) {
|
|
9830
|
+
return null;
|
|
9831
|
+
}
|
|
9832
|
+
let stats;
|
|
9833
|
+
try {
|
|
9834
|
+
stats = fs9__namespace.lstatSync(resolved);
|
|
9835
|
+
} catch {
|
|
9836
|
+
return null;
|
|
9837
|
+
}
|
|
9838
|
+
if (!stats.isFile()) return null;
|
|
9839
|
+
try {
|
|
9840
|
+
if (path10__namespace.dirname(fs9__namespace.realpathSync(resolved)) !== fs9__namespace.realpathSync(partsDir)) return null;
|
|
9841
|
+
} catch {
|
|
8475
9842
|
return null;
|
|
8476
9843
|
}
|
|
8477
9844
|
return resolved;
|
|
@@ -8481,7 +9848,7 @@ function readManifest3(workspace) {
|
|
|
8481
9848
|
const shown = path10__namespace.relative(workspace.root, file).split(path10__namespace.sep).join("/") || file;
|
|
8482
9849
|
let stats;
|
|
8483
9850
|
try {
|
|
8484
|
-
stats =
|
|
9851
|
+
stats = fs9__namespace.statSync(file);
|
|
8485
9852
|
} catch {
|
|
8486
9853
|
return {
|
|
8487
9854
|
ok: false,
|
|
@@ -8490,12 +9857,12 @@ function readManifest3(workspace) {
|
|
|
8490
9857
|
};
|
|
8491
9858
|
}
|
|
8492
9859
|
const cached = manifestCache.get(file);
|
|
8493
|
-
if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) {
|
|
9860
|
+
if (cached && cached.mtimeMs === stats.mtimeMs && cached.ctimeMs === stats.ctimeMs && cached.size === stats.size) {
|
|
8494
9861
|
return { ok: true, manifest: cached.manifest, file };
|
|
8495
9862
|
}
|
|
8496
9863
|
let raw;
|
|
8497
9864
|
try {
|
|
8498
|
-
raw =
|
|
9865
|
+
raw = fs9__namespace.readFileSync(file, "utf8");
|
|
8499
9866
|
} catch (error) {
|
|
8500
9867
|
return {
|
|
8501
9868
|
ok: false,
|
|
@@ -8514,7 +9881,18 @@ function readManifest3(workspace) {
|
|
|
8514
9881
|
return { ok: false, missing: false, message: `${shown} is not a snapshot manifest: ${problem}` };
|
|
8515
9882
|
}
|
|
8516
9883
|
const manifest = parsed;
|
|
8517
|
-
manifestCache.
|
|
9884
|
+
manifestCache.delete(file);
|
|
9885
|
+
manifestCache.set(file, {
|
|
9886
|
+
mtimeMs: stats.mtimeMs,
|
|
9887
|
+
ctimeMs: stats.ctimeMs,
|
|
9888
|
+
size: stats.size,
|
|
9889
|
+
manifest
|
|
9890
|
+
});
|
|
9891
|
+
while (manifestCache.size > MANIFEST_CACHE_LIMIT) {
|
|
9892
|
+
const oldest = manifestCache.keys().next().value;
|
|
9893
|
+
if (oldest === void 0) break;
|
|
9894
|
+
manifestCache.delete(oldest);
|
|
9895
|
+
}
|
|
8518
9896
|
return { ok: true, manifest, file };
|
|
8519
9897
|
}
|
|
8520
9898
|
function forgetManifest(file) {
|
|
@@ -8617,11 +9995,11 @@ function toRelativePath(root, value) {
|
|
|
8617
9995
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
8618
9996
|
const resolvedRoot = path10__namespace.resolve(root);
|
|
8619
9997
|
const absolute = path10__namespace.resolve(resolvedRoot, cleaned);
|
|
8620
|
-
const
|
|
8621
|
-
if (
|
|
9998
|
+
const relative9 = path10__namespace.relative(resolvedRoot, absolute);
|
|
9999
|
+
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${path10__namespace.sep}`) || path10__namespace.isAbsolute(relative9)) {
|
|
8622
10000
|
return null;
|
|
8623
10001
|
}
|
|
8624
|
-
return
|
|
10002
|
+
return relative9.split(path10__namespace.sep).join("/");
|
|
8625
10003
|
}
|
|
8626
10004
|
function symbolsOf(entry) {
|
|
8627
10005
|
const summary = entry.summary;
|
|
@@ -8662,7 +10040,9 @@ function symbolsOf(entry) {
|
|
|
8662
10040
|
async function prepare(args, context, overrides = {}) {
|
|
8663
10041
|
const rootOutcome = resolveRoot(args.root, context);
|
|
8664
10042
|
if (!rootOutcome.ok) return { ok: false, outcome: failure(rootOutcome.message) };
|
|
8665
|
-
const opened = await openWorkspace(rootOutcome.root, overrides, context.roots
|
|
10043
|
+
const opened = await openWorkspace(rootOutcome.root, overrides, context.roots, {
|
|
10044
|
+
allowExecutableConfig: false
|
|
10045
|
+
});
|
|
8666
10046
|
if (!opened.ok) return { ok: false, outcome: failure(opened.message) };
|
|
8667
10047
|
return { ok: true, workspace: opened.workspace };
|
|
8668
10048
|
}
|
|
@@ -9018,10 +10398,12 @@ var locateTool = {
|
|
|
9018
10398
|
else if (wants("kind") && entry.kind.toLowerCase().includes(needle)) add(entry, "kind");
|
|
9019
10399
|
}
|
|
9020
10400
|
if (wants("route")) {
|
|
10401
|
+
const matchedPaths = new Set(matches.map((match) => match.path));
|
|
9021
10402
|
for (const route of manifest.indexes.routes) {
|
|
9022
10403
|
const method = route.methods.find((name) => name.toLowerCase().includes(needle));
|
|
9023
10404
|
if (!route.path.toLowerCase().includes(needle) && method === void 0) continue;
|
|
9024
|
-
if (
|
|
10405
|
+
if (matchedPaths.has(route.path)) continue;
|
|
10406
|
+
matchedPaths.add(route.path);
|
|
9025
10407
|
matches.push({
|
|
9026
10408
|
path: route.path,
|
|
9027
10409
|
part: route.part,
|
|
@@ -9214,7 +10596,9 @@ var readTool = {
|
|
|
9214
10596
|
fromLine: { type: "integer" },
|
|
9215
10597
|
returnedLines: { type: "integer" },
|
|
9216
10598
|
totalLines: { type: "integer" },
|
|
9217
|
-
nextFromLine: { type: "integer" }
|
|
10599
|
+
nextFromLine: { type: "integer" },
|
|
10600
|
+
pageable: { type: "boolean" },
|
|
10601
|
+
reason: { type: "string" }
|
|
9218
10602
|
}
|
|
9219
10603
|
},
|
|
9220
10604
|
annotations: READ_ONLY,
|
|
@@ -9253,7 +10637,7 @@ var readTool = {
|
|
|
9253
10637
|
}
|
|
9254
10638
|
let partText;
|
|
9255
10639
|
try {
|
|
9256
|
-
partText =
|
|
10640
|
+
partText = fs9__namespace.readFileSync(partPath, "utf8");
|
|
9257
10641
|
} catch {
|
|
9258
10642
|
return failure(
|
|
9259
10643
|
`${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
|
|
@@ -9270,15 +10654,20 @@ var readTool = {
|
|
|
9270
10654
|
const window = windowText(section.body, fromLine, lineCount);
|
|
9271
10655
|
let body = window.text;
|
|
9272
10656
|
let truncatedByBytes = false;
|
|
10657
|
+
let clippedInsideLine = false;
|
|
9273
10658
|
if (Buffer.byteLength(body, "utf8") > MAX_RESULT_BYTES) {
|
|
9274
10659
|
const clipped = truncateToBytes(body, MAX_RESULT_BYTES);
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
10660
|
+
const lastBreak = clipped.content.lastIndexOf("\n");
|
|
10661
|
+
if (lastBreak > 0) {
|
|
10662
|
+
body = clipped.content.slice(0, lastBreak);
|
|
10663
|
+
} else {
|
|
10664
|
+
body = clipped.content;
|
|
10665
|
+
clippedInsideLine = true;
|
|
10666
|
+
}
|
|
9278
10667
|
truncatedByBytes = true;
|
|
9279
10668
|
}
|
|
9280
10669
|
const returnedLines = body.length === 0 ? 0 : body.split("\n").length;
|
|
9281
|
-
const moreRemain = !window.pastEnd && (window.truncated || truncatedByBytes);
|
|
10670
|
+
const moreRemain = !clippedInsideLine && !window.pastEnd && (window.truncated || truncatedByBytes);
|
|
9282
10671
|
const header = [
|
|
9283
10672
|
`${entry.relativePath} \u2014 ${entry.part}, ${entry.layer}/${entry.kind}, ${entry.language}`,
|
|
9284
10673
|
// The line range is the answer to "where am I in this file", and it is computed from the
|
|
@@ -9292,12 +10681,17 @@ var readTool = {
|
|
|
9292
10681
|
] : section.inclusion === "signatures" ? [
|
|
9293
10682
|
"Signatures: function and method bodies were replaced with `{ /* ... */ }` when the snapshot was generated."
|
|
9294
10683
|
] : [],
|
|
9295
|
-
window.totalLines === 0 ? "This file is empty." : window.pastEnd ? `This file has ${window.totalLines} line(s); fromLine=${window.fromLine} is past its end.` : `Lines ${window.fromLine}\u2013${window.fromLine + returnedLines - 1} of ${window.totalLines}.`
|
|
10684
|
+
window.totalLines === 0 ? "This file is empty." : window.pastEnd ? `This file has ${window.totalLines} line(s); fromLine=${window.fromLine} is past its end.` : clippedInsideLine ? `Line ${window.fromLine} of ${window.totalLines}: this line is longer than one result can carry, so this page ends mid-line.` : `Lines ${window.fromLine}\u2013${window.fromLine + returnedLines - 1} of ${window.totalLines}.`
|
|
9296
10685
|
];
|
|
9297
10686
|
const lines = [...header, "", body];
|
|
9298
10687
|
if (moreRemain) {
|
|
9299
10688
|
const next = window.fromLine + returnedLines;
|
|
9300
10689
|
lines.push("", `Truncated. Call snapshot_read with fromLine=${next} for the rest.`);
|
|
10690
|
+
} else if (clippedInsideLine) {
|
|
10691
|
+
lines.push(
|
|
10692
|
+
"",
|
|
10693
|
+
"Truncated. The remainder of this line is not reachable through snapshot_read; read the file from disk to see it."
|
|
10694
|
+
);
|
|
9301
10695
|
}
|
|
9302
10696
|
return {
|
|
9303
10697
|
text: lines.join("\n"),
|
|
@@ -9311,7 +10705,9 @@ var readTool = {
|
|
|
9311
10705
|
fromLine: window.fromLine,
|
|
9312
10706
|
returnedLines,
|
|
9313
10707
|
totalLines: window.totalLines,
|
|
9314
|
-
truncated: moreRemain,
|
|
10708
|
+
truncated: moreRemain || clippedInsideLine,
|
|
10709
|
+
pageable: !clippedInsideLine,
|
|
10710
|
+
...clippedInsideLine ? { reason: "line exceeds the result limit; its remainder is not reachable by fromLine" } : {},
|
|
9315
10711
|
nextFromLine: moreRemain ? window.fromLine + returnedLines : null,
|
|
9316
10712
|
sha256: entry.hashSha256
|
|
9317
10713
|
}
|
|
@@ -9535,13 +10931,14 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
9535
10931
|
"with-dependents",
|
|
9536
10932
|
"cwd",
|
|
9537
10933
|
"out-dir",
|
|
9538
|
-
|
|
10934
|
+
// `--large-file-bytes` changes the inclusion mode `explain` reports, so it belongs here.
|
|
10935
|
+
// `--max-part-bytes`, `--max-monolith-bytes`, `--include-monolith`, `--skip-artifacts` and
|
|
10936
|
+
// `--only-artifacts` were accepted and never read: a per-file answer cannot depend on how the
|
|
10937
|
+
// whole snapshot is partitioned, and none of them changes whether this file is included.
|
|
10938
|
+
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
10939
|
+
// this table exists to prevent.
|
|
9539
10940
|
"large-file-bytes",
|
|
9540
|
-
"max-monolith-bytes",
|
|
9541
|
-
"include-monolith",
|
|
9542
10941
|
"include-sensitive-files",
|
|
9543
|
-
"skip-artifacts",
|
|
9544
|
-
"only-artifacts",
|
|
9545
10942
|
"no-config",
|
|
9546
10943
|
"discovery",
|
|
9547
10944
|
"no-update-check",
|
|
@@ -9820,7 +11217,7 @@ function buildAgentContract() {
|
|
|
9820
11217
|
type: "string",
|
|
9821
11218
|
default: "unset",
|
|
9822
11219
|
appliesTo: optionAppliesTo("max-part-tokens"),
|
|
9823
|
-
summary: "Ceiling on a part expressed in tokens.
|
|
11220
|
+
summary: "Ceiling on a part expressed in tokens. Converted to bytes at 4 bytes/token and enforced as that byte ceiling \u2014 the estimate in manifest.parts[].estimatedTokens is not a hard bound, and a warning names any part whose estimate exceeds it. Minimum 1024."
|
|
9824
11221
|
},
|
|
9825
11222
|
{
|
|
9826
11223
|
flag: "--large-file-bytes",
|
|
@@ -9855,7 +11252,7 @@ function buildAgentContract() {
|
|
|
9855
11252
|
type: "string",
|
|
9856
11253
|
default: "auto",
|
|
9857
11254
|
appliesTo: optionAppliesTo("discovery"),
|
|
9858
|
-
summary: "How files are discovered: auto (git when usable), git (require git), walk (read
|
|
11255
|
+
summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
|
|
9859
11256
|
},
|
|
9860
11257
|
{
|
|
9861
11258
|
flag: "--skip-artifacts",
|
|
@@ -9876,7 +11273,7 @@ function buildAgentContract() {
|
|
|
9876
11273
|
type: "boolean",
|
|
9877
11274
|
default: false,
|
|
9878
11275
|
appliesTo: optionAppliesTo("skeleton"),
|
|
9879
|
-
summary: 'Replace function and method bodies with `{ /* ... */ }` in
|
|
11276
|
+
summary: 'Replace function and method bodies with `{ /* ... */ }` in JS, JSX, TS and TSX files (including .mjs/.cjs; .d.ts files have nothing to collapse), keeping signatures and comments. The part records inclusionMode "signatures" for each file it touched.'
|
|
9880
11277
|
},
|
|
9881
11278
|
{
|
|
9882
11279
|
flag: "--sarif",
|
|
@@ -9990,7 +11387,7 @@ function buildAgentContract() {
|
|
|
9990
11387
|
type: "boolean",
|
|
9991
11388
|
default: false,
|
|
9992
11389
|
appliesTo: optionAppliesTo("autopilot"),
|
|
9993
|
-
summary: "Set the project up without asking, then generate: detect the preset, write the config and .gitignore, add the npm scripts and devDependency, install with the project's own package manager, generate. Never overwrites an existing config, and never prompts. Refuses an empty directory (exit 1); contradicts --no-config (exit 2)."
|
|
11390
|
+
summary: "Set the project up without asking, then generate: detect the preset, write the config and .gitignore, add the npm scripts and devDependency, install with the project's own package manager, generate. Autopilot chooses the preset and takes no --preset/--include/--exclude/--install-hook: those belong to `setup` or `init`. Never overwrites an existing config, and never prompts. Refuses an empty directory (exit 1); contradicts --no-config (exit 2)."
|
|
9994
11391
|
},
|
|
9995
11392
|
{
|
|
9996
11393
|
flag: "--install",
|
|
@@ -10361,13 +11758,13 @@ function formatBytes2(bytes) {
|
|
|
10361
11758
|
async function workspaceFor(context) {
|
|
10362
11759
|
const root = resolveRoot(void 0, context);
|
|
10363
11760
|
if (!root.ok) return { error: root.message };
|
|
10364
|
-
const opened = await openWorkspace(root.root);
|
|
11761
|
+
const opened = await openWorkspace(root.root, {}, void 0, { allowExecutableConfig: false });
|
|
10365
11762
|
if (!opened.ok) return { error: opened.message };
|
|
10366
11763
|
return opened.workspace;
|
|
10367
11764
|
}
|
|
10368
11765
|
function readFileIfPresent(file) {
|
|
10369
11766
|
try {
|
|
10370
|
-
return
|
|
11767
|
+
return fs9__namespace.readFileSync(file, "utf8");
|
|
10371
11768
|
} catch {
|
|
10372
11769
|
return null;
|
|
10373
11770
|
}
|
|
@@ -10485,7 +11882,7 @@ function buildResourceProvider() {
|
|
|
10485
11882
|
if (partPath === null) return null;
|
|
10486
11883
|
let partBytes;
|
|
10487
11884
|
try {
|
|
10488
|
-
partBytes =
|
|
11885
|
+
partBytes = fs9__namespace.statSync(partPath).size;
|
|
10489
11886
|
} catch {
|
|
10490
11887
|
return null;
|
|
10491
11888
|
}
|
|
@@ -11038,6 +12435,7 @@ async function runStdioServer(options) {
|
|
|
11038
12435
|
});
|
|
11039
12436
|
return writeChain;
|
|
11040
12437
|
};
|
|
12438
|
+
const MAX_IN_FLIGHT = 4;
|
|
11041
12439
|
let inFlight = 0;
|
|
11042
12440
|
let inputEnded = false;
|
|
11043
12441
|
let resolveDone = () => void 0;
|
|
@@ -11058,9 +12456,31 @@ async function runStdioServer(options) {
|
|
|
11058
12456
|
const response = await server.handle(message);
|
|
11059
12457
|
if (response) await send(response);
|
|
11060
12458
|
};
|
|
12459
|
+
const rejectOverloaded = (line) => {
|
|
12460
|
+
let id = null;
|
|
12461
|
+
try {
|
|
12462
|
+
const parsed = JSON.parse(line);
|
|
12463
|
+
if (!isJsonObject(parsed)) return;
|
|
12464
|
+
if (typeof parsed.id === "string" || typeof parsed.id === "number") id = parsed.id;
|
|
12465
|
+
else return;
|
|
12466
|
+
} catch {
|
|
12467
|
+
return;
|
|
12468
|
+
}
|
|
12469
|
+
void send(
|
|
12470
|
+
errorResponse(
|
|
12471
|
+
id,
|
|
12472
|
+
ERROR_CODES.overloaded,
|
|
12473
|
+
`The server is already handling ${MAX_IN_FLIGHT} requests; retry this one when it is free.`
|
|
12474
|
+
)
|
|
12475
|
+
);
|
|
12476
|
+
};
|
|
11061
12477
|
const stopReading = createLineReader(process.stdin, {
|
|
11062
12478
|
onOverflow: (bytes) => log(`mcp: discarded an oversized message (${bytes} bytes)`),
|
|
11063
12479
|
onLine: (line) => {
|
|
12480
|
+
if (inFlight >= MAX_IN_FLIGHT) {
|
|
12481
|
+
rejectOverloaded(line);
|
|
12482
|
+
return;
|
|
12483
|
+
}
|
|
11064
12484
|
inFlight += 1;
|
|
11065
12485
|
void handleLine(line).finally(() => {
|
|
11066
12486
|
inFlight -= 1;
|