codebase-snapshot 0.10.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/README.md +10 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +1282 -296
- package/dist/{chunk-5EYBTBFY.js → chunk-5FPYVWP3.js} +50 -3
- package/dist/{chunk-5AV7OR3J.js → chunk-6HXDYIJS.js} +1204 -338
- package/dist/cli.cjs +1423 -443
- package/dist/cli.d.cts +36 -3
- package/dist/cli.d.ts +36 -3
- package/dist/cli.js +71 -5
- package/dist/index.cjs +1199 -333
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +206 -4
- package/dist/mcp.js +2 -2
- package/dist/{types-BoWneA7n.d.cts → types-c0tLF2WC.d.cts} +91 -1
- package/dist/{types-BoWneA7n.d.ts → types-c0tLF2WC.d.ts} +91 -1
- package/docs/cli.md +8 -3
- package/docs/configuration.md +108 -0
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +58 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var crypto2 = require('crypto');
|
|
4
4
|
var worker_threads = require('worker_threads');
|
|
5
5
|
var async_hooks = require('async_hooks');
|
|
6
|
-
var
|
|
6
|
+
var fs16 = require('fs');
|
|
7
7
|
var os = require('os');
|
|
8
|
-
var
|
|
8
|
+
var path17 = require('path');
|
|
9
9
|
var ts = require('typescript');
|
|
10
10
|
var module$1 = require('module');
|
|
11
11
|
var url = require('url');
|
|
@@ -35,9 +35,9 @@ function _interopNamespace(e) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
var crypto2__namespace = /*#__PURE__*/_interopNamespace(crypto2);
|
|
38
|
-
var
|
|
38
|
+
var fs16__namespace = /*#__PURE__*/_interopNamespace(fs16);
|
|
39
39
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
40
|
-
var
|
|
40
|
+
var path17__namespace = /*#__PURE__*/_interopNamespace(path17);
|
|
41
41
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
42
42
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
43
43
|
var http__namespace = /*#__PURE__*/_interopNamespace(http);
|
|
@@ -412,9 +412,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
412
412
|
var jvmProfile = {
|
|
413
413
|
id: "jvm",
|
|
414
414
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
415
|
-
summarize(
|
|
415
|
+
summarize(path18, content) {
|
|
416
416
|
const summary = emptySummary();
|
|
417
|
-
const lower =
|
|
417
|
+
const lower = path18.toLowerCase();
|
|
418
418
|
const isJava = lower.endsWith(".java");
|
|
419
419
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
420
420
|
eachLine(content, (line) => {
|
|
@@ -1022,17 +1022,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
1022
1022
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
1023
1023
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
1024
1024
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
1025
|
-
function componentName(
|
|
1026
|
-
const base =
|
|
1025
|
+
function componentName(path18) {
|
|
1026
|
+
const base = path18.split("/").pop() ?? path18;
|
|
1027
1027
|
return base.replace(/\.[^.]+$/, "");
|
|
1028
1028
|
}
|
|
1029
1029
|
var sfcProfile = {
|
|
1030
1030
|
id: "sfc",
|
|
1031
1031
|
extensions: [".vue", ".svelte", ".astro"],
|
|
1032
|
-
summarize(
|
|
1032
|
+
summarize(path18, content) {
|
|
1033
1033
|
let script = "";
|
|
1034
|
-
let usesJsx =
|
|
1035
|
-
if (
|
|
1034
|
+
let usesJsx = path18.toLowerCase().endsWith(".astro");
|
|
1035
|
+
if (path18.toLowerCase().endsWith(".astro")) {
|
|
1036
1036
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
1037
1037
|
if (frontmatter) script += `${frontmatter[1]}
|
|
1038
1038
|
`;
|
|
@@ -1042,7 +1042,7 @@ var sfcProfile = {
|
|
|
1042
1042
|
script += `${match[2]}
|
|
1043
1043
|
`;
|
|
1044
1044
|
}
|
|
1045
|
-
const name = componentName(
|
|
1045
|
+
const name = componentName(path18);
|
|
1046
1046
|
if (!script.trim()) {
|
|
1047
1047
|
const summary2 = emptySummary();
|
|
1048
1048
|
if (name) {
|
|
@@ -1233,15 +1233,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
1233
1233
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
1234
1234
|
}
|
|
1235
1235
|
}
|
|
1236
|
-
function profileForPath(
|
|
1237
|
-
const lower =
|
|
1236
|
+
function profileForPath(path18) {
|
|
1237
|
+
const lower = path18.toLowerCase();
|
|
1238
1238
|
const dot = lower.lastIndexOf(".");
|
|
1239
1239
|
if (dot === -1) return null;
|
|
1240
1240
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
1241
1241
|
}
|
|
1242
|
-
function summarizeWithProfile(
|
|
1243
|
-
const profile = profileForPath(
|
|
1244
|
-
return profile ? profile.summarize(
|
|
1242
|
+
function summarizeWithProfile(path18, content) {
|
|
1243
|
+
const profile = profileForPath(path18);
|
|
1244
|
+
return profile ? profile.summarize(path18, content) : null;
|
|
1245
1245
|
}
|
|
1246
1246
|
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1247
1247
|
".png",
|
|
@@ -1286,7 +1286,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1286
1286
|
".so"
|
|
1287
1287
|
]);
|
|
1288
1288
|
function isBinaryExtension(filePath) {
|
|
1289
|
-
const ext =
|
|
1289
|
+
const ext = path17__namespace.extname(filePath).toLowerCase();
|
|
1290
1290
|
return BINARY_EXTENSIONS.has(ext);
|
|
1291
1291
|
}
|
|
1292
1292
|
function isBinaryBuffer(buffer) {
|
|
@@ -1456,13 +1456,13 @@ function isBinaryFile(absolutePath) {
|
|
|
1456
1456
|
if (isBinaryExtension(absolutePath)) return true;
|
|
1457
1457
|
let fd;
|
|
1458
1458
|
try {
|
|
1459
|
-
fd =
|
|
1459
|
+
fd = fs16__namespace.openSync(absolutePath, "r");
|
|
1460
1460
|
const buffer = Buffer.alloc(CHUNK);
|
|
1461
1461
|
let sample;
|
|
1462
1462
|
let position = 0;
|
|
1463
1463
|
while (position < BINARY_SCAN_BYTES) {
|
|
1464
1464
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
1465
|
-
const bytesRead =
|
|
1465
|
+
const bytesRead = fs16__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
1466
1466
|
if (bytesRead === 0) return false;
|
|
1467
1467
|
const chunk = buffer.subarray(0, bytesRead);
|
|
1468
1468
|
if (sample === void 0) {
|
|
@@ -1480,7 +1480,7 @@ function isBinaryFile(absolutePath) {
|
|
|
1480
1480
|
} finally {
|
|
1481
1481
|
if (fd !== void 0) {
|
|
1482
1482
|
try {
|
|
1483
|
-
|
|
1483
|
+
fs16__namespace.closeSync(fd);
|
|
1484
1484
|
} catch {
|
|
1485
1485
|
}
|
|
1486
1486
|
}
|
|
@@ -1502,9 +1502,9 @@ function importsOfText(relativePath, text2) {
|
|
|
1502
1502
|
function importsOfFile(relativePath, absolutePath) {
|
|
1503
1503
|
let buffer;
|
|
1504
1504
|
try {
|
|
1505
|
-
const stats =
|
|
1505
|
+
const stats = fs16__namespace.statSync(absolutePath);
|
|
1506
1506
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
1507
|
-
buffer =
|
|
1507
|
+
buffer = fs16__namespace.readFileSync(absolutePath);
|
|
1508
1508
|
} catch {
|
|
1509
1509
|
return [];
|
|
1510
1510
|
}
|
|
@@ -1750,6 +1750,77 @@ function isSkeletonizable(filePath) {
|
|
|
1750
1750
|
}
|
|
1751
1751
|
return lower.endsWith(".ts") || lower.endsWith(".tsx") || lower.endsWith(".mts") || lower.endsWith(".cts") || lower.endsWith(".js") || lower.endsWith(".jsx") || lower.endsWith(".mjs") || lower.endsWith(".cjs");
|
|
1752
1752
|
}
|
|
1753
|
+
var OWNER_SECTIONS = ["Stakes", "The system", "What came before", "The bar", "Calibration"];
|
|
1754
|
+
var RESERVED_SECTIONS = [
|
|
1755
|
+
"The job",
|
|
1756
|
+
"What you have",
|
|
1757
|
+
"Coverage",
|
|
1758
|
+
"What a useful answer contains",
|
|
1759
|
+
"This snapshot",
|
|
1760
|
+
"Attaching this",
|
|
1761
|
+
"Your task"
|
|
1762
|
+
];
|
|
1763
|
+
function parseOwnerBrief(filePath, text2) {
|
|
1764
|
+
const problems = [];
|
|
1765
|
+
const source = text2.replace(/^\uFEFF/, "");
|
|
1766
|
+
const preamble = [];
|
|
1767
|
+
const sections = [];
|
|
1768
|
+
let current = null;
|
|
1769
|
+
for (const line of source.split(/\r?\n/)) {
|
|
1770
|
+
const heading = /^##\s+(.+?)\s*$/.exec(line);
|
|
1771
|
+
if (heading) {
|
|
1772
|
+
current = { heading: heading[1], body: [] };
|
|
1773
|
+
sections.push(current);
|
|
1774
|
+
continue;
|
|
1775
|
+
}
|
|
1776
|
+
if (current) current.body.push(line);
|
|
1777
|
+
else preamble.push(line);
|
|
1778
|
+
}
|
|
1779
|
+
const recognised = {};
|
|
1780
|
+
const notes = [];
|
|
1781
|
+
const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
|
|
1782
|
+
const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
|
|
1783
|
+
const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
|
|
1784
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1785
|
+
for (const section of sections) {
|
|
1786
|
+
const body = section.body.join("\n").trim();
|
|
1787
|
+
const key = canonical(section.heading);
|
|
1788
|
+
if (seen.has(key)) {
|
|
1789
|
+
problems.push(
|
|
1790
|
+
`the brief defines "${section.heading}" twice; a section cannot say two things.`
|
|
1791
|
+
);
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
seen.add(key);
|
|
1795
|
+
if (canonicalReserved.has(key)) {
|
|
1796
|
+
problems.push(
|
|
1797
|
+
`the brief may not define "${section.heading}": that section is rendered from the manifest, and letting prose overwrite a measured section would make the document lie.`
|
|
1798
|
+
);
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1801
|
+
const ownerName = canonicalOwner.get(key);
|
|
1802
|
+
if (ownerName !== void 0) {
|
|
1803
|
+
recognised[ownerName] = body;
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
notes.push({ heading: section.heading, body });
|
|
1807
|
+
}
|
|
1808
|
+
const preambleText = preamble.join("\n").trim();
|
|
1809
|
+
return {
|
|
1810
|
+
brief: {
|
|
1811
|
+
path: filePath,
|
|
1812
|
+
digest: crypto2.createHash("sha256").update(text2, "utf8").digest("hex"),
|
|
1813
|
+
...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
|
|
1814
|
+
...recognised["The system"] ? { system: recognised["The system"] } : {},
|
|
1815
|
+
...recognised["What came before"] ? { history: recognised["What came before"] } : {},
|
|
1816
|
+
...recognised["The bar"] ? { bar: recognised["The bar"] } : {},
|
|
1817
|
+
...recognised["Calibration"] ? { calibration: recognised["Calibration"] } : {},
|
|
1818
|
+
notes,
|
|
1819
|
+
...preambleText.length > 0 ? { preamble: preambleText } : {}
|
|
1820
|
+
},
|
|
1821
|
+
problems
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1753
1824
|
var MANIFEST_FILES = [
|
|
1754
1825
|
"package.json",
|
|
1755
1826
|
"pyproject.toml",
|
|
@@ -1796,15 +1867,15 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
1796
1867
|
]);
|
|
1797
1868
|
function readSmallFile(fullPath) {
|
|
1798
1869
|
try {
|
|
1799
|
-
const stats =
|
|
1870
|
+
const stats = fs16__namespace.statSync(fullPath);
|
|
1800
1871
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
1801
|
-
return
|
|
1872
|
+
return fs16__namespace.readFileSync(fullPath, "utf8");
|
|
1802
1873
|
} catch {
|
|
1803
1874
|
return null;
|
|
1804
1875
|
}
|
|
1805
1876
|
}
|
|
1806
1877
|
function readManifest(cwd, name) {
|
|
1807
|
-
return readSmallFile(
|
|
1878
|
+
return readSmallFile(path17__namespace.join(cwd, name));
|
|
1808
1879
|
}
|
|
1809
1880
|
function dependenciesFromPackageJson(raw) {
|
|
1810
1881
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -1864,7 +1935,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
1864
1935
|
function childDirectories(cwd, parent) {
|
|
1865
1936
|
let entries;
|
|
1866
1937
|
try {
|
|
1867
|
-
entries =
|
|
1938
|
+
entries = fs16__namespace.readdirSync(path17__namespace.join(cwd, parent), { withFileTypes: true });
|
|
1868
1939
|
} catch {
|
|
1869
1940
|
return [];
|
|
1870
1941
|
}
|
|
@@ -1900,12 +1971,12 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
1900
1971
|
const files = /* @__PURE__ */ new Set();
|
|
1901
1972
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1902
1973
|
for (const relative11 of workspacePackageDirs(cwd, patterns)) {
|
|
1903
|
-
const full =
|
|
1974
|
+
const full = path17__namespace.join(cwd, relative11);
|
|
1904
1975
|
try {
|
|
1905
|
-
for (const entry of
|
|
1976
|
+
for (const entry of fs16__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
1906
1977
|
} catch {
|
|
1907
1978
|
}
|
|
1908
|
-
const raw = readSmallFile(
|
|
1979
|
+
const raw = readSmallFile(path17__namespace.join(full, "package.json"));
|
|
1909
1980
|
if (raw !== null) {
|
|
1910
1981
|
for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
|
|
1911
1982
|
}
|
|
@@ -1915,7 +1986,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
1915
1986
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
1916
1987
|
function isToolOwnedDirectory(dir) {
|
|
1917
1988
|
try {
|
|
1918
|
-
return
|
|
1989
|
+
return fs16__namespace.statSync(dir).isDirectory() && fs16__namespace.existsSync(path17__namespace.join(dir, SNAPSHOT_MARKER));
|
|
1919
1990
|
} catch {
|
|
1920
1991
|
return false;
|
|
1921
1992
|
}
|
|
@@ -1930,7 +2001,7 @@ function countMarkdownFiles(cwd) {
|
|
|
1930
2001
|
directoriesSeen += 1;
|
|
1931
2002
|
let entries;
|
|
1932
2003
|
try {
|
|
1933
|
-
entries =
|
|
2004
|
+
entries = fs16__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
1934
2005
|
} catch {
|
|
1935
2006
|
continue;
|
|
1936
2007
|
}
|
|
@@ -1941,7 +2012,7 @@ function countMarkdownFiles(cwd) {
|
|
|
1941
2012
|
}
|
|
1942
2013
|
if (!entry.isDirectory() || current.depth >= 2) continue;
|
|
1943
2014
|
if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
|
|
1944
|
-
const child =
|
|
2015
|
+
const child = path17__namespace.join(current.dir, entry.name);
|
|
1945
2016
|
if (isToolOwnedDirectory(child)) continue;
|
|
1946
2017
|
queue.push({ dir: child, depth: current.depth + 1 });
|
|
1947
2018
|
}
|
|
@@ -1952,7 +2023,7 @@ function buildPresetContext(cwd) {
|
|
|
1952
2023
|
const files = /* @__PURE__ */ new Set();
|
|
1953
2024
|
const dirs = /* @__PURE__ */ new Set();
|
|
1954
2025
|
try {
|
|
1955
|
-
for (const entry of
|
|
2026
|
+
for (const entry of fs16__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
1956
2027
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
1957
2028
|
else if (entry.isFile()) files.add(entry.name);
|
|
1958
2029
|
}
|
|
@@ -1969,7 +2040,7 @@ function buildPresetContext(cwd) {
|
|
|
1969
2040
|
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;
|
|
1970
2041
|
let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
|
|
1971
2042
|
if (isWorkspace) {
|
|
1972
|
-
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(
|
|
2043
|
+
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path17__namespace.join(cwd, "pnpm-workspace.yaml")) : null;
|
|
1973
2044
|
const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
|
|
1974
2045
|
const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
|
|
1975
2046
|
workspace = scanWorkspacePackages(cwd, patterns);
|
|
@@ -3923,7 +3994,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
3923
3994
|
|
|
3924
3995
|
// src/version.ts
|
|
3925
3996
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3926
|
-
var GENERATOR_VERSION = "0.
|
|
3997
|
+
var GENERATOR_VERSION = "0.12.0";
|
|
3927
3998
|
var SCHEMA_VERSION = "3.0.0";
|
|
3928
3999
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
3929
4000
|
function isOurGeneratorName(name) {
|
|
@@ -3940,14 +4011,14 @@ var PRESET_IGNORES = new Set(
|
|
|
3940
4011
|
);
|
|
3941
4012
|
function readLinkTarget(linkPath, fallback) {
|
|
3942
4013
|
try {
|
|
3943
|
-
return
|
|
4014
|
+
return fs16__namespace.readlinkSync(linkPath);
|
|
3944
4015
|
} catch {
|
|
3945
4016
|
return fallback;
|
|
3946
4017
|
}
|
|
3947
4018
|
}
|
|
3948
4019
|
function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
3949
4020
|
const rawTarget = readLinkTarget(linkPath, linkPath);
|
|
3950
|
-
const resolvedFallback =
|
|
4021
|
+
const resolvedFallback = path17__namespace.resolve(path17__namespace.dirname(linkPath), rawTarget);
|
|
3951
4022
|
return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
|
|
3952
4023
|
path: relativePath,
|
|
3953
4024
|
reason: "outside-root",
|
|
@@ -3955,8 +4026,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
3955
4026
|
};
|
|
3956
4027
|
}
|
|
3957
4028
|
function isInside(root, candidate) {
|
|
3958
|
-
const relative11 =
|
|
3959
|
-
return relative11 === "" || !relative11.startsWith(`..${
|
|
4029
|
+
const relative11 = path17__namespace.relative(root, candidate);
|
|
4030
|
+
return relative11 === "" || !relative11.startsWith(`..${path17__namespace.sep}`) && relative11 !== ".." && !path17__namespace.isAbsolute(relative11);
|
|
3960
4031
|
}
|
|
3961
4032
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
3962
4033
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -4214,10 +4285,10 @@ function trimUnescapedTrailingSpaces(line) {
|
|
|
4214
4285
|
return line.slice(0, end);
|
|
4215
4286
|
}
|
|
4216
4287
|
function readGitignoreRules(dir) {
|
|
4217
|
-
const gitignorePath2 =
|
|
4288
|
+
const gitignorePath2 = path17__namespace.join(dir, ".gitignore");
|
|
4218
4289
|
let raw;
|
|
4219
4290
|
try {
|
|
4220
|
-
raw =
|
|
4291
|
+
raw = fs16__namespace.readFileSync(gitignorePath2, "utf8");
|
|
4221
4292
|
} catch {
|
|
4222
4293
|
return [];
|
|
4223
4294
|
}
|
|
@@ -4371,6 +4442,35 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
4371
4442
|
}
|
|
4372
4443
|
return null;
|
|
4373
4444
|
}
|
|
4445
|
+
var COMMIT_BODY_LIMIT = 400;
|
|
4446
|
+
function recentCommits(cwd, limit = 10) {
|
|
4447
|
+
try {
|
|
4448
|
+
const stdout = childProcess__namespace.execFileSync(
|
|
4449
|
+
"git",
|
|
4450
|
+
// \x1f between fields and \x1e between records: neither can appear in a commit message, so
|
|
4451
|
+
// the parse cannot be confused by a message that contains a newline or a dash.
|
|
4452
|
+
["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
|
|
4453
|
+
{
|
|
4454
|
+
cwd,
|
|
4455
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
4456
|
+
encoding: "utf8",
|
|
4457
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
4458
|
+
}
|
|
4459
|
+
);
|
|
4460
|
+
return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
|
|
4461
|
+
const separator = record.indexOf("");
|
|
4462
|
+
const subject = separator === -1 ? record : record.slice(0, separator);
|
|
4463
|
+
const rawBody = separator === -1 ? "" : record.slice(separator + 1);
|
|
4464
|
+
const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
|
|
4465
|
+
return {
|
|
4466
|
+
subject: subject.trim(),
|
|
4467
|
+
body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
|
|
4468
|
+
};
|
|
4469
|
+
}).filter((commit) => commit.subject.length > 0);
|
|
4470
|
+
} catch {
|
|
4471
|
+
return [];
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4374
4474
|
function listIgnoredPaths(cwd) {
|
|
4375
4475
|
try {
|
|
4376
4476
|
const stdout = childProcess__namespace.execFileSync(
|
|
@@ -4390,7 +4490,7 @@ function listIgnoredPaths(cwd) {
|
|
|
4390
4490
|
}
|
|
4391
4491
|
function hasSnapshotMarker(target) {
|
|
4392
4492
|
try {
|
|
4393
|
-
return
|
|
4493
|
+
return fs16__namespace.statSync(target).isDirectory() && fs16__namespace.existsSync(path17__namespace.join(target, ".codebase-snapshot"));
|
|
4394
4494
|
} catch {
|
|
4395
4495
|
return false;
|
|
4396
4496
|
}
|
|
@@ -4399,7 +4499,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
4399
4499
|
function isToolOwnedDirectory2(dir) {
|
|
4400
4500
|
let raw;
|
|
4401
4501
|
try {
|
|
4402
|
-
raw =
|
|
4502
|
+
raw = fs16__namespace.readFileSync(path17__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
4403
4503
|
} catch {
|
|
4404
4504
|
return false;
|
|
4405
4505
|
}
|
|
@@ -4426,7 +4526,7 @@ function isToolOwnedDirectory2(dir) {
|
|
|
4426
4526
|
}
|
|
4427
4527
|
let entries;
|
|
4428
4528
|
try {
|
|
4429
|
-
entries =
|
|
4529
|
+
entries = fs16__namespace.readdirSync(dir);
|
|
4430
4530
|
} catch {
|
|
4431
4531
|
return false;
|
|
4432
4532
|
}
|
|
@@ -4443,7 +4543,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
|
4443
4543
|
const prefix = parts.slice(0, depth).join("/");
|
|
4444
4544
|
let hasMarker = markers.get(prefix);
|
|
4445
4545
|
if (hasMarker === void 0) {
|
|
4446
|
-
hasMarker = isToolOwnedDirectory2(
|
|
4546
|
+
hasMarker = isToolOwnedDirectory2(path17__namespace.join(cwd, prefix));
|
|
4447
4547
|
markers.set(prefix, hasMarker);
|
|
4448
4548
|
}
|
|
4449
4549
|
if (hasMarker) return true;
|
|
@@ -4458,7 +4558,7 @@ function makeLinkProbe() {
|
|
|
4458
4558
|
let known = cache.get(absolutePath);
|
|
4459
4559
|
if (known === void 0) {
|
|
4460
4560
|
try {
|
|
4461
|
-
known =
|
|
4561
|
+
known = fs16__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
4462
4562
|
} catch {
|
|
4463
4563
|
known = false;
|
|
4464
4564
|
}
|
|
@@ -4471,7 +4571,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4471
4571
|
const isLink = makeLinkProbe();
|
|
4472
4572
|
let rootReal = cwd;
|
|
4473
4573
|
try {
|
|
4474
|
-
rootReal =
|
|
4574
|
+
rootReal = fs16__namespace.realpathSync(cwd);
|
|
4475
4575
|
} catch {
|
|
4476
4576
|
}
|
|
4477
4577
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -4486,7 +4586,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4486
4586
|
let linkedPath = null;
|
|
4487
4587
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
4488
4588
|
const prefix = parts.slice(0, depth).join("/");
|
|
4489
|
-
if (isLink(
|
|
4589
|
+
if (isLink(path17__namespace.join(cwd, prefix))) {
|
|
4490
4590
|
linkedPath = prefix;
|
|
4491
4591
|
break;
|
|
4492
4592
|
}
|
|
@@ -4495,11 +4595,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4495
4595
|
kept.push(candidate);
|
|
4496
4596
|
continue;
|
|
4497
4597
|
}
|
|
4498
|
-
const absolute =
|
|
4598
|
+
const absolute = path17__namespace.join(cwd, linkedPath);
|
|
4499
4599
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
4500
4600
|
let targetReal = null;
|
|
4501
4601
|
try {
|
|
4502
|
-
targetReal =
|
|
4602
|
+
targetReal = fs16__namespace.realpathSync(absolute);
|
|
4503
4603
|
} catch {
|
|
4504
4604
|
targetReal = null;
|
|
4505
4605
|
}
|
|
@@ -4517,7 +4617,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4517
4617
|
}
|
|
4518
4618
|
let stats = null;
|
|
4519
4619
|
try {
|
|
4520
|
-
stats =
|
|
4620
|
+
stats = fs16__namespace.statSync(absolute);
|
|
4521
4621
|
} catch {
|
|
4522
4622
|
stats = null;
|
|
4523
4623
|
}
|
|
@@ -4605,7 +4705,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
4605
4705
|
"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."
|
|
4606
4706
|
);
|
|
4607
4707
|
}
|
|
4608
|
-
if (
|
|
4708
|
+
if (fs16__namespace.existsSync(path17__namespace.join(cwd, ".git"))) {
|
|
4609
4709
|
throw new Error(
|
|
4610
4710
|
"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."
|
|
4611
4711
|
);
|
|
@@ -4673,7 +4773,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
4673
4773
|
}
|
|
4674
4774
|
function rootRealFor(root) {
|
|
4675
4775
|
try {
|
|
4676
|
-
return
|
|
4776
|
+
return fs16__namespace.realpathSync(root);
|
|
4677
4777
|
} catch {
|
|
4678
4778
|
return root;
|
|
4679
4779
|
}
|
|
@@ -4682,18 +4782,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4682
4782
|
const results = { files: [], skipped: [] };
|
|
4683
4783
|
const stack = [];
|
|
4684
4784
|
const toolDirNames = toolDirNamesFor(reservedPaths);
|
|
4685
|
-
const relativeToBase = (target) =>
|
|
4785
|
+
const relativeToBase = (target) => path17__namespace.relative(baseDir, target).replace(/\\/g, "/") || ".";
|
|
4686
4786
|
const enter = (current, layers) => {
|
|
4687
4787
|
if (visited.has(current)) return false;
|
|
4688
4788
|
visited.add(current);
|
|
4689
4789
|
const localRules = readGitignoreRules(current);
|
|
4690
4790
|
const gitignoreLayers = localRules.length === 0 ? layers : [
|
|
4691
4791
|
...layers,
|
|
4692
|
-
{ prefix:
|
|
4792
|
+
{ prefix: path17__namespace.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
|
|
4693
4793
|
];
|
|
4694
4794
|
let entries;
|
|
4695
4795
|
try {
|
|
4696
|
-
entries =
|
|
4796
|
+
entries = fs16__namespace.readdirSync(current, { withFileTypes: true });
|
|
4697
4797
|
} catch {
|
|
4698
4798
|
results.skipped.push({
|
|
4699
4799
|
path: relativeToBase(current),
|
|
@@ -4715,8 +4815,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4715
4815
|
}
|
|
4716
4816
|
const entry = frame.entries[frame.index];
|
|
4717
4817
|
frame.index += 1;
|
|
4718
|
-
const fullPath =
|
|
4719
|
-
const relPath =
|
|
4818
|
+
const fullPath = path17__namespace.join(frame.dir, entry.name);
|
|
4819
|
+
const relPath = path17__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
4720
4820
|
if (reservedPaths.has(relPath)) continue;
|
|
4721
4821
|
if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
|
|
4722
4822
|
results.skipped.push({
|
|
@@ -4749,14 +4849,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4749
4849
|
if (entry.isSymbolicLink()) {
|
|
4750
4850
|
let targetReal;
|
|
4751
4851
|
try {
|
|
4752
|
-
targetReal =
|
|
4852
|
+
targetReal = fs16__namespace.realpathSync(fullPath);
|
|
4753
4853
|
} catch {
|
|
4754
4854
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
4755
4855
|
continue;
|
|
4756
4856
|
}
|
|
4757
4857
|
let stats;
|
|
4758
4858
|
try {
|
|
4759
|
-
stats =
|
|
4859
|
+
stats = fs16__namespace.statSync(fullPath);
|
|
4760
4860
|
} catch {
|
|
4761
4861
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
4762
4862
|
continue;
|
|
@@ -4786,7 +4886,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4786
4886
|
});
|
|
4787
4887
|
continue;
|
|
4788
4888
|
}
|
|
4789
|
-
const targetRelative =
|
|
4889
|
+
const targetRelative = path17__namespace.relative(rootReal, targetReal).split(path17__namespace.sep).join("/");
|
|
4790
4890
|
if (isSensitivePath(targetRelative)) {
|
|
4791
4891
|
results.skipped.push({
|
|
4792
4892
|
path: relPath,
|
|
@@ -4895,6 +4995,12 @@ function normalizeResolvedConfig(config) {
|
|
|
4895
4995
|
return markResolvedConfig({
|
|
4896
4996
|
...config,
|
|
4897
4997
|
discovery,
|
|
4998
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
4999
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
5000
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
5001
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
5002
|
+
promptTask: resolvePromptTask(config.promptTask),
|
|
5003
|
+
...config.brief === void 0 ? {} : { brief: config.brief },
|
|
4898
5004
|
includeMonolith: artifacts.monolith,
|
|
4899
5005
|
secretRules: compileSecretRules(config.secretRules),
|
|
4900
5006
|
artifacts,
|
|
@@ -4963,7 +5069,9 @@ function describeValue2(value) {
|
|
|
4963
5069
|
var isThenable = (value) => typeof value.then === "function";
|
|
4964
5070
|
var CONFIG_KEY_NAMES = [
|
|
4965
5071
|
"artifacts",
|
|
5072
|
+
"attachmentSlots",
|
|
4966
5073
|
"branch",
|
|
5074
|
+
"brief",
|
|
4967
5075
|
"budgets",
|
|
4968
5076
|
"changedSince",
|
|
4969
5077
|
"cwd",
|
|
@@ -4980,10 +5088,12 @@ var CONFIG_KEY_NAMES = [
|
|
|
4980
5088
|
"layersMode",
|
|
4981
5089
|
"maxMonolithBytes",
|
|
4982
5090
|
"maxPartBytes",
|
|
5091
|
+
"maxParts",
|
|
4983
5092
|
"maxPartTokens",
|
|
4984
5093
|
"outDir",
|
|
4985
5094
|
"preset",
|
|
4986
5095
|
"previewHeadLines",
|
|
5096
|
+
"promptTask",
|
|
4987
5097
|
"staged",
|
|
4988
5098
|
"previewTailLines",
|
|
4989
5099
|
"secretRules",
|
|
@@ -5034,10 +5144,10 @@ function readConfigExport(exported, file) {
|
|
|
5034
5144
|
var lastModuleConfig = null;
|
|
5035
5145
|
function moduleConfigKey(fullPath) {
|
|
5036
5146
|
try {
|
|
5037
|
-
return crypto2.createHash("sha256").update(
|
|
5147
|
+
return crypto2.createHash("sha256").update(fs16__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
5038
5148
|
} catch {
|
|
5039
5149
|
try {
|
|
5040
|
-
const stats =
|
|
5150
|
+
const stats = fs16__namespace.statSync(fullPath);
|
|
5041
5151
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
5042
5152
|
} catch {
|
|
5043
5153
|
return "unreadable";
|
|
@@ -5063,7 +5173,7 @@ async function importConfigModule(fullPath) {
|
|
|
5063
5173
|
function attachConfigDir(config, filePath) {
|
|
5064
5174
|
if (typeof config === "object" && config !== null) {
|
|
5065
5175
|
Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
|
|
5066
|
-
value:
|
|
5176
|
+
value: path17__namespace.dirname(filePath),
|
|
5067
5177
|
enumerable: false,
|
|
5068
5178
|
configurable: true
|
|
5069
5179
|
});
|
|
@@ -5075,12 +5185,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5075
5185
|
const errors = [];
|
|
5076
5186
|
const configDirectories = [];
|
|
5077
5187
|
for (const filename of CONFIG_FILENAMES) {
|
|
5078
|
-
const fullPath =
|
|
5188
|
+
const fullPath = path17__namespace.join(cwd, filename);
|
|
5079
5189
|
let candidateStats = null;
|
|
5080
5190
|
try {
|
|
5081
|
-
candidateStats =
|
|
5191
|
+
candidateStats = fs16__namespace.statSync(fullPath);
|
|
5082
5192
|
} catch {
|
|
5083
|
-
if (!
|
|
5193
|
+
if (!fs16__namespace.existsSync(fullPath)) continue;
|
|
5084
5194
|
}
|
|
5085
5195
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
5086
5196
|
configDirectories.push(fullPath);
|
|
@@ -5088,7 +5198,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5088
5198
|
}
|
|
5089
5199
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
5090
5200
|
try {
|
|
5091
|
-
const config = parseJsonish(
|
|
5201
|
+
const config = parseJsonish(fs16__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
5092
5202
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
5093
5203
|
throw new Error(
|
|
5094
5204
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -5128,10 +5238,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5128
5238
|
continue;
|
|
5129
5239
|
}
|
|
5130
5240
|
}
|
|
5131
|
-
const pkgJsonPath =
|
|
5132
|
-
if (
|
|
5241
|
+
const pkgJsonPath = path17__namespace.join(cwd, "package.json");
|
|
5242
|
+
if (fs16__namespace.existsSync(pkgJsonPath)) {
|
|
5133
5243
|
try {
|
|
5134
|
-
const parsed = parseJsonish(
|
|
5244
|
+
const parsed = parseJsonish(fs16__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
5135
5245
|
const snapshotKey = parsed.snapshot;
|
|
5136
5246
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
5137
5247
|
assertKnownConfigKeys(
|
|
@@ -5185,6 +5295,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
5185
5295
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
5186
5296
|
var ARTIFACT_NAMES = [
|
|
5187
5297
|
"readme",
|
|
5298
|
+
"prompt",
|
|
5188
5299
|
"manifest",
|
|
5189
5300
|
"parts",
|
|
5190
5301
|
"navigation",
|
|
@@ -5194,6 +5305,7 @@ var ARTIFACT_NAMES = [
|
|
|
5194
5305
|
];
|
|
5195
5306
|
var DEFAULT_ARTIFACTS = {
|
|
5196
5307
|
readme: true,
|
|
5308
|
+
prompt: true,
|
|
5197
5309
|
manifest: true,
|
|
5198
5310
|
parts: true,
|
|
5199
5311
|
navigation: true,
|
|
@@ -5254,6 +5366,57 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
5254
5366
|
}
|
|
5255
5367
|
return artifacts;
|
|
5256
5368
|
}
|
|
5369
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
5370
|
+
function resolveAttachmentSlots(value) {
|
|
5371
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
5372
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
5373
|
+
throw new Error(
|
|
5374
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
5375
|
+
);
|
|
5376
|
+
}
|
|
5377
|
+
return value;
|
|
5378
|
+
}
|
|
5379
|
+
function resolveMaxParts(value) {
|
|
5380
|
+
if (value === void 0 || value === null) return null;
|
|
5381
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
5382
|
+
throw new Error(
|
|
5383
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
5384
|
+
);
|
|
5385
|
+
}
|
|
5386
|
+
return value;
|
|
5387
|
+
}
|
|
5388
|
+
function resolvePromptTask(value) {
|
|
5389
|
+
if (value === void 0 || value === null) return "audit";
|
|
5390
|
+
if (value === "audit" || value === "review" || value === "explain") return value;
|
|
5391
|
+
throw new Error(
|
|
5392
|
+
'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
|
|
5393
|
+
);
|
|
5394
|
+
}
|
|
5395
|
+
function readConfiguredBrief(cwd, value) {
|
|
5396
|
+
if (value === void 0 || value === null) return void 0;
|
|
5397
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
5398
|
+
throw new Error(
|
|
5399
|
+
"brief must be a path to a markdown file (received " + describeValue2(value) + ")."
|
|
5400
|
+
);
|
|
5401
|
+
}
|
|
5402
|
+
const filePath = path17__namespace.resolve(cwd, value);
|
|
5403
|
+
let text2;
|
|
5404
|
+
try {
|
|
5405
|
+
if (!fs16__namespace.statSync(filePath).isFile()) throw new Error("not a file");
|
|
5406
|
+
text2 = fs16__namespace.readFileSync(filePath, "utf8");
|
|
5407
|
+
} catch {
|
|
5408
|
+
throw new Error(
|
|
5409
|
+
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
5410
|
+
);
|
|
5411
|
+
}
|
|
5412
|
+
const parsed = parseOwnerBrief(value, text2);
|
|
5413
|
+
if (parsed.problems.length > 0) {
|
|
5414
|
+
throw new Error(
|
|
5415
|
+
'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
|
|
5416
|
+
);
|
|
5417
|
+
}
|
|
5418
|
+
return parsed.brief;
|
|
5419
|
+
}
|
|
5257
5420
|
function strictPositiveInteger(value, fallback, label) {
|
|
5258
5421
|
if (value === void 0) return fallback;
|
|
5259
5422
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -5346,9 +5509,9 @@ function resolveKindRules(value) {
|
|
|
5346
5509
|
function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
5347
5510
|
const patterns = [];
|
|
5348
5511
|
for (const dir of [outDir, tmpDir]) {
|
|
5349
|
-
const absolute =
|
|
5350
|
-
const relative11 =
|
|
5351
|
-
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${
|
|
5512
|
+
const absolute = path17__namespace.resolve(cwd, dir);
|
|
5513
|
+
const relative11 = path17__namespace.relative(cwd, absolute);
|
|
5514
|
+
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path17__namespace.sep}`) || path17__namespace.isAbsolute(relative11)) {
|
|
5352
5515
|
continue;
|
|
5353
5516
|
}
|
|
5354
5517
|
patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
|
|
@@ -5481,11 +5644,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
5481
5644
|
);
|
|
5482
5645
|
}
|
|
5483
5646
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
5484
|
-
const resolved =
|
|
5485
|
-
if (!
|
|
5647
|
+
const resolved = path17__namespace.resolve(candidate);
|
|
5648
|
+
if (!fs16__namespace.existsSync(resolved)) {
|
|
5486
5649
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
5487
5650
|
}
|
|
5488
|
-
if (!
|
|
5651
|
+
if (!fs16__namespace.statSync(resolved).isDirectory()) {
|
|
5489
5652
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
5490
5653
|
}
|
|
5491
5654
|
return resolved;
|
|
@@ -5613,6 +5776,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5613
5776
|
configuredSensitiveFiles,
|
|
5614
5777
|
"`includeSensitiveFiles`"
|
|
5615
5778
|
);
|
|
5779
|
+
const configuredBrief = readConfiguredBrief(
|
|
5780
|
+
cwd,
|
|
5781
|
+
cliOptions?.brief ?? userConfig?.brief
|
|
5782
|
+
);
|
|
5616
5783
|
const presetExclude = [
|
|
5617
5784
|
.../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
|
|
5618
5785
|
];
|
|
@@ -5632,6 +5799,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5632
5799
|
"maxMonolithBytes"
|
|
5633
5800
|
),
|
|
5634
5801
|
includeSensitiveFiles,
|
|
5802
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
5803
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
5804
|
+
),
|
|
5805
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
5806
|
+
promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
|
|
5807
|
+
...configuredBrief === void 0 ? {} : { brief: configuredBrief },
|
|
5635
5808
|
...changedSince === void 0 ? {} : { changedSince },
|
|
5636
5809
|
...staged ? { staged } : {},
|
|
5637
5810
|
...withDependents ? { withDependents } : {},
|
|
@@ -5714,6 +5887,15 @@ function configDigest(config) {
|
|
|
5714
5887
|
includeMonolith: config.includeMonolith,
|
|
5715
5888
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
5716
5889
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
5890
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
5891
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
5892
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
5893
|
+
// The default value is omitted for the same reason: a snapshot taken before the setting
|
|
5894
|
+
// existed kept the audit job, so it must keep the digest it was written with.
|
|
5895
|
+
...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
|
|
5896
|
+
// The owner brief is instruction, not payload, but it changes what the snapshot tells a
|
|
5897
|
+
// reader to do, so a changed brief is drift exactly like a changed budget.
|
|
5898
|
+
...config.brief === void 0 ? {} : { brief: config.brief.digest },
|
|
5717
5899
|
artifacts: config.artifacts,
|
|
5718
5900
|
include: config.include,
|
|
5719
5901
|
excludePatterns: config.excludePatterns,
|
|
@@ -6673,10 +6855,509 @@ function generateNavigation(manifest) {
|
|
|
6673
6855
|
return lines.join("\n");
|
|
6674
6856
|
}
|
|
6675
6857
|
|
|
6858
|
+
// src/generator/prompt.ts
|
|
6859
|
+
var MAX_PART_ROWS = 16;
|
|
6860
|
+
var MAX_LAYER_ROWS = 8;
|
|
6861
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
6862
|
+
var MAX_CENTRAL_FILES = 5;
|
|
6863
|
+
var MAX_ENTRY_POINTS = 4;
|
|
6864
|
+
var MAX_LARGEST_FILES = 3;
|
|
6865
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
6866
|
+
var UNLIMITED_SLOTS = 0;
|
|
6867
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
6868
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
6869
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
6870
|
+
function generatePrompt(manifest, artifacts, context = {}) {
|
|
6871
|
+
const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
|
|
6872
|
+
const task = context.task ?? "audit";
|
|
6873
|
+
const history = context.history ?? [];
|
|
6874
|
+
const overview = context.overview ?? { releases: [] };
|
|
6875
|
+
const brief = context.brief;
|
|
6876
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
6877
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
6878
|
+
const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
|
|
6879
|
+
const lines = [
|
|
6880
|
+
"# PROMPT.md",
|
|
6881
|
+
"",
|
|
6882
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
6883
|
+
"",
|
|
6884
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
6885
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
6886
|
+
"Regenerate it after the code moves.",
|
|
6887
|
+
"",
|
|
6888
|
+
"---",
|
|
6889
|
+
"",
|
|
6890
|
+
"```text",
|
|
6891
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
6892
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
6893
|
+
"the snapshot is what exists.",
|
|
6894
|
+
""
|
|
6895
|
+
];
|
|
6896
|
+
if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
|
|
6897
|
+
lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
|
|
6898
|
+
lines.push(...stakesSection(brief, code));
|
|
6899
|
+
lines.push(...haveSection(wrote), "");
|
|
6900
|
+
lines.push(...whatThisIsSection(overview), "");
|
|
6901
|
+
lines.push(...systemSection(manifest, code, brief), "");
|
|
6902
|
+
lines.push(...historySection(history, brief, code), "");
|
|
6903
|
+
lines.push(...barSection(brief, code), "");
|
|
6904
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
6905
|
+
lines.push(...answerSection(), "");
|
|
6906
|
+
lines.push(...calibrationSection(brief, code), "");
|
|
6907
|
+
lines.push(...ownerNotesSection(brief, code));
|
|
6908
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
6909
|
+
lines.push(...deliverySection(manifest, wrote("parts"), slots));
|
|
6910
|
+
lines.push(
|
|
6911
|
+
"## Your task",
|
|
6912
|
+
"",
|
|
6913
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
6914
|
+
"```"
|
|
6915
|
+
);
|
|
6916
|
+
lines.push(
|
|
6917
|
+
"",
|
|
6918
|
+
"---",
|
|
6919
|
+
"",
|
|
6920
|
+
"## Why this file exists",
|
|
6921
|
+
"",
|
|
6922
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
6923
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
6924
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
6925
|
+
"facts in it move with the snapshot.",
|
|
6926
|
+
"",
|
|
6927
|
+
"## Keeping it true",
|
|
6928
|
+
"",
|
|
6929
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
6930
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
6931
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
6932
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
6933
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
6934
|
+
" brief, because it reads as current.",
|
|
6935
|
+
""
|
|
6936
|
+
);
|
|
6937
|
+
return lines.join("\n");
|
|
6938
|
+
}
|
|
6939
|
+
function haveSection(wrote) {
|
|
6940
|
+
const out = ["## What you have", ""];
|
|
6941
|
+
const bullets = [];
|
|
6942
|
+
if (wrote("readme")) {
|
|
6943
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
6944
|
+
}
|
|
6945
|
+
if (wrote("manifest")) {
|
|
6946
|
+
bullets.push(
|
|
6947
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
6948
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
6949
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
6950
|
+
" every included file whose emitted body is not the whole file."
|
|
6951
|
+
);
|
|
6952
|
+
}
|
|
6953
|
+
if (wrote("navigation")) {
|
|
6954
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
6955
|
+
}
|
|
6956
|
+
if (wrote("projectTree")) {
|
|
6957
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
6958
|
+
}
|
|
6959
|
+
if (wrote("audit")) {
|
|
6960
|
+
bullets.push(
|
|
6961
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
6962
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
6963
|
+
);
|
|
6964
|
+
}
|
|
6965
|
+
if (wrote("parts")) {
|
|
6966
|
+
bullets.push(
|
|
6967
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
6968
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
6969
|
+
);
|
|
6970
|
+
}
|
|
6971
|
+
if (wrote("monolith")) {
|
|
6972
|
+
bullets.push(
|
|
6973
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
6974
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
6975
|
+
);
|
|
6976
|
+
}
|
|
6977
|
+
if (bullets.length === 0) {
|
|
6978
|
+
bullets.push(
|
|
6979
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
6980
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
6981
|
+
);
|
|
6982
|
+
}
|
|
6983
|
+
out.push(...bullets);
|
|
6984
|
+
return out;
|
|
6985
|
+
}
|
|
6986
|
+
function systemSection(manifest, code, brief) {
|
|
6987
|
+
const out = ["## The system", ""];
|
|
6988
|
+
if (brief?.system !== void 0) {
|
|
6989
|
+
out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
|
|
6990
|
+
}
|
|
6991
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
6992
|
+
if (layers.length > 0) {
|
|
6993
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
6994
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
6995
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
6996
|
+
}
|
|
6997
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
6998
|
+
if (central.length > 0) {
|
|
6999
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
7000
|
+
out.push(
|
|
7001
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
7002
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
7003
|
+
);
|
|
7004
|
+
}
|
|
7005
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path18) => ENTRY_POINT.test(path18)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
7006
|
+
out.push(
|
|
7007
|
+
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"
|
|
7008
|
+
);
|
|
7009
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
7010
|
+
const routes = manifest.indexes.routes.length;
|
|
7011
|
+
const handlers = manifest.indexes.handlers.length;
|
|
7012
|
+
const components = manifest.indexes.components.length;
|
|
7013
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
7014
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
7015
|
+
if (routes + handlers + components === 0) {
|
|
7016
|
+
out.push(
|
|
7017
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
7018
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
7019
|
+
);
|
|
7020
|
+
} else {
|
|
7021
|
+
const parts = [];
|
|
7022
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
7023
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
7024
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
7025
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
7026
|
+
}
|
|
7027
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
7028
|
+
if (largest.length > 0) {
|
|
7029
|
+
out.push(
|
|
7030
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
7031
|
+
);
|
|
7032
|
+
}
|
|
7033
|
+
const tests = manifest.files.filter(
|
|
7034
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
7035
|
+
);
|
|
7036
|
+
if (tests.length > 0) {
|
|
7037
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
7038
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
7039
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
7040
|
+
out.push(
|
|
7041
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
7042
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
7043
|
+
" real system never sends."
|
|
7044
|
+
);
|
|
7045
|
+
}
|
|
7046
|
+
return out;
|
|
7047
|
+
}
|
|
7048
|
+
function historySection(history, brief, code) {
|
|
7049
|
+
const out = ["## What came before", ""];
|
|
7050
|
+
if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
|
|
7051
|
+
if (history.length === 0) {
|
|
7052
|
+
out.push(
|
|
7053
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
7054
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
7055
|
+
);
|
|
7056
|
+
return out;
|
|
7057
|
+
}
|
|
7058
|
+
out.push(
|
|
7059
|
+
"The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
|
|
7060
|
+
"claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
|
|
7061
|
+
"these fixes looks incomplete, quote the lines and say which call site it missed.",
|
|
7062
|
+
""
|
|
7063
|
+
);
|
|
7064
|
+
for (const commit of history) {
|
|
7065
|
+
out.push("- " + commit.subject);
|
|
7066
|
+
if (commit.body.length > 0) out.push(" " + commit.body);
|
|
7067
|
+
}
|
|
7068
|
+
return out;
|
|
7069
|
+
}
|
|
7070
|
+
function barSection(brief, code) {
|
|
7071
|
+
if (brief?.bar !== void 0) {
|
|
7072
|
+
return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
|
|
7073
|
+
}
|
|
7074
|
+
return [
|
|
7075
|
+
"## The bar",
|
|
7076
|
+
"",
|
|
7077
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
7078
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
7079
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
7080
|
+
"behaviour.",
|
|
7081
|
+
"",
|
|
7082
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
7083
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
7084
|
+
" that makes it clean.",
|
|
7085
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
7086
|
+
" you cannot decide by reading.",
|
|
7087
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
7088
|
+
" findings; they have different owners and different fixes."
|
|
7089
|
+
];
|
|
7090
|
+
}
|
|
7091
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
7092
|
+
const out = ["## Coverage", ""];
|
|
7093
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
7094
|
+
for (const record of manifest.skipped) {
|
|
7095
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
7096
|
+
}
|
|
7097
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
7098
|
+
out.push(
|
|
7099
|
+
"- " + formatNumber(manifest.totals.candidateFiles) + " path(s) were found; " + formatNumber(manifest.totals.includedFiles) + " are in the parts and " + formatNumber(manifest.counts.skippedCount) + " were skipped" + (tally.length > 0 ? " (" + tally + ")" : "") + ".",
|
|
7100
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
7101
|
+
);
|
|
7102
|
+
out.push(...incompleteSection(manifest, code));
|
|
7103
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
7104
|
+
out.push(
|
|
7105
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
7106
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
7107
|
+
" is an input defect, not a code finding - report it as one."
|
|
7108
|
+
);
|
|
7109
|
+
return out;
|
|
7110
|
+
}
|
|
7111
|
+
function answerSection() {
|
|
7112
|
+
return [
|
|
7113
|
+
"## What a useful answer contains",
|
|
7114
|
+
"",
|
|
7115
|
+
"- An opening line, filled from This snapshot below:",
|
|
7116
|
+
"",
|
|
7117
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
7118
|
+
"",
|
|
7119
|
+
"- What you read and what you did not, named by path or by part.",
|
|
7120
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
7121
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
7122
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
7123
|
+
"- What you retracted after re-reading.",
|
|
7124
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
7125
|
+
"- One paragraph on the failure you would bet on next.",
|
|
7126
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
7127
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
7128
|
+
" the gap you filled by asking instead of guessing."
|
|
7129
|
+
];
|
|
7130
|
+
}
|
|
7131
|
+
function calibrationSection(brief, code) {
|
|
7132
|
+
if (brief?.calibration !== void 0) {
|
|
7133
|
+
return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
|
|
7134
|
+
}
|
|
7135
|
+
return [
|
|
7136
|
+
"## Calibration",
|
|
7137
|
+
"",
|
|
7138
|
+
"The findings that matter here do not crash. They look like:",
|
|
7139
|
+
"",
|
|
7140
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
7141
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
7142
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
7143
|
+
"- a document that describes a different run than the one beside it;",
|
|
7144
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
7145
|
+
"",
|
|
7146
|
+
"None of these throw. All are invisible in a summary."
|
|
7147
|
+
];
|
|
7148
|
+
}
|
|
7149
|
+
function jobSection(task, hasHistory) {
|
|
7150
|
+
const out = ["## The job", ""];
|
|
7151
|
+
if (task === "audit") {
|
|
7152
|
+
out.push(
|
|
7153
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
7154
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
7155
|
+
"honest account of what you covered and what you did not.",
|
|
7156
|
+
""
|
|
7157
|
+
);
|
|
7158
|
+
if (hasHistory) {
|
|
7159
|
+
out.push(
|
|
7160
|
+
"Another pass of the same findings is worth nothing. This repository carries a record of",
|
|
7161
|
+
"what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
|
|
7162
|
+
"and treat a variant of one at a different call site as a new finding."
|
|
7163
|
+
);
|
|
7164
|
+
} else {
|
|
7165
|
+
out.push(
|
|
7166
|
+
"Another pass of the same findings is worth nothing, but no earlier round is readable here,",
|
|
7167
|
+
"so you cannot tell what has already been tried. Do not assume this is the first attempt."
|
|
7168
|
+
);
|
|
7169
|
+
}
|
|
7170
|
+
out.push(
|
|
7171
|
+
"",
|
|
7172
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer",
|
|
7173
|
+
"a question - that task wins. The standard and the coverage duty below still apply to it."
|
|
7174
|
+
);
|
|
7175
|
+
} else if (task === "review") {
|
|
7176
|
+
out.push(
|
|
7177
|
+
"Review the change or the area named in the task against this snapshot. Report what breaks,",
|
|
7178
|
+
"what the change claims but does not do, and what a reader would believe that the code does",
|
|
7179
|
+
"not support. Restating the diff is not a review; the standard and the coverage duty below",
|
|
7180
|
+
"still apply."
|
|
7181
|
+
);
|
|
7182
|
+
} else {
|
|
7183
|
+
out.push(
|
|
7184
|
+
"Explain how the part of the system named in the task works: the data flow, the boundaries",
|
|
7185
|
+
"and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
|
|
7186
|
+
"need, say which file you need rather than reconstructing it from the shape of the names."
|
|
7187
|
+
);
|
|
7188
|
+
}
|
|
7189
|
+
return out;
|
|
7190
|
+
}
|
|
7191
|
+
function stakesSection(brief, code) {
|
|
7192
|
+
if (brief?.stakes === void 0) return [];
|
|
7193
|
+
return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
|
|
7194
|
+
}
|
|
7195
|
+
function whatThisIsSection(overview) {
|
|
7196
|
+
const body = [];
|
|
7197
|
+
if (overview.description !== void 0) {
|
|
7198
|
+
body.push("- Declared in `package.json`: " + overview.description);
|
|
7199
|
+
}
|
|
7200
|
+
if (overview.summary !== void 0) {
|
|
7201
|
+
body.push("- From the `README.md` first paragraph: " + overview.summary);
|
|
7202
|
+
}
|
|
7203
|
+
if (overview.releases.length > 0) {
|
|
7204
|
+
body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
|
|
7205
|
+
}
|
|
7206
|
+
if (body.length === 0) return [];
|
|
7207
|
+
return [
|
|
7208
|
+
"## What this is",
|
|
7209
|
+
"",
|
|
7210
|
+
...body,
|
|
7211
|
+
"",
|
|
7212
|
+
"Those are the project's own claims, not evidence about the code.",
|
|
7213
|
+
""
|
|
7214
|
+
];
|
|
7215
|
+
}
|
|
7216
|
+
function ownerNotesSection(brief, code) {
|
|
7217
|
+
if (brief === void 0 || brief.notes.length === 0) return [];
|
|
7218
|
+
const out = ["## Owner notes", ""];
|
|
7219
|
+
for (const note of brief.notes) {
|
|
7220
|
+
out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
|
|
7221
|
+
}
|
|
7222
|
+
return out;
|
|
7223
|
+
}
|
|
7224
|
+
function ownerBlock(text2, path18, code) {
|
|
7225
|
+
return ["> Written by the project owner in " + code(path18) + ", not generated.", "", text2];
|
|
7226
|
+
}
|
|
7227
|
+
function snapshotSection(manifest, code) {
|
|
7228
|
+
const out = ["## This snapshot", ""];
|
|
7229
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
7230
|
+
out.push(
|
|
7231
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
7232
|
+
);
|
|
7233
|
+
out.push(
|
|
7234
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
7235
|
+
);
|
|
7236
|
+
out.push(
|
|
7237
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
7238
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
7239
|
+
" claim that needs re-checking, not a fact."
|
|
7240
|
+
);
|
|
7241
|
+
if (manifest.parts.length > 0) {
|
|
7242
|
+
out.push(
|
|
7243
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
7244
|
+
);
|
|
7245
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
7246
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
7247
|
+
}
|
|
7248
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
7249
|
+
out.push(
|
|
7250
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
7251
|
+
);
|
|
7252
|
+
}
|
|
7253
|
+
}
|
|
7254
|
+
return out;
|
|
7255
|
+
}
|
|
7256
|
+
function incompleteSection(manifest, code) {
|
|
7257
|
+
const out = [];
|
|
7258
|
+
const list2 = manifest.incomplete;
|
|
7259
|
+
if (list2.length === 0) {
|
|
7260
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
7261
|
+
return out;
|
|
7262
|
+
}
|
|
7263
|
+
out.push(
|
|
7264
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
7265
|
+
" missing lines are named, not implied:"
|
|
7266
|
+
);
|
|
7267
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
7268
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
7269
|
+
out.push(
|
|
7270
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
7271
|
+
);
|
|
7272
|
+
}
|
|
7273
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
7274
|
+
out.push(
|
|
7275
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
7276
|
+
);
|
|
7277
|
+
}
|
|
7278
|
+
return out;
|
|
7279
|
+
}
|
|
7280
|
+
function redactionSection(manifest, auditWritten) {
|
|
7281
|
+
const redacted = manifest.totals.redactedLines;
|
|
7282
|
+
if (redacted === 0) {
|
|
7283
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
7284
|
+
}
|
|
7285
|
+
const where = auditWritten ? "`reports/audit.md` names the files; the values are not recoverable from it." : "`reports/audit.md` was disabled for this run, so only the count is available.";
|
|
7286
|
+
return [
|
|
7287
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
7288
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
7289
|
+
" " + where
|
|
7290
|
+
];
|
|
7291
|
+
}
|
|
7292
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
7293
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
7294
|
+
const parts = manifest.parts.length;
|
|
7295
|
+
const wholeSet = parts + 5;
|
|
7296
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
7297
|
+
const out = ["## Attaching this", ""];
|
|
7298
|
+
out.push(
|
|
7299
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
7300
|
+
"",
|
|
7301
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
7302
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
7303
|
+
);
|
|
7304
|
+
if (unlimited) {
|
|
7305
|
+
out.push(
|
|
7306
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
7307
|
+
);
|
|
7308
|
+
} else if (wholeSet <= slots) {
|
|
7309
|
+
out.push(
|
|
7310
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
7311
|
+
);
|
|
7312
|
+
} else if (parts + 1 <= slots) {
|
|
7313
|
+
out.push(
|
|
7314
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
7315
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
7316
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
7317
|
+
);
|
|
7318
|
+
} else if (parts <= slots) {
|
|
7319
|
+
out.push(
|
|
7320
|
+
parts === 1 ? "- The only part fills a " + slots + "-file destination, so `manifest.json` and" : "- The " + parts + " parts fill a " + slots + "-file destination, so `manifest.json` and",
|
|
7321
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
7322
|
+
);
|
|
7323
|
+
if (parts > 1) {
|
|
7324
|
+
out.push(
|
|
7325
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
7326
|
+
);
|
|
7327
|
+
}
|
|
7328
|
+
} else {
|
|
7329
|
+
out.push(
|
|
7330
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
7331
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
7332
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
7333
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
7334
|
+
);
|
|
7335
|
+
}
|
|
7336
|
+
out.push(
|
|
7337
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
7338
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
7339
|
+
""
|
|
7340
|
+
);
|
|
7341
|
+
return out;
|
|
7342
|
+
}
|
|
7343
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
7344
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
7345
|
+
const target = Math.max(1, slots - 1);
|
|
7346
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
7347
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
7348
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
7349
|
+
return Math.round(budget / 1024) + "k";
|
|
7350
|
+
}
|
|
7351
|
+
|
|
6676
7352
|
// src/generator/readme.ts
|
|
6677
7353
|
function generateReadme(manifest, artifacts) {
|
|
6678
7354
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
6679
7355
|
const reportLinks = [];
|
|
7356
|
+
if (wrote("prompt")) {
|
|
7357
|
+
reportLinks.push(
|
|
7358
|
+
"- [PROMPT.md](PROMPT.md) \u2014 The instruction sheet to paste with this snapshot: what it contains, what it left out, and the rules for citing it."
|
|
7359
|
+
);
|
|
7360
|
+
}
|
|
6680
7361
|
if (wrote("navigation")) {
|
|
6681
7362
|
reportLinks.push(
|
|
6682
7363
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -6746,6 +7427,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
6746
7427
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
6747
7428
|
}
|
|
6748
7429
|
const readOrder = [];
|
|
7430
|
+
if (wrote("prompt")) {
|
|
7431
|
+
readOrder.push(
|
|
7432
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
7433
|
+
);
|
|
7434
|
+
}
|
|
6749
7435
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
6750
7436
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
6751
7437
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -6893,7 +7579,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6893
7579
|
const descriptions = [];
|
|
6894
7580
|
if (request.changedSince !== void 0) {
|
|
6895
7581
|
assertUsableRef(request.changedSince);
|
|
6896
|
-
for (const
|
|
7582
|
+
for (const path18 of gitPaths(cwd, [
|
|
6897
7583
|
"diff",
|
|
6898
7584
|
"--name-only",
|
|
6899
7585
|
"-z",
|
|
@@ -6901,9 +7587,9 @@ function resolveChangedScope(cwd, request) {
|
|
|
6901
7587
|
`${request.changedSince}...HEAD`,
|
|
6902
7588
|
"--"
|
|
6903
7589
|
])) {
|
|
6904
|
-
paths.add(
|
|
7590
|
+
paths.add(path18);
|
|
6905
7591
|
}
|
|
6906
|
-
for (const
|
|
7592
|
+
for (const path18 of gitPaths(cwd, [
|
|
6907
7593
|
"diff",
|
|
6908
7594
|
"--name-only",
|
|
6909
7595
|
"-z",
|
|
@@ -6911,15 +7597,15 @@ function resolveChangedScope(cwd, request) {
|
|
|
6911
7597
|
"HEAD",
|
|
6912
7598
|
"--"
|
|
6913
7599
|
])) {
|
|
6914
|
-
paths.add(
|
|
7600
|
+
paths.add(path18);
|
|
6915
7601
|
}
|
|
6916
|
-
for (const
|
|
6917
|
-
paths.add(
|
|
7602
|
+
for (const path18 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
7603
|
+
paths.add(path18);
|
|
6918
7604
|
}
|
|
6919
7605
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
6920
7606
|
}
|
|
6921
7607
|
if (request.staged === true) {
|
|
6922
|
-
for (const
|
|
7608
|
+
for (const path18 of gitPaths(cwd, [
|
|
6923
7609
|
"diff",
|
|
6924
7610
|
"--cached",
|
|
6925
7611
|
"--name-only",
|
|
@@ -6927,10 +7613,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
6927
7613
|
"--relative",
|
|
6928
7614
|
"--"
|
|
6929
7615
|
])) {
|
|
6930
|
-
paths.add(
|
|
6931
|
-
stagedPaths.add(
|
|
7616
|
+
paths.add(path18);
|
|
7617
|
+
stagedPaths.add(path18);
|
|
6932
7618
|
}
|
|
6933
|
-
for (const
|
|
7619
|
+
for (const path18 of gitPaths(cwd, [
|
|
6934
7620
|
"diff",
|
|
6935
7621
|
"--cached",
|
|
6936
7622
|
"--name-only",
|
|
@@ -6939,7 +7625,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6939
7625
|
"--diff-filter=D",
|
|
6940
7626
|
"--"
|
|
6941
7627
|
])) {
|
|
6942
|
-
deletedPaths.add(
|
|
7628
|
+
deletedPaths.add(path18);
|
|
6943
7629
|
}
|
|
6944
7630
|
descriptions.push("staged");
|
|
6945
7631
|
}
|
|
@@ -6977,10 +7663,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
|
6977
7663
|
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
6978
7664
|
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
6979
7665
|
function tsconfigPathsFor(cwd) {
|
|
6980
|
-
const configPath =
|
|
7666
|
+
const configPath = path17__namespace.join(cwd, "tsconfig.json");
|
|
6981
7667
|
let stats;
|
|
6982
7668
|
try {
|
|
6983
|
-
stats =
|
|
7669
|
+
stats = fs16__namespace.statSync(configPath);
|
|
6984
7670
|
} catch (err) {
|
|
6985
7671
|
if (err.code === "ENOENT") return null;
|
|
6986
7672
|
return null;
|
|
@@ -7014,8 +7700,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
7014
7700
|
return value;
|
|
7015
7701
|
}
|
|
7016
7702
|
function repositoryRelative(cwd, target) {
|
|
7017
|
-
const relative11 =
|
|
7018
|
-
return relative11.length === 0 || !relative11.startsWith("..") && !
|
|
7703
|
+
const relative11 = path17__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
7704
|
+
return relative11.length === 0 || !relative11.startsWith("..") && !path17__namespace.isAbsolute(relative11) ? relative11 : null;
|
|
7019
7705
|
}
|
|
7020
7706
|
function rememberFirst(map, key, value) {
|
|
7021
7707
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -7030,15 +7716,15 @@ function buildImportResolver(files, options = {}) {
|
|
|
7030
7716
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7031
7717
|
rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
7032
7718
|
}
|
|
7033
|
-
const extension =
|
|
7719
|
+
const extension = path17__namespace.posix.extname(relativePath);
|
|
7034
7720
|
if (!SOURCE_EXTENSIONS.has(extension)) return;
|
|
7035
7721
|
const stem = relativePath.slice(0, -extension.length);
|
|
7036
7722
|
rememberFirst(byStem, stem, relativePath);
|
|
7037
7723
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7038
7724
|
rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
|
|
7039
7725
|
}
|
|
7040
|
-
if (
|
|
7041
|
-
const directory =
|
|
7726
|
+
if (path17__namespace.posix.basename(stem) === "index") {
|
|
7727
|
+
const directory = path17__namespace.posix.dirname(stem);
|
|
7042
7728
|
rememberFirst(byStem, directory, relativePath);
|
|
7043
7729
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7044
7730
|
rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
|
|
@@ -7054,7 +7740,7 @@ function buildImportResolver(files, options = {}) {
|
|
|
7054
7740
|
return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
|
|
7055
7741
|
}
|
|
7056
7742
|
function resolveSpecifier(fromFile, specifier, resolver) {
|
|
7057
|
-
const extension =
|
|
7743
|
+
const extension = path17__namespace.posix.extname(fromFile).toLowerCase();
|
|
7058
7744
|
const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
7059
7745
|
const firstOf = (candidates) => {
|
|
7060
7746
|
for (const candidate of candidates) {
|
|
@@ -7077,34 +7763,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
7077
7763
|
if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
|
|
7078
7764
|
const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
|
|
7079
7765
|
const rest = specifier.slice(dots).replace(/\./g, "/");
|
|
7080
|
-
let base =
|
|
7081
|
-
for (let up = 1; up < dots; up += 1) base =
|
|
7082
|
-
const joined2 = rest ?
|
|
7766
|
+
let base = path17__namespace.posix.dirname(fromFile);
|
|
7767
|
+
for (let up = 1; up < dots; up += 1) base = path17__namespace.posix.dirname(base);
|
|
7768
|
+
const joined2 = rest ? path17__namespace.posix.normalize(path17__namespace.posix.join(base, rest)) : base;
|
|
7083
7769
|
return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
|
|
7084
7770
|
}
|
|
7085
7771
|
if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
7086
|
-
const joined2 =
|
|
7087
|
-
|
|
7772
|
+
const joined2 = path17__namespace.posix.normalize(
|
|
7773
|
+
path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
|
|
7088
7774
|
);
|
|
7089
7775
|
return firstOf([`${joined2}.rb`, joined2]);
|
|
7090
7776
|
}
|
|
7091
7777
|
if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
7092
|
-
const joined2 =
|
|
7093
|
-
|
|
7778
|
+
const joined2 = path17__namespace.posix.normalize(
|
|
7779
|
+
path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
|
|
7094
7780
|
);
|
|
7095
7781
|
return exact(joined2);
|
|
7096
7782
|
}
|
|
7097
7783
|
if (extension === ".dart" && !specifier.includes(":")) {
|
|
7098
|
-
const joined2 =
|
|
7099
|
-
|
|
7784
|
+
const joined2 = path17__namespace.posix.normalize(
|
|
7785
|
+
path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
|
|
7100
7786
|
);
|
|
7101
7787
|
return firstOf([joined2, `${joined2}.dart`]);
|
|
7102
7788
|
}
|
|
7103
7789
|
if (!RELATIVE_SPECIFIER.test(specifier)) {
|
|
7104
7790
|
return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
|
|
7105
7791
|
}
|
|
7106
|
-
const joined =
|
|
7107
|
-
|
|
7792
|
+
const joined = path17__namespace.posix.normalize(
|
|
7793
|
+
path17__namespace.posix.join(path17__namespace.posix.dirname(fromFile), specifier)
|
|
7108
7794
|
);
|
|
7109
7795
|
return lookupPath(joined);
|
|
7110
7796
|
}
|
|
@@ -7128,13 +7814,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
|
|
|
7128
7814
|
if (captured === null) continue;
|
|
7129
7815
|
for (const target of rule.targets) {
|
|
7130
7816
|
const substituted = target.split("*").join(captured);
|
|
7131
|
-
const base = config.baseUrl === null ? substituted :
|
|
7132
|
-
const hit = lookupPath(
|
|
7817
|
+
const base = config.baseUrl === null ? substituted : path17__namespace.posix.join(config.baseUrl, substituted);
|
|
7818
|
+
const hit = lookupPath(path17__namespace.posix.normalize(base));
|
|
7133
7819
|
if (hit) return hit;
|
|
7134
7820
|
}
|
|
7135
7821
|
}
|
|
7136
7822
|
if (config.baseUrl !== null) {
|
|
7137
|
-
return lookupPath(
|
|
7823
|
+
return lookupPath(path17__namespace.posix.normalize(path17__namespace.posix.join(config.baseUrl, specifier)));
|
|
7138
7824
|
}
|
|
7139
7825
|
return null;
|
|
7140
7826
|
}
|
|
@@ -7145,6 +7831,58 @@ function importsChangedFile(importerPath, imports, changedPaths, resolver) {
|
|
|
7145
7831
|
}
|
|
7146
7832
|
return false;
|
|
7147
7833
|
}
|
|
7834
|
+
var SUMMARY_LIMIT = 400;
|
|
7835
|
+
var MAX_RELEASES = 2;
|
|
7836
|
+
function readProjectOverview(cwd) {
|
|
7837
|
+
return {
|
|
7838
|
+
...readDescription(cwd),
|
|
7839
|
+
...readSummary(cwd),
|
|
7840
|
+
releases: readReleases(cwd)
|
|
7841
|
+
};
|
|
7842
|
+
}
|
|
7843
|
+
function readText(file) {
|
|
7844
|
+
try {
|
|
7845
|
+
return fs16__namespace.readFileSync(file, "utf8");
|
|
7846
|
+
} catch {
|
|
7847
|
+
return null;
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
function readDescription(cwd) {
|
|
7851
|
+
const raw = readText(path17__namespace.join(cwd, "package.json"));
|
|
7852
|
+
if (raw === null) return {};
|
|
7853
|
+
try {
|
|
7854
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
7855
|
+
return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
|
|
7856
|
+
} catch {
|
|
7857
|
+
return {};
|
|
7858
|
+
}
|
|
7859
|
+
}
|
|
7860
|
+
function readSummary(cwd) {
|
|
7861
|
+
const raw = readText(path17__namespace.join(cwd, "README.md"));
|
|
7862
|
+
if (raw === null) return {};
|
|
7863
|
+
const lines = raw.split(/\r?\n/);
|
|
7864
|
+
const paragraph = [];
|
|
7865
|
+
for (const line of lines) {
|
|
7866
|
+
const trimmed = line.trim();
|
|
7867
|
+
if (paragraph.length === 0) {
|
|
7868
|
+
if (trimmed.length === 0) continue;
|
|
7869
|
+
if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
|
|
7870
|
+
if (/^\[[^\]]+\]:/.test(trimmed)) continue;
|
|
7871
|
+
} else if (trimmed.length === 0 || /^#/.test(trimmed)) {
|
|
7872
|
+
break;
|
|
7873
|
+
}
|
|
7874
|
+
paragraph.push(trimmed);
|
|
7875
|
+
}
|
|
7876
|
+
const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
|
|
7877
|
+
if (summary.length === 0) return {};
|
|
7878
|
+
return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
|
|
7879
|
+
}
|
|
7880
|
+
function readReleases(cwd) {
|
|
7881
|
+
const raw = readText(path17__namespace.join(cwd, "CHANGELOG.md"));
|
|
7882
|
+
if (raw === null) return [];
|
|
7883
|
+
const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
|
|
7884
|
+
return headings.slice(0, MAX_RELEASES);
|
|
7885
|
+
}
|
|
7148
7886
|
var LANGUAGE_BY_EXTENSION = {
|
|
7149
7887
|
".ts": "typescript",
|
|
7150
7888
|
".mts": "typescript",
|
|
@@ -7202,10 +7940,10 @@ var LANGUAGE_BY_BASENAME = {
|
|
|
7202
7940
|
};
|
|
7203
7941
|
function detectLanguage(filePath) {
|
|
7204
7942
|
const normalized = filePath.replace(/\\/g, "/");
|
|
7205
|
-
const base =
|
|
7943
|
+
const base = path17__namespace.posix.basename(normalized);
|
|
7206
7944
|
if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
|
|
7207
7945
|
if (base === ".env" || base.startsWith(".env.")) return "dotenv";
|
|
7208
|
-
const ext =
|
|
7946
|
+
const ext = path17__namespace.posix.extname(base).toLowerCase();
|
|
7209
7947
|
return LANGUAGE_BY_EXTENSION[ext] ?? "text";
|
|
7210
7948
|
}
|
|
7211
7949
|
function maskedPath(value, secretRules) {
|
|
@@ -7213,33 +7951,33 @@ function maskedPath(value, secretRules) {
|
|
|
7213
7951
|
}
|
|
7214
7952
|
function confineToDirectory(directory, filename) {
|
|
7215
7953
|
if (filename.includes("\0")) return null;
|
|
7216
|
-
if (
|
|
7217
|
-
const base =
|
|
7218
|
-
const resolved =
|
|
7954
|
+
if (path17__namespace.isAbsolute(filename)) return null;
|
|
7955
|
+
const base = path17__namespace.resolve(directory);
|
|
7956
|
+
const resolved = path17__namespace.resolve(base, filename);
|
|
7219
7957
|
const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
|
|
7220
|
-
const prefix = caseInsensitive ? `${base}${
|
|
7958
|
+
const prefix = caseInsensitive ? `${base}${path17__namespace.sep}`.toLowerCase() : `${base}${path17__namespace.sep}`;
|
|
7221
7959
|
const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
|
|
7222
7960
|
return candidate.startsWith(prefix) ? resolved : null;
|
|
7223
7961
|
}
|
|
7224
7962
|
function findStagingDirectory(config) {
|
|
7225
|
-
const tmpDir =
|
|
7963
|
+
const tmpDir = path17__namespace.resolve(config.cwd, config.tmpDir);
|
|
7226
7964
|
let entries;
|
|
7227
7965
|
try {
|
|
7228
|
-
entries =
|
|
7966
|
+
entries = fs16__namespace.readdirSync(tmpDir);
|
|
7229
7967
|
} catch {
|
|
7230
7968
|
return null;
|
|
7231
7969
|
}
|
|
7232
7970
|
const runs = entries.filter((name) => name.startsWith("run-")).sort();
|
|
7233
7971
|
const newest = runs[runs.length - 1];
|
|
7234
|
-
return newest ?
|
|
7972
|
+
return newest ? path17__namespace.join(tmpDir, newest) : null;
|
|
7235
7973
|
}
|
|
7236
7974
|
function describeMissingManifest(config, manifestPath) {
|
|
7237
|
-
const outDir =
|
|
7238
|
-
const markerPath =
|
|
7975
|
+
const outDir = path17__namespace.resolve(config.cwd, config.outDir);
|
|
7976
|
+
const markerPath = path17__namespace.join(outDir, ".codebase-snapshot");
|
|
7239
7977
|
let marker2 = null;
|
|
7240
7978
|
try {
|
|
7241
|
-
if (
|
|
7242
|
-
const parsed = JSON.parse(
|
|
7979
|
+
if (fs16__namespace.existsSync(markerPath)) {
|
|
7980
|
+
const parsed = JSON.parse(fs16__namespace.readFileSync(markerPath, "utf8"));
|
|
7243
7981
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7244
7982
|
marker2 = parsed;
|
|
7245
7983
|
}
|
|
@@ -7274,13 +8012,13 @@ function sha256Hex(buffer) {
|
|
|
7274
8012
|
return crypto2__namespace.createHash("sha256").update(buffer).digest("hex");
|
|
7275
8013
|
}
|
|
7276
8014
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
7277
|
-
const absolutePath =
|
|
8015
|
+
const absolutePath = path17__namespace.join(cwd, relativePath);
|
|
7278
8016
|
try {
|
|
7279
|
-
const stats =
|
|
8017
|
+
const stats = fs16__namespace.statSync(absolutePath);
|
|
7280
8018
|
if (!stats.isFile()) return false;
|
|
7281
8019
|
if (isBinaryExtension(absolutePath)) return false;
|
|
7282
8020
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
7283
|
-
return !decodeText(
|
|
8021
|
+
return !decodeText(fs16__namespace.readFileSync(absolutePath)).binary;
|
|
7284
8022
|
} catch {
|
|
7285
8023
|
return false;
|
|
7286
8024
|
}
|
|
@@ -7292,7 +8030,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
|
7292
8030
|
]);
|
|
7293
8031
|
function isConfinedRelative(value) {
|
|
7294
8032
|
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
7295
|
-
if (
|
|
8033
|
+
if (path17__namespace.isAbsolute(value)) return false;
|
|
7296
8034
|
return !value.split("/").includes("..");
|
|
7297
8035
|
}
|
|
7298
8036
|
function describeManifestShapeProblem(value) {
|
|
@@ -7460,7 +8198,7 @@ function describeManifestShapeProblem(value) {
|
|
|
7460
8198
|
if (typeof filename !== "string" || filename.trim() === "") {
|
|
7461
8199
|
return 'a "parts" entry has no "filename"';
|
|
7462
8200
|
}
|
|
7463
|
-
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." ||
|
|
8201
|
+
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path17__namespace.isAbsolute(filename)) {
|
|
7464
8202
|
return 'a "parts" entry "filename" must be a bare filename inside parts/';
|
|
7465
8203
|
}
|
|
7466
8204
|
if (currentSchema) {
|
|
@@ -7486,8 +8224,8 @@ function describeManifestShapeProblem(value) {
|
|
|
7486
8224
|
function validateSnapshot(configInput) {
|
|
7487
8225
|
assertUsableConfigInput(configInput);
|
|
7488
8226
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
7489
|
-
const manifestPath =
|
|
7490
|
-
if (!
|
|
8227
|
+
const manifestPath = path17__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
8228
|
+
if (!fs16__namespace.existsSync(manifestPath)) {
|
|
7491
8229
|
return {
|
|
7492
8230
|
valid: false,
|
|
7493
8231
|
manifestPresent: false,
|
|
@@ -7498,7 +8236,7 @@ function validateSnapshot(configInput) {
|
|
|
7498
8236
|
}
|
|
7499
8237
|
let manifest;
|
|
7500
8238
|
try {
|
|
7501
|
-
manifest = JSON.parse(
|
|
8239
|
+
manifest = JSON.parse(fs16__namespace.readFileSync(manifestPath, "utf8"));
|
|
7502
8240
|
} catch (err) {
|
|
7503
8241
|
return {
|
|
7504
8242
|
valid: false,
|
|
@@ -7520,7 +8258,7 @@ function validateSnapshot(configInput) {
|
|
|
7520
8258
|
}
|
|
7521
8259
|
const drift = emptyDrift();
|
|
7522
8260
|
const warnings = [];
|
|
7523
|
-
const snapshotDir =
|
|
8261
|
+
const snapshotDir = path17__namespace.resolve(config.cwd, config.outDir);
|
|
7524
8262
|
const unreadableSkips = manifest.skipped.filter(
|
|
7525
8263
|
(entry) => entry.reason === "missing" || entry.reason === "read-error"
|
|
7526
8264
|
);
|
|
@@ -7623,7 +8361,7 @@ function validateSnapshot(configInput) {
|
|
|
7623
8361
|
);
|
|
7624
8362
|
return importsChangedFile(
|
|
7625
8363
|
diskFile,
|
|
7626
|
-
importsOfFile(diskFile,
|
|
8364
|
+
importsOfFile(diskFile, path17__namespace.join(config.cwd, diskFile)),
|
|
7627
8365
|
unchangedScope,
|
|
7628
8366
|
dependentResolver
|
|
7629
8367
|
);
|
|
@@ -7641,7 +8379,7 @@ function validateSnapshot(configInput) {
|
|
|
7641
8379
|
// own output directory as a set of files missing from the snapshot, so a correct
|
|
7642
8380
|
// snapshot was reported as drifting.
|
|
7643
8381
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7644
|
-
(directory) =>
|
|
8382
|
+
(directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7645
8383
|
).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
|
|
7646
8384
|
});
|
|
7647
8385
|
for (const diskFile of collection.files) {
|
|
@@ -7667,7 +8405,7 @@ function validateSnapshot(configInput) {
|
|
|
7667
8405
|
}
|
|
7668
8406
|
let diskHash;
|
|
7669
8407
|
try {
|
|
7670
|
-
diskHash = sha256Hex(
|
|
8408
|
+
diskHash = sha256Hex(fs16__namespace.readFileSync(path17__namespace.join(config.cwd, diskFile)));
|
|
7671
8409
|
} catch (err) {
|
|
7672
8410
|
if (err.code === "ENOENT") {
|
|
7673
8411
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -7691,7 +8429,7 @@ function validateSnapshot(configInput) {
|
|
|
7691
8429
|
}
|
|
7692
8430
|
let statFailure = null;
|
|
7693
8431
|
try {
|
|
7694
|
-
|
|
8432
|
+
fs16__namespace.statSync(confined);
|
|
7695
8433
|
} catch (err) {
|
|
7696
8434
|
statFailure = err;
|
|
7697
8435
|
}
|
|
@@ -7711,7 +8449,7 @@ function validateSnapshot(configInput) {
|
|
|
7711
8449
|
...Object.values(config.budgets.byLayer)
|
|
7712
8450
|
);
|
|
7713
8451
|
const partNames = /* @__PURE__ */ new Set();
|
|
7714
|
-
const partsDir =
|
|
8452
|
+
const partsDir = path17__namespace.join(snapshotDir, "parts");
|
|
7715
8453
|
for (const part of manifest.parts) {
|
|
7716
8454
|
if (!part || typeof part.filename !== "string") continue;
|
|
7717
8455
|
partNames.add(part.filename);
|
|
@@ -7726,7 +8464,7 @@ function validateSnapshot(configInput) {
|
|
|
7726
8464
|
}
|
|
7727
8465
|
let buffer;
|
|
7728
8466
|
try {
|
|
7729
|
-
buffer =
|
|
8467
|
+
buffer = fs16__namespace.readFileSync(partPath);
|
|
7730
8468
|
} catch {
|
|
7731
8469
|
drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
|
|
7732
8470
|
continue;
|
|
@@ -8043,7 +8781,8 @@ function validateSnapshot(configInput) {
|
|
|
8043
8781
|
);
|
|
8044
8782
|
}
|
|
8045
8783
|
}
|
|
8046
|
-
|
|
8784
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
8785
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
8047
8786
|
totalsMismatches.push(
|
|
8048
8787
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
8049
8788
|
);
|
|
@@ -8072,6 +8811,7 @@ function validateSnapshot(configInput) {
|
|
|
8072
8811
|
}
|
|
8073
8812
|
const declaredArtifacts = [
|
|
8074
8813
|
["README.md", manifest.artifacts?.readme],
|
|
8814
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
8075
8815
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
8076
8816
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
8077
8817
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -8080,11 +8820,11 @@ function validateSnapshot(configInput) {
|
|
|
8080
8820
|
];
|
|
8081
8821
|
for (const [key, artifact] of declaredArtifacts) {
|
|
8082
8822
|
if (!artifact) continue;
|
|
8083
|
-
const artifactPath =
|
|
8823
|
+
const artifactPath = path17__namespace.join(snapshotDir, ...key.split("/"));
|
|
8084
8824
|
let buffer;
|
|
8085
8825
|
try {
|
|
8086
|
-
if (!
|
|
8087
|
-
buffer =
|
|
8826
|
+
if (!fs16__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
|
|
8827
|
+
buffer = fs16__namespace.readFileSync(artifactPath);
|
|
8088
8828
|
} catch {
|
|
8089
8829
|
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
8090
8830
|
continue;
|
|
@@ -8097,9 +8837,9 @@ function validateSnapshot(configInput) {
|
|
|
8097
8837
|
for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
8098
8838
|
const target = match[1].split("#")[0];
|
|
8099
8839
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
8100
|
-
const resolved =
|
|
8101
|
-
const relative11 =
|
|
8102
|
-
if (relative11.startsWith("..") ||
|
|
8840
|
+
const resolved = path17__namespace.resolve(snapshotDir, "reports", target);
|
|
8841
|
+
const relative11 = path17__namespace.relative(snapshotDir, resolved);
|
|
8842
|
+
if (relative11.startsWith("..") || path17__namespace.isAbsolute(relative11) || !fs16__namespace.existsSync(resolved)) {
|
|
8103
8843
|
drift.partIssues.push({
|
|
8104
8844
|
part: key,
|
|
8105
8845
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -8112,7 +8852,7 @@ function validateSnapshot(configInput) {
|
|
|
8112
8852
|
if (sarifArtifact) {
|
|
8113
8853
|
const sarifKey = "reports/audit.sarif";
|
|
8114
8854
|
try {
|
|
8115
|
-
const buffer =
|
|
8855
|
+
const buffer = fs16__namespace.readFileSync(path17__namespace.join(snapshotDir, "reports", "audit.sarif"));
|
|
8116
8856
|
if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
|
|
8117
8857
|
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
8118
8858
|
}
|
|
@@ -8230,17 +8970,17 @@ function isNewer(candidate, current) {
|
|
|
8230
8970
|
}
|
|
8231
8971
|
function cacheDirectory(env = process.env, platform = process.platform) {
|
|
8232
8972
|
if (platform === "win32") {
|
|
8233
|
-
const base2 = env.LOCALAPPDATA ??
|
|
8234
|
-
return
|
|
8973
|
+
const base2 = env.LOCALAPPDATA ?? path17__namespace.join(os__namespace.homedir(), "AppData", "Local");
|
|
8974
|
+
return path17__namespace.join(base2, "codebase-snapshot");
|
|
8235
8975
|
}
|
|
8236
8976
|
if (platform === "darwin") {
|
|
8237
|
-
return
|
|
8977
|
+
return path17__namespace.join(os__namespace.homedir(), "Library", "Caches", "codebase-snapshot");
|
|
8238
8978
|
}
|
|
8239
|
-
const base = env.XDG_CACHE_HOME ??
|
|
8240
|
-
return
|
|
8979
|
+
const base = env.XDG_CACHE_HOME ?? path17__namespace.join(os__namespace.homedir(), ".cache");
|
|
8980
|
+
return path17__namespace.join(base, "codebase-snapshot");
|
|
8241
8981
|
}
|
|
8242
8982
|
function cacheFilePath(env = process.env) {
|
|
8243
|
-
return
|
|
8983
|
+
return path17__namespace.join(cacheDirectory(env), "update-check.json");
|
|
8244
8984
|
}
|
|
8245
8985
|
function shouldCheck(argv, env) {
|
|
8246
8986
|
const disabled = ["1", "true", "yes"].includes(
|
|
@@ -8270,7 +9010,7 @@ function shouldCheck(argv, env) {
|
|
|
8270
9010
|
function readCache(file) {
|
|
8271
9011
|
let raw;
|
|
8272
9012
|
try {
|
|
8273
|
-
raw =
|
|
9013
|
+
raw = fs16__namespace.readFileSync(file, "utf8");
|
|
8274
9014
|
} catch {
|
|
8275
9015
|
return null;
|
|
8276
9016
|
}
|
|
@@ -8287,8 +9027,8 @@ function readCache(file) {
|
|
|
8287
9027
|
}
|
|
8288
9028
|
function writeCache(file, entry) {
|
|
8289
9029
|
try {
|
|
8290
|
-
|
|
8291
|
-
|
|
9030
|
+
fs16__namespace.mkdirSync(path17__namespace.dirname(file), { recursive: true });
|
|
9031
|
+
fs16__namespace.writeFileSync(file, `${JSON.stringify(entry)}
|
|
8292
9032
|
`, "utf8");
|
|
8293
9033
|
} catch {
|
|
8294
9034
|
}
|
|
@@ -8387,13 +9127,13 @@ function describeMatcher(matcher) {
|
|
|
8387
9127
|
return String(matcher);
|
|
8388
9128
|
}
|
|
8389
9129
|
function normalizeTarget(cwd, target) {
|
|
8390
|
-
const resolvedCwd =
|
|
8391
|
-
const absolute =
|
|
8392
|
-
const relative11 =
|
|
8393
|
-
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${
|
|
9130
|
+
const resolvedCwd = path17__namespace.resolve(cwd);
|
|
9131
|
+
const absolute = path17__namespace.resolve(resolvedCwd, target);
|
|
9132
|
+
const relative11 = path17__namespace.relative(resolvedCwd, absolute);
|
|
9133
|
+
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path17__namespace.sep}`) || path17__namespace.isAbsolute(relative11)) {
|
|
8394
9134
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
8395
9135
|
}
|
|
8396
|
-
return { relative: relative11.split(
|
|
9136
|
+
return { relative: relative11.split(path17__namespace.sep).join("/"), outsideRoot: false };
|
|
8397
9137
|
}
|
|
8398
9138
|
function findRuleMatch(rules, relativePath) {
|
|
8399
9139
|
return rules.find(
|
|
@@ -8412,9 +9152,9 @@ function findRecordedAncestor(skipped, relative11, maskedPath2) {
|
|
|
8412
9152
|
return nearest;
|
|
8413
9153
|
}
|
|
8414
9154
|
function readManifest2(config) {
|
|
8415
|
-
const manifestPath =
|
|
9155
|
+
const manifestPath = path17__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
8416
9156
|
try {
|
|
8417
|
-
return JSON.parse(
|
|
9157
|
+
return JSON.parse(fs16__namespace.readFileSync(manifestPath, "utf8"));
|
|
8418
9158
|
} catch {
|
|
8419
9159
|
return null;
|
|
8420
9160
|
}
|
|
@@ -8432,10 +9172,10 @@ function explainPath(config, target) {
|
|
|
8432
9172
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
8433
9173
|
};
|
|
8434
9174
|
}
|
|
8435
|
-
const absolute =
|
|
9175
|
+
const absolute = path17__namespace.join(config.cwd, relative11);
|
|
8436
9176
|
const result = {
|
|
8437
9177
|
path: maskedPath2,
|
|
8438
|
-
exists:
|
|
9178
|
+
exists: fs16__namespace.existsSync(absolute),
|
|
8439
9179
|
included: false
|
|
8440
9180
|
};
|
|
8441
9181
|
const collection = collectFiles(config.cwd, {
|
|
@@ -8449,7 +9189,7 @@ function explainPath(config, target) {
|
|
|
8449
9189
|
// Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
|
|
8450
9190
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
8451
9191
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
8452
|
-
(directory) =>
|
|
9192
|
+
(directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
8453
9193
|
).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
|
|
8454
9194
|
});
|
|
8455
9195
|
if (!collection.files.includes(relative11)) {
|
|
@@ -8514,7 +9254,7 @@ function explainPath(config, target) {
|
|
|
8514
9254
|
}
|
|
8515
9255
|
let sizeOnDisk = null;
|
|
8516
9256
|
try {
|
|
8517
|
-
sizeOnDisk =
|
|
9257
|
+
sizeOnDisk = fs16__namespace.statSync(absolute).size;
|
|
8518
9258
|
} catch {
|
|
8519
9259
|
sizeOnDisk = null;
|
|
8520
9260
|
}
|
|
@@ -8524,10 +9264,10 @@ function explainPath(config, target) {
|
|
|
8524
9264
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
8525
9265
|
return result;
|
|
8526
9266
|
}
|
|
8527
|
-
if (
|
|
9267
|
+
if (fs16__namespace.existsSync(absolute) && fs16__namespace.statSync(absolute).isFile()) {
|
|
8528
9268
|
let buffer;
|
|
8529
9269
|
try {
|
|
8530
|
-
buffer =
|
|
9270
|
+
buffer = fs16__namespace.readFileSync(absolute);
|
|
8531
9271
|
} catch (err) {
|
|
8532
9272
|
result.included = false;
|
|
8533
9273
|
result.reason = "read-error";
|
|
@@ -8817,14 +9557,14 @@ function compareManifests(before, after, secretRules) {
|
|
|
8817
9557
|
function loadManifest(target) {
|
|
8818
9558
|
let isDirectory;
|
|
8819
9559
|
try {
|
|
8820
|
-
isDirectory =
|
|
9560
|
+
isDirectory = fs16__namespace.statSync(target).isDirectory();
|
|
8821
9561
|
} catch {
|
|
8822
9562
|
throw new Error(`No snapshot found at ${target}: the path does not exist.`);
|
|
8823
9563
|
}
|
|
8824
|
-
const manifestPath = isDirectory ?
|
|
9564
|
+
const manifestPath = isDirectory ? path17__namespace.join(target, "manifest.json") : target;
|
|
8825
9565
|
let raw;
|
|
8826
9566
|
try {
|
|
8827
|
-
raw =
|
|
9567
|
+
raw = fs16__namespace.readFileSync(manifestPath, "utf8");
|
|
8828
9568
|
} catch {
|
|
8829
9569
|
throw new Error(`Could not read a manifest at ${manifestPath}.`);
|
|
8830
9570
|
}
|
|
@@ -8926,15 +9666,15 @@ function canonicalIgnorePattern(line) {
|
|
|
8926
9666
|
function appendGitignoreEntries(cwd, entries) {
|
|
8927
9667
|
const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
|
|
8928
9668
|
if (wanted.length === 0) return { added: [], note: null };
|
|
8929
|
-
const ignorePath =
|
|
9669
|
+
const ignorePath = path17__namespace.join(cwd, ".gitignore");
|
|
8930
9670
|
const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
|
|
8931
9671
|
let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
|
|
8932
9672
|
try {
|
|
8933
|
-
if (
|
|
8934
|
-
if (
|
|
9673
|
+
if (fs16__namespace.existsSync(ignorePath)) {
|
|
9674
|
+
if (fs16__namespace.statSync(ignorePath).isDirectory()) {
|
|
8935
9675
|
return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
|
|
8936
9676
|
}
|
|
8937
|
-
const read = decodeGitignore(
|
|
9677
|
+
const read = decodeGitignore(fs16__namespace.readFileSync(ignorePath));
|
|
8938
9678
|
if (read === null) {
|
|
8939
9679
|
return {
|
|
8940
9680
|
added: [],
|
|
@@ -8956,7 +9696,7 @@ function appendGitignoreEntries(cwd, entries) {
|
|
|
8956
9696
|
const newline = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
8957
9697
|
const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
|
|
8958
9698
|
try {
|
|
8959
|
-
|
|
9699
|
+
fs16__namespace.writeFileSync(
|
|
8960
9700
|
ignorePath,
|
|
8961
9701
|
encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
|
|
8962
9702
|
);
|
|
@@ -8966,7 +9706,7 @@ function appendGitignoreEntries(cwd, entries) {
|
|
|
8966
9706
|
return { added, note: null };
|
|
8967
9707
|
}
|
|
8968
9708
|
function gitignorePath(cwd, filePath) {
|
|
8969
|
-
return
|
|
9709
|
+
return path17__namespace.relative(cwd, filePath).split(path17__namespace.sep).join("/");
|
|
8970
9710
|
}
|
|
8971
9711
|
|
|
8972
9712
|
// src/wizard/config-template.ts
|
|
@@ -8984,6 +9724,7 @@ var DEFAULT_ANSWERS = {
|
|
|
8984
9724
|
excludePatterns: [],
|
|
8985
9725
|
artifacts: {
|
|
8986
9726
|
readme: true,
|
|
9727
|
+
prompt: true,
|
|
8987
9728
|
manifest: true,
|
|
8988
9729
|
parts: true,
|
|
8989
9730
|
navigation: true,
|
|
@@ -9100,6 +9841,7 @@ function renderConfig(answers) {
|
|
|
9100
9841
|
// \u2500\u2500 Artifacts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
9101
9842
|
artifacts: {
|
|
9102
9843
|
readme: ${artifacts.readme}, // README.md
|
|
9844
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
9103
9845
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
9104
9846
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
9105
9847
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -9115,6 +9857,15 @@ function renderConfig(answers) {
|
|
|
9115
9857
|
includeMonolith: ${artifacts.monolith},
|
|
9116
9858
|
|
|
9117
9859
|
// \u2500\u2500 Advanced \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
9860
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
9861
|
+
// attachmentSlots: 10,
|
|
9862
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
9863
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
9864
|
+
// maxParts: 10,
|
|
9865
|
+
// The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
|
|
9866
|
+
// brief: "docs/brief.md",
|
|
9867
|
+
// Which job the brief is written for: audit, review or explain.
|
|
9868
|
+
// promptTask: "audit",
|
|
9118
9869
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
9119
9870
|
hooks: {},
|
|
9120
9871
|
};
|
|
@@ -9509,7 +10260,7 @@ function parsePackageJson(raw) {
|
|
|
9509
10260
|
}
|
|
9510
10261
|
function readPackageJson(cwd) {
|
|
9511
10262
|
try {
|
|
9512
|
-
return parsePackageJson(
|
|
10263
|
+
return parsePackageJson(fs16__namespace.readFileSync(path17__namespace.join(cwd, "package.json"), "utf8"));
|
|
9513
10264
|
} catch {
|
|
9514
10265
|
return null;
|
|
9515
10266
|
}
|
|
@@ -9546,7 +10297,7 @@ function artifactAnswers(options) {
|
|
|
9546
10297
|
}
|
|
9547
10298
|
function topLevelDirs(cwd) {
|
|
9548
10299
|
try {
|
|
9549
|
-
return
|
|
10300
|
+
return fs16__namespace.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
|
|
9550
10301
|
} catch {
|
|
9551
10302
|
return [];
|
|
9552
10303
|
}
|
|
@@ -9561,7 +10312,7 @@ function writeFileOrExplain(target, content) {
|
|
|
9561
10312
|
try {
|
|
9562
10313
|
let stats = null;
|
|
9563
10314
|
try {
|
|
9564
|
-
stats =
|
|
10315
|
+
stats = fs16__namespace.lstatSync(target);
|
|
9565
10316
|
} catch {
|
|
9566
10317
|
stats = null;
|
|
9567
10318
|
}
|
|
@@ -9576,12 +10327,12 @@ function writeFileOrExplain(target, content) {
|
|
|
9576
10327
|
);
|
|
9577
10328
|
}
|
|
9578
10329
|
const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
9579
|
-
|
|
10330
|
+
fs16__namespace.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
|
|
9580
10331
|
try {
|
|
9581
|
-
|
|
10332
|
+
fs16__namespace.renameSync(temporary, target);
|
|
9582
10333
|
} catch (err) {
|
|
9583
10334
|
try {
|
|
9584
|
-
|
|
10335
|
+
fs16__namespace.unlinkSync(temporary);
|
|
9585
10336
|
} catch {
|
|
9586
10337
|
}
|
|
9587
10338
|
throw err;
|
|
@@ -9629,19 +10380,19 @@ function serializePackageJson(raw, value) {
|
|
|
9629
10380
|
return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
|
|
9630
10381
|
}
|
|
9631
10382
|
function updatePackageJson(cwd, notes) {
|
|
9632
|
-
const packagePath =
|
|
10383
|
+
const packagePath = path17__namespace.join(cwd, "package.json");
|
|
9633
10384
|
const unchanged = {
|
|
9634
10385
|
scripts: [],
|
|
9635
10386
|
dependency: { name: GENERATOR_NAME, range: null, added: false }
|
|
9636
10387
|
};
|
|
9637
|
-
if (!
|
|
10388
|
+
if (!fs16__namespace.existsSync(packagePath)) {
|
|
9638
10389
|
notes.push("No package.json found, so npm scripts and the devDependency were not added.");
|
|
9639
10390
|
return unchanged;
|
|
9640
10391
|
}
|
|
9641
10392
|
let raw;
|
|
9642
10393
|
let parsed;
|
|
9643
10394
|
try {
|
|
9644
|
-
raw =
|
|
10395
|
+
raw = fs16__namespace.readFileSync(packagePath, "utf8");
|
|
9645
10396
|
parsed = parsePackageJson(raw);
|
|
9646
10397
|
} catch {
|
|
9647
10398
|
notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
|
|
@@ -9716,8 +10467,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
|
9716
10467
|
const entries = [];
|
|
9717
10468
|
for (const directory of [outDir, tmpDir]) {
|
|
9718
10469
|
if (directory === null) continue;
|
|
9719
|
-
const relative11 =
|
|
9720
|
-
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") ||
|
|
10470
|
+
const relative11 = path17__namespace.relative(cwd, path17__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
10471
|
+
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path17__namespace.isAbsolute(relative11)) {
|
|
9721
10472
|
continue;
|
|
9722
10473
|
}
|
|
9723
10474
|
entries.push(`/${relative11}/`);
|
|
@@ -9805,6 +10556,7 @@ async function runInit(options) {
|
|
|
9805
10556
|
let lastScope = "all";
|
|
9806
10557
|
const artifactChoices = [
|
|
9807
10558
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
10559
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
9808
10560
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
9809
10561
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
9810
10562
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9968,7 +10720,7 @@ async function runInit(options) {
|
|
|
9968
10720
|
const configText = renderConfig(answers);
|
|
9969
10721
|
const preferredName = chooseConfigFileName(options.cwd);
|
|
9970
10722
|
const presentConfigs = CONFIG_CANDIDATES.filter(
|
|
9971
|
-
(name) =>
|
|
10723
|
+
(name) => fs16__namespace.existsSync(path17__namespace.join(options.cwd, name))
|
|
9972
10724
|
);
|
|
9973
10725
|
const present = presentConfigs[0] ?? null;
|
|
9974
10726
|
if (presentConfigs.length > 1) {
|
|
@@ -9977,7 +10729,7 @@ async function runInit(options) {
|
|
|
9977
10729
|
);
|
|
9978
10730
|
}
|
|
9979
10731
|
const configName = present !== null && options.force ? present : preferredName;
|
|
9980
|
-
const configPath =
|
|
10732
|
+
const configPath = path17__namespace.join(options.cwd, configName);
|
|
9981
10733
|
const reused = present !== null && options.force !== true && options.reuseConfig === true;
|
|
9982
10734
|
if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
|
|
9983
10735
|
if (options.dryRun) {
|
|
@@ -10011,7 +10763,7 @@ async function runInit(options) {
|
|
|
10011
10763
|
'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.'
|
|
10012
10764
|
);
|
|
10013
10765
|
}
|
|
10014
|
-
if (
|
|
10766
|
+
if (fs16__namespace.existsSync(configPath) && !options.force && !reused) {
|
|
10015
10767
|
throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
|
|
10016
10768
|
}
|
|
10017
10769
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
@@ -10037,9 +10789,9 @@ async function runInit(options) {
|
|
|
10037
10789
|
};
|
|
10038
10790
|
}
|
|
10039
10791
|
function describeTarget(cwd) {
|
|
10040
|
-
const relative11 =
|
|
10792
|
+
const relative11 = path17__namespace.relative(process.cwd(), cwd);
|
|
10041
10793
|
if (relative11 === "") return "this directory";
|
|
10042
|
-
if (relative11.startsWith("..") ||
|
|
10794
|
+
if (relative11.startsWith("..") || path17__namespace.isAbsolute(relative11)) return cwd;
|
|
10043
10795
|
return relative11;
|
|
10044
10796
|
}
|
|
10045
10797
|
function firstRunMessage(reason, cwd) {
|
|
@@ -10063,7 +10815,7 @@ function planFirstRun(facts) {
|
|
|
10063
10815
|
var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
|
|
10064
10816
|
function isEffectivelyEmpty(cwd) {
|
|
10065
10817
|
try {
|
|
10066
|
-
return
|
|
10818
|
+
return fs16__namespace.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
|
|
10067
10819
|
} catch {
|
|
10068
10820
|
return false;
|
|
10069
10821
|
}
|
|
@@ -10071,7 +10823,7 @@ function isEffectivelyEmpty(cwd) {
|
|
|
10071
10823
|
function hasPriorSnapshot(cwd, outDir) {
|
|
10072
10824
|
let parsed;
|
|
10073
10825
|
try {
|
|
10074
|
-
parsed = JSON.parse(
|
|
10826
|
+
parsed = JSON.parse(fs16__namespace.readFileSync(path17__namespace.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
|
|
10075
10827
|
} catch {
|
|
10076
10828
|
return false;
|
|
10077
10829
|
}
|
|
@@ -10119,36 +10871,36 @@ fi
|
|
|
10119
10871
|
`;
|
|
10120
10872
|
}
|
|
10121
10873
|
function gitDirectory(cwd) {
|
|
10122
|
-
const dotGit =
|
|
10874
|
+
const dotGit = path17__namespace.join(cwd, ".git");
|
|
10123
10875
|
let stats;
|
|
10124
10876
|
try {
|
|
10125
|
-
stats =
|
|
10877
|
+
stats = fs16__namespace.statSync(dotGit);
|
|
10126
10878
|
} catch {
|
|
10127
10879
|
return null;
|
|
10128
10880
|
}
|
|
10129
10881
|
if (stats.isDirectory()) return dotGit;
|
|
10130
10882
|
if (!stats.isFile()) return null;
|
|
10131
10883
|
try {
|
|
10132
|
-
const contents =
|
|
10884
|
+
const contents = fs16__namespace.readFileSync(dotGit, "utf8");
|
|
10133
10885
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
10134
10886
|
if (!match) return null;
|
|
10135
10887
|
const target = match[1];
|
|
10136
|
-
const resolved =
|
|
10137
|
-
if (!
|
|
10138
|
-
if (isInside2(
|
|
10139
|
-
return isRegisteredWorktree(
|
|
10888
|
+
const resolved = path17__namespace.isAbsolute(target.trim()) ? target.trim() : path17__namespace.join(cwd, target.trim());
|
|
10889
|
+
if (!fs16__namespace.statSync(resolved).isDirectory()) return null;
|
|
10890
|
+
if (isInside2(path17__namespace.resolve(cwd), path17__namespace.resolve(resolved))) return resolved;
|
|
10891
|
+
return isRegisteredWorktree(path17__namespace.resolve(resolved), cwd) ? resolved : null;
|
|
10140
10892
|
} catch {
|
|
10141
10893
|
return null;
|
|
10142
10894
|
}
|
|
10143
10895
|
}
|
|
10144
10896
|
function isInside2(parent, child) {
|
|
10145
|
-
const relative11 =
|
|
10146
|
-
return relative11 === "" || !relative11.startsWith("..") && !
|
|
10897
|
+
const relative11 = path17__namespace.relative(parent, child);
|
|
10898
|
+
return relative11 === "" || !relative11.startsWith("..") && !path17__namespace.isAbsolute(relative11);
|
|
10147
10899
|
}
|
|
10148
10900
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
10149
10901
|
try {
|
|
10150
|
-
const back =
|
|
10151
|
-
return
|
|
10902
|
+
const back = fs16__namespace.readFileSync(path17__namespace.join(gitDir, "gitdir"), "utf8").trim();
|
|
10903
|
+
return path17__namespace.resolve(gitDir, back) === path17__namespace.join(path17__namespace.resolve(cwd), ".git");
|
|
10152
10904
|
} catch {
|
|
10153
10905
|
return false;
|
|
10154
10906
|
}
|
|
@@ -10169,10 +10921,10 @@ function gitOutput(cwd, args) {
|
|
|
10169
10921
|
function configuredHooksDirectory(cwd) {
|
|
10170
10922
|
const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
|
|
10171
10923
|
if (hooks === null) return null;
|
|
10172
|
-
const resolved =
|
|
10924
|
+
const resolved = path17__namespace.resolve(cwd, hooks);
|
|
10173
10925
|
const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
|
|
10174
|
-
const commonDir = common === null ? null :
|
|
10175
|
-
if (isInside2(
|
|
10926
|
+
const commonDir = common === null ? null : path17__namespace.resolve(cwd, common);
|
|
10927
|
+
if (isInside2(path17__namespace.resolve(cwd), resolved)) return { dir: resolved };
|
|
10176
10928
|
if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
|
|
10177
10929
|
return {
|
|
10178
10930
|
refusal: `The hooks directory git reports (${resolved}) is outside this repository, so no hook was written. Add \`npx ${GENERATOR_NAME} validate\` to the hook manager that owns it instead.`
|
|
@@ -10193,10 +10945,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10193
10945
|
]
|
|
10194
10946
|
};
|
|
10195
10947
|
}
|
|
10196
|
-
const hooksDir = configured === null ?
|
|
10197
|
-
const hookPath =
|
|
10948
|
+
const hooksDir = configured === null ? path17__namespace.join(gitDir, "hooks") : configured.dir;
|
|
10949
|
+
const hookPath = path17__namespace.join(hooksDir, "pre-commit");
|
|
10198
10950
|
try {
|
|
10199
|
-
|
|
10951
|
+
fs16__namespace.mkdirSync(hooksDir, { recursive: true });
|
|
10200
10952
|
} catch (err) {
|
|
10201
10953
|
return {
|
|
10202
10954
|
path: hookPath,
|
|
@@ -10206,7 +10958,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10206
10958
|
}
|
|
10207
10959
|
let existing = null;
|
|
10208
10960
|
try {
|
|
10209
|
-
existing =
|
|
10961
|
+
existing = fs16__namespace.readFileSync(hookPath, "utf8");
|
|
10210
10962
|
} catch {
|
|
10211
10963
|
existing = null;
|
|
10212
10964
|
}
|
|
@@ -10221,8 +10973,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10221
10973
|
};
|
|
10222
10974
|
}
|
|
10223
10975
|
try {
|
|
10224
|
-
|
|
10225
|
-
|
|
10976
|
+
fs16__namespace.writeFileSync(hookPath, hookScript(outDir), "utf8");
|
|
10977
|
+
fs16__namespace.chmodSync(hookPath, 493);
|
|
10226
10978
|
} catch (err) {
|
|
10227
10979
|
return {
|
|
10228
10980
|
path: hookPath,
|
|
@@ -10239,7 +10991,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10239
10991
|
};
|
|
10240
10992
|
}
|
|
10241
10993
|
function workerEntry(directory, isCjs) {
|
|
10242
|
-
const entry =
|
|
10994
|
+
const entry = path17__namespace.join(directory, isCjs ? "index.cjs" : "index.js");
|
|
10243
10995
|
return { path: entry, url: url.pathToFileURL(entry).href };
|
|
10244
10996
|
}
|
|
10245
10997
|
|
|
@@ -10248,23 +11000,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
|
10248
11000
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
10249
11001
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
10250
11002
|
var fileDerivationBytes = 0;
|
|
10251
|
-
function takeDerivation(
|
|
10252
|
-
const cached = FILE_DERIVATIONS.get(
|
|
11003
|
+
function takeDerivation(path18, hash, settings) {
|
|
11004
|
+
const cached = FILE_DERIVATIONS.get(path18);
|
|
10253
11005
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
10254
|
-
FILE_DERIVATIONS.delete(
|
|
10255
|
-
FILE_DERIVATIONS.set(
|
|
11006
|
+
FILE_DERIVATIONS.delete(path18);
|
|
11007
|
+
FILE_DERIVATIONS.set(path18, cached);
|
|
10256
11008
|
return cached;
|
|
10257
11009
|
}
|
|
10258
|
-
function rememberDerivation(
|
|
11010
|
+
function rememberDerivation(path18, hash, settings, derivation) {
|
|
10259
11011
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
10260
11012
|
const bytes = bodyBytes * 2 + 512;
|
|
10261
11013
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
10262
|
-
const previous = FILE_DERIVATIONS.get(
|
|
11014
|
+
const previous = FILE_DERIVATIONS.get(path18);
|
|
10263
11015
|
if (previous !== void 0) {
|
|
10264
|
-
FILE_DERIVATIONS.delete(
|
|
11016
|
+
FILE_DERIVATIONS.delete(path18);
|
|
10265
11017
|
fileDerivationBytes -= previous.bytes;
|
|
10266
11018
|
} else {
|
|
10267
|
-
FILE_DERIVATIONS.delete(
|
|
11019
|
+
FILE_DERIVATIONS.delete(path18);
|
|
10268
11020
|
}
|
|
10269
11021
|
while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
|
|
10270
11022
|
const oldest = FILE_DERIVATIONS.keys().next();
|
|
@@ -10273,7 +11025,7 @@ function rememberDerivation(path17, hash, settings, derivation) {
|
|
|
10273
11025
|
FILE_DERIVATIONS.delete(oldest.value);
|
|
10274
11026
|
if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
|
|
10275
11027
|
}
|
|
10276
|
-
FILE_DERIVATIONS.set(
|
|
11028
|
+
FILE_DERIVATIONS.set(path18, { ...derivation, hash, settings, bytes });
|
|
10277
11029
|
fileDerivationBytes += bytes;
|
|
10278
11030
|
}
|
|
10279
11031
|
function derivationSettings(config) {
|
|
@@ -10524,11 +11276,11 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
10524
11276
|
return errors;
|
|
10525
11277
|
}
|
|
10526
11278
|
function resolveSafeOutputDirs(config) {
|
|
10527
|
-
const cwd =
|
|
10528
|
-
const outDir =
|
|
10529
|
-
const tmpDir =
|
|
10530
|
-
const root =
|
|
10531
|
-
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${
|
|
11279
|
+
const cwd = path17__namespace.resolve(config.cwd);
|
|
11280
|
+
const outDir = path17__namespace.resolve(cwd, config.outDir);
|
|
11281
|
+
const tmpDir = path17__namespace.resolve(cwd, config.tmpDir);
|
|
11282
|
+
const root = path17__namespace.parse(cwd).root;
|
|
11283
|
+
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17__namespace.sep}`);
|
|
10532
11284
|
const reject = (reason) => {
|
|
10533
11285
|
throw new Error(
|
|
10534
11286
|
`Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
|
|
@@ -10568,6 +11320,28 @@ function maskSummaryStrings(value, secretRules) {
|
|
|
10568
11320
|
function maskPathText(value, secretRules) {
|
|
10569
11321
|
return findSecretInPath(value, secretRules)?.masked ?? value;
|
|
10570
11322
|
}
|
|
11323
|
+
function maskOwnerBrief(brief, secretRules) {
|
|
11324
|
+
if (brief === void 0) return void 0;
|
|
11325
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11326
|
+
return {
|
|
11327
|
+
...brief,
|
|
11328
|
+
...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
|
|
11329
|
+
...brief.system === void 0 ? {} : { system: mask(brief.system) },
|
|
11330
|
+
...brief.history === void 0 ? {} : { history: mask(brief.history) },
|
|
11331
|
+
...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
|
|
11332
|
+
...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
|
|
11333
|
+
...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
|
|
11334
|
+
notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
|
|
11335
|
+
};
|
|
11336
|
+
}
|
|
11337
|
+
function maskOverview(overview, secretRules) {
|
|
11338
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11339
|
+
return {
|
|
11340
|
+
...overview.description === void 0 ? {} : { description: mask(overview.description) },
|
|
11341
|
+
...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
|
|
11342
|
+
releases: overview.releases.map(mask)
|
|
11343
|
+
};
|
|
11344
|
+
}
|
|
10571
11345
|
function maskSkipRecords(records, secretRules) {
|
|
10572
11346
|
return maskSkipPaths(records, secretRules);
|
|
10573
11347
|
}
|
|
@@ -10588,14 +11362,14 @@ function listEntries(dir) {
|
|
|
10588
11362
|
const walk = (absolute, prefix) => {
|
|
10589
11363
|
let children;
|
|
10590
11364
|
try {
|
|
10591
|
-
children =
|
|
11365
|
+
children = fs16__namespace.readdirSync(absolute, { withFileTypes: true });
|
|
10592
11366
|
} catch {
|
|
10593
11367
|
return;
|
|
10594
11368
|
}
|
|
10595
11369
|
for (const child of children) {
|
|
10596
11370
|
const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
10597
11371
|
entries.push(relative11);
|
|
10598
|
-
if (child.isDirectory()) walk(
|
|
11372
|
+
if (child.isDirectory()) walk(path17__namespace.join(absolute, child.name), relative11);
|
|
10599
11373
|
}
|
|
10600
11374
|
};
|
|
10601
11375
|
walk(dir, "");
|
|
@@ -10607,10 +11381,10 @@ function markerInventory(dir, written) {
|
|
|
10607
11381
|
for (const entry of entries) {
|
|
10608
11382
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10609
11383
|
if (isIgnorableEntry(entry)) continue;
|
|
10610
|
-
const full =
|
|
11384
|
+
const full = path17__namespace.join(dir, ...entry.split("/"));
|
|
10611
11385
|
let stats;
|
|
10612
11386
|
try {
|
|
10613
|
-
stats =
|
|
11387
|
+
stats = fs16__namespace.lstatSync(full);
|
|
10614
11388
|
} catch {
|
|
10615
11389
|
continue;
|
|
10616
11390
|
}
|
|
@@ -10622,7 +11396,7 @@ function markerInventory(dir, written) {
|
|
|
10622
11396
|
}
|
|
10623
11397
|
let digest;
|
|
10624
11398
|
try {
|
|
10625
|
-
digest = sha256Hex2(
|
|
11399
|
+
digest = sha256Hex2(fs16__namespace.readFileSync(full));
|
|
10626
11400
|
} catch {
|
|
10627
11401
|
continue;
|
|
10628
11402
|
}
|
|
@@ -10643,15 +11417,15 @@ function markerPayload(dir, state, id, createdAt, written) {
|
|
|
10643
11417
|
entries,
|
|
10644
11418
|
files
|
|
10645
11419
|
};
|
|
10646
|
-
const manifestPath =
|
|
10647
|
-
if (
|
|
10648
|
-
marker2.manifestSha256 = sha256Hex2(
|
|
11420
|
+
const manifestPath = path17__namespace.join(dir, "manifest.json");
|
|
11421
|
+
if (fs16__namespace.existsSync(manifestPath)) {
|
|
11422
|
+
marker2.manifestSha256 = sha256Hex2(fs16__namespace.readFileSync(manifestPath));
|
|
10649
11423
|
}
|
|
10650
11424
|
return marker2;
|
|
10651
11425
|
}
|
|
10652
11426
|
function writeOwnershipMarker(dir, marker2) {
|
|
10653
|
-
|
|
10654
|
-
|
|
11427
|
+
fs16__namespace.writeFileSync(
|
|
11428
|
+
path17__namespace.join(dir, OWNERSHIP_MARKER),
|
|
10655
11429
|
`${JSON.stringify(marker2, null, 2)}
|
|
10656
11430
|
`,
|
|
10657
11431
|
"utf8"
|
|
@@ -10663,13 +11437,13 @@ function markerBelongsTo(dir, id) {
|
|
|
10663
11437
|
return evidence.marker.id === id;
|
|
10664
11438
|
}
|
|
10665
11439
|
function readOwnershipMarker(dir) {
|
|
10666
|
-
const markerPath =
|
|
10667
|
-
if (!
|
|
11440
|
+
const markerPath = path17__namespace.join(dir, OWNERSHIP_MARKER);
|
|
11441
|
+
if (!fs16__namespace.existsSync(markerPath)) {
|
|
10668
11442
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
10669
11443
|
}
|
|
10670
11444
|
let raw;
|
|
10671
11445
|
try {
|
|
10672
|
-
raw =
|
|
11446
|
+
raw = fs16__namespace.readFileSync(markerPath, "utf8");
|
|
10673
11447
|
} catch {
|
|
10674
11448
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
10675
11449
|
}
|
|
@@ -10769,10 +11543,10 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10769
11543
|
for (const entry of entries) {
|
|
10770
11544
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10771
11545
|
if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
|
|
10772
|
-
const full =
|
|
11546
|
+
const full = path17__namespace.join(dir, ...entry.split("/"));
|
|
10773
11547
|
let stats;
|
|
10774
11548
|
try {
|
|
10775
|
-
stats =
|
|
11549
|
+
stats = fs16__namespace.lstatSync(full);
|
|
10776
11550
|
} catch {
|
|
10777
11551
|
return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
|
|
10778
11552
|
}
|
|
@@ -10797,7 +11571,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10797
11571
|
}
|
|
10798
11572
|
let digest;
|
|
10799
11573
|
try {
|
|
10800
|
-
digest = sha256Hex2(
|
|
11574
|
+
digest = sha256Hex2(fs16__namespace.readFileSync(full));
|
|
10801
11575
|
} catch {
|
|
10802
11576
|
return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
|
|
10803
11577
|
}
|
|
@@ -10818,12 +11592,12 @@ function assessSnapshotDirectory(dir) {
|
|
|
10818
11592
|
marker: marker2
|
|
10819
11593
|
};
|
|
10820
11594
|
}
|
|
10821
|
-
const manifestPath =
|
|
10822
|
-
const hasManifest =
|
|
11595
|
+
const manifestPath = path17__namespace.join(dir, "manifest.json");
|
|
11596
|
+
const hasManifest = fs16__namespace.existsSync(manifestPath);
|
|
10823
11597
|
if (hasManifest) {
|
|
10824
11598
|
let raw;
|
|
10825
11599
|
try {
|
|
10826
|
-
raw =
|
|
11600
|
+
raw = fs16__namespace.readFileSync(manifestPath, "utf8");
|
|
10827
11601
|
} catch {
|
|
10828
11602
|
return {
|
|
10829
11603
|
owned: false,
|
|
@@ -10918,13 +11692,13 @@ function containsNoFiles(dir) {
|
|
|
10918
11692
|
const current = pending.pop();
|
|
10919
11693
|
let entries;
|
|
10920
11694
|
try {
|
|
10921
|
-
entries =
|
|
11695
|
+
entries = fs16__namespace.readdirSync(current, { withFileTypes: true });
|
|
10922
11696
|
} catch {
|
|
10923
11697
|
return false;
|
|
10924
11698
|
}
|
|
10925
11699
|
for (const entry of entries) {
|
|
10926
11700
|
if (entry.isDirectory()) {
|
|
10927
|
-
pending.push(
|
|
11701
|
+
pending.push(path17__namespace.join(current, entry.name));
|
|
10928
11702
|
} else if (!IGNORABLE_ENTRIES.has(entry.name)) {
|
|
10929
11703
|
return false;
|
|
10930
11704
|
}
|
|
@@ -10933,13 +11707,13 @@ function containsNoFiles(dir) {
|
|
|
10933
11707
|
return true;
|
|
10934
11708
|
}
|
|
10935
11709
|
function assertReplaceable(target, label, secretRules) {
|
|
10936
|
-
if (!
|
|
10937
|
-
if (!
|
|
11710
|
+
if (!fs16__namespace.existsSync(target)) return;
|
|
11711
|
+
if (!fs16__namespace.statSync(target).isDirectory()) {
|
|
10938
11712
|
throw new Error(
|
|
10939
11713
|
`Refusing to write into ${label} ${target}: it exists but is not a directory.`
|
|
10940
11714
|
);
|
|
10941
11715
|
}
|
|
10942
|
-
const entries =
|
|
11716
|
+
const entries = fs16__namespace.readdirSync(target);
|
|
10943
11717
|
if (entries.length === 0) return;
|
|
10944
11718
|
if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
|
|
10945
11719
|
if (containsNoFiles(target)) return;
|
|
@@ -10959,18 +11733,18 @@ function assertReplaceable(target, label, secretRules) {
|
|
|
10959
11733
|
);
|
|
10960
11734
|
}
|
|
10961
11735
|
function assertStagingRootUsable(tmpDir, secretRules) {
|
|
10962
|
-
if (!
|
|
10963
|
-
if (!
|
|
11736
|
+
if (!fs16__namespace.existsSync(tmpDir)) return;
|
|
11737
|
+
if (!fs16__namespace.statSync(tmpDir).isDirectory()) {
|
|
10964
11738
|
throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
|
|
10965
11739
|
}
|
|
10966
|
-
const entries =
|
|
11740
|
+
const entries = fs16__namespace.readdirSync(tmpDir);
|
|
10967
11741
|
if (entries.length === 0) return;
|
|
10968
11742
|
const foreign = entries.filter((name) => {
|
|
10969
|
-
const full =
|
|
11743
|
+
const full = path17__namespace.join(tmpDir, name);
|
|
10970
11744
|
if (!name.startsWith(RUN_DIR_PREFIX)) return true;
|
|
10971
11745
|
let stats;
|
|
10972
11746
|
try {
|
|
10973
|
-
stats =
|
|
11747
|
+
stats = fs16__namespace.statSync(full);
|
|
10974
11748
|
} catch {
|
|
10975
11749
|
return true;
|
|
10976
11750
|
}
|
|
@@ -10978,7 +11752,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
10978
11752
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
10979
11753
|
if (marker2) return false;
|
|
10980
11754
|
try {
|
|
10981
|
-
return
|
|
11755
|
+
return fs16__namespace.readdirSync(full).length > 0;
|
|
10982
11756
|
} catch {
|
|
10983
11757
|
return true;
|
|
10984
11758
|
}
|
|
@@ -10993,13 +11767,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
10993
11767
|
function cleanStaleRunDirs(tmpDir) {
|
|
10994
11768
|
let entries;
|
|
10995
11769
|
try {
|
|
10996
|
-
entries =
|
|
11770
|
+
entries = fs16__namespace.readdirSync(tmpDir);
|
|
10997
11771
|
} catch {
|
|
10998
11772
|
return;
|
|
10999
11773
|
}
|
|
11000
11774
|
for (const name of entries) {
|
|
11001
11775
|
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
11002
|
-
const full =
|
|
11776
|
+
const full = path17__namespace.join(tmpDir, name);
|
|
11003
11777
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
11004
11778
|
if (marker2) {
|
|
11005
11779
|
const created = Date.parse(marker2.createdAt);
|
|
@@ -11007,33 +11781,33 @@ function cleanStaleRunDirs(tmpDir) {
|
|
|
11007
11781
|
const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
|
|
11008
11782
|
if (aged || abandoned) {
|
|
11009
11783
|
try {
|
|
11010
|
-
|
|
11784
|
+
fs16__namespace.rmSync(full, { recursive: true, force: true });
|
|
11011
11785
|
} catch {
|
|
11012
11786
|
}
|
|
11013
11787
|
}
|
|
11014
11788
|
continue;
|
|
11015
11789
|
}
|
|
11016
11790
|
try {
|
|
11017
|
-
if (
|
|
11791
|
+
if (fs16__namespace.readdirSync(full).length === 0) fs16__namespace.rmSync(full, { recursive: true, force: true });
|
|
11018
11792
|
} catch {
|
|
11019
11793
|
}
|
|
11020
11794
|
}
|
|
11021
11795
|
}
|
|
11022
11796
|
function removeIfEmpty(dir) {
|
|
11023
11797
|
try {
|
|
11024
|
-
if (
|
|
11798
|
+
if (fs16__namespace.readdirSync(dir).length === 0) fs16__namespace.rmSync(dir, { recursive: true, force: true });
|
|
11025
11799
|
} catch {
|
|
11026
11800
|
}
|
|
11027
11801
|
}
|
|
11028
11802
|
function ensureParentDirectory(target, label) {
|
|
11029
|
-
const parent =
|
|
11030
|
-
if (
|
|
11803
|
+
const parent = path17__namespace.dirname(target);
|
|
11804
|
+
if (fs16__namespace.existsSync(parent) && !fs16__namespace.statSync(parent).isDirectory()) {
|
|
11031
11805
|
throw new Error(
|
|
11032
11806
|
`Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
|
|
11033
11807
|
);
|
|
11034
11808
|
}
|
|
11035
11809
|
try {
|
|
11036
|
-
|
|
11810
|
+
fs16__namespace.mkdirSync(parent, { recursive: true });
|
|
11037
11811
|
} catch (err) {
|
|
11038
11812
|
throw new Error(
|
|
11039
11813
|
`Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
|
|
@@ -11091,17 +11865,17 @@ function acquireRunLock(stagingRoot) {
|
|
|
11091
11865
|
`;
|
|
11092
11866
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
11093
11867
|
try {
|
|
11094
|
-
const handle =
|
|
11868
|
+
const handle = fs16__namespace.openSync(lockPath, "wx");
|
|
11095
11869
|
try {
|
|
11096
|
-
|
|
11870
|
+
fs16__namespace.writeSync(handle, payload);
|
|
11097
11871
|
} finally {
|
|
11098
|
-
|
|
11872
|
+
fs16__namespace.closeSync(handle);
|
|
11099
11873
|
}
|
|
11100
11874
|
const stopHeartbeat = startLockHeartbeat(lockPath);
|
|
11101
11875
|
return () => {
|
|
11102
11876
|
stopHeartbeat();
|
|
11103
11877
|
try {
|
|
11104
|
-
|
|
11878
|
+
fs16__namespace.rmSync(lockPath, { force: true });
|
|
11105
11879
|
} catch {
|
|
11106
11880
|
}
|
|
11107
11881
|
};
|
|
@@ -11121,26 +11895,26 @@ function lockKeyFor(stagingRoot) {
|
|
|
11121
11895
|
return sha256Hex2(key).slice(0, 16);
|
|
11122
11896
|
}
|
|
11123
11897
|
function canonicalLockTarget(targetPath) {
|
|
11124
|
-
const resolved =
|
|
11898
|
+
const resolved = path17__namespace.resolve(targetPath);
|
|
11125
11899
|
let existing = resolved;
|
|
11126
11900
|
const tail = [];
|
|
11127
11901
|
for (; ; ) {
|
|
11128
11902
|
try {
|
|
11129
|
-
return
|
|
11903
|
+
return path17__namespace.join(fs16__namespace.realpathSync(existing), ...tail);
|
|
11130
11904
|
} catch {
|
|
11131
|
-
const parent =
|
|
11905
|
+
const parent = path17__namespace.dirname(existing);
|
|
11132
11906
|
if (parent === existing) return resolved;
|
|
11133
|
-
tail.unshift(
|
|
11907
|
+
tail.unshift(path17__namespace.basename(existing));
|
|
11134
11908
|
existing = parent;
|
|
11135
11909
|
}
|
|
11136
11910
|
}
|
|
11137
11911
|
}
|
|
11138
11912
|
function lockPathFor(stagingRoot) {
|
|
11139
|
-
return
|
|
11913
|
+
return path17__namespace.join(os__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
11140
11914
|
}
|
|
11141
11915
|
function lockHeartbeatAgeMs(lockPath) {
|
|
11142
11916
|
try {
|
|
11143
|
-
return Date.now() -
|
|
11917
|
+
return Date.now() - fs16__namespace.statSync(lockPath).mtimeMs;
|
|
11144
11918
|
} catch {
|
|
11145
11919
|
return Number.POSITIVE_INFINITY;
|
|
11146
11920
|
}
|
|
@@ -11148,7 +11922,7 @@ function lockHeartbeatAgeMs(lockPath) {
|
|
|
11148
11922
|
function lockOwnerIsGone(lockPath) {
|
|
11149
11923
|
let raw;
|
|
11150
11924
|
try {
|
|
11151
|
-
raw =
|
|
11925
|
+
raw = fs16__namespace.readFileSync(lockPath, "utf8");
|
|
11152
11926
|
} catch {
|
|
11153
11927
|
return false;
|
|
11154
11928
|
}
|
|
@@ -11170,16 +11944,16 @@ function lockOwnerIsGone(lockPath) {
|
|
|
11170
11944
|
function reclaimStaleLock(lockPath) {
|
|
11171
11945
|
let before;
|
|
11172
11946
|
try {
|
|
11173
|
-
before =
|
|
11947
|
+
before = fs16__namespace.statSync(lockPath);
|
|
11174
11948
|
} catch {
|
|
11175
11949
|
return true;
|
|
11176
11950
|
}
|
|
11177
11951
|
if (!lockOwnerIsGone(lockPath)) return false;
|
|
11178
11952
|
try {
|
|
11179
|
-
const current =
|
|
11953
|
+
const current = fs16__namespace.statSync(lockPath);
|
|
11180
11954
|
const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
|
|
11181
11955
|
if (!sameFile) return false;
|
|
11182
|
-
|
|
11956
|
+
fs16__namespace.rmSync(lockPath, { force: true });
|
|
11183
11957
|
return true;
|
|
11184
11958
|
} catch {
|
|
11185
11959
|
return false;
|
|
@@ -11190,12 +11964,12 @@ function lockFileIsAncient(lockPath) {
|
|
|
11190
11964
|
}
|
|
11191
11965
|
function writeManifestAtomically(manifestPath, manifest) {
|
|
11192
11966
|
const tempPath = `${manifestPath}.${process.pid}.tmp`;
|
|
11193
|
-
|
|
11967
|
+
fs16__namespace.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
|
|
11194
11968
|
try {
|
|
11195
|
-
|
|
11969
|
+
fs16__namespace.renameSync(tempPath, manifestPath);
|
|
11196
11970
|
} catch (err) {
|
|
11197
11971
|
try {
|
|
11198
|
-
|
|
11972
|
+
fs16__namespace.rmSync(tempPath, { force: true });
|
|
11199
11973
|
} catch {
|
|
11200
11974
|
}
|
|
11201
11975
|
throw err;
|
|
@@ -11220,21 +11994,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
|
|
|
11220
11994
|
}
|
|
11221
11995
|
}
|
|
11222
11996
|
function recoverInterruptedPublish(outDir) {
|
|
11223
|
-
if (
|
|
11224
|
-
const parent =
|
|
11225
|
-
const base =
|
|
11997
|
+
if (fs16__namespace.existsSync(outDir)) return;
|
|
11998
|
+
const parent = path17__namespace.dirname(outDir);
|
|
11999
|
+
const base = path17__namespace.basename(outDir);
|
|
11226
12000
|
let backups;
|
|
11227
12001
|
try {
|
|
11228
|
-
backups =
|
|
12002
|
+
backups = fs16__namespace.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
|
|
11229
12003
|
} catch {
|
|
11230
12004
|
return;
|
|
11231
12005
|
}
|
|
11232
12006
|
if (backups.length !== 1) return;
|
|
11233
|
-
const backupDir =
|
|
12007
|
+
const backupDir = path17__namespace.join(parent, backups[0]);
|
|
11234
12008
|
const { marker: marker2, problem } = readOwnershipMarker(backupDir);
|
|
11235
12009
|
if (problem !== null || marker2 === null || marker2.state !== "complete") return;
|
|
11236
12010
|
try {
|
|
11237
|
-
|
|
12011
|
+
fs16__namespace.renameSync(backupDir, outDir);
|
|
11238
12012
|
process.stderr.write(
|
|
11239
12013
|
`\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
|
|
11240
12014
|
`
|
|
@@ -11244,16 +12018,16 @@ function recoverInterruptedPublish(outDir) {
|
|
|
11244
12018
|
}
|
|
11245
12019
|
function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
11246
12020
|
const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
|
|
11247
|
-
const hadPrevious =
|
|
12021
|
+
const hadPrevious = fs16__namespace.existsSync(outDir);
|
|
11248
12022
|
if (hadPrevious) beforeSwap?.();
|
|
11249
12023
|
let movedAside = false;
|
|
11250
12024
|
if (hadPrevious) {
|
|
11251
12025
|
try {
|
|
11252
|
-
|
|
12026
|
+
fs16__namespace.renameSync(outDir, backupDir);
|
|
11253
12027
|
movedAside = true;
|
|
11254
12028
|
} catch (err) {
|
|
11255
12029
|
if (!isLockError(err)) throw err;
|
|
11256
|
-
|
|
12030
|
+
fs16__namespace.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
11257
12031
|
process.stderr.write(
|
|
11258
12032
|
`\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.
|
|
11259
12033
|
`
|
|
@@ -11262,26 +12036,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11262
12036
|
}
|
|
11263
12037
|
try {
|
|
11264
12038
|
try {
|
|
11265
|
-
|
|
12039
|
+
fs16__namespace.renameSync(stagingDir, outDir);
|
|
11266
12040
|
} catch (err) {
|
|
11267
12041
|
if (err.code !== "EXDEV") throw err;
|
|
11268
12042
|
const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
|
|
11269
12043
|
try {
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
12044
|
+
fs16__namespace.cpSync(stagingDir, partialDir, { recursive: true });
|
|
12045
|
+
fs16__namespace.renameSync(partialDir, outDir);
|
|
12046
|
+
fs16__namespace.rmSync(stagingDir, { recursive: true, force: true });
|
|
11273
12047
|
} catch (copyErr) {
|
|
11274
12048
|
try {
|
|
11275
|
-
|
|
12049
|
+
fs16__namespace.rmSync(partialDir, { recursive: true, force: true });
|
|
11276
12050
|
} catch {
|
|
11277
12051
|
}
|
|
11278
12052
|
throw copyErr;
|
|
11279
12053
|
}
|
|
11280
12054
|
}
|
|
11281
12055
|
} catch (err) {
|
|
11282
|
-
if (hadPrevious && movedAside &&
|
|
11283
|
-
if (
|
|
11284
|
-
|
|
12056
|
+
if (hadPrevious && movedAside && fs16__namespace.existsSync(backupDir)) {
|
|
12057
|
+
if (fs16__namespace.existsSync(outDir)) fs16__namespace.rmSync(outDir, { recursive: true, force: true });
|
|
12058
|
+
fs16__namespace.renameSync(backupDir, outDir);
|
|
11285
12059
|
} else if (hadPrevious && !movedAside) {
|
|
11286
12060
|
process.stderr.write(
|
|
11287
12061
|
`\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
|
|
@@ -11292,7 +12066,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11292
12066
|
}
|
|
11293
12067
|
if (hadPrevious) {
|
|
11294
12068
|
try {
|
|
11295
|
-
|
|
12069
|
+
fs16__namespace.rmSync(backupDir, { recursive: true, force: true });
|
|
11296
12070
|
} catch (err) {
|
|
11297
12071
|
process.stderr.write(
|
|
11298
12072
|
`\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.
|
|
@@ -11351,7 +12125,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11351
12125
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11352
12126
|
}
|
|
11353
12127
|
function partitionByBudget(files, config, fingerprint) {
|
|
11354
|
-
const
|
|
12128
|
+
const configured = {
|
|
12129
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
12130
|
+
budgets: config.budgets,
|
|
12131
|
+
maxPartBytes: config.maxPartBytes,
|
|
12132
|
+
warnings: []
|
|
12133
|
+
};
|
|
12134
|
+
const limit = config.maxParts;
|
|
12135
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
12136
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
12137
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
12138
|
+
const seen = [];
|
|
12139
|
+
let low = config.budgets.default;
|
|
12140
|
+
let fitting = null;
|
|
12141
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
12142
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
12143
|
+
if (parts2.length <= limit) {
|
|
12144
|
+
fitting = { target, parts: parts2 };
|
|
12145
|
+
break;
|
|
12146
|
+
}
|
|
12147
|
+
seen.push(parts2.length);
|
|
12148
|
+
low = target;
|
|
12149
|
+
target = Math.ceil(target * 1.3);
|
|
12150
|
+
}
|
|
12151
|
+
if (fitting === null) {
|
|
12152
|
+
throw new Error(
|
|
12153
|
+
`maxParts ${limit} could not be met: ${seen.join(", ")} part(s) at budgets up to ${formatNumber(target)} B. Raise maxParts, include fewer files, or drop the setting.`
|
|
12154
|
+
);
|
|
12155
|
+
}
|
|
12156
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
12157
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
12158
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
12159
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
12160
|
+
else low = middle;
|
|
12161
|
+
}
|
|
12162
|
+
const { target: chosen, parts } = fitting;
|
|
12163
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
12164
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
12165
|
+
const warnings = [
|
|
12166
|
+
`maxParts ${limit}: the part budget grew from ${formatNumber(config.maxPartBytes)} B to ${formatNumber(maxPartBytes)} B, and the snapshot now has ${formatNumber(parts.length)} part(s).`
|
|
12167
|
+
];
|
|
12168
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
12169
|
+
warnings.push(
|
|
12170
|
+
`maxParts ${limit}: parts are now above the configured maxPartBytes (${formatNumber(config.maxPartBytes)} B). A larger part is more tokens for the destination to take at once, and some destinations cap a single file.`
|
|
12171
|
+
);
|
|
12172
|
+
}
|
|
12173
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
12174
|
+
}
|
|
12175
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
12176
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11355
12177
|
const buckets = /* @__PURE__ */ new Map();
|
|
11356
12178
|
for (const file of files) {
|
|
11357
12179
|
const budget = budgetFor(file);
|
|
@@ -11368,6 +12190,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11368
12190
|
fingerprint
|
|
11369
12191
|
);
|
|
11370
12192
|
}
|
|
12193
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
12194
|
+
const factor = targetDefault / budgets.default;
|
|
12195
|
+
return {
|
|
12196
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
12197
|
+
byLayer: Object.fromEntries(
|
|
12198
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
12199
|
+
name,
|
|
12200
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12201
|
+
])
|
|
12202
|
+
)
|
|
12203
|
+
};
|
|
12204
|
+
}
|
|
11371
12205
|
function generateSnapshot(configInput, options) {
|
|
11372
12206
|
assertUsableConfigInput(configInput);
|
|
11373
12207
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11390,7 +12224,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11390
12224
|
// first run cannot have marked them yet, so the name alone keeps a run from recording its own
|
|
11391
12225
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11392
12226
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11393
|
-
(directory) =>
|
|
12227
|
+
(directory) => path17__namespace.relative(config.cwd, path17__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11394
12228
|
).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
|
|
11395
12229
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11396
12230
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
@@ -11419,7 +12253,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11419
12253
|
let totalSizeBytes = 0;
|
|
11420
12254
|
let largeFileCount = 0;
|
|
11421
12255
|
for (const relativePath of candidateFiles) {
|
|
11422
|
-
const absolutePath =
|
|
12256
|
+
const absolutePath = path17__namespace.join(config.cwd, relativePath);
|
|
11423
12257
|
const fromIndex = stagedPaths.has(relativePath);
|
|
11424
12258
|
let buffer;
|
|
11425
12259
|
let sizeBytes;
|
|
@@ -11450,9 +12284,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11450
12284
|
} else {
|
|
11451
12285
|
let stats;
|
|
11452
12286
|
try {
|
|
11453
|
-
stats =
|
|
12287
|
+
stats = fs16__namespace.statSync(absolutePath);
|
|
11454
12288
|
if (!stats.isFile()) {
|
|
11455
|
-
const nestedRepository = stats.isDirectory() &&
|
|
12289
|
+
const nestedRepository = stats.isDirectory() && fs16__namespace.existsSync(path17__namespace.join(absolutePath, ".git"));
|
|
11456
12290
|
skipped.push(
|
|
11457
12291
|
nestedRepository ? {
|
|
11458
12292
|
path: relativePath,
|
|
@@ -11488,7 +12322,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11488
12322
|
continue;
|
|
11489
12323
|
}
|
|
11490
12324
|
try {
|
|
11491
|
-
buffer =
|
|
12325
|
+
buffer = fs16__namespace.readFileSync(absolutePath);
|
|
11492
12326
|
} catch (err) {
|
|
11493
12327
|
const code = err.code;
|
|
11494
12328
|
skipped.push({
|
|
@@ -11617,14 +12451,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11617
12451
|
(finding) => finding.path === void 0 || keep.has(finding.path)
|
|
11618
12452
|
);
|
|
11619
12453
|
retain(encodingNotes, (note) => keep.has(note.path));
|
|
11620
|
-
retain(oversizeSummaryPaths, (
|
|
11621
|
-
retain(previewSummaryPaths, (
|
|
12454
|
+
retain(oversizeSummaryPaths, (path18) => keep.has(path18));
|
|
12455
|
+
retain(previewSummaryPaths, (path18) => keep.has(path18));
|
|
11622
12456
|
retain(fileWarnings, (warning) => keep.has(warning.path));
|
|
11623
|
-
for (const
|
|
11624
|
-
if (!keep.has(
|
|
12457
|
+
for (const path18 of [...monolithBodies.keys()]) {
|
|
12458
|
+
if (!keep.has(path18)) monolithBodies.delete(path18);
|
|
11625
12459
|
}
|
|
11626
|
-
for (const
|
|
11627
|
-
if (!keep.has(
|
|
12460
|
+
for (const path18 of [...skippedSummaryImports.keys()]) {
|
|
12461
|
+
if (!keep.has(path18)) skippedSummaryImports.delete(path18);
|
|
11628
12462
|
}
|
|
11629
12463
|
}
|
|
11630
12464
|
if (changedScope !== null) {
|
|
@@ -11696,7 +12530,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11696
12530
|
);
|
|
11697
12531
|
}
|
|
11698
12532
|
}
|
|
11699
|
-
const
|
|
12533
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12534
|
+
const parts = partitioned.parts;
|
|
11700
12535
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11701
12536
|
const incomplete = files.flatMap((file) => {
|
|
11702
12537
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11733,7 +12568,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11733
12568
|
// the README and the audit report.
|
|
11734
12569
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11735
12570
|
budgets: {
|
|
11736
|
-
|
|
12571
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12572
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12573
|
+
// `validate` compares against the config on disk.
|
|
12574
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11737
12575
|
largeFileBytes: config.largeFileBytes
|
|
11738
12576
|
},
|
|
11739
12577
|
config: {
|
|
@@ -11751,6 +12589,16 @@ function generateSnapshot(configInput, options) {
|
|
|
11751
12589
|
// invisible in the manifest that is supposed to describe the run.
|
|
11752
12590
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11753
12591
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12592
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12593
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12594
|
+
// snapshot fail `validate` as configuration drift.
|
|
12595
|
+
attachmentSlots: config.attachmentSlots,
|
|
12596
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12597
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12598
|
+
// configuration drift.
|
|
12599
|
+
maxParts: config.maxParts ?? null,
|
|
12600
|
+
promptTask: config.promptTask,
|
|
12601
|
+
...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
|
|
11754
12602
|
discovery: config.discovery ?? "auto",
|
|
11755
12603
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11756
12604
|
// describes the run has to name it.
|
|
@@ -11821,6 +12669,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11821
12669
|
incomplete,
|
|
11822
12670
|
warnings
|
|
11823
12671
|
};
|
|
12672
|
+
if (partitioned.warnings.length > 0) {
|
|
12673
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12674
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12675
|
+
}
|
|
11824
12676
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11825
12677
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11826
12678
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11877,6 +12729,17 @@ function generateSnapshot(configInput, options) {
|
|
|
11877
12729
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11878
12730
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11879
12731
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12732
|
+
const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
|
|
12733
|
+
slots: config.attachmentSlots,
|
|
12734
|
+
task: config.promptTask,
|
|
12735
|
+
brief: maskOwnerBrief(config.brief, config.secretRules),
|
|
12736
|
+
history: recentCommits(config.cwd).map((commit) => ({
|
|
12737
|
+
subject: maskPathText(commit.subject, config.secretRules),
|
|
12738
|
+
body: maskPathText(commit.body, config.secretRules)
|
|
12739
|
+
})),
|
|
12740
|
+
overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
|
|
12741
|
+
}) : null;
|
|
12742
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11880
12743
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11881
12744
|
let monolithJson = null;
|
|
11882
12745
|
let monolithMarkdown = null;
|
|
@@ -11951,12 +12814,12 @@ function generateSnapshot(configInput, options) {
|
|
|
11951
12814
|
let releaseDeferred = false;
|
|
11952
12815
|
try {
|
|
11953
12816
|
ensureParentDirectory(outDir, "outDir");
|
|
11954
|
-
|
|
12817
|
+
fs16__namespace.mkdirSync(tmpDir, { recursive: true });
|
|
11955
12818
|
cleanStaleRunDirs(tmpDir);
|
|
11956
12819
|
const snapshotId = crypto2__namespace.randomUUID();
|
|
11957
12820
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11958
|
-
stagingDir =
|
|
11959
|
-
|
|
12821
|
+
stagingDir = path17__namespace.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
|
|
12822
|
+
fs16__namespace.mkdirSync(stagingDir);
|
|
11960
12823
|
writeOwnershipMarker(stagingDir, {
|
|
11961
12824
|
generator: GENERATOR_NAME,
|
|
11962
12825
|
version: GENERATOR_VERSION,
|
|
@@ -11966,30 +12829,30 @@ function generateSnapshot(configInput, options) {
|
|
|
11966
12829
|
id: snapshotId,
|
|
11967
12830
|
pid: process.pid
|
|
11968
12831
|
});
|
|
11969
|
-
const partsDir =
|
|
11970
|
-
const reportsDir =
|
|
11971
|
-
if (artifacts.parts)
|
|
12832
|
+
const partsDir = path17__namespace.join(stagingDir, "parts");
|
|
12833
|
+
const reportsDir = path17__namespace.join(stagingDir, "reports");
|
|
12834
|
+
if (artifacts.parts) fs16__namespace.mkdirSync(partsDir, { recursive: true });
|
|
11972
12835
|
if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
|
|
11973
|
-
|
|
12836
|
+
fs16__namespace.mkdirSync(reportsDir, { recursive: true });
|
|
11974
12837
|
}
|
|
11975
12838
|
const writtenArtifacts = /* @__PURE__ */ new Map();
|
|
11976
12839
|
const writeArtifact = (targetDir, relativeEntry, data) => {
|
|
11977
|
-
const full =
|
|
11978
|
-
|
|
11979
|
-
const stats =
|
|
12840
|
+
const full = path17__namespace.join(targetDir, ...relativeEntry.split("/"));
|
|
12841
|
+
fs16__namespace.writeFileSync(full, data, "utf8");
|
|
12842
|
+
const stats = fs16__namespace.statSync(full);
|
|
11980
12843
|
writtenArtifacts.set(relativeEntry, {
|
|
11981
12844
|
digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
|
|
11982
12845
|
mtimeMs: stats.mtimeMs
|
|
11983
12846
|
});
|
|
11984
12847
|
};
|
|
11985
12848
|
const recordArtifact = (targetDir, relativeEntry) => {
|
|
11986
|
-
const full =
|
|
11987
|
-
const stats =
|
|
12849
|
+
const full = path17__namespace.join(targetDir, ...relativeEntry.split("/"));
|
|
12850
|
+
const stats = fs16__namespace.statSync(full);
|
|
11988
12851
|
writtenArtifacts.set(relativeEntry, {
|
|
11989
12852
|
digest: {
|
|
11990
12853
|
path: relativeEntry,
|
|
11991
12854
|
bytes: stats.size,
|
|
11992
|
-
sha256: sha256Hex2(
|
|
12855
|
+
sha256: sha256Hex2(fs16__namespace.readFileSync(full))
|
|
11993
12856
|
},
|
|
11994
12857
|
mtimeMs: stats.mtimeMs
|
|
11995
12858
|
});
|
|
@@ -12014,6 +12877,9 @@ function generateSnapshot(configInput, options) {
|
|
|
12014
12877
|
if (readmeText !== null) {
|
|
12015
12878
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
12016
12879
|
}
|
|
12880
|
+
if (promptText !== null) {
|
|
12881
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12882
|
+
}
|
|
12017
12883
|
if (artifacts.manifest) {
|
|
12018
12884
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
12019
12885
|
}
|
|
@@ -12034,7 +12900,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12034
12900
|
const shipHookState = () => {
|
|
12035
12901
|
if (!markerBelongsTo(outDir, snapshotId)) return;
|
|
12036
12902
|
if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
|
|
12037
|
-
writeManifestAtomically(
|
|
12903
|
+
writeManifestAtomically(path17__namespace.join(outDir, "manifest.json"), manifest);
|
|
12038
12904
|
recordArtifact(outDir, "manifest.json");
|
|
12039
12905
|
}
|
|
12040
12906
|
writeOwnershipMarker(
|
|
@@ -12077,7 +12943,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12077
12943
|
} catch (err) {
|
|
12078
12944
|
if (stagingDir !== null) {
|
|
12079
12945
|
try {
|
|
12080
|
-
|
|
12946
|
+
fs16__namespace.rmSync(stagingDir, { recursive: true, force: true });
|
|
12081
12947
|
} catch {
|
|
12082
12948
|
}
|
|
12083
12949
|
}
|