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
|
@@ -2,9 +2,9 @@ import * as crypto2 from 'crypto';
|
|
|
2
2
|
import { createHash } from 'crypto';
|
|
3
3
|
import { Worker } from 'worker_threads';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
|
-
import * as
|
|
5
|
+
import * as fs16 from 'fs';
|
|
6
6
|
import * as os from 'os';
|
|
7
|
-
import * as
|
|
7
|
+
import * as path17 from 'path';
|
|
8
8
|
import ts from 'typescript';
|
|
9
9
|
import { createRequire } from 'module';
|
|
10
10
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
@@ -395,9 +395,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
395
395
|
var jvmProfile = {
|
|
396
396
|
id: "jvm",
|
|
397
397
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
398
|
-
summarize(
|
|
398
|
+
summarize(path18, content) {
|
|
399
399
|
const summary = emptySummary();
|
|
400
|
-
const lower =
|
|
400
|
+
const lower = path18.toLowerCase();
|
|
401
401
|
const isJava = lower.endsWith(".java");
|
|
402
402
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
403
403
|
eachLine(content, (line) => {
|
|
@@ -1005,17 +1005,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
1005
1005
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
1006
1006
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
1007
1007
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
1008
|
-
function componentName(
|
|
1009
|
-
const base =
|
|
1008
|
+
function componentName(path18) {
|
|
1009
|
+
const base = path18.split("/").pop() ?? path18;
|
|
1010
1010
|
return base.replace(/\.[^.]+$/, "");
|
|
1011
1011
|
}
|
|
1012
1012
|
var sfcProfile = {
|
|
1013
1013
|
id: "sfc",
|
|
1014
1014
|
extensions: [".vue", ".svelte", ".astro"],
|
|
1015
|
-
summarize(
|
|
1015
|
+
summarize(path18, content) {
|
|
1016
1016
|
let script = "";
|
|
1017
|
-
let usesJsx =
|
|
1018
|
-
if (
|
|
1017
|
+
let usesJsx = path18.toLowerCase().endsWith(".astro");
|
|
1018
|
+
if (path18.toLowerCase().endsWith(".astro")) {
|
|
1019
1019
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
1020
1020
|
if (frontmatter) script += `${frontmatter[1]}
|
|
1021
1021
|
`;
|
|
@@ -1025,7 +1025,7 @@ var sfcProfile = {
|
|
|
1025
1025
|
script += `${match[2]}
|
|
1026
1026
|
`;
|
|
1027
1027
|
}
|
|
1028
|
-
const name = componentName(
|
|
1028
|
+
const name = componentName(path18);
|
|
1029
1029
|
if (!script.trim()) {
|
|
1030
1030
|
const summary2 = emptySummary();
|
|
1031
1031
|
if (name) {
|
|
@@ -1216,15 +1216,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
1216
1216
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
1217
1217
|
}
|
|
1218
1218
|
}
|
|
1219
|
-
function profileForPath(
|
|
1220
|
-
const lower =
|
|
1219
|
+
function profileForPath(path18) {
|
|
1220
|
+
const lower = path18.toLowerCase();
|
|
1221
1221
|
const dot = lower.lastIndexOf(".");
|
|
1222
1222
|
if (dot === -1) return null;
|
|
1223
1223
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
1224
1224
|
}
|
|
1225
|
-
function summarizeWithProfile(
|
|
1226
|
-
const profile = profileForPath(
|
|
1227
|
-
return profile ? profile.summarize(
|
|
1225
|
+
function summarizeWithProfile(path18, content) {
|
|
1226
|
+
const profile = profileForPath(path18);
|
|
1227
|
+
return profile ? profile.summarize(path18, content) : null;
|
|
1228
1228
|
}
|
|
1229
1229
|
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1230
1230
|
".png",
|
|
@@ -1269,7 +1269,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
1269
1269
|
".so"
|
|
1270
1270
|
]);
|
|
1271
1271
|
function isBinaryExtension(filePath) {
|
|
1272
|
-
const ext =
|
|
1272
|
+
const ext = path17.extname(filePath).toLowerCase();
|
|
1273
1273
|
return BINARY_EXTENSIONS.has(ext);
|
|
1274
1274
|
}
|
|
1275
1275
|
function isBinaryBuffer(buffer) {
|
|
@@ -1439,13 +1439,13 @@ function isBinaryFile(absolutePath) {
|
|
|
1439
1439
|
if (isBinaryExtension(absolutePath)) return true;
|
|
1440
1440
|
let fd;
|
|
1441
1441
|
try {
|
|
1442
|
-
fd =
|
|
1442
|
+
fd = fs16.openSync(absolutePath, "r");
|
|
1443
1443
|
const buffer = Buffer.alloc(CHUNK);
|
|
1444
1444
|
let sample;
|
|
1445
1445
|
let position = 0;
|
|
1446
1446
|
while (position < BINARY_SCAN_BYTES) {
|
|
1447
1447
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
1448
|
-
const bytesRead =
|
|
1448
|
+
const bytesRead = fs16.readSync(fd, buffer, 0, wanted, position);
|
|
1449
1449
|
if (bytesRead === 0) return false;
|
|
1450
1450
|
const chunk = buffer.subarray(0, bytesRead);
|
|
1451
1451
|
if (sample === void 0) {
|
|
@@ -1463,7 +1463,7 @@ function isBinaryFile(absolutePath) {
|
|
|
1463
1463
|
} finally {
|
|
1464
1464
|
if (fd !== void 0) {
|
|
1465
1465
|
try {
|
|
1466
|
-
|
|
1466
|
+
fs16.closeSync(fd);
|
|
1467
1467
|
} catch {
|
|
1468
1468
|
}
|
|
1469
1469
|
}
|
|
@@ -1485,9 +1485,9 @@ function importsOfText(relativePath, text2) {
|
|
|
1485
1485
|
function importsOfFile(relativePath, absolutePath) {
|
|
1486
1486
|
let buffer;
|
|
1487
1487
|
try {
|
|
1488
|
-
const stats =
|
|
1488
|
+
const stats = fs16.statSync(absolutePath);
|
|
1489
1489
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
1490
|
-
buffer =
|
|
1490
|
+
buffer = fs16.readFileSync(absolutePath);
|
|
1491
1491
|
} catch {
|
|
1492
1492
|
return [];
|
|
1493
1493
|
}
|
|
@@ -1733,6 +1733,77 @@ function isSkeletonizable(filePath) {
|
|
|
1733
1733
|
}
|
|
1734
1734
|
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");
|
|
1735
1735
|
}
|
|
1736
|
+
var OWNER_SECTIONS = ["Stakes", "The system", "What came before", "The bar", "Calibration"];
|
|
1737
|
+
var RESERVED_SECTIONS = [
|
|
1738
|
+
"The job",
|
|
1739
|
+
"What you have",
|
|
1740
|
+
"Coverage",
|
|
1741
|
+
"What a useful answer contains",
|
|
1742
|
+
"This snapshot",
|
|
1743
|
+
"Attaching this",
|
|
1744
|
+
"Your task"
|
|
1745
|
+
];
|
|
1746
|
+
function parseOwnerBrief(filePath, text2) {
|
|
1747
|
+
const problems = [];
|
|
1748
|
+
const source = text2.replace(/^\uFEFF/, "");
|
|
1749
|
+
const preamble = [];
|
|
1750
|
+
const sections = [];
|
|
1751
|
+
let current = null;
|
|
1752
|
+
for (const line of source.split(/\r?\n/)) {
|
|
1753
|
+
const heading = /^##\s+(.+?)\s*$/.exec(line);
|
|
1754
|
+
if (heading) {
|
|
1755
|
+
current = { heading: heading[1], body: [] };
|
|
1756
|
+
sections.push(current);
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
if (current) current.body.push(line);
|
|
1760
|
+
else preamble.push(line);
|
|
1761
|
+
}
|
|
1762
|
+
const recognised = {};
|
|
1763
|
+
const notes = [];
|
|
1764
|
+
const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
|
|
1765
|
+
const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
|
|
1766
|
+
const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
|
|
1767
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1768
|
+
for (const section of sections) {
|
|
1769
|
+
const body = section.body.join("\n").trim();
|
|
1770
|
+
const key = canonical(section.heading);
|
|
1771
|
+
if (seen.has(key)) {
|
|
1772
|
+
problems.push(
|
|
1773
|
+
`the brief defines "${section.heading}" twice; a section cannot say two things.`
|
|
1774
|
+
);
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
seen.add(key);
|
|
1778
|
+
if (canonicalReserved.has(key)) {
|
|
1779
|
+
problems.push(
|
|
1780
|
+
`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.`
|
|
1781
|
+
);
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
const ownerName = canonicalOwner.get(key);
|
|
1785
|
+
if (ownerName !== void 0) {
|
|
1786
|
+
recognised[ownerName] = body;
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
notes.push({ heading: section.heading, body });
|
|
1790
|
+
}
|
|
1791
|
+
const preambleText = preamble.join("\n").trim();
|
|
1792
|
+
return {
|
|
1793
|
+
brief: {
|
|
1794
|
+
path: filePath,
|
|
1795
|
+
digest: createHash("sha256").update(text2, "utf8").digest("hex"),
|
|
1796
|
+
...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
|
|
1797
|
+
...recognised["The system"] ? { system: recognised["The system"] } : {},
|
|
1798
|
+
...recognised["What came before"] ? { history: recognised["What came before"] } : {},
|
|
1799
|
+
...recognised["The bar"] ? { bar: recognised["The bar"] } : {},
|
|
1800
|
+
...recognised["Calibration"] ? { calibration: recognised["Calibration"] } : {},
|
|
1801
|
+
notes,
|
|
1802
|
+
...preambleText.length > 0 ? { preamble: preambleText } : {}
|
|
1803
|
+
},
|
|
1804
|
+
problems
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1736
1807
|
var MANIFEST_FILES = [
|
|
1737
1808
|
"package.json",
|
|
1738
1809
|
"pyproject.toml",
|
|
@@ -1779,15 +1850,15 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
1779
1850
|
]);
|
|
1780
1851
|
function readSmallFile(fullPath) {
|
|
1781
1852
|
try {
|
|
1782
|
-
const stats =
|
|
1853
|
+
const stats = fs16.statSync(fullPath);
|
|
1783
1854
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
1784
|
-
return
|
|
1855
|
+
return fs16.readFileSync(fullPath, "utf8");
|
|
1785
1856
|
} catch {
|
|
1786
1857
|
return null;
|
|
1787
1858
|
}
|
|
1788
1859
|
}
|
|
1789
1860
|
function readManifest(cwd, name) {
|
|
1790
|
-
return readSmallFile(
|
|
1861
|
+
return readSmallFile(path17.join(cwd, name));
|
|
1791
1862
|
}
|
|
1792
1863
|
function dependenciesFromPackageJson(raw) {
|
|
1793
1864
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -1847,7 +1918,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
1847
1918
|
function childDirectories(cwd, parent) {
|
|
1848
1919
|
let entries;
|
|
1849
1920
|
try {
|
|
1850
|
-
entries =
|
|
1921
|
+
entries = fs16.readdirSync(path17.join(cwd, parent), { withFileTypes: true });
|
|
1851
1922
|
} catch {
|
|
1852
1923
|
return [];
|
|
1853
1924
|
}
|
|
@@ -1883,12 +1954,12 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
1883
1954
|
const files = /* @__PURE__ */ new Set();
|
|
1884
1955
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1885
1956
|
for (const relative11 of workspacePackageDirs(cwd, patterns)) {
|
|
1886
|
-
const full =
|
|
1957
|
+
const full = path17.join(cwd, relative11);
|
|
1887
1958
|
try {
|
|
1888
|
-
for (const entry of
|
|
1959
|
+
for (const entry of fs16.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
1889
1960
|
} catch {
|
|
1890
1961
|
}
|
|
1891
|
-
const raw = readSmallFile(
|
|
1962
|
+
const raw = readSmallFile(path17.join(full, "package.json"));
|
|
1892
1963
|
if (raw !== null) {
|
|
1893
1964
|
for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
|
|
1894
1965
|
}
|
|
@@ -1898,7 +1969,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
1898
1969
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
1899
1970
|
function isToolOwnedDirectory(dir) {
|
|
1900
1971
|
try {
|
|
1901
|
-
return
|
|
1972
|
+
return fs16.statSync(dir).isDirectory() && fs16.existsSync(path17.join(dir, SNAPSHOT_MARKER));
|
|
1902
1973
|
} catch {
|
|
1903
1974
|
return false;
|
|
1904
1975
|
}
|
|
@@ -1913,7 +1984,7 @@ function countMarkdownFiles(cwd) {
|
|
|
1913
1984
|
directoriesSeen += 1;
|
|
1914
1985
|
let entries;
|
|
1915
1986
|
try {
|
|
1916
|
-
entries =
|
|
1987
|
+
entries = fs16.readdirSync(current.dir, { withFileTypes: true });
|
|
1917
1988
|
} catch {
|
|
1918
1989
|
continue;
|
|
1919
1990
|
}
|
|
@@ -1924,7 +1995,7 @@ function countMarkdownFiles(cwd) {
|
|
|
1924
1995
|
}
|
|
1925
1996
|
if (!entry.isDirectory() || current.depth >= 2) continue;
|
|
1926
1997
|
if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
|
|
1927
|
-
const child =
|
|
1998
|
+
const child = path17.join(current.dir, entry.name);
|
|
1928
1999
|
if (isToolOwnedDirectory(child)) continue;
|
|
1929
2000
|
queue.push({ dir: child, depth: current.depth + 1 });
|
|
1930
2001
|
}
|
|
@@ -1935,7 +2006,7 @@ function buildPresetContext(cwd) {
|
|
|
1935
2006
|
const files = /* @__PURE__ */ new Set();
|
|
1936
2007
|
const dirs = /* @__PURE__ */ new Set();
|
|
1937
2008
|
try {
|
|
1938
|
-
for (const entry of
|
|
2009
|
+
for (const entry of fs16.readdirSync(cwd, { withFileTypes: true })) {
|
|
1939
2010
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
1940
2011
|
else if (entry.isFile()) files.add(entry.name);
|
|
1941
2012
|
}
|
|
@@ -1952,7 +2023,7 @@ function buildPresetContext(cwd) {
|
|
|
1952
2023
|
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;
|
|
1953
2024
|
let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
|
|
1954
2025
|
if (isWorkspace) {
|
|
1955
|
-
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(
|
|
2026
|
+
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path17.join(cwd, "pnpm-workspace.yaml")) : null;
|
|
1956
2027
|
const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
|
|
1957
2028
|
const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
|
|
1958
2029
|
workspace = scanWorkspacePackages(cwd, patterns);
|
|
@@ -3906,7 +3977,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
3906
3977
|
|
|
3907
3978
|
// src/version.ts
|
|
3908
3979
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3909
|
-
var GENERATOR_VERSION = "0.
|
|
3980
|
+
var GENERATOR_VERSION = "0.12.0";
|
|
3910
3981
|
var SCHEMA_VERSION = "3.0.0";
|
|
3911
3982
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
3912
3983
|
function isOurGeneratorName(name) {
|
|
@@ -3923,14 +3994,14 @@ var PRESET_IGNORES = new Set(
|
|
|
3923
3994
|
);
|
|
3924
3995
|
function readLinkTarget(linkPath, fallback) {
|
|
3925
3996
|
try {
|
|
3926
|
-
return
|
|
3997
|
+
return fs16.readlinkSync(linkPath);
|
|
3927
3998
|
} catch {
|
|
3928
3999
|
return fallback;
|
|
3929
4000
|
}
|
|
3930
4001
|
}
|
|
3931
4002
|
function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
3932
4003
|
const rawTarget = readLinkTarget(linkPath, linkPath);
|
|
3933
|
-
const resolvedFallback =
|
|
4004
|
+
const resolvedFallback = path17.resolve(path17.dirname(linkPath), rawTarget);
|
|
3934
4005
|
return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
|
|
3935
4006
|
path: relativePath,
|
|
3936
4007
|
reason: "outside-root",
|
|
@@ -3938,8 +4009,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
3938
4009
|
};
|
|
3939
4010
|
}
|
|
3940
4011
|
function isInside(root, candidate) {
|
|
3941
|
-
const relative11 =
|
|
3942
|
-
return relative11 === "" || !relative11.startsWith(`..${
|
|
4012
|
+
const relative11 = path17.relative(root, candidate);
|
|
4013
|
+
return relative11 === "" || !relative11.startsWith(`..${path17.sep}`) && relative11 !== ".." && !path17.isAbsolute(relative11);
|
|
3943
4014
|
}
|
|
3944
4015
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
3945
4016
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -4197,10 +4268,10 @@ function trimUnescapedTrailingSpaces(line) {
|
|
|
4197
4268
|
return line.slice(0, end);
|
|
4198
4269
|
}
|
|
4199
4270
|
function readGitignoreRules(dir) {
|
|
4200
|
-
const gitignorePath2 =
|
|
4271
|
+
const gitignorePath2 = path17.join(dir, ".gitignore");
|
|
4201
4272
|
let raw;
|
|
4202
4273
|
try {
|
|
4203
|
-
raw =
|
|
4274
|
+
raw = fs16.readFileSync(gitignorePath2, "utf8");
|
|
4204
4275
|
} catch {
|
|
4205
4276
|
return [];
|
|
4206
4277
|
}
|
|
@@ -4354,6 +4425,35 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
4354
4425
|
}
|
|
4355
4426
|
return null;
|
|
4356
4427
|
}
|
|
4428
|
+
var COMMIT_BODY_LIMIT = 400;
|
|
4429
|
+
function recentCommits(cwd, limit = 10) {
|
|
4430
|
+
try {
|
|
4431
|
+
const stdout = childProcess.execFileSync(
|
|
4432
|
+
"git",
|
|
4433
|
+
// \x1f between fields and \x1e between records: neither can appear in a commit message, so
|
|
4434
|
+
// the parse cannot be confused by a message that contains a newline or a dash.
|
|
4435
|
+
["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
|
|
4436
|
+
{
|
|
4437
|
+
cwd,
|
|
4438
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
4439
|
+
encoding: "utf8",
|
|
4440
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
4441
|
+
}
|
|
4442
|
+
);
|
|
4443
|
+
return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
|
|
4444
|
+
const separator = record.indexOf("");
|
|
4445
|
+
const subject = separator === -1 ? record : record.slice(0, separator);
|
|
4446
|
+
const rawBody = separator === -1 ? "" : record.slice(separator + 1);
|
|
4447
|
+
const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
|
|
4448
|
+
return {
|
|
4449
|
+
subject: subject.trim(),
|
|
4450
|
+
body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
|
|
4451
|
+
};
|
|
4452
|
+
}).filter((commit) => commit.subject.length > 0);
|
|
4453
|
+
} catch {
|
|
4454
|
+
return [];
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4357
4457
|
function listIgnoredPaths(cwd) {
|
|
4358
4458
|
try {
|
|
4359
4459
|
const stdout = childProcess.execFileSync(
|
|
@@ -4373,7 +4473,7 @@ function listIgnoredPaths(cwd) {
|
|
|
4373
4473
|
}
|
|
4374
4474
|
function hasSnapshotMarker(target) {
|
|
4375
4475
|
try {
|
|
4376
|
-
return
|
|
4476
|
+
return fs16.statSync(target).isDirectory() && fs16.existsSync(path17.join(target, ".codebase-snapshot"));
|
|
4377
4477
|
} catch {
|
|
4378
4478
|
return false;
|
|
4379
4479
|
}
|
|
@@ -4382,7 +4482,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
4382
4482
|
function isToolOwnedDirectory2(dir) {
|
|
4383
4483
|
let raw;
|
|
4384
4484
|
try {
|
|
4385
|
-
raw =
|
|
4485
|
+
raw = fs16.readFileSync(path17.join(dir, ".codebase-snapshot"), "utf8");
|
|
4386
4486
|
} catch {
|
|
4387
4487
|
return false;
|
|
4388
4488
|
}
|
|
@@ -4409,7 +4509,7 @@ function isToolOwnedDirectory2(dir) {
|
|
|
4409
4509
|
}
|
|
4410
4510
|
let entries;
|
|
4411
4511
|
try {
|
|
4412
|
-
entries =
|
|
4512
|
+
entries = fs16.readdirSync(dir);
|
|
4413
4513
|
} catch {
|
|
4414
4514
|
return false;
|
|
4415
4515
|
}
|
|
@@ -4426,7 +4526,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
|
4426
4526
|
const prefix = parts.slice(0, depth).join("/");
|
|
4427
4527
|
let hasMarker = markers.get(prefix);
|
|
4428
4528
|
if (hasMarker === void 0) {
|
|
4429
|
-
hasMarker = isToolOwnedDirectory2(
|
|
4529
|
+
hasMarker = isToolOwnedDirectory2(path17.join(cwd, prefix));
|
|
4430
4530
|
markers.set(prefix, hasMarker);
|
|
4431
4531
|
}
|
|
4432
4532
|
if (hasMarker) return true;
|
|
@@ -4441,7 +4541,7 @@ function makeLinkProbe() {
|
|
|
4441
4541
|
let known = cache.get(absolutePath);
|
|
4442
4542
|
if (known === void 0) {
|
|
4443
4543
|
try {
|
|
4444
|
-
known =
|
|
4544
|
+
known = fs16.lstatSync(absolutePath).isSymbolicLink();
|
|
4445
4545
|
} catch {
|
|
4446
4546
|
known = false;
|
|
4447
4547
|
}
|
|
@@ -4454,7 +4554,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4454
4554
|
const isLink = makeLinkProbe();
|
|
4455
4555
|
let rootReal = cwd;
|
|
4456
4556
|
try {
|
|
4457
|
-
rootReal =
|
|
4557
|
+
rootReal = fs16.realpathSync(cwd);
|
|
4458
4558
|
} catch {
|
|
4459
4559
|
}
|
|
4460
4560
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -4469,7 +4569,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4469
4569
|
let linkedPath = null;
|
|
4470
4570
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
4471
4571
|
const prefix = parts.slice(0, depth).join("/");
|
|
4472
|
-
if (isLink(
|
|
4572
|
+
if (isLink(path17.join(cwd, prefix))) {
|
|
4473
4573
|
linkedPath = prefix;
|
|
4474
4574
|
break;
|
|
4475
4575
|
}
|
|
@@ -4478,11 +4578,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4478
4578
|
kept.push(candidate);
|
|
4479
4579
|
continue;
|
|
4480
4580
|
}
|
|
4481
|
-
const absolute =
|
|
4581
|
+
const absolute = path17.join(cwd, linkedPath);
|
|
4482
4582
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
4483
4583
|
let targetReal = null;
|
|
4484
4584
|
try {
|
|
4485
|
-
targetReal =
|
|
4585
|
+
targetReal = fs16.realpathSync(absolute);
|
|
4486
4586
|
} catch {
|
|
4487
4587
|
targetReal = null;
|
|
4488
4588
|
}
|
|
@@ -4500,7 +4600,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
4500
4600
|
}
|
|
4501
4601
|
let stats = null;
|
|
4502
4602
|
try {
|
|
4503
|
-
stats =
|
|
4603
|
+
stats = fs16.statSync(absolute);
|
|
4504
4604
|
} catch {
|
|
4505
4605
|
stats = null;
|
|
4506
4606
|
}
|
|
@@ -4588,7 +4688,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
4588
4688
|
"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."
|
|
4589
4689
|
);
|
|
4590
4690
|
}
|
|
4591
|
-
if (
|
|
4691
|
+
if (fs16.existsSync(path17.join(cwd, ".git"))) {
|
|
4592
4692
|
throw new Error(
|
|
4593
4693
|
"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."
|
|
4594
4694
|
);
|
|
@@ -4656,7 +4756,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
4656
4756
|
}
|
|
4657
4757
|
function rootRealFor(root) {
|
|
4658
4758
|
try {
|
|
4659
|
-
return
|
|
4759
|
+
return fs16.realpathSync(root);
|
|
4660
4760
|
} catch {
|
|
4661
4761
|
return root;
|
|
4662
4762
|
}
|
|
@@ -4665,18 +4765,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4665
4765
|
const results = { files: [], skipped: [] };
|
|
4666
4766
|
const stack = [];
|
|
4667
4767
|
const toolDirNames = toolDirNamesFor(reservedPaths);
|
|
4668
|
-
const relativeToBase = (target) =>
|
|
4768
|
+
const relativeToBase = (target) => path17.relative(baseDir, target).replace(/\\/g, "/") || ".";
|
|
4669
4769
|
const enter = (current, layers) => {
|
|
4670
4770
|
if (visited.has(current)) return false;
|
|
4671
4771
|
visited.add(current);
|
|
4672
4772
|
const localRules = readGitignoreRules(current);
|
|
4673
4773
|
const gitignoreLayers = localRules.length === 0 ? layers : [
|
|
4674
4774
|
...layers,
|
|
4675
|
-
{ prefix:
|
|
4775
|
+
{ prefix: path17.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
|
|
4676
4776
|
];
|
|
4677
4777
|
let entries;
|
|
4678
4778
|
try {
|
|
4679
|
-
entries =
|
|
4779
|
+
entries = fs16.readdirSync(current, { withFileTypes: true });
|
|
4680
4780
|
} catch {
|
|
4681
4781
|
results.skipped.push({
|
|
4682
4782
|
path: relativeToBase(current),
|
|
@@ -4698,8 +4798,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4698
4798
|
}
|
|
4699
4799
|
const entry = frame.entries[frame.index];
|
|
4700
4800
|
frame.index += 1;
|
|
4701
|
-
const fullPath =
|
|
4702
|
-
const relPath =
|
|
4801
|
+
const fullPath = path17.join(frame.dir, entry.name);
|
|
4802
|
+
const relPath = path17.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
4703
4803
|
if (reservedPaths.has(relPath)) continue;
|
|
4704
4804
|
if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
|
|
4705
4805
|
results.skipped.push({
|
|
@@ -4732,14 +4832,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4732
4832
|
if (entry.isSymbolicLink()) {
|
|
4733
4833
|
let targetReal;
|
|
4734
4834
|
try {
|
|
4735
|
-
targetReal =
|
|
4835
|
+
targetReal = fs16.realpathSync(fullPath);
|
|
4736
4836
|
} catch {
|
|
4737
4837
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
4738
4838
|
continue;
|
|
4739
4839
|
}
|
|
4740
4840
|
let stats;
|
|
4741
4841
|
try {
|
|
4742
|
-
stats =
|
|
4842
|
+
stats = fs16.statSync(fullPath);
|
|
4743
4843
|
} catch {
|
|
4744
4844
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
4745
4845
|
continue;
|
|
@@ -4769,7 +4869,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
4769
4869
|
});
|
|
4770
4870
|
continue;
|
|
4771
4871
|
}
|
|
4772
|
-
const targetRelative =
|
|
4872
|
+
const targetRelative = path17.relative(rootReal, targetReal).split(path17.sep).join("/");
|
|
4773
4873
|
if (isSensitivePath(targetRelative)) {
|
|
4774
4874
|
results.skipped.push({
|
|
4775
4875
|
path: relPath,
|
|
@@ -4825,20 +4925,20 @@ var CONFIG_FILENAMES = [
|
|
|
4825
4925
|
];
|
|
4826
4926
|
function findConfigFile(cwd) {
|
|
4827
4927
|
for (const filename of CONFIG_FILENAMES) {
|
|
4828
|
-
const fullPath =
|
|
4928
|
+
const fullPath = path17.join(cwd, filename);
|
|
4829
4929
|
let stats = null;
|
|
4830
4930
|
try {
|
|
4831
|
-
stats =
|
|
4931
|
+
stats = fs16.statSync(fullPath);
|
|
4832
4932
|
} catch {
|
|
4833
|
-
if (
|
|
4933
|
+
if (fs16.existsSync(fullPath)) return fullPath;
|
|
4834
4934
|
continue;
|
|
4835
4935
|
}
|
|
4836
4936
|
if (stats.isFile()) return fullPath;
|
|
4837
4937
|
}
|
|
4838
|
-
const pkgJsonPath =
|
|
4839
|
-
if (!
|
|
4938
|
+
const pkgJsonPath = path17.join(cwd, "package.json");
|
|
4939
|
+
if (!fs16.existsSync(pkgJsonPath)) return null;
|
|
4840
4940
|
try {
|
|
4841
|
-
const parsed = JSON.parse(stripJsonComments(
|
|
4941
|
+
const parsed = JSON.parse(stripJsonComments(fs16.readFileSync(pkgJsonPath, "utf8")));
|
|
4842
4942
|
const snapshot = parsed?.snapshot;
|
|
4843
4943
|
return typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? pkgJsonPath : null;
|
|
4844
4944
|
} catch {
|
|
@@ -4900,6 +5000,12 @@ function normalizeResolvedConfig(config) {
|
|
|
4900
5000
|
return markResolvedConfig({
|
|
4901
5001
|
...config,
|
|
4902
5002
|
discovery,
|
|
5003
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
5004
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
5005
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
5006
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
5007
|
+
promptTask: resolvePromptTask(config.promptTask),
|
|
5008
|
+
...config.brief === void 0 ? {} : { brief: config.brief },
|
|
4903
5009
|
includeMonolith: artifacts.monolith,
|
|
4904
5010
|
secretRules: compileSecretRules(config.secretRules),
|
|
4905
5011
|
artifacts,
|
|
@@ -4968,7 +5074,9 @@ function describeValue2(value) {
|
|
|
4968
5074
|
var isThenable = (value) => typeof value.then === "function";
|
|
4969
5075
|
var CONFIG_KEY_NAMES = [
|
|
4970
5076
|
"artifacts",
|
|
5077
|
+
"attachmentSlots",
|
|
4971
5078
|
"branch",
|
|
5079
|
+
"brief",
|
|
4972
5080
|
"budgets",
|
|
4973
5081
|
"changedSince",
|
|
4974
5082
|
"cwd",
|
|
@@ -4985,10 +5093,12 @@ var CONFIG_KEY_NAMES = [
|
|
|
4985
5093
|
"layersMode",
|
|
4986
5094
|
"maxMonolithBytes",
|
|
4987
5095
|
"maxPartBytes",
|
|
5096
|
+
"maxParts",
|
|
4988
5097
|
"maxPartTokens",
|
|
4989
5098
|
"outDir",
|
|
4990
5099
|
"preset",
|
|
4991
5100
|
"previewHeadLines",
|
|
5101
|
+
"promptTask",
|
|
4992
5102
|
"staged",
|
|
4993
5103
|
"previewTailLines",
|
|
4994
5104
|
"secretRules",
|
|
@@ -5039,10 +5149,10 @@ function readConfigExport(exported, file) {
|
|
|
5039
5149
|
var lastModuleConfig = null;
|
|
5040
5150
|
function moduleConfigKey(fullPath) {
|
|
5041
5151
|
try {
|
|
5042
|
-
return createHash("sha256").update(
|
|
5152
|
+
return createHash("sha256").update(fs16.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
5043
5153
|
} catch {
|
|
5044
5154
|
try {
|
|
5045
|
-
const stats =
|
|
5155
|
+
const stats = fs16.statSync(fullPath);
|
|
5046
5156
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
5047
5157
|
} catch {
|
|
5048
5158
|
return "unreadable";
|
|
@@ -5068,7 +5178,7 @@ async function importConfigModule(fullPath) {
|
|
|
5068
5178
|
function attachConfigDir(config, filePath) {
|
|
5069
5179
|
if (typeof config === "object" && config !== null) {
|
|
5070
5180
|
Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
|
|
5071
|
-
value:
|
|
5181
|
+
value: path17.dirname(filePath),
|
|
5072
5182
|
enumerable: false,
|
|
5073
5183
|
configurable: true
|
|
5074
5184
|
});
|
|
@@ -5080,12 +5190,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5080
5190
|
const errors = [];
|
|
5081
5191
|
const configDirectories = [];
|
|
5082
5192
|
for (const filename of CONFIG_FILENAMES) {
|
|
5083
|
-
const fullPath =
|
|
5193
|
+
const fullPath = path17.join(cwd, filename);
|
|
5084
5194
|
let candidateStats = null;
|
|
5085
5195
|
try {
|
|
5086
|
-
candidateStats =
|
|
5196
|
+
candidateStats = fs16.statSync(fullPath);
|
|
5087
5197
|
} catch {
|
|
5088
|
-
if (!
|
|
5198
|
+
if (!fs16.existsSync(fullPath)) continue;
|
|
5089
5199
|
}
|
|
5090
5200
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
5091
5201
|
configDirectories.push(fullPath);
|
|
@@ -5093,7 +5203,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5093
5203
|
}
|
|
5094
5204
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
5095
5205
|
try {
|
|
5096
|
-
const config = parseJsonish(
|
|
5206
|
+
const config = parseJsonish(fs16.readFileSync(fullPath, "utf8"), fullPath);
|
|
5097
5207
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
5098
5208
|
throw new Error(
|
|
5099
5209
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -5133,10 +5243,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
5133
5243
|
continue;
|
|
5134
5244
|
}
|
|
5135
5245
|
}
|
|
5136
|
-
const pkgJsonPath =
|
|
5137
|
-
if (
|
|
5246
|
+
const pkgJsonPath = path17.join(cwd, "package.json");
|
|
5247
|
+
if (fs16.existsSync(pkgJsonPath)) {
|
|
5138
5248
|
try {
|
|
5139
|
-
const parsed = parseJsonish(
|
|
5249
|
+
const parsed = parseJsonish(fs16.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
5140
5250
|
const snapshotKey = parsed.snapshot;
|
|
5141
5251
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
5142
5252
|
assertKnownConfigKeys(
|
|
@@ -5190,6 +5300,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
5190
5300
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
5191
5301
|
var ARTIFACT_NAMES = [
|
|
5192
5302
|
"readme",
|
|
5303
|
+
"prompt",
|
|
5193
5304
|
"manifest",
|
|
5194
5305
|
"parts",
|
|
5195
5306
|
"navigation",
|
|
@@ -5199,6 +5310,7 @@ var ARTIFACT_NAMES = [
|
|
|
5199
5310
|
];
|
|
5200
5311
|
var DEFAULT_ARTIFACTS = {
|
|
5201
5312
|
readme: true,
|
|
5313
|
+
prompt: true,
|
|
5202
5314
|
manifest: true,
|
|
5203
5315
|
parts: true,
|
|
5204
5316
|
navigation: true,
|
|
@@ -5259,6 +5371,57 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
5259
5371
|
}
|
|
5260
5372
|
return artifacts;
|
|
5261
5373
|
}
|
|
5374
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
5375
|
+
function resolveAttachmentSlots(value) {
|
|
5376
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
5377
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
5378
|
+
throw new Error(
|
|
5379
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
5380
|
+
);
|
|
5381
|
+
}
|
|
5382
|
+
return value;
|
|
5383
|
+
}
|
|
5384
|
+
function resolveMaxParts(value) {
|
|
5385
|
+
if (value === void 0 || value === null) return null;
|
|
5386
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
5387
|
+
throw new Error(
|
|
5388
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
5389
|
+
);
|
|
5390
|
+
}
|
|
5391
|
+
return value;
|
|
5392
|
+
}
|
|
5393
|
+
function resolvePromptTask(value) {
|
|
5394
|
+
if (value === void 0 || value === null) return "audit";
|
|
5395
|
+
if (value === "audit" || value === "review" || value === "explain") return value;
|
|
5396
|
+
throw new Error(
|
|
5397
|
+
'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
|
|
5398
|
+
);
|
|
5399
|
+
}
|
|
5400
|
+
function readConfiguredBrief(cwd, value) {
|
|
5401
|
+
if (value === void 0 || value === null) return void 0;
|
|
5402
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
5403
|
+
throw new Error(
|
|
5404
|
+
"brief must be a path to a markdown file (received " + describeValue2(value) + ")."
|
|
5405
|
+
);
|
|
5406
|
+
}
|
|
5407
|
+
const filePath = path17.resolve(cwd, value);
|
|
5408
|
+
let text2;
|
|
5409
|
+
try {
|
|
5410
|
+
if (!fs16.statSync(filePath).isFile()) throw new Error("not a file");
|
|
5411
|
+
text2 = fs16.readFileSync(filePath, "utf8");
|
|
5412
|
+
} catch {
|
|
5413
|
+
throw new Error(
|
|
5414
|
+
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
5415
|
+
);
|
|
5416
|
+
}
|
|
5417
|
+
const parsed = parseOwnerBrief(value, text2);
|
|
5418
|
+
if (parsed.problems.length > 0) {
|
|
5419
|
+
throw new Error(
|
|
5420
|
+
'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
|
|
5421
|
+
);
|
|
5422
|
+
}
|
|
5423
|
+
return parsed.brief;
|
|
5424
|
+
}
|
|
5262
5425
|
function strictPositiveInteger(value, fallback, label) {
|
|
5263
5426
|
if (value === void 0) return fallback;
|
|
5264
5427
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -5351,9 +5514,9 @@ function resolveKindRules(value) {
|
|
|
5351
5514
|
function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
5352
5515
|
const patterns = [];
|
|
5353
5516
|
for (const dir of [outDir, tmpDir]) {
|
|
5354
|
-
const absolute =
|
|
5355
|
-
const relative11 =
|
|
5356
|
-
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${
|
|
5517
|
+
const absolute = path17.resolve(cwd, dir);
|
|
5518
|
+
const relative11 = path17.relative(cwd, absolute);
|
|
5519
|
+
if (!relative11 || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
|
|
5357
5520
|
continue;
|
|
5358
5521
|
}
|
|
5359
5522
|
patterns.push(`${relative11.replace(/\\/g, "/")}/**`);
|
|
@@ -5486,11 +5649,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
5486
5649
|
);
|
|
5487
5650
|
}
|
|
5488
5651
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
5489
|
-
const resolved =
|
|
5490
|
-
if (!
|
|
5652
|
+
const resolved = path17.resolve(candidate);
|
|
5653
|
+
if (!fs16.existsSync(resolved)) {
|
|
5491
5654
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
5492
5655
|
}
|
|
5493
|
-
if (!
|
|
5656
|
+
if (!fs16.statSync(resolved).isDirectory()) {
|
|
5494
5657
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
5495
5658
|
}
|
|
5496
5659
|
return resolved;
|
|
@@ -5618,6 +5781,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5618
5781
|
configuredSensitiveFiles,
|
|
5619
5782
|
"`includeSensitiveFiles`"
|
|
5620
5783
|
);
|
|
5784
|
+
const configuredBrief = readConfiguredBrief(
|
|
5785
|
+
cwd,
|
|
5786
|
+
cliOptions?.brief ?? userConfig?.brief
|
|
5787
|
+
);
|
|
5621
5788
|
const presetExclude = [
|
|
5622
5789
|
.../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
|
|
5623
5790
|
];
|
|
@@ -5637,6 +5804,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5637
5804
|
"maxMonolithBytes"
|
|
5638
5805
|
),
|
|
5639
5806
|
includeSensitiveFiles,
|
|
5807
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
5808
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
5809
|
+
),
|
|
5810
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
5811
|
+
promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
|
|
5812
|
+
...configuredBrief === void 0 ? {} : { brief: configuredBrief },
|
|
5640
5813
|
...changedSince === void 0 ? {} : { changedSince },
|
|
5641
5814
|
...staged ? { staged } : {},
|
|
5642
5815
|
...withDependents ? { withDependents } : {},
|
|
@@ -5719,6 +5892,15 @@ function configDigest(config) {
|
|
|
5719
5892
|
includeMonolith: config.includeMonolith,
|
|
5720
5893
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
5721
5894
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
5895
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
5896
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
5897
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
5898
|
+
// The default value is omitted for the same reason: a snapshot taken before the setting
|
|
5899
|
+
// existed kept the audit job, so it must keep the digest it was written with.
|
|
5900
|
+
...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
|
|
5901
|
+
// The owner brief is instruction, not payload, but it changes what the snapshot tells a
|
|
5902
|
+
// reader to do, so a changed brief is drift exactly like a changed budget.
|
|
5903
|
+
...config.brief === void 0 ? {} : { brief: config.brief.digest },
|
|
5722
5904
|
artifacts: config.artifacts,
|
|
5723
5905
|
include: config.include,
|
|
5724
5906
|
excludePatterns: config.excludePatterns,
|
|
@@ -6678,10 +6860,509 @@ function generateNavigation(manifest) {
|
|
|
6678
6860
|
return lines.join("\n");
|
|
6679
6861
|
}
|
|
6680
6862
|
|
|
6863
|
+
// src/generator/prompt.ts
|
|
6864
|
+
var MAX_PART_ROWS = 16;
|
|
6865
|
+
var MAX_LAYER_ROWS = 8;
|
|
6866
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
6867
|
+
var MAX_CENTRAL_FILES = 5;
|
|
6868
|
+
var MAX_ENTRY_POINTS = 4;
|
|
6869
|
+
var MAX_LARGEST_FILES = 3;
|
|
6870
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
6871
|
+
var UNLIMITED_SLOTS = 0;
|
|
6872
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
6873
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
6874
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
6875
|
+
function generatePrompt(manifest, artifacts, context = {}) {
|
|
6876
|
+
const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
|
|
6877
|
+
const task = context.task ?? "audit";
|
|
6878
|
+
const history = context.history ?? [];
|
|
6879
|
+
const overview = context.overview ?? { releases: [] };
|
|
6880
|
+
const brief = context.brief;
|
|
6881
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
6882
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
6883
|
+
const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
|
|
6884
|
+
const lines = [
|
|
6885
|
+
"# PROMPT.md",
|
|
6886
|
+
"",
|
|
6887
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
6888
|
+
"",
|
|
6889
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
6890
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
6891
|
+
"Regenerate it after the code moves.",
|
|
6892
|
+
"",
|
|
6893
|
+
"---",
|
|
6894
|
+
"",
|
|
6895
|
+
"```text",
|
|
6896
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
6897
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
6898
|
+
"the snapshot is what exists.",
|
|
6899
|
+
""
|
|
6900
|
+
];
|
|
6901
|
+
if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
|
|
6902
|
+
lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
|
|
6903
|
+
lines.push(...stakesSection(brief, code));
|
|
6904
|
+
lines.push(...haveSection(wrote), "");
|
|
6905
|
+
lines.push(...whatThisIsSection(overview), "");
|
|
6906
|
+
lines.push(...systemSection(manifest, code, brief), "");
|
|
6907
|
+
lines.push(...historySection(history, brief, code), "");
|
|
6908
|
+
lines.push(...barSection(brief, code), "");
|
|
6909
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
6910
|
+
lines.push(...answerSection(), "");
|
|
6911
|
+
lines.push(...calibrationSection(brief, code), "");
|
|
6912
|
+
lines.push(...ownerNotesSection(brief, code));
|
|
6913
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
6914
|
+
lines.push(...deliverySection(manifest, wrote("parts"), slots));
|
|
6915
|
+
lines.push(
|
|
6916
|
+
"## Your task",
|
|
6917
|
+
"",
|
|
6918
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
6919
|
+
"```"
|
|
6920
|
+
);
|
|
6921
|
+
lines.push(
|
|
6922
|
+
"",
|
|
6923
|
+
"---",
|
|
6924
|
+
"",
|
|
6925
|
+
"## Why this file exists",
|
|
6926
|
+
"",
|
|
6927
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
6928
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
6929
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
6930
|
+
"facts in it move with the snapshot.",
|
|
6931
|
+
"",
|
|
6932
|
+
"## Keeping it true",
|
|
6933
|
+
"",
|
|
6934
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
6935
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
6936
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
6937
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
6938
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
6939
|
+
" brief, because it reads as current.",
|
|
6940
|
+
""
|
|
6941
|
+
);
|
|
6942
|
+
return lines.join("\n");
|
|
6943
|
+
}
|
|
6944
|
+
function haveSection(wrote) {
|
|
6945
|
+
const out = ["## What you have", ""];
|
|
6946
|
+
const bullets = [];
|
|
6947
|
+
if (wrote("readme")) {
|
|
6948
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
6949
|
+
}
|
|
6950
|
+
if (wrote("manifest")) {
|
|
6951
|
+
bullets.push(
|
|
6952
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
6953
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
6954
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
6955
|
+
" every included file whose emitted body is not the whole file."
|
|
6956
|
+
);
|
|
6957
|
+
}
|
|
6958
|
+
if (wrote("navigation")) {
|
|
6959
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
6960
|
+
}
|
|
6961
|
+
if (wrote("projectTree")) {
|
|
6962
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
6963
|
+
}
|
|
6964
|
+
if (wrote("audit")) {
|
|
6965
|
+
bullets.push(
|
|
6966
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
6967
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
6968
|
+
);
|
|
6969
|
+
}
|
|
6970
|
+
if (wrote("parts")) {
|
|
6971
|
+
bullets.push(
|
|
6972
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
6973
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
6974
|
+
);
|
|
6975
|
+
}
|
|
6976
|
+
if (wrote("monolith")) {
|
|
6977
|
+
bullets.push(
|
|
6978
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
6979
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
6980
|
+
);
|
|
6981
|
+
}
|
|
6982
|
+
if (bullets.length === 0) {
|
|
6983
|
+
bullets.push(
|
|
6984
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
6985
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
6986
|
+
);
|
|
6987
|
+
}
|
|
6988
|
+
out.push(...bullets);
|
|
6989
|
+
return out;
|
|
6990
|
+
}
|
|
6991
|
+
function systemSection(manifest, code, brief) {
|
|
6992
|
+
const out = ["## The system", ""];
|
|
6993
|
+
if (brief?.system !== void 0) {
|
|
6994
|
+
out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
|
|
6995
|
+
}
|
|
6996
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
6997
|
+
if (layers.length > 0) {
|
|
6998
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
6999
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
7000
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
7001
|
+
}
|
|
7002
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
7003
|
+
if (central.length > 0) {
|
|
7004
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
7005
|
+
out.push(
|
|
7006
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
7007
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
7008
|
+
);
|
|
7009
|
+
}
|
|
7010
|
+
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);
|
|
7011
|
+
out.push(
|
|
7012
|
+
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"
|
|
7013
|
+
);
|
|
7014
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
7015
|
+
const routes = manifest.indexes.routes.length;
|
|
7016
|
+
const handlers = manifest.indexes.handlers.length;
|
|
7017
|
+
const components = manifest.indexes.components.length;
|
|
7018
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
7019
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
7020
|
+
if (routes + handlers + components === 0) {
|
|
7021
|
+
out.push(
|
|
7022
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
7023
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
7024
|
+
);
|
|
7025
|
+
} else {
|
|
7026
|
+
const parts = [];
|
|
7027
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
7028
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
7029
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
7030
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
7031
|
+
}
|
|
7032
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
7033
|
+
if (largest.length > 0) {
|
|
7034
|
+
out.push(
|
|
7035
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
7036
|
+
);
|
|
7037
|
+
}
|
|
7038
|
+
const tests = manifest.files.filter(
|
|
7039
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
7040
|
+
);
|
|
7041
|
+
if (tests.length > 0) {
|
|
7042
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
7043
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
7044
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
7045
|
+
out.push(
|
|
7046
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
7047
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
7048
|
+
" real system never sends."
|
|
7049
|
+
);
|
|
7050
|
+
}
|
|
7051
|
+
return out;
|
|
7052
|
+
}
|
|
7053
|
+
function historySection(history, brief, code) {
|
|
7054
|
+
const out = ["## What came before", ""];
|
|
7055
|
+
if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
|
|
7056
|
+
if (history.length === 0) {
|
|
7057
|
+
out.push(
|
|
7058
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
7059
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
7060
|
+
);
|
|
7061
|
+
return out;
|
|
7062
|
+
}
|
|
7063
|
+
out.push(
|
|
7064
|
+
"The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
|
|
7065
|
+
"claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
|
|
7066
|
+
"these fixes looks incomplete, quote the lines and say which call site it missed.",
|
|
7067
|
+
""
|
|
7068
|
+
);
|
|
7069
|
+
for (const commit of history) {
|
|
7070
|
+
out.push("- " + commit.subject);
|
|
7071
|
+
if (commit.body.length > 0) out.push(" " + commit.body);
|
|
7072
|
+
}
|
|
7073
|
+
return out;
|
|
7074
|
+
}
|
|
7075
|
+
function barSection(brief, code) {
|
|
7076
|
+
if (brief?.bar !== void 0) {
|
|
7077
|
+
return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
|
|
7078
|
+
}
|
|
7079
|
+
return [
|
|
7080
|
+
"## The bar",
|
|
7081
|
+
"",
|
|
7082
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
7083
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
7084
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
7085
|
+
"behaviour.",
|
|
7086
|
+
"",
|
|
7087
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
7088
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
7089
|
+
" that makes it clean.",
|
|
7090
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
7091
|
+
" you cannot decide by reading.",
|
|
7092
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
7093
|
+
" findings; they have different owners and different fixes."
|
|
7094
|
+
];
|
|
7095
|
+
}
|
|
7096
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
7097
|
+
const out = ["## Coverage", ""];
|
|
7098
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
7099
|
+
for (const record of manifest.skipped) {
|
|
7100
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
7101
|
+
}
|
|
7102
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
7103
|
+
out.push(
|
|
7104
|
+
"- " + 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 + ")" : "") + ".",
|
|
7105
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
7106
|
+
);
|
|
7107
|
+
out.push(...incompleteSection(manifest, code));
|
|
7108
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
7109
|
+
out.push(
|
|
7110
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
7111
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
7112
|
+
" is an input defect, not a code finding - report it as one."
|
|
7113
|
+
);
|
|
7114
|
+
return out;
|
|
7115
|
+
}
|
|
7116
|
+
function answerSection() {
|
|
7117
|
+
return [
|
|
7118
|
+
"## What a useful answer contains",
|
|
7119
|
+
"",
|
|
7120
|
+
"- An opening line, filled from This snapshot below:",
|
|
7121
|
+
"",
|
|
7122
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
7123
|
+
"",
|
|
7124
|
+
"- What you read and what you did not, named by path or by part.",
|
|
7125
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
7126
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
7127
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
7128
|
+
"- What you retracted after re-reading.",
|
|
7129
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
7130
|
+
"- One paragraph on the failure you would bet on next.",
|
|
7131
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
7132
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
7133
|
+
" the gap you filled by asking instead of guessing."
|
|
7134
|
+
];
|
|
7135
|
+
}
|
|
7136
|
+
function calibrationSection(brief, code) {
|
|
7137
|
+
if (brief?.calibration !== void 0) {
|
|
7138
|
+
return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
|
|
7139
|
+
}
|
|
7140
|
+
return [
|
|
7141
|
+
"## Calibration",
|
|
7142
|
+
"",
|
|
7143
|
+
"The findings that matter here do not crash. They look like:",
|
|
7144
|
+
"",
|
|
7145
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
7146
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
7147
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
7148
|
+
"- a document that describes a different run than the one beside it;",
|
|
7149
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
7150
|
+
"",
|
|
7151
|
+
"None of these throw. All are invisible in a summary."
|
|
7152
|
+
];
|
|
7153
|
+
}
|
|
7154
|
+
function jobSection(task, hasHistory) {
|
|
7155
|
+
const out = ["## The job", ""];
|
|
7156
|
+
if (task === "audit") {
|
|
7157
|
+
out.push(
|
|
7158
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
7159
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
7160
|
+
"honest account of what you covered and what you did not.",
|
|
7161
|
+
""
|
|
7162
|
+
);
|
|
7163
|
+
if (hasHistory) {
|
|
7164
|
+
out.push(
|
|
7165
|
+
"Another pass of the same findings is worth nothing. This repository carries a record of",
|
|
7166
|
+
"what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
|
|
7167
|
+
"and treat a variant of one at a different call site as a new finding."
|
|
7168
|
+
);
|
|
7169
|
+
} else {
|
|
7170
|
+
out.push(
|
|
7171
|
+
"Another pass of the same findings is worth nothing, but no earlier round is readable here,",
|
|
7172
|
+
"so you cannot tell what has already been tried. Do not assume this is the first attempt."
|
|
7173
|
+
);
|
|
7174
|
+
}
|
|
7175
|
+
out.push(
|
|
7176
|
+
"",
|
|
7177
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer",
|
|
7178
|
+
"a question - that task wins. The standard and the coverage duty below still apply to it."
|
|
7179
|
+
);
|
|
7180
|
+
} else if (task === "review") {
|
|
7181
|
+
out.push(
|
|
7182
|
+
"Review the change or the area named in the task against this snapshot. Report what breaks,",
|
|
7183
|
+
"what the change claims but does not do, and what a reader would believe that the code does",
|
|
7184
|
+
"not support. Restating the diff is not a review; the standard and the coverage duty below",
|
|
7185
|
+
"still apply."
|
|
7186
|
+
);
|
|
7187
|
+
} else {
|
|
7188
|
+
out.push(
|
|
7189
|
+
"Explain how the part of the system named in the task works: the data flow, the boundaries",
|
|
7190
|
+
"and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
|
|
7191
|
+
"need, say which file you need rather than reconstructing it from the shape of the names."
|
|
7192
|
+
);
|
|
7193
|
+
}
|
|
7194
|
+
return out;
|
|
7195
|
+
}
|
|
7196
|
+
function stakesSection(brief, code) {
|
|
7197
|
+
if (brief?.stakes === void 0) return [];
|
|
7198
|
+
return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
|
|
7199
|
+
}
|
|
7200
|
+
function whatThisIsSection(overview) {
|
|
7201
|
+
const body = [];
|
|
7202
|
+
if (overview.description !== void 0) {
|
|
7203
|
+
body.push("- Declared in `package.json`: " + overview.description);
|
|
7204
|
+
}
|
|
7205
|
+
if (overview.summary !== void 0) {
|
|
7206
|
+
body.push("- From the `README.md` first paragraph: " + overview.summary);
|
|
7207
|
+
}
|
|
7208
|
+
if (overview.releases.length > 0) {
|
|
7209
|
+
body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
|
|
7210
|
+
}
|
|
7211
|
+
if (body.length === 0) return [];
|
|
7212
|
+
return [
|
|
7213
|
+
"## What this is",
|
|
7214
|
+
"",
|
|
7215
|
+
...body,
|
|
7216
|
+
"",
|
|
7217
|
+
"Those are the project's own claims, not evidence about the code.",
|
|
7218
|
+
""
|
|
7219
|
+
];
|
|
7220
|
+
}
|
|
7221
|
+
function ownerNotesSection(brief, code) {
|
|
7222
|
+
if (brief === void 0 || brief.notes.length === 0) return [];
|
|
7223
|
+
const out = ["## Owner notes", ""];
|
|
7224
|
+
for (const note of brief.notes) {
|
|
7225
|
+
out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
|
|
7226
|
+
}
|
|
7227
|
+
return out;
|
|
7228
|
+
}
|
|
7229
|
+
function ownerBlock(text2, path18, code) {
|
|
7230
|
+
return ["> Written by the project owner in " + code(path18) + ", not generated.", "", text2];
|
|
7231
|
+
}
|
|
7232
|
+
function snapshotSection(manifest, code) {
|
|
7233
|
+
const out = ["## This snapshot", ""];
|
|
7234
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
7235
|
+
out.push(
|
|
7236
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
7237
|
+
);
|
|
7238
|
+
out.push(
|
|
7239
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
7240
|
+
);
|
|
7241
|
+
out.push(
|
|
7242
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
7243
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
7244
|
+
" claim that needs re-checking, not a fact."
|
|
7245
|
+
);
|
|
7246
|
+
if (manifest.parts.length > 0) {
|
|
7247
|
+
out.push(
|
|
7248
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
7249
|
+
);
|
|
7250
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
7251
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
7252
|
+
}
|
|
7253
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
7254
|
+
out.push(
|
|
7255
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
7256
|
+
);
|
|
7257
|
+
}
|
|
7258
|
+
}
|
|
7259
|
+
return out;
|
|
7260
|
+
}
|
|
7261
|
+
function incompleteSection(manifest, code) {
|
|
7262
|
+
const out = [];
|
|
7263
|
+
const list2 = manifest.incomplete;
|
|
7264
|
+
if (list2.length === 0) {
|
|
7265
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
7266
|
+
return out;
|
|
7267
|
+
}
|
|
7268
|
+
out.push(
|
|
7269
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
7270
|
+
" missing lines are named, not implied:"
|
|
7271
|
+
);
|
|
7272
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
7273
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
7274
|
+
out.push(
|
|
7275
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
7276
|
+
);
|
|
7277
|
+
}
|
|
7278
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
7279
|
+
out.push(
|
|
7280
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
7281
|
+
);
|
|
7282
|
+
}
|
|
7283
|
+
return out;
|
|
7284
|
+
}
|
|
7285
|
+
function redactionSection(manifest, auditWritten) {
|
|
7286
|
+
const redacted = manifest.totals.redactedLines;
|
|
7287
|
+
if (redacted === 0) {
|
|
7288
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
7289
|
+
}
|
|
7290
|
+
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.";
|
|
7291
|
+
return [
|
|
7292
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
7293
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
7294
|
+
" " + where
|
|
7295
|
+
];
|
|
7296
|
+
}
|
|
7297
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
7298
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
7299
|
+
const parts = manifest.parts.length;
|
|
7300
|
+
const wholeSet = parts + 5;
|
|
7301
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
7302
|
+
const out = ["## Attaching this", ""];
|
|
7303
|
+
out.push(
|
|
7304
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
7305
|
+
"",
|
|
7306
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
7307
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
7308
|
+
);
|
|
7309
|
+
if (unlimited) {
|
|
7310
|
+
out.push(
|
|
7311
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
7312
|
+
);
|
|
7313
|
+
} else if (wholeSet <= slots) {
|
|
7314
|
+
out.push(
|
|
7315
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
7316
|
+
);
|
|
7317
|
+
} else if (parts + 1 <= slots) {
|
|
7318
|
+
out.push(
|
|
7319
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
7320
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
7321
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
7322
|
+
);
|
|
7323
|
+
} else if (parts <= slots) {
|
|
7324
|
+
out.push(
|
|
7325
|
+
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",
|
|
7326
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
7327
|
+
);
|
|
7328
|
+
if (parts > 1) {
|
|
7329
|
+
out.push(
|
|
7330
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
7331
|
+
);
|
|
7332
|
+
}
|
|
7333
|
+
} else {
|
|
7334
|
+
out.push(
|
|
7335
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
7336
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
7337
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
7338
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
7339
|
+
);
|
|
7340
|
+
}
|
|
7341
|
+
out.push(
|
|
7342
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
7343
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
7344
|
+
""
|
|
7345
|
+
);
|
|
7346
|
+
return out;
|
|
7347
|
+
}
|
|
7348
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
7349
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
7350
|
+
const target = Math.max(1, slots - 1);
|
|
7351
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
7352
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
7353
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
7354
|
+
return Math.round(budget / 1024) + "k";
|
|
7355
|
+
}
|
|
7356
|
+
|
|
6681
7357
|
// src/generator/readme.ts
|
|
6682
7358
|
function generateReadme(manifest, artifacts) {
|
|
6683
7359
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
6684
7360
|
const reportLinks = [];
|
|
7361
|
+
if (wrote("prompt")) {
|
|
7362
|
+
reportLinks.push(
|
|
7363
|
+
"- [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."
|
|
7364
|
+
);
|
|
7365
|
+
}
|
|
6685
7366
|
if (wrote("navigation")) {
|
|
6686
7367
|
reportLinks.push(
|
|
6687
7368
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -6751,6 +7432,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
6751
7432
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
6752
7433
|
}
|
|
6753
7434
|
const readOrder = [];
|
|
7435
|
+
if (wrote("prompt")) {
|
|
7436
|
+
readOrder.push(
|
|
7437
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
7438
|
+
);
|
|
7439
|
+
}
|
|
6754
7440
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
6755
7441
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
6756
7442
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -6898,7 +7584,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6898
7584
|
const descriptions = [];
|
|
6899
7585
|
if (request.changedSince !== void 0) {
|
|
6900
7586
|
assertUsableRef(request.changedSince);
|
|
6901
|
-
for (const
|
|
7587
|
+
for (const path18 of gitPaths(cwd, [
|
|
6902
7588
|
"diff",
|
|
6903
7589
|
"--name-only",
|
|
6904
7590
|
"-z",
|
|
@@ -6906,9 +7592,9 @@ function resolveChangedScope(cwd, request) {
|
|
|
6906
7592
|
`${request.changedSince}...HEAD`,
|
|
6907
7593
|
"--"
|
|
6908
7594
|
])) {
|
|
6909
|
-
paths.add(
|
|
7595
|
+
paths.add(path18);
|
|
6910
7596
|
}
|
|
6911
|
-
for (const
|
|
7597
|
+
for (const path18 of gitPaths(cwd, [
|
|
6912
7598
|
"diff",
|
|
6913
7599
|
"--name-only",
|
|
6914
7600
|
"-z",
|
|
@@ -6916,15 +7602,15 @@ function resolveChangedScope(cwd, request) {
|
|
|
6916
7602
|
"HEAD",
|
|
6917
7603
|
"--"
|
|
6918
7604
|
])) {
|
|
6919
|
-
paths.add(
|
|
7605
|
+
paths.add(path18);
|
|
6920
7606
|
}
|
|
6921
|
-
for (const
|
|
6922
|
-
paths.add(
|
|
7607
|
+
for (const path18 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
7608
|
+
paths.add(path18);
|
|
6923
7609
|
}
|
|
6924
7610
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
6925
7611
|
}
|
|
6926
7612
|
if (request.staged === true) {
|
|
6927
|
-
for (const
|
|
7613
|
+
for (const path18 of gitPaths(cwd, [
|
|
6928
7614
|
"diff",
|
|
6929
7615
|
"--cached",
|
|
6930
7616
|
"--name-only",
|
|
@@ -6932,10 +7618,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
6932
7618
|
"--relative",
|
|
6933
7619
|
"--"
|
|
6934
7620
|
])) {
|
|
6935
|
-
paths.add(
|
|
6936
|
-
stagedPaths.add(
|
|
7621
|
+
paths.add(path18);
|
|
7622
|
+
stagedPaths.add(path18);
|
|
6937
7623
|
}
|
|
6938
|
-
for (const
|
|
7624
|
+
for (const path18 of gitPaths(cwd, [
|
|
6939
7625
|
"diff",
|
|
6940
7626
|
"--cached",
|
|
6941
7627
|
"--name-only",
|
|
@@ -6944,7 +7630,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6944
7630
|
"--diff-filter=D",
|
|
6945
7631
|
"--"
|
|
6946
7632
|
])) {
|
|
6947
|
-
deletedPaths.add(
|
|
7633
|
+
deletedPaths.add(path18);
|
|
6948
7634
|
}
|
|
6949
7635
|
descriptions.push("staged");
|
|
6950
7636
|
}
|
|
@@ -6982,10 +7668,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
|
6982
7668
|
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
6983
7669
|
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
6984
7670
|
function tsconfigPathsFor(cwd) {
|
|
6985
|
-
const configPath =
|
|
7671
|
+
const configPath = path17.join(cwd, "tsconfig.json");
|
|
6986
7672
|
let stats;
|
|
6987
7673
|
try {
|
|
6988
|
-
stats =
|
|
7674
|
+
stats = fs16.statSync(configPath);
|
|
6989
7675
|
} catch (err) {
|
|
6990
7676
|
if (err.code === "ENOENT") return null;
|
|
6991
7677
|
return null;
|
|
@@ -7019,8 +7705,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
7019
7705
|
return value;
|
|
7020
7706
|
}
|
|
7021
7707
|
function repositoryRelative(cwd, target) {
|
|
7022
|
-
const relative11 =
|
|
7023
|
-
return relative11.length === 0 || !relative11.startsWith("..") && !
|
|
7708
|
+
const relative11 = path17.relative(cwd, target).replace(/\\/g, "/");
|
|
7709
|
+
return relative11.length === 0 || !relative11.startsWith("..") && !path17.isAbsolute(relative11) ? relative11 : null;
|
|
7024
7710
|
}
|
|
7025
7711
|
function rememberFirst(map, key, value) {
|
|
7026
7712
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -7035,15 +7721,15 @@ function buildImportResolver(files, options = {}) {
|
|
|
7035
7721
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7036
7722
|
rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
7037
7723
|
}
|
|
7038
|
-
const extension =
|
|
7724
|
+
const extension = path17.posix.extname(relativePath);
|
|
7039
7725
|
if (!SOURCE_EXTENSIONS.has(extension)) return;
|
|
7040
7726
|
const stem = relativePath.slice(0, -extension.length);
|
|
7041
7727
|
rememberFirst(byStem, stem, relativePath);
|
|
7042
7728
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7043
7729
|
rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
|
|
7044
7730
|
}
|
|
7045
|
-
if (
|
|
7046
|
-
const directory =
|
|
7731
|
+
if (path17.posix.basename(stem) === "index") {
|
|
7732
|
+
const directory = path17.posix.dirname(stem);
|
|
7047
7733
|
rememberFirst(byStem, directory, relativePath);
|
|
7048
7734
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
7049
7735
|
rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
|
|
@@ -7059,7 +7745,7 @@ function buildImportResolver(files, options = {}) {
|
|
|
7059
7745
|
return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
|
|
7060
7746
|
}
|
|
7061
7747
|
function resolveSpecifier(fromFile, specifier, resolver) {
|
|
7062
|
-
const extension =
|
|
7748
|
+
const extension = path17.posix.extname(fromFile).toLowerCase();
|
|
7063
7749
|
const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
7064
7750
|
const firstOf = (candidates) => {
|
|
7065
7751
|
for (const candidate of candidates) {
|
|
@@ -7082,34 +7768,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
7082
7768
|
if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
|
|
7083
7769
|
const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
|
|
7084
7770
|
const rest = specifier.slice(dots).replace(/\./g, "/");
|
|
7085
|
-
let base =
|
|
7086
|
-
for (let up = 1; up < dots; up += 1) base =
|
|
7087
|
-
const joined2 = rest ?
|
|
7771
|
+
let base = path17.posix.dirname(fromFile);
|
|
7772
|
+
for (let up = 1; up < dots; up += 1) base = path17.posix.dirname(base);
|
|
7773
|
+
const joined2 = rest ? path17.posix.normalize(path17.posix.join(base, rest)) : base;
|
|
7088
7774
|
return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
|
|
7089
7775
|
}
|
|
7090
7776
|
if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
7091
|
-
const joined2 =
|
|
7092
|
-
|
|
7777
|
+
const joined2 = path17.posix.normalize(
|
|
7778
|
+
path17.posix.join(path17.posix.dirname(fromFile), specifier)
|
|
7093
7779
|
);
|
|
7094
7780
|
return firstOf([`${joined2}.rb`, joined2]);
|
|
7095
7781
|
}
|
|
7096
7782
|
if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
7097
|
-
const joined2 =
|
|
7098
|
-
|
|
7783
|
+
const joined2 = path17.posix.normalize(
|
|
7784
|
+
path17.posix.join(path17.posix.dirname(fromFile), specifier)
|
|
7099
7785
|
);
|
|
7100
7786
|
return exact(joined2);
|
|
7101
7787
|
}
|
|
7102
7788
|
if (extension === ".dart" && !specifier.includes(":")) {
|
|
7103
|
-
const joined2 =
|
|
7104
|
-
|
|
7789
|
+
const joined2 = path17.posix.normalize(
|
|
7790
|
+
path17.posix.join(path17.posix.dirname(fromFile), specifier)
|
|
7105
7791
|
);
|
|
7106
7792
|
return firstOf([joined2, `${joined2}.dart`]);
|
|
7107
7793
|
}
|
|
7108
7794
|
if (!RELATIVE_SPECIFIER.test(specifier)) {
|
|
7109
7795
|
return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
|
|
7110
7796
|
}
|
|
7111
|
-
const joined =
|
|
7112
|
-
|
|
7797
|
+
const joined = path17.posix.normalize(
|
|
7798
|
+
path17.posix.join(path17.posix.dirname(fromFile), specifier)
|
|
7113
7799
|
);
|
|
7114
7800
|
return lookupPath(joined);
|
|
7115
7801
|
}
|
|
@@ -7133,13 +7819,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
|
|
|
7133
7819
|
if (captured === null) continue;
|
|
7134
7820
|
for (const target of rule.targets) {
|
|
7135
7821
|
const substituted = target.split("*").join(captured);
|
|
7136
|
-
const base = config.baseUrl === null ? substituted :
|
|
7137
|
-
const hit = lookupPath(
|
|
7822
|
+
const base = config.baseUrl === null ? substituted : path17.posix.join(config.baseUrl, substituted);
|
|
7823
|
+
const hit = lookupPath(path17.posix.normalize(base));
|
|
7138
7824
|
if (hit) return hit;
|
|
7139
7825
|
}
|
|
7140
7826
|
}
|
|
7141
7827
|
if (config.baseUrl !== null) {
|
|
7142
|
-
return lookupPath(
|
|
7828
|
+
return lookupPath(path17.posix.normalize(path17.posix.join(config.baseUrl, specifier)));
|
|
7143
7829
|
}
|
|
7144
7830
|
return null;
|
|
7145
7831
|
}
|
|
@@ -7150,6 +7836,58 @@ function importsChangedFile(importerPath, imports, changedPaths, resolver) {
|
|
|
7150
7836
|
}
|
|
7151
7837
|
return false;
|
|
7152
7838
|
}
|
|
7839
|
+
var SUMMARY_LIMIT = 400;
|
|
7840
|
+
var MAX_RELEASES = 2;
|
|
7841
|
+
function readProjectOverview(cwd) {
|
|
7842
|
+
return {
|
|
7843
|
+
...readDescription(cwd),
|
|
7844
|
+
...readSummary(cwd),
|
|
7845
|
+
releases: readReleases(cwd)
|
|
7846
|
+
};
|
|
7847
|
+
}
|
|
7848
|
+
function readText(file) {
|
|
7849
|
+
try {
|
|
7850
|
+
return fs16.readFileSync(file, "utf8");
|
|
7851
|
+
} catch {
|
|
7852
|
+
return null;
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7855
|
+
function readDescription(cwd) {
|
|
7856
|
+
const raw = readText(path17.join(cwd, "package.json"));
|
|
7857
|
+
if (raw === null) return {};
|
|
7858
|
+
try {
|
|
7859
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
7860
|
+
return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
|
|
7861
|
+
} catch {
|
|
7862
|
+
return {};
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
function readSummary(cwd) {
|
|
7866
|
+
const raw = readText(path17.join(cwd, "README.md"));
|
|
7867
|
+
if (raw === null) return {};
|
|
7868
|
+
const lines = raw.split(/\r?\n/);
|
|
7869
|
+
const paragraph = [];
|
|
7870
|
+
for (const line of lines) {
|
|
7871
|
+
const trimmed = line.trim();
|
|
7872
|
+
if (paragraph.length === 0) {
|
|
7873
|
+
if (trimmed.length === 0) continue;
|
|
7874
|
+
if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
|
|
7875
|
+
if (/^\[[^\]]+\]:/.test(trimmed)) continue;
|
|
7876
|
+
} else if (trimmed.length === 0 || /^#/.test(trimmed)) {
|
|
7877
|
+
break;
|
|
7878
|
+
}
|
|
7879
|
+
paragraph.push(trimmed);
|
|
7880
|
+
}
|
|
7881
|
+
const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
|
|
7882
|
+
if (summary.length === 0) return {};
|
|
7883
|
+
return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
|
|
7884
|
+
}
|
|
7885
|
+
function readReleases(cwd) {
|
|
7886
|
+
const raw = readText(path17.join(cwd, "CHANGELOG.md"));
|
|
7887
|
+
if (raw === null) return [];
|
|
7888
|
+
const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
|
|
7889
|
+
return headings.slice(0, MAX_RELEASES);
|
|
7890
|
+
}
|
|
7153
7891
|
var LANGUAGE_BY_EXTENSION = {
|
|
7154
7892
|
".ts": "typescript",
|
|
7155
7893
|
".mts": "typescript",
|
|
@@ -7207,10 +7945,10 @@ var LANGUAGE_BY_BASENAME = {
|
|
|
7207
7945
|
};
|
|
7208
7946
|
function detectLanguage(filePath) {
|
|
7209
7947
|
const normalized = filePath.replace(/\\/g, "/");
|
|
7210
|
-
const base =
|
|
7948
|
+
const base = path17.posix.basename(normalized);
|
|
7211
7949
|
if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
|
|
7212
7950
|
if (base === ".env" || base.startsWith(".env.")) return "dotenv";
|
|
7213
|
-
const ext =
|
|
7951
|
+
const ext = path17.posix.extname(base).toLowerCase();
|
|
7214
7952
|
return LANGUAGE_BY_EXTENSION[ext] ?? "text";
|
|
7215
7953
|
}
|
|
7216
7954
|
function maskedPath(value, secretRules) {
|
|
@@ -7218,33 +7956,33 @@ function maskedPath(value, secretRules) {
|
|
|
7218
7956
|
}
|
|
7219
7957
|
function confineToDirectory(directory, filename) {
|
|
7220
7958
|
if (filename.includes("\0")) return null;
|
|
7221
|
-
if (
|
|
7222
|
-
const base =
|
|
7223
|
-
const resolved =
|
|
7959
|
+
if (path17.isAbsolute(filename)) return null;
|
|
7960
|
+
const base = path17.resolve(directory);
|
|
7961
|
+
const resolved = path17.resolve(base, filename);
|
|
7224
7962
|
const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
|
|
7225
|
-
const prefix = caseInsensitive ? `${base}${
|
|
7963
|
+
const prefix = caseInsensitive ? `${base}${path17.sep}`.toLowerCase() : `${base}${path17.sep}`;
|
|
7226
7964
|
const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
|
|
7227
7965
|
return candidate.startsWith(prefix) ? resolved : null;
|
|
7228
7966
|
}
|
|
7229
7967
|
function findStagingDirectory(config) {
|
|
7230
|
-
const tmpDir =
|
|
7968
|
+
const tmpDir = path17.resolve(config.cwd, config.tmpDir);
|
|
7231
7969
|
let entries;
|
|
7232
7970
|
try {
|
|
7233
|
-
entries =
|
|
7971
|
+
entries = fs16.readdirSync(tmpDir);
|
|
7234
7972
|
} catch {
|
|
7235
7973
|
return null;
|
|
7236
7974
|
}
|
|
7237
7975
|
const runs = entries.filter((name) => name.startsWith("run-")).sort();
|
|
7238
7976
|
const newest = runs[runs.length - 1];
|
|
7239
|
-
return newest ?
|
|
7977
|
+
return newest ? path17.join(tmpDir, newest) : null;
|
|
7240
7978
|
}
|
|
7241
7979
|
function describeMissingManifest(config, manifestPath) {
|
|
7242
|
-
const outDir =
|
|
7243
|
-
const markerPath =
|
|
7980
|
+
const outDir = path17.resolve(config.cwd, config.outDir);
|
|
7981
|
+
const markerPath = path17.join(outDir, ".codebase-snapshot");
|
|
7244
7982
|
let marker2 = null;
|
|
7245
7983
|
try {
|
|
7246
|
-
if (
|
|
7247
|
-
const parsed = JSON.parse(
|
|
7984
|
+
if (fs16.existsSync(markerPath)) {
|
|
7985
|
+
const parsed = JSON.parse(fs16.readFileSync(markerPath, "utf8"));
|
|
7248
7986
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7249
7987
|
marker2 = parsed;
|
|
7250
7988
|
}
|
|
@@ -7279,13 +8017,13 @@ function sha256Hex(buffer) {
|
|
|
7279
8017
|
return crypto2.createHash("sha256").update(buffer).digest("hex");
|
|
7280
8018
|
}
|
|
7281
8019
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
7282
|
-
const absolutePath =
|
|
8020
|
+
const absolutePath = path17.join(cwd, relativePath);
|
|
7283
8021
|
try {
|
|
7284
|
-
const stats =
|
|
8022
|
+
const stats = fs16.statSync(absolutePath);
|
|
7285
8023
|
if (!stats.isFile()) return false;
|
|
7286
8024
|
if (isBinaryExtension(absolutePath)) return false;
|
|
7287
8025
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
7288
|
-
return !decodeText(
|
|
8026
|
+
return !decodeText(fs16.readFileSync(absolutePath)).binary;
|
|
7289
8027
|
} catch {
|
|
7290
8028
|
return false;
|
|
7291
8029
|
}
|
|
@@ -7297,7 +8035,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
|
7297
8035
|
]);
|
|
7298
8036
|
function isConfinedRelative(value) {
|
|
7299
8037
|
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
7300
|
-
if (
|
|
8038
|
+
if (path17.isAbsolute(value)) return false;
|
|
7301
8039
|
return !value.split("/").includes("..");
|
|
7302
8040
|
}
|
|
7303
8041
|
function describeManifestShapeProblem(value) {
|
|
@@ -7465,7 +8203,7 @@ function describeManifestShapeProblem(value) {
|
|
|
7465
8203
|
if (typeof filename !== "string" || filename.trim() === "") {
|
|
7466
8204
|
return 'a "parts" entry has no "filename"';
|
|
7467
8205
|
}
|
|
7468
|
-
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." ||
|
|
8206
|
+
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path17.isAbsolute(filename)) {
|
|
7469
8207
|
return 'a "parts" entry "filename" must be a bare filename inside parts/';
|
|
7470
8208
|
}
|
|
7471
8209
|
if (currentSchema) {
|
|
@@ -7491,8 +8229,8 @@ function describeManifestShapeProblem(value) {
|
|
|
7491
8229
|
function validateSnapshot(configInput) {
|
|
7492
8230
|
assertUsableConfigInput(configInput);
|
|
7493
8231
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
7494
|
-
const manifestPath =
|
|
7495
|
-
if (!
|
|
8232
|
+
const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
|
|
8233
|
+
if (!fs16.existsSync(manifestPath)) {
|
|
7496
8234
|
return {
|
|
7497
8235
|
valid: false,
|
|
7498
8236
|
manifestPresent: false,
|
|
@@ -7503,7 +8241,7 @@ function validateSnapshot(configInput) {
|
|
|
7503
8241
|
}
|
|
7504
8242
|
let manifest;
|
|
7505
8243
|
try {
|
|
7506
|
-
manifest = JSON.parse(
|
|
8244
|
+
manifest = JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
|
|
7507
8245
|
} catch (err) {
|
|
7508
8246
|
return {
|
|
7509
8247
|
valid: false,
|
|
@@ -7525,7 +8263,7 @@ function validateSnapshot(configInput) {
|
|
|
7525
8263
|
}
|
|
7526
8264
|
const drift = emptyDrift();
|
|
7527
8265
|
const warnings = [];
|
|
7528
|
-
const snapshotDir =
|
|
8266
|
+
const snapshotDir = path17.resolve(config.cwd, config.outDir);
|
|
7529
8267
|
const unreadableSkips = manifest.skipped.filter(
|
|
7530
8268
|
(entry) => entry.reason === "missing" || entry.reason === "read-error"
|
|
7531
8269
|
);
|
|
@@ -7628,7 +8366,7 @@ function validateSnapshot(configInput) {
|
|
|
7628
8366
|
);
|
|
7629
8367
|
return importsChangedFile(
|
|
7630
8368
|
diskFile,
|
|
7631
|
-
importsOfFile(diskFile,
|
|
8369
|
+
importsOfFile(diskFile, path17.join(config.cwd, diskFile)),
|
|
7632
8370
|
unchangedScope,
|
|
7633
8371
|
dependentResolver
|
|
7634
8372
|
);
|
|
@@ -7646,7 +8384,7 @@ function validateSnapshot(configInput) {
|
|
|
7646
8384
|
// own output directory as a set of files missing from the snapshot, so a correct
|
|
7647
8385
|
// snapshot was reported as drifting.
|
|
7648
8386
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7649
|
-
(directory) =>
|
|
8387
|
+
(directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7650
8388
|
).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
|
|
7651
8389
|
});
|
|
7652
8390
|
for (const diskFile of collection.files) {
|
|
@@ -7672,7 +8410,7 @@ function validateSnapshot(configInput) {
|
|
|
7672
8410
|
}
|
|
7673
8411
|
let diskHash;
|
|
7674
8412
|
try {
|
|
7675
|
-
diskHash = sha256Hex(
|
|
8413
|
+
diskHash = sha256Hex(fs16.readFileSync(path17.join(config.cwd, diskFile)));
|
|
7676
8414
|
} catch (err) {
|
|
7677
8415
|
if (err.code === "ENOENT") {
|
|
7678
8416
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -7696,7 +8434,7 @@ function validateSnapshot(configInput) {
|
|
|
7696
8434
|
}
|
|
7697
8435
|
let statFailure = null;
|
|
7698
8436
|
try {
|
|
7699
|
-
|
|
8437
|
+
fs16.statSync(confined);
|
|
7700
8438
|
} catch (err) {
|
|
7701
8439
|
statFailure = err;
|
|
7702
8440
|
}
|
|
@@ -7716,7 +8454,7 @@ function validateSnapshot(configInput) {
|
|
|
7716
8454
|
...Object.values(config.budgets.byLayer)
|
|
7717
8455
|
);
|
|
7718
8456
|
const partNames = /* @__PURE__ */ new Set();
|
|
7719
|
-
const partsDir =
|
|
8457
|
+
const partsDir = path17.join(snapshotDir, "parts");
|
|
7720
8458
|
for (const part of manifest.parts) {
|
|
7721
8459
|
if (!part || typeof part.filename !== "string") continue;
|
|
7722
8460
|
partNames.add(part.filename);
|
|
@@ -7731,7 +8469,7 @@ function validateSnapshot(configInput) {
|
|
|
7731
8469
|
}
|
|
7732
8470
|
let buffer;
|
|
7733
8471
|
try {
|
|
7734
|
-
buffer =
|
|
8472
|
+
buffer = fs16.readFileSync(partPath);
|
|
7735
8473
|
} catch {
|
|
7736
8474
|
drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
|
|
7737
8475
|
continue;
|
|
@@ -8048,7 +8786,8 @@ function validateSnapshot(configInput) {
|
|
|
8048
8786
|
);
|
|
8049
8787
|
}
|
|
8050
8788
|
}
|
|
8051
|
-
|
|
8789
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
8790
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
8052
8791
|
totalsMismatches.push(
|
|
8053
8792
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
8054
8793
|
);
|
|
@@ -8077,6 +8816,7 @@ function validateSnapshot(configInput) {
|
|
|
8077
8816
|
}
|
|
8078
8817
|
const declaredArtifacts = [
|
|
8079
8818
|
["README.md", manifest.artifacts?.readme],
|
|
8819
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
8080
8820
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
8081
8821
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
8082
8822
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -8085,11 +8825,11 @@ function validateSnapshot(configInput) {
|
|
|
8085
8825
|
];
|
|
8086
8826
|
for (const [key, artifact] of declaredArtifacts) {
|
|
8087
8827
|
if (!artifact) continue;
|
|
8088
|
-
const artifactPath =
|
|
8828
|
+
const artifactPath = path17.join(snapshotDir, ...key.split("/"));
|
|
8089
8829
|
let buffer;
|
|
8090
8830
|
try {
|
|
8091
|
-
if (!
|
|
8092
|
-
buffer =
|
|
8831
|
+
if (!fs16.statSync(artifactPath).isFile()) throw new Error("not a regular file");
|
|
8832
|
+
buffer = fs16.readFileSync(artifactPath);
|
|
8093
8833
|
} catch {
|
|
8094
8834
|
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
8095
8835
|
continue;
|
|
@@ -8102,9 +8842,9 @@ function validateSnapshot(configInput) {
|
|
|
8102
8842
|
for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
8103
8843
|
const target = match[1].split("#")[0];
|
|
8104
8844
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
8105
|
-
const resolved =
|
|
8106
|
-
const relative11 =
|
|
8107
|
-
if (relative11.startsWith("..") ||
|
|
8845
|
+
const resolved = path17.resolve(snapshotDir, "reports", target);
|
|
8846
|
+
const relative11 = path17.relative(snapshotDir, resolved);
|
|
8847
|
+
if (relative11.startsWith("..") || path17.isAbsolute(relative11) || !fs16.existsSync(resolved)) {
|
|
8108
8848
|
drift.partIssues.push({
|
|
8109
8849
|
part: key,
|
|
8110
8850
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -8117,7 +8857,7 @@ function validateSnapshot(configInput) {
|
|
|
8117
8857
|
if (sarifArtifact) {
|
|
8118
8858
|
const sarifKey = "reports/audit.sarif";
|
|
8119
8859
|
try {
|
|
8120
|
-
const buffer =
|
|
8860
|
+
const buffer = fs16.readFileSync(path17.join(snapshotDir, "reports", "audit.sarif"));
|
|
8121
8861
|
if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
|
|
8122
8862
|
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
8123
8863
|
}
|
|
@@ -8235,17 +8975,17 @@ function isNewer(candidate, current) {
|
|
|
8235
8975
|
}
|
|
8236
8976
|
function cacheDirectory(env = process.env, platform = process.platform) {
|
|
8237
8977
|
if (platform === "win32") {
|
|
8238
|
-
const base2 = env.LOCALAPPDATA ??
|
|
8239
|
-
return
|
|
8978
|
+
const base2 = env.LOCALAPPDATA ?? path17.join(os.homedir(), "AppData", "Local");
|
|
8979
|
+
return path17.join(base2, "codebase-snapshot");
|
|
8240
8980
|
}
|
|
8241
8981
|
if (platform === "darwin") {
|
|
8242
|
-
return
|
|
8982
|
+
return path17.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
|
|
8243
8983
|
}
|
|
8244
|
-
const base = env.XDG_CACHE_HOME ??
|
|
8245
|
-
return
|
|
8984
|
+
const base = env.XDG_CACHE_HOME ?? path17.join(os.homedir(), ".cache");
|
|
8985
|
+
return path17.join(base, "codebase-snapshot");
|
|
8246
8986
|
}
|
|
8247
8987
|
function cacheFilePath(env = process.env) {
|
|
8248
|
-
return
|
|
8988
|
+
return path17.join(cacheDirectory(env), "update-check.json");
|
|
8249
8989
|
}
|
|
8250
8990
|
function shouldCheck(argv, env) {
|
|
8251
8991
|
const disabled = ["1", "true", "yes"].includes(
|
|
@@ -8275,7 +9015,7 @@ function shouldCheck(argv, env) {
|
|
|
8275
9015
|
function readCache(file) {
|
|
8276
9016
|
let raw;
|
|
8277
9017
|
try {
|
|
8278
|
-
raw =
|
|
9018
|
+
raw = fs16.readFileSync(file, "utf8");
|
|
8279
9019
|
} catch {
|
|
8280
9020
|
return null;
|
|
8281
9021
|
}
|
|
@@ -8292,8 +9032,8 @@ function readCache(file) {
|
|
|
8292
9032
|
}
|
|
8293
9033
|
function writeCache(file, entry) {
|
|
8294
9034
|
try {
|
|
8295
|
-
|
|
8296
|
-
|
|
9035
|
+
fs16.mkdirSync(path17.dirname(file), { recursive: true });
|
|
9036
|
+
fs16.writeFileSync(file, `${JSON.stringify(entry)}
|
|
8297
9037
|
`, "utf8");
|
|
8298
9038
|
} catch {
|
|
8299
9039
|
}
|
|
@@ -8392,13 +9132,13 @@ function describeMatcher(matcher) {
|
|
|
8392
9132
|
return String(matcher);
|
|
8393
9133
|
}
|
|
8394
9134
|
function normalizeTarget(cwd, target) {
|
|
8395
|
-
const resolvedCwd =
|
|
8396
|
-
const absolute =
|
|
8397
|
-
const relative11 =
|
|
8398
|
-
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${
|
|
9135
|
+
const resolvedCwd = path17.resolve(cwd);
|
|
9136
|
+
const absolute = path17.resolve(resolvedCwd, target);
|
|
9137
|
+
const relative11 = path17.relative(resolvedCwd, absolute);
|
|
9138
|
+
if (relative11 === "" || relative11 === ".." || relative11.startsWith(`..${path17.sep}`) || path17.isAbsolute(relative11)) {
|
|
8399
9139
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
8400
9140
|
}
|
|
8401
|
-
return { relative: relative11.split(
|
|
9141
|
+
return { relative: relative11.split(path17.sep).join("/"), outsideRoot: false };
|
|
8402
9142
|
}
|
|
8403
9143
|
function findRuleMatch(rules, relativePath) {
|
|
8404
9144
|
return rules.find(
|
|
@@ -8417,9 +9157,9 @@ function findRecordedAncestor(skipped, relative11, maskedPath2) {
|
|
|
8417
9157
|
return nearest;
|
|
8418
9158
|
}
|
|
8419
9159
|
function readManifest2(config) {
|
|
8420
|
-
const manifestPath =
|
|
9160
|
+
const manifestPath = path17.resolve(config.cwd, config.outDir, "manifest.json");
|
|
8421
9161
|
try {
|
|
8422
|
-
return JSON.parse(
|
|
9162
|
+
return JSON.parse(fs16.readFileSync(manifestPath, "utf8"));
|
|
8423
9163
|
} catch {
|
|
8424
9164
|
return null;
|
|
8425
9165
|
}
|
|
@@ -8437,10 +9177,10 @@ function explainPath(config, target) {
|
|
|
8437
9177
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
8438
9178
|
};
|
|
8439
9179
|
}
|
|
8440
|
-
const absolute =
|
|
9180
|
+
const absolute = path17.join(config.cwd, relative11);
|
|
8441
9181
|
const result = {
|
|
8442
9182
|
path: maskedPath2,
|
|
8443
|
-
exists:
|
|
9183
|
+
exists: fs16.existsSync(absolute),
|
|
8444
9184
|
included: false
|
|
8445
9185
|
};
|
|
8446
9186
|
const collection = collectFiles(config.cwd, {
|
|
@@ -8454,7 +9194,7 @@ function explainPath(config, target) {
|
|
|
8454
9194
|
// Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
|
|
8455
9195
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
8456
9196
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
8457
|
-
(directory) =>
|
|
9197
|
+
(directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
8458
9198
|
).filter((relative12) => relative12.length > 0 && !relative12.startsWith(".."))
|
|
8459
9199
|
});
|
|
8460
9200
|
if (!collection.files.includes(relative11)) {
|
|
@@ -8519,7 +9259,7 @@ function explainPath(config, target) {
|
|
|
8519
9259
|
}
|
|
8520
9260
|
let sizeOnDisk = null;
|
|
8521
9261
|
try {
|
|
8522
|
-
sizeOnDisk =
|
|
9262
|
+
sizeOnDisk = fs16.statSync(absolute).size;
|
|
8523
9263
|
} catch {
|
|
8524
9264
|
sizeOnDisk = null;
|
|
8525
9265
|
}
|
|
@@ -8529,10 +9269,10 @@ function explainPath(config, target) {
|
|
|
8529
9269
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
8530
9270
|
return result;
|
|
8531
9271
|
}
|
|
8532
|
-
if (
|
|
9272
|
+
if (fs16.existsSync(absolute) && fs16.statSync(absolute).isFile()) {
|
|
8533
9273
|
let buffer;
|
|
8534
9274
|
try {
|
|
8535
|
-
buffer =
|
|
9275
|
+
buffer = fs16.readFileSync(absolute);
|
|
8536
9276
|
} catch (err) {
|
|
8537
9277
|
result.included = false;
|
|
8538
9278
|
result.reason = "read-error";
|
|
@@ -8822,14 +9562,14 @@ function compareManifests(before, after, secretRules) {
|
|
|
8822
9562
|
function loadManifest(target) {
|
|
8823
9563
|
let isDirectory;
|
|
8824
9564
|
try {
|
|
8825
|
-
isDirectory =
|
|
9565
|
+
isDirectory = fs16.statSync(target).isDirectory();
|
|
8826
9566
|
} catch {
|
|
8827
9567
|
throw new Error(`No snapshot found at ${target}: the path does not exist.`);
|
|
8828
9568
|
}
|
|
8829
|
-
const manifestPath = isDirectory ?
|
|
9569
|
+
const manifestPath = isDirectory ? path17.join(target, "manifest.json") : target;
|
|
8830
9570
|
let raw;
|
|
8831
9571
|
try {
|
|
8832
|
-
raw =
|
|
9572
|
+
raw = fs16.readFileSync(manifestPath, "utf8");
|
|
8833
9573
|
} catch {
|
|
8834
9574
|
throw new Error(`Could not read a manifest at ${manifestPath}.`);
|
|
8835
9575
|
}
|
|
@@ -8931,15 +9671,15 @@ function canonicalIgnorePattern(line) {
|
|
|
8931
9671
|
function appendGitignoreEntries(cwd, entries) {
|
|
8932
9672
|
const wanted = [...new Set(entries)].filter((entry) => entry.trim().length > 0);
|
|
8933
9673
|
if (wanted.length === 0) return { added: [], note: null };
|
|
8934
|
-
const ignorePath =
|
|
9674
|
+
const ignorePath = path17.join(cwd, ".gitignore");
|
|
8935
9675
|
const manual = `Add ${wanted.map((entry) => `"${entry}"`).join(" and ")} to your .gitignore yourself.`;
|
|
8936
9676
|
let decoded = { text: "", bom: Buffer.alloc(0), encoding: "utf8" };
|
|
8937
9677
|
try {
|
|
8938
|
-
if (
|
|
8939
|
-
if (
|
|
9678
|
+
if (fs16.existsSync(ignorePath)) {
|
|
9679
|
+
if (fs16.statSync(ignorePath).isDirectory()) {
|
|
8940
9680
|
return { added: [], note: `${ignorePath} is a directory, so it was not updated. ${manual}` };
|
|
8941
9681
|
}
|
|
8942
|
-
const read = decodeGitignore(
|
|
9682
|
+
const read = decodeGitignore(fs16.readFileSync(ignorePath));
|
|
8943
9683
|
if (read === null) {
|
|
8944
9684
|
return {
|
|
8945
9685
|
added: [],
|
|
@@ -8961,7 +9701,7 @@ function appendGitignoreEntries(cwd, entries) {
|
|
|
8961
9701
|
const newline = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
8962
9702
|
const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : newline;
|
|
8963
9703
|
try {
|
|
8964
|
-
|
|
9704
|
+
fs16.writeFileSync(
|
|
8965
9705
|
ignorePath,
|
|
8966
9706
|
encodeGitignore(decoded, `${existing}${prefix}${added.join(newline)}${newline}`)
|
|
8967
9707
|
);
|
|
@@ -8971,7 +9711,7 @@ function appendGitignoreEntries(cwd, entries) {
|
|
|
8971
9711
|
return { added, note: null };
|
|
8972
9712
|
}
|
|
8973
9713
|
function gitignorePath(cwd, filePath) {
|
|
8974
|
-
return
|
|
9714
|
+
return path17.relative(cwd, filePath).split(path17.sep).join("/");
|
|
8975
9715
|
}
|
|
8976
9716
|
|
|
8977
9717
|
// src/wizard/config-template.ts
|
|
@@ -8989,6 +9729,7 @@ var DEFAULT_ANSWERS = {
|
|
|
8989
9729
|
excludePatterns: [],
|
|
8990
9730
|
artifacts: {
|
|
8991
9731
|
readme: true,
|
|
9732
|
+
prompt: true,
|
|
8992
9733
|
manifest: true,
|
|
8993
9734
|
parts: true,
|
|
8994
9735
|
navigation: true,
|
|
@@ -9105,6 +9846,7 @@ function renderConfig(answers) {
|
|
|
9105
9846
|
// \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
|
|
9106
9847
|
artifacts: {
|
|
9107
9848
|
readme: ${artifacts.readme}, // README.md
|
|
9849
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
9108
9850
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
9109
9851
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
9110
9852
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -9120,6 +9862,15 @@ function renderConfig(answers) {
|
|
|
9120
9862
|
includeMonolith: ${artifacts.monolith},
|
|
9121
9863
|
|
|
9122
9864
|
// \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
|
|
9865
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
9866
|
+
// attachmentSlots: 10,
|
|
9867
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
9868
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
9869
|
+
// maxParts: 10,
|
|
9870
|
+
// The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
|
|
9871
|
+
// brief: "docs/brief.md",
|
|
9872
|
+
// Which job the brief is written for: audit, review or explain.
|
|
9873
|
+
// promptTask: "audit",
|
|
9123
9874
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
9124
9875
|
hooks: {},
|
|
9125
9876
|
};
|
|
@@ -9514,7 +10265,7 @@ function parsePackageJson(raw) {
|
|
|
9514
10265
|
}
|
|
9515
10266
|
function readPackageJson(cwd) {
|
|
9516
10267
|
try {
|
|
9517
|
-
return parsePackageJson(
|
|
10268
|
+
return parsePackageJson(fs16.readFileSync(path17.join(cwd, "package.json"), "utf8"));
|
|
9518
10269
|
} catch {
|
|
9519
10270
|
return null;
|
|
9520
10271
|
}
|
|
@@ -9551,7 +10302,7 @@ function artifactAnswers(options) {
|
|
|
9551
10302
|
}
|
|
9552
10303
|
function topLevelDirs(cwd) {
|
|
9553
10304
|
try {
|
|
9554
|
-
return
|
|
10305
|
+
return fs16.readdirSync(cwd, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").map((entry) => entry.name).sort();
|
|
9555
10306
|
} catch {
|
|
9556
10307
|
return [];
|
|
9557
10308
|
}
|
|
@@ -9566,7 +10317,7 @@ function writeFileOrExplain(target, content) {
|
|
|
9566
10317
|
try {
|
|
9567
10318
|
let stats = null;
|
|
9568
10319
|
try {
|
|
9569
|
-
stats =
|
|
10320
|
+
stats = fs16.lstatSync(target);
|
|
9570
10321
|
} catch {
|
|
9571
10322
|
stats = null;
|
|
9572
10323
|
}
|
|
@@ -9581,12 +10332,12 @@ function writeFileOrExplain(target, content) {
|
|
|
9581
10332
|
);
|
|
9582
10333
|
}
|
|
9583
10334
|
const temporary = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
9584
|
-
|
|
10335
|
+
fs16.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx" });
|
|
9585
10336
|
try {
|
|
9586
|
-
|
|
10337
|
+
fs16.renameSync(temporary, target);
|
|
9587
10338
|
} catch (err) {
|
|
9588
10339
|
try {
|
|
9589
|
-
|
|
10340
|
+
fs16.unlinkSync(temporary);
|
|
9590
10341
|
} catch {
|
|
9591
10342
|
}
|
|
9592
10343
|
throw err;
|
|
@@ -9634,19 +10385,19 @@ function serializePackageJson(raw, value) {
|
|
|
9634
10385
|
return `${bom}${text2}${raw.endsWith("\n") ? crlf ? "\r\n" : "\n" : ""}`;
|
|
9635
10386
|
}
|
|
9636
10387
|
function updatePackageJson(cwd, notes) {
|
|
9637
|
-
const packagePath =
|
|
10388
|
+
const packagePath = path17.join(cwd, "package.json");
|
|
9638
10389
|
const unchanged = {
|
|
9639
10390
|
scripts: [],
|
|
9640
10391
|
dependency: { name: GENERATOR_NAME, range: null, added: false }
|
|
9641
10392
|
};
|
|
9642
|
-
if (!
|
|
10393
|
+
if (!fs16.existsSync(packagePath)) {
|
|
9643
10394
|
notes.push("No package.json found, so npm scripts and the devDependency were not added.");
|
|
9644
10395
|
return unchanged;
|
|
9645
10396
|
}
|
|
9646
10397
|
let raw;
|
|
9647
10398
|
let parsed;
|
|
9648
10399
|
try {
|
|
9649
|
-
raw =
|
|
10400
|
+
raw = fs16.readFileSync(packagePath, "utf8");
|
|
9650
10401
|
parsed = parsePackageJson(raw);
|
|
9651
10402
|
} catch {
|
|
9652
10403
|
notes.push("Could not parse package.json; npm scripts and the devDependency were not added.");
|
|
@@ -9721,8 +10472,8 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
|
9721
10472
|
const entries = [];
|
|
9722
10473
|
for (const directory of [outDir, tmpDir]) {
|
|
9723
10474
|
if (directory === null) continue;
|
|
9724
|
-
const relative11 =
|
|
9725
|
-
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") ||
|
|
10475
|
+
const relative11 = path17.relative(cwd, path17.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
10476
|
+
if (relative11 === "" || relative11 === "." || relative11.startsWith("..") || path17.isAbsolute(relative11)) {
|
|
9726
10477
|
continue;
|
|
9727
10478
|
}
|
|
9728
10479
|
entries.push(`/${relative11}/`);
|
|
@@ -9810,6 +10561,7 @@ async function runInit(options) {
|
|
|
9810
10561
|
let lastScope = "all";
|
|
9811
10562
|
const artifactChoices = [
|
|
9812
10563
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
10564
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
9813
10565
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
9814
10566
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
9815
10567
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -9973,7 +10725,7 @@ async function runInit(options) {
|
|
|
9973
10725
|
const configText = renderConfig(answers);
|
|
9974
10726
|
const preferredName = chooseConfigFileName(options.cwd);
|
|
9975
10727
|
const presentConfigs = CONFIG_CANDIDATES.filter(
|
|
9976
|
-
(name) =>
|
|
10728
|
+
(name) => fs16.existsSync(path17.join(options.cwd, name))
|
|
9977
10729
|
);
|
|
9978
10730
|
const present = presentConfigs[0] ?? null;
|
|
9979
10731
|
if (presentConfigs.length > 1) {
|
|
@@ -9982,7 +10734,7 @@ async function runInit(options) {
|
|
|
9982
10734
|
);
|
|
9983
10735
|
}
|
|
9984
10736
|
const configName = present !== null && options.force ? present : preferredName;
|
|
9985
|
-
const configPath =
|
|
10737
|
+
const configPath = path17.join(options.cwd, configName);
|
|
9986
10738
|
const reused = present !== null && options.force !== true && options.reuseConfig === true;
|
|
9987
10739
|
if (reused) notes.push(`Kept the existing ${present} instead of writing a new one.`);
|
|
9988
10740
|
if (options.dryRun) {
|
|
@@ -10016,7 +10768,7 @@ async function runInit(options) {
|
|
|
10016
10768
|
'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.'
|
|
10017
10769
|
);
|
|
10018
10770
|
}
|
|
10019
|
-
if (
|
|
10771
|
+
if (fs16.existsSync(configPath) && !options.force && !reused) {
|
|
10020
10772
|
throw new Error(`${configName} already exists. Re-run with --force to replace it.`);
|
|
10021
10773
|
}
|
|
10022
10774
|
if (!reused) writeFileOrExplain(configPath, configText);
|
|
@@ -10042,9 +10794,9 @@ async function runInit(options) {
|
|
|
10042
10794
|
};
|
|
10043
10795
|
}
|
|
10044
10796
|
function describeTarget(cwd) {
|
|
10045
|
-
const relative11 =
|
|
10797
|
+
const relative11 = path17.relative(process.cwd(), cwd);
|
|
10046
10798
|
if (relative11 === "") return "this directory";
|
|
10047
|
-
if (relative11.startsWith("..") ||
|
|
10799
|
+
if (relative11.startsWith("..") || path17.isAbsolute(relative11)) return cwd;
|
|
10048
10800
|
return relative11;
|
|
10049
10801
|
}
|
|
10050
10802
|
function firstRunMessage(reason, cwd) {
|
|
@@ -10068,7 +10820,7 @@ function planFirstRun(facts) {
|
|
|
10068
10820
|
var NOT_CONTENT = /* @__PURE__ */ new Set([".git", ".hg", ".svn", ".bzr", ".DS_Store", "Thumbs.db"]);
|
|
10069
10821
|
function isEffectivelyEmpty(cwd) {
|
|
10070
10822
|
try {
|
|
10071
|
-
return
|
|
10823
|
+
return fs16.readdirSync(cwd).every((entry) => NOT_CONTENT.has(entry));
|
|
10072
10824
|
} catch {
|
|
10073
10825
|
return false;
|
|
10074
10826
|
}
|
|
@@ -10076,7 +10828,7 @@ function isEffectivelyEmpty(cwd) {
|
|
|
10076
10828
|
function hasPriorSnapshot(cwd, outDir) {
|
|
10077
10829
|
let parsed;
|
|
10078
10830
|
try {
|
|
10079
|
-
parsed = JSON.parse(
|
|
10831
|
+
parsed = JSON.parse(fs16.readFileSync(path17.join(cwd, outDir, ".codebase-snapshot"), "utf8"));
|
|
10080
10832
|
} catch {
|
|
10081
10833
|
return false;
|
|
10082
10834
|
}
|
|
@@ -10124,36 +10876,36 @@ fi
|
|
|
10124
10876
|
`;
|
|
10125
10877
|
}
|
|
10126
10878
|
function gitDirectory(cwd) {
|
|
10127
|
-
const dotGit =
|
|
10879
|
+
const dotGit = path17.join(cwd, ".git");
|
|
10128
10880
|
let stats;
|
|
10129
10881
|
try {
|
|
10130
|
-
stats =
|
|
10882
|
+
stats = fs16.statSync(dotGit);
|
|
10131
10883
|
} catch {
|
|
10132
10884
|
return null;
|
|
10133
10885
|
}
|
|
10134
10886
|
if (stats.isDirectory()) return dotGit;
|
|
10135
10887
|
if (!stats.isFile()) return null;
|
|
10136
10888
|
try {
|
|
10137
|
-
const contents =
|
|
10889
|
+
const contents = fs16.readFileSync(dotGit, "utf8");
|
|
10138
10890
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
10139
10891
|
if (!match) return null;
|
|
10140
10892
|
const target = match[1];
|
|
10141
|
-
const resolved =
|
|
10142
|
-
if (!
|
|
10143
|
-
if (isInside2(
|
|
10144
|
-
return isRegisteredWorktree(
|
|
10893
|
+
const resolved = path17.isAbsolute(target.trim()) ? target.trim() : path17.join(cwd, target.trim());
|
|
10894
|
+
if (!fs16.statSync(resolved).isDirectory()) return null;
|
|
10895
|
+
if (isInside2(path17.resolve(cwd), path17.resolve(resolved))) return resolved;
|
|
10896
|
+
return isRegisteredWorktree(path17.resolve(resolved), cwd) ? resolved : null;
|
|
10145
10897
|
} catch {
|
|
10146
10898
|
return null;
|
|
10147
10899
|
}
|
|
10148
10900
|
}
|
|
10149
10901
|
function isInside2(parent, child) {
|
|
10150
|
-
const relative11 =
|
|
10151
|
-
return relative11 === "" || !relative11.startsWith("..") && !
|
|
10902
|
+
const relative11 = path17.relative(parent, child);
|
|
10903
|
+
return relative11 === "" || !relative11.startsWith("..") && !path17.isAbsolute(relative11);
|
|
10152
10904
|
}
|
|
10153
10905
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
10154
10906
|
try {
|
|
10155
|
-
const back =
|
|
10156
|
-
return
|
|
10907
|
+
const back = fs16.readFileSync(path17.join(gitDir, "gitdir"), "utf8").trim();
|
|
10908
|
+
return path17.resolve(gitDir, back) === path17.join(path17.resolve(cwd), ".git");
|
|
10157
10909
|
} catch {
|
|
10158
10910
|
return false;
|
|
10159
10911
|
}
|
|
@@ -10174,10 +10926,10 @@ function gitOutput(cwd, args) {
|
|
|
10174
10926
|
function configuredHooksDirectory(cwd) {
|
|
10175
10927
|
const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
|
|
10176
10928
|
if (hooks === null) return null;
|
|
10177
|
-
const resolved =
|
|
10929
|
+
const resolved = path17.resolve(cwd, hooks);
|
|
10178
10930
|
const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
|
|
10179
|
-
const commonDir = common === null ? null :
|
|
10180
|
-
if (isInside2(
|
|
10931
|
+
const commonDir = common === null ? null : path17.resolve(cwd, common);
|
|
10932
|
+
if (isInside2(path17.resolve(cwd), resolved)) return { dir: resolved };
|
|
10181
10933
|
if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
|
|
10182
10934
|
return {
|
|
10183
10935
|
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.`
|
|
@@ -10198,10 +10950,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10198
10950
|
]
|
|
10199
10951
|
};
|
|
10200
10952
|
}
|
|
10201
|
-
const hooksDir = configured === null ?
|
|
10202
|
-
const hookPath =
|
|
10953
|
+
const hooksDir = configured === null ? path17.join(gitDir, "hooks") : configured.dir;
|
|
10954
|
+
const hookPath = path17.join(hooksDir, "pre-commit");
|
|
10203
10955
|
try {
|
|
10204
|
-
|
|
10956
|
+
fs16.mkdirSync(hooksDir, { recursive: true });
|
|
10205
10957
|
} catch (err) {
|
|
10206
10958
|
return {
|
|
10207
10959
|
path: hookPath,
|
|
@@ -10211,7 +10963,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10211
10963
|
}
|
|
10212
10964
|
let existing = null;
|
|
10213
10965
|
try {
|
|
10214
|
-
existing =
|
|
10966
|
+
existing = fs16.readFileSync(hookPath, "utf8");
|
|
10215
10967
|
} catch {
|
|
10216
10968
|
existing = null;
|
|
10217
10969
|
}
|
|
@@ -10226,8 +10978,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10226
10978
|
};
|
|
10227
10979
|
}
|
|
10228
10980
|
try {
|
|
10229
|
-
|
|
10230
|
-
|
|
10981
|
+
fs16.writeFileSync(hookPath, hookScript(outDir), "utf8");
|
|
10982
|
+
fs16.chmodSync(hookPath, 493);
|
|
10231
10983
|
} catch (err) {
|
|
10232
10984
|
return {
|
|
10233
10985
|
path: hookPath,
|
|
@@ -10244,7 +10996,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10244
10996
|
};
|
|
10245
10997
|
}
|
|
10246
10998
|
function workerEntry(directory, isCjs) {
|
|
10247
|
-
const entry =
|
|
10999
|
+
const entry = path17.join(directory, isCjs ? "index.cjs" : "index.js");
|
|
10248
11000
|
return { path: entry, url: pathToFileURL(entry).href };
|
|
10249
11001
|
}
|
|
10250
11002
|
var WORKER_SOURCE = `
|
|
@@ -10311,7 +11063,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
10311
11063
|
resolve8(result);
|
|
10312
11064
|
};
|
|
10313
11065
|
const isCjs = typeof __dirname !== "undefined";
|
|
10314
|
-
const directory = isCjs ? __dirname :
|
|
11066
|
+
const directory = isCjs ? __dirname : path17.dirname(fileURLToPath(import.meta.url));
|
|
10315
11067
|
try {
|
|
10316
11068
|
worker = new Worker(WORKER_SOURCE, {
|
|
10317
11069
|
eval: true,
|
|
@@ -10346,23 +11098,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
|
10346
11098
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
10347
11099
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
10348
11100
|
var fileDerivationBytes = 0;
|
|
10349
|
-
function takeDerivation(
|
|
10350
|
-
const cached = FILE_DERIVATIONS.get(
|
|
11101
|
+
function takeDerivation(path18, hash, settings) {
|
|
11102
|
+
const cached = FILE_DERIVATIONS.get(path18);
|
|
10351
11103
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
10352
|
-
FILE_DERIVATIONS.delete(
|
|
10353
|
-
FILE_DERIVATIONS.set(
|
|
11104
|
+
FILE_DERIVATIONS.delete(path18);
|
|
11105
|
+
FILE_DERIVATIONS.set(path18, cached);
|
|
10354
11106
|
return cached;
|
|
10355
11107
|
}
|
|
10356
|
-
function rememberDerivation(
|
|
11108
|
+
function rememberDerivation(path18, hash, settings, derivation) {
|
|
10357
11109
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
10358
11110
|
const bytes = bodyBytes * 2 + 512;
|
|
10359
11111
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
10360
|
-
const previous = FILE_DERIVATIONS.get(
|
|
11112
|
+
const previous = FILE_DERIVATIONS.get(path18);
|
|
10361
11113
|
if (previous !== void 0) {
|
|
10362
|
-
FILE_DERIVATIONS.delete(
|
|
11114
|
+
FILE_DERIVATIONS.delete(path18);
|
|
10363
11115
|
fileDerivationBytes -= previous.bytes;
|
|
10364
11116
|
} else {
|
|
10365
|
-
FILE_DERIVATIONS.delete(
|
|
11117
|
+
FILE_DERIVATIONS.delete(path18);
|
|
10366
11118
|
}
|
|
10367
11119
|
while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
|
|
10368
11120
|
const oldest = FILE_DERIVATIONS.keys().next();
|
|
@@ -10371,7 +11123,7 @@ function rememberDerivation(path17, hash, settings, derivation) {
|
|
|
10371
11123
|
FILE_DERIVATIONS.delete(oldest.value);
|
|
10372
11124
|
if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
|
|
10373
11125
|
}
|
|
10374
|
-
FILE_DERIVATIONS.set(
|
|
11126
|
+
FILE_DERIVATIONS.set(path18, { ...derivation, hash, settings, bytes });
|
|
10375
11127
|
fileDerivationBytes += bytes;
|
|
10376
11128
|
}
|
|
10377
11129
|
function derivationSettings(config) {
|
|
@@ -10622,11 +11374,11 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
10622
11374
|
return errors;
|
|
10623
11375
|
}
|
|
10624
11376
|
function resolveSafeOutputDirs(config) {
|
|
10625
|
-
const cwd =
|
|
10626
|
-
const outDir =
|
|
10627
|
-
const tmpDir =
|
|
10628
|
-
const root =
|
|
10629
|
-
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${
|
|
11377
|
+
const cwd = path17.resolve(config.cwd);
|
|
11378
|
+
const outDir = path17.resolve(cwd, config.outDir);
|
|
11379
|
+
const tmpDir = path17.resolve(cwd, config.tmpDir);
|
|
11380
|
+
const root = path17.parse(cwd).root;
|
|
11381
|
+
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17.sep}`);
|
|
10630
11382
|
const reject = (reason) => {
|
|
10631
11383
|
throw new Error(
|
|
10632
11384
|
`Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
|
|
@@ -10666,6 +11418,28 @@ function maskSummaryStrings(value, secretRules) {
|
|
|
10666
11418
|
function maskPathText(value, secretRules) {
|
|
10667
11419
|
return findSecretInPath(value, secretRules)?.masked ?? value;
|
|
10668
11420
|
}
|
|
11421
|
+
function maskOwnerBrief(brief, secretRules) {
|
|
11422
|
+
if (brief === void 0) return void 0;
|
|
11423
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11424
|
+
return {
|
|
11425
|
+
...brief,
|
|
11426
|
+
...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
|
|
11427
|
+
...brief.system === void 0 ? {} : { system: mask(brief.system) },
|
|
11428
|
+
...brief.history === void 0 ? {} : { history: mask(brief.history) },
|
|
11429
|
+
...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
|
|
11430
|
+
...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
|
|
11431
|
+
...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
|
|
11432
|
+
notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
|
|
11433
|
+
};
|
|
11434
|
+
}
|
|
11435
|
+
function maskOverview(overview, secretRules) {
|
|
11436
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11437
|
+
return {
|
|
11438
|
+
...overview.description === void 0 ? {} : { description: mask(overview.description) },
|
|
11439
|
+
...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
|
|
11440
|
+
releases: overview.releases.map(mask)
|
|
11441
|
+
};
|
|
11442
|
+
}
|
|
10669
11443
|
function maskSkipRecords(records, secretRules) {
|
|
10670
11444
|
return maskSkipPaths(records, secretRules);
|
|
10671
11445
|
}
|
|
@@ -10686,14 +11460,14 @@ function listEntries(dir) {
|
|
|
10686
11460
|
const walk = (absolute, prefix) => {
|
|
10687
11461
|
let children;
|
|
10688
11462
|
try {
|
|
10689
|
-
children =
|
|
11463
|
+
children = fs16.readdirSync(absolute, { withFileTypes: true });
|
|
10690
11464
|
} catch {
|
|
10691
11465
|
return;
|
|
10692
11466
|
}
|
|
10693
11467
|
for (const child of children) {
|
|
10694
11468
|
const relative11 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
10695
11469
|
entries.push(relative11);
|
|
10696
|
-
if (child.isDirectory()) walk(
|
|
11470
|
+
if (child.isDirectory()) walk(path17.join(absolute, child.name), relative11);
|
|
10697
11471
|
}
|
|
10698
11472
|
};
|
|
10699
11473
|
walk(dir, "");
|
|
@@ -10705,10 +11479,10 @@ function markerInventory(dir, written) {
|
|
|
10705
11479
|
for (const entry of entries) {
|
|
10706
11480
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10707
11481
|
if (isIgnorableEntry(entry)) continue;
|
|
10708
|
-
const full =
|
|
11482
|
+
const full = path17.join(dir, ...entry.split("/"));
|
|
10709
11483
|
let stats;
|
|
10710
11484
|
try {
|
|
10711
|
-
stats =
|
|
11485
|
+
stats = fs16.lstatSync(full);
|
|
10712
11486
|
} catch {
|
|
10713
11487
|
continue;
|
|
10714
11488
|
}
|
|
@@ -10720,7 +11494,7 @@ function markerInventory(dir, written) {
|
|
|
10720
11494
|
}
|
|
10721
11495
|
let digest;
|
|
10722
11496
|
try {
|
|
10723
|
-
digest = sha256Hex2(
|
|
11497
|
+
digest = sha256Hex2(fs16.readFileSync(full));
|
|
10724
11498
|
} catch {
|
|
10725
11499
|
continue;
|
|
10726
11500
|
}
|
|
@@ -10741,15 +11515,15 @@ function markerPayload(dir, state, id, createdAt, written) {
|
|
|
10741
11515
|
entries,
|
|
10742
11516
|
files
|
|
10743
11517
|
};
|
|
10744
|
-
const manifestPath =
|
|
10745
|
-
if (
|
|
10746
|
-
marker2.manifestSha256 = sha256Hex2(
|
|
11518
|
+
const manifestPath = path17.join(dir, "manifest.json");
|
|
11519
|
+
if (fs16.existsSync(manifestPath)) {
|
|
11520
|
+
marker2.manifestSha256 = sha256Hex2(fs16.readFileSync(manifestPath));
|
|
10747
11521
|
}
|
|
10748
11522
|
return marker2;
|
|
10749
11523
|
}
|
|
10750
11524
|
function writeOwnershipMarker(dir, marker2) {
|
|
10751
|
-
|
|
10752
|
-
|
|
11525
|
+
fs16.writeFileSync(
|
|
11526
|
+
path17.join(dir, OWNERSHIP_MARKER),
|
|
10753
11527
|
`${JSON.stringify(marker2, null, 2)}
|
|
10754
11528
|
`,
|
|
10755
11529
|
"utf8"
|
|
@@ -10761,13 +11535,13 @@ function markerBelongsTo(dir, id) {
|
|
|
10761
11535
|
return evidence.marker.id === id;
|
|
10762
11536
|
}
|
|
10763
11537
|
function readOwnershipMarker(dir) {
|
|
10764
|
-
const markerPath =
|
|
10765
|
-
if (!
|
|
11538
|
+
const markerPath = path17.join(dir, OWNERSHIP_MARKER);
|
|
11539
|
+
if (!fs16.existsSync(markerPath)) {
|
|
10766
11540
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
10767
11541
|
}
|
|
10768
11542
|
let raw;
|
|
10769
11543
|
try {
|
|
10770
|
-
raw =
|
|
11544
|
+
raw = fs16.readFileSync(markerPath, "utf8");
|
|
10771
11545
|
} catch {
|
|
10772
11546
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
10773
11547
|
}
|
|
@@ -10867,10 +11641,10 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10867
11641
|
for (const entry of entries) {
|
|
10868
11642
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10869
11643
|
if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
|
|
10870
|
-
const full =
|
|
11644
|
+
const full = path17.join(dir, ...entry.split("/"));
|
|
10871
11645
|
let stats;
|
|
10872
11646
|
try {
|
|
10873
|
-
stats =
|
|
11647
|
+
stats = fs16.lstatSync(full);
|
|
10874
11648
|
} catch {
|
|
10875
11649
|
return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
|
|
10876
11650
|
}
|
|
@@ -10895,7 +11669,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10895
11669
|
}
|
|
10896
11670
|
let digest;
|
|
10897
11671
|
try {
|
|
10898
|
-
digest = sha256Hex2(
|
|
11672
|
+
digest = sha256Hex2(fs16.readFileSync(full));
|
|
10899
11673
|
} catch {
|
|
10900
11674
|
return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
|
|
10901
11675
|
}
|
|
@@ -10916,12 +11690,12 @@ function assessSnapshotDirectory(dir) {
|
|
|
10916
11690
|
marker: marker2
|
|
10917
11691
|
};
|
|
10918
11692
|
}
|
|
10919
|
-
const manifestPath =
|
|
10920
|
-
const hasManifest =
|
|
11693
|
+
const manifestPath = path17.join(dir, "manifest.json");
|
|
11694
|
+
const hasManifest = fs16.existsSync(manifestPath);
|
|
10921
11695
|
if (hasManifest) {
|
|
10922
11696
|
let raw;
|
|
10923
11697
|
try {
|
|
10924
|
-
raw =
|
|
11698
|
+
raw = fs16.readFileSync(manifestPath, "utf8");
|
|
10925
11699
|
} catch {
|
|
10926
11700
|
return {
|
|
10927
11701
|
owned: false,
|
|
@@ -11016,13 +11790,13 @@ function containsNoFiles(dir) {
|
|
|
11016
11790
|
const current = pending.pop();
|
|
11017
11791
|
let entries;
|
|
11018
11792
|
try {
|
|
11019
|
-
entries =
|
|
11793
|
+
entries = fs16.readdirSync(current, { withFileTypes: true });
|
|
11020
11794
|
} catch {
|
|
11021
11795
|
return false;
|
|
11022
11796
|
}
|
|
11023
11797
|
for (const entry of entries) {
|
|
11024
11798
|
if (entry.isDirectory()) {
|
|
11025
|
-
pending.push(
|
|
11799
|
+
pending.push(path17.join(current, entry.name));
|
|
11026
11800
|
} else if (!IGNORABLE_ENTRIES.has(entry.name)) {
|
|
11027
11801
|
return false;
|
|
11028
11802
|
}
|
|
@@ -11031,13 +11805,13 @@ function containsNoFiles(dir) {
|
|
|
11031
11805
|
return true;
|
|
11032
11806
|
}
|
|
11033
11807
|
function assertReplaceable(target, label, secretRules) {
|
|
11034
|
-
if (!
|
|
11035
|
-
if (!
|
|
11808
|
+
if (!fs16.existsSync(target)) return;
|
|
11809
|
+
if (!fs16.statSync(target).isDirectory()) {
|
|
11036
11810
|
throw new Error(
|
|
11037
11811
|
`Refusing to write into ${label} ${target}: it exists but is not a directory.`
|
|
11038
11812
|
);
|
|
11039
11813
|
}
|
|
11040
|
-
const entries =
|
|
11814
|
+
const entries = fs16.readdirSync(target);
|
|
11041
11815
|
if (entries.length === 0) return;
|
|
11042
11816
|
if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
|
|
11043
11817
|
if (containsNoFiles(target)) return;
|
|
@@ -11057,18 +11831,18 @@ function assertReplaceable(target, label, secretRules) {
|
|
|
11057
11831
|
);
|
|
11058
11832
|
}
|
|
11059
11833
|
function assertStagingRootUsable(tmpDir, secretRules) {
|
|
11060
|
-
if (!
|
|
11061
|
-
if (!
|
|
11834
|
+
if (!fs16.existsSync(tmpDir)) return;
|
|
11835
|
+
if (!fs16.statSync(tmpDir).isDirectory()) {
|
|
11062
11836
|
throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
|
|
11063
11837
|
}
|
|
11064
|
-
const entries =
|
|
11838
|
+
const entries = fs16.readdirSync(tmpDir);
|
|
11065
11839
|
if (entries.length === 0) return;
|
|
11066
11840
|
const foreign = entries.filter((name) => {
|
|
11067
|
-
const full =
|
|
11841
|
+
const full = path17.join(tmpDir, name);
|
|
11068
11842
|
if (!name.startsWith(RUN_DIR_PREFIX)) return true;
|
|
11069
11843
|
let stats;
|
|
11070
11844
|
try {
|
|
11071
|
-
stats =
|
|
11845
|
+
stats = fs16.statSync(full);
|
|
11072
11846
|
} catch {
|
|
11073
11847
|
return true;
|
|
11074
11848
|
}
|
|
@@ -11076,7 +11850,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
11076
11850
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
11077
11851
|
if (marker2) return false;
|
|
11078
11852
|
try {
|
|
11079
|
-
return
|
|
11853
|
+
return fs16.readdirSync(full).length > 0;
|
|
11080
11854
|
} catch {
|
|
11081
11855
|
return true;
|
|
11082
11856
|
}
|
|
@@ -11091,13 +11865,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
11091
11865
|
function cleanStaleRunDirs(tmpDir) {
|
|
11092
11866
|
let entries;
|
|
11093
11867
|
try {
|
|
11094
|
-
entries =
|
|
11868
|
+
entries = fs16.readdirSync(tmpDir);
|
|
11095
11869
|
} catch {
|
|
11096
11870
|
return;
|
|
11097
11871
|
}
|
|
11098
11872
|
for (const name of entries) {
|
|
11099
11873
|
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
11100
|
-
const full =
|
|
11874
|
+
const full = path17.join(tmpDir, name);
|
|
11101
11875
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
11102
11876
|
if (marker2) {
|
|
11103
11877
|
const created = Date.parse(marker2.createdAt);
|
|
@@ -11105,33 +11879,33 @@ function cleanStaleRunDirs(tmpDir) {
|
|
|
11105
11879
|
const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
|
|
11106
11880
|
if (aged || abandoned) {
|
|
11107
11881
|
try {
|
|
11108
|
-
|
|
11882
|
+
fs16.rmSync(full, { recursive: true, force: true });
|
|
11109
11883
|
} catch {
|
|
11110
11884
|
}
|
|
11111
11885
|
}
|
|
11112
11886
|
continue;
|
|
11113
11887
|
}
|
|
11114
11888
|
try {
|
|
11115
|
-
if (
|
|
11889
|
+
if (fs16.readdirSync(full).length === 0) fs16.rmSync(full, { recursive: true, force: true });
|
|
11116
11890
|
} catch {
|
|
11117
11891
|
}
|
|
11118
11892
|
}
|
|
11119
11893
|
}
|
|
11120
11894
|
function removeIfEmpty(dir) {
|
|
11121
11895
|
try {
|
|
11122
|
-
if (
|
|
11896
|
+
if (fs16.readdirSync(dir).length === 0) fs16.rmSync(dir, { recursive: true, force: true });
|
|
11123
11897
|
} catch {
|
|
11124
11898
|
}
|
|
11125
11899
|
}
|
|
11126
11900
|
function ensureParentDirectory(target, label) {
|
|
11127
|
-
const parent =
|
|
11128
|
-
if (
|
|
11901
|
+
const parent = path17.dirname(target);
|
|
11902
|
+
if (fs16.existsSync(parent) && !fs16.statSync(parent).isDirectory()) {
|
|
11129
11903
|
throw new Error(
|
|
11130
11904
|
`Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
|
|
11131
11905
|
);
|
|
11132
11906
|
}
|
|
11133
11907
|
try {
|
|
11134
|
-
|
|
11908
|
+
fs16.mkdirSync(parent, { recursive: true });
|
|
11135
11909
|
} catch (err) {
|
|
11136
11910
|
throw new Error(
|
|
11137
11911
|
`Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
|
|
@@ -11189,17 +11963,17 @@ function acquireRunLock(stagingRoot) {
|
|
|
11189
11963
|
`;
|
|
11190
11964
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
11191
11965
|
try {
|
|
11192
|
-
const handle =
|
|
11966
|
+
const handle = fs16.openSync(lockPath, "wx");
|
|
11193
11967
|
try {
|
|
11194
|
-
|
|
11968
|
+
fs16.writeSync(handle, payload);
|
|
11195
11969
|
} finally {
|
|
11196
|
-
|
|
11970
|
+
fs16.closeSync(handle);
|
|
11197
11971
|
}
|
|
11198
11972
|
const stopHeartbeat = startLockHeartbeat(lockPath);
|
|
11199
11973
|
return () => {
|
|
11200
11974
|
stopHeartbeat();
|
|
11201
11975
|
try {
|
|
11202
|
-
|
|
11976
|
+
fs16.rmSync(lockPath, { force: true });
|
|
11203
11977
|
} catch {
|
|
11204
11978
|
}
|
|
11205
11979
|
};
|
|
@@ -11219,26 +11993,26 @@ function lockKeyFor(stagingRoot) {
|
|
|
11219
11993
|
return sha256Hex2(key).slice(0, 16);
|
|
11220
11994
|
}
|
|
11221
11995
|
function canonicalLockTarget(targetPath) {
|
|
11222
|
-
const resolved =
|
|
11996
|
+
const resolved = path17.resolve(targetPath);
|
|
11223
11997
|
let existing = resolved;
|
|
11224
11998
|
const tail = [];
|
|
11225
11999
|
for (; ; ) {
|
|
11226
12000
|
try {
|
|
11227
|
-
return
|
|
12001
|
+
return path17.join(fs16.realpathSync(existing), ...tail);
|
|
11228
12002
|
} catch {
|
|
11229
|
-
const parent =
|
|
12003
|
+
const parent = path17.dirname(existing);
|
|
11230
12004
|
if (parent === existing) return resolved;
|
|
11231
|
-
tail.unshift(
|
|
12005
|
+
tail.unshift(path17.basename(existing));
|
|
11232
12006
|
existing = parent;
|
|
11233
12007
|
}
|
|
11234
12008
|
}
|
|
11235
12009
|
}
|
|
11236
12010
|
function lockPathFor(stagingRoot) {
|
|
11237
|
-
return
|
|
12011
|
+
return path17.join(os.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
11238
12012
|
}
|
|
11239
12013
|
function lockHeartbeatAgeMs(lockPath) {
|
|
11240
12014
|
try {
|
|
11241
|
-
return Date.now() -
|
|
12015
|
+
return Date.now() - fs16.statSync(lockPath).mtimeMs;
|
|
11242
12016
|
} catch {
|
|
11243
12017
|
return Number.POSITIVE_INFINITY;
|
|
11244
12018
|
}
|
|
@@ -11246,7 +12020,7 @@ function lockHeartbeatAgeMs(lockPath) {
|
|
|
11246
12020
|
function lockOwnerIsGone(lockPath) {
|
|
11247
12021
|
let raw;
|
|
11248
12022
|
try {
|
|
11249
|
-
raw =
|
|
12023
|
+
raw = fs16.readFileSync(lockPath, "utf8");
|
|
11250
12024
|
} catch {
|
|
11251
12025
|
return false;
|
|
11252
12026
|
}
|
|
@@ -11268,16 +12042,16 @@ function lockOwnerIsGone(lockPath) {
|
|
|
11268
12042
|
function reclaimStaleLock(lockPath) {
|
|
11269
12043
|
let before;
|
|
11270
12044
|
try {
|
|
11271
|
-
before =
|
|
12045
|
+
before = fs16.statSync(lockPath);
|
|
11272
12046
|
} catch {
|
|
11273
12047
|
return true;
|
|
11274
12048
|
}
|
|
11275
12049
|
if (!lockOwnerIsGone(lockPath)) return false;
|
|
11276
12050
|
try {
|
|
11277
|
-
const current =
|
|
12051
|
+
const current = fs16.statSync(lockPath);
|
|
11278
12052
|
const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
|
|
11279
12053
|
if (!sameFile) return false;
|
|
11280
|
-
|
|
12054
|
+
fs16.rmSync(lockPath, { force: true });
|
|
11281
12055
|
return true;
|
|
11282
12056
|
} catch {
|
|
11283
12057
|
return false;
|
|
@@ -11288,12 +12062,12 @@ function lockFileIsAncient(lockPath) {
|
|
|
11288
12062
|
}
|
|
11289
12063
|
function writeManifestAtomically(manifestPath, manifest) {
|
|
11290
12064
|
const tempPath = `${manifestPath}.${process.pid}.tmp`;
|
|
11291
|
-
|
|
12065
|
+
fs16.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
|
|
11292
12066
|
try {
|
|
11293
|
-
|
|
12067
|
+
fs16.renameSync(tempPath, manifestPath);
|
|
11294
12068
|
} catch (err) {
|
|
11295
12069
|
try {
|
|
11296
|
-
|
|
12070
|
+
fs16.rmSync(tempPath, { force: true });
|
|
11297
12071
|
} catch {
|
|
11298
12072
|
}
|
|
11299
12073
|
throw err;
|
|
@@ -11318,21 +12092,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
|
|
|
11318
12092
|
}
|
|
11319
12093
|
}
|
|
11320
12094
|
function recoverInterruptedPublish(outDir) {
|
|
11321
|
-
if (
|
|
11322
|
-
const parent =
|
|
11323
|
-
const base =
|
|
12095
|
+
if (fs16.existsSync(outDir)) return;
|
|
12096
|
+
const parent = path17.dirname(outDir);
|
|
12097
|
+
const base = path17.basename(outDir);
|
|
11324
12098
|
let backups;
|
|
11325
12099
|
try {
|
|
11326
|
-
backups =
|
|
12100
|
+
backups = fs16.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
|
|
11327
12101
|
} catch {
|
|
11328
12102
|
return;
|
|
11329
12103
|
}
|
|
11330
12104
|
if (backups.length !== 1) return;
|
|
11331
|
-
const backupDir =
|
|
12105
|
+
const backupDir = path17.join(parent, backups[0]);
|
|
11332
12106
|
const { marker: marker2, problem } = readOwnershipMarker(backupDir);
|
|
11333
12107
|
if (problem !== null || marker2 === null || marker2.state !== "complete") return;
|
|
11334
12108
|
try {
|
|
11335
|
-
|
|
12109
|
+
fs16.renameSync(backupDir, outDir);
|
|
11336
12110
|
process.stderr.write(
|
|
11337
12111
|
`\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
|
|
11338
12112
|
`
|
|
@@ -11342,16 +12116,16 @@ function recoverInterruptedPublish(outDir) {
|
|
|
11342
12116
|
}
|
|
11343
12117
|
function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
11344
12118
|
const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
|
|
11345
|
-
const hadPrevious =
|
|
12119
|
+
const hadPrevious = fs16.existsSync(outDir);
|
|
11346
12120
|
if (hadPrevious) beforeSwap?.();
|
|
11347
12121
|
let movedAside = false;
|
|
11348
12122
|
if (hadPrevious) {
|
|
11349
12123
|
try {
|
|
11350
|
-
|
|
12124
|
+
fs16.renameSync(outDir, backupDir);
|
|
11351
12125
|
movedAside = true;
|
|
11352
12126
|
} catch (err) {
|
|
11353
12127
|
if (!isLockError(err)) throw err;
|
|
11354
|
-
|
|
12128
|
+
fs16.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
11355
12129
|
process.stderr.write(
|
|
11356
12130
|
`\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.
|
|
11357
12131
|
`
|
|
@@ -11360,26 +12134,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11360
12134
|
}
|
|
11361
12135
|
try {
|
|
11362
12136
|
try {
|
|
11363
|
-
|
|
12137
|
+
fs16.renameSync(stagingDir, outDir);
|
|
11364
12138
|
} catch (err) {
|
|
11365
12139
|
if (err.code !== "EXDEV") throw err;
|
|
11366
12140
|
const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
|
|
11367
12141
|
try {
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
12142
|
+
fs16.cpSync(stagingDir, partialDir, { recursive: true });
|
|
12143
|
+
fs16.renameSync(partialDir, outDir);
|
|
12144
|
+
fs16.rmSync(stagingDir, { recursive: true, force: true });
|
|
11371
12145
|
} catch (copyErr) {
|
|
11372
12146
|
try {
|
|
11373
|
-
|
|
12147
|
+
fs16.rmSync(partialDir, { recursive: true, force: true });
|
|
11374
12148
|
} catch {
|
|
11375
12149
|
}
|
|
11376
12150
|
throw copyErr;
|
|
11377
12151
|
}
|
|
11378
12152
|
}
|
|
11379
12153
|
} catch (err) {
|
|
11380
|
-
if (hadPrevious && movedAside &&
|
|
11381
|
-
if (
|
|
11382
|
-
|
|
12154
|
+
if (hadPrevious && movedAside && fs16.existsSync(backupDir)) {
|
|
12155
|
+
if (fs16.existsSync(outDir)) fs16.rmSync(outDir, { recursive: true, force: true });
|
|
12156
|
+
fs16.renameSync(backupDir, outDir);
|
|
11383
12157
|
} else if (hadPrevious && !movedAside) {
|
|
11384
12158
|
process.stderr.write(
|
|
11385
12159
|
`\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
|
|
@@ -11390,7 +12164,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11390
12164
|
}
|
|
11391
12165
|
if (hadPrevious) {
|
|
11392
12166
|
try {
|
|
11393
|
-
|
|
12167
|
+
fs16.rmSync(backupDir, { recursive: true, force: true });
|
|
11394
12168
|
} catch (err) {
|
|
11395
12169
|
process.stderr.write(
|
|
11396
12170
|
`\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.
|
|
@@ -11449,7 +12223,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11449
12223
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11450
12224
|
}
|
|
11451
12225
|
function partitionByBudget(files, config, fingerprint) {
|
|
11452
|
-
const
|
|
12226
|
+
const configured = {
|
|
12227
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
12228
|
+
budgets: config.budgets,
|
|
12229
|
+
maxPartBytes: config.maxPartBytes,
|
|
12230
|
+
warnings: []
|
|
12231
|
+
};
|
|
12232
|
+
const limit = config.maxParts;
|
|
12233
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
12234
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
12235
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
12236
|
+
const seen = [];
|
|
12237
|
+
let low = config.budgets.default;
|
|
12238
|
+
let fitting = null;
|
|
12239
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
12240
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
12241
|
+
if (parts2.length <= limit) {
|
|
12242
|
+
fitting = { target, parts: parts2 };
|
|
12243
|
+
break;
|
|
12244
|
+
}
|
|
12245
|
+
seen.push(parts2.length);
|
|
12246
|
+
low = target;
|
|
12247
|
+
target = Math.ceil(target * 1.3);
|
|
12248
|
+
}
|
|
12249
|
+
if (fitting === null) {
|
|
12250
|
+
throw new Error(
|
|
12251
|
+
`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.`
|
|
12252
|
+
);
|
|
12253
|
+
}
|
|
12254
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
12255
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
12256
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
12257
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
12258
|
+
else low = middle;
|
|
12259
|
+
}
|
|
12260
|
+
const { target: chosen, parts } = fitting;
|
|
12261
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
12262
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
12263
|
+
const warnings = [
|
|
12264
|
+
`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).`
|
|
12265
|
+
];
|
|
12266
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
12267
|
+
warnings.push(
|
|
12268
|
+
`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.`
|
|
12269
|
+
);
|
|
12270
|
+
}
|
|
12271
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
12272
|
+
}
|
|
12273
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
12274
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11453
12275
|
const buckets = /* @__PURE__ */ new Map();
|
|
11454
12276
|
for (const file of files) {
|
|
11455
12277
|
const budget = budgetFor(file);
|
|
@@ -11466,6 +12288,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11466
12288
|
fingerprint
|
|
11467
12289
|
);
|
|
11468
12290
|
}
|
|
12291
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
12292
|
+
const factor = targetDefault / budgets.default;
|
|
12293
|
+
return {
|
|
12294
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
12295
|
+
byLayer: Object.fromEntries(
|
|
12296
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
12297
|
+
name,
|
|
12298
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12299
|
+
])
|
|
12300
|
+
)
|
|
12301
|
+
};
|
|
12302
|
+
}
|
|
11469
12303
|
function generateSnapshot(configInput, options) {
|
|
11470
12304
|
assertUsableConfigInput(configInput);
|
|
11471
12305
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11488,7 +12322,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11488
12322
|
// first run cannot have marked them yet, so the name alone keeps a run from recording its own
|
|
11489
12323
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11490
12324
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11491
|
-
(directory) =>
|
|
12325
|
+
(directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11492
12326
|
).filter((relative11) => relative11.length > 0 && !relative11.startsWith("..")),
|
|
11493
12327
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11494
12328
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
@@ -11517,7 +12351,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11517
12351
|
let totalSizeBytes = 0;
|
|
11518
12352
|
let largeFileCount = 0;
|
|
11519
12353
|
for (const relativePath of candidateFiles) {
|
|
11520
|
-
const absolutePath =
|
|
12354
|
+
const absolutePath = path17.join(config.cwd, relativePath);
|
|
11521
12355
|
const fromIndex = stagedPaths.has(relativePath);
|
|
11522
12356
|
let buffer;
|
|
11523
12357
|
let sizeBytes;
|
|
@@ -11548,9 +12382,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11548
12382
|
} else {
|
|
11549
12383
|
let stats;
|
|
11550
12384
|
try {
|
|
11551
|
-
stats =
|
|
12385
|
+
stats = fs16.statSync(absolutePath);
|
|
11552
12386
|
if (!stats.isFile()) {
|
|
11553
|
-
const nestedRepository = stats.isDirectory() &&
|
|
12387
|
+
const nestedRepository = stats.isDirectory() && fs16.existsSync(path17.join(absolutePath, ".git"));
|
|
11554
12388
|
skipped.push(
|
|
11555
12389
|
nestedRepository ? {
|
|
11556
12390
|
path: relativePath,
|
|
@@ -11586,7 +12420,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11586
12420
|
continue;
|
|
11587
12421
|
}
|
|
11588
12422
|
try {
|
|
11589
|
-
buffer =
|
|
12423
|
+
buffer = fs16.readFileSync(absolutePath);
|
|
11590
12424
|
} catch (err) {
|
|
11591
12425
|
const code = err.code;
|
|
11592
12426
|
skipped.push({
|
|
@@ -11715,14 +12549,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11715
12549
|
(finding) => finding.path === void 0 || keep.has(finding.path)
|
|
11716
12550
|
);
|
|
11717
12551
|
retain(encodingNotes, (note) => keep.has(note.path));
|
|
11718
|
-
retain(oversizeSummaryPaths, (
|
|
11719
|
-
retain(previewSummaryPaths, (
|
|
12552
|
+
retain(oversizeSummaryPaths, (path18) => keep.has(path18));
|
|
12553
|
+
retain(previewSummaryPaths, (path18) => keep.has(path18));
|
|
11720
12554
|
retain(fileWarnings, (warning) => keep.has(warning.path));
|
|
11721
|
-
for (const
|
|
11722
|
-
if (!keep.has(
|
|
12555
|
+
for (const path18 of [...monolithBodies.keys()]) {
|
|
12556
|
+
if (!keep.has(path18)) monolithBodies.delete(path18);
|
|
11723
12557
|
}
|
|
11724
|
-
for (const
|
|
11725
|
-
if (!keep.has(
|
|
12558
|
+
for (const path18 of [...skippedSummaryImports.keys()]) {
|
|
12559
|
+
if (!keep.has(path18)) skippedSummaryImports.delete(path18);
|
|
11726
12560
|
}
|
|
11727
12561
|
}
|
|
11728
12562
|
if (changedScope !== null) {
|
|
@@ -11794,7 +12628,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11794
12628
|
);
|
|
11795
12629
|
}
|
|
11796
12630
|
}
|
|
11797
|
-
const
|
|
12631
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12632
|
+
const parts = partitioned.parts;
|
|
11798
12633
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11799
12634
|
const incomplete = files.flatMap((file) => {
|
|
11800
12635
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11831,7 +12666,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11831
12666
|
// the README and the audit report.
|
|
11832
12667
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11833
12668
|
budgets: {
|
|
11834
|
-
|
|
12669
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12670
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12671
|
+
// `validate` compares against the config on disk.
|
|
12672
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11835
12673
|
largeFileBytes: config.largeFileBytes
|
|
11836
12674
|
},
|
|
11837
12675
|
config: {
|
|
@@ -11849,6 +12687,16 @@ function generateSnapshot(configInput, options) {
|
|
|
11849
12687
|
// invisible in the manifest that is supposed to describe the run.
|
|
11850
12688
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11851
12689
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12690
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12691
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12692
|
+
// snapshot fail `validate` as configuration drift.
|
|
12693
|
+
attachmentSlots: config.attachmentSlots,
|
|
12694
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12695
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12696
|
+
// configuration drift.
|
|
12697
|
+
maxParts: config.maxParts ?? null,
|
|
12698
|
+
promptTask: config.promptTask,
|
|
12699
|
+
...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
|
|
11852
12700
|
discovery: config.discovery ?? "auto",
|
|
11853
12701
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11854
12702
|
// describes the run has to name it.
|
|
@@ -11919,6 +12767,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11919
12767
|
incomplete,
|
|
11920
12768
|
warnings
|
|
11921
12769
|
};
|
|
12770
|
+
if (partitioned.warnings.length > 0) {
|
|
12771
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12772
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12773
|
+
}
|
|
11922
12774
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11923
12775
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11924
12776
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11975,6 +12827,17 @@ function generateSnapshot(configInput, options) {
|
|
|
11975
12827
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11976
12828
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11977
12829
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12830
|
+
const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
|
|
12831
|
+
slots: config.attachmentSlots,
|
|
12832
|
+
task: config.promptTask,
|
|
12833
|
+
brief: maskOwnerBrief(config.brief, config.secretRules),
|
|
12834
|
+
history: recentCommits(config.cwd).map((commit) => ({
|
|
12835
|
+
subject: maskPathText(commit.subject, config.secretRules),
|
|
12836
|
+
body: maskPathText(commit.body, config.secretRules)
|
|
12837
|
+
})),
|
|
12838
|
+
overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
|
|
12839
|
+
}) : null;
|
|
12840
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11978
12841
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11979
12842
|
let monolithJson = null;
|
|
11980
12843
|
let monolithMarkdown = null;
|
|
@@ -12049,12 +12912,12 @@ function generateSnapshot(configInput, options) {
|
|
|
12049
12912
|
let releaseDeferred = false;
|
|
12050
12913
|
try {
|
|
12051
12914
|
ensureParentDirectory(outDir, "outDir");
|
|
12052
|
-
|
|
12915
|
+
fs16.mkdirSync(tmpDir, { recursive: true });
|
|
12053
12916
|
cleanStaleRunDirs(tmpDir);
|
|
12054
12917
|
const snapshotId = crypto2.randomUUID();
|
|
12055
12918
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
12056
|
-
stagingDir =
|
|
12057
|
-
|
|
12919
|
+
stagingDir = path17.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
|
|
12920
|
+
fs16.mkdirSync(stagingDir);
|
|
12058
12921
|
writeOwnershipMarker(stagingDir, {
|
|
12059
12922
|
generator: GENERATOR_NAME,
|
|
12060
12923
|
version: GENERATOR_VERSION,
|
|
@@ -12064,30 +12927,30 @@ function generateSnapshot(configInput, options) {
|
|
|
12064
12927
|
id: snapshotId,
|
|
12065
12928
|
pid: process.pid
|
|
12066
12929
|
});
|
|
12067
|
-
const partsDir =
|
|
12068
|
-
const reportsDir =
|
|
12069
|
-
if (artifacts.parts)
|
|
12930
|
+
const partsDir = path17.join(stagingDir, "parts");
|
|
12931
|
+
const reportsDir = path17.join(stagingDir, "reports");
|
|
12932
|
+
if (artifacts.parts) fs16.mkdirSync(partsDir, { recursive: true });
|
|
12070
12933
|
if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
|
|
12071
|
-
|
|
12934
|
+
fs16.mkdirSync(reportsDir, { recursive: true });
|
|
12072
12935
|
}
|
|
12073
12936
|
const writtenArtifacts = /* @__PURE__ */ new Map();
|
|
12074
12937
|
const writeArtifact = (targetDir, relativeEntry, data) => {
|
|
12075
|
-
const full =
|
|
12076
|
-
|
|
12077
|
-
const stats =
|
|
12938
|
+
const full = path17.join(targetDir, ...relativeEntry.split("/"));
|
|
12939
|
+
fs16.writeFileSync(full, data, "utf8");
|
|
12940
|
+
const stats = fs16.statSync(full);
|
|
12078
12941
|
writtenArtifacts.set(relativeEntry, {
|
|
12079
12942
|
digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
|
|
12080
12943
|
mtimeMs: stats.mtimeMs
|
|
12081
12944
|
});
|
|
12082
12945
|
};
|
|
12083
12946
|
const recordArtifact = (targetDir, relativeEntry) => {
|
|
12084
|
-
const full =
|
|
12085
|
-
const stats =
|
|
12947
|
+
const full = path17.join(targetDir, ...relativeEntry.split("/"));
|
|
12948
|
+
const stats = fs16.statSync(full);
|
|
12086
12949
|
writtenArtifacts.set(relativeEntry, {
|
|
12087
12950
|
digest: {
|
|
12088
12951
|
path: relativeEntry,
|
|
12089
12952
|
bytes: stats.size,
|
|
12090
|
-
sha256: sha256Hex2(
|
|
12953
|
+
sha256: sha256Hex2(fs16.readFileSync(full))
|
|
12091
12954
|
},
|
|
12092
12955
|
mtimeMs: stats.mtimeMs
|
|
12093
12956
|
});
|
|
@@ -12112,6 +12975,9 @@ function generateSnapshot(configInput, options) {
|
|
|
12112
12975
|
if (readmeText !== null) {
|
|
12113
12976
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
12114
12977
|
}
|
|
12978
|
+
if (promptText !== null) {
|
|
12979
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
12980
|
+
}
|
|
12115
12981
|
if (artifacts.manifest) {
|
|
12116
12982
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
12117
12983
|
}
|
|
@@ -12132,7 +12998,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12132
12998
|
const shipHookState = () => {
|
|
12133
12999
|
if (!markerBelongsTo(outDir, snapshotId)) return;
|
|
12134
13000
|
if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
|
|
12135
|
-
writeManifestAtomically(
|
|
13001
|
+
writeManifestAtomically(path17.join(outDir, "manifest.json"), manifest);
|
|
12136
13002
|
recordArtifact(outDir, "manifest.json");
|
|
12137
13003
|
}
|
|
12138
13004
|
writeOwnershipMarker(
|
|
@@ -12175,7 +13041,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12175
13041
|
} catch (err) {
|
|
12176
13042
|
if (stagingDir !== null) {
|
|
12177
13043
|
try {
|
|
12178
|
-
|
|
13044
|
+
fs16.rmSync(stagingDir, { recursive: true, force: true });
|
|
12179
13045
|
} catch {
|
|
12180
13046
|
}
|
|
12181
13047
|
}
|