codebase-snapshot 0.20.5 → 0.20.7
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 +65 -0
- package/README.md +1 -1
- package/dist/bin.js +1532 -1037
- package/dist/{chunk-C3WVC4FV.js → chunk-RSWAYB6U.js} +1194 -776
- package/dist/{chunk-HYTY6T7P.js → chunk-UIF7U77H.js} +32 -8
- package/dist/cli.cjs +1557 -1059
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +73 -19
- package/dist/{generate-worker-CNRsO_z7.d.cts → generate-worker-CkWFKtf0.d.ts} +6 -0
- package/dist/{generate-worker-CNRsO_z7.d.ts → generate-worker-Wne8FzN5.d.cts} +6 -0
- package/dist/index.cjs +1178 -772
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +470 -180
- package/dist/mcp.d.cts +2 -1
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-DnYsA6_Y.d.cts → types-CykWdR6V.d.cts} +2 -0
- package/dist/{types-DnYsA6_Y.d.ts → types-CykWdR6V.d.ts} +2 -0
- package/docs/cli.md +5 -5
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +4 -4
- package/package.json +8 -3
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var worker_threads = require('worker_threads');
|
|
5
5
|
var async_hooks = require('async_hooks');
|
|
6
|
-
var
|
|
6
|
+
var fs24 = require('fs');
|
|
7
7
|
var os2 = require('os');
|
|
8
|
-
var
|
|
8
|
+
var path25 = require('path');
|
|
9
9
|
var ts = require('typescript');
|
|
10
10
|
var module$1 = require('module');
|
|
11
11
|
var url = require('url');
|
|
@@ -37,9 +37,9 @@ function _interopNamespace(e) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
40
|
-
var
|
|
40
|
+
var fs24__namespace = /*#__PURE__*/_interopNamespace(fs24);
|
|
41
41
|
var os2__namespace = /*#__PURE__*/_interopNamespace(os2);
|
|
42
|
-
var
|
|
42
|
+
var path25__namespace = /*#__PURE__*/_interopNamespace(path25);
|
|
43
43
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
44
44
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
45
45
|
var http__namespace = /*#__PURE__*/_interopNamespace(http);
|
|
@@ -134,7 +134,7 @@ function finalizeSummary(summary) {
|
|
|
134
134
|
}
|
|
135
135
|
function eachLine(content, visit) {
|
|
136
136
|
const text2 = content.length > MAX_SUMMARY_CHARS ? content.slice(0, MAX_SUMMARY_CHARS) : content;
|
|
137
|
-
for (const line of text2.split(/\r
|
|
137
|
+
for (const line of text2.split(/\r\n|\n|\r/)) visit(line);
|
|
138
138
|
}
|
|
139
139
|
function isTopLevel(line) {
|
|
140
140
|
return !/^[\s]/.test(line);
|
|
@@ -414,9 +414,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
414
414
|
var jvmProfile = {
|
|
415
415
|
id: "jvm",
|
|
416
416
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
417
|
-
summarize(
|
|
417
|
+
summarize(path26, content) {
|
|
418
418
|
const summary = emptySummary();
|
|
419
|
-
const lower =
|
|
419
|
+
const lower = path26.toLowerCase();
|
|
420
420
|
const isJava = lower.endsWith(".java");
|
|
421
421
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
422
422
|
eachLine(content, (line) => {
|
|
@@ -825,7 +825,7 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
825
825
|
routeHandlers: []
|
|
826
826
|
};
|
|
827
827
|
const lowerPath = relativePath.toLowerCase();
|
|
828
|
-
const scriptKind2 =
|
|
828
|
+
const scriptKind2 = /\.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;
|
|
829
829
|
const sourceFile = ts__default.default.createSourceFile(
|
|
830
830
|
relativePath,
|
|
831
831
|
content,
|
|
@@ -1024,17 +1024,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
1024
1024
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
1025
1025
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
1026
1026
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
1027
|
-
function componentName(
|
|
1028
|
-
const base =
|
|
1027
|
+
function componentName(path26) {
|
|
1028
|
+
const base = path26.split("/").pop() ?? path26;
|
|
1029
1029
|
return base.replace(/\.[^.]+$/, "");
|
|
1030
1030
|
}
|
|
1031
1031
|
var sfcProfile = {
|
|
1032
1032
|
id: "sfc",
|
|
1033
1033
|
extensions: [".vue", ".svelte", ".astro"],
|
|
1034
|
-
summarize(
|
|
1034
|
+
summarize(path26, content) {
|
|
1035
1035
|
let script = "";
|
|
1036
|
-
let usesJsx =
|
|
1037
|
-
if (
|
|
1036
|
+
let usesJsx = path26.toLowerCase().endsWith(".astro");
|
|
1037
|
+
if (path26.toLowerCase().endsWith(".astro")) {
|
|
1038
1038
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
1039
1039
|
if (frontmatter) script += `${frontmatter[1]}
|
|
1040
1040
|
`;
|
|
@@ -1044,7 +1044,7 @@ var sfcProfile = {
|
|
|
1044
1044
|
script += `${match[2]}
|
|
1045
1045
|
`;
|
|
1046
1046
|
}
|
|
1047
|
-
const name = componentName(
|
|
1047
|
+
const name = componentName(path26);
|
|
1048
1048
|
if (!script.trim()) {
|
|
1049
1049
|
const summary2 = emptySummary();
|
|
1050
1050
|
if (name) {
|
|
@@ -1235,15 +1235,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
1235
1235
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
1236
1236
|
}
|
|
1237
1237
|
}
|
|
1238
|
-
function profileForPath(
|
|
1239
|
-
const lower =
|
|
1238
|
+
function profileForPath(path26) {
|
|
1239
|
+
const lower = path26.toLowerCase();
|
|
1240
1240
|
const dot = lower.lastIndexOf(".");
|
|
1241
1241
|
if (dot === -1) return null;
|
|
1242
1242
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
1243
1243
|
}
|
|
1244
|
-
function summarizeWithProfile(
|
|
1245
|
-
const profile = profileForPath(
|
|
1246
|
-
return profile ? profile.summarize(
|
|
1244
|
+
function summarizeWithProfile(path26, content) {
|
|
1245
|
+
const profile = profileForPath(path26);
|
|
1246
|
+
return profile ? profile.summarize(path26, content) : null;
|
|
1247
1247
|
}
|
|
1248
1248
|
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1249
1249
|
".png",
|
|
@@ -1288,7 +1288,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1288
1288
|
".so"
|
|
1289
1289
|
]);
|
|
1290
1290
|
function isBinaryExtension(filePath) {
|
|
1291
|
-
const ext =
|
|
1291
|
+
const ext = path25__namespace.extname(filePath).toLowerCase();
|
|
1292
1292
|
return BINARY_EXTENSIONS.has(ext);
|
|
1293
1293
|
}
|
|
1294
1294
|
function isBinaryBuffer(buffer) {
|
|
@@ -1417,17 +1417,17 @@ function decodeText(buffer) {
|
|
|
1417
1417
|
};
|
|
1418
1418
|
}
|
|
1419
1419
|
const invalidBytes = countInvalidUtf8Bytes(buffer);
|
|
1420
|
+
const controlBytes = countControlBytes(buffer);
|
|
1421
|
+
if (controlBytes > CONTROL_BYTES_FLOOR && controlBytes * 100 > buffer.length) {
|
|
1422
|
+
return {
|
|
1423
|
+
text: "",
|
|
1424
|
+
encoding: "utf-8",
|
|
1425
|
+
invalidBytes,
|
|
1426
|
+
binary: true,
|
|
1427
|
+
binaryReason: `${controlBytes} control byte(s) in ${buffer.length} B; not text`
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1420
1430
|
if (invalidBytes === 0) {
|
|
1421
|
-
const controlBytes = countControlBytes(buffer);
|
|
1422
|
-
if (controlBytes > CONTROL_BYTES_FLOOR && controlBytes * 100 > buffer.length) {
|
|
1423
|
-
return {
|
|
1424
|
-
text: "",
|
|
1425
|
-
encoding: "utf-8",
|
|
1426
|
-
invalidBytes: 0,
|
|
1427
|
-
binary: true,
|
|
1428
|
-
binaryReason: `${controlBytes} control byte(s) in ${buffer.length} B; valid UTF-8 but not text`
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
1431
|
return {
|
|
1432
1432
|
text: new TextDecoder("utf-8").decode(buffer),
|
|
1433
1433
|
encoding: "utf-8",
|
|
@@ -1458,13 +1458,13 @@ function isBinaryFile(absolutePath) {
|
|
|
1458
1458
|
if (isBinaryExtension(absolutePath)) return true;
|
|
1459
1459
|
let fd;
|
|
1460
1460
|
try {
|
|
1461
|
-
fd =
|
|
1461
|
+
fd = fs24__namespace.openSync(absolutePath, "r");
|
|
1462
1462
|
const buffer = Buffer.alloc(CHUNK);
|
|
1463
1463
|
let sample2;
|
|
1464
1464
|
let position = 0;
|
|
1465
1465
|
while (position < BINARY_SCAN_BYTES) {
|
|
1466
1466
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
1467
|
-
const bytesRead =
|
|
1467
|
+
const bytesRead = fs24__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
1468
1468
|
if (bytesRead === 0) return false;
|
|
1469
1469
|
const chunk = buffer.subarray(0, bytesRead);
|
|
1470
1470
|
if (sample2 === void 0) {
|
|
@@ -1482,7 +1482,7 @@ function isBinaryFile(absolutePath) {
|
|
|
1482
1482
|
} finally {
|
|
1483
1483
|
if (fd !== void 0) {
|
|
1484
1484
|
try {
|
|
1485
|
-
|
|
1485
|
+
fs24__namespace.closeSync(fd);
|
|
1486
1486
|
} catch {
|
|
1487
1487
|
}
|
|
1488
1488
|
}
|
|
@@ -1504,9 +1504,9 @@ function importsOfText(relativePath, text2) {
|
|
|
1504
1504
|
function importsOfFile(relativePath, absolutePath) {
|
|
1505
1505
|
let buffer;
|
|
1506
1506
|
try {
|
|
1507
|
-
const stats =
|
|
1507
|
+
const stats = fs24__namespace.statSync(absolutePath);
|
|
1508
1508
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
1509
|
-
buffer =
|
|
1509
|
+
buffer = fs24__namespace.readFileSync(absolutePath);
|
|
1510
1510
|
} catch {
|
|
1511
1511
|
return [];
|
|
1512
1512
|
}
|
|
@@ -1726,9 +1726,15 @@ function skeletonizeTypeScript(source, fileName = "file.ts") {
|
|
|
1726
1726
|
if (end > start) spans.push({ start, end });
|
|
1727
1727
|
}
|
|
1728
1728
|
}
|
|
1729
|
-
ts__default.default.forEachChild(node, visit);
|
|
1730
1729
|
};
|
|
1731
|
-
|
|
1730
|
+
const stack = [sourceFile];
|
|
1731
|
+
while (stack.length > 0) {
|
|
1732
|
+
const node = stack.pop();
|
|
1733
|
+
visit(node);
|
|
1734
|
+
ts__default.default.forEachChild(node, (child) => {
|
|
1735
|
+
stack.push(child);
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1732
1738
|
if (spans.length === 0) return { text: source, collapsed: 0 };
|
|
1733
1739
|
const outermost = [];
|
|
1734
1740
|
for (const span of spans.sort((a, b) => a.start - b.start || b.end - a.end)) {
|
|
@@ -1885,20 +1891,20 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
1885
1891
|
]);
|
|
1886
1892
|
function readSmallFile(fullPath) {
|
|
1887
1893
|
try {
|
|
1888
|
-
const stats =
|
|
1894
|
+
const stats = fs24__namespace.statSync(fullPath);
|
|
1889
1895
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
1890
|
-
return
|
|
1896
|
+
return fs24__namespace.readFileSync(fullPath, "utf8");
|
|
1891
1897
|
} catch {
|
|
1892
1898
|
return null;
|
|
1893
1899
|
}
|
|
1894
1900
|
}
|
|
1895
1901
|
function readManifest(cwd, name) {
|
|
1896
|
-
return readSmallFile(
|
|
1902
|
+
return readSmallFile(path25__namespace.join(cwd, name));
|
|
1897
1903
|
}
|
|
1898
1904
|
function dependenciesFromPackageJson(raw) {
|
|
1899
1905
|
const names = /* @__PURE__ */ new Set();
|
|
1900
1906
|
try {
|
|
1901
|
-
const parsed = JSON.parse(raw);
|
|
1907
|
+
const parsed = JSON.parse(stripJsonComments(raw.replace(/^\uFEFF/, "")));
|
|
1902
1908
|
for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
1903
1909
|
const block = parsed[section];
|
|
1904
1910
|
if (block && typeof block === "object") {
|
|
@@ -1953,7 +1959,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
1953
1959
|
function childDirectories(cwd, parent) {
|
|
1954
1960
|
let entries;
|
|
1955
1961
|
try {
|
|
1956
|
-
entries =
|
|
1962
|
+
entries = fs24__namespace.readdirSync(path25__namespace.join(cwd, parent), { withFileTypes: true });
|
|
1957
1963
|
} catch {
|
|
1958
1964
|
return [];
|
|
1959
1965
|
}
|
|
@@ -1989,12 +1995,12 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
1989
1995
|
const files = /* @__PURE__ */ new Set();
|
|
1990
1996
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1991
1997
|
for (const relative15 of workspacePackageDirs(cwd, patterns)) {
|
|
1992
|
-
const full =
|
|
1998
|
+
const full = path25__namespace.join(cwd, relative15);
|
|
1993
1999
|
try {
|
|
1994
|
-
for (const entry of
|
|
2000
|
+
for (const entry of fs24__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
1995
2001
|
} catch {
|
|
1996
2002
|
}
|
|
1997
|
-
const raw = readSmallFile(
|
|
2003
|
+
const raw = readSmallFile(path25__namespace.join(full, "package.json"));
|
|
1998
2004
|
if (raw !== null) {
|
|
1999
2005
|
for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
|
|
2000
2006
|
}
|
|
@@ -2004,7 +2010,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
2004
2010
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
2005
2011
|
function isToolOwnedDirectory(dir) {
|
|
2006
2012
|
try {
|
|
2007
|
-
return
|
|
2013
|
+
return fs24__namespace.statSync(dir).isDirectory() && fs24__namespace.existsSync(path25__namespace.join(dir, SNAPSHOT_MARKER));
|
|
2008
2014
|
} catch {
|
|
2009
2015
|
return false;
|
|
2010
2016
|
}
|
|
@@ -2019,7 +2025,7 @@ function countMarkdownFiles(cwd) {
|
|
|
2019
2025
|
directoriesSeen += 1;
|
|
2020
2026
|
let entries;
|
|
2021
2027
|
try {
|
|
2022
|
-
entries =
|
|
2028
|
+
entries = fs24__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
2023
2029
|
} catch {
|
|
2024
2030
|
continue;
|
|
2025
2031
|
}
|
|
@@ -2030,7 +2036,7 @@ function countMarkdownFiles(cwd) {
|
|
|
2030
2036
|
}
|
|
2031
2037
|
if (!entry.isDirectory() || current.depth >= 2) continue;
|
|
2032
2038
|
if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
|
|
2033
|
-
const child =
|
|
2039
|
+
const child = path25__namespace.join(current.dir, entry.name);
|
|
2034
2040
|
if (isToolOwnedDirectory(child)) continue;
|
|
2035
2041
|
queue.push({ dir: child, depth: current.depth + 1 });
|
|
2036
2042
|
}
|
|
@@ -2041,7 +2047,7 @@ function buildPresetContext(cwd) {
|
|
|
2041
2047
|
const files = /* @__PURE__ */ new Set();
|
|
2042
2048
|
const dirs = /* @__PURE__ */ new Set();
|
|
2043
2049
|
try {
|
|
2044
|
-
for (const entry of
|
|
2050
|
+
for (const entry of fs24__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
2045
2051
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
2046
2052
|
else if (entry.isFile()) files.add(entry.name);
|
|
2047
2053
|
}
|
|
@@ -2058,7 +2064,7 @@ function buildPresetContext(cwd) {
|
|
|
2058
2064
|
const isWorkspace = files.has("pnpm-workspace.yaml") || files.has("nx.json") || files.has("turbo.json") || files.has("lerna.json") || packageJson !== void 0 && packageJson.includes('"workspaces"') || declaredWorkspaces.length > 0;
|
|
2059
2065
|
let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
|
|
2060
2066
|
if (isWorkspace) {
|
|
2061
|
-
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(
|
|
2067
|
+
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path25__namespace.join(cwd, "pnpm-workspace.yaml")) : null;
|
|
2062
2068
|
const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
|
|
2063
2069
|
const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
|
|
2064
2070
|
workspace = scanWorkspacePackages(cwd, patterns);
|
|
@@ -3797,7 +3803,7 @@ function redactStructuredValues(text2, filePath, recordFinding) {
|
|
|
3797
3803
|
}
|
|
3798
3804
|
return segments.join("");
|
|
3799
3805
|
}
|
|
3800
|
-
var DOCKERFILE_ENV = /^([ \t]*ENV[ \t]+)([A-Za-z_][A-Za-z0-9_]*)([ \t]+)(\S.*)
|
|
3806
|
+
var DOCKERFILE_ENV = /^([ \t]*)(ENV|ARG)([ \t]+)([A-Za-z_][A-Za-z0-9_]*)([ \t]*=[ \t]*|[ \t]+)(\S.*)$/i;
|
|
3801
3807
|
function redactDockerfileEnv(text2, filePath, recordFinding) {
|
|
3802
3808
|
if (!isDockerfile(filePath)) return text2;
|
|
3803
3809
|
const segments = text2.split(LINE_BREAK);
|
|
@@ -3806,10 +3812,9 @@ function redactDockerfileEnv(text2, filePath, recordFinding) {
|
|
|
3806
3812
|
if (line === void 0) continue;
|
|
3807
3813
|
const match = DOCKERFILE_ENV.exec(line);
|
|
3808
3814
|
if (match === null) continue;
|
|
3809
|
-
if (!CREDENTIAL_KEY_TAIL.test(match[
|
|
3810
|
-
const
|
|
3811
|
-
|
|
3812
|
-
segments[index] = `${match[1]}${match[2]}${match[3]}${REDACTION_MARKER}`;
|
|
3815
|
+
if (!CREDENTIAL_KEY_TAIL.test(match[4] ?? "")) continue;
|
|
3816
|
+
const separator = match[5] ?? "";
|
|
3817
|
+
segments[index] = `${match[1]}${match[2]}${match[3]}${match[4]}${separator}${REDACTION_MARKER}`;
|
|
3813
3818
|
recordFinding(index / 2 + 1, ["dockerfile-env-secret"]);
|
|
3814
3819
|
}
|
|
3815
3820
|
return segments.join("");
|
|
@@ -3894,6 +3899,7 @@ function isSourceCodeFile(filePath) {
|
|
|
3894
3899
|
var PLACEHOLDER_PATTERNS = [
|
|
3895
3900
|
/^<[^>]*>?$/,
|
|
3896
3901
|
/^\.{3,}$/,
|
|
3902
|
+
/^(?:[A-Za-z0-9_-]{1,8}-)?\.{3,}$/,
|
|
3897
3903
|
/^(?:x{4,}|X{4,}|\*{3,})$/,
|
|
3898
3904
|
/^(?:replace|change)[-_ ]?me(?:[-_ ].*)?$/i,
|
|
3899
3905
|
/^your[-_ ].*$/i,
|
|
@@ -3907,7 +3913,7 @@ function isPlaceholderValue(value) {
|
|
|
3907
3913
|
if (trimmed.length === 0) return false;
|
|
3908
3914
|
if (PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
|
|
3909
3915
|
if (trimmed.includes(REDACTION_MARKER) || trimmed.includes(PEM_REDACTION_MARKER)) return true;
|
|
3910
|
-
return
|
|
3916
|
+
return false;
|
|
3911
3917
|
}
|
|
3912
3918
|
function quotesAreBalanced(text2) {
|
|
3913
3919
|
let single = 0;
|
|
@@ -3959,6 +3965,7 @@ var ASSIGNMENT_FILE = /\.(?:sh|bash|zsh|ksh|fish|env|ya?ml|toml|ini|conf|cfg|pro
|
|
|
3959
3965
|
var ASSIGNMENT_BASENAME = /^(?:\.env(?:\.[^/]*)?|\.envrc|\.profile|\.bashrc|\.zshrc|\.bash_profile)$/i;
|
|
3960
3966
|
function isAssignmentFile(filePath) {
|
|
3961
3967
|
if (filePath === void 0) return false;
|
|
3968
|
+
if (isDockerfile(filePath)) return true;
|
|
3962
3969
|
const normalised = filePath.replace(/\\/g, "/");
|
|
3963
3970
|
if (ASSIGNMENT_FILE.test(normalised)) return true;
|
|
3964
3971
|
const base = normalised.slice(normalised.lastIndexOf("/") + 1);
|
|
@@ -4020,7 +4027,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
4020
4027
|
}
|
|
4021
4028
|
var SIGNATURE_FILE = "signature.json";
|
|
4022
4029
|
function signManifest(manifestPath, options = {}) {
|
|
4023
|
-
const bytes =
|
|
4030
|
+
const bytes = fs24__namespace.readFileSync(manifestPath);
|
|
4024
4031
|
const manifest = JSON.parse(bytes.toString("utf8"));
|
|
4025
4032
|
if (typeof manifest.fingerprint !== "string" || !/^[0-9a-f]{64}$/.test(manifest.fingerprint)) {
|
|
4026
4033
|
throw new Error("refusing to sign: the manifest has no valid fingerprint");
|
|
@@ -4040,12 +4047,12 @@ function signManifest(manifestPath, options = {}) {
|
|
|
4040
4047
|
};
|
|
4041
4048
|
}
|
|
4042
4049
|
function verifySnapshotSignature(snapshotDir) {
|
|
4043
|
-
const signaturePath =
|
|
4044
|
-
const manifestPath =
|
|
4045
|
-
if (!
|
|
4050
|
+
const signaturePath = path25__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
4051
|
+
const manifestPath = path25__namespace.join(snapshotDir, "manifest.json");
|
|
4052
|
+
if (!fs24__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
4046
4053
|
let record;
|
|
4047
4054
|
try {
|
|
4048
|
-
record = JSON.parse(
|
|
4055
|
+
record = JSON.parse(fs24__namespace.readFileSync(signaturePath, "utf8"));
|
|
4049
4056
|
} catch (error) {
|
|
4050
4057
|
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
4051
4058
|
}
|
|
@@ -4054,7 +4061,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
4054
4061
|
}
|
|
4055
4062
|
let bytes;
|
|
4056
4063
|
try {
|
|
4057
|
-
bytes =
|
|
4064
|
+
bytes = fs24__namespace.readFileSync(manifestPath);
|
|
4058
4065
|
} catch {
|
|
4059
4066
|
return { ok: false, reason: "the signed manifest is missing" };
|
|
4060
4067
|
}
|
|
@@ -4062,6 +4069,15 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
4062
4069
|
if (sha2562 !== record.manifestSha256) {
|
|
4063
4070
|
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
4064
4071
|
}
|
|
4072
|
+
let signedFingerprint;
|
|
4073
|
+
try {
|
|
4074
|
+
signedFingerprint = JSON.parse(bytes.toString("utf8")).fingerprint;
|
|
4075
|
+
} catch {
|
|
4076
|
+
return { ok: false, reason: "the signed manifest is not JSON" };
|
|
4077
|
+
}
|
|
4078
|
+
if (typeof record.fingerprint !== "string" || record.fingerprint !== signedFingerprint) {
|
|
4079
|
+
return { ok: false, reason: "signature.json names a different fingerprint than the manifest" };
|
|
4080
|
+
}
|
|
4065
4081
|
let verified = false;
|
|
4066
4082
|
try {
|
|
4067
4083
|
const key = crypto__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
@@ -4074,7 +4090,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
4074
4090
|
|
|
4075
4091
|
// src/version.ts
|
|
4076
4092
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
4077
|
-
var GENERATOR_VERSION = "0.20.
|
|
4093
|
+
var GENERATOR_VERSION = "0.20.7";
|
|
4078
4094
|
var SCHEMA_VERSION = "3.0.0";
|
|
4079
4095
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
4080
4096
|
function isOurGeneratorName(name) {
|
|
@@ -4091,14 +4107,14 @@ var PRESET_IGNORES = new Set(
|
|
|
4091
4107
|
);
|
|
4092
4108
|
function readLinkTarget(linkPath, fallback) {
|
|
4093
4109
|
try {
|
|
4094
|
-
return
|
|
4110
|
+
return fs24__namespace.readlinkSync(linkPath);
|
|
4095
4111
|
} catch {
|
|
4096
4112
|
return fallback;
|
|
4097
4113
|
}
|
|
4098
4114
|
}
|
|
4099
4115
|
function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
4100
4116
|
const rawTarget = readLinkTarget(linkPath, linkPath);
|
|
4101
|
-
const resolvedFallback =
|
|
4117
|
+
const resolvedFallback = path25__namespace.resolve(path25__namespace.dirname(linkPath), rawTarget);
|
|
4102
4118
|
return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
|
|
4103
4119
|
path: relativePath,
|
|
4104
4120
|
reason: "outside-root",
|
|
@@ -4106,8 +4122,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
4106
4122
|
};
|
|
4107
4123
|
}
|
|
4108
4124
|
function isInside(root, candidate) {
|
|
4109
|
-
const relative15 =
|
|
4110
|
-
return relative15 === "" || !relative15.startsWith(`..${
|
|
4125
|
+
const relative15 = path25__namespace.relative(root, candidate);
|
|
4126
|
+
return relative15 === "" || !relative15.startsWith(`..${path25__namespace.sep}`) && relative15 !== ".." && !path25__namespace.isAbsolute(relative15);
|
|
4111
4127
|
}
|
|
4112
4128
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
4113
4129
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -4173,7 +4189,7 @@ var DEFAULT_IGNORED_FILES = [
|
|
|
4173
4189
|
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;
|
|
4174
4190
|
var SENSITIVE_PATH = /(?:^|\/)\.(?:aws|ssh|gnupg)\/|(?:^|\/)\.docker\/config\.json$|(?:^|\/)\.kube\/config$|(?:^|\/)\.config\/gcloud\/|(?:^|\/)\.composer\/|(?:^|\/)\.terraform\/credentials\.tfrc\.json$/i;
|
|
4175
4191
|
var SENSITIVE_EXT = /\.(?:pem|key|p12|pfx|jks|keystore|ppk|asc|kdbx|tfstate|tfvars)$/i;
|
|
4176
|
-
var TEMPLATE_SUFFIX = /^(.*)\.(?:example|sample|template|dist)(\.
|
|
4192
|
+
var TEMPLATE_SUFFIX = /^(.*)\.(?:example|sample|template|dist)(\.(?:json|ya?ml|toml|ini|txt|md|properties|conf|cfg))?$/i;
|
|
4177
4193
|
var BACKUP_SUFFIX = /(?:~|\.(?:bak|backup|old|orig|save|copy|swp|swo|tmp|part))$/i;
|
|
4178
4194
|
function normaliseName(name) {
|
|
4179
4195
|
let normalised = name.trim().replace(/[. ]+$/, "");
|
|
@@ -4367,10 +4383,10 @@ function trimUnescapedTrailingSpaces(line) {
|
|
|
4367
4383
|
return line.slice(0, end);
|
|
4368
4384
|
}
|
|
4369
4385
|
function readGitignoreRules(dir) {
|
|
4370
|
-
const gitignorePath2 =
|
|
4386
|
+
const gitignorePath2 = path25__namespace.join(dir, ".gitignore");
|
|
4371
4387
|
let raw;
|
|
4372
4388
|
try {
|
|
4373
|
-
raw =
|
|
4389
|
+
raw = fs24__namespace.readFileSync(gitignorePath2, "utf8");
|
|
4374
4390
|
} catch {
|
|
4375
4391
|
return [];
|
|
4376
4392
|
}
|
|
@@ -4581,7 +4597,7 @@ function listIgnoredPaths(cwd) {
|
|
|
4581
4597
|
}
|
|
4582
4598
|
function hasSnapshotMarker(target) {
|
|
4583
4599
|
try {
|
|
4584
|
-
return
|
|
4600
|
+
return fs24__namespace.statSync(target).isDirectory() && isToolOwnedDirectory2(target);
|
|
4585
4601
|
} catch {
|
|
4586
4602
|
return false;
|
|
4587
4603
|
}
|
|
@@ -4590,7 +4606,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
4590
4606
|
function isToolOwnedDirectory2(dir) {
|
|
4591
4607
|
let raw;
|
|
4592
4608
|
try {
|
|
4593
|
-
raw =
|
|
4609
|
+
raw = fs24__namespace.readFileSync(path25__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
4594
4610
|
} catch {
|
|
4595
4611
|
return false;
|
|
4596
4612
|
}
|
|
@@ -4602,30 +4618,67 @@ function isToolOwnedDirectory2(dir) {
|
|
|
4602
4618
|
}
|
|
4603
4619
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
4604
4620
|
const marker2 = parsed;
|
|
4605
|
-
if (marker2.generator !== GENERATOR_NAME || marker2.state !== "complete" || typeof marker2.id !== "string" || !Array.isArray(marker2.files)) {
|
|
4621
|
+
if (marker2.generator !== GENERATOR_NAME || marker2.state !== "complete" || marker2.schemaVersion !== SCHEMA_VERSION || typeof marker2.id !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(marker2.id) || typeof marker2.manifestSha256 !== "string" || !Array.isArray(marker2.files)) {
|
|
4606
4622
|
return false;
|
|
4607
4623
|
}
|
|
4608
|
-
|
|
4624
|
+
let manifestBytes;
|
|
4625
|
+
try {
|
|
4626
|
+
manifestBytes = fs24__namespace.readFileSync(path25__namespace.join(dir, "manifest.json"));
|
|
4627
|
+
} catch {
|
|
4628
|
+
return false;
|
|
4629
|
+
}
|
|
4630
|
+
if (crypto.createHash("sha256").update(manifestBytes).digest("hex") !== marker2.manifestSha256) {
|
|
4631
|
+
return false;
|
|
4632
|
+
}
|
|
4633
|
+
const recordedFiles = /* @__PURE__ */ new Set();
|
|
4609
4634
|
for (const item of marker2.files) {
|
|
4610
4635
|
if (!item || typeof item !== "object" || Array.isArray(item)) return false;
|
|
4611
|
-
const
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4636
|
+
const record = item;
|
|
4637
|
+
const entry = record.path;
|
|
4638
|
+
if (typeof entry !== "string" || entry.length === 0 || entry.includes(String.fromCharCode(92)) || entry.includes("\0") || path25__namespace.isAbsolute(entry) || entry.split("/").includes("..") || typeof record.bytes !== "number" || !Number.isSafeInteger(record.bytes) || record.bytes < 0 || typeof record.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(record.sha256)) {
|
|
4639
|
+
return false;
|
|
4640
|
+
}
|
|
4641
|
+
const full = path25__namespace.join(dir, ...entry.split("/"));
|
|
4642
|
+
let stats;
|
|
4643
|
+
try {
|
|
4644
|
+
stats = fs24__namespace.lstatSync(full);
|
|
4645
|
+
} catch {
|
|
4646
|
+
return false;
|
|
4616
4647
|
}
|
|
4648
|
+
if (!stats.isFile() || stats.size !== record.bytes) return false;
|
|
4649
|
+
let digest;
|
|
4650
|
+
try {
|
|
4651
|
+
digest = crypto.createHash("sha256").update(fs24__namespace.readFileSync(full)).digest("hex");
|
|
4652
|
+
} catch {
|
|
4653
|
+
return false;
|
|
4654
|
+
}
|
|
4655
|
+
if (digest !== record.sha256) return false;
|
|
4656
|
+
recordedFiles.add(entry);
|
|
4617
4657
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4658
|
+
const stack = [""];
|
|
4659
|
+
while (stack.length > 0) {
|
|
4660
|
+
const current = stack.pop();
|
|
4661
|
+
let entries;
|
|
4662
|
+
try {
|
|
4663
|
+
entries = fs24__namespace.readdirSync(path25__namespace.join(dir, current), { withFileTypes: true });
|
|
4664
|
+
} catch {
|
|
4665
|
+
return false;
|
|
4666
|
+
}
|
|
4667
|
+
for (const entry of entries) {
|
|
4668
|
+
const relative15 = current === "" ? entry.name : current + "/" + entry.name;
|
|
4669
|
+
if (relative15 === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry.name)) continue;
|
|
4670
|
+
if (entry.isDirectory()) {
|
|
4671
|
+
stack.push(relative15);
|
|
4672
|
+
continue;
|
|
4673
|
+
}
|
|
4674
|
+
if (!entry.isFile()) return false;
|
|
4675
|
+
if (relative15 === "signature.json" && !recordedFiles.has(relative15) && verifySnapshotSignature(dir).ok) {
|
|
4676
|
+
continue;
|
|
4677
|
+
}
|
|
4678
|
+
if (!recordedFiles.has(relative15)) return false;
|
|
4679
|
+
}
|
|
4623
4680
|
}
|
|
4624
|
-
return
|
|
4625
|
-
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) || // A snapshot signed before signing moved into staging has a valid signature.json the old
|
|
4626
|
-
// marker could not record. It is our artifact when the signature verifies.
|
|
4627
|
-
entry === "signature.json" && verifySnapshotSignature(dir).ok || accounted.has(entry)
|
|
4628
|
-
);
|
|
4681
|
+
return true;
|
|
4629
4682
|
}
|
|
4630
4683
|
function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
4631
4684
|
const markers = /* @__PURE__ */ new Map();
|
|
@@ -4636,7 +4689,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
|
4636
4689
|
const prefix = parts.slice(0, depth).join("/");
|
|
4637
4690
|
let hasMarker = markers.get(prefix);
|
|
4638
4691
|
if (hasMarker === void 0) {
|
|
4639
|
-
hasMarker = isToolOwnedDirectory2(
|
|
4692
|
+
hasMarker = isToolOwnedDirectory2(path25__namespace.join(cwd, prefix));
|
|
4640
4693
|
markers.set(prefix, hasMarker);
|
|
4641
4694
|
}
|
|
4642
4695
|
if (hasMarker) return true;
|
|
@@ -4651,7 +4704,7 @@ function makeLinkProbe() {
|
|
|
4651
4704
|
let known = cache.get(absolutePath);
|
|
4652
4705
|
if (known === void 0) {
|
|
4653
4706
|
try {
|
|
4654
|
-
known =
|
|
4707
|
+
known = fs24__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
4655
4708
|
} catch {
|
|
4656
4709
|
known = false;
|
|
4657
4710
|
}
|
|
@@ -4664,7 +4717,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4664
4717
|
const isLink = makeLinkProbe();
|
|
4665
4718
|
let rootReal = cwd;
|
|
4666
4719
|
try {
|
|
4667
|
-
rootReal =
|
|
4720
|
+
rootReal = fs24__namespace.realpathSync(cwd);
|
|
4668
4721
|
} catch {
|
|
4669
4722
|
}
|
|
4670
4723
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -4679,7 +4732,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4679
4732
|
let linkedPath = null;
|
|
4680
4733
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
4681
4734
|
const prefix = parts.slice(0, depth).join("/");
|
|
4682
|
-
if (isLink(
|
|
4735
|
+
if (isLink(path25__namespace.join(cwd, prefix))) {
|
|
4683
4736
|
linkedPath = prefix;
|
|
4684
4737
|
break;
|
|
4685
4738
|
}
|
|
@@ -4688,11 +4741,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4688
4741
|
kept.push(candidate);
|
|
4689
4742
|
continue;
|
|
4690
4743
|
}
|
|
4691
|
-
const absolute =
|
|
4744
|
+
const absolute = path25__namespace.join(cwd, linkedPath);
|
|
4692
4745
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
4693
4746
|
let targetReal = null;
|
|
4694
4747
|
try {
|
|
4695
|
-
targetReal =
|
|
4748
|
+
targetReal = fs24__namespace.realpathSync(absolute);
|
|
4696
4749
|
} catch {
|
|
4697
4750
|
targetReal = null;
|
|
4698
4751
|
}
|
|
@@ -4710,7 +4763,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4710
4763
|
}
|
|
4711
4764
|
let stats = null;
|
|
4712
4765
|
try {
|
|
4713
|
-
stats =
|
|
4766
|
+
stats = fs24__namespace.statSync(absolute);
|
|
4714
4767
|
} catch {
|
|
4715
4768
|
stats = null;
|
|
4716
4769
|
}
|
|
@@ -4734,7 +4787,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4734
4787
|
});
|
|
4735
4788
|
continue;
|
|
4736
4789
|
}
|
|
4737
|
-
const targetRelative =
|
|
4790
|
+
const targetRelative = path25__namespace.relative(rootReal, targetReal).split(path25__namespace.sep).join("/");
|
|
4738
4791
|
if (isSensitivePath(targetRelative)) {
|
|
4739
4792
|
report2(linkedPath, {
|
|
4740
4793
|
path: linkedPath,
|
|
@@ -4807,7 +4860,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
4807
4860
|
"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."
|
|
4808
4861
|
);
|
|
4809
4862
|
}
|
|
4810
|
-
if (
|
|
4863
|
+
if (fs24__namespace.existsSync(path25__namespace.join(cwd, ".git"))) {
|
|
4811
4864
|
throw new Error(
|
|
4812
4865
|
"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."
|
|
4813
4866
|
);
|
|
@@ -4878,15 +4931,16 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
4878
4931
|
const aliases = /* @__PURE__ */ new Set();
|
|
4879
4932
|
for (const file of files) {
|
|
4880
4933
|
try {
|
|
4881
|
-
if (
|
|
4934
|
+
if (fs24__namespace.lstatSync(path25__namespace.join(cwd, file)).isSymbolicLink()) aliases.add(file);
|
|
4882
4935
|
} catch {
|
|
4883
4936
|
}
|
|
4884
4937
|
}
|
|
4885
4938
|
if (aliases.size === 0) return [...files];
|
|
4886
4939
|
const includedTargets = /* @__PURE__ */ new Set();
|
|
4887
4940
|
for (const file of files) {
|
|
4941
|
+
if (aliases.has(file)) continue;
|
|
4888
4942
|
try {
|
|
4889
|
-
includedTargets.add(
|
|
4943
|
+
includedTargets.add(fs24__namespace.realpathSync(path25__namespace.join(cwd, file)));
|
|
4890
4944
|
} catch {
|
|
4891
4945
|
}
|
|
4892
4946
|
}
|
|
@@ -4898,7 +4952,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
4898
4952
|
}
|
|
4899
4953
|
let target;
|
|
4900
4954
|
try {
|
|
4901
|
-
target =
|
|
4955
|
+
target = fs24__namespace.realpathSync(path25__namespace.join(cwd, file));
|
|
4902
4956
|
} catch {
|
|
4903
4957
|
skipped.push({ path: file, reason: "read-error", detail: "symlink target could not be resolved" });
|
|
4904
4958
|
continue;
|
|
@@ -4917,7 +4971,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
4917
4971
|
}
|
|
4918
4972
|
function rootRealFor(root) {
|
|
4919
4973
|
try {
|
|
4920
|
-
return
|
|
4974
|
+
return fs24__namespace.realpathSync(root);
|
|
4921
4975
|
} catch {
|
|
4922
4976
|
return root;
|
|
4923
4977
|
}
|
|
@@ -4926,18 +4980,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4926
4980
|
const results = { files: [], skipped: [] };
|
|
4927
4981
|
const stack = [];
|
|
4928
4982
|
const toolDirNames = toolDirNamesFor(reservedPaths);
|
|
4929
|
-
const relativeToBase = (target) =>
|
|
4983
|
+
const relativeToBase = (target) => path25__namespace.relative(baseDir, target).replace(/\\/g, "/") || ".";
|
|
4930
4984
|
const enter = (current, layers) => {
|
|
4931
4985
|
if (visited.has(current)) return false;
|
|
4932
4986
|
visited.add(current);
|
|
4933
4987
|
const localRules = readGitignoreRules(current);
|
|
4934
4988
|
const gitignoreLayers = localRules.length === 0 ? layers : [
|
|
4935
4989
|
...layers,
|
|
4936
|
-
{ prefix:
|
|
4990
|
+
{ prefix: path25__namespace.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
|
|
4937
4991
|
];
|
|
4938
4992
|
let entries;
|
|
4939
4993
|
try {
|
|
4940
|
-
entries =
|
|
4994
|
+
entries = fs24__namespace.readdirSync(current, { withFileTypes: true });
|
|
4941
4995
|
} catch {
|
|
4942
4996
|
results.skipped.push({
|
|
4943
4997
|
path: relativeToBase(current),
|
|
@@ -4959,8 +5013,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4959
5013
|
}
|
|
4960
5014
|
const entry = frame.entries[frame.index];
|
|
4961
5015
|
frame.index += 1;
|
|
4962
|
-
const fullPath =
|
|
4963
|
-
const relPath =
|
|
5016
|
+
const fullPath = path25__namespace.join(frame.dir, entry.name);
|
|
5017
|
+
const relPath = path25__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
4964
5018
|
if (reservedPaths.has(relPath)) continue;
|
|
4965
5019
|
if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
|
|
4966
5020
|
results.skipped.push({
|
|
@@ -4993,14 +5047,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4993
5047
|
if (entry.isSymbolicLink()) {
|
|
4994
5048
|
let targetReal;
|
|
4995
5049
|
try {
|
|
4996
|
-
targetReal =
|
|
5050
|
+
targetReal = fs24__namespace.realpathSync(fullPath);
|
|
4997
5051
|
} catch {
|
|
4998
5052
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
4999
5053
|
continue;
|
|
5000
5054
|
}
|
|
5001
5055
|
let stats;
|
|
5002
5056
|
try {
|
|
5003
|
-
stats =
|
|
5057
|
+
stats = fs24__namespace.statSync(fullPath);
|
|
5004
5058
|
} catch {
|
|
5005
5059
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
5006
5060
|
continue;
|
|
@@ -5030,7 +5084,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
5030
5084
|
});
|
|
5031
5085
|
continue;
|
|
5032
5086
|
}
|
|
5033
|
-
const targetRelative =
|
|
5087
|
+
const targetRelative = path25__namespace.relative(rootReal, targetReal).split(path25__namespace.sep).join("/");
|
|
5034
5088
|
if (isSensitivePath(targetRelative)) {
|
|
5035
5089
|
results.skipped.push({
|
|
5036
5090
|
path: relPath,
|
|
@@ -5136,8 +5190,25 @@ function normalizeResolvedConfig(config) {
|
|
|
5136
5190
|
monolithWanted,
|
|
5137
5191
|
monolithWanted
|
|
5138
5192
|
);
|
|
5193
|
+
if (!Number.isSafeInteger(config.maxPartBytes) || config.maxPartBytes < MIN_MAX_PART_BYTES) {
|
|
5194
|
+
throw new Error(
|
|
5195
|
+
`maxPartBytes must be at least ${MIN_MAX_PART_BYTES} bytes (received ${String(config.maxPartBytes)}).`
|
|
5196
|
+
);
|
|
5197
|
+
}
|
|
5198
|
+
if (!Number.isSafeInteger(config.largeFileBytes) || config.largeFileBytes < 0) {
|
|
5199
|
+
throw new Error(
|
|
5200
|
+
`largeFileBytes must be a non-negative integer; received ${String(config.largeFileBytes)}.`
|
|
5201
|
+
);
|
|
5202
|
+
}
|
|
5203
|
+
const maxPartTokens = config.maxPartTokens ?? Math.floor(config.maxPartBytes / 4);
|
|
5204
|
+
if (!Number.isSafeInteger(maxPartTokens) || maxPartTokens < MIN_MAX_PART_TOKENS) {
|
|
5205
|
+
throw new Error(
|
|
5206
|
+
`maxPartTokens must be at least ${MIN_MAX_PART_TOKENS} tokens; received ${String(maxPartTokens)}.`
|
|
5207
|
+
);
|
|
5208
|
+
}
|
|
5139
5209
|
return markResolvedConfig({
|
|
5140
5210
|
...config,
|
|
5211
|
+
maxPartTokens,
|
|
5141
5212
|
discovery,
|
|
5142
5213
|
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
5143
5214
|
// is re-validated because the number reaches a rendered artifact.
|
|
@@ -5292,10 +5363,10 @@ function readConfigExport(exported, file) {
|
|
|
5292
5363
|
var lastModuleConfig = null;
|
|
5293
5364
|
function moduleConfigKey(fullPath) {
|
|
5294
5365
|
try {
|
|
5295
|
-
return crypto.createHash("sha256").update(
|
|
5366
|
+
return crypto.createHash("sha256").update(fs24__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
5296
5367
|
} catch {
|
|
5297
5368
|
try {
|
|
5298
|
-
const stats =
|
|
5369
|
+
const stats = fs24__namespace.statSync(fullPath);
|
|
5299
5370
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
5300
5371
|
} catch {
|
|
5301
5372
|
return "unreadable";
|
|
@@ -5321,7 +5392,7 @@ async function importConfigModule(fullPath) {
|
|
|
5321
5392
|
function attachConfigDir(config, filePath) {
|
|
5322
5393
|
if (typeof config === "object" && config !== null) {
|
|
5323
5394
|
Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
|
|
5324
|
-
value:
|
|
5395
|
+
value: path25__namespace.dirname(filePath),
|
|
5325
5396
|
enumerable: false,
|
|
5326
5397
|
configurable: true
|
|
5327
5398
|
});
|
|
@@ -5333,12 +5404,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5333
5404
|
const errors = [];
|
|
5334
5405
|
const configDirectories = [];
|
|
5335
5406
|
for (const filename of CONFIG_FILENAMES) {
|
|
5336
|
-
const fullPath =
|
|
5407
|
+
const fullPath = path25__namespace.join(cwd, filename);
|
|
5337
5408
|
let candidateStats = null;
|
|
5338
5409
|
try {
|
|
5339
|
-
candidateStats =
|
|
5410
|
+
candidateStats = fs24__namespace.statSync(fullPath);
|
|
5340
5411
|
} catch {
|
|
5341
|
-
if (!
|
|
5412
|
+
if (!fs24__namespace.existsSync(fullPath)) continue;
|
|
5342
5413
|
}
|
|
5343
5414
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
5344
5415
|
configDirectories.push(fullPath);
|
|
@@ -5346,7 +5417,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5346
5417
|
}
|
|
5347
5418
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
5348
5419
|
try {
|
|
5349
|
-
const config = parseJsonish(
|
|
5420
|
+
const config = parseJsonish(fs24__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
5350
5421
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
5351
5422
|
throw new Error(
|
|
5352
5423
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -5386,10 +5457,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5386
5457
|
continue;
|
|
5387
5458
|
}
|
|
5388
5459
|
}
|
|
5389
|
-
const pkgJsonPath =
|
|
5390
|
-
if (
|
|
5460
|
+
const pkgJsonPath = path25__namespace.join(cwd, "package.json");
|
|
5461
|
+
if (fs24__namespace.existsSync(pkgJsonPath)) {
|
|
5391
5462
|
try {
|
|
5392
|
-
const parsed = parseJsonish(
|
|
5463
|
+
const parsed = parseJsonish(fs24__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
5393
5464
|
const snapshotKey = parsed.snapshot;
|
|
5394
5465
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
5395
5466
|
assertKnownConfigKeys(
|
|
@@ -5564,27 +5635,27 @@ function readConfiguredBrief(cwd, value) {
|
|
|
5564
5635
|
}
|
|
5565
5636
|
const rootReal = (() => {
|
|
5566
5637
|
try {
|
|
5567
|
-
return
|
|
5638
|
+
return fs24__namespace.realpathSync(cwd);
|
|
5568
5639
|
} catch {
|
|
5569
|
-
return
|
|
5640
|
+
return path25__namespace.resolve(cwd);
|
|
5570
5641
|
}
|
|
5571
5642
|
})();
|
|
5572
|
-
const requested =
|
|
5643
|
+
const requested = path25__namespace.resolve(cwd, value);
|
|
5573
5644
|
let filePath;
|
|
5574
5645
|
try {
|
|
5575
|
-
filePath =
|
|
5646
|
+
filePath = fs24__namespace.realpathSync(requested);
|
|
5576
5647
|
} catch {
|
|
5577
5648
|
throw new Error(
|
|
5578
5649
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
5579
5650
|
);
|
|
5580
5651
|
}
|
|
5581
|
-
const relative15 =
|
|
5582
|
-
if (relative15.length === 0 || relative15 === ".." || relative15.startsWith(`..${
|
|
5652
|
+
const relative15 = path25__namespace.relative(rootReal, filePath);
|
|
5653
|
+
if (relative15.length === 0 || relative15 === ".." || relative15.startsWith(`..${path25__namespace.sep}`) || path25__namespace.isAbsolute(relative15)) {
|
|
5583
5654
|
throw new Error(
|
|
5584
5655
|
'brief "' + value + '" resolves outside the repository. A brief must be a file inside the repository being described; an absolute or parent path is refused.'
|
|
5585
5656
|
);
|
|
5586
5657
|
}
|
|
5587
|
-
const posixRelative = relative15.split(
|
|
5658
|
+
const posixRelative = relative15.split(path25__namespace.sep).join("/");
|
|
5588
5659
|
if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
|
|
5589
5660
|
throw new Error(
|
|
5590
5661
|
'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
|
|
@@ -5592,9 +5663,16 @@ function readConfiguredBrief(cwd, value) {
|
|
|
5592
5663
|
}
|
|
5593
5664
|
let text2;
|
|
5594
5665
|
try {
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5666
|
+
const stats = fs24__namespace.statSync(filePath);
|
|
5667
|
+
if (!stats.isFile()) throw new Error("not a file");
|
|
5668
|
+
if (stats.size > MAX_BRIEF_BYTES) {
|
|
5669
|
+
throw new Error(
|
|
5670
|
+
'brief "' + value + '" is ' + stats.size + " bytes; the limit is " + MAX_BRIEF_BYTES + ". Keep it to what a reader can act on, or move the detail into a document the snapshot carries."
|
|
5671
|
+
);
|
|
5672
|
+
}
|
|
5673
|
+
text2 = fs24__namespace.readFileSync(filePath, "utf8");
|
|
5674
|
+
} catch (error) {
|
|
5675
|
+
if (error instanceof Error && error.message.startsWith('brief "')) throw error;
|
|
5598
5676
|
throw new Error(
|
|
5599
5677
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
5600
5678
|
);
|
|
@@ -5705,9 +5783,9 @@ function resolveKindRules(value) {
|
|
|
5705
5783
|
function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
5706
5784
|
const patterns = [];
|
|
5707
5785
|
for (const dir of [outDir, tmpDir]) {
|
|
5708
|
-
const absolute =
|
|
5709
|
-
const relative15 =
|
|
5710
|
-
if (!relative15 || relative15 === ".." || relative15.startsWith(`..${
|
|
5786
|
+
const absolute = path25__namespace.resolve(cwd, dir);
|
|
5787
|
+
const relative15 = path25__namespace.relative(cwd, absolute);
|
|
5788
|
+
if (!relative15 || relative15 === ".." || relative15.startsWith(`..${path25__namespace.sep}`) || path25__namespace.isAbsolute(relative15)) {
|
|
5711
5789
|
continue;
|
|
5712
5790
|
}
|
|
5713
5791
|
patterns.push(`${relative15.replace(/\\/g, "/")}/**`);
|
|
@@ -5840,11 +5918,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
5840
5918
|
);
|
|
5841
5919
|
}
|
|
5842
5920
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
5843
|
-
const resolved =
|
|
5844
|
-
if (!
|
|
5921
|
+
const resolved = path25__namespace.resolve(candidate);
|
|
5922
|
+
if (!fs24__namespace.existsSync(resolved)) {
|
|
5845
5923
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
5846
5924
|
}
|
|
5847
|
-
if (!
|
|
5925
|
+
if (!fs24__namespace.statSync(resolved).isDirectory()) {
|
|
5848
5926
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
5849
5927
|
}
|
|
5850
5928
|
return resolved;
|
|
@@ -5997,7 +6075,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5997
6075
|
outDir,
|
|
5998
6076
|
tmpDir,
|
|
5999
6077
|
maxPartBytes: resolvedMaxPartBytes,
|
|
6000
|
-
|
|
6078
|
+
// Record the effective value even when the user did not set it. normalizeResolvedConfig
|
|
6079
|
+
// derives it for the manifest; leaving validate's fresh resolution unset made a clean
|
|
6080
|
+
// snapshot report a configuration mismatch.
|
|
6081
|
+
maxPartTokens: maxPartTokens ?? Math.floor(resolvedMaxPartBytes / 4),
|
|
6001
6082
|
largeFileBytes: largeFileBytesFor(resolvedMaxPartBytes, cliOptions, userConfig),
|
|
6002
6083
|
previewHeadLines: strictPositiveInteger(userConfig?.previewHeadLines, 80, "`previewHeadLines`"),
|
|
6003
6084
|
previewTailLines: strictPositiveInteger(userConfig?.previewTailLines, 40, "`previewTailLines`"),
|
|
@@ -6399,7 +6480,8 @@ function generateSarifReport(manifest, findings, rules, toolVersion) {
|
|
|
6399
6480
|
const results = findings.filter((finding) => typeof finding.path === "string" && finding.path.length > 0).map((finding) => {
|
|
6400
6481
|
const primary = finding.rules[0] ?? "unknown";
|
|
6401
6482
|
const line = Math.max(1, finding.line);
|
|
6402
|
-
const
|
|
6483
|
+
const rawPath = findSecretInPath(String(finding.path), rules)?.masked ?? String(finding.path);
|
|
6484
|
+
const findingPath = rawPath.replace(/\\/g, "/").split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
6403
6485
|
return {
|
|
6404
6486
|
ruleId: ruleIdFor(primary),
|
|
6405
6487
|
ruleIndex: ruleIndex.get(primary) ?? 0,
|
|
@@ -6824,7 +6906,9 @@ function fenceIsOpen(text2, fence) {
|
|
|
6824
6906
|
}
|
|
6825
6907
|
var OMISSION_NOTICE_LINE = /^\.\.\. \[\d+ lines omitted: [^\]]*\] \.\.\.$/;
|
|
6826
6908
|
function applyTruncatedContent(file, content, reason) {
|
|
6827
|
-
const keptLines = content.split("\n").filter(
|
|
6909
|
+
const keptLines = content.split("\n").filter(
|
|
6910
|
+
(line) => !OMISSION_NOTICE_LINE.test(line) && line.trim() !== SECTION_TRUNCATION_NOTICE
|
|
6911
|
+
).length;
|
|
6828
6912
|
file.content = content;
|
|
6829
6913
|
file.isPreviewTruncated = true;
|
|
6830
6914
|
file.inclusionMode = "preview";
|
|
@@ -6844,7 +6928,8 @@ function rehashPart(part, markdown) {
|
|
|
6844
6928
|
byteSize: Buffer.byteLength(redistributed, "utf8"),
|
|
6845
6929
|
sha256: crypto__namespace.createHash("sha256").update(redistributed).digest("hex"),
|
|
6846
6930
|
lines: countLines(redistributed),
|
|
6847
|
-
estimatedTokens
|
|
6931
|
+
estimatedTokens,
|
|
6932
|
+
hardClipped: true
|
|
6848
6933
|
}
|
|
6849
6934
|
};
|
|
6850
6935
|
}
|
|
@@ -7020,11 +7105,14 @@ function generateMonolithJson(manifest, filesWithContent) {
|
|
|
7020
7105
|
);
|
|
7021
7106
|
return JSON.stringify({ manifest: embedded, files }, null, 2);
|
|
7022
7107
|
}
|
|
7108
|
+
function xmlSafe(value) {
|
|
7109
|
+
return value.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g, "\uFFFD");
|
|
7110
|
+
}
|
|
7023
7111
|
function xmlAttribute(value) {
|
|
7024
|
-
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
7112
|
+
return xmlSafe(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
7025
7113
|
}
|
|
7026
7114
|
function cdata(value) {
|
|
7027
|
-
return "<![CDATA[" + value.replace(/\]\]>/g, "]]]]><![CDATA[>") + "]]>";
|
|
7115
|
+
return "<![CDATA[" + xmlSafe(value).replace(/\]\]>/g, "]]]]><![CDATA[>") + "]]>";
|
|
7028
7116
|
}
|
|
7029
7117
|
function generateMonolithXml(manifest, filesWithContent) {
|
|
7030
7118
|
const files = filesWithContent.map((file) => {
|
|
@@ -7125,14 +7213,19 @@ function generateNavigation(manifest) {
|
|
|
7125
7213
|
}
|
|
7126
7214
|
|
|
7127
7215
|
// src/generator/selection.ts
|
|
7216
|
+
function cell(value) {
|
|
7217
|
+
return escapeControls(value).replace(/\r?\n/g, " ").replace(/\|/g, "\\|");
|
|
7218
|
+
}
|
|
7128
7219
|
function generateSelectionReport(manifest, selection) {
|
|
7129
7220
|
const lines = [];
|
|
7130
7221
|
lines.push("# Selection");
|
|
7131
7222
|
lines.push("");
|
|
7132
7223
|
lines.push("**Kind:** `" + selection.kind + "` ");
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7224
|
+
const detail = selection.detail.replace(/\r?\n/g, " ");
|
|
7225
|
+
const colon = detail.indexOf(":");
|
|
7226
|
+
lines.push(
|
|
7227
|
+
"**" + (colon === -1 ? "Selection" : detail.slice(0, colon)) + ":**" + (colon === -1 ? " " + detail : detail.slice(colon + 1)) + " "
|
|
7228
|
+
);
|
|
7136
7229
|
lines.push("**Selected files:** " + selection.files.length + " ");
|
|
7137
7230
|
const spent = manifest.budget?.usedTokens ?? manifest.slice?.usedTokens ?? 0;
|
|
7138
7231
|
lines.push("**Tokens spent:** " + spent.toLocaleString("en-US"));
|
|
@@ -7142,7 +7235,7 @@ function generateSelectionReport(manifest, selection) {
|
|
|
7142
7235
|
lines.push("| File | Tokens | Reason |");
|
|
7143
7236
|
lines.push("| :-- | --: | :-- |");
|
|
7144
7237
|
for (const file of selection.files) {
|
|
7145
|
-
lines.push("| `" + file.path + "` | " + file.tokens.toLocaleString("en-US") + " | " + file.why + " |");
|
|
7238
|
+
lines.push("| `" + cell(file.path) + "` | " + file.tokens.toLocaleString("en-US") + " | " + cell(file.why) + " |");
|
|
7146
7239
|
}
|
|
7147
7240
|
lines.push("");
|
|
7148
7241
|
const dropped = selection.kind === "slice" ? manifest.slice?.dropped : manifest.budget?.dropped;
|
|
@@ -7162,7 +7255,7 @@ function generateSelectionReport(manifest, selection) {
|
|
|
7162
7255
|
lines.push("| File | Tokens |");
|
|
7163
7256
|
lines.push("| :-- | --: |");
|
|
7164
7257
|
for (const item of next) {
|
|
7165
|
-
lines.push("| `" + item.path + "` | " + item.tokens.toLocaleString("en-US") + " |");
|
|
7258
|
+
lines.push("| `" + cell(item.path) + "` | " + item.tokens.toLocaleString("en-US") + " |");
|
|
7166
7259
|
}
|
|
7167
7260
|
lines.push("");
|
|
7168
7261
|
}
|
|
@@ -7261,10 +7354,10 @@ function resolveImport(from, specifier, byPath) {
|
|
|
7261
7354
|
if (segment === "..") parts.pop();
|
|
7262
7355
|
else parts.push(segment);
|
|
7263
7356
|
}
|
|
7264
|
-
const
|
|
7265
|
-
const withoutExtension =
|
|
7357
|
+
const path26 = parts.join("/");
|
|
7358
|
+
const withoutExtension = path26.replace(/\.[cm]?[jt]sx?$/, "");
|
|
7266
7359
|
const candidates = [
|
|
7267
|
-
|
|
7360
|
+
path26,
|
|
7268
7361
|
withoutExtension + ".ts",
|
|
7269
7362
|
withoutExtension + ".tsx",
|
|
7270
7363
|
withoutExtension + ".js",
|
|
@@ -7273,18 +7366,18 @@ function resolveImport(from, specifier, byPath) {
|
|
|
7273
7366
|
withoutExtension + ".go",
|
|
7274
7367
|
withoutExtension + ".rs",
|
|
7275
7368
|
withoutExtension + "/index.ts",
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7369
|
+
path26 + ".ts",
|
|
7370
|
+
path26 + ".tsx",
|
|
7371
|
+
path26 + ".js",
|
|
7372
|
+
path26 + ".jsx",
|
|
7373
|
+
path26 + ".mjs",
|
|
7374
|
+
path26 + ".cjs",
|
|
7375
|
+
path26 + ".py",
|
|
7376
|
+
path26 + ".go",
|
|
7377
|
+
path26 + ".rs",
|
|
7378
|
+
path26 + ".java",
|
|
7379
|
+
path26 + "/index.ts",
|
|
7380
|
+
path26 + "/index.js"
|
|
7288
7381
|
];
|
|
7289
7382
|
for (const candidate of candidates) {
|
|
7290
7383
|
const found = byPath.get(candidate);
|
|
@@ -7313,12 +7406,12 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
7313
7406
|
const scored = [];
|
|
7314
7407
|
for (const file of manifest.files) {
|
|
7315
7408
|
if (isTest(file) && !wantsTests) continue;
|
|
7316
|
-
const
|
|
7317
|
-
const words =
|
|
7409
|
+
const path26 = file.relativePath.toLowerCase();
|
|
7410
|
+
const words = path26.split(/[^a-z0-9_]+/).filter((word) => word.length >= 3);
|
|
7318
7411
|
let score = 0;
|
|
7319
7412
|
const reasons = [];
|
|
7320
7413
|
for (const term of terms) {
|
|
7321
|
-
if (
|
|
7414
|
+
if (path26.includes(term)) {
|
|
7322
7415
|
score += 8;
|
|
7323
7416
|
reasons.push("path:" + term);
|
|
7324
7417
|
continue;
|
|
@@ -7369,7 +7462,9 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
7369
7462
|
notes.push("No file matched the question's terms; the plan falls back to the most-imported files.");
|
|
7370
7463
|
}
|
|
7371
7464
|
}
|
|
7372
|
-
scored.sort(
|
|
7465
|
+
scored.sort(
|
|
7466
|
+
(left, right) => right.score - left.score || (left.file.relativePath < right.file.relativePath ? -1 : left.file.relativePath > right.file.relativePath ? 1 : 0)
|
|
7467
|
+
);
|
|
7373
7468
|
const chosen = /* @__PURE__ */ new Map();
|
|
7374
7469
|
const skipped = [];
|
|
7375
7470
|
let used = 0;
|
|
@@ -7477,12 +7572,15 @@ function stripComments2(text2, relativePath) {
|
|
|
7477
7572
|
if (ranges_ === void 0) return;
|
|
7478
7573
|
for (const range of ranges_) ranges.push([range.pos, range.end]);
|
|
7479
7574
|
};
|
|
7480
|
-
const
|
|
7575
|
+
const stack = [source];
|
|
7576
|
+
while (stack.length > 0) {
|
|
7577
|
+
const node = stack.pop();
|
|
7481
7578
|
collect(ts__default.default.getLeadingCommentRanges(text2, node.getFullStart()));
|
|
7482
7579
|
collect(ts__default.default.getTrailingCommentRanges(text2, node.getEnd()));
|
|
7483
|
-
ts__default.default.forEachChild(node,
|
|
7484
|
-
|
|
7485
|
-
|
|
7580
|
+
ts__default.default.forEachChild(node, (child) => {
|
|
7581
|
+
stack.push(child);
|
|
7582
|
+
});
|
|
7583
|
+
}
|
|
7486
7584
|
collect(ts__default.default.getLeadingCommentRanges(text2, source.endOfFileToken.getFullStart()));
|
|
7487
7585
|
if (ranges.length === 0) return { text: text2, removed: 0 };
|
|
7488
7586
|
ranges.sort((left, right) => left[0] - right[0]);
|
|
@@ -7507,7 +7605,15 @@ function stripComments2(text2, relativePath) {
|
|
|
7507
7605
|
function runGit(cwd, args) {
|
|
7508
7606
|
const result = childProcess.spawnSync(
|
|
7509
7607
|
"git",
|
|
7510
|
-
[
|
|
7608
|
+
[
|
|
7609
|
+
"-c",
|
|
7610
|
+
"core.quotepath=false",
|
|
7611
|
+
"-c",
|
|
7612
|
+
"diff.noprefix=false",
|
|
7613
|
+
"-c",
|
|
7614
|
+
"diff.mnemonicPrefix=false",
|
|
7615
|
+
...args
|
|
7616
|
+
],
|
|
7511
7617
|
{ cwd, encoding: "utf8", windowsHide: true, maxBuffer: 64 * 1024 * 1024 }
|
|
7512
7618
|
);
|
|
7513
7619
|
if (result.status !== 0) return { ok: false, out: (result.stderr ?? "").trim() };
|
|
@@ -7566,60 +7672,44 @@ function unquoteGitPath(value) {
|
|
|
7566
7672
|
flushBytes();
|
|
7567
7673
|
return out;
|
|
7568
7674
|
}
|
|
7569
|
-
function
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
let index = 1;
|
|
7573
|
-
while (index < value.length) {
|
|
7574
|
-
if (value[index] === "\\") {
|
|
7575
|
-
index += 2;
|
|
7576
|
-
continue;
|
|
7577
|
-
}
|
|
7578
|
-
if (value[index] === '"') {
|
|
7579
|
-
return { token: value.slice(0, index + 1), rest: value.slice(index + 1).replace(/^ /, "") };
|
|
7580
|
-
}
|
|
7581
|
-
index += 1;
|
|
7582
|
-
}
|
|
7583
|
-
return null;
|
|
7584
|
-
}
|
|
7585
|
-
const space = value.indexOf(" ");
|
|
7586
|
-
if (space === -1) return { token: value, rest: "" };
|
|
7587
|
-
return { token: value.slice(0, space), rest: value.slice(space + 1) };
|
|
7588
|
-
}
|
|
7589
|
-
function pathFromGitToken(token, prefix) {
|
|
7590
|
-
const unquoted = unquoteGitPath(token);
|
|
7675
|
+
function wholeLinePath(value, prefix) {
|
|
7676
|
+
const withoutTimestamp = value.endsWith(" ") ? value.slice(0, -1) : value;
|
|
7677
|
+
const unquoted = unquoteGitPath(withoutTimestamp);
|
|
7591
7678
|
if (unquoted === "/dev/null") return null;
|
|
7592
7679
|
if (!unquoted.startsWith(prefix)) return null;
|
|
7593
7680
|
return unquoted.slice(prefix.length);
|
|
7594
7681
|
}
|
|
7682
|
+
function headerPaths(value) {
|
|
7683
|
+
const separator = value.lastIndexOf(" b/");
|
|
7684
|
+
if (separator <= 0) return [];
|
|
7685
|
+
const left = unquoteGitPath(value.slice(0, separator));
|
|
7686
|
+
const right = unquoteGitPath(value.slice(separator + 1));
|
|
7687
|
+
const paths = [];
|
|
7688
|
+
if (left.startsWith("a/")) paths.push(left.slice(2));
|
|
7689
|
+
if (right.startsWith("b/")) paths.push(right.slice(2));
|
|
7690
|
+
return paths;
|
|
7691
|
+
}
|
|
7595
7692
|
function diffSectionPaths(body) {
|
|
7596
7693
|
const paths = /* @__PURE__ */ new Set();
|
|
7694
|
+
let header = null;
|
|
7597
7695
|
for (const line of body.split("\n")) {
|
|
7598
7696
|
if (line.startsWith("diff --git ")) {
|
|
7599
|
-
|
|
7600
|
-
if (first === null) continue;
|
|
7601
|
-
const second = takeGitPath(first.rest);
|
|
7602
|
-
if (second === null) continue;
|
|
7603
|
-
const left = pathFromGitToken(first.token, "a/");
|
|
7604
|
-
const right = pathFromGitToken(second.token, "b/");
|
|
7605
|
-
if (left !== null) paths.add(left);
|
|
7606
|
-
if (right !== null) paths.add(right);
|
|
7697
|
+
header = line.slice("diff --git ".length);
|
|
7607
7698
|
continue;
|
|
7608
7699
|
}
|
|
7609
7700
|
if (line.startsWith("+++ ")) {
|
|
7610
|
-
const
|
|
7611
|
-
if (
|
|
7612
|
-
const path27 = pathFromGitToken(token.token, "b/");
|
|
7613
|
-
if (path27 !== null) paths.add(path27);
|
|
7701
|
+
const path26 = wholeLinePath(line.slice(4), "b/");
|
|
7702
|
+
if (path26 !== null) paths.add(path26);
|
|
7614
7703
|
continue;
|
|
7615
7704
|
}
|
|
7616
7705
|
if (line.startsWith("--- ")) {
|
|
7617
|
-
const
|
|
7618
|
-
if (
|
|
7619
|
-
const path27 = pathFromGitToken(token.token, "a/");
|
|
7620
|
-
if (path27 !== null) paths.add(path27);
|
|
7706
|
+
const path26 = wholeLinePath(line.slice(4), "a/");
|
|
7707
|
+
if (path26 !== null) paths.add(path26);
|
|
7621
7708
|
}
|
|
7622
7709
|
}
|
|
7710
|
+
if (paths.size === 0 && header !== null) {
|
|
7711
|
+
for (const path26 of headerPaths(header)) paths.add(path26);
|
|
7712
|
+
}
|
|
7623
7713
|
return [...paths];
|
|
7624
7714
|
}
|
|
7625
7715
|
function generateDiffReport(cwd, options = {}) {
|
|
@@ -7643,7 +7733,7 @@ function generateDiffReport(cwd, options = {}) {
|
|
|
7643
7733
|
omittedUnparseable += 1;
|
|
7644
7734
|
continue;
|
|
7645
7735
|
}
|
|
7646
|
-
const blocked = paths2.some((
|
|
7736
|
+
const blocked = paths2.some((path26) => isSensitivePath(path26) || options.excluded?.(path26) === true);
|
|
7647
7737
|
if (blocked) {
|
|
7648
7738
|
omittedSensitive += 1;
|
|
7649
7739
|
continue;
|
|
@@ -7670,7 +7760,7 @@ function generateDiffReport(cwd, options = {}) {
|
|
|
7670
7760
|
}
|
|
7671
7761
|
if (sections.length === 0) return null;
|
|
7672
7762
|
const paths = /* @__PURE__ */ new Set();
|
|
7673
|
-
for (const section of sections) for (const
|
|
7763
|
+
for (const section of sections) for (const path26 of diffSectionPaths(section)) paths.add(path26);
|
|
7674
7764
|
const joined = [
|
|
7675
7765
|
"# Uncommitted changes",
|
|
7676
7766
|
"",
|
|
@@ -7720,28 +7810,39 @@ function generateLogReport(cwd, options = {}) {
|
|
|
7720
7810
|
}
|
|
7721
7811
|
|
|
7722
7812
|
// src/generator/tokens.ts
|
|
7813
|
+
function cell2(value) {
|
|
7814
|
+
return escapeControls(value).replace(/\r?\n/g, " ").replace(/\|/g, "\\|");
|
|
7815
|
+
}
|
|
7816
|
+
function byCodeUnit(left, right) {
|
|
7817
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
7818
|
+
}
|
|
7723
7819
|
function tokensOf2(bytes) {
|
|
7724
7820
|
return Math.max(1, Math.ceil(bytes * 0.25));
|
|
7725
7821
|
}
|
|
7726
7822
|
function generateTokenTree(manifest) {
|
|
7727
7823
|
if (manifest.files.length === 0) return null;
|
|
7728
|
-
const rows = manifest.files.map((file) => ({ path: file.relativePath, layer: file.layer, part: file.part, tokens: tokensOf2(file.includedBytes) })).sort((left, right) => right.tokens - left.tokens || left.path
|
|
7824
|
+
const rows = manifest.files.map((file) => ({ path: file.relativePath, layer: file.layer, part: file.part, tokens: tokensOf2(file.includedBytes) })).sort((left, right) => right.tokens - left.tokens || byCodeUnit(left.path, right.path));
|
|
7729
7825
|
const byDirectory = /* @__PURE__ */ new Map();
|
|
7730
7826
|
for (const row of rows) {
|
|
7731
7827
|
const directory = row.path.includes("/") ? row.path.slice(0, row.path.lastIndexOf("/")) : ".";
|
|
7732
7828
|
byDirectory.set(directory, (byDirectory.get(directory) ?? 0) + row.tokens);
|
|
7733
7829
|
}
|
|
7734
|
-
const directories = [...byDirectory.entries()].sort(
|
|
7830
|
+
const directories = [...byDirectory.entries()].sort(
|
|
7831
|
+
(left, right) => right[1] - left[1] || byCodeUnit(left[0], right[0])
|
|
7832
|
+
);
|
|
7735
7833
|
const total = rows.reduce((sum, row) => sum + row.tokens, 0);
|
|
7736
|
-
const rowsTable = rows.map(
|
|
7834
|
+
const rowsTable = rows.map(
|
|
7835
|
+
(row) => "| " + cell2(row.path) + " | " + cell2(row.layer) + " | " + cell2(row.part) + " | " + row.tokens + " |"
|
|
7836
|
+
);
|
|
7737
7837
|
const directoryTable = directories.map(
|
|
7738
|
-
(entry) => "| " + entry[0] + " | " + entry[1] + " | " + (entry[1] / total * 100).toFixed(1) + "% |"
|
|
7838
|
+
(entry) => "| " + cell2(entry[0]) + " | " + entry[1] + " | " + (entry[1] / total * 100).toFixed(1) + "% |"
|
|
7739
7839
|
);
|
|
7740
7840
|
const text2 = [
|
|
7741
7841
|
"# Token tree",
|
|
7742
7842
|
"",
|
|
7743
|
-
"Estimated tokens per file (one token per four bytes of emitted body), sorted by cost.
|
|
7744
|
-
"is
|
|
7843
|
+
"Estimated tokens per file (one token per four bytes of emitted body), sorted by cost. Each",
|
|
7844
|
+
"row is an estimate; the manifest total is estimated from the assembled parts, so the two can",
|
|
7845
|
+
"differ slightly and neither is a tokenizer count.",
|
|
7745
7846
|
"",
|
|
7746
7847
|
"## Directories",
|
|
7747
7848
|
"",
|
|
@@ -7943,7 +8044,9 @@ function systemSection(manifest, code, brief, escape, sawManifest) {
|
|
|
7943
8044
|
if (brief?.system !== void 0) {
|
|
7944
8045
|
out.push(...ownerBlock(brief.system, brief.path, code, escape), "", "What the index records:", "");
|
|
7945
8046
|
}
|
|
7946
|
-
const layers = Object.entries(manifest.layers).sort(
|
|
8047
|
+
const layers = Object.entries(manifest.layers).sort(
|
|
8048
|
+
(a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)
|
|
8049
|
+
);
|
|
7947
8050
|
if (layers.length > 0) {
|
|
7948
8051
|
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
7949
8052
|
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
@@ -7957,7 +8060,7 @@ function systemSection(manifest, code, brief, escape, sawManifest) {
|
|
|
7957
8060
|
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
7958
8061
|
);
|
|
7959
8062
|
}
|
|
7960
|
-
const entryPoints = manifest.files.map((file) => file.relativePath).filter((
|
|
8063
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path26) => ENTRY_POINT.test(path26)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
7961
8064
|
out.push(
|
|
7962
8065
|
entryPoints.length > 0 ? "- Entry points by convention: " + entryPoints.map(code).join(", ") + "." : "- No entry point was identifiable by name. The largest files below are where execution"
|
|
7963
8066
|
);
|
|
@@ -8061,7 +8164,7 @@ function coverageSection(manifest, code, auditWritten, partsWritten, sawManifest
|
|
|
8061
8164
|
for (const record of manifest.skipped) {
|
|
8062
8165
|
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
8063
8166
|
}
|
|
8064
|
-
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0]
|
|
8167
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
8065
8168
|
const found = manifest.totals.candidateFiles;
|
|
8066
8169
|
const included = manifest.totals.includedFiles;
|
|
8067
8170
|
const skipped = manifest.counts.skippedCount;
|
|
@@ -8192,8 +8295,8 @@ function ownerNotesSection(brief, code, text2) {
|
|
|
8192
8295
|
}
|
|
8193
8296
|
return out;
|
|
8194
8297
|
}
|
|
8195
|
-
function ownerBlock(body,
|
|
8196
|
-
return ["> Written by the project owner in " + code(
|
|
8298
|
+
function ownerBlock(body, path26, code, escape) {
|
|
8299
|
+
return ["> Written by the project owner in " + code(path26) + ", not generated.", "", escape(body)];
|
|
8197
8300
|
}
|
|
8198
8301
|
function snapshotSection(manifest, code, partsWritten) {
|
|
8199
8302
|
const out = ["## This snapshot", ""];
|
|
@@ -8563,7 +8666,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
8563
8666
|
const descriptions = [];
|
|
8564
8667
|
if (request.changedSince !== void 0) {
|
|
8565
8668
|
assertUsableRef(request.changedSince);
|
|
8566
|
-
for (const
|
|
8669
|
+
for (const path26 of gitPaths(cwd, [
|
|
8567
8670
|
"diff",
|
|
8568
8671
|
"--name-only",
|
|
8569
8672
|
"-z",
|
|
@@ -8571,9 +8674,9 @@ function resolveChangedScope(cwd, request) {
|
|
|
8571
8674
|
`${request.changedSince}...HEAD`,
|
|
8572
8675
|
"--"
|
|
8573
8676
|
])) {
|
|
8574
|
-
paths.add(
|
|
8677
|
+
paths.add(path26);
|
|
8575
8678
|
}
|
|
8576
|
-
for (const
|
|
8679
|
+
for (const path26 of gitPaths(cwd, [
|
|
8577
8680
|
"diff",
|
|
8578
8681
|
"--name-only",
|
|
8579
8682
|
"-z",
|
|
@@ -8581,15 +8684,15 @@ function resolveChangedScope(cwd, request) {
|
|
|
8581
8684
|
"HEAD",
|
|
8582
8685
|
"--"
|
|
8583
8686
|
])) {
|
|
8584
|
-
paths.add(
|
|
8687
|
+
paths.add(path26);
|
|
8585
8688
|
}
|
|
8586
|
-
for (const
|
|
8587
|
-
paths.add(
|
|
8689
|
+
for (const path26 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
8690
|
+
paths.add(path26);
|
|
8588
8691
|
}
|
|
8589
8692
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
8590
8693
|
}
|
|
8591
8694
|
if (request.staged === true) {
|
|
8592
|
-
for (const
|
|
8695
|
+
for (const path26 of gitPaths(cwd, [
|
|
8593
8696
|
"diff",
|
|
8594
8697
|
"--cached",
|
|
8595
8698
|
"--name-only",
|
|
@@ -8597,10 +8700,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
8597
8700
|
"--relative",
|
|
8598
8701
|
"--"
|
|
8599
8702
|
])) {
|
|
8600
|
-
paths.add(
|
|
8601
|
-
stagedPaths.add(
|
|
8703
|
+
paths.add(path26);
|
|
8704
|
+
stagedPaths.add(path26);
|
|
8602
8705
|
}
|
|
8603
|
-
for (const
|
|
8706
|
+
for (const path26 of gitPaths(cwd, [
|
|
8604
8707
|
"diff",
|
|
8605
8708
|
"--cached",
|
|
8606
8709
|
"--name-only",
|
|
@@ -8609,7 +8712,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
8609
8712
|
"--diff-filter=D",
|
|
8610
8713
|
"--"
|
|
8611
8714
|
])) {
|
|
8612
|
-
deletedPaths.add(
|
|
8715
|
+
deletedPaths.add(path26);
|
|
8613
8716
|
}
|
|
8614
8717
|
descriptions.push("staged");
|
|
8615
8718
|
}
|
|
@@ -8647,15 +8750,19 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
|
8647
8750
|
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
8648
8751
|
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
8649
8752
|
function tsconfigPathsFor(cwd) {
|
|
8650
|
-
const configPath =
|
|
8753
|
+
const configPath = path25__namespace.join(cwd, "tsconfig.json");
|
|
8651
8754
|
let stats;
|
|
8652
8755
|
try {
|
|
8653
|
-
stats =
|
|
8756
|
+
stats = fs24__namespace.statSync(configPath);
|
|
8654
8757
|
} catch (err) {
|
|
8655
8758
|
if (err.code === "ENOENT") return null;
|
|
8656
8759
|
return null;
|
|
8657
8760
|
}
|
|
8658
8761
|
const key = `${stats.mtimeMs}:${stats.size}`;
|
|
8762
|
+
if (!TSCONFIG_CACHE.has(configPath) && TSCONFIG_CACHE.size >= 64) {
|
|
8763
|
+
const oldest = TSCONFIG_CACHE.keys().next().value;
|
|
8764
|
+
if (oldest !== void 0) TSCONFIG_CACHE.delete(oldest);
|
|
8765
|
+
}
|
|
8659
8766
|
const cached = TSCONFIG_CACHE.get(configPath);
|
|
8660
8767
|
if (cached !== void 0 && cached.key === key) return cached.value;
|
|
8661
8768
|
let value = null;
|
|
@@ -8684,8 +8791,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
8684
8791
|
return value;
|
|
8685
8792
|
}
|
|
8686
8793
|
function repositoryRelative(cwd, target) {
|
|
8687
|
-
const relative15 =
|
|
8688
|
-
return relative15.length === 0 || !relative15.startsWith("..") && !
|
|
8794
|
+
const relative15 = path25__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
8795
|
+
return relative15.length === 0 || !relative15.startsWith("..") && !path25__namespace.isAbsolute(relative15) ? relative15 : null;
|
|
8689
8796
|
}
|
|
8690
8797
|
function rememberFirst(map, key, value) {
|
|
8691
8798
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -8700,15 +8807,15 @@ function buildImportResolver(files, options = {}) {
|
|
|
8700
8807
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
8701
8808
|
rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
8702
8809
|
}
|
|
8703
|
-
const extension =
|
|
8810
|
+
const extension = path25__namespace.posix.extname(relativePath);
|
|
8704
8811
|
if (!SOURCE_EXTENSIONS.has(extension)) return;
|
|
8705
8812
|
const stem = relativePath.slice(0, -extension.length);
|
|
8706
8813
|
rememberFirst(byStem, stem, relativePath);
|
|
8707
8814
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
8708
8815
|
rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
|
|
8709
8816
|
}
|
|
8710
|
-
if (
|
|
8711
|
-
const directory =
|
|
8817
|
+
if (path25__namespace.posix.basename(stem) === "index") {
|
|
8818
|
+
const directory = path25__namespace.posix.dirname(stem);
|
|
8712
8819
|
rememberFirst(byStem, directory, relativePath);
|
|
8713
8820
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
8714
8821
|
rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
|
|
@@ -8724,7 +8831,7 @@ function buildImportResolver(files, options = {}) {
|
|
|
8724
8831
|
return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
|
|
8725
8832
|
}
|
|
8726
8833
|
function resolveSpecifier(fromFile, specifier, resolver) {
|
|
8727
|
-
const extension =
|
|
8834
|
+
const extension = path25__namespace.posix.extname(fromFile).toLowerCase();
|
|
8728
8835
|
const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
8729
8836
|
const firstOf = (candidates) => {
|
|
8730
8837
|
for (const candidate of candidates) {
|
|
@@ -8747,34 +8854,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
8747
8854
|
if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
|
|
8748
8855
|
const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
|
|
8749
8856
|
const rest = specifier.slice(dots).replace(/\./g, "/");
|
|
8750
|
-
let base =
|
|
8751
|
-
for (let up = 1; up < dots; up += 1) base =
|
|
8752
|
-
const joined2 = rest ?
|
|
8857
|
+
let base = path25__namespace.posix.dirname(fromFile);
|
|
8858
|
+
for (let up = 1; up < dots; up += 1) base = path25__namespace.posix.dirname(base);
|
|
8859
|
+
const joined2 = rest ? path25__namespace.posix.normalize(path25__namespace.posix.join(base, rest)) : base;
|
|
8753
8860
|
return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
|
|
8754
8861
|
}
|
|
8755
8862
|
if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
8756
|
-
const joined2 =
|
|
8757
|
-
|
|
8863
|
+
const joined2 = path25__namespace.posix.normalize(
|
|
8864
|
+
path25__namespace.posix.join(path25__namespace.posix.dirname(fromFile), specifier)
|
|
8758
8865
|
);
|
|
8759
8866
|
return firstOf([`${joined2}.rb`, joined2]);
|
|
8760
8867
|
}
|
|
8761
8868
|
if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
8762
|
-
const joined2 =
|
|
8763
|
-
|
|
8869
|
+
const joined2 = path25__namespace.posix.normalize(
|
|
8870
|
+
path25__namespace.posix.join(path25__namespace.posix.dirname(fromFile), specifier)
|
|
8764
8871
|
);
|
|
8765
8872
|
return exact(joined2);
|
|
8766
8873
|
}
|
|
8767
8874
|
if (extension === ".dart" && !specifier.includes(":")) {
|
|
8768
|
-
const joined2 =
|
|
8769
|
-
|
|
8875
|
+
const joined2 = path25__namespace.posix.normalize(
|
|
8876
|
+
path25__namespace.posix.join(path25__namespace.posix.dirname(fromFile), specifier)
|
|
8770
8877
|
);
|
|
8771
8878
|
return firstOf([joined2, `${joined2}.dart`]);
|
|
8772
8879
|
}
|
|
8773
8880
|
if (!RELATIVE_SPECIFIER.test(specifier)) {
|
|
8774
8881
|
return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
|
|
8775
8882
|
}
|
|
8776
|
-
const joined =
|
|
8777
|
-
|
|
8883
|
+
const joined = path25__namespace.posix.normalize(
|
|
8884
|
+
path25__namespace.posix.join(path25__namespace.posix.dirname(fromFile), specifier)
|
|
8778
8885
|
);
|
|
8779
8886
|
return lookupPath(joined);
|
|
8780
8887
|
}
|
|
@@ -8798,13 +8905,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
|
|
|
8798
8905
|
if (captured === null) continue;
|
|
8799
8906
|
for (const target of rule.targets) {
|
|
8800
8907
|
const substituted = target.split("*").join(captured);
|
|
8801
|
-
const base = config.baseUrl === null ? substituted :
|
|
8802
|
-
const hit = lookupPath(
|
|
8908
|
+
const base = config.baseUrl === null ? substituted : path25__namespace.posix.join(config.baseUrl, substituted);
|
|
8909
|
+
const hit = lookupPath(path25__namespace.posix.normalize(base));
|
|
8803
8910
|
if (hit) return hit;
|
|
8804
8911
|
}
|
|
8805
8912
|
}
|
|
8806
8913
|
if (config.baseUrl !== null) {
|
|
8807
|
-
return lookupPath(
|
|
8914
|
+
return lookupPath(path25__namespace.posix.normalize(path25__namespace.posix.join(config.baseUrl, specifier)));
|
|
8808
8915
|
}
|
|
8809
8916
|
return null;
|
|
8810
8917
|
}
|
|
@@ -8815,6 +8922,77 @@ function importsChangedFile(importerPath, imports, changedPaths, resolver) {
|
|
|
8815
8922
|
}
|
|
8816
8923
|
return false;
|
|
8817
8924
|
}
|
|
8925
|
+
function isInside2(parent, child) {
|
|
8926
|
+
const relative15 = path25__namespace.relative(parent, child);
|
|
8927
|
+
return relative15 === "" || !relative15.startsWith("..") && !path25__namespace.isAbsolute(relative15);
|
|
8928
|
+
}
|
|
8929
|
+
function resolveConfined(baseDir, relativePath) {
|
|
8930
|
+
if (relativePath.length === 0 || relativePath.includes("\0")) {
|
|
8931
|
+
return { ok: false, reason: "not-file", message: "the file name is empty or contains a NUL byte" };
|
|
8932
|
+
}
|
|
8933
|
+
if (path25__namespace.isAbsolute(relativePath)) {
|
|
8934
|
+
return { ok: false, reason: "outside", message: "an absolute path is not a snapshot-relative file" };
|
|
8935
|
+
}
|
|
8936
|
+
let baseReal;
|
|
8937
|
+
try {
|
|
8938
|
+
baseReal = fs24__namespace.realpathSync(path25__namespace.resolve(baseDir));
|
|
8939
|
+
} catch {
|
|
8940
|
+
return { ok: false, reason: "missing", message: "the snapshot directory does not exist" };
|
|
8941
|
+
}
|
|
8942
|
+
const candidate = path25__namespace.resolve(baseReal, relativePath);
|
|
8943
|
+
if (!isInside2(baseReal, candidate)) {
|
|
8944
|
+
return { ok: false, reason: "outside", message: "the path resolves outside the snapshot directory" };
|
|
8945
|
+
}
|
|
8946
|
+
let stats;
|
|
8947
|
+
try {
|
|
8948
|
+
stats = fs24__namespace.lstatSync(candidate);
|
|
8949
|
+
} catch (error) {
|
|
8950
|
+
const code = error.code;
|
|
8951
|
+
return {
|
|
8952
|
+
ok: false,
|
|
8953
|
+
reason: code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable",
|
|
8954
|
+
message: code === "ENOENT" || code === "ENOTDIR" ? "the file does not exist" : "the file could not be inspected"
|
|
8955
|
+
};
|
|
8956
|
+
}
|
|
8957
|
+
if (stats.isSymbolicLink()) {
|
|
8958
|
+
return { ok: false, reason: "not-file", message: "the file is a symbolic link" };
|
|
8959
|
+
}
|
|
8960
|
+
if (!stats.isFile()) {
|
|
8961
|
+
return { ok: false, reason: "not-file", message: "the path is not a regular file" };
|
|
8962
|
+
}
|
|
8963
|
+
let real;
|
|
8964
|
+
try {
|
|
8965
|
+
real = fs24__namespace.realpathSync(candidate);
|
|
8966
|
+
} catch {
|
|
8967
|
+
return { ok: false, reason: "unreadable", message: "the file could not be resolved" };
|
|
8968
|
+
}
|
|
8969
|
+
if (!isInside2(baseReal, real)) {
|
|
8970
|
+
return { ok: false, reason: "outside", message: "the file resolves outside the snapshot directory" };
|
|
8971
|
+
}
|
|
8972
|
+
return { ok: true, path: real, stats };
|
|
8973
|
+
}
|
|
8974
|
+
function readConfinedBytes(baseDir, relativePath) {
|
|
8975
|
+
const resolved = resolveConfined(baseDir, relativePath);
|
|
8976
|
+
if (!resolved.ok) return resolved;
|
|
8977
|
+
try {
|
|
8978
|
+
const bytes = fs24__namespace.readFileSync(resolved.path);
|
|
8979
|
+
return { ok: true, bytes, path: resolved.path, stats: fs24__namespace.statSync(resolved.path) };
|
|
8980
|
+
} catch {
|
|
8981
|
+
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
8982
|
+
}
|
|
8983
|
+
}
|
|
8984
|
+
function readConfinedText(baseDir, relativePath) {
|
|
8985
|
+
const resolved = resolveConfined(baseDir, relativePath);
|
|
8986
|
+
if (!resolved.ok) return resolved;
|
|
8987
|
+
try {
|
|
8988
|
+
const text2 = fs24__namespace.readFileSync(resolved.path, "utf8");
|
|
8989
|
+
return { ok: true, text: text2, path: resolved.path, stats: fs24__namespace.statSync(resolved.path) };
|
|
8990
|
+
} catch {
|
|
8991
|
+
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
8992
|
+
}
|
|
8993
|
+
}
|
|
8994
|
+
|
|
8995
|
+
// src/generator/overview.ts
|
|
8818
8996
|
var SUMMARY_LIMIT = 400;
|
|
8819
8997
|
var MAX_RELEASES = 2;
|
|
8820
8998
|
function readProjectOverview(cwd) {
|
|
@@ -8824,15 +9002,12 @@ function readProjectOverview(cwd) {
|
|
|
8824
9002
|
releases: readReleases(cwd)
|
|
8825
9003
|
};
|
|
8826
9004
|
}
|
|
8827
|
-
function readText(
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
} catch {
|
|
8831
|
-
return null;
|
|
8832
|
-
}
|
|
9005
|
+
function readText(cwd, relative15) {
|
|
9006
|
+
const read = readConfinedText(cwd, relative15);
|
|
9007
|
+
return read.ok ? read.text : null;
|
|
8833
9008
|
}
|
|
8834
9009
|
function readDescription(cwd) {
|
|
8835
|
-
const raw = readText(
|
|
9010
|
+
const raw = readText(cwd, "package.json");
|
|
8836
9011
|
if (raw === null) return {};
|
|
8837
9012
|
try {
|
|
8838
9013
|
const parsed = JSON.parse(stripJsonComments(raw));
|
|
@@ -8842,7 +9017,7 @@ function readDescription(cwd) {
|
|
|
8842
9017
|
}
|
|
8843
9018
|
}
|
|
8844
9019
|
function readSummary(cwd) {
|
|
8845
|
-
const raw = readText(
|
|
9020
|
+
const raw = readText(cwd, "README.md");
|
|
8846
9021
|
if (raw === null) return {};
|
|
8847
9022
|
const text2 = raw.replace(/<h[1-6][^>]*>[\s\S]*?<\/h[1-6]>/gi, "\n").replace(/<\/(p|div|section|header|footer|li)>/gi, "\n").replace(/<br\s*\/?>/gi, " ").replace(/<[^>]*>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'");
|
|
8848
9023
|
const paragraph = [];
|
|
@@ -8868,7 +9043,7 @@ function truncate(text2, limit) {
|
|
|
8868
9043
|
return (space > limit / 2 ? window.slice(0, space) : window).trim() + "\u2026";
|
|
8869
9044
|
}
|
|
8870
9045
|
function readReleases(cwd) {
|
|
8871
|
-
const raw = readText(
|
|
9046
|
+
const raw = readText(cwd, "CHANGELOG.md");
|
|
8872
9047
|
if (raw === null) return [];
|
|
8873
9048
|
const headings = raw.split(/\r?\n/).map((line) => /^##\s+(.+?)\s*$/.exec(line)?.[1]?.trim()).filter((heading) => heading !== void 0 && /^v?\d+\.\d+/.test(heading));
|
|
8874
9049
|
return headings.slice(0, MAX_RELEASES);
|
|
@@ -8930,10 +9105,10 @@ var LANGUAGE_BY_BASENAME = {
|
|
|
8930
9105
|
};
|
|
8931
9106
|
function detectLanguage(filePath) {
|
|
8932
9107
|
const normalized = filePath.replace(/\\/g, "/");
|
|
8933
|
-
const base =
|
|
9108
|
+
const base = path25__namespace.posix.basename(normalized);
|
|
8934
9109
|
if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
|
|
8935
9110
|
if (base === ".env" || base.startsWith(".env.")) return "dotenv";
|
|
8936
|
-
const ext =
|
|
9111
|
+
const ext = path25__namespace.posix.extname(base).toLowerCase();
|
|
8937
9112
|
return LANGUAGE_BY_EXTENSION[ext] ?? "text";
|
|
8938
9113
|
}
|
|
8939
9114
|
function maskedPath(value, secretRules) {
|
|
@@ -8941,33 +9116,33 @@ function maskedPath(value, secretRules) {
|
|
|
8941
9116
|
}
|
|
8942
9117
|
function confineToDirectory(directory, filename) {
|
|
8943
9118
|
if (filename.includes("\0")) return null;
|
|
8944
|
-
if (
|
|
8945
|
-
const base =
|
|
8946
|
-
const resolved =
|
|
9119
|
+
if (path25__namespace.isAbsolute(filename)) return null;
|
|
9120
|
+
const base = path25__namespace.resolve(directory);
|
|
9121
|
+
const resolved = path25__namespace.resolve(base, filename);
|
|
8947
9122
|
const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
|
|
8948
|
-
const prefix = caseInsensitive ? `${base}${
|
|
9123
|
+
const prefix = caseInsensitive ? `${base}${path25__namespace.sep}`.toLowerCase() : `${base}${path25__namespace.sep}`;
|
|
8949
9124
|
const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
|
|
8950
9125
|
return candidate.startsWith(prefix) ? resolved : null;
|
|
8951
9126
|
}
|
|
8952
9127
|
function findStagingDirectory(config) {
|
|
8953
|
-
const tmpDir =
|
|
9128
|
+
const tmpDir = path25__namespace.resolve(config.cwd, config.tmpDir);
|
|
8954
9129
|
let entries;
|
|
8955
9130
|
try {
|
|
8956
|
-
entries =
|
|
9131
|
+
entries = fs24__namespace.readdirSync(tmpDir);
|
|
8957
9132
|
} catch {
|
|
8958
9133
|
return null;
|
|
8959
9134
|
}
|
|
8960
9135
|
const runs = entries.filter((name) => name.startsWith("run-")).sort();
|
|
8961
9136
|
const newest = runs[runs.length - 1];
|
|
8962
|
-
return newest ?
|
|
9137
|
+
return newest ? path25__namespace.join(tmpDir, newest) : null;
|
|
8963
9138
|
}
|
|
8964
9139
|
function describeMissingManifest(config, manifestPath) {
|
|
8965
|
-
const outDir =
|
|
8966
|
-
const markerPath =
|
|
9140
|
+
const outDir = path25__namespace.resolve(config.cwd, config.outDir);
|
|
9141
|
+
const markerPath = path25__namespace.join(outDir, ".codebase-snapshot");
|
|
8967
9142
|
let marker2 = null;
|
|
8968
9143
|
try {
|
|
8969
|
-
if (
|
|
8970
|
-
const parsed = JSON.parse(
|
|
9144
|
+
if (fs24__namespace.existsSync(markerPath)) {
|
|
9145
|
+
const parsed = JSON.parse(fs24__namespace.readFileSync(markerPath, "utf8"));
|
|
8971
9146
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
8972
9147
|
marker2 = parsed;
|
|
8973
9148
|
}
|
|
@@ -9002,13 +9177,13 @@ function sha256Hex(buffer) {
|
|
|
9002
9177
|
return crypto__namespace.createHash("sha256").update(buffer).digest("hex");
|
|
9003
9178
|
}
|
|
9004
9179
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
9005
|
-
const absolutePath =
|
|
9180
|
+
const absolutePath = path25__namespace.join(cwd, relativePath);
|
|
9006
9181
|
try {
|
|
9007
|
-
const stats =
|
|
9182
|
+
const stats = fs24__namespace.statSync(absolutePath);
|
|
9008
9183
|
if (!stats.isFile()) return false;
|
|
9009
9184
|
if (isBinaryExtension(absolutePath)) return false;
|
|
9010
9185
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
9011
|
-
return !decodeText(
|
|
9186
|
+
return !decodeText(fs24__namespace.readFileSync(absolutePath)).binary;
|
|
9012
9187
|
} catch {
|
|
9013
9188
|
return false;
|
|
9014
9189
|
}
|
|
@@ -9020,7 +9195,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
|
9020
9195
|
]);
|
|
9021
9196
|
function isConfinedRelative(value) {
|
|
9022
9197
|
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
9023
|
-
if (
|
|
9198
|
+
if (path25__namespace.isAbsolute(value)) return false;
|
|
9024
9199
|
return !value.split("/").includes("..");
|
|
9025
9200
|
}
|
|
9026
9201
|
function describeManifestShapeProblem(value) {
|
|
@@ -9186,6 +9361,9 @@ function describeManifestShapeProblem(value) {
|
|
|
9186
9361
|
if (typeof fields.relativePath !== "string") {
|
|
9187
9362
|
return 'a "files" entry has no "relativePath"';
|
|
9188
9363
|
}
|
|
9364
|
+
if (!isConfinedRelative(fields.relativePath)) {
|
|
9365
|
+
return 'a "files" entry "relativePath" resolves outside the repository and was not inspected';
|
|
9366
|
+
}
|
|
9189
9367
|
if (!currentSchema) continue;
|
|
9190
9368
|
if (typeof fields.part !== "string" || fields.part.length === 0) {
|
|
9191
9369
|
return 'a "files" entry records no "part"';
|
|
@@ -9204,6 +9382,18 @@ function describeManifestShapeProblem(value) {
|
|
|
9204
9382
|
}
|
|
9205
9383
|
}
|
|
9206
9384
|
if (!Array.isArray(candidate.skipped)) return 'missing "skipped" array';
|
|
9385
|
+
for (const entry of candidate.skipped) {
|
|
9386
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
9387
|
+
return 'a "skipped" entry is not an object';
|
|
9388
|
+
}
|
|
9389
|
+
const fields = entry;
|
|
9390
|
+
if (typeof fields.path !== "string" || !isConfinedRelative(fields.path)) {
|
|
9391
|
+
return 'a "skipped" entry "path" resolves outside the repository and was not inspected';
|
|
9392
|
+
}
|
|
9393
|
+
if (typeof fields.reason !== "string" || fields.reason.length === 0) {
|
|
9394
|
+
return 'a "skipped" entry has no "reason"';
|
|
9395
|
+
}
|
|
9396
|
+
}
|
|
9207
9397
|
if (!Array.isArray(candidate.parts)) return 'missing "parts" array';
|
|
9208
9398
|
for (const entry of candidate.parts) {
|
|
9209
9399
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
@@ -9214,7 +9404,7 @@ function describeManifestShapeProblem(value) {
|
|
|
9214
9404
|
if (typeof filename !== "string" || filename.trim() === "") {
|
|
9215
9405
|
return 'a "parts" entry has no "filename"';
|
|
9216
9406
|
}
|
|
9217
|
-
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." ||
|
|
9407
|
+
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path25__namespace.isAbsolute(filename)) {
|
|
9218
9408
|
return 'a "parts" entry "filename" must be a bare filename inside parts/';
|
|
9219
9409
|
}
|
|
9220
9410
|
if (currentSchema) {
|
|
@@ -9240,8 +9430,8 @@ function describeManifestShapeProblem(value) {
|
|
|
9240
9430
|
function validateSnapshot(configInput) {
|
|
9241
9431
|
assertUsableConfigInput(configInput);
|
|
9242
9432
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
9243
|
-
const manifestPath =
|
|
9244
|
-
if (!
|
|
9433
|
+
const manifestPath = path25__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
9434
|
+
if (!fs24__namespace.existsSync(manifestPath)) {
|
|
9245
9435
|
return {
|
|
9246
9436
|
valid: false,
|
|
9247
9437
|
manifestPresent: false,
|
|
@@ -9252,7 +9442,7 @@ function validateSnapshot(configInput) {
|
|
|
9252
9442
|
}
|
|
9253
9443
|
let manifest;
|
|
9254
9444
|
try {
|
|
9255
|
-
manifest = JSON.parse(
|
|
9445
|
+
manifest = JSON.parse(fs24__namespace.readFileSync(manifestPath, "utf8"));
|
|
9256
9446
|
} catch (err) {
|
|
9257
9447
|
return {
|
|
9258
9448
|
valid: false,
|
|
@@ -9264,17 +9454,19 @@ function validateSnapshot(configInput) {
|
|
|
9264
9454
|
}
|
|
9265
9455
|
const shapeProblem = describeManifestShapeProblem(manifest);
|
|
9266
9456
|
if (shapeProblem) {
|
|
9457
|
+
const drift2 = emptyDrift();
|
|
9458
|
+
drift2.partIssues.push({ part: "manifest.json", issue: shapeProblem });
|
|
9267
9459
|
return {
|
|
9268
9460
|
valid: false,
|
|
9269
9461
|
manifestPresent: true,
|
|
9270
|
-
drift:
|
|
9462
|
+
drift: drift2,
|
|
9271
9463
|
errors: [`${manifestPath} is not a snapshot manifest: ${shapeProblem}`],
|
|
9272
9464
|
warnings: []
|
|
9273
9465
|
};
|
|
9274
9466
|
}
|
|
9275
9467
|
const drift = emptyDrift();
|
|
9276
9468
|
const warnings = [];
|
|
9277
|
-
const snapshotDir =
|
|
9469
|
+
const snapshotDir = path25__namespace.resolve(config.cwd, config.outDir);
|
|
9278
9470
|
const unreadableSkips = manifest.skipped.filter(
|
|
9279
9471
|
(entry) => entry.reason === "missing" || entry.reason === "read-error"
|
|
9280
9472
|
);
|
|
@@ -9382,7 +9574,7 @@ function validateSnapshot(configInput) {
|
|
|
9382
9574
|
);
|
|
9383
9575
|
return importsChangedFile(
|
|
9384
9576
|
diskFile,
|
|
9385
|
-
importsOfFile(diskFile,
|
|
9577
|
+
importsOfFile(diskFile, path25__namespace.join(config.cwd, diskFile)),
|
|
9386
9578
|
unchangedScope,
|
|
9387
9579
|
dependentResolver
|
|
9388
9580
|
);
|
|
@@ -9404,7 +9596,7 @@ function validateSnapshot(configInput) {
|
|
|
9404
9596
|
// own output directory as a set of files missing from the snapshot, so a correct
|
|
9405
9597
|
// snapshot was reported as drifting.
|
|
9406
9598
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
9407
|
-
(directory) =>
|
|
9599
|
+
(directory) => path25__namespace.relative(config.cwd, path25__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
9408
9600
|
).filter((relative15) => relative15.length > 0 && !relative15.startsWith(".."))
|
|
9409
9601
|
});
|
|
9410
9602
|
for (const diskFile of collection.files) {
|
|
@@ -9432,7 +9624,7 @@ function validateSnapshot(configInput) {
|
|
|
9432
9624
|
let diskHash;
|
|
9433
9625
|
try {
|
|
9434
9626
|
const stagedBlob = recordedStaged && stagedScope?.has(diskFile) === true ? readStagedBlob(config.cwd, diskFile) : null;
|
|
9435
|
-
diskHash = sha256Hex(stagedBlob ??
|
|
9627
|
+
diskHash = sha256Hex(stagedBlob ?? fs24__namespace.readFileSync(path25__namespace.join(config.cwd, diskFile)));
|
|
9436
9628
|
} catch (err) {
|
|
9437
9629
|
if (err.code === "ENOENT") {
|
|
9438
9630
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -9462,7 +9654,7 @@ function validateSnapshot(configInput) {
|
|
|
9462
9654
|
}
|
|
9463
9655
|
let statFailure = null;
|
|
9464
9656
|
try {
|
|
9465
|
-
|
|
9657
|
+
fs24__namespace.statSync(confined);
|
|
9466
9658
|
} catch (err) {
|
|
9467
9659
|
statFailure = err;
|
|
9468
9660
|
}
|
|
@@ -9482,7 +9674,7 @@ function validateSnapshot(configInput) {
|
|
|
9482
9674
|
...Object.values(config.budgets.byLayer)
|
|
9483
9675
|
);
|
|
9484
9676
|
const partNames = /* @__PURE__ */ new Set();
|
|
9485
|
-
const partsDir =
|
|
9677
|
+
const partsDir = path25__namespace.join(snapshotDir, "parts");
|
|
9486
9678
|
for (const part of manifest.parts) {
|
|
9487
9679
|
if (!part || typeof part.filename !== "string") continue;
|
|
9488
9680
|
partNames.add(part.filename);
|
|
@@ -9495,13 +9687,15 @@ function validateSnapshot(configInput) {
|
|
|
9495
9687
|
});
|
|
9496
9688
|
continue;
|
|
9497
9689
|
}
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9690
|
+
const partRead = readConfinedBytes(partsDir, part.filename);
|
|
9691
|
+
if (!partRead.ok) {
|
|
9692
|
+
drift.partIssues.push({
|
|
9693
|
+
part: part.filename,
|
|
9694
|
+
issue: `missing or not a regular file in snapshot/parts (${partRead.reason})`
|
|
9695
|
+
});
|
|
9503
9696
|
continue;
|
|
9504
9697
|
}
|
|
9698
|
+
const buffer = partRead.bytes;
|
|
9505
9699
|
if (buffer.length !== part.byteSize) {
|
|
9506
9700
|
drift.partIssues.push({
|
|
9507
9701
|
part: part.filename,
|
|
@@ -9874,15 +10068,15 @@ function validateSnapshot(configInput) {
|
|
|
9874
10068
|
];
|
|
9875
10069
|
for (const [key, artifact] of declaredArtifacts) {
|
|
9876
10070
|
if (!artifact) continue;
|
|
9877
|
-
const
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
10071
|
+
const artifactRead = readConfinedBytes(snapshotDir, key);
|
|
10072
|
+
if (!artifactRead.ok) {
|
|
10073
|
+
drift.partIssues.push({
|
|
10074
|
+
part: key,
|
|
10075
|
+
issue: `declared artifact is missing or not a regular file (${artifactRead.reason})`
|
|
10076
|
+
});
|
|
9884
10077
|
continue;
|
|
9885
10078
|
}
|
|
10079
|
+
const buffer = artifactRead.bytes;
|
|
9886
10080
|
if (sha256Hex(buffer) !== artifact.sha256 || buffer.length !== artifact.byteSize) {
|
|
9887
10081
|
drift.partIssues.push({ part: key, issue: "artifact does not match its recorded digest" });
|
|
9888
10082
|
continue;
|
|
@@ -9891,9 +10085,9 @@ function validateSnapshot(configInput) {
|
|
|
9891
10085
|
for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
9892
10086
|
const target = match[1].split("#")[0];
|
|
9893
10087
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
9894
|
-
const resolved =
|
|
9895
|
-
const relative15 =
|
|
9896
|
-
if (relative15.startsWith("..") ||
|
|
10088
|
+
const resolved = path25__namespace.resolve(snapshotDir, "reports", target);
|
|
10089
|
+
const relative15 = path25__namespace.relative(snapshotDir, resolved);
|
|
10090
|
+
if (relative15.startsWith("..") || path25__namespace.isAbsolute(relative15) || !fs24__namespace.existsSync(resolved)) {
|
|
9897
10091
|
drift.partIssues.push({
|
|
9898
10092
|
part: key,
|
|
9899
10093
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -9905,13 +10099,11 @@ function validateSnapshot(configInput) {
|
|
|
9905
10099
|
const sarifArtifact = manifest.artifacts?.sarif;
|
|
9906
10100
|
if (sarifArtifact) {
|
|
9907
10101
|
const sarifKey = "reports/audit.sarif";
|
|
9908
|
-
|
|
9909
|
-
|
|
9910
|
-
|
|
9911
|
-
|
|
9912
|
-
}
|
|
9913
|
-
} catch {
|
|
9914
|
-
drift.partIssues.push({ part: sarifKey, issue: "declared artifact is missing" });
|
|
10102
|
+
const sarifRead = readConfinedBytes(snapshotDir, "reports/audit.sarif");
|
|
10103
|
+
if (!sarifRead.ok) {
|
|
10104
|
+
drift.partIssues.push({ part: sarifKey, issue: "declared artifact is missing or not a regular file" });
|
|
10105
|
+
} else if (sha256Hex(sarifRead.bytes) !== sarifArtifact.sha256 || sarifRead.bytes.length !== sarifArtifact.byteSize) {
|
|
10106
|
+
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
9915
10107
|
}
|
|
9916
10108
|
}
|
|
9917
10109
|
if (manifest.git && manifest.git.branch && manifest.git.branch !== config.branch) {
|
|
@@ -9952,9 +10144,9 @@ function validateSnapshot(configInput) {
|
|
|
9952
10144
|
`${drift.configMismatches.length} configuration mismatch(es) between the manifest and this run.`
|
|
9953
10145
|
);
|
|
9954
10146
|
}
|
|
9955
|
-
const signaturePath =
|
|
9956
|
-
if (
|
|
9957
|
-
const outcome = verifySnapshotSignature(
|
|
10147
|
+
const signaturePath = path25__namespace.join(path25__namespace.dirname(manifestPath), "signature.json");
|
|
10148
|
+
if (fs24__namespace.existsSync(signaturePath)) {
|
|
10149
|
+
const outcome = verifySnapshotSignature(path25__namespace.dirname(manifestPath));
|
|
9958
10150
|
if (!outcome.ok) errors.push("signature: " + outcome.reason + ".");
|
|
9959
10151
|
}
|
|
9960
10152
|
if (manifest.slice !== void 0 || manifest.budget !== void 0) {
|
|
@@ -10097,7 +10289,7 @@ function parseRemoteSource(input, options = {}) {
|
|
|
10097
10289
|
const directory = url.fileURLToPath(url2);
|
|
10098
10290
|
return {
|
|
10099
10291
|
ok: true,
|
|
10100
|
-
source: { kind: "file", url: trimmed, host: "file", owner: "", repo:
|
|
10292
|
+
source: { kind: "file", url: trimmed, host: "file", owner: "", repo: path25__namespace.basename(directory), ref: null }
|
|
10101
10293
|
};
|
|
10102
10294
|
}
|
|
10103
10295
|
let url$1;
|
|
@@ -10175,9 +10367,9 @@ function gitEnvironment(token, host) {
|
|
|
10175
10367
|
async function cloneRepository(source, options) {
|
|
10176
10368
|
const log = options.log ?? (() => {
|
|
10177
10369
|
});
|
|
10178
|
-
const dest =
|
|
10179
|
-
|
|
10180
|
-
|
|
10370
|
+
const dest = path25__namespace.resolve(options.dest);
|
|
10371
|
+
fs24__namespace.rmSync(dest, { recursive: true, force: true });
|
|
10372
|
+
fs24__namespace.mkdirSync(dest, { recursive: true });
|
|
10181
10373
|
try {
|
|
10182
10374
|
const ref = options.ref ?? source.ref;
|
|
10183
10375
|
const args = [
|
|
@@ -10236,7 +10428,7 @@ async function cloneRepository(source, options) {
|
|
|
10236
10428
|
};
|
|
10237
10429
|
} catch (error) {
|
|
10238
10430
|
try {
|
|
10239
|
-
|
|
10431
|
+
fs24__namespace.rmSync(dest, { recursive: true, force: true });
|
|
10240
10432
|
} catch {
|
|
10241
10433
|
}
|
|
10242
10434
|
throw error;
|
|
@@ -10249,16 +10441,16 @@ function directorySize(root) {
|
|
|
10249
10441
|
const current = stack.pop();
|
|
10250
10442
|
let entries;
|
|
10251
10443
|
try {
|
|
10252
|
-
entries =
|
|
10444
|
+
entries = fs24__namespace.readdirSync(current, { withFileTypes: true });
|
|
10253
10445
|
} catch {
|
|
10254
10446
|
continue;
|
|
10255
10447
|
}
|
|
10256
10448
|
for (const entry of entries) {
|
|
10257
|
-
const full =
|
|
10449
|
+
const full = path25__namespace.join(current, entry.name);
|
|
10258
10450
|
if (entry.isDirectory()) stack.push(full);
|
|
10259
10451
|
else if (entry.isFile()) {
|
|
10260
10452
|
try {
|
|
10261
|
-
total +=
|
|
10453
|
+
total += fs24__namespace.statSync(full).size;
|
|
10262
10454
|
} catch {
|
|
10263
10455
|
}
|
|
10264
10456
|
}
|
|
@@ -10267,7 +10459,7 @@ function directorySize(root) {
|
|
|
10267
10459
|
return total;
|
|
10268
10460
|
}
|
|
10269
10461
|
function makeCloneDirectory() {
|
|
10270
|
-
return
|
|
10462
|
+
return fs24__namespace.mkdtempSync(path25__namespace.join(os2__namespace.tmpdir(), "codebase-snapshot-clone-"));
|
|
10271
10463
|
}
|
|
10272
10464
|
|
|
10273
10465
|
// src/mcp/instructions.ts
|
|
@@ -10465,7 +10657,7 @@ var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
|
|
|
10465
10657
|
var META_PREFIX = "- Meta: ";
|
|
10466
10658
|
var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
|
|
10467
10659
|
var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
|
|
10468
|
-
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
|
|
10660
|
+
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures", "comments-stripped"]);
|
|
10469
10661
|
var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
|
|
10470
10662
|
function readIncludedLines(fields) {
|
|
10471
10663
|
const last = fields[fields.length - 1];
|
|
@@ -10538,8 +10730,8 @@ function findSection(sections, relativePath) {
|
|
|
10538
10730
|
if (exact) return exact;
|
|
10539
10731
|
const foldedPath = rendered.toLowerCase();
|
|
10540
10732
|
const folded = sections.filter((section) => {
|
|
10541
|
-
const
|
|
10542
|
-
return
|
|
10733
|
+
const path26 = section.path.toLowerCase();
|
|
10734
|
+
return path26 === relativePath.toLowerCase() || path26 === foldedPath;
|
|
10543
10735
|
});
|
|
10544
10736
|
return folded.length === 1 ? folded[0] : null;
|
|
10545
10737
|
}
|
|
@@ -10560,26 +10752,28 @@ var ARTIFACT_FILES = {
|
|
|
10560
10752
|
fullXml: "full-codebase.xml",
|
|
10561
10753
|
sarif: "reports/audit.sarif"
|
|
10562
10754
|
};
|
|
10563
|
-
var TEXT_ARTIFACT = /\.(md|json|txt|sarif)$/i;
|
|
10755
|
+
var TEXT_ARTIFACT = /\.(md|json|txt|sarif|xml)$/i;
|
|
10564
10756
|
function sha256(buffer) {
|
|
10565
10757
|
return crypto.createHash("sha256").update(buffer).digest("hex");
|
|
10566
10758
|
}
|
|
10567
|
-
function readBytes(file) {
|
|
10568
|
-
try {
|
|
10569
|
-
return fs25__namespace.readFileSync(file);
|
|
10570
|
-
} catch {
|
|
10571
|
-
return null;
|
|
10572
|
-
}
|
|
10573
|
-
}
|
|
10574
10759
|
function readText2(file) {
|
|
10575
10760
|
try {
|
|
10576
|
-
return
|
|
10761
|
+
return fs24__namespace.readFileSync(file, "utf8");
|
|
10577
10762
|
} catch {
|
|
10578
10763
|
return null;
|
|
10579
10764
|
}
|
|
10580
10765
|
}
|
|
10766
|
+
function snapshotText(snapshotDir, relative15) {
|
|
10767
|
+
const read = readConfinedText(snapshotDir, relative15);
|
|
10768
|
+
return read.ok ? read.text : null;
|
|
10769
|
+
}
|
|
10770
|
+
function snapshotBytes(snapshotDir, relative15) {
|
|
10771
|
+
const read = readConfinedBytes(snapshotDir, relative15);
|
|
10772
|
+
return read.ok ? read.bytes : null;
|
|
10773
|
+
}
|
|
10581
10774
|
function readJson(file) {
|
|
10582
|
-
const
|
|
10775
|
+
const confined = readConfinedText(path25__namespace.dirname(file), path25__namespace.basename(file));
|
|
10776
|
+
const text2 = confined.ok ? confined.text : null;
|
|
10583
10777
|
if (text2 === null) return null;
|
|
10584
10778
|
try {
|
|
10585
10779
|
return JSON.parse(text2);
|
|
@@ -10590,14 +10784,14 @@ function readJson(file) {
|
|
|
10590
10784
|
function walk(dir, prefix = "") {
|
|
10591
10785
|
let entries;
|
|
10592
10786
|
try {
|
|
10593
|
-
entries =
|
|
10787
|
+
entries = fs24__namespace.readdirSync(dir, { withFileTypes: true });
|
|
10594
10788
|
} catch {
|
|
10595
10789
|
return [];
|
|
10596
10790
|
}
|
|
10597
10791
|
const files = [];
|
|
10598
10792
|
for (const entry of entries) {
|
|
10599
10793
|
const relative15 = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
10600
|
-
if (entry.isDirectory()) files.push(...walk(
|
|
10794
|
+
if (entry.isDirectory()) files.push(...walk(path25__namespace.join(dir, entry.name), relative15));
|
|
10601
10795
|
else if (entry.isFile()) files.push(relative15);
|
|
10602
10796
|
}
|
|
10603
10797
|
return files;
|
|
@@ -10636,16 +10830,28 @@ function secretTokens(text2) {
|
|
|
10636
10830
|
}
|
|
10637
10831
|
return [...tokens];
|
|
10638
10832
|
}
|
|
10639
|
-
function readArtifactTexts(snapshotDir) {
|
|
10833
|
+
function readArtifactTexts(snapshotDir, maxBytes = 32 * 1024 * 1024) {
|
|
10640
10834
|
const texts = [];
|
|
10835
|
+
let bytes = 0;
|
|
10641
10836
|
for (const relative15 of walk(snapshotDir)) {
|
|
10642
10837
|
if (!TEXT_ARTIFACT.test(relative15)) continue;
|
|
10643
|
-
const
|
|
10644
|
-
|
|
10838
|
+
const full = path25__namespace.join(snapshotDir, relative15);
|
|
10839
|
+
let size2;
|
|
10840
|
+
try {
|
|
10841
|
+
size2 = fs24__namespace.statSync(full).size;
|
|
10842
|
+
} catch {
|
|
10843
|
+
continue;
|
|
10844
|
+
}
|
|
10845
|
+
if (bytes + size2 > maxBytes) break;
|
|
10846
|
+
const text2 = snapshotText(snapshotDir, relative15);
|
|
10847
|
+
if (text2 !== null) {
|
|
10848
|
+
texts.push(text2);
|
|
10849
|
+
bytes += Buffer.byteLength(text2, "utf8");
|
|
10850
|
+
}
|
|
10645
10851
|
}
|
|
10646
10852
|
return texts;
|
|
10647
10853
|
}
|
|
10648
|
-
function findHostPaths(snapshotDir, repoDir) {
|
|
10854
|
+
function findHostPaths(snapshotDir, repoDir, maxBytes = 32 * 1024 * 1024) {
|
|
10649
10855
|
const patterns = [
|
|
10650
10856
|
/\/home\/[A-Za-z0-9._-]+/g,
|
|
10651
10857
|
/\/Users\/[A-Za-z0-9._-]+/g,
|
|
@@ -10656,10 +10862,19 @@ function findHostPaths(snapshotDir, repoDir) {
|
|
|
10656
10862
|
];
|
|
10657
10863
|
const repoPattern = new RegExp(escapeRegExp(repoDir), "g");
|
|
10658
10864
|
const hits = /* @__PURE__ */ new Set();
|
|
10865
|
+
let scanned = 0;
|
|
10659
10866
|
for (const relative15 of walk(snapshotDir)) {
|
|
10660
10867
|
if (!TEXT_ARTIFACT.test(relative15)) continue;
|
|
10661
|
-
|
|
10868
|
+
let size2;
|
|
10869
|
+
try {
|
|
10870
|
+
size2 = fs24__namespace.statSync(path25__namespace.join(snapshotDir, relative15)).size;
|
|
10871
|
+
} catch {
|
|
10872
|
+
continue;
|
|
10873
|
+
}
|
|
10874
|
+
if (scanned + size2 > maxBytes) break;
|
|
10875
|
+
const text2 = snapshotText(snapshotDir, relative15);
|
|
10662
10876
|
if (text2 === null) continue;
|
|
10877
|
+
scanned += Buffer.byteLength(text2, "utf8");
|
|
10663
10878
|
for (const pattern of patterns) {
|
|
10664
10879
|
for (const match of text2.match(pattern) ?? []) hits.add(relative15 + ": " + match);
|
|
10665
10880
|
}
|
|
@@ -10814,10 +11029,10 @@ function markdownPackBodies(text2) {
|
|
|
10814
11029
|
return bodies.size === 0 ? null : bodies;
|
|
10815
11030
|
}
|
|
10816
11031
|
function auditSnapshot(options) {
|
|
10817
|
-
const snapshotDir =
|
|
10818
|
-
const repoDir =
|
|
11032
|
+
const snapshotDir = path25__namespace.resolve(options.snapshotDir);
|
|
11033
|
+
const repoDir = path25__namespace.resolve(options.repoDir);
|
|
10819
11034
|
const checks = [];
|
|
10820
|
-
const manifestFile =
|
|
11035
|
+
const manifestFile = path25__namespace.join(snapshotDir, "manifest.json");
|
|
10821
11036
|
const raw = readJson(manifestFile);
|
|
10822
11037
|
const problem = raw === null ? "the file is missing or is not valid JSON" : describeManifestShapeProblem(raw);
|
|
10823
11038
|
if (raw === null || problem !== null) {
|
|
@@ -10846,7 +11061,7 @@ function auditSnapshot(options) {
|
|
|
10846
11061
|
const missingParts = [];
|
|
10847
11062
|
const mismatched = [];
|
|
10848
11063
|
for (const part of manifest.parts) {
|
|
10849
|
-
const bytes =
|
|
11064
|
+
const bytes = snapshotBytes(snapshotDir, "parts/" + part.filename);
|
|
10850
11065
|
if (bytes === null) {
|
|
10851
11066
|
missingParts.push(part.filename);
|
|
10852
11067
|
continue;
|
|
@@ -10914,7 +11129,7 @@ function auditSnapshot(options) {
|
|
|
10914
11129
|
const relative15 = ARTIFACT_FILES[key];
|
|
10915
11130
|
if (relative15 === void 0) continue;
|
|
10916
11131
|
artifactCount += 1;
|
|
10917
|
-
const bytes =
|
|
11132
|
+
const bytes = snapshotBytes(snapshotDir, relative15);
|
|
10918
11133
|
if (bytes === null) artifactProblems.push(relative15 + " is missing");
|
|
10919
11134
|
else if (typeof value.sha256 === "string" && sha256(bytes) !== value.sha256) {
|
|
10920
11135
|
artifactProblems.push(relative15 + " changed");
|
|
@@ -10961,8 +11176,8 @@ function auditSnapshot(options) {
|
|
|
10961
11176
|
unexpected.length + " unexpected path(s): " + sample(unexpected)
|
|
10962
11177
|
)
|
|
10963
11178
|
);
|
|
10964
|
-
const signaturePath =
|
|
10965
|
-
if (
|
|
11179
|
+
const signaturePath = path25__namespace.join(snapshotDir, "signature.json");
|
|
11180
|
+
if (fs24__namespace.existsSync(signaturePath)) {
|
|
10966
11181
|
const outcome = verifySnapshotSignature(snapshotDir);
|
|
10967
11182
|
checks.push(
|
|
10968
11183
|
outcome.ok ? check(
|
|
@@ -11027,7 +11242,7 @@ function auditSnapshot(options) {
|
|
|
11027
11242
|
manifest.files.map((file) => [anchorForPath(file.relativePath), file.relativePath])
|
|
11028
11243
|
);
|
|
11029
11244
|
for (const part of manifest.parts) {
|
|
11030
|
-
const partText =
|
|
11245
|
+
const partText = snapshotText(snapshotDir, "parts/" + part.filename);
|
|
11031
11246
|
if (partText === null) continue;
|
|
11032
11247
|
const sections = parsePartSections(partText);
|
|
11033
11248
|
partTexts.set(part.filename, partText);
|
|
@@ -11094,7 +11309,7 @@ function auditSnapshot(options) {
|
|
|
11094
11309
|
}
|
|
11095
11310
|
};
|
|
11096
11311
|
if (manifest.artifacts?.readme != null) {
|
|
11097
|
-
const text2 =
|
|
11312
|
+
const text2 = snapshotText(snapshotDir, "README.md");
|
|
11098
11313
|
if (text2 === null) {
|
|
11099
11314
|
reportProblems.push("README.md is recorded but unreadable");
|
|
11100
11315
|
} else {
|
|
@@ -11134,7 +11349,7 @@ function auditSnapshot(options) {
|
|
|
11134
11349
|
}
|
|
11135
11350
|
}
|
|
11136
11351
|
if (manifest.artifacts?.prompt != null) {
|
|
11137
|
-
const text2 =
|
|
11352
|
+
const text2 = snapshotText(snapshotDir, "PROMPT.md");
|
|
11138
11353
|
if (text2 === null) {
|
|
11139
11354
|
reportProblems.push("PROMPT.md is recorded but unreadable");
|
|
11140
11355
|
} else {
|
|
@@ -11323,7 +11538,7 @@ function auditSnapshot(options) {
|
|
|
11323
11538
|
];
|
|
11324
11539
|
for (const reader of packReaders) {
|
|
11325
11540
|
if (manifest.artifacts?.[reader.key] == null) continue;
|
|
11326
|
-
const packText =
|
|
11541
|
+
const packText = snapshotText(snapshotDir, reader.file);
|
|
11327
11542
|
const problems = [];
|
|
11328
11543
|
if (packText === null) {
|
|
11329
11544
|
problems.push(reader.file + " is recorded but unreadable");
|
|
@@ -11336,8 +11551,8 @@ function auditSnapshot(options) {
|
|
|
11336
11551
|
for (const file of manifest.files) {
|
|
11337
11552
|
if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
|
|
11338
11553
|
}
|
|
11339
|
-
for (const
|
|
11340
|
-
if (!known2.has(
|
|
11554
|
+
for (const path26 of packed) {
|
|
11555
|
+
if (!known2.has(path26)) problems.push(path26 + " is in the pack but not the manifest");
|
|
11341
11556
|
}
|
|
11342
11557
|
}
|
|
11343
11558
|
}
|
|
@@ -11486,7 +11701,7 @@ function auditSnapshot(options) {
|
|
|
11486
11701
|
let packBodies = 0;
|
|
11487
11702
|
let packSkipped = 0;
|
|
11488
11703
|
for (const pack of packsWanted) {
|
|
11489
|
-
const text2 =
|
|
11704
|
+
const text2 = snapshotText(snapshotDir, pack.file);
|
|
11490
11705
|
if (text2 === null) continue;
|
|
11491
11706
|
const bodies = pack.read(text2);
|
|
11492
11707
|
if (bodies === null) {
|
|
@@ -11550,7 +11765,8 @@ function auditSnapshot(options) {
|
|
|
11550
11765
|
unreplayable += 1;
|
|
11551
11766
|
continue;
|
|
11552
11767
|
}
|
|
11553
|
-
const
|
|
11768
|
+
const repoBytes = readConfinedBytes(repoDir, file.relativePath);
|
|
11769
|
+
const bytes = repoBytes.ok ? repoBytes.bytes : null;
|
|
11554
11770
|
if (bytes === null || sha256(bytes) !== file.hashSha256) {
|
|
11555
11771
|
unreplayable += 1;
|
|
11556
11772
|
continue;
|
|
@@ -11588,9 +11804,9 @@ function auditSnapshot(options) {
|
|
|
11588
11804
|
)
|
|
11589
11805
|
);
|
|
11590
11806
|
}
|
|
11591
|
-
const indexParent =
|
|
11592
|
-
const indexPath =
|
|
11593
|
-
if (
|
|
11807
|
+
const indexParent = path25__namespace.dirname(snapshotDir);
|
|
11808
|
+
const indexPath = path25__namespace.join(indexParent, "WORKSPACE.json");
|
|
11809
|
+
if (fs24__namespace.existsSync(indexPath)) {
|
|
11594
11810
|
const indexText = readText2(indexPath);
|
|
11595
11811
|
let members = [];
|
|
11596
11812
|
let problem2 = null;
|
|
@@ -11601,7 +11817,7 @@ function auditSnapshot(options) {
|
|
|
11601
11817
|
} catch (error) {
|
|
11602
11818
|
problem2 = error.message;
|
|
11603
11819
|
}
|
|
11604
|
-
const memberName =
|
|
11820
|
+
const memberName = path25__namespace.basename(snapshotDir);
|
|
11605
11821
|
const member = members.find((entry) => entry.name === memberName);
|
|
11606
11822
|
if (problem2 !== null) {
|
|
11607
11823
|
checks.push(check(
|
|
@@ -11625,7 +11841,7 @@ function auditSnapshot(options) {
|
|
|
11625
11841
|
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
11626
11842
|
disagreements.push("file count");
|
|
11627
11843
|
}
|
|
11628
|
-
const sourceGone = typeof member.path === "string" && !
|
|
11844
|
+
const sourceGone = typeof member.path === "string" && !fs24__namespace.existsSync(member.path) ? "Member " + memberName + " source directory is gone (" + member.path + "); the snapshot still describes it. Regenerate the workspace." : null;
|
|
11629
11845
|
checks.push(
|
|
11630
11846
|
sourceGone !== null ? check("workspace.index", "The workspace index agrees with this member", "warning", "warn", sourceGone) : disagreements.length === 0 ? check(
|
|
11631
11847
|
"workspace.index",
|
|
@@ -11650,7 +11866,14 @@ function auditSnapshot(options) {
|
|
|
11650
11866
|
for (const relative15 of walk(snapshotDir)) {
|
|
11651
11867
|
if (!TEXT_ARTIFACT.test(relative15) || scannedBytes > scanBudget) continue;
|
|
11652
11868
|
if (relative15 === SIGNATURE_FILE) continue;
|
|
11653
|
-
|
|
11869
|
+
let size2;
|
|
11870
|
+
try {
|
|
11871
|
+
size2 = fs24__namespace.statSync(path25__namespace.join(snapshotDir, relative15)).size;
|
|
11872
|
+
} catch {
|
|
11873
|
+
continue;
|
|
11874
|
+
}
|
|
11875
|
+
if (scannedBytes + size2 > scanBudget) break;
|
|
11876
|
+
const text2 = snapshotText(snapshotDir, relative15);
|
|
11654
11877
|
if (text2 === null) continue;
|
|
11655
11878
|
scannedBytes += Buffer.byteLength(text2, "utf8");
|
|
11656
11879
|
let findingCount = 0;
|
|
@@ -11668,9 +11891,9 @@ function auditSnapshot(options) {
|
|
|
11668
11891
|
leakHits.push(relative15 + " (" + findingCount + " line(s))");
|
|
11669
11892
|
}
|
|
11670
11893
|
}
|
|
11671
|
-
const signatureRecordPath =
|
|
11672
|
-
if (
|
|
11673
|
-
const recordText =
|
|
11894
|
+
const signatureRecordPath = path25__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
11895
|
+
if (fs24__namespace.existsSync(signatureRecordPath)) {
|
|
11896
|
+
const recordText = snapshotText(snapshotDir, SIGNATURE_FILE);
|
|
11674
11897
|
if (recordText !== null) {
|
|
11675
11898
|
scannedBytes += Buffer.byteLength(recordText, "utf8");
|
|
11676
11899
|
let scanText = recordText;
|
|
@@ -11710,11 +11933,17 @@ function auditSnapshot(options) {
|
|
|
11710
11933
|
);
|
|
11711
11934
|
const leakedFrom = [];
|
|
11712
11935
|
let compared = 0;
|
|
11713
|
-
const artifactTexts = readArtifactTexts(snapshotDir);
|
|
11936
|
+
const artifactTexts = readArtifactTexts(snapshotDir, scanBudget);
|
|
11714
11937
|
const artifactContains = (token) => artifactTexts.some((text2) => text2.includes(token));
|
|
11715
11938
|
for (const record of skippedSensitive.slice(0, 40)) {
|
|
11716
11939
|
if (record.path.includes("[REDACTED") || compared > 400) continue;
|
|
11717
|
-
|
|
11940
|
+
try {
|
|
11941
|
+
if (fs24__namespace.statSync(path25__namespace.join(repoDir, record.path)).size > scanBudget) continue;
|
|
11942
|
+
} catch {
|
|
11943
|
+
continue;
|
|
11944
|
+
}
|
|
11945
|
+
const repoRead = readConfinedText(repoDir, record.path);
|
|
11946
|
+
const text2 = repoRead.ok ? repoRead.text : null;
|
|
11718
11947
|
if (text2 === null) continue;
|
|
11719
11948
|
for (const token of secretTokens(text2)) {
|
|
11720
11949
|
compared += 1;
|
|
@@ -11736,7 +11965,7 @@ function auditSnapshot(options) {
|
|
|
11736
11965
|
"A value from " + sample([...new Set(leakedFrom)]) + " appears in the snapshot."
|
|
11737
11966
|
)
|
|
11738
11967
|
);
|
|
11739
|
-
const pii = findHostPaths(snapshotDir, repoDir);
|
|
11968
|
+
const pii = findHostPaths(snapshotDir, repoDir, scanBudget);
|
|
11740
11969
|
checks.push(
|
|
11741
11970
|
pii.length === 0 ? check(
|
|
11742
11971
|
"pii.paths",
|
|
@@ -11857,6 +12086,17 @@ function report(snapshotDir, repoDir, checks) {
|
|
|
11857
12086
|
counts
|
|
11858
12087
|
};
|
|
11859
12088
|
}
|
|
12089
|
+
function safeRegularFile(cwd, absolute) {
|
|
12090
|
+
try {
|
|
12091
|
+
if (!fs24__namespace.lstatSync(absolute).isFile()) return false;
|
|
12092
|
+
const root = fs24__namespace.realpathSync(cwd);
|
|
12093
|
+
const real = fs24__namespace.realpathSync(absolute);
|
|
12094
|
+
const relative15 = path25__namespace.relative(root, real);
|
|
12095
|
+
return relative15 !== ".." && !relative15.startsWith(".." + path25__namespace.sep) && !path25__namespace.isAbsolute(relative15);
|
|
12096
|
+
} catch {
|
|
12097
|
+
return false;
|
|
12098
|
+
}
|
|
12099
|
+
}
|
|
11860
12100
|
function describeMatcher(matcher) {
|
|
11861
12101
|
if (typeof matcher === "string") return matcher;
|
|
11862
12102
|
if (matcher instanceof RegExp) return String(matcher);
|
|
@@ -11866,13 +12106,13 @@ function describeMatcher(matcher) {
|
|
|
11866
12106
|
return String(matcher);
|
|
11867
12107
|
}
|
|
11868
12108
|
function normalizeTarget(cwd, target) {
|
|
11869
|
-
const resolvedCwd =
|
|
11870
|
-
const absolute =
|
|
11871
|
-
const relative15 =
|
|
11872
|
-
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${
|
|
12109
|
+
const resolvedCwd = path25__namespace.resolve(cwd);
|
|
12110
|
+
const absolute = path25__namespace.resolve(resolvedCwd, target);
|
|
12111
|
+
const relative15 = path25__namespace.relative(resolvedCwd, absolute);
|
|
12112
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path25__namespace.sep}`) || path25__namespace.isAbsolute(relative15)) {
|
|
11873
12113
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
11874
12114
|
}
|
|
11875
|
-
return { relative: relative15.split(
|
|
12115
|
+
return { relative: relative15.split(path25__namespace.sep).join("/"), outsideRoot: false };
|
|
11876
12116
|
}
|
|
11877
12117
|
function findRuleMatch(rules, relativePath) {
|
|
11878
12118
|
return rules.find(
|
|
@@ -11891,9 +12131,9 @@ function findRecordedAncestor(skipped, relative15, maskedPath2) {
|
|
|
11891
12131
|
return nearest;
|
|
11892
12132
|
}
|
|
11893
12133
|
function readManifest2(config) {
|
|
11894
|
-
const manifestPath =
|
|
12134
|
+
const manifestPath = path25__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
11895
12135
|
try {
|
|
11896
|
-
return JSON.parse(
|
|
12136
|
+
return JSON.parse(fs24__namespace.readFileSync(manifestPath, "utf8"));
|
|
11897
12137
|
} catch {
|
|
11898
12138
|
return null;
|
|
11899
12139
|
}
|
|
@@ -11911,10 +12151,14 @@ function explainPath(config, target) {
|
|
|
11911
12151
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
11912
12152
|
};
|
|
11913
12153
|
}
|
|
11914
|
-
const absolute =
|
|
12154
|
+
const absolute = path25__namespace.join(config.cwd, relative15);
|
|
12155
|
+
const stagedBlob = config.staged === true ? readStagedBlob(config.cwd, relative15) : null;
|
|
11915
12156
|
const result = {
|
|
11916
12157
|
path: maskedPath2,
|
|
11917
|
-
|
|
12158
|
+
// `existsSync` follows a symlink, so an in-repo link to /etc/passwd answered "exists" for a
|
|
12159
|
+
// file the scanner refuses. `lstat` plus a canonical containment check keeps the answer about
|
|
12160
|
+
// a regular file the repository actually contains; a staged blob is the index's answer.
|
|
12161
|
+
exists: stagedBlob !== null || safeRegularFile(config.cwd, absolute),
|
|
11918
12162
|
included: false
|
|
11919
12163
|
};
|
|
11920
12164
|
const collection = collectFiles(config.cwd, {
|
|
@@ -11928,7 +12172,7 @@ function explainPath(config, target) {
|
|
|
11928
12172
|
// Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
|
|
11929
12173
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
11930
12174
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11931
|
-
(directory) =>
|
|
12175
|
+
(directory) => path25__namespace.relative(config.cwd, path25__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11932
12176
|
).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
|
|
11933
12177
|
});
|
|
11934
12178
|
if (!collection.files.includes(relative15)) {
|
|
@@ -11993,11 +12237,13 @@ function explainPath(config, target) {
|
|
|
11993
12237
|
result.detail = "binary extension; generate skips it without reading and records `binary` in manifest.skipped[]";
|
|
11994
12238
|
return result;
|
|
11995
12239
|
}
|
|
11996
|
-
let sizeOnDisk = null;
|
|
11997
|
-
|
|
11998
|
-
|
|
11999
|
-
|
|
12000
|
-
|
|
12240
|
+
let sizeOnDisk = stagedBlob?.length ?? null;
|
|
12241
|
+
if (sizeOnDisk === null) {
|
|
12242
|
+
try {
|
|
12243
|
+
sizeOnDisk = fs24__namespace.statSync(absolute).size;
|
|
12244
|
+
} catch {
|
|
12245
|
+
sizeOnDisk = null;
|
|
12246
|
+
}
|
|
12001
12247
|
}
|
|
12002
12248
|
if (sizeOnDisk !== null && sizeOnDisk > BINARY_SCAN_BYTES && isBinaryFile(absolute)) {
|
|
12003
12249
|
result.included = false;
|
|
@@ -12005,10 +12251,10 @@ function explainPath(config, target) {
|
|
|
12005
12251
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
12006
12252
|
return result;
|
|
12007
12253
|
}
|
|
12008
|
-
if (
|
|
12254
|
+
if (stagedBlob !== null || safeRegularFile(config.cwd, absolute)) {
|
|
12009
12255
|
let buffer;
|
|
12010
12256
|
try {
|
|
12011
|
-
buffer =
|
|
12257
|
+
buffer = stagedBlob ?? fs24__namespace.readFileSync(absolute);
|
|
12012
12258
|
} catch (err) {
|
|
12013
12259
|
result.included = false;
|
|
12014
12260
|
result.reason = "read-error";
|
|
@@ -12057,6 +12303,22 @@ function explainPath(config, target) {
|
|
|
12057
12303
|
const record = manifest?.skipped?.find((skip) => skip.path === relative15);
|
|
12058
12304
|
if (record !== void 0 && (record.reason === "not-selected" || record.reason === "unchanged")) {
|
|
12059
12305
|
result.included = false;
|
|
12306
|
+
for (const key of [
|
|
12307
|
+
"layer",
|
|
12308
|
+
"layerMatch",
|
|
12309
|
+
"kind",
|
|
12310
|
+
"kindMatch",
|
|
12311
|
+
"language",
|
|
12312
|
+
"inclusionMode",
|
|
12313
|
+
"lines",
|
|
12314
|
+
"bytes",
|
|
12315
|
+
"encoding",
|
|
12316
|
+
"secretCount",
|
|
12317
|
+
"secrets"
|
|
12318
|
+
]) {
|
|
12319
|
+
delete result[key];
|
|
12320
|
+
}
|
|
12321
|
+
result.part = null;
|
|
12060
12322
|
result.reason = record.reason;
|
|
12061
12323
|
result.detail = record.detail ?? (record.reason === "not-selected" ? "the snapshot was generated for a selection (--slice or --budget-tokens) that did not include this path" : "the snapshot was generated with a changed-files scope that did not include this path");
|
|
12062
12324
|
}
|
|
@@ -12098,7 +12360,7 @@ function renderExplainText(result) {
|
|
|
12098
12360
|
return lines.join("\n");
|
|
12099
12361
|
}
|
|
12100
12362
|
function workerEntry(directory, isCjs) {
|
|
12101
|
-
const entry =
|
|
12363
|
+
const entry = path25__namespace.join(directory, isCjs ? "index.cjs" : "index.js");
|
|
12102
12364
|
return { path: entry, url: url.pathToFileURL(entry).href };
|
|
12103
12365
|
}
|
|
12104
12366
|
var WORKER_SOURCE = `
|
|
@@ -12107,7 +12369,10 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
12107
12369
|
(async () => {
|
|
12108
12370
|
try {
|
|
12109
12371
|
const mod = await import(workerData.entryUrl);
|
|
12110
|
-
const loaded =
|
|
12372
|
+
const loaded =
|
|
12373
|
+
workerData.config === null || workerData.config === undefined
|
|
12374
|
+
? await mod.loadConfigFileDetailed(workerData.cwd, { allowExecutableConfig: false })
|
|
12375
|
+
: { config: workerData.config, errors: [] };
|
|
12111
12376
|
if (loaded.errors.length > 0) {
|
|
12112
12377
|
parentPort.postMessage({ ok: false, message: loaded.errors.join("; ") });
|
|
12113
12378
|
return;
|
|
@@ -12119,6 +12384,7 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
12119
12384
|
const manifest = mod.generateSnapshot(config, {
|
|
12120
12385
|
dryRun: workerData.dryRun === true,
|
|
12121
12386
|
...(workerData.narrow ?? {}),
|
|
12387
|
+
...(workerData.source === undefined ? {} : { source: workerData.source }),
|
|
12122
12388
|
...(workerData.runId === undefined ? {} : { runId: workerData.runId }),
|
|
12123
12389
|
});
|
|
12124
12390
|
const skipCounts = new Map();
|
|
@@ -12174,7 +12440,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
12174
12440
|
});
|
|
12175
12441
|
};
|
|
12176
12442
|
const isCjs = typeof __dirname !== "undefined";
|
|
12177
|
-
const directory = isCjs ? __dirname :
|
|
12443
|
+
const directory = isCjs ? __dirname : path25__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
12178
12444
|
try {
|
|
12179
12445
|
worker = new worker_threads.Worker(WORKER_SOURCE, {
|
|
12180
12446
|
eval: true,
|
|
@@ -12184,6 +12450,8 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
12184
12450
|
cliOptions,
|
|
12185
12451
|
dryRun: options.dryRun === true,
|
|
12186
12452
|
narrow: options.narrow ?? {},
|
|
12453
|
+
...options.config === void 0 ? {} : { config: options.config },
|
|
12454
|
+
...options.source === void 0 ? {} : { source: options.source },
|
|
12187
12455
|
...options.runId === void 0 ? {} : { runId: options.runId }
|
|
12188
12456
|
}
|
|
12189
12457
|
});
|
|
@@ -12236,69 +12504,13 @@ function windowText(body, fromLine, lineCount) {
|
|
|
12236
12504
|
pastEnd
|
|
12237
12505
|
};
|
|
12238
12506
|
}
|
|
12239
|
-
function isInside2(parent, child) {
|
|
12240
|
-
const relative15 = path26__namespace.relative(parent, child);
|
|
12241
|
-
return relative15 === "" || !relative15.startsWith("..") && !path26__namespace.isAbsolute(relative15);
|
|
12242
|
-
}
|
|
12243
|
-
function readConfinedText(baseDir, relativePath) {
|
|
12244
|
-
if (relativePath.length === 0 || relativePath.includes("\0")) {
|
|
12245
|
-
return { ok: false, reason: "not-file", message: "the file name is empty or contains a NUL byte" };
|
|
12246
|
-
}
|
|
12247
|
-
if (path26__namespace.isAbsolute(relativePath)) {
|
|
12248
|
-
return { ok: false, reason: "outside", message: "an absolute path is not a snapshot-relative file" };
|
|
12249
|
-
}
|
|
12250
|
-
let baseReal;
|
|
12251
|
-
try {
|
|
12252
|
-
baseReal = fs25__namespace.realpathSync(path26__namespace.resolve(baseDir));
|
|
12253
|
-
} catch {
|
|
12254
|
-
return { ok: false, reason: "missing", message: "the snapshot directory does not exist" };
|
|
12255
|
-
}
|
|
12256
|
-
const candidate = path26__namespace.resolve(baseReal, relativePath);
|
|
12257
|
-
if (!isInside2(baseReal, candidate)) {
|
|
12258
|
-
return { ok: false, reason: "outside", message: "the path resolves outside the snapshot directory" };
|
|
12259
|
-
}
|
|
12260
|
-
let stats;
|
|
12261
|
-
try {
|
|
12262
|
-
stats = fs25__namespace.lstatSync(candidate);
|
|
12263
|
-
} catch (error) {
|
|
12264
|
-
const code = error.code;
|
|
12265
|
-
return {
|
|
12266
|
-
ok: false,
|
|
12267
|
-
reason: code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable",
|
|
12268
|
-
message: code === "ENOENT" || code === "ENOTDIR" ? "the file does not exist" : "the file could not be inspected"
|
|
12269
|
-
};
|
|
12270
|
-
}
|
|
12271
|
-
if (stats.isSymbolicLink()) {
|
|
12272
|
-
return { ok: false, reason: "not-file", message: "the file is a symbolic link" };
|
|
12273
|
-
}
|
|
12274
|
-
if (!stats.isFile()) {
|
|
12275
|
-
return { ok: false, reason: "not-file", message: "the path is not a regular file" };
|
|
12276
|
-
}
|
|
12277
|
-
let real;
|
|
12278
|
-
try {
|
|
12279
|
-
real = fs25__namespace.realpathSync(candidate);
|
|
12280
|
-
} catch {
|
|
12281
|
-
return { ok: false, reason: "unreadable", message: "the file could not be resolved" };
|
|
12282
|
-
}
|
|
12283
|
-
if (!isInside2(baseReal, real)) {
|
|
12284
|
-
return { ok: false, reason: "outside", message: "the file resolves outside the snapshot directory" };
|
|
12285
|
-
}
|
|
12286
|
-
try {
|
|
12287
|
-
const text2 = fs25__namespace.readFileSync(real, "utf8");
|
|
12288
|
-
return { ok: true, text: text2, path: real, stats: fs25__namespace.statSync(real) };
|
|
12289
|
-
} catch {
|
|
12290
|
-
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
12291
|
-
}
|
|
12292
|
-
}
|
|
12293
|
-
|
|
12294
|
-
// src/mcp/workspace.ts
|
|
12295
12507
|
function foldForComparison(value) {
|
|
12296
12508
|
return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
12297
12509
|
}
|
|
12298
12510
|
function canonicalPath(value) {
|
|
12299
|
-
const absolute =
|
|
12511
|
+
const absolute = path25__namespace.resolve(value);
|
|
12300
12512
|
try {
|
|
12301
|
-
return
|
|
12513
|
+
return fs24__namespace.realpathSync(absolute);
|
|
12302
12514
|
} catch {
|
|
12303
12515
|
return absolute;
|
|
12304
12516
|
}
|
|
@@ -12306,29 +12518,29 @@ function canonicalPath(value) {
|
|
|
12306
12518
|
function isInside3(parent, child) {
|
|
12307
12519
|
const foldedParent = foldForComparison(parent);
|
|
12308
12520
|
const foldedChild = foldForComparison(child);
|
|
12309
|
-
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${
|
|
12521
|
+
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path25__namespace.sep}`);
|
|
12310
12522
|
}
|
|
12311
12523
|
function resolveThroughExistingAncestor(target) {
|
|
12312
12524
|
let existing = target;
|
|
12313
12525
|
const missing = [];
|
|
12314
|
-
while (!
|
|
12315
|
-
missing.unshift(
|
|
12316
|
-
const parent =
|
|
12526
|
+
while (!fs24__namespace.existsSync(existing)) {
|
|
12527
|
+
missing.unshift(path25__namespace.basename(existing));
|
|
12528
|
+
const parent = path25__namespace.dirname(existing);
|
|
12317
12529
|
if (parent === existing) break;
|
|
12318
12530
|
existing = parent;
|
|
12319
12531
|
}
|
|
12320
12532
|
const resolved = canonicalPath(existing);
|
|
12321
|
-
return missing.length === 0 ? resolved :
|
|
12533
|
+
return missing.length === 0 ? resolved : path25__namespace.join(resolved, ...missing);
|
|
12322
12534
|
}
|
|
12323
12535
|
function resolveRoot(requested, context) {
|
|
12324
12536
|
if (requested !== void 0 && (typeof requested !== "string" || requested.trim().length === 0)) {
|
|
12325
12537
|
return { ok: false, message: '"root" must be a non-empty string when provided.' };
|
|
12326
12538
|
}
|
|
12327
12539
|
const wanted = typeof requested === "string" ? requested.trim() : context.cwd;
|
|
12328
|
-
const absolute =
|
|
12540
|
+
const absolute = path25__namespace.resolve(context.cwd, wanted);
|
|
12329
12541
|
let stats;
|
|
12330
12542
|
try {
|
|
12331
|
-
stats =
|
|
12543
|
+
stats = fs24__namespace.statSync(absolute);
|
|
12332
12544
|
} catch {
|
|
12333
12545
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
12334
12546
|
}
|
|
@@ -12380,7 +12592,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
12380
12592
|
}
|
|
12381
12593
|
const requested = overrides.outDir.trim();
|
|
12382
12594
|
const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
|
|
12383
|
-
const resolved = resolveThroughExistingAncestor(
|
|
12595
|
+
const resolved = resolveThroughExistingAncestor(path25__namespace.resolve(root, requested));
|
|
12384
12596
|
if (!permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) {
|
|
12385
12597
|
const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
|
|
12386
12598
|
return {
|
|
@@ -12430,25 +12642,25 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
12430
12642
|
var MANIFEST_CACHE_LIMIT = 8;
|
|
12431
12643
|
var manifestCache = /* @__PURE__ */ new Map();
|
|
12432
12644
|
function manifestPathFor(workspace) {
|
|
12433
|
-
return
|
|
12645
|
+
return path25__namespace.resolve(workspace.root, workspace.config.outDir, "manifest.json");
|
|
12434
12646
|
}
|
|
12435
12647
|
function partPathFor(workspace, filename) {
|
|
12436
12648
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
12437
|
-
const partsDir =
|
|
12438
|
-
const resolved =
|
|
12439
|
-
const relative15 =
|
|
12440
|
-
if (relative15.length === 0 || relative15.includes(
|
|
12649
|
+
const partsDir = path25__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
12650
|
+
const resolved = path25__namespace.resolve(partsDir, filename);
|
|
12651
|
+
const relative15 = path25__namespace.relative(partsDir, resolved);
|
|
12652
|
+
if (relative15.length === 0 || relative15.includes(path25__namespace.sep) || relative15.includes("/") || relative15.includes("\\") || path25__namespace.isAbsolute(relative15)) {
|
|
12441
12653
|
return null;
|
|
12442
12654
|
}
|
|
12443
12655
|
let stats;
|
|
12444
12656
|
try {
|
|
12445
|
-
stats =
|
|
12657
|
+
stats = fs24__namespace.lstatSync(resolved);
|
|
12446
12658
|
} catch {
|
|
12447
12659
|
return null;
|
|
12448
12660
|
}
|
|
12449
12661
|
if (!stats.isFile()) return null;
|
|
12450
12662
|
try {
|
|
12451
|
-
if (
|
|
12663
|
+
if (path25__namespace.dirname(fs24__namespace.realpathSync(resolved)) !== fs24__namespace.realpathSync(partsDir)) return null;
|
|
12452
12664
|
} catch {
|
|
12453
12665
|
return null;
|
|
12454
12666
|
}
|
|
@@ -12456,8 +12668,8 @@ function partPathFor(workspace, filename) {
|
|
|
12456
12668
|
}
|
|
12457
12669
|
function readManifest3(workspace) {
|
|
12458
12670
|
const file = manifestPathFor(workspace);
|
|
12459
|
-
const shown =
|
|
12460
|
-
const confined = readConfinedText(
|
|
12671
|
+
const shown = path25__namespace.relative(workspace.root, file).split(path25__namespace.sep).join("/") || file;
|
|
12672
|
+
const confined = readConfinedText(path25__namespace.dirname(file), path25__namespace.basename(file));
|
|
12461
12673
|
if (!confined.ok) {
|
|
12462
12674
|
if (confined.reason === "missing") {
|
|
12463
12675
|
return {
|
|
@@ -12539,11 +12751,18 @@ function unsafeRegExpReason(source) {
|
|
|
12539
12751
|
if (char === ")") {
|
|
12540
12752
|
const group = groups.pop();
|
|
12541
12753
|
if (group === void 0) continue;
|
|
12542
|
-
|
|
12543
|
-
if (next === "*" || next === "+" || next === "{" && isUnboundedBrace(source, index + 1)) {
|
|
12754
|
+
if (isQuantifiedAt(source, index + 1)) {
|
|
12544
12755
|
if (group.quantified || group.alternation) {
|
|
12545
12756
|
return "a quantified group contains another quantifier or an alternation";
|
|
12546
12757
|
}
|
|
12758
|
+
group.quantified = true;
|
|
12759
|
+
} else if (isOptionalQuantifierAt(source, index + 1)) {
|
|
12760
|
+
group.quantified = true;
|
|
12761
|
+
}
|
|
12762
|
+
const parent = groups[groups.length - 1];
|
|
12763
|
+
if (parent !== void 0) {
|
|
12764
|
+
parent.quantified = parent.quantified || group.quantified;
|
|
12765
|
+
parent.alternation = parent.alternation || group.alternation;
|
|
12547
12766
|
}
|
|
12548
12767
|
continue;
|
|
12549
12768
|
}
|
|
@@ -12590,11 +12809,31 @@ function unsafeRegExpReason(source) {
|
|
|
12590
12809
|
}
|
|
12591
12810
|
return null;
|
|
12592
12811
|
}
|
|
12593
|
-
function
|
|
12812
|
+
function isOptionalQuantifierAt(source, start) {
|
|
12813
|
+
if (source[start] === "?") return true;
|
|
12814
|
+
if (source[start] !== "{") return false;
|
|
12594
12815
|
const close = source.indexOf("}", start + 1);
|
|
12595
12816
|
if (close === -1) return false;
|
|
12596
12817
|
const body = source.slice(start + 1, close);
|
|
12597
|
-
|
|
12818
|
+
const match = /^(\d+)(?:,(\d*))?$/.exec(body);
|
|
12819
|
+
if (match === null) return false;
|
|
12820
|
+
const minimum = Number(match[1]);
|
|
12821
|
+
if (match[2] === void 0) return minimum <= 1;
|
|
12822
|
+
const maximum = match[2] === "" ? Infinity : Number(match[2]);
|
|
12823
|
+
return maximum <= 1;
|
|
12824
|
+
}
|
|
12825
|
+
function isQuantifiedAt(source, start) {
|
|
12826
|
+
const char = source[start];
|
|
12827
|
+
if (char === "*" || char === "+") return true;
|
|
12828
|
+
if (char !== "{") return false;
|
|
12829
|
+
const close = source.indexOf("}", start + 1);
|
|
12830
|
+
if (close === -1) return false;
|
|
12831
|
+
const body = source.slice(start + 1, close);
|
|
12832
|
+
const match = /^(\d+)(?:,(\d*))?$/.exec(body);
|
|
12833
|
+
if (match === null) return false;
|
|
12834
|
+
if (match[2] === void 0) return Number(match[1]) > 1;
|
|
12835
|
+
if (match[2] === "") return true;
|
|
12836
|
+
return Number(match[2]) > 1;
|
|
12598
12837
|
}
|
|
12599
12838
|
|
|
12600
12839
|
// src/mcp/tools.ts
|
|
@@ -12689,7 +12928,7 @@ function formatBytes2(bytes) {
|
|
|
12689
12928
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
12690
12929
|
}
|
|
12691
12930
|
function relativeFor(workspace, absolute) {
|
|
12692
|
-
return
|
|
12931
|
+
return path25__namespace.relative(workspace.root, absolute).split(path25__namespace.sep).join("/");
|
|
12693
12932
|
}
|
|
12694
12933
|
function capped(values, limit = 20) {
|
|
12695
12934
|
return { count: values.length, sample: values.slice(0, limit) };
|
|
@@ -12708,13 +12947,13 @@ function summarizeDrift(drift) {
|
|
|
12708
12947
|
function toRelativePath(root, value) {
|
|
12709
12948
|
const cleaned = value.trim();
|
|
12710
12949
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
12711
|
-
const resolvedRoot =
|
|
12712
|
-
const absolute =
|
|
12713
|
-
const relative15 =
|
|
12714
|
-
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${
|
|
12950
|
+
const resolvedRoot = path25__namespace.resolve(root);
|
|
12951
|
+
const absolute = path25__namespace.resolve(resolvedRoot, cleaned);
|
|
12952
|
+
const relative15 = path25__namespace.relative(resolvedRoot, absolute);
|
|
12953
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path25__namespace.sep}`) || path25__namespace.isAbsolute(relative15)) {
|
|
12715
12954
|
return null;
|
|
12716
12955
|
}
|
|
12717
|
-
return relative15.split(
|
|
12956
|
+
return relative15.split(path25__namespace.sep).join("/");
|
|
12718
12957
|
}
|
|
12719
12958
|
function symbolsOf(entry) {
|
|
12720
12959
|
const summary = entry.summary;
|
|
@@ -12807,8 +13046,8 @@ var historyTool = {
|
|
|
12807
13046
|
async handler(args, context) {
|
|
12808
13047
|
const prepared = await prepare(args, context, outDirOverride(args));
|
|
12809
13048
|
if (!prepared.ok) return prepared.outcome;
|
|
12810
|
-
const snapshotDir =
|
|
12811
|
-
const reportRead = readConfinedText(snapshotDir,
|
|
13049
|
+
const snapshotDir = path25__namespace.resolve(prepared.workspace.root, prepared.workspace.config.outDir);
|
|
13050
|
+
const reportRead = readConfinedText(snapshotDir, path25__namespace.posix.join("reports", "log.md"));
|
|
12812
13051
|
if (!reportRead.ok) {
|
|
12813
13052
|
return {
|
|
12814
13053
|
text: "This snapshot has no readable reports/log.md. Generate it with `snapshot_generate { includeLogs: 20 }`, or `generate --include-logs 20` on the command line; the report is opt-in because the commit subjects are repository content, and it must be a regular file inside the snapshot.",
|
|
@@ -12876,7 +13115,7 @@ var budgetTool = {
|
|
|
12876
13115
|
...args.includeTests === true ? { includeTests: true } : {}
|
|
12877
13116
|
});
|
|
12878
13117
|
const paths = new Set(plan.files.map((file) => file.path));
|
|
12879
|
-
const gained = [...paths].filter((
|
|
13118
|
+
const gained = [...paths].filter((path26) => !previous.has(path26)).sort();
|
|
12880
13119
|
previous = paths;
|
|
12881
13120
|
rows.push({
|
|
12882
13121
|
budget,
|
|
@@ -12979,8 +13218,8 @@ var workspaceTool = {
|
|
|
12979
13218
|
async handler(args, context) {
|
|
12980
13219
|
const prepared = await prepare(args, context, outDirOverride(args));
|
|
12981
13220
|
if (!prepared.ok) return prepared.outcome;
|
|
12982
|
-
const snapshotDir =
|
|
12983
|
-
const index =
|
|
13221
|
+
const snapshotDir = path25__namespace.resolve(prepared.workspace.root, prepared.workspace.config.outDir);
|
|
13222
|
+
const index = path25__namespace.join(snapshotDir, "WORKSPACE.json");
|
|
12984
13223
|
const read = readConfinedText(snapshotDir, "WORKSPACE.json");
|
|
12985
13224
|
if (!read.ok) {
|
|
12986
13225
|
return {
|
|
@@ -12989,7 +13228,12 @@ var workspaceTool = {
|
|
|
12989
13228
|
};
|
|
12990
13229
|
}
|
|
12991
13230
|
const text2 = read.text;
|
|
12992
|
-
|
|
13231
|
+
let document;
|
|
13232
|
+
try {
|
|
13233
|
+
document = JSON.parse(text2);
|
|
13234
|
+
} catch (error) {
|
|
13235
|
+
return { text: "WORKSPACE.json is not valid JSON: " + error.message, isError: true };
|
|
13236
|
+
}
|
|
12993
13237
|
const members = document.members ?? [];
|
|
12994
13238
|
const links = document.links ?? [];
|
|
12995
13239
|
const lines = [
|
|
@@ -13188,7 +13432,7 @@ var cyclesTool = {
|
|
|
13188
13432
|
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
13189
13433
|
});
|
|
13190
13434
|
const edges = /* @__PURE__ */ new Map();
|
|
13191
|
-
for (const
|
|
13435
|
+
for (const path26 of byPath.keys()) edges.set(path26, []);
|
|
13192
13436
|
for (const entry of read.manifest.indexes.imports.byFile) {
|
|
13193
13437
|
const targets = edges.get(entry.path);
|
|
13194
13438
|
if (targets === void 0) continue;
|
|
@@ -13300,15 +13544,21 @@ var searchTool = {
|
|
|
13300
13544
|
if (partPath === null) continue;
|
|
13301
13545
|
let text2;
|
|
13302
13546
|
try {
|
|
13303
|
-
text2 =
|
|
13547
|
+
text2 = fs24__namespace.readFileSync(partPath, "utf8");
|
|
13304
13548
|
} catch {
|
|
13305
13549
|
continue;
|
|
13306
13550
|
}
|
|
13307
|
-
|
|
13551
|
+
const partBytes = Buffer.byteLength(text2, "utf8");
|
|
13552
|
+
if (partBytes > MAX_SEARCH_BYTES) {
|
|
13308
13553
|
skippedOversize.push(part.filename);
|
|
13554
|
+
truncated = true;
|
|
13309
13555
|
continue;
|
|
13310
13556
|
}
|
|
13311
|
-
scanned
|
|
13557
|
+
if (scanned + partBytes > MAX_SEARCH_BYTES) {
|
|
13558
|
+
truncated = true;
|
|
13559
|
+
break;
|
|
13560
|
+
}
|
|
13561
|
+
scanned += partBytes;
|
|
13312
13562
|
for (const section of parsePartSections(text2)) {
|
|
13313
13563
|
if (matches.length >= cap) {
|
|
13314
13564
|
truncated = true;
|
|
@@ -13431,7 +13681,7 @@ var reviewTool = {
|
|
|
13431
13681
|
return { text: error.message, isError: true };
|
|
13432
13682
|
}
|
|
13433
13683
|
const report2 = auditSnapshot({
|
|
13434
|
-
snapshotDir:
|
|
13684
|
+
snapshotDir: path25__namespace.resolve(workspace.root, workspace.config.outDir),
|
|
13435
13685
|
repoDir: workspace.root
|
|
13436
13686
|
});
|
|
13437
13687
|
const failed = report2.checks.filter((check2) => check2.status === "fail").map((check2) => check2.id + ": " + check2.detail);
|
|
@@ -13453,7 +13703,7 @@ var reviewTool = {
|
|
|
13453
13703
|
}
|
|
13454
13704
|
let section = null;
|
|
13455
13705
|
try {
|
|
13456
|
-
section = findSection(parsePartSections(
|
|
13706
|
+
section = findSection(parsePartSections(fs24__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
13457
13707
|
} catch {
|
|
13458
13708
|
section = null;
|
|
13459
13709
|
}
|
|
@@ -13543,31 +13793,31 @@ var diffContextTool = {
|
|
|
13543
13793
|
const changed = [];
|
|
13544
13794
|
const text2 = [];
|
|
13545
13795
|
let used = 0;
|
|
13546
|
-
for (const
|
|
13547
|
-
const file = byPath.get(
|
|
13796
|
+
for (const path26 of wanted) {
|
|
13797
|
+
const file = byPath.get(path26.toLowerCase());
|
|
13548
13798
|
if (file === void 0) {
|
|
13549
|
-
missing.push(
|
|
13799
|
+
missing.push(path26);
|
|
13550
13800
|
continue;
|
|
13551
13801
|
}
|
|
13552
13802
|
const partPath = partPathFor(workspace, file.part);
|
|
13553
13803
|
if (partPath === null) {
|
|
13554
|
-
missing.push(
|
|
13804
|
+
missing.push(path26 + " (part missing)");
|
|
13555
13805
|
continue;
|
|
13556
13806
|
}
|
|
13557
13807
|
let section;
|
|
13558
13808
|
try {
|
|
13559
|
-
section = findSection(parsePartSections(
|
|
13809
|
+
section = findSection(parsePartSections(fs24__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
13560
13810
|
} catch {
|
|
13561
13811
|
section = null;
|
|
13562
13812
|
}
|
|
13563
13813
|
if (section === null) {
|
|
13564
|
-
missing.push(
|
|
13814
|
+
missing.push(path26 + " (section not found)");
|
|
13565
13815
|
continue;
|
|
13566
13816
|
}
|
|
13567
13817
|
const window = windowText(section.body, 1, linesPerFile);
|
|
13568
13818
|
const tokens = Math.max(1, Math.ceil(Buffer.byteLength(window.text, "utf8") / 4));
|
|
13569
13819
|
if (used + tokens > budget) {
|
|
13570
|
-
missing.push(
|
|
13820
|
+
missing.push(path26 + " (budget)");
|
|
13571
13821
|
continue;
|
|
13572
13822
|
}
|
|
13573
13823
|
used += tokens;
|
|
@@ -13642,7 +13892,7 @@ var symbolTool = {
|
|
|
13642
13892
|
if (partPath === null) continue;
|
|
13643
13893
|
let partText;
|
|
13644
13894
|
try {
|
|
13645
|
-
partText =
|
|
13895
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
13646
13896
|
} catch {
|
|
13647
13897
|
continue;
|
|
13648
13898
|
}
|
|
@@ -13693,7 +13943,7 @@ var symbolTool = {
|
|
|
13693
13943
|
}
|
|
13694
13944
|
let partText;
|
|
13695
13945
|
try {
|
|
13696
|
-
partText =
|
|
13946
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
13697
13947
|
} catch {
|
|
13698
13948
|
continue;
|
|
13699
13949
|
}
|
|
@@ -13797,7 +14047,7 @@ var contextTool = {
|
|
|
13797
14047
|
}
|
|
13798
14048
|
if (!sectionsByPart.has(file.part)) {
|
|
13799
14049
|
try {
|
|
13800
|
-
sectionsByPart.set(file.part, parsePartSections(
|
|
14050
|
+
sectionsByPart.set(file.part, parsePartSections(fs24__namespace.readFileSync(partPath, "utf8")));
|
|
13801
14051
|
} catch {
|
|
13802
14052
|
sectionsByPart.set(file.part, null);
|
|
13803
14053
|
}
|
|
@@ -14035,7 +14285,7 @@ var answerTool = {
|
|
|
14035
14285
|
let partText = parts.get(partPath);
|
|
14036
14286
|
if (partText === void 0) {
|
|
14037
14287
|
try {
|
|
14038
|
-
partText =
|
|
14288
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
14039
14289
|
} catch {
|
|
14040
14290
|
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
14041
14291
|
continue;
|
|
@@ -14132,7 +14382,7 @@ var healthTool = {
|
|
|
14132
14382
|
if (!prepared.ok) return prepared.outcome;
|
|
14133
14383
|
const workspace = prepared.workspace;
|
|
14134
14384
|
const report2 = auditSnapshot({
|
|
14135
|
-
snapshotDir:
|
|
14385
|
+
snapshotDir: path25__namespace.resolve(workspace.root, workspace.config.outDir),
|
|
14136
14386
|
repoDir: workspace.root,
|
|
14137
14387
|
...typeof args.maxScanBytes === "number" ? { maxScanBytes: args.maxScanBytes } : {},
|
|
14138
14388
|
...args.deep === true ? { deep: true } : {}
|
|
@@ -14271,7 +14521,12 @@ var planTool = {
|
|
|
14271
14521
|
const prepared = await prepare(args, context, workspaceOverrides(args));
|
|
14272
14522
|
if (!prepared.ok) return prepared.outcome;
|
|
14273
14523
|
const workspace = prepared.workspace;
|
|
14274
|
-
const
|
|
14524
|
+
const controller = new AbortController();
|
|
14525
|
+
context.onCancel?.(() => controller.abort());
|
|
14526
|
+
const result = await generateInWorker(workspace.root, workspace.cliOptions, {
|
|
14527
|
+
dryRun: true,
|
|
14528
|
+
signal: controller.signal
|
|
14529
|
+
});
|
|
14275
14530
|
if (!result.ok) return failure(result.message);
|
|
14276
14531
|
const summary = result.summary;
|
|
14277
14532
|
const topReasons = summary.skipReasons;
|
|
@@ -14416,7 +14671,7 @@ var generateTool = {
|
|
|
14416
14671
|
context.notify?.({ message: "writing the snapshot", progress: 2, total: 2 });
|
|
14417
14672
|
const summary = result.summary;
|
|
14418
14673
|
forgetManifest(manifestPathFor(workspace));
|
|
14419
|
-
const written = relativeFor(workspace,
|
|
14674
|
+
const written = relativeFor(workspace, path25__namespace.resolve(workspace.root, workspace.config.outDir));
|
|
14420
14675
|
const lines = [
|
|
14421
14676
|
`Wrote ${written}/`,
|
|
14422
14677
|
`Files: ${summary.totalFiles} included, ${summary.skippedCount} skipped, ${plural(summary.partsCount, "part")}`,
|
|
@@ -14479,7 +14734,12 @@ function configAsGenerated(workspace, manifest) {
|
|
|
14479
14734
|
...cli.includeLogs !== void 0 || configured("logCount") || recorded?.logCount !== void 0 ? { logCount: choose("logCount", recorded?.logCount, workspace.config.logCount, cli.includeLogs) } : {},
|
|
14480
14735
|
...cli.skeleton === true || configured("skeleton") || recorded?.skeleton !== void 0 ? { skeleton: choose("skeleton", recorded?.skeleton, workspace.config.skeleton, cli.skeleton === true ? true : void 0) } : {},
|
|
14481
14736
|
...cli.sarif === true || configured("sarif") || recorded?.sarif !== void 0 ? { sarif: choose("sarif", recorded?.sarif, workspace.config.sarif, cli.sarif === true ? true : void 0) } : {},
|
|
14482
|
-
...configured("maxParts") || recorded?.maxParts !== void 0 ? { maxParts: choose("maxParts", recorded?.maxParts, workspace.config.maxParts) } : {}
|
|
14737
|
+
...configured("maxParts") || recorded?.maxParts !== void 0 ? { maxParts: choose("maxParts", recorded?.maxParts, workspace.config.maxParts) } : {},
|
|
14738
|
+
...cli.maxPartTokens !== void 0 || configured("maxPartTokens") || recorded?.maxPartTokens !== void 0 ? { maxPartTokens: choose("maxPartTokens", recorded?.maxPartTokens, workspace.config.maxPartTokens, cli.maxPartTokens) } : {},
|
|
14739
|
+
...cli.changedSince !== void 0 || configured("changedSince") || recorded?.changedSince !== void 0 ? { changedSince: choose("changedSince", recorded?.changedSince, workspace.config.changedSince, cli.changedSince) } : {},
|
|
14740
|
+
...cli.staged === true || configured("staged") || recorded?.staged !== void 0 ? { staged: choose("staged", recorded?.staged, workspace.config.staged, cli.staged === true ? true : void 0) } : {},
|
|
14741
|
+
...cli.withDependents === true || configured("withDependents") || recorded?.withDependents !== void 0 ? { withDependents: choose("withDependents", recorded?.withDependents, workspace.config.withDependents, cli.withDependents === true ? true : void 0) } : {},
|
|
14742
|
+
...configured("promptTask") || recorded?.promptTask !== void 0 ? { promptTask: choose("promptTask", recorded?.promptTask, workspace.config.promptTask) } : {}
|
|
14483
14743
|
};
|
|
14484
14744
|
}
|
|
14485
14745
|
var validateTool = {
|
|
@@ -14861,7 +15121,7 @@ var readTool = {
|
|
|
14861
15121
|
}
|
|
14862
15122
|
let partText;
|
|
14863
15123
|
try {
|
|
14864
|
-
partText =
|
|
15124
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
14865
15125
|
} catch {
|
|
14866
15126
|
return failure(
|
|
14867
15127
|
`${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
|
|
@@ -15370,7 +15630,7 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
15370
15630
|
"version"
|
|
15371
15631
|
],
|
|
15372
15632
|
diff: ["format", "mode", "no-config", "no-update-check", "help", "version"],
|
|
15373
|
-
describe: ["format", "mode", "help", "version"],
|
|
15633
|
+
describe: ["format", "mode", "no-update-check", "help", "version"],
|
|
15374
15634
|
init: [
|
|
15375
15635
|
"install-hook",
|
|
15376
15636
|
"cwd",
|
|
@@ -15391,7 +15651,7 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
15391
15651
|
"help",
|
|
15392
15652
|
"version"
|
|
15393
15653
|
],
|
|
15394
|
-
skill: ["cwd", "format", "mode", "install", "target", "help", "version"],
|
|
15654
|
+
skill: ["cwd", "format", "mode", "install", "target", "no-update-check", "help", "version"],
|
|
15395
15655
|
// `mcp` reads the repository, so it takes --cwd. It has no --format: stdout carries JSON-RPC
|
|
15396
15656
|
// messages, and there is no second shape to choose, so offering the flag would be a lie.
|
|
15397
15657
|
serve: ["port", "host", "token", "no-auth", "allow-private", "cwd", "no-update-check", "help"],
|
|
@@ -15450,6 +15710,7 @@ var COMMAND_ORDER = [
|
|
|
15450
15710
|
"health",
|
|
15451
15711
|
"report",
|
|
15452
15712
|
"explain",
|
|
15713
|
+
"update",
|
|
15453
15714
|
"init",
|
|
15454
15715
|
"setup",
|
|
15455
15716
|
"diff",
|
|
@@ -15842,24 +16103,28 @@ function buildAgentContract() {
|
|
|
15842
16103
|
{
|
|
15843
16104
|
flag: "--only",
|
|
15844
16105
|
type: "string",
|
|
16106
|
+
default: "unset",
|
|
15845
16107
|
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
15846
16108
|
appliesTo: optionAppliesTo("only")
|
|
15847
16109
|
},
|
|
15848
16110
|
{
|
|
15849
16111
|
flag: "--ignore",
|
|
15850
16112
|
type: "string",
|
|
16113
|
+
default: "unset",
|
|
15851
16114
|
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
15852
16115
|
appliesTo: optionAppliesTo("ignore")
|
|
15853
16116
|
},
|
|
15854
16117
|
{
|
|
15855
16118
|
flag: "--remove-empty-lines",
|
|
15856
16119
|
type: "boolean",
|
|
16120
|
+
default: false,
|
|
15857
16121
|
summary: "Drop blank and whitespace-only lines from emitted bodies; line numbers no longer match the source.",
|
|
15858
16122
|
appliesTo: optionAppliesTo("remove-empty-lines")
|
|
15859
16123
|
},
|
|
15860
16124
|
{
|
|
15861
16125
|
flag: "--all-members",
|
|
15862
16126
|
type: "boolean",
|
|
16127
|
+
default: false,
|
|
15863
16128
|
summary: "Audit every snapshot a --workspace run wrote, not only the one at outDir.",
|
|
15864
16129
|
appliesTo: optionAppliesTo("all-members")
|
|
15865
16130
|
},
|
|
@@ -16470,7 +16735,7 @@ async function workspaceFor(context) {
|
|
|
16470
16735
|
}
|
|
16471
16736
|
function readFileIfPresent(file) {
|
|
16472
16737
|
try {
|
|
16473
|
-
return
|
|
16738
|
+
return fs24__namespace.readFileSync(file, "utf8");
|
|
16474
16739
|
} catch {
|
|
16475
16740
|
return null;
|
|
16476
16741
|
}
|
|
@@ -16509,9 +16774,9 @@ function buildResourceProvider() {
|
|
|
16509
16774
|
}
|
|
16510
16775
|
];
|
|
16511
16776
|
const workspace = await workspaceFor(context);
|
|
16512
|
-
const reportsDir = "error" in workspace ? null :
|
|
16777
|
+
const reportsDir = "error" in workspace ? null : path25__namespace.resolve(workspace.root, workspace.config.outDir, "reports");
|
|
16513
16778
|
for (const [uri, report2] of REPORT_URIS) {
|
|
16514
|
-
const present = reportsDir !== null &&
|
|
16779
|
+
const present = reportsDir !== null && fs24__namespace.existsSync(path25__namespace.join(reportsDir, report2.file));
|
|
16515
16780
|
if (!present) continue;
|
|
16516
16781
|
resources.push({
|
|
16517
16782
|
uri,
|
|
@@ -16573,7 +16838,7 @@ function buildResourceProvider() {
|
|
|
16573
16838
|
}
|
|
16574
16839
|
const workspace = await workspaceFor(context);
|
|
16575
16840
|
if ("error" in workspace) return null;
|
|
16576
|
-
const snapshotDir =
|
|
16841
|
+
const snapshotDir = path25__namespace.resolve(workspace.root, workspace.config.outDir);
|
|
16577
16842
|
if (uri === PROMPT_URI) {
|
|
16578
16843
|
const read = readConfinedText(snapshotDir, "PROMPT.md");
|
|
16579
16844
|
if (!read.ok) {
|
|
@@ -16590,7 +16855,7 @@ function buildResourceProvider() {
|
|
|
16590
16855
|
}
|
|
16591
16856
|
const report2 = REPORT_URIS.get(uri);
|
|
16592
16857
|
if (report2) {
|
|
16593
|
-
const read = readConfinedText(snapshotDir,
|
|
16858
|
+
const read = readConfinedText(snapshotDir, path25__namespace.posix.join("reports", report2.file));
|
|
16594
16859
|
if (!read.ok) {
|
|
16595
16860
|
throw new ResourceNotFoundError(
|
|
16596
16861
|
uri,
|
|
@@ -16606,7 +16871,7 @@ function buildResourceProvider() {
|
|
|
16606
16871
|
if (uri === "snapshot://manifest") {
|
|
16607
16872
|
const read = readManifest3(workspace);
|
|
16608
16873
|
if (!read.ok) return null;
|
|
16609
|
-
const confined = readConfinedText(
|
|
16874
|
+
const confined = readConfinedText(path25__namespace.dirname(read.file), path25__namespace.basename(read.file));
|
|
16610
16875
|
if (!confined.ok) return null;
|
|
16611
16876
|
return {
|
|
16612
16877
|
uri,
|
|
@@ -16625,7 +16890,7 @@ function buildResourceProvider() {
|
|
|
16625
16890
|
if (partPath === null) return null;
|
|
16626
16891
|
let partBytes;
|
|
16627
16892
|
try {
|
|
16628
|
-
partBytes =
|
|
16893
|
+
partBytes = fs24__namespace.statSync(partPath).size;
|
|
16629
16894
|
} catch {
|
|
16630
16895
|
return null;
|
|
16631
16896
|
}
|
|
@@ -16661,52 +16926,52 @@ function validateArguments(schema, value) {
|
|
|
16661
16926
|
}
|
|
16662
16927
|
return problems;
|
|
16663
16928
|
}
|
|
16664
|
-
function checkValue(
|
|
16929
|
+
function checkValue(path26, schema, value) {
|
|
16665
16930
|
if (schema.enum && !schema.enum.includes(value)) {
|
|
16666
|
-
return [`"${
|
|
16931
|
+
return [`"${path26}" must be one of: ${schema.enum.join(", ")}`];
|
|
16667
16932
|
}
|
|
16668
16933
|
switch (schema.type) {
|
|
16669
16934
|
case "string": {
|
|
16670
|
-
if (typeof value !== "string") return [`"${
|
|
16935
|
+
if (typeof value !== "string") return [`"${path26}" must be a string`];
|
|
16671
16936
|
const problems = [];
|
|
16672
16937
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
16673
|
-
problems.push(`"${
|
|
16938
|
+
problems.push(`"${path26}" must be at least ${schema.minLength} character(s)`);
|
|
16674
16939
|
}
|
|
16675
16940
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
16676
|
-
problems.push(`"${
|
|
16941
|
+
problems.push(`"${path26}" must be at most ${schema.maxLength} character(s)`);
|
|
16677
16942
|
}
|
|
16678
16943
|
return problems;
|
|
16679
16944
|
}
|
|
16680
16945
|
case "number":
|
|
16681
16946
|
case "integer": {
|
|
16682
16947
|
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
16683
|
-
return [`"${
|
|
16948
|
+
return [`"${path26}" must be a number`];
|
|
16684
16949
|
}
|
|
16685
16950
|
if (schema.type === "integer" && !Number.isInteger(value)) {
|
|
16686
|
-
return [`"${
|
|
16951
|
+
return [`"${path26}" must be an integer`];
|
|
16687
16952
|
}
|
|
16688
16953
|
const problems = [];
|
|
16689
16954
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
16690
|
-
problems.push(`"${
|
|
16955
|
+
problems.push(`"${path26}" must be >= ${schema.minimum}`);
|
|
16691
16956
|
}
|
|
16692
16957
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
16693
|
-
problems.push(`"${
|
|
16958
|
+
problems.push(`"${path26}" must be <= ${schema.maximum}`);
|
|
16694
16959
|
}
|
|
16695
16960
|
return problems;
|
|
16696
16961
|
}
|
|
16697
16962
|
case "boolean":
|
|
16698
|
-
return typeof value === "boolean" ? [] : [`"${
|
|
16963
|
+
return typeof value === "boolean" ? [] : [`"${path26}" must be a boolean`];
|
|
16699
16964
|
case "array": {
|
|
16700
|
-
if (!Array.isArray(value)) return [`"${
|
|
16965
|
+
if (!Array.isArray(value)) return [`"${path26}" must be an array`];
|
|
16701
16966
|
if (!schema.items) return [];
|
|
16702
16967
|
const problems = [];
|
|
16703
16968
|
value.forEach((item, index) => {
|
|
16704
|
-
problems.push(...checkValue(`${
|
|
16969
|
+
problems.push(...checkValue(`${path26}[${index}]`, schema.items, item));
|
|
16705
16970
|
});
|
|
16706
16971
|
return problems;
|
|
16707
16972
|
}
|
|
16708
16973
|
case "object":
|
|
16709
|
-
return isJsonObject(value) ? [] : [`"${
|
|
16974
|
+
return isJsonObject(value) ? [] : [`"${path26}" must be an object`];
|
|
16710
16975
|
default:
|
|
16711
16976
|
return [];
|
|
16712
16977
|
}
|
|
@@ -17114,30 +17379,44 @@ function crc32(data) {
|
|
|
17114
17379
|
return (crc ^ 4294967295) >>> 0;
|
|
17115
17380
|
}
|
|
17116
17381
|
function dosDateTime(date) {
|
|
17117
|
-
const year = Math.max(1980, date.
|
|
17382
|
+
const year = Math.max(1980, date.getUTCFullYear());
|
|
17118
17383
|
return {
|
|
17119
|
-
time: date.
|
|
17120
|
-
date: year - 1980 << 9 | date.
|
|
17384
|
+
time: date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2),
|
|
17385
|
+
date: year - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate()
|
|
17121
17386
|
};
|
|
17122
17387
|
}
|
|
17123
17388
|
function walkFiles(root, prefix = "") {
|
|
17124
17389
|
const files = [];
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17390
|
+
const stack = [prefix];
|
|
17391
|
+
while (stack.length > 0) {
|
|
17392
|
+
const current = stack.pop();
|
|
17393
|
+
for (const entry of fs24__namespace.readdirSync(path25__namespace.join(root, current), { withFileTypes: true })) {
|
|
17394
|
+
const relative15 = current === "" ? entry.name : current + "/" + entry.name;
|
|
17395
|
+
if (entry.isDirectory()) stack.push(relative15);
|
|
17396
|
+
else if (entry.isFile()) files.push(relative15);
|
|
17397
|
+
}
|
|
17129
17398
|
}
|
|
17130
17399
|
return files;
|
|
17131
17400
|
}
|
|
17132
17401
|
function writeZip(options) {
|
|
17133
17402
|
const entries = [...options.entries ?? []];
|
|
17403
|
+
const maxTotalBytes = options.maxTotalBytes ?? 256 * 1024 * 1024;
|
|
17404
|
+
let totalBytes = entries.reduce((total, entry) => total + entry.content.length, 0);
|
|
17405
|
+
if (totalBytes > maxTotalBytes) {
|
|
17406
|
+
throw new Error("zip: uncompressed content exceeds " + maxTotalBytes + " bytes");
|
|
17407
|
+
}
|
|
17134
17408
|
if (options.directory !== void 0) {
|
|
17135
17409
|
const root = options.directory;
|
|
17136
17410
|
for (const relative15 of walkFiles(root)) {
|
|
17137
17411
|
if (options.skip !== void 0 && options.skip(relative15)) continue;
|
|
17138
|
-
const full =
|
|
17139
|
-
const stat =
|
|
17140
|
-
|
|
17412
|
+
const full = path25__namespace.join(root, relative15);
|
|
17413
|
+
const stat = fs24__namespace.statSync(full);
|
|
17414
|
+
if (totalBytes + stat.size > maxTotalBytes) {
|
|
17415
|
+
throw new Error("zip: uncompressed content exceeds " + maxTotalBytes + " bytes");
|
|
17416
|
+
}
|
|
17417
|
+
const content = fs24__namespace.readFileSync(full);
|
|
17418
|
+
totalBytes += content.length;
|
|
17419
|
+
entries.push({ name: relative15, content, mtime: stat.mtime });
|
|
17141
17420
|
}
|
|
17142
17421
|
}
|
|
17143
17422
|
if (entries.length > 65535) {
|
|
@@ -17375,6 +17654,23 @@ async function startWebServer(options) {
|
|
|
17375
17654
|
throw new Error("Refusing to serve " + host + " without a token.");
|
|
17376
17655
|
}
|
|
17377
17656
|
const createMcp = () => createServer({ cwd: options.cwd, log });
|
|
17657
|
+
const toolCount = buildTools().length;
|
|
17658
|
+
const rateWindows = /* @__PURE__ */ new Map();
|
|
17659
|
+
const rateLimited = (request) => {
|
|
17660
|
+
const remote = request.socket.remoteAddress ?? "unknown";
|
|
17661
|
+
const now = Date.now();
|
|
17662
|
+
const window = rateWindows.get(remote);
|
|
17663
|
+
if (window === void 0 || window.resetAt <= now) {
|
|
17664
|
+
if (!rateWindows.has(remote) && rateWindows.size >= 1024) {
|
|
17665
|
+
for (const [key, value] of rateWindows) if (value.resetAt <= now) rateWindows.delete(key);
|
|
17666
|
+
}
|
|
17667
|
+
rateWindows.set(remote, { count: 1, resetAt: now + 1e4 });
|
|
17668
|
+
return false;
|
|
17669
|
+
}
|
|
17670
|
+
if (window.count >= 120) return true;
|
|
17671
|
+
window.count += 1;
|
|
17672
|
+
return false;
|
|
17673
|
+
};
|
|
17378
17674
|
const mcpPerSocket = /* @__PURE__ */ new WeakMap();
|
|
17379
17675
|
const mcpFor = (socket) => {
|
|
17380
17676
|
let server2 = mcpPerSocket.get(socket);
|
|
@@ -17386,43 +17682,44 @@ async function startWebServer(options) {
|
|
|
17386
17682
|
};
|
|
17387
17683
|
const temporaryClones = /* @__PURE__ */ new Set();
|
|
17388
17684
|
let mcpInFlight = 0;
|
|
17389
|
-
const allowedRoots = [
|
|
17685
|
+
const allowedRoots = [path25__namespace.resolve(options.cwd)];
|
|
17390
17686
|
const canonical = (candidate) => {
|
|
17391
17687
|
try {
|
|
17392
|
-
return
|
|
17688
|
+
return fs24__namespace.realpathSync(candidate);
|
|
17393
17689
|
} catch {
|
|
17394
17690
|
return null;
|
|
17395
17691
|
}
|
|
17396
17692
|
};
|
|
17693
|
+
const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
17397
17694
|
const inside = (resolved) => allowedRoots.some((root) => {
|
|
17398
17695
|
const canonicalRoot = canonical(root);
|
|
17399
17696
|
if (canonicalRoot === null) return false;
|
|
17400
|
-
const relative15 =
|
|
17401
|
-
return relative15 === "" || !relative15.startsWith(`..${
|
|
17697
|
+
const relative15 = path25__namespace.relative(fold(canonicalRoot), fold(resolved));
|
|
17698
|
+
return relative15 === "" || !relative15.startsWith(`..${path25__namespace.sep}`) && relative15 !== ".." && !path25__namespace.isAbsolute(relative15);
|
|
17402
17699
|
});
|
|
17403
17700
|
const insideAllowedRoots = (candidate) => {
|
|
17404
17701
|
const resolved = canonical(candidate);
|
|
17405
17702
|
return resolved === null ? false : inside(resolved);
|
|
17406
17703
|
};
|
|
17407
17704
|
const lexicallyInside = (candidate) => {
|
|
17408
|
-
const resolved =
|
|
17705
|
+
const resolved = fold(path25__namespace.resolve(candidate));
|
|
17409
17706
|
return allowedRoots.some((root) => {
|
|
17410
|
-
const
|
|
17411
|
-
return resolved ===
|
|
17707
|
+
const resolvedRoot = fold(path25__namespace.resolve(root));
|
|
17708
|
+
return resolved === resolvedRoot || resolved.startsWith(resolvedRoot + path25__namespace.sep);
|
|
17412
17709
|
});
|
|
17413
17710
|
};
|
|
17414
17711
|
const insideAllowedRootsForWrite = (candidate) => {
|
|
17415
|
-
let existing =
|
|
17712
|
+
let existing = path25__namespace.resolve(candidate);
|
|
17416
17713
|
const tail = [];
|
|
17417
|
-
while (!
|
|
17418
|
-
tail.unshift(
|
|
17419
|
-
const parent =
|
|
17714
|
+
while (!fs24__namespace.existsSync(existing)) {
|
|
17715
|
+
tail.unshift(path25__namespace.basename(existing));
|
|
17716
|
+
const parent = path25__namespace.dirname(existing);
|
|
17420
17717
|
if (parent === existing) break;
|
|
17421
17718
|
existing = parent;
|
|
17422
17719
|
}
|
|
17423
17720
|
const resolved = canonical(existing);
|
|
17424
17721
|
if (resolved === null) return false;
|
|
17425
|
-
return inside(tail.length === 0 ? resolved :
|
|
17722
|
+
return inside(tail.length === 0 ? resolved : path25__namespace.join(resolved, ...tail));
|
|
17426
17723
|
};
|
|
17427
17724
|
const authorized = (request) => {
|
|
17428
17725
|
if (token === null) return true;
|
|
@@ -17466,8 +17763,12 @@ async function startWebServer(options) {
|
|
|
17466
17763
|
response.end();
|
|
17467
17764
|
return;
|
|
17468
17765
|
}
|
|
17766
|
+
if (rateLimited(request)) {
|
|
17767
|
+
send(429, { error: "too many requests" }, { "retry-after": "10" });
|
|
17768
|
+
return;
|
|
17769
|
+
}
|
|
17469
17770
|
if (request.method === "GET" && request.url === "/healthz") {
|
|
17470
|
-
send(200, { ok: true, name: "codebase-snapshot", tools:
|
|
17771
|
+
send(200, { ok: true, name: "codebase-snapshot", tools: toolCount });
|
|
17471
17772
|
return;
|
|
17472
17773
|
}
|
|
17473
17774
|
if (request.method === "GET" && (request.url === "/" || request.url === "/index.html")) {
|
|
@@ -17534,7 +17835,13 @@ async function startWebServer(options) {
|
|
|
17534
17835
|
}
|
|
17535
17836
|
if (answers.length === 0) send(202, "");
|
|
17536
17837
|
else send(200, Array.isArray(message) ? answers : answers[0]);
|
|
17537
|
-
})()
|
|
17838
|
+
})().catch((error) => {
|
|
17839
|
+
log("serve: " + error.message);
|
|
17840
|
+
try {
|
|
17841
|
+
send(500, { error: "internal error" });
|
|
17842
|
+
} catch {
|
|
17843
|
+
}
|
|
17844
|
+
});
|
|
17538
17845
|
});
|
|
17539
17846
|
return;
|
|
17540
17847
|
}
|
|
@@ -17610,7 +17917,7 @@ async function startWebServer(options) {
|
|
|
17610
17917
|
return;
|
|
17611
17918
|
}
|
|
17612
17919
|
} else {
|
|
17613
|
-
target =
|
|
17920
|
+
target = path25__namespace.resolve(options.cwd, source);
|
|
17614
17921
|
if (!insideAllowedRoots(target)) {
|
|
17615
17922
|
send(403, { error: "outside the served directory: " + target });
|
|
17616
17923
|
return;
|
|
@@ -17618,7 +17925,7 @@ async function startWebServer(options) {
|
|
|
17618
17925
|
}
|
|
17619
17926
|
let stat;
|
|
17620
17927
|
try {
|
|
17621
|
-
stat =
|
|
17928
|
+
stat = fs24__namespace.statSync(target);
|
|
17622
17929
|
} catch {
|
|
17623
17930
|
send(404, { error: "no such path: " + target });
|
|
17624
17931
|
return;
|
|
@@ -17627,36 +17934,55 @@ async function startWebServer(options) {
|
|
|
17627
17934
|
send(400, { error: "not a directory: " + target });
|
|
17628
17935
|
return;
|
|
17629
17936
|
}
|
|
17630
|
-
const loaded = await loadConfigFileDetailed(target, { allowExecutableConfig: false });
|
|
17937
|
+
const loaded = isRemote ? { config: null, errors: [] } : await loadConfigFileDetailed(target, { allowExecutableConfig: false });
|
|
17631
17938
|
if (loaded.errors.length > 0) {
|
|
17632
17939
|
send(400, { error: loaded.errors.join("; ") });
|
|
17633
17940
|
return;
|
|
17634
17941
|
}
|
|
17635
17942
|
const runConfig = isRemote ? {
|
|
17636
|
-
...loaded.config ?? {},
|
|
17637
17943
|
outDir: "snapshot",
|
|
17638
17944
|
tmpDir: "snapshot.tmp",
|
|
17639
17945
|
hooks: {}
|
|
17640
17946
|
} : loaded.config ?? {};
|
|
17641
17947
|
const configuredOutDir = typeof runConfig.outDir === "string" && runConfig.outDir.trim() !== "" ? runConfig.outDir : "snapshot";
|
|
17642
|
-
const snapshotDir =
|
|
17948
|
+
const snapshotDir = path25__namespace.resolve(target, configuredOutDir);
|
|
17643
17949
|
if (!insideAllowedRootsForWrite(snapshotDir)) {
|
|
17644
17950
|
send(403, { error: "the configured outDir resolves outside the served directory" });
|
|
17645
17951
|
return;
|
|
17646
17952
|
}
|
|
17647
17953
|
const configuredTmpDir = typeof runConfig.tmpDir === "string" && runConfig.tmpDir.trim() !== "" ? runConfig.tmpDir : "snapshot.tmp";
|
|
17648
|
-
const stagingDir =
|
|
17954
|
+
const stagingDir = path25__namespace.resolve(target, configuredTmpDir);
|
|
17649
17955
|
if (!insideAllowedRootsForWrite(stagingDir)) {
|
|
17650
17956
|
send(403, { error: "the configured tmpDir resolves outside the served directory" });
|
|
17651
17957
|
return;
|
|
17652
17958
|
}
|
|
17653
17959
|
const started = Date.now();
|
|
17654
17960
|
try {
|
|
17655
|
-
const
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
|
|
17961
|
+
const generated = await generateInWorker(
|
|
17962
|
+
target,
|
|
17963
|
+
{ cwd: target },
|
|
17964
|
+
{
|
|
17965
|
+
config: runConfig,
|
|
17966
|
+
...provenance === void 0 ? {} : { source: provenance },
|
|
17967
|
+
...mode === "slice" && question.length >= 3 ? { narrow: { slice: { question } } } : {},
|
|
17968
|
+
...mode === "budget" && budgetTokens !== void 0 ? { narrow: { budgetTokens } } : {}
|
|
17969
|
+
}
|
|
17970
|
+
);
|
|
17971
|
+
if (!generated.ok) {
|
|
17972
|
+
send(500, { error: generated.message });
|
|
17973
|
+
return;
|
|
17974
|
+
}
|
|
17975
|
+
const manifestRead = readConfinedText(snapshotDir, "manifest.json");
|
|
17976
|
+
if (!manifestRead.ok) {
|
|
17977
|
+
send(500, { error: "the generate worker did not write manifest.json" });
|
|
17978
|
+
return;
|
|
17979
|
+
}
|
|
17980
|
+
const manifest = JSON.parse(manifestRead.text);
|
|
17981
|
+
const shape = describeManifestShapeProblem(manifest);
|
|
17982
|
+
if (shape !== null) {
|
|
17983
|
+
send(500, { error: "the generated manifest is not a snapshot manifest: " + shape });
|
|
17984
|
+
return;
|
|
17985
|
+
}
|
|
17660
17986
|
const seconds = ((Date.now() - started) / 1e3).toFixed(2);
|
|
17661
17987
|
const health = auditSnapshot({ snapshotDir, repoDir: target });
|
|
17662
17988
|
send(200, {
|
|
@@ -17679,35 +18005,50 @@ async function startWebServer(options) {
|
|
|
17679
18005
|
} catch (error) {
|
|
17680
18006
|
send(500, { error: error.message });
|
|
17681
18007
|
}
|
|
17682
|
-
})()
|
|
18008
|
+
})().catch((error) => {
|
|
18009
|
+
log("serve: " + error.message);
|
|
18010
|
+
try {
|
|
18011
|
+
send(500, { error: "internal error" });
|
|
18012
|
+
} catch {
|
|
18013
|
+
}
|
|
18014
|
+
});
|
|
17683
18015
|
});
|
|
17684
18016
|
return;
|
|
17685
18017
|
}
|
|
17686
18018
|
if (request.method === "GET" && request.url?.startsWith("/api/health?") === true) {
|
|
17687
|
-
const target =
|
|
18019
|
+
const target = path25__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
17688
18020
|
if (!lexicallyInside(target)) {
|
|
17689
18021
|
send(403, { error: "outside the served directory: " + target });
|
|
17690
18022
|
return;
|
|
17691
18023
|
}
|
|
17692
|
-
if (!
|
|
17693
|
-
send(404, { error: "no
|
|
18024
|
+
if (!fs24__namespace.existsSync(target)) {
|
|
18025
|
+
send(404, { error: "no snapshot directory at " + target });
|
|
17694
18026
|
return;
|
|
17695
18027
|
}
|
|
17696
18028
|
if (!insideAllowedRoots(target)) {
|
|
17697
18029
|
send(403, { error: "outside the served directory: " + target });
|
|
17698
18030
|
return;
|
|
17699
18031
|
}
|
|
17700
|
-
const
|
|
18032
|
+
const repoDir = path25__namespace.dirname(target);
|
|
18033
|
+
if (!insideAllowedRoots(repoDir)) {
|
|
18034
|
+
send(403, { error: "the repository root for this snapshot is outside the served directory" });
|
|
18035
|
+
return;
|
|
18036
|
+
}
|
|
18037
|
+
if (!fs24__namespace.existsSync(path25__namespace.join(target, "manifest.json"))) {
|
|
18038
|
+
send(404, { error: "no manifest.json under " + target });
|
|
18039
|
+
return;
|
|
18040
|
+
}
|
|
18041
|
+
const report2 = auditSnapshot({ snapshotDir: target, repoDir });
|
|
17701
18042
|
send(200, { score: report2.score, counts: report2.counts, checks: report2.checks });
|
|
17702
18043
|
return;
|
|
17703
18044
|
}
|
|
17704
18045
|
if (request.method === "GET" && (request.url?.startsWith("/api/snapshot?") === true || request.url === "/api/snapshot")) {
|
|
17705
|
-
const target =
|
|
18046
|
+
const target = path25__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
17706
18047
|
if (!lexicallyInside(target)) {
|
|
17707
18048
|
send(403, { error: "outside the served directory: " + target });
|
|
17708
18049
|
return;
|
|
17709
18050
|
}
|
|
17710
|
-
if (!
|
|
18051
|
+
if (!fs24__namespace.existsSync(target)) {
|
|
17711
18052
|
send(404, { error: "no manifest.json under " + target });
|
|
17712
18053
|
return;
|
|
17713
18054
|
}
|
|
@@ -17750,12 +18091,12 @@ async function startWebServer(options) {
|
|
|
17750
18091
|
return;
|
|
17751
18092
|
}
|
|
17752
18093
|
if (request.method === "GET" && request.url?.startsWith("/api/snapshot.zip") === true) {
|
|
17753
|
-
const target =
|
|
18094
|
+
const target = path25__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
17754
18095
|
if (!lexicallyInside(target)) {
|
|
17755
18096
|
send(403, { error: "outside the served directory: " + target });
|
|
17756
18097
|
return;
|
|
17757
18098
|
}
|
|
17758
|
-
if (!
|
|
18099
|
+
if (!fs24__namespace.existsSync(target)) {
|
|
17759
18100
|
send(404, { error: "not a snapshot directory: " + target });
|
|
17760
18101
|
return;
|
|
17761
18102
|
}
|
|
@@ -17763,6 +18104,10 @@ async function startWebServer(options) {
|
|
|
17763
18104
|
send(403, { error: "outside the served directory: " + target });
|
|
17764
18105
|
return;
|
|
17765
18106
|
}
|
|
18107
|
+
if (!fs24__namespace.existsSync(path25__namespace.join(target, "manifest.json")) && !fs24__namespace.existsSync(path25__namespace.join(target, ".codebase-snapshot"))) {
|
|
18108
|
+
send(404, { error: "not a snapshot directory: " + target });
|
|
18109
|
+
return;
|
|
18110
|
+
}
|
|
17766
18111
|
try {
|
|
17767
18112
|
const zip = writeZip({ directory: target });
|
|
17768
18113
|
response.writeHead(200, {
|
|
@@ -17798,7 +18143,7 @@ async function startWebServer(options) {
|
|
|
17798
18143
|
close: () => new Promise((resolve15) => {
|
|
17799
18144
|
for (const directory of temporaryClones) {
|
|
17800
18145
|
try {
|
|
17801
|
-
|
|
18146
|
+
fs24__namespace.rmSync(directory, { recursive: true, force: true });
|
|
17802
18147
|
} catch {
|
|
17803
18148
|
}
|
|
17804
18149
|
}
|
|
@@ -17854,17 +18199,17 @@ function isNewer(candidate, current) {
|
|
|
17854
18199
|
}
|
|
17855
18200
|
function cacheDirectory(env = process.env, platform = process.platform) {
|
|
17856
18201
|
if (platform === "win32") {
|
|
17857
|
-
const base2 = env.LOCALAPPDATA ??
|
|
17858
|
-
return
|
|
18202
|
+
const base2 = env.LOCALAPPDATA ?? path25__namespace.join(os2__namespace.homedir(), "AppData", "Local");
|
|
18203
|
+
return path25__namespace.join(base2, "codebase-snapshot");
|
|
17859
18204
|
}
|
|
17860
18205
|
if (platform === "darwin") {
|
|
17861
|
-
return
|
|
18206
|
+
return path25__namespace.join(os2__namespace.homedir(), "Library", "Caches", "codebase-snapshot");
|
|
17862
18207
|
}
|
|
17863
|
-
const base = env.XDG_CACHE_HOME ??
|
|
17864
|
-
return
|
|
18208
|
+
const base = env.XDG_CACHE_HOME ?? path25__namespace.join(os2__namespace.homedir(), ".cache");
|
|
18209
|
+
return path25__namespace.join(base, "codebase-snapshot");
|
|
17865
18210
|
}
|
|
17866
18211
|
function cacheFilePath(env = process.env) {
|
|
17867
|
-
return
|
|
18212
|
+
return path25__namespace.join(cacheDirectory(env), "update-check.json");
|
|
17868
18213
|
}
|
|
17869
18214
|
function shouldCheck(argv, env) {
|
|
17870
18215
|
const disabled = ["1", "true", "yes"].includes(
|
|
@@ -17894,7 +18239,7 @@ function shouldCheck(argv, env) {
|
|
|
17894
18239
|
function readCache(file) {
|
|
17895
18240
|
let raw;
|
|
17896
18241
|
try {
|
|
17897
|
-
raw =
|
|
18242
|
+
raw = fs24__namespace.readFileSync(file, "utf8");
|
|
17898
18243
|
} catch {
|
|
17899
18244
|
return null;
|
|
17900
18245
|
}
|
|
@@ -17911,8 +18256,8 @@ function readCache(file) {
|
|
|
17911
18256
|
}
|
|
17912
18257
|
function writeCache(file, entry) {
|
|
17913
18258
|
try {
|
|
17914
|
-
|
|
17915
|
-
|
|
18259
|
+
fs24__namespace.mkdirSync(path25__namespace.dirname(file), { recursive: true });
|
|
18260
|
+
fs24__namespace.writeFileSync(file, `${JSON.stringify(entry)}
|
|
17916
18261
|
`, "utf8");
|
|
17917
18262
|
} catch {
|
|
17918
18263
|
}
|
|
@@ -18220,14 +18565,14 @@ function compareManifests(before, after, secretRules) {
|
|
|
18220
18565
|
function loadManifest(target) {
|
|
18221
18566
|
let isDirectory;
|
|
18222
18567
|
try {
|
|
18223
|
-
isDirectory =
|
|
18568
|
+
isDirectory = fs24__namespace.statSync(target).isDirectory();
|
|
18224
18569
|
} catch {
|
|
18225
18570
|
throw new Error(`No snapshot found at ${target}: the path does not exist.`);
|
|
18226
18571
|
}
|
|
18227
|
-
const manifestPath = isDirectory ?
|
|
18572
|
+
const manifestPath = isDirectory ? path25__namespace.join(target, "manifest.json") : target;
|
|
18228
18573
|
let raw;
|
|
18229
18574
|
try {
|
|
18230
|
-
raw =
|
|
18575
|
+
raw = fs24__namespace.readFileSync(manifestPath, "utf8");
|
|
18231
18576
|
} catch {
|
|
18232
18577
|
throw new Error(`Could not read a manifest at ${manifestPath}.`);
|
|
18233
18578
|
}
|
|
@@ -18329,15 +18674,31 @@ function canonicalIgnorePattern(line) {
|
|
|
18329
18674
|
function appendGitignoreEntries(cwd, entries) {
|
|
18330
18675
|
const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
|
|
18331
18676
|
if (wanted.length === 0) return { added: [], note: null };
|
|
18332
|
-
const ignorePath =
|
|
18677
|
+
const ignorePath = path25__namespace.join(cwd, ".gitignore");
|
|
18333
18678
|
const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
|
|
18334
18679
|
let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
|
|
18335
18680
|
try {
|
|
18336
|
-
if (
|
|
18337
|
-
|
|
18681
|
+
if (fs24__namespace.existsSync(ignorePath)) {
|
|
18682
|
+
const stats = fs24__namespace.lstatSync(ignorePath);
|
|
18683
|
+
if (stats.isDirectory()) {
|
|
18338
18684
|
return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
|
|
18339
18685
|
}
|
|
18340
|
-
|
|
18686
|
+
if (stats.isSymbolicLink() || !stats.isFile() || stats.nlink > 1) {
|
|
18687
|
+
return {
|
|
18688
|
+
added: [],
|
|
18689
|
+
note: `${ignorePath} is a symbolic link, a hard link, or not a regular file, so it was not updated. ` + manual
|
|
18690
|
+
};
|
|
18691
|
+
}
|
|
18692
|
+
const rootReal = fs24__namespace.realpathSync(cwd);
|
|
18693
|
+
const fileReal = fs24__namespace.realpathSync(ignorePath);
|
|
18694
|
+
const relative15 = path25__namespace.relative(rootReal, fileReal);
|
|
18695
|
+
if (relative15 === ".." || relative15.startsWith(`..${path25__namespace.sep}`) || path25__namespace.isAbsolute(relative15)) {
|
|
18696
|
+
return {
|
|
18697
|
+
added: [],
|
|
18698
|
+
note: `${ignorePath} resolves outside the repository, so it was not updated. ${manual}`
|
|
18699
|
+
};
|
|
18700
|
+
}
|
|
18701
|
+
const read = decodeGitignore(fs24__namespace.readFileSync(ignorePath));
|
|
18341
18702
|
if (read === null) {
|
|
18342
18703
|
return {
|
|
18343
18704
|
added: [],
|
|
@@ -18358,18 +18719,25 @@ function appendGitignoreEntries(cwd, entries) {
|
|
|
18358
18719
|
if (added.length === 0) return { added: [], note: null };
|
|
18359
18720
|
const newline = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
18360
18721
|
const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
|
|
18722
|
+
const tempPath = `${ignorePath}.${process.pid}.${Date.now()}.tmp`;
|
|
18361
18723
|
try {
|
|
18362
|
-
|
|
18363
|
-
|
|
18364
|
-
encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
|
|
18724
|
+
fs24__namespace.writeFileSync(
|
|
18725
|
+
tempPath,
|
|
18726
|
+
encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`),
|
|
18727
|
+
{ flag: "wx" }
|
|
18365
18728
|
);
|
|
18729
|
+
fs24__namespace.renameSync(tempPath, ignorePath);
|
|
18366
18730
|
} catch (err) {
|
|
18731
|
+
try {
|
|
18732
|
+
fs24__namespace.rmSync(tempPath, { force: true });
|
|
18733
|
+
} catch {
|
|
18734
|
+
}
|
|
18367
18735
|
return { added: [], note: `${err.message}. ${manual}` };
|
|
18368
18736
|
}
|
|
18369
18737
|
return { added, note: null };
|
|
18370
18738
|
}
|
|
18371
18739
|
function gitignorePath(cwd, filePath) {
|
|
18372
|
-
return
|
|
18740
|
+
return path25__namespace.relative(cwd, filePath).split(path25__namespace.sep).join("/");
|
|
18373
18741
|
}
|
|
18374
18742
|
|
|
18375
18743
|
// src/wizard/brief-template.ts
|
|
@@ -18985,7 +19353,7 @@ function parsePackageJson(raw) {
|
|
|
18985
19353
|
}
|
|
18986
19354
|
function readPackageJson(cwd) {
|
|
18987
19355
|
try {
|
|
18988
|
-
return parsePackageJson(
|
|
19356
|
+
return parsePackageJson(fs24__namespace.readFileSync(path25__namespace.join(cwd, "package.json"), "utf8"));
|
|
18989
19357
|
} catch {
|
|
18990
19358
|
return null;
|
|
18991
19359
|
}
|
|
@@ -19022,7 +19390,7 @@ function artifactAnswers(options) {
|
|
|
19022
19390
|
}
|
|
19023
19391
|
function topLevelDirs(cwd) {
|
|
19024
19392
|
try {
|
|
19025
|
-
return
|
|
19393
|
+
return fs24__namespace.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
|
|
19026
19394
|
} catch {
|
|
19027
19395
|
return [];
|
|
19028
19396
|
}
|
|
@@ -19037,7 +19405,7 @@ function writeFileOrExplain(target, content) {
|
|
|
19037
19405
|
try {
|
|
19038
19406
|
let stats = null;
|
|
19039
19407
|
try {
|
|
19040
|
-
stats =
|
|
19408
|
+
stats = fs24__namespace.lstatSync(target);
|
|
19041
19409
|
} catch {
|
|
19042
19410
|
stats = null;
|
|
19043
19411
|
}
|
|
@@ -19052,12 +19420,12 @@ function writeFileOrExplain(target, content) {
|
|
|
19052
19420
|
);
|
|
19053
19421
|
}
|
|
19054
19422
|
const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
19055
|
-
|
|
19423
|
+
fs24__namespace.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
|
|
19056
19424
|
try {
|
|
19057
|
-
|
|
19425
|
+
fs24__namespace.renameSync(temporary, target);
|
|
19058
19426
|
} catch (err) {
|
|
19059
19427
|
try {
|
|
19060
|
-
|
|
19428
|
+
fs24__namespace.unlinkSync(temporary);
|
|
19061
19429
|
} catch {
|
|
19062
19430
|
}
|
|
19063
19431
|
throw err;
|
|
@@ -19105,19 +19473,19 @@ function serializePackageJson(raw, value) {
|
|
|
19105
19473
|
return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
|
|
19106
19474
|
}
|
|
19107
19475
|
function updatePackageJson(cwd, notes) {
|
|
19108
|
-
const packagePath =
|
|
19476
|
+
const packagePath = path25__namespace.join(cwd, "package.json");
|
|
19109
19477
|
const unchanged = {
|
|
19110
19478
|
scripts: [],
|
|
19111
19479
|
dependency: { name: GENERATOR_NAME, range: null, added: false }
|
|
19112
19480
|
};
|
|
19113
|
-
if (!
|
|
19481
|
+
if (!fs24__namespace.existsSync(packagePath)) {
|
|
19114
19482
|
notes.push("No package.json found, so npm scripts and the devDependency were not added.");
|
|
19115
19483
|
return unchanged;
|
|
19116
19484
|
}
|
|
19117
19485
|
let raw;
|
|
19118
19486
|
let parsed;
|
|
19119
19487
|
try {
|
|
19120
|
-
raw =
|
|
19488
|
+
raw = fs24__namespace.readFileSync(packagePath, "utf8");
|
|
19121
19489
|
parsed = parsePackageJson(raw);
|
|
19122
19490
|
} catch {
|
|
19123
19491
|
notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
|
|
@@ -19192,8 +19560,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
|
19192
19560
|
const entries = [];
|
|
19193
19561
|
for (const directory of [outDir, tmpDir]) {
|
|
19194
19562
|
if (directory === null) continue;
|
|
19195
|
-
const relative15 =
|
|
19196
|
-
if (relative15 === "" || relative15 === "." || relative15.startsWith("..") ||
|
|
19563
|
+
const relative15 = path25__namespace.relative(cwd, path25__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
19564
|
+
if (relative15 === "" || relative15 === "." || relative15.startsWith("..") || path25__namespace.isAbsolute(relative15)) {
|
|
19197
19565
|
continue;
|
|
19198
19566
|
}
|
|
19199
19567
|
entries.push(`/${relative15}/`);
|
|
@@ -19352,7 +19720,14 @@ async function runInit(options) {
|
|
|
19352
19720
|
try {
|
|
19353
19721
|
const raw = await text(io, "Part size (e.g. 150k, 1.5mb, 900000)", {
|
|
19354
19722
|
defaultValue: currentBudget,
|
|
19355
|
-
validate: (value) =>
|
|
19723
|
+
validate: (value) => {
|
|
19724
|
+
const parsed = parseByteSize(value);
|
|
19725
|
+
if (parsed === void 0) return "Not a valid size.";
|
|
19726
|
+
if (parsed < MIN_MAX_PART_BYTES) {
|
|
19727
|
+
return `A part budget below ${MIN_MAX_PART_BYTES} bytes cannot hold the truncation notice.`;
|
|
19728
|
+
}
|
|
19729
|
+
return null;
|
|
19730
|
+
},
|
|
19356
19731
|
allowBack: true
|
|
19357
19732
|
});
|
|
19358
19733
|
answers.maxPartBytes = parseByteSize(raw) ?? answers.maxPartBytes;
|
|
@@ -19448,7 +19823,7 @@ async function runInit(options) {
|
|
|
19448
19823
|
const configText = renderConfig(answers);
|
|
19449
19824
|
const preferredName = chooseConfigFileName(options.cwd);
|
|
19450
19825
|
const presentConfigs = CONFIG_CANDIDATES.filter(
|
|
19451
|
-
(name) =>
|
|
19826
|
+
(name) => fs24__namespace.existsSync(path25__namespace.join(options.cwd, name))
|
|
19452
19827
|
);
|
|
19453
19828
|
const present = presentConfigs[0] ?? null;
|
|
19454
19829
|
if (presentConfigs.length > 1) {
|
|
@@ -19457,7 +19832,7 @@ async function runInit(options) {
|
|
|
19457
19832
|
);
|
|
19458
19833
|
}
|
|
19459
19834
|
const configName = present !== null && options.force ? present : preferredName;
|
|
19460
|
-
const configPath =
|
|
19835
|
+
const configPath = path25__namespace.join(options.cwd, configName);
|
|
19461
19836
|
const reused = present !== null && options.force !== true && options.reuseConfig === true;
|
|
19462
19837
|
if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
|
|
19463
19838
|
if (options.dryRun) {
|
|
@@ -19474,7 +19849,7 @@ async function runInit(options) {
|
|
|
19474
19849
|
dependency: { name: GENERATOR_NAME, range: `^${GENERATOR_VERSION}`, added: false },
|
|
19475
19850
|
notes,
|
|
19476
19851
|
outDir: answers.outDir,
|
|
19477
|
-
briefPath:
|
|
19852
|
+
briefPath: path25__namespace.join(options.cwd, BRIEF_SCAFFOLD_FILE),
|
|
19478
19853
|
briefWritten: false
|
|
19479
19854
|
};
|
|
19480
19855
|
}
|
|
@@ -19493,13 +19868,13 @@ async function runInit(options) {
|
|
|
19493
19868
|
'package.json already defines a "snapshot" config. Remove that key, or re-run with --force to write a config file that takes precedence over it.'
|
|
19494
19869
|
);
|
|
19495
19870
|
}
|
|
19496
|
-
if (
|
|
19871
|
+
if (fs24__namespace.existsSync(configPath) && !options.force && !reused) {
|
|
19497
19872
|
throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
|
|
19498
19873
|
}
|
|
19499
19874
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
19500
|
-
const briefPath =
|
|
19875
|
+
const briefPath = path25__namespace.join(options.cwd, BRIEF_SCAFFOLD_FILE);
|
|
19501
19876
|
let briefWritten = false;
|
|
19502
|
-
if (!
|
|
19877
|
+
if (!fs24__namespace.existsSync(briefPath)) {
|
|
19503
19878
|
writeFileOrExplain(briefPath, BRIEF_SCAFFOLD);
|
|
19504
19879
|
briefWritten = true;
|
|
19505
19880
|
}
|
|
@@ -19527,9 +19902,9 @@ async function runInit(options) {
|
|
|
19527
19902
|
};
|
|
19528
19903
|
}
|
|
19529
19904
|
function describeTarget(cwd) {
|
|
19530
|
-
const relative15 =
|
|
19905
|
+
const relative15 = path25__namespace.relative(process.cwd(), cwd);
|
|
19531
19906
|
if (relative15 === "") return "this directory";
|
|
19532
|
-
if (relative15.startsWith("..") ||
|
|
19907
|
+
if (relative15.startsWith("..") || path25__namespace.isAbsolute(relative15)) return cwd;
|
|
19533
19908
|
return relative15;
|
|
19534
19909
|
}
|
|
19535
19910
|
function firstRunMessage(reason, cwd) {
|
|
@@ -19553,7 +19928,7 @@ function planFirstRun(facts) {
|
|
|
19553
19928
|
var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
|
|
19554
19929
|
function isEffectivelyEmpty(cwd) {
|
|
19555
19930
|
try {
|
|
19556
|
-
return
|
|
19931
|
+
return fs24__namespace.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
|
|
19557
19932
|
} catch {
|
|
19558
19933
|
return false;
|
|
19559
19934
|
}
|
|
@@ -19561,7 +19936,7 @@ function isEffectivelyEmpty(cwd) {
|
|
|
19561
19936
|
function hasPriorSnapshot(cwd, outDir) {
|
|
19562
19937
|
let parsed;
|
|
19563
19938
|
try {
|
|
19564
|
-
parsed = JSON.parse(
|
|
19939
|
+
parsed = JSON.parse(fs24__namespace.readFileSync(path25__namespace.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
|
|
19565
19940
|
} catch {
|
|
19566
19941
|
return false;
|
|
19567
19942
|
}
|
|
@@ -19600,7 +19975,7 @@ if [ ! -f "$SNAPSHOT_DIR/manifest.json" ]; then
|
|
|
19600
19975
|
exit 1
|
|
19601
19976
|
fi
|
|
19602
19977
|
|
|
19603
|
-
if ! npx --no-install ${GENERATOR_NAME} validate >/dev/null 2>&1; then
|
|
19978
|
+
if ! npx --no-install ${GENERATOR_NAME} validate --out-dir "$SNAPSHOT_DIR" >/dev/null 2>&1; then
|
|
19604
19979
|
echo "${GENERATOR_NAME}: the snapshot is out of date." >&2
|
|
19605
19980
|
echo " Run \\"npx ${GENERATOR_NAME} generate\\", stage the change, and commit again." >&2
|
|
19606
19981
|
echo " (npx --no-install is used on purpose: this hook must not install anything)" >&2
|
|
@@ -19609,52 +19984,56 @@ fi
|
|
|
19609
19984
|
`;
|
|
19610
19985
|
}
|
|
19611
19986
|
function gitDirectory(cwd) {
|
|
19612
|
-
const dotGit =
|
|
19987
|
+
const dotGit = path25__namespace.join(cwd, ".git");
|
|
19613
19988
|
let stats;
|
|
19614
19989
|
try {
|
|
19615
|
-
stats =
|
|
19990
|
+
stats = fs24__namespace.statSync(dotGit);
|
|
19616
19991
|
} catch {
|
|
19617
19992
|
return null;
|
|
19618
19993
|
}
|
|
19619
19994
|
if (stats.isDirectory()) return dotGit;
|
|
19620
19995
|
if (!stats.isFile()) return null;
|
|
19621
19996
|
try {
|
|
19622
|
-
const contents =
|
|
19997
|
+
const contents = fs24__namespace.readFileSync(dotGit, "utf8");
|
|
19623
19998
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
19624
19999
|
if (!match) return null;
|
|
19625
20000
|
const target = match[1];
|
|
19626
|
-
const resolved =
|
|
19627
|
-
|
|
19628
|
-
|
|
19629
|
-
|
|
20001
|
+
const resolved = path25__namespace.isAbsolute(target.trim()) ? target.trim() : path25__namespace.join(cwd, target.trim());
|
|
20002
|
+
const cwdReal = canonicalForWrite(cwd);
|
|
20003
|
+
const resolvedReal = canonicalForWrite(resolved);
|
|
20004
|
+
if (cwdReal === null || resolvedReal === null || !fs24__namespace.statSync(resolvedReal).isDirectory()) {
|
|
20005
|
+
return null;
|
|
20006
|
+
}
|
|
20007
|
+
if (isInside4(cwdReal, resolvedReal)) return resolvedReal;
|
|
20008
|
+
return isRegisteredWorktree(path25__namespace.resolve(resolved), cwd) ? resolvedReal : null;
|
|
19630
20009
|
} catch {
|
|
19631
20010
|
return null;
|
|
19632
20011
|
}
|
|
19633
20012
|
}
|
|
19634
20013
|
function isInside4(parent, child) {
|
|
19635
|
-
const relative15 =
|
|
19636
|
-
return relative15 === "" || !relative15.startsWith("..") && !
|
|
20014
|
+
const relative15 = path25__namespace.relative(parent, child);
|
|
20015
|
+
return relative15 === "" || !relative15.startsWith("..") && !path25__namespace.isAbsolute(relative15);
|
|
19637
20016
|
}
|
|
19638
20017
|
function canonicalForWrite(target) {
|
|
19639
|
-
let existing =
|
|
20018
|
+
let existing = path25__namespace.resolve(target);
|
|
19640
20019
|
const tail = [];
|
|
19641
|
-
while (!
|
|
19642
|
-
tail.unshift(
|
|
19643
|
-
const parent =
|
|
20020
|
+
while (!fs24__namespace.existsSync(existing)) {
|
|
20021
|
+
tail.unshift(path25__namespace.basename(existing));
|
|
20022
|
+
const parent = path25__namespace.dirname(existing);
|
|
19644
20023
|
if (parent === existing) break;
|
|
19645
20024
|
existing = parent;
|
|
19646
20025
|
}
|
|
19647
20026
|
try {
|
|
19648
|
-
const real =
|
|
19649
|
-
return tail.length === 0 ? real :
|
|
20027
|
+
const real = fs24__namespace.realpathSync(existing);
|
|
20028
|
+
return tail.length === 0 ? real : path25__namespace.join(real, ...tail);
|
|
19650
20029
|
} catch {
|
|
19651
20030
|
return null;
|
|
19652
20031
|
}
|
|
19653
20032
|
}
|
|
19654
20033
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
19655
20034
|
try {
|
|
19656
|
-
const back =
|
|
19657
|
-
return
|
|
20035
|
+
const back = fs24__namespace.readFileSync(path25__namespace.join(gitDir, "gitdir"), "utf8").trim();
|
|
20036
|
+
return path25__namespace.resolve(gitDir, back) === path25__namespace.join(path25__namespace.resolve(cwd), ".git");
|
|
19658
20037
|
} catch {
|
|
19659
20038
|
return false;
|
|
19660
20039
|
}
|
|
@@ -19675,9 +20054,9 @@ function gitOutput(cwd, args) {
|
|
|
19675
20054
|
function configuredHooksDirectory(cwd) {
|
|
19676
20055
|
const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
|
|
19677
20056
|
if (hooks === null) return null;
|
|
19678
|
-
const resolved =
|
|
20057
|
+
const resolved = path25__namespace.resolve(cwd, hooks);
|
|
19679
20058
|
const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
|
|
19680
|
-
const commonDir = common === null ? null : canonicalForWrite(
|
|
20059
|
+
const commonDir = common === null ? null : canonicalForWrite(path25__namespace.resolve(cwd, common));
|
|
19681
20060
|
const cwdReal = canonicalForWrite(cwd);
|
|
19682
20061
|
const hooksReal = canonicalForWrite(resolved);
|
|
19683
20062
|
if (hooksReal === null || cwdReal === null) {
|
|
@@ -19706,10 +20085,18 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
19706
20085
|
]
|
|
19707
20086
|
};
|
|
19708
20087
|
}
|
|
19709
|
-
const
|
|
19710
|
-
const
|
|
20088
|
+
const hooksDirRaw = configured === null ? path25__namespace.join(gitDir, "hooks") : configured.dir;
|
|
20089
|
+
const hooksDir = canonicalForWrite(hooksDirRaw);
|
|
20090
|
+
if (hooksDir === null) {
|
|
20091
|
+
return {
|
|
20092
|
+
path: null,
|
|
20093
|
+
written: false,
|
|
20094
|
+
notes: [`Refusing to write the hooks directory: ${hooksDirRaw} could not be resolved.`]
|
|
20095
|
+
};
|
|
20096
|
+
}
|
|
20097
|
+
const hookPath = path25__namespace.join(hooksDir, "pre-commit");
|
|
19711
20098
|
try {
|
|
19712
|
-
const existingStats =
|
|
20099
|
+
const existingStats = fs24__namespace.lstatSync(hookPath);
|
|
19713
20100
|
if (existingStats.isSymbolicLink()) {
|
|
19714
20101
|
return {
|
|
19715
20102
|
path: hookPath,
|
|
@@ -19741,7 +20128,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
19741
20128
|
}
|
|
19742
20129
|
}
|
|
19743
20130
|
try {
|
|
19744
|
-
|
|
20131
|
+
fs24__namespace.mkdirSync(hooksDir, { recursive: true });
|
|
19745
20132
|
} catch (err) {
|
|
19746
20133
|
return {
|
|
19747
20134
|
path: hookPath,
|
|
@@ -19751,7 +20138,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
19751
20138
|
}
|
|
19752
20139
|
let existing = null;
|
|
19753
20140
|
try {
|
|
19754
|
-
existing =
|
|
20141
|
+
existing = fs24__namespace.readFileSync(hookPath, "utf8");
|
|
19755
20142
|
} catch {
|
|
19756
20143
|
existing = null;
|
|
19757
20144
|
}
|
|
@@ -19766,8 +20153,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
19766
20153
|
};
|
|
19767
20154
|
}
|
|
19768
20155
|
try {
|
|
19769
|
-
|
|
19770
|
-
|
|
20156
|
+
fs24__namespace.writeFileSync(hookPath, hookScript(outDir), "utf8");
|
|
20157
|
+
fs24__namespace.chmodSync(hookPath, 493);
|
|
19771
20158
|
} catch (err) {
|
|
19772
20159
|
return {
|
|
19773
20160
|
path: hookPath,
|
|
@@ -19789,23 +20176,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
|
19789
20176
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
19790
20177
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
19791
20178
|
var fileDerivationBytes = 0;
|
|
19792
|
-
function takeDerivation(
|
|
19793
|
-
const
|
|
20179
|
+
function takeDerivation(path26, relativePath, hash, settings) {
|
|
20180
|
+
const key = path26 + "\0" + relativePath;
|
|
20181
|
+
const cached = FILE_DERIVATIONS.get(key);
|
|
19794
20182
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
19795
|
-
FILE_DERIVATIONS.delete(
|
|
19796
|
-
FILE_DERIVATIONS.set(
|
|
20183
|
+
FILE_DERIVATIONS.delete(key);
|
|
20184
|
+
FILE_DERIVATIONS.set(key, cached);
|
|
19797
20185
|
return cached;
|
|
19798
20186
|
}
|
|
19799
|
-
function rememberDerivation(
|
|
20187
|
+
function rememberDerivation(path26, relativePath, hash, settings, derivation) {
|
|
20188
|
+
const key = path26 + "\0" + relativePath;
|
|
19800
20189
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
19801
20190
|
const bytes = bodyBytes * 2 + 512;
|
|
19802
20191
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
19803
|
-
const previous = FILE_DERIVATIONS.get(
|
|
20192
|
+
const previous = FILE_DERIVATIONS.get(key);
|
|
19804
20193
|
if (previous !== void 0) {
|
|
19805
|
-
FILE_DERIVATIONS.delete(
|
|
20194
|
+
FILE_DERIVATIONS.delete(key);
|
|
19806
20195
|
fileDerivationBytes -= previous.bytes;
|
|
19807
|
-
} else {
|
|
19808
|
-
FILE_DERIVATIONS.delete(path27);
|
|
19809
20196
|
}
|
|
19810
20197
|
while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
|
|
19811
20198
|
const oldest = FILE_DERIVATIONS.keys().next();
|
|
@@ -19814,7 +20201,7 @@ function rememberDerivation(path27, hash, settings, derivation) {
|
|
|
19814
20201
|
FILE_DERIVATIONS.delete(oldest.value);
|
|
19815
20202
|
if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
|
|
19816
20203
|
}
|
|
19817
|
-
FILE_DERIVATIONS.set(
|
|
20204
|
+
FILE_DERIVATIONS.set(key, { ...derivation, hash, settings, bytes });
|
|
19818
20205
|
fileDerivationBytes += bytes;
|
|
19819
20206
|
}
|
|
19820
20207
|
function derivationSettings(config) {
|
|
@@ -20070,6 +20457,11 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
20070
20457
|
}
|
|
20071
20458
|
}
|
|
20072
20459
|
for (const part of parts) {
|
|
20460
|
+
if (part.metadata.hardClipped === true) {
|
|
20461
|
+
errors.push(
|
|
20462
|
+
`${part.filename} was hard-clipped by the part budget; its manifest entries cannot describe the surviving sections. Increase the budget or split the file instead of shipping a lie.`
|
|
20463
|
+
);
|
|
20464
|
+
}
|
|
20073
20465
|
if (sha256Hex2(part.markdown) !== part.metadata.sha256) {
|
|
20074
20466
|
errors.push(`${part.filename} content does not match its recorded sha256.`);
|
|
20075
20467
|
}
|
|
@@ -20094,11 +20486,16 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
20094
20486
|
return errors;
|
|
20095
20487
|
}
|
|
20096
20488
|
function resolveSafeOutputDirs(config) {
|
|
20097
|
-
const cwd =
|
|
20098
|
-
const outDir =
|
|
20099
|
-
const tmpDir =
|
|
20100
|
-
const root =
|
|
20101
|
-
const
|
|
20489
|
+
const cwd = path25__namespace.resolve(config.cwd);
|
|
20490
|
+
const outDir = path25__namespace.resolve(cwd, config.outDir);
|
|
20491
|
+
const tmpDir = path25__namespace.resolve(cwd, config.tmpDir);
|
|
20492
|
+
const root = path25__namespace.parse(cwd).root;
|
|
20493
|
+
const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
20494
|
+
const contains = (parent, child) => {
|
|
20495
|
+
const foldedParent = fold(parent);
|
|
20496
|
+
const foldedChild = fold(child);
|
|
20497
|
+
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path25__namespace.sep}`);
|
|
20498
|
+
};
|
|
20102
20499
|
const reject = (reason) => {
|
|
20103
20500
|
throw new Error(
|
|
20104
20501
|
`Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
|
|
@@ -20187,14 +20584,14 @@ function listEntries(dir) {
|
|
|
20187
20584
|
const walk2 = (absolute, prefix) => {
|
|
20188
20585
|
let children;
|
|
20189
20586
|
try {
|
|
20190
|
-
children =
|
|
20587
|
+
children = fs24__namespace.readdirSync(absolute, { withFileTypes: true });
|
|
20191
20588
|
} catch {
|
|
20192
20589
|
return;
|
|
20193
20590
|
}
|
|
20194
20591
|
for (const child of children) {
|
|
20195
20592
|
const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
20196
20593
|
entries.push(relative15);
|
|
20197
|
-
if (child.isDirectory()) walk2(
|
|
20594
|
+
if (child.isDirectory()) walk2(path25__namespace.join(absolute, child.name), relative15);
|
|
20198
20595
|
}
|
|
20199
20596
|
};
|
|
20200
20597
|
walk2(dir, "");
|
|
@@ -20206,10 +20603,10 @@ function markerInventory(dir, written) {
|
|
|
20206
20603
|
for (const entry of entries) {
|
|
20207
20604
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
20208
20605
|
if (isIgnorableEntry(entry)) continue;
|
|
20209
|
-
const full =
|
|
20606
|
+
const full = path25__namespace.join(dir, ...entry.split("/"));
|
|
20210
20607
|
let stats;
|
|
20211
20608
|
try {
|
|
20212
|
-
stats =
|
|
20609
|
+
stats = fs24__namespace.lstatSync(full);
|
|
20213
20610
|
} catch {
|
|
20214
20611
|
continue;
|
|
20215
20612
|
}
|
|
@@ -20221,7 +20618,7 @@ function markerInventory(dir, written) {
|
|
|
20221
20618
|
}
|
|
20222
20619
|
let digest;
|
|
20223
20620
|
try {
|
|
20224
|
-
digest = sha256Hex2(
|
|
20621
|
+
digest = sha256Hex2(fs24__namespace.readFileSync(full));
|
|
20225
20622
|
} catch {
|
|
20226
20623
|
continue;
|
|
20227
20624
|
}
|
|
@@ -20243,15 +20640,15 @@ function markerPayload(dir, state, id, createdAt, written, runId) {
|
|
|
20243
20640
|
entries,
|
|
20244
20641
|
files
|
|
20245
20642
|
};
|
|
20246
|
-
const manifestPath =
|
|
20247
|
-
if (
|
|
20248
|
-
marker2.manifestSha256 = sha256Hex2(
|
|
20643
|
+
const manifestPath = path25__namespace.join(dir, "manifest.json");
|
|
20644
|
+
if (fs24__namespace.existsSync(manifestPath)) {
|
|
20645
|
+
marker2.manifestSha256 = sha256Hex2(fs24__namespace.readFileSync(manifestPath));
|
|
20249
20646
|
}
|
|
20250
20647
|
return marker2;
|
|
20251
20648
|
}
|
|
20252
20649
|
function writeOwnershipMarker(dir, marker2) {
|
|
20253
|
-
|
|
20254
|
-
|
|
20650
|
+
fs24__namespace.writeFileSync(
|
|
20651
|
+
path25__namespace.join(dir, OWNERSHIP_MARKER),
|
|
20255
20652
|
`${JSON.stringify(marker2, null, 2)}
|
|
20256
20653
|
`,
|
|
20257
20654
|
"utf8"
|
|
@@ -20263,13 +20660,13 @@ function markerBelongsTo(dir, id) {
|
|
|
20263
20660
|
return evidence.marker.id === id;
|
|
20264
20661
|
}
|
|
20265
20662
|
function readOwnershipMarker(dir) {
|
|
20266
|
-
const markerPath =
|
|
20267
|
-
if (!
|
|
20663
|
+
const markerPath = path25__namespace.join(dir, OWNERSHIP_MARKER);
|
|
20664
|
+
if (!fs24__namespace.existsSync(markerPath)) {
|
|
20268
20665
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
20269
20666
|
}
|
|
20270
20667
|
let raw;
|
|
20271
20668
|
try {
|
|
20272
|
-
raw =
|
|
20669
|
+
raw = fs24__namespace.readFileSync(markerPath, "utf8");
|
|
20273
20670
|
} catch {
|
|
20274
20671
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
20275
20672
|
}
|
|
@@ -20370,10 +20767,10 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
20370
20767
|
for (const entry of entries) {
|
|
20371
20768
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
20372
20769
|
if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
|
|
20373
|
-
const full =
|
|
20770
|
+
const full = path25__namespace.join(dir, ...entry.split("/"));
|
|
20374
20771
|
let stats;
|
|
20375
20772
|
try {
|
|
20376
|
-
stats =
|
|
20773
|
+
stats = fs24__namespace.lstatSync(full);
|
|
20377
20774
|
} catch {
|
|
20378
20775
|
return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
|
|
20379
20776
|
}
|
|
@@ -20398,7 +20795,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
20398
20795
|
}
|
|
20399
20796
|
let digest;
|
|
20400
20797
|
try {
|
|
20401
|
-
digest = sha256Hex2(
|
|
20798
|
+
digest = sha256Hex2(fs24__namespace.readFileSync(full));
|
|
20402
20799
|
} catch {
|
|
20403
20800
|
return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
|
|
20404
20801
|
}
|
|
@@ -20419,12 +20816,12 @@ function assessSnapshotDirectory(dir) {
|
|
|
20419
20816
|
marker: marker2
|
|
20420
20817
|
};
|
|
20421
20818
|
}
|
|
20422
|
-
const manifestPath =
|
|
20423
|
-
const hasManifest =
|
|
20819
|
+
const manifestPath = path25__namespace.join(dir, "manifest.json");
|
|
20820
|
+
const hasManifest = fs24__namespace.existsSync(manifestPath);
|
|
20424
20821
|
if (hasManifest) {
|
|
20425
20822
|
let raw;
|
|
20426
20823
|
try {
|
|
20427
|
-
raw =
|
|
20824
|
+
raw = fs24__namespace.readFileSync(manifestPath, "utf8");
|
|
20428
20825
|
} catch {
|
|
20429
20826
|
return {
|
|
20430
20827
|
owned: false,
|
|
@@ -20525,13 +20922,13 @@ function containsNoFiles(dir) {
|
|
|
20525
20922
|
const current = pending.pop();
|
|
20526
20923
|
let entries;
|
|
20527
20924
|
try {
|
|
20528
|
-
entries =
|
|
20925
|
+
entries = fs24__namespace.readdirSync(current, { withFileTypes: true });
|
|
20529
20926
|
} catch {
|
|
20530
20927
|
return false;
|
|
20531
20928
|
}
|
|
20532
20929
|
for (const entry of entries) {
|
|
20533
20930
|
if (entry.isDirectory()) {
|
|
20534
|
-
pending.push(
|
|
20931
|
+
pending.push(path25__namespace.join(current, entry.name));
|
|
20535
20932
|
} else if (!IGNORABLE_ENTRIES.has(entry.name)) {
|
|
20536
20933
|
return false;
|
|
20537
20934
|
}
|
|
@@ -20540,13 +20937,13 @@ function containsNoFiles(dir) {
|
|
|
20540
20937
|
return true;
|
|
20541
20938
|
}
|
|
20542
20939
|
function assertReplaceable(target, label, secretRules) {
|
|
20543
|
-
if (!
|
|
20544
|
-
if (!
|
|
20940
|
+
if (!fs24__namespace.existsSync(target)) return;
|
|
20941
|
+
if (!fs24__namespace.statSync(target).isDirectory()) {
|
|
20545
20942
|
throw new Error(
|
|
20546
20943
|
`Refusing to write into ${label} ${target}: it exists but is not a directory.`
|
|
20547
20944
|
);
|
|
20548
20945
|
}
|
|
20549
|
-
const entries =
|
|
20946
|
+
const entries = fs24__namespace.readdirSync(target);
|
|
20550
20947
|
if (entries.length === 0) return;
|
|
20551
20948
|
if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
|
|
20552
20949
|
if (containsNoFiles(target)) return;
|
|
@@ -20566,18 +20963,18 @@ function assertReplaceable(target, label, secretRules) {
|
|
|
20566
20963
|
);
|
|
20567
20964
|
}
|
|
20568
20965
|
function assertStagingRootUsable(tmpDir, secretRules) {
|
|
20569
|
-
if (!
|
|
20570
|
-
if (!
|
|
20966
|
+
if (!fs24__namespace.existsSync(tmpDir)) return;
|
|
20967
|
+
if (!fs24__namespace.statSync(tmpDir).isDirectory()) {
|
|
20571
20968
|
throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
|
|
20572
20969
|
}
|
|
20573
|
-
const entries =
|
|
20970
|
+
const entries = fs24__namespace.readdirSync(tmpDir);
|
|
20574
20971
|
if (entries.length === 0) return;
|
|
20575
20972
|
const foreign = entries.filter((name) => {
|
|
20576
|
-
const full =
|
|
20973
|
+
const full = path25__namespace.join(tmpDir, name);
|
|
20577
20974
|
if (!name.startsWith(RUN_DIR_PREFIX)) return true;
|
|
20578
20975
|
let stats;
|
|
20579
20976
|
try {
|
|
20580
|
-
stats =
|
|
20977
|
+
stats = fs24__namespace.statSync(full);
|
|
20581
20978
|
} catch {
|
|
20582
20979
|
return true;
|
|
20583
20980
|
}
|
|
@@ -20585,7 +20982,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
20585
20982
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
20586
20983
|
if (marker2) return false;
|
|
20587
20984
|
try {
|
|
20588
|
-
return
|
|
20985
|
+
return fs24__namespace.readdirSync(full).length > 0;
|
|
20589
20986
|
} catch {
|
|
20590
20987
|
return true;
|
|
20591
20988
|
}
|
|
@@ -20600,13 +20997,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
20600
20997
|
function cleanStaleRunDirs(tmpDir) {
|
|
20601
20998
|
let entries;
|
|
20602
20999
|
try {
|
|
20603
|
-
entries =
|
|
21000
|
+
entries = fs24__namespace.readdirSync(tmpDir);
|
|
20604
21001
|
} catch {
|
|
20605
21002
|
return;
|
|
20606
21003
|
}
|
|
20607
21004
|
for (const name of entries) {
|
|
20608
21005
|
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
20609
|
-
const full =
|
|
21006
|
+
const full = path25__namespace.join(tmpDir, name);
|
|
20610
21007
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
20611
21008
|
if (marker2) {
|
|
20612
21009
|
const created = Date.parse(marker2.createdAt);
|
|
@@ -20614,33 +21011,33 @@ function cleanStaleRunDirs(tmpDir) {
|
|
|
20614
21011
|
const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
|
|
20615
21012
|
if (aged || abandoned) {
|
|
20616
21013
|
try {
|
|
20617
|
-
|
|
21014
|
+
fs24__namespace.rmSync(full, { recursive: true, force: true });
|
|
20618
21015
|
} catch {
|
|
20619
21016
|
}
|
|
20620
21017
|
}
|
|
20621
21018
|
continue;
|
|
20622
21019
|
}
|
|
20623
21020
|
try {
|
|
20624
|
-
if (
|
|
21021
|
+
if (fs24__namespace.readdirSync(full).length === 0) fs24__namespace.rmSync(full, { recursive: true, force: true });
|
|
20625
21022
|
} catch {
|
|
20626
21023
|
}
|
|
20627
21024
|
}
|
|
20628
21025
|
}
|
|
20629
21026
|
function removeIfEmpty(dir) {
|
|
20630
21027
|
try {
|
|
20631
|
-
if (
|
|
21028
|
+
if (fs24__namespace.readdirSync(dir).length === 0) fs24__namespace.rmSync(dir, { recursive: true, force: true });
|
|
20632
21029
|
} catch {
|
|
20633
21030
|
}
|
|
20634
21031
|
}
|
|
20635
21032
|
function ensureParentDirectory(target, label) {
|
|
20636
|
-
const parent =
|
|
20637
|
-
if (
|
|
21033
|
+
const parent = path25__namespace.dirname(target);
|
|
21034
|
+
if (fs24__namespace.existsSync(parent) && !fs24__namespace.statSync(parent).isDirectory()) {
|
|
20638
21035
|
throw new Error(
|
|
20639
21036
|
`Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
|
|
20640
21037
|
);
|
|
20641
21038
|
}
|
|
20642
21039
|
try {
|
|
20643
|
-
|
|
21040
|
+
fs24__namespace.mkdirSync(parent, { recursive: true });
|
|
20644
21041
|
} catch (err) {
|
|
20645
21042
|
throw new Error(
|
|
20646
21043
|
`Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
|
|
@@ -20699,17 +21096,17 @@ function acquireRunLock(stagingRoot, runId) {
|
|
|
20699
21096
|
`;
|
|
20700
21097
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
20701
21098
|
try {
|
|
20702
|
-
const handle =
|
|
21099
|
+
const handle = fs24__namespace.openSync(lockPath, "wx");
|
|
20703
21100
|
try {
|
|
20704
|
-
|
|
21101
|
+
fs24__namespace.writeSync(handle, payload);
|
|
20705
21102
|
} finally {
|
|
20706
|
-
|
|
21103
|
+
fs24__namespace.closeSync(handle);
|
|
20707
21104
|
}
|
|
20708
21105
|
const stopHeartbeat = startLockHeartbeat(lockPath);
|
|
20709
21106
|
return () => {
|
|
20710
21107
|
stopHeartbeat();
|
|
20711
21108
|
try {
|
|
20712
|
-
|
|
21109
|
+
fs24__namespace.rmSync(lockPath, { force: true });
|
|
20713
21110
|
} catch {
|
|
20714
21111
|
}
|
|
20715
21112
|
};
|
|
@@ -20729,45 +21126,45 @@ function lockKeyFor(stagingRoot) {
|
|
|
20729
21126
|
return sha256Hex2(key).slice(0, 16);
|
|
20730
21127
|
}
|
|
20731
21128
|
function canonicalLockTarget(targetPath) {
|
|
20732
|
-
const resolved =
|
|
21129
|
+
const resolved = path25__namespace.resolve(targetPath);
|
|
20733
21130
|
let existing = resolved;
|
|
20734
21131
|
const tail = [];
|
|
20735
21132
|
for (; ; ) {
|
|
20736
21133
|
try {
|
|
20737
|
-
return
|
|
21134
|
+
return path25__namespace.join(fs24__namespace.realpathSync(existing), ...tail);
|
|
20738
21135
|
} catch {
|
|
20739
|
-
const parent =
|
|
21136
|
+
const parent = path25__namespace.dirname(existing);
|
|
20740
21137
|
if (parent === existing) return resolved;
|
|
20741
|
-
tail.unshift(
|
|
21138
|
+
tail.unshift(path25__namespace.basename(existing));
|
|
20742
21139
|
existing = parent;
|
|
20743
21140
|
}
|
|
20744
21141
|
}
|
|
20745
21142
|
}
|
|
20746
21143
|
function lockPathFor(stagingRoot) {
|
|
20747
|
-
return
|
|
21144
|
+
return path25__namespace.join(os2__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
20748
21145
|
}
|
|
20749
21146
|
function releaseAbandonedRun(stagingRoots, runId) {
|
|
20750
21147
|
if (runId.length === 0) return;
|
|
20751
21148
|
for (const root of new Set(stagingRoots)) {
|
|
20752
21149
|
const lockPath = lockPathFor(root);
|
|
20753
21150
|
try {
|
|
20754
|
-
const payload = JSON.parse(
|
|
20755
|
-
if (payload.runId === runId)
|
|
21151
|
+
const payload = JSON.parse(fs24__namespace.readFileSync(lockPath, "utf8"));
|
|
21152
|
+
if (payload.runId === runId) fs24__namespace.rmSync(lockPath, { force: true });
|
|
20756
21153
|
} catch {
|
|
20757
21154
|
}
|
|
20758
21155
|
let entries;
|
|
20759
21156
|
try {
|
|
20760
|
-
entries =
|
|
21157
|
+
entries = fs24__namespace.readdirSync(root);
|
|
20761
21158
|
} catch {
|
|
20762
21159
|
continue;
|
|
20763
21160
|
}
|
|
20764
21161
|
for (const name of entries) {
|
|
20765
21162
|
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
20766
|
-
const directory =
|
|
21163
|
+
const directory = path25__namespace.join(root, name);
|
|
20767
21164
|
const { marker: marker2 } = readOwnershipMarker(directory);
|
|
20768
21165
|
if (marker2?.runId !== runId) continue;
|
|
20769
21166
|
try {
|
|
20770
|
-
|
|
21167
|
+
fs24__namespace.rmSync(directory, { recursive: true, force: true });
|
|
20771
21168
|
} catch {
|
|
20772
21169
|
}
|
|
20773
21170
|
}
|
|
@@ -20775,7 +21172,7 @@ function releaseAbandonedRun(stagingRoots, runId) {
|
|
|
20775
21172
|
}
|
|
20776
21173
|
function lockHeartbeatAgeMs(lockPath) {
|
|
20777
21174
|
try {
|
|
20778
|
-
return Date.now() -
|
|
21175
|
+
return Date.now() - fs24__namespace.statSync(lockPath).mtimeMs;
|
|
20779
21176
|
} catch {
|
|
20780
21177
|
return Number.POSITIVE_INFINITY;
|
|
20781
21178
|
}
|
|
@@ -20783,7 +21180,7 @@ function lockHeartbeatAgeMs(lockPath) {
|
|
|
20783
21180
|
function lockOwnerIsGone(lockPath) {
|
|
20784
21181
|
let raw;
|
|
20785
21182
|
try {
|
|
20786
|
-
raw =
|
|
21183
|
+
raw = fs24__namespace.readFileSync(lockPath, "utf8");
|
|
20787
21184
|
} catch {
|
|
20788
21185
|
return false;
|
|
20789
21186
|
}
|
|
@@ -20807,16 +21204,16 @@ function lockOwnerIsGone(lockPath) {
|
|
|
20807
21204
|
function reclaimStaleLock(lockPath) {
|
|
20808
21205
|
let before;
|
|
20809
21206
|
try {
|
|
20810
|
-
before =
|
|
21207
|
+
before = fs24__namespace.statSync(lockPath);
|
|
20811
21208
|
} catch {
|
|
20812
21209
|
return true;
|
|
20813
21210
|
}
|
|
20814
21211
|
if (!lockOwnerIsGone(lockPath)) return false;
|
|
20815
21212
|
try {
|
|
20816
|
-
const current =
|
|
21213
|
+
const current = fs24__namespace.statSync(lockPath);
|
|
20817
21214
|
const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
|
|
20818
21215
|
if (!sameFile) return false;
|
|
20819
|
-
|
|
21216
|
+
fs24__namespace.rmSync(lockPath, { force: true });
|
|
20820
21217
|
return true;
|
|
20821
21218
|
} catch {
|
|
20822
21219
|
return false;
|
|
@@ -20827,12 +21224,12 @@ function lockFileIsAncient(lockPath, thresholdMs = LOCK_STALE_HEARTBEAT_MS) {
|
|
|
20827
21224
|
}
|
|
20828
21225
|
function writeManifestAtomically(manifestPath, manifest) {
|
|
20829
21226
|
const tempPath = `${manifestPath}.${process.pid}.tmp`;
|
|
20830
|
-
|
|
21227
|
+
fs24__namespace.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
|
|
20831
21228
|
try {
|
|
20832
|
-
|
|
21229
|
+
fs24__namespace.renameSync(tempPath, manifestPath);
|
|
20833
21230
|
} catch (err) {
|
|
20834
21231
|
try {
|
|
20835
|
-
|
|
21232
|
+
fs24__namespace.rmSync(tempPath, { force: true });
|
|
20836
21233
|
} catch {
|
|
20837
21234
|
}
|
|
20838
21235
|
throw err;
|
|
@@ -20857,21 +21254,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap, onStagingPreserved) {
|
|
|
20857
21254
|
}
|
|
20858
21255
|
}
|
|
20859
21256
|
function recoverInterruptedPublish(outDir) {
|
|
20860
|
-
if (
|
|
20861
|
-
const parent =
|
|
20862
|
-
const base =
|
|
21257
|
+
if (fs24__namespace.existsSync(outDir)) return;
|
|
21258
|
+
const parent = path25__namespace.dirname(outDir);
|
|
21259
|
+
const base = path25__namespace.basename(outDir);
|
|
20863
21260
|
let backups;
|
|
20864
21261
|
try {
|
|
20865
|
-
backups =
|
|
21262
|
+
backups = fs24__namespace.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
|
|
20866
21263
|
} catch {
|
|
20867
21264
|
return;
|
|
20868
21265
|
}
|
|
20869
21266
|
if (backups.length !== 1) return;
|
|
20870
|
-
const backupDir =
|
|
21267
|
+
const backupDir = path25__namespace.join(parent, backups[0]);
|
|
20871
21268
|
const { marker: marker2, problem } = readOwnershipMarker(backupDir);
|
|
20872
21269
|
if (problem !== null || marker2 === null || marker2.state !== "complete") return;
|
|
20873
21270
|
try {
|
|
20874
|
-
|
|
21271
|
+
fs24__namespace.renameSync(backupDir, outDir);
|
|
20875
21272
|
process.stderr.write(
|
|
20876
21273
|
`\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
|
|
20877
21274
|
`
|
|
@@ -20881,17 +21278,17 @@ function recoverInterruptedPublish(outDir) {
|
|
|
20881
21278
|
}
|
|
20882
21279
|
function swapOnce(stagingDir, outDir, beforeSwap, onStagingPreserved) {
|
|
20883
21280
|
const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
|
|
20884
|
-
const hadPrevious =
|
|
21281
|
+
const hadPrevious = fs24__namespace.existsSync(outDir);
|
|
20885
21282
|
if (hadPrevious) beforeSwap?.();
|
|
20886
21283
|
let movedAside = false;
|
|
20887
21284
|
if (hadPrevious) {
|
|
20888
21285
|
try {
|
|
20889
|
-
|
|
21286
|
+
fs24__namespace.renameSync(outDir, backupDir);
|
|
20890
21287
|
movedAside = true;
|
|
20891
21288
|
} catch (err) {
|
|
20892
21289
|
if (!isLockError(err)) throw err;
|
|
20893
21290
|
onStagingPreserved?.();
|
|
20894
|
-
|
|
21291
|
+
fs24__namespace.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
20895
21292
|
process.stderr.write(
|
|
20896
21293
|
`\u26A0 ${outDir} could not be moved aside (${err.message}), so it was replaced in place. Close anything holding the old snapshot open to avoid this next time.
|
|
20897
21294
|
`
|
|
@@ -20900,26 +21297,26 @@ function swapOnce(stagingDir, outDir, beforeSwap, onStagingPreserved) {
|
|
|
20900
21297
|
}
|
|
20901
21298
|
try {
|
|
20902
21299
|
try {
|
|
20903
|
-
|
|
21300
|
+
fs24__namespace.renameSync(stagingDir, outDir);
|
|
20904
21301
|
} catch (err) {
|
|
20905
21302
|
if (err.code !== "EXDEV") throw err;
|
|
20906
21303
|
const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
|
|
20907
21304
|
try {
|
|
20908
|
-
|
|
20909
|
-
|
|
20910
|
-
|
|
21305
|
+
fs24__namespace.cpSync(stagingDir, partialDir, { recursive: true });
|
|
21306
|
+
fs24__namespace.renameSync(partialDir, outDir);
|
|
21307
|
+
fs24__namespace.rmSync(stagingDir, { recursive: true, force: true });
|
|
20911
21308
|
} catch (copyErr) {
|
|
20912
21309
|
try {
|
|
20913
|
-
|
|
21310
|
+
fs24__namespace.rmSync(partialDir, { recursive: true, force: true });
|
|
20914
21311
|
} catch {
|
|
20915
21312
|
}
|
|
20916
21313
|
throw copyErr;
|
|
20917
21314
|
}
|
|
20918
21315
|
}
|
|
20919
21316
|
} catch (err) {
|
|
20920
|
-
if (hadPrevious && movedAside &&
|
|
20921
|
-
if (
|
|
20922
|
-
|
|
21317
|
+
if (hadPrevious && movedAside && fs24__namespace.existsSync(backupDir)) {
|
|
21318
|
+
if (fs24__namespace.existsSync(outDir)) fs24__namespace.rmSync(outDir, { recursive: true, force: true });
|
|
21319
|
+
fs24__namespace.renameSync(backupDir, outDir);
|
|
20923
21320
|
} else if (hadPrevious && !movedAside) {
|
|
20924
21321
|
onStagingPreserved?.();
|
|
20925
21322
|
process.stderr.write(
|
|
@@ -20931,7 +21328,7 @@ function swapOnce(stagingDir, outDir, beforeSwap, onStagingPreserved) {
|
|
|
20931
21328
|
}
|
|
20932
21329
|
if (hadPrevious) {
|
|
20933
21330
|
try {
|
|
20934
|
-
|
|
21331
|
+
fs24__namespace.rmSync(backupDir, { recursive: true, force: true });
|
|
20935
21332
|
} catch (err) {
|
|
20936
21333
|
process.stderr.write(
|
|
20937
21334
|
`\u26A0 The previous snapshot could not be removed from ${backupDir} (${err.message}). The new snapshot is in place; delete that directory by hand when convenient.
|
|
@@ -21110,7 +21507,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21110
21507
|
// first run cannot have marked them yet, so the name alone keeps a run from recording its own
|
|
21111
21508
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
21112
21509
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
21113
|
-
(directory) =>
|
|
21510
|
+
(directory) => path25__namespace.relative(config.cwd, path25__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
21114
21511
|
).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
|
|
21115
21512
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
21116
21513
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
@@ -21139,7 +21536,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21139
21536
|
let totalSizeBytes = 0;
|
|
21140
21537
|
let largeFileCount = 0;
|
|
21141
21538
|
for (const relativePath of candidateFiles) {
|
|
21142
|
-
const absolutePath =
|
|
21539
|
+
const absolutePath = path25__namespace.join(config.cwd, relativePath);
|
|
21143
21540
|
const fromIndex = stagedPaths.has(relativePath);
|
|
21144
21541
|
let buffer;
|
|
21145
21542
|
let sizeBytes;
|
|
@@ -21170,9 +21567,9 @@ function generateSnapshot(configInput, options) {
|
|
|
21170
21567
|
} else {
|
|
21171
21568
|
let stats;
|
|
21172
21569
|
try {
|
|
21173
|
-
stats =
|
|
21570
|
+
stats = fs24__namespace.statSync(absolutePath);
|
|
21174
21571
|
if (!stats.isFile()) {
|
|
21175
|
-
const nestedRepository = stats.isDirectory() &&
|
|
21572
|
+
const nestedRepository = stats.isDirectory() && fs24__namespace.existsSync(path25__namespace.join(absolutePath, ".git"));
|
|
21176
21573
|
skipped.push(
|
|
21177
21574
|
nestedRepository ? {
|
|
21178
21575
|
path: relativePath,
|
|
@@ -21208,7 +21605,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21208
21605
|
continue;
|
|
21209
21606
|
}
|
|
21210
21607
|
try {
|
|
21211
|
-
buffer =
|
|
21608
|
+
buffer = fs24__namespace.readFileSync(absolutePath);
|
|
21212
21609
|
} catch (err) {
|
|
21213
21610
|
const code = err.code;
|
|
21214
21611
|
skipped.push({
|
|
@@ -21257,9 +21654,9 @@ function generateSnapshot(configInput, options) {
|
|
|
21257
21654
|
const language = detectLanguage(relativePath);
|
|
21258
21655
|
bump(layerCounts, layer2);
|
|
21259
21656
|
bump(kindCounts, kind);
|
|
21260
|
-
const derivation = takeDerivation(absolutePath, hashSha256, derivationKey) ?? (() => {
|
|
21657
|
+
const derivation = takeDerivation(absolutePath, relativePath, hashSha256, derivationKey) ?? (() => {
|
|
21261
21658
|
const fresh = deriveFile(relativePath, rawContent, sizeBytes, config);
|
|
21262
|
-
rememberDerivation(absolutePath, hashSha256, derivationKey, fresh);
|
|
21659
|
+
rememberDerivation(absolutePath, relativePath, hashSha256, derivationKey, fresh);
|
|
21263
21660
|
return fresh;
|
|
21264
21661
|
})();
|
|
21265
21662
|
const { lineCount } = derivation;
|
|
@@ -21323,14 +21720,14 @@ function generateSnapshot(configInput, options) {
|
|
|
21323
21720
|
}
|
|
21324
21721
|
retain(secretFindings, (finding) => finding.path === void 0 || keep.has(finding.path));
|
|
21325
21722
|
retain(encodingNotes, (note) => keep.has(note.path));
|
|
21326
|
-
retain(oversizeSummaryPaths, (
|
|
21327
|
-
retain(previewSummaryPaths, (
|
|
21723
|
+
retain(oversizeSummaryPaths, (path26) => keep.has(path26));
|
|
21724
|
+
retain(previewSummaryPaths, (path26) => keep.has(path26));
|
|
21328
21725
|
retain(fileWarnings, (warning) => keep.has(warning.path));
|
|
21329
|
-
for (const
|
|
21330
|
-
if (!keep.has(
|
|
21726
|
+
for (const path26 of [...monolithBodies.keys()]) {
|
|
21727
|
+
if (!keep.has(path26)) monolithBodies.delete(path26);
|
|
21331
21728
|
}
|
|
21332
|
-
for (const
|
|
21333
|
-
if (!keep.has(
|
|
21729
|
+
for (const path26 of [...skippedSummaryImports.keys()]) {
|
|
21730
|
+
if (!keep.has(path26)) skippedSummaryImports.delete(path26);
|
|
21334
21731
|
}
|
|
21335
21732
|
};
|
|
21336
21733
|
if (changedScope !== null && changedPaths !== null && config.withDependents === true) {
|
|
@@ -21439,7 +21836,9 @@ function generateSnapshot(configInput, options) {
|
|
|
21439
21836
|
const tokens = Math.max(1, Math.ceil(file.includedBytes / 4));
|
|
21440
21837
|
const value = (entry(file.relativePath) ? 100 : 0) + layerWeight(file.layer) + Math.min(60, (importers.get(file.relativePath) ?? 0) * 6) - Math.min(40, tokens / 250);
|
|
21441
21838
|
return { file, tokens, value };
|
|
21442
|
-
}).sort(
|
|
21839
|
+
}).sort(
|
|
21840
|
+
(left, right) => right.value - left.value || left.tokens - right.tokens || (left.file.relativePath < right.file.relativePath ? -1 : left.file.relativePath > right.file.relativePath ? 1 : 0)
|
|
21841
|
+
);
|
|
21443
21842
|
const keep = /* @__PURE__ */ new Set();
|
|
21444
21843
|
let used = 0;
|
|
21445
21844
|
const selected = [];
|
|
@@ -21848,8 +22247,11 @@ function generateSnapshot(configInput, options) {
|
|
|
21848
22247
|
const entry = {
|
|
21849
22248
|
...file,
|
|
21850
22249
|
content,
|
|
21851
|
-
|
|
21852
|
-
|
|
22250
|
+
// `fullContents` is the pre-preview body but still carries comments and blank lines: the
|
|
22251
|
+
// monolith is the whole source, not the comments-stripped variant. Calling it
|
|
22252
|
+
// `comments-stripped` (or copying `emptyLinesRemoved`) described a transformation this
|
|
22253
|
+
// artifact did not perform.
|
|
22254
|
+
inclusionMode: "full",
|
|
21853
22255
|
isPreviewTruncated: false,
|
|
21854
22256
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
21855
22257
|
includedLines: countLines(content)
|
|
@@ -21932,12 +22334,12 @@ function generateSnapshot(configInput, options) {
|
|
|
21932
22334
|
let releaseDeferred = false;
|
|
21933
22335
|
try {
|
|
21934
22336
|
ensureParentDirectory(outDir, "outDir");
|
|
21935
|
-
|
|
22337
|
+
fs24__namespace.mkdirSync(tmpDir, { recursive: true });
|
|
21936
22338
|
cleanStaleRunDirs(tmpDir);
|
|
21937
22339
|
const snapshotId = crypto__namespace.randomUUID();
|
|
21938
22340
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
21939
|
-
stagingDir =
|
|
21940
|
-
|
|
22341
|
+
stagingDir = path25__namespace.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
|
|
22342
|
+
fs24__namespace.mkdirSync(stagingDir);
|
|
21941
22343
|
writeOwnershipMarker(stagingDir, {
|
|
21942
22344
|
generator: GENERATOR_NAME,
|
|
21943
22345
|
version: GENERATOR_VERSION,
|
|
@@ -21948,30 +22350,34 @@ function generateSnapshot(configInput, options) {
|
|
|
21948
22350
|
runId,
|
|
21949
22351
|
pid: process.pid
|
|
21950
22352
|
});
|
|
21951
|
-
const partsDir =
|
|
21952
|
-
const reportsDir =
|
|
21953
|
-
if (artifacts.parts)
|
|
22353
|
+
const partsDir = path25__namespace.join(stagingDir, "parts");
|
|
22354
|
+
const reportsDir = path25__namespace.join(stagingDir, "reports");
|
|
22355
|
+
if (artifacts.parts) fs24__namespace.mkdirSync(partsDir, { recursive: true });
|
|
21954
22356
|
if (artifacts.navigation || artifacts.projectTree || artifacts.audit || artifacts.diff || artifacts.log || artifacts.tokenTree || config.sarif === true) {
|
|
21955
|
-
|
|
22357
|
+
fs24__namespace.mkdirSync(reportsDir, { recursive: true });
|
|
21956
22358
|
}
|
|
21957
22359
|
const writtenArtifacts = /* @__PURE__ */ new Map();
|
|
22360
|
+
const ledgerRoot = (targetDir) => stagingDir !== null && (targetDir === stagingDir || targetDir.startsWith(stagingDir + path25__namespace.sep)) ? stagingDir : outDir;
|
|
22361
|
+
const ledgerEntry = (targetDir, relativeEntry) => path25__namespace.relative(ledgerRoot(targetDir), path25__namespace.join(targetDir, ...relativeEntry.split("/"))).split(path25__namespace.sep).join("/");
|
|
21958
22362
|
const writeArtifact = (targetDir, relativeEntry, data) => {
|
|
21959
|
-
const full =
|
|
21960
|
-
|
|
21961
|
-
const stats =
|
|
21962
|
-
|
|
21963
|
-
|
|
22363
|
+
const full = path25__namespace.join(targetDir, ...relativeEntry.split("/"));
|
|
22364
|
+
fs24__namespace.writeFileSync(full, data, "utf8");
|
|
22365
|
+
const stats = fs24__namespace.statSync(full);
|
|
22366
|
+
const entry = ledgerEntry(targetDir, relativeEntry);
|
|
22367
|
+
writtenArtifacts.set(entry, {
|
|
22368
|
+
digest: { path: entry, bytes: stats.size, sha256: sha256Hex2(data) },
|
|
21964
22369
|
mtimeMs: stats.mtimeMs
|
|
21965
22370
|
});
|
|
21966
22371
|
};
|
|
21967
22372
|
const recordArtifact = (targetDir, relativeEntry) => {
|
|
21968
|
-
const full =
|
|
21969
|
-
const stats =
|
|
21970
|
-
|
|
22373
|
+
const full = path25__namespace.join(targetDir, ...relativeEntry.split("/"));
|
|
22374
|
+
const stats = fs24__namespace.statSync(full);
|
|
22375
|
+
const entry = ledgerEntry(targetDir, relativeEntry);
|
|
22376
|
+
writtenArtifacts.set(entry, {
|
|
21971
22377
|
digest: {
|
|
21972
|
-
path:
|
|
22378
|
+
path: entry,
|
|
21973
22379
|
bytes: stats.size,
|
|
21974
|
-
sha256: sha256Hex2(
|
|
22380
|
+
sha256: sha256Hex2(fs24__namespace.readFileSync(full))
|
|
21975
22381
|
},
|
|
21976
22382
|
mtimeMs: stats.mtimeMs
|
|
21977
22383
|
});
|
|
@@ -22020,7 +22426,7 @@ function generateSnapshot(configInput, options) {
|
|
|
22020
22426
|
"Refusing to sign: manifest.json is disabled for this run. Signing covers the manifest, so enable the manifest artifact or drop --sign."
|
|
22021
22427
|
);
|
|
22022
22428
|
}
|
|
22023
|
-
const record = signManifest(
|
|
22429
|
+
const record = signManifest(path25__namespace.join(stagingDir, "manifest.json"), {
|
|
22024
22430
|
key: options.sign.key ?? null
|
|
22025
22431
|
});
|
|
22026
22432
|
writeArtifact(stagingDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
|
|
@@ -22052,10 +22458,10 @@ function generateSnapshot(configInput, options) {
|
|
|
22052
22458
|
const shipHookState = () => {
|
|
22053
22459
|
if (!markerBelongsTo(outDir, snapshotId)) return;
|
|
22054
22460
|
if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
|
|
22055
|
-
writeManifestAtomically(
|
|
22461
|
+
writeManifestAtomically(path25__namespace.join(outDir, "manifest.json"), manifest);
|
|
22056
22462
|
recordArtifact(outDir, "manifest.json");
|
|
22057
22463
|
if (options?.sign !== void 0) {
|
|
22058
|
-
const record = signManifest(
|
|
22464
|
+
const record = signManifest(path25__namespace.join(outDir, "manifest.json"), {
|
|
22059
22465
|
key: options.sign.key ?? null
|
|
22060
22466
|
});
|
|
22061
22467
|
writeArtifact(outDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
|
|
@@ -22101,7 +22507,7 @@ function generateSnapshot(configInput, options) {
|
|
|
22101
22507
|
} catch (err) {
|
|
22102
22508
|
if (stagingDir !== null && !stagingPreserved) {
|
|
22103
22509
|
try {
|
|
22104
|
-
|
|
22510
|
+
fs24__namespace.rmSync(stagingDir, { recursive: true, force: true });
|
|
22105
22511
|
} catch {
|
|
22106
22512
|
}
|
|
22107
22513
|
}
|