codebase-snapshot 0.20.3 → 0.20.4
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 +63 -0
- package/README.md +1 -1
- package/dist/bin.js +897 -419
- package/dist/{chunk-7JQRJBMP.js → chunk-AQZNT3QL.js} +657 -256
- package/dist/{chunk-TUL3I7O6.js → chunk-QB5TNXMZ.js} +90 -14
- package/dist/cli.cjs +808 -329
- package/dist/cli.d.cts +14 -2
- package/dist/cli.d.ts +14 -2
- package/dist/cli.js +72 -73
- package/dist/{generate-worker-C6Z1I0XS.d.cts → generate-worker-CNRsO_z7.d.cts} +4 -0
- package/dist/{generate-worker-C6Z1I0XS.d.ts → generate-worker-CNRsO_z7.d.ts} +4 -0
- package/dist/index.cjs +660 -232
- package/dist/index.d.cts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +672 -306
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/docs/brief.md +5 -0
- package/docs/cli.md +5 -5
- package/docs/configuration.md +5 -0
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +11 -4
- package/docs/security-review.md +16 -3
- package/docs/serve.md +8 -4
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -197,8 +197,8 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
197
197
|
function scanWorkspacePackages(cwd, patterns) {
|
|
198
198
|
const files = /* @__PURE__ */ new Set();
|
|
199
199
|
const dependencies = /* @__PURE__ */ new Set();
|
|
200
|
-
for (const
|
|
201
|
-
const full = path27__namespace.join(cwd,
|
|
200
|
+
for (const relative16 of workspacePackageDirs(cwd, patterns)) {
|
|
201
|
+
const full = path27__namespace.join(cwd, relative16);
|
|
202
202
|
try {
|
|
203
203
|
for (const entry of fs24__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
204
204
|
} catch {
|
|
@@ -2226,10 +2226,68 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2226
2226
|
out += line.slice(cursor);
|
|
2227
2227
|
return out;
|
|
2228
2228
|
}
|
|
2229
|
+
var SIGNATURE_FILE = "signature.json";
|
|
2230
|
+
function loadSigningKey(environment = process.env) {
|
|
2231
|
+
const pem = environment.SNAPSHOT_SIGNING_KEY;
|
|
2232
|
+
if (pem === void 0 || pem.trim() === "") return null;
|
|
2233
|
+
return crypto__namespace.createPrivateKey({ key: pem, format: "pem" });
|
|
2234
|
+
}
|
|
2235
|
+
function signManifest(manifestPath, options = {}) {
|
|
2236
|
+
const bytes = fs24__namespace.readFileSync(manifestPath);
|
|
2237
|
+
const manifest = JSON.parse(bytes.toString("utf8"));
|
|
2238
|
+
if (typeof manifest.fingerprint !== "string" || !/^[0-9a-f]{64}$/.test(manifest.fingerprint)) {
|
|
2239
|
+
throw new Error("refusing to sign: the manifest has no valid fingerprint");
|
|
2240
|
+
}
|
|
2241
|
+
const configured = options.key ?? null;
|
|
2242
|
+
const key = configured ?? crypto__namespace.generateKeyPairSync("ed25519").privateKey;
|
|
2243
|
+
const publicKey = crypto__namespace.createPublicKey(key).export({ type: "spki", format: "der" }).toString("base64");
|
|
2244
|
+
const signature = crypto__namespace.sign(null, bytes, key).toString("base64");
|
|
2245
|
+
return {
|
|
2246
|
+
algorithm: "ed25519",
|
|
2247
|
+
signedAt: options.signedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2248
|
+
fingerprint: manifest.fingerprint,
|
|
2249
|
+
manifestSha256: crypto__namespace.createHash("sha256").update(bytes).digest("hex"),
|
|
2250
|
+
publicKey,
|
|
2251
|
+
signature,
|
|
2252
|
+
keyOrigin: configured === null ? "generated" : "configured"
|
|
2253
|
+
};
|
|
2254
|
+
}
|
|
2255
|
+
function verifySnapshotSignature(snapshotDir) {
|
|
2256
|
+
const signaturePath = path27__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
2257
|
+
const manifestPath = path27__namespace.join(snapshotDir, "manifest.json");
|
|
2258
|
+
if (!fs24__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
2259
|
+
let record;
|
|
2260
|
+
try {
|
|
2261
|
+
record = JSON.parse(fs24__namespace.readFileSync(signaturePath, "utf8"));
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
2264
|
+
}
|
|
2265
|
+
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
2266
|
+
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
2267
|
+
}
|
|
2268
|
+
let bytes;
|
|
2269
|
+
try {
|
|
2270
|
+
bytes = fs24__namespace.readFileSync(manifestPath);
|
|
2271
|
+
} catch {
|
|
2272
|
+
return { ok: false, reason: "the signed manifest is missing" };
|
|
2273
|
+
}
|
|
2274
|
+
const sha2562 = crypto__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
2275
|
+
if (sha2562 !== record.manifestSha256) {
|
|
2276
|
+
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
2277
|
+
}
|
|
2278
|
+
let verified = false;
|
|
2279
|
+
try {
|
|
2280
|
+
const key = crypto__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
2281
|
+
verified = crypto__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
2282
|
+
} catch (error) {
|
|
2283
|
+
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
2284
|
+
}
|
|
2285
|
+
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
2286
|
+
}
|
|
2229
2287
|
|
|
2230
2288
|
// src/version.ts
|
|
2231
2289
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2232
|
-
var GENERATOR_VERSION = "0.20.
|
|
2290
|
+
var GENERATOR_VERSION = "0.20.4";
|
|
2233
2291
|
var SCHEMA_VERSION = "3.0.0";
|
|
2234
2292
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2235
2293
|
function isOurGeneratorName(name) {
|
|
@@ -2261,8 +2319,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
2261
2319
|
};
|
|
2262
2320
|
}
|
|
2263
2321
|
function isInside(root, candidate) {
|
|
2264
|
-
const
|
|
2265
|
-
return
|
|
2322
|
+
const relative16 = path27__namespace.relative(root, candidate);
|
|
2323
|
+
return relative16 === "" || !relative16.startsWith(`..${path27__namespace.sep}`) && relative16 !== ".." && !path27__namespace.isAbsolute(relative16);
|
|
2266
2324
|
}
|
|
2267
2325
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
2268
2326
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -2736,7 +2794,7 @@ function listIgnoredPaths(cwd) {
|
|
|
2736
2794
|
}
|
|
2737
2795
|
function hasSnapshotMarker(target) {
|
|
2738
2796
|
try {
|
|
2739
|
-
return fs24__namespace.statSync(target).isDirectory() &&
|
|
2797
|
+
return fs24__namespace.statSync(target).isDirectory() && isToolOwnedDirectory2(target);
|
|
2740
2798
|
} catch {
|
|
2741
2799
|
return false;
|
|
2742
2800
|
}
|
|
@@ -2777,7 +2835,9 @@ function isToolOwnedDirectory2(dir) {
|
|
|
2777
2835
|
return false;
|
|
2778
2836
|
}
|
|
2779
2837
|
return entries.every(
|
|
2780
|
-
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) ||
|
|
2838
|
+
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) || // A snapshot signed before signing moved into staging has a valid signature.json the old
|
|
2839
|
+
// marker could not record. It is our artifact when the signature verifies.
|
|
2840
|
+
entry === "signature.json" && verifySnapshotSignature(dir).ok || accounted.has(entry)
|
|
2781
2841
|
);
|
|
2782
2842
|
}
|
|
2783
2843
|
function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
@@ -2887,6 +2947,15 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
2887
2947
|
});
|
|
2888
2948
|
continue;
|
|
2889
2949
|
}
|
|
2950
|
+
const targetRelative = path27__namespace.relative(rootReal, targetReal).split(path27__namespace.sep).join("/");
|
|
2951
|
+
if (isSensitivePath(targetRelative)) {
|
|
2952
|
+
report2(linkedPath, {
|
|
2953
|
+
path: linkedPath,
|
|
2954
|
+
reason: "sensitive-file",
|
|
2955
|
+
detail: "link target is a credential-bearing file; not followed"
|
|
2956
|
+
});
|
|
2957
|
+
continue;
|
|
2958
|
+
}
|
|
2890
2959
|
kept.push(candidate);
|
|
2891
2960
|
}
|
|
2892
2961
|
return kept;
|
|
@@ -3612,21 +3681,25 @@ var CONFIG_KEY_NAMES = [
|
|
|
3612
3681
|
"kinds",
|
|
3613
3682
|
"largeFileBytes",
|
|
3614
3683
|
"layers",
|
|
3684
|
+
"logCount",
|
|
3615
3685
|
"layersMode",
|
|
3616
3686
|
"maxMonolithBytes",
|
|
3617
3687
|
"maxPartBytes",
|
|
3618
3688
|
"maxParts",
|
|
3619
3689
|
"maxPartTokens",
|
|
3620
3690
|
"outDir",
|
|
3691
|
+
"pack",
|
|
3621
3692
|
"preset",
|
|
3622
3693
|
"previewHeadLines",
|
|
3623
3694
|
"promptTask",
|
|
3624
3695
|
"staged",
|
|
3625
3696
|
"previewTailLines",
|
|
3697
|
+
"removeEmptyLines",
|
|
3626
3698
|
"secretRules",
|
|
3627
3699
|
"secrets",
|
|
3628
3700
|
"sarif",
|
|
3629
3701
|
"skeleton",
|
|
3702
|
+
"stripComments",
|
|
3630
3703
|
"tmpDir",
|
|
3631
3704
|
"withDependents"
|
|
3632
3705
|
];
|
|
@@ -3934,7 +4007,34 @@ function readConfiguredBrief(cwd, value) {
|
|
|
3934
4007
|
"brief must be a path to a markdown file (received " + describeValue2(value) + ")."
|
|
3935
4008
|
);
|
|
3936
4009
|
}
|
|
3937
|
-
const
|
|
4010
|
+
const rootReal = (() => {
|
|
4011
|
+
try {
|
|
4012
|
+
return fs24__namespace.realpathSync(cwd);
|
|
4013
|
+
} catch {
|
|
4014
|
+
return path27__namespace.resolve(cwd);
|
|
4015
|
+
}
|
|
4016
|
+
})();
|
|
4017
|
+
const requested = path27__namespace.resolve(cwd, value);
|
|
4018
|
+
let filePath;
|
|
4019
|
+
try {
|
|
4020
|
+
filePath = fs24__namespace.realpathSync(requested);
|
|
4021
|
+
} catch {
|
|
4022
|
+
throw new Error(
|
|
4023
|
+
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
4024
|
+
);
|
|
4025
|
+
}
|
|
4026
|
+
const relative16 = path27__namespace.relative(rootReal, filePath);
|
|
4027
|
+
if (relative16.length === 0 || relative16 === ".." || relative16.startsWith(`..${path27__namespace.sep}`) || path27__namespace.isAbsolute(relative16)) {
|
|
4028
|
+
throw new Error(
|
|
4029
|
+
'brief "' + value + '" resolves outside the repository. A brief must be a file inside the repository being described; an absolute or parent path is refused.'
|
|
4030
|
+
);
|
|
4031
|
+
}
|
|
4032
|
+
const posixRelative = relative16.split(path27__namespace.sep).join("/");
|
|
4033
|
+
if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
|
|
4034
|
+
throw new Error(
|
|
4035
|
+
'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
|
|
4036
|
+
);
|
|
4037
|
+
}
|
|
3938
4038
|
let text2;
|
|
3939
4039
|
try {
|
|
3940
4040
|
if (!fs24__namespace.statSync(filePath).isFile()) throw new Error("not a file");
|
|
@@ -4051,11 +4151,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
4051
4151
|
const patterns = [];
|
|
4052
4152
|
for (const dir of [outDir, tmpDir]) {
|
|
4053
4153
|
const absolute = path27__namespace.resolve(cwd, dir);
|
|
4054
|
-
const
|
|
4055
|
-
if (!
|
|
4154
|
+
const relative16 = path27__namespace.relative(cwd, absolute);
|
|
4155
|
+
if (!relative16 || relative16 === ".." || relative16.startsWith(`..${path27__namespace.sep}`) || path27__namespace.isAbsolute(relative16)) {
|
|
4056
4156
|
continue;
|
|
4057
4157
|
}
|
|
4058
|
-
patterns.push(`${
|
|
4158
|
+
patterns.push(`${relative16.replace(/\\/g, "/")}/**`);
|
|
4059
4159
|
}
|
|
4060
4160
|
return patterns;
|
|
4061
4161
|
}
|
|
@@ -4685,8 +4785,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
4685
4785
|
return value;
|
|
4686
4786
|
}
|
|
4687
4787
|
function repositoryRelative(cwd, target) {
|
|
4688
|
-
const
|
|
4689
|
-
return
|
|
4788
|
+
const relative16 = path27__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
4789
|
+
return relative16.length === 0 || !relative16.startsWith("..") && !path27__namespace.isAbsolute(relative16) ? relative16 : null;
|
|
4690
4790
|
}
|
|
4691
4791
|
function rememberFirst(map, key, value) {
|
|
4692
4792
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -5650,9 +5750,9 @@ var rubyProfile = {
|
|
|
5650
5750
|
eachLine(content, (line) => {
|
|
5651
5751
|
const trimmed = line.trim();
|
|
5652
5752
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
5653
|
-
const
|
|
5654
|
-
if (
|
|
5655
|
-
summary.imports.push(`./${
|
|
5753
|
+
const relative16 = REQUIRE_RELATIVE.exec(trimmed);
|
|
5754
|
+
if (relative16) {
|
|
5755
|
+
summary.imports.push(`./${relative16[1]}`);
|
|
5656
5756
|
return;
|
|
5657
5757
|
}
|
|
5658
5758
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -6235,69 +6335,6 @@ function importsOfFile(relativePath, absolutePath) {
|
|
|
6235
6335
|
if (decoded.binary) return [];
|
|
6236
6336
|
return importsOfText(relativePath, decoded.text);
|
|
6237
6337
|
}
|
|
6238
|
-
var SIGNATURE_FILE = "signature.json";
|
|
6239
|
-
function loadSigningKey(environment = process.env) {
|
|
6240
|
-
const pem = environment.SNAPSHOT_SIGNING_KEY;
|
|
6241
|
-
if (pem === void 0 || pem.trim() === "") return null;
|
|
6242
|
-
return crypto__namespace.createPrivateKey({ key: pem, format: "pem" });
|
|
6243
|
-
}
|
|
6244
|
-
function signManifest(manifestPath, options = {}) {
|
|
6245
|
-
const bytes = fs24__namespace.readFileSync(manifestPath);
|
|
6246
|
-
const manifest = JSON.parse(bytes.toString("utf8"));
|
|
6247
|
-
if (typeof manifest.fingerprint !== "string" || !/^[0-9a-f]{64}$/.test(manifest.fingerprint)) {
|
|
6248
|
-
throw new Error("refusing to sign: the manifest has no valid fingerprint");
|
|
6249
|
-
}
|
|
6250
|
-
const configured = options.key ?? null;
|
|
6251
|
-
const key = configured ?? crypto__namespace.generateKeyPairSync("ed25519").privateKey;
|
|
6252
|
-
const publicKey = crypto__namespace.createPublicKey(key).export({ type: "spki", format: "der" }).toString("base64");
|
|
6253
|
-
const signature = crypto__namespace.sign(null, bytes, key).toString("base64");
|
|
6254
|
-
return {
|
|
6255
|
-
algorithm: "ed25519",
|
|
6256
|
-
signedAt: options.signedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
6257
|
-
fingerprint: manifest.fingerprint,
|
|
6258
|
-
manifestSha256: crypto__namespace.createHash("sha256").update(bytes).digest("hex"),
|
|
6259
|
-
publicKey,
|
|
6260
|
-
signature,
|
|
6261
|
-
keyOrigin: configured === null ? "generated" : "configured"
|
|
6262
|
-
};
|
|
6263
|
-
}
|
|
6264
|
-
function writeSignature(snapshotDir, record) {
|
|
6265
|
-
const target = path27__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
6266
|
-
fs24__namespace.writeFileSync(target, JSON.stringify(record, null, 2) + "\n", "utf8");
|
|
6267
|
-
return target;
|
|
6268
|
-
}
|
|
6269
|
-
function verifySnapshotSignature(snapshotDir) {
|
|
6270
|
-
const signaturePath = path27__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
6271
|
-
const manifestPath = path27__namespace.join(snapshotDir, "manifest.json");
|
|
6272
|
-
if (!fs24__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
6273
|
-
let record;
|
|
6274
|
-
try {
|
|
6275
|
-
record = JSON.parse(fs24__namespace.readFileSync(signaturePath, "utf8"));
|
|
6276
|
-
} catch (error) {
|
|
6277
|
-
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
6278
|
-
}
|
|
6279
|
-
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
6280
|
-
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
6281
|
-
}
|
|
6282
|
-
let bytes;
|
|
6283
|
-
try {
|
|
6284
|
-
bytes = fs24__namespace.readFileSync(manifestPath);
|
|
6285
|
-
} catch {
|
|
6286
|
-
return { ok: false, reason: "the signed manifest is missing" };
|
|
6287
|
-
}
|
|
6288
|
-
const sha2562 = crypto__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
6289
|
-
if (sha2562 !== record.manifestSha256) {
|
|
6290
|
-
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
6291
|
-
}
|
|
6292
|
-
let verified = false;
|
|
6293
|
-
try {
|
|
6294
|
-
const key = crypto__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
6295
|
-
verified = crypto__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
6296
|
-
} catch (error) {
|
|
6297
|
-
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
6298
|
-
}
|
|
6299
|
-
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
6300
|
-
}
|
|
6301
6338
|
|
|
6302
6339
|
// src/validator/validate.ts
|
|
6303
6340
|
function maskedPath(value, secretRules) {
|
|
@@ -6716,17 +6753,18 @@ function validateSnapshot(configInput) {
|
|
|
6716
6753
|
return skippedReasons.get(maskedPath(diskFile, config.secretRules)) ?? null;
|
|
6717
6754
|
};
|
|
6718
6755
|
let unchangedScope = null;
|
|
6756
|
+
let stagedScope = null;
|
|
6719
6757
|
const recordedChangedSince = manifest.config?.changedSince;
|
|
6720
6758
|
const recordedStaged = manifest.config?.staged === true;
|
|
6721
6759
|
const recordedWithDependents = manifest.config?.withDependents === true;
|
|
6722
6760
|
if (recordedChangedSince !== void 0 || recordedStaged) {
|
|
6723
6761
|
try {
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
);
|
|
6762
|
+
const scope = resolveChangedScope(config.cwd, {
|
|
6763
|
+
...recordedChangedSince === void 0 ? {} : { changedSince: recordedChangedSince },
|
|
6764
|
+
...recordedStaged ? { staged: true } : {}
|
|
6765
|
+
});
|
|
6766
|
+
unchangedScope = new Set(scope.paths);
|
|
6767
|
+
if (recordedStaged) stagedScope = new Set(scope.stagedPaths);
|
|
6730
6768
|
} catch {
|
|
6731
6769
|
warnings.push(
|
|
6732
6770
|
"The snapshot was generated with a changed-files scope, but that scope could not be re-resolved; files it recorded as `unchanged` were trusted rather than re-checked."
|
|
@@ -6737,7 +6775,11 @@ function validateSnapshot(configInput) {
|
|
|
6737
6775
|
function becameDependent(diskFile) {
|
|
6738
6776
|
if (!recordedWithDependents || unchangedScope === null) return false;
|
|
6739
6777
|
dependentResolver ??= buildImportResolver(
|
|
6740
|
-
collection.files.map((file) => ({ relativePath: file }))
|
|
6778
|
+
collection.files.map((file) => ({ relativePath: file })),
|
|
6779
|
+
{
|
|
6780
|
+
tsconfig: tsconfigPathsFor(config.cwd),
|
|
6781
|
+
...unchangedScope === null ? {} : { extraPaths: unchangedScope }
|
|
6782
|
+
}
|
|
6741
6783
|
);
|
|
6742
6784
|
return importsChangedFile(
|
|
6743
6785
|
diskFile,
|
|
@@ -6760,7 +6802,7 @@ function validateSnapshot(configInput) {
|
|
|
6760
6802
|
// snapshot was reported as drifting.
|
|
6761
6803
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
6762
6804
|
(directory) => path27__namespace.relative(config.cwd, path27__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
6763
|
-
).filter((
|
|
6805
|
+
).filter((relative16) => relative16.length > 0 && !relative16.startsWith(".."))
|
|
6764
6806
|
});
|
|
6765
6807
|
for (const diskFile of collection.files) {
|
|
6766
6808
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -6786,7 +6828,8 @@ function validateSnapshot(configInput) {
|
|
|
6786
6828
|
}
|
|
6787
6829
|
let diskHash;
|
|
6788
6830
|
try {
|
|
6789
|
-
|
|
6831
|
+
const stagedBlob = recordedStaged && stagedScope?.has(diskFile) === true ? readStagedBlob(config.cwd, diskFile) : null;
|
|
6832
|
+
diskHash = sha256Hex(stagedBlob ?? fs24__namespace.readFileSync(path27__namespace.join(config.cwd, diskFile)));
|
|
6790
6833
|
} catch (err) {
|
|
6791
6834
|
if (err.code === "ENOENT") {
|
|
6792
6835
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -7240,8 +7283,8 @@ function validateSnapshot(configInput) {
|
|
|
7240
7283
|
const target = match[1].split("#")[0];
|
|
7241
7284
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7242
7285
|
const resolved = path27__namespace.resolve(snapshotDir, "reports", target);
|
|
7243
|
-
const
|
|
7244
|
-
if (
|
|
7286
|
+
const relative16 = path27__namespace.relative(snapshotDir, resolved);
|
|
7287
|
+
if (relative16.startsWith("..") || path27__namespace.isAbsolute(relative16) || !fs24__namespace.existsSync(resolved)) {
|
|
7245
7288
|
drift.partIssues.push({
|
|
7246
7289
|
part: key,
|
|
7247
7290
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -7884,23 +7927,23 @@ function describeMatcher(matcher) {
|
|
|
7884
7927
|
function normalizeTarget(cwd, target) {
|
|
7885
7928
|
const resolvedCwd = path27__namespace.resolve(cwd);
|
|
7886
7929
|
const absolute = path27__namespace.resolve(resolvedCwd, target);
|
|
7887
|
-
const
|
|
7888
|
-
if (
|
|
7930
|
+
const relative16 = path27__namespace.relative(resolvedCwd, absolute);
|
|
7931
|
+
if (relative16 === "" || relative16 === ".." || relative16.startsWith(`..${path27__namespace.sep}`) || path27__namespace.isAbsolute(relative16)) {
|
|
7889
7932
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
7890
7933
|
}
|
|
7891
|
-
return { relative:
|
|
7934
|
+
return { relative: relative16.split(path27__namespace.sep).join("/"), outsideRoot: false };
|
|
7892
7935
|
}
|
|
7893
7936
|
function findRuleMatch(rules, relativePath) {
|
|
7894
7937
|
return rules.find(
|
|
7895
7938
|
(rule) => matchRule(relativePath, rule.match)
|
|
7896
7939
|
);
|
|
7897
7940
|
}
|
|
7898
|
-
function findRecordedAncestor(skipped,
|
|
7941
|
+
function findRecordedAncestor(skipped, relative16, maskedPath2) {
|
|
7899
7942
|
let nearest;
|
|
7900
7943
|
for (const record of skipped) {
|
|
7901
7944
|
const ancestorPath = record.path;
|
|
7902
7945
|
if (ancestorPath.length === 0) continue;
|
|
7903
|
-
const isAncestor =
|
|
7946
|
+
const isAncestor = relative16.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
7904
7947
|
if (!isAncestor) continue;
|
|
7905
7948
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
7906
7949
|
}
|
|
@@ -7916,8 +7959,8 @@ function readManifest2(config) {
|
|
|
7916
7959
|
}
|
|
7917
7960
|
function explainPath(config, target) {
|
|
7918
7961
|
const normalized = normalizeTarget(config.cwd, target);
|
|
7919
|
-
const
|
|
7920
|
-
const maskedPath2 = findSecretInPath(
|
|
7962
|
+
const relative16 = normalized.relative;
|
|
7963
|
+
const maskedPath2 = findSecretInPath(relative16, config.secretRules)?.masked ?? relative16;
|
|
7921
7964
|
if (normalized.outsideRoot) {
|
|
7922
7965
|
return {
|
|
7923
7966
|
path: maskedPath2,
|
|
@@ -7927,7 +7970,7 @@ function explainPath(config, target) {
|
|
|
7927
7970
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
7928
7971
|
};
|
|
7929
7972
|
}
|
|
7930
|
-
const absolute = path27__namespace.join(config.cwd,
|
|
7973
|
+
const absolute = path27__namespace.join(config.cwd, relative16);
|
|
7931
7974
|
const result = {
|
|
7932
7975
|
path: maskedPath2,
|
|
7933
7976
|
exists: fs24__namespace.existsSync(absolute),
|
|
@@ -7945,11 +7988,11 @@ function explainPath(config, target) {
|
|
|
7945
7988
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
7946
7989
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7947
7990
|
(directory) => path27__namespace.relative(config.cwd, path27__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7948
|
-
).filter((
|
|
7991
|
+
).filter((relative17) => relative17.length > 0 && !relative17.startsWith(".."))
|
|
7949
7992
|
});
|
|
7950
|
-
if (!collection.files.includes(
|
|
7993
|
+
if (!collection.files.includes(relative16)) {
|
|
7951
7994
|
const record = collection.skipped.find(
|
|
7952
|
-
(entry2) => entry2.path ===
|
|
7995
|
+
(entry2) => entry2.path === relative16 || entry2.path === maskedPath2
|
|
7953
7996
|
);
|
|
7954
7997
|
if (record) {
|
|
7955
7998
|
result.reason = record.reason;
|
|
@@ -7958,7 +8001,7 @@ function explainPath(config, target) {
|
|
|
7958
8001
|
result.reason = "missing";
|
|
7959
8002
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
7960
8003
|
} else {
|
|
7961
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
8004
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative16, maskedPath2);
|
|
7962
8005
|
if (ancestor) {
|
|
7963
8006
|
result.reason = ancestor.reason;
|
|
7964
8007
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -7978,13 +8021,15 @@ function explainPath(config, target) {
|
|
|
7978
8021
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
7979
8022
|
...config.staged === true ? { staged: true } : {}
|
|
7980
8023
|
});
|
|
7981
|
-
inScope = scope.paths.has(
|
|
8024
|
+
inScope = scope.paths.has(relative16);
|
|
7982
8025
|
if (!inScope && config.withDependents === true) {
|
|
7983
8026
|
inScope = importsChangedFile(
|
|
7984
|
-
|
|
7985
|
-
importsOfFile(
|
|
8027
|
+
relative16,
|
|
8028
|
+
importsOfFile(relative16, absolute),
|
|
7986
8029
|
scope.paths,
|
|
7987
|
-
buildImportResolver(collection.files.map((file) => ({ relativePath: file }))
|
|
8030
|
+
buildImportResolver(collection.files.map((file) => ({ relativePath: file })), {
|
|
8031
|
+
tsconfig: tsconfigPathsFor(config.cwd)
|
|
8032
|
+
})
|
|
7988
8033
|
);
|
|
7989
8034
|
}
|
|
7990
8035
|
scopeDetail = scope.detail;
|
|
@@ -8040,15 +8085,15 @@ function explainPath(config, target) {
|
|
|
8040
8085
|
result.bytes = buffer.length;
|
|
8041
8086
|
result.lines = countLines(text2);
|
|
8042
8087
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
8043
|
-
const { findings } = scanAndRedactSecrets(text2, config.secretRules,
|
|
8088
|
+
const { findings } = scanAndRedactSecrets(text2, config.secretRules, relative16);
|
|
8044
8089
|
result.secretCount = findings.length;
|
|
8045
8090
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
8046
8091
|
let inclusionMode = "full";
|
|
8047
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
8048
|
-
const skeleton = skeletonizeTypeScript(text2,
|
|
8092
|
+
if (config.skeleton === true && isSkeletonizable(relative16)) {
|
|
8093
|
+
const skeleton = skeletonizeTypeScript(text2, relative16);
|
|
8049
8094
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
8050
8095
|
}
|
|
8051
|
-
if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(
|
|
8096
|
+
if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(relative16) && stripComments2(text2, relative16).removed > 0) {
|
|
8052
8097
|
inclusionMode = "comments-stripped";
|
|
8053
8098
|
}
|
|
8054
8099
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -8057,18 +8102,18 @@ function explainPath(config, target) {
|
|
|
8057
8102
|
}
|
|
8058
8103
|
result.inclusionMode = inclusionMode;
|
|
8059
8104
|
}
|
|
8060
|
-
result.layer = classifyLayer(
|
|
8061
|
-
result.kind = classifyKind(
|
|
8062
|
-
result.language = detectLanguage(
|
|
8063
|
-
const layerRule = findRuleMatch(config.layers,
|
|
8105
|
+
result.layer = classifyLayer(relative16, config.layers);
|
|
8106
|
+
result.kind = classifyKind(relative16, config.kinds);
|
|
8107
|
+
result.language = detectLanguage(relative16);
|
|
8108
|
+
const layerRule = findRuleMatch(config.layers, relative16);
|
|
8064
8109
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
8065
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
8110
|
+
const kindRule = findRuleMatch(config.kinds, relative16);
|
|
8066
8111
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
8067
8112
|
const manifest = readManifest2(config);
|
|
8068
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
8113
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative16) : void 0;
|
|
8069
8114
|
result.part = entry?.part ?? null;
|
|
8070
8115
|
if (entry === void 0) {
|
|
8071
|
-
const record = manifest?.skipped?.find((skip) => skip.path ===
|
|
8116
|
+
const record = manifest?.skipped?.find((skip) => skip.path === relative16);
|
|
8072
8117
|
if (record !== void 0 && (record.reason === "not-selected" || record.reason === "unchanged")) {
|
|
8073
8118
|
result.included = false;
|
|
8074
8119
|
result.reason = record.reason;
|
|
@@ -8333,9 +8378,17 @@ function renderConfig(answers) {
|
|
|
8333
8378
|
// Replace function and method bodies with \`{ /* ... */ }\` in TypeScript files.
|
|
8334
8379
|
// Signatures and comments stay, so the structure of the file survives.
|
|
8335
8380
|
skeleton: ${answers.skeleton},
|
|
8381
|
+
// Remove comment text from JavaScript and TypeScript bodies.
|
|
8382
|
+
stripComments: false,
|
|
8383
|
+
// Drop blank lines from emitted bodies; line numbers in the part move.
|
|
8384
|
+
removeEmptyLines: false,
|
|
8336
8385
|
// Also write reports/audit.sarif (SARIF 2.1.0) for a CI security gate. The
|
|
8337
8386
|
// matched value is never included \u2014 only the path, the line and the rule.
|
|
8338
8387
|
sarif: ${answers.sarif},
|
|
8388
|
+
// Commit lines in reports/log.md when the log artifact is enabled.
|
|
8389
|
+
logCount: 20,
|
|
8390
|
+
// Write one single-file pack: "single", "xml" or "json". null = no pack.
|
|
8391
|
+
pack: null,
|
|
8339
8392
|
// Snapshot only the files that differ from a git ref (for example "main"),
|
|
8340
8393
|
// plus untracked ones. null means "snapshot everything"; any other value must
|
|
8341
8394
|
// be a git ref string, and anything else is a configuration error.
|
|
@@ -9009,11 +9062,11 @@ function gitignoreEntriesFor(cwd, outDir, tmpDir) {
|
|
|
9009
9062
|
const entries = [];
|
|
9010
9063
|
for (const directory of [outDir, tmpDir]) {
|
|
9011
9064
|
if (directory === null) continue;
|
|
9012
|
-
const
|
|
9013
|
-
if (
|
|
9065
|
+
const relative16 = path27__namespace.relative(cwd, path27__namespace.resolve(cwd, directory)).replace(/\\/g, "/");
|
|
9066
|
+
if (relative16 === "" || relative16 === "." || relative16.startsWith("..") || path27__namespace.isAbsolute(relative16)) {
|
|
9014
9067
|
continue;
|
|
9015
9068
|
}
|
|
9016
|
-
entries.push(`/${
|
|
9069
|
+
entries.push(`/${relative16}/`);
|
|
9017
9070
|
}
|
|
9018
9071
|
return [...new Set(entries)];
|
|
9019
9072
|
}
|
|
@@ -9344,10 +9397,10 @@ async function runInit(options) {
|
|
|
9344
9397
|
};
|
|
9345
9398
|
}
|
|
9346
9399
|
function describeTarget(cwd) {
|
|
9347
|
-
const
|
|
9348
|
-
if (
|
|
9349
|
-
if (
|
|
9350
|
-
return
|
|
9400
|
+
const relative16 = path27__namespace.relative(process.cwd(), cwd);
|
|
9401
|
+
if (relative16 === "") return "this directory";
|
|
9402
|
+
if (relative16.startsWith("..") || path27__namespace.isAbsolute(relative16)) return cwd;
|
|
9403
|
+
return relative16;
|
|
9351
9404
|
}
|
|
9352
9405
|
function firstRunMessage(reason, cwd) {
|
|
9353
9406
|
const where = describeTarget(cwd);
|
|
@@ -10570,12 +10623,27 @@ function runGit(cwd, args) {
|
|
|
10570
10623
|
function isGitRepository(cwd) {
|
|
10571
10624
|
return runGit(cwd, ["rev-parse", "--is-inside-work-tree"]).out.trim() === "true";
|
|
10572
10625
|
}
|
|
10626
|
+
function diffSectionPaths(body) {
|
|
10627
|
+
const paths = /* @__PURE__ */ new Set();
|
|
10628
|
+
for (const line of body.split("\n")) {
|
|
10629
|
+
const plus = /^\+\+\+ b\/(.*)$/.exec(line);
|
|
10630
|
+
if (plus !== null) paths.add(plus[1]);
|
|
10631
|
+
const minus = /^--- a\/(.*)$/.exec(line);
|
|
10632
|
+
if (minus !== null) paths.add(minus[1]);
|
|
10633
|
+
const header = /^diff --git a\/(.*?) b\/(.*)$/.exec(line);
|
|
10634
|
+
if (header !== null) {
|
|
10635
|
+
paths.add(header[1]);
|
|
10636
|
+
paths.add(header[2]);
|
|
10637
|
+
}
|
|
10638
|
+
}
|
|
10639
|
+
return [...paths];
|
|
10640
|
+
}
|
|
10573
10641
|
function generateDiffReport(cwd, options = {}) {
|
|
10574
10642
|
if (!isGitRepository(cwd)) return null;
|
|
10575
10643
|
const maxBytes = options.maxBytes ?? 200 * 1024;
|
|
10576
10644
|
const sections = [];
|
|
10577
|
-
let bytes = 0;
|
|
10578
10645
|
let truncated = false;
|
|
10646
|
+
let omittedSensitive = 0;
|
|
10579
10647
|
const commands = [
|
|
10580
10648
|
["Unstaged", ["diff", "--no-color"]],
|
|
10581
10649
|
["Staged", ["diff", "--cached", "--no-color"]]
|
|
@@ -10583,28 +10651,47 @@ function generateDiffReport(cwd, options = {}) {
|
|
|
10583
10651
|
for (const [title, args] of commands) {
|
|
10584
10652
|
const result = runGit(cwd, args);
|
|
10585
10653
|
if (!result.ok || result.out.trim() === "") continue;
|
|
10586
|
-
const
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
|
|
10654
|
+
const rawSections = result.out.split(/(?=^diff --git )/m).filter((section) => section.length > 0);
|
|
10655
|
+
for (const rawSection of rawSections) {
|
|
10656
|
+
const paths2 = diffSectionPaths(rawSection);
|
|
10657
|
+
const blocked = paths2.some((path28) => isSensitivePath(path28) || options.excluded?.(path28) === true);
|
|
10658
|
+
if (blocked) {
|
|
10659
|
+
omittedSensitive += 1;
|
|
10660
|
+
continue;
|
|
10661
|
+
}
|
|
10662
|
+
const used = Buffer.byteLength(sections.join(""), "utf8");
|
|
10663
|
+
const remaining = Math.max(0, maxBytes - used);
|
|
10664
|
+
if (remaining === 0) {
|
|
10665
|
+
truncated = true;
|
|
10666
|
+
break;
|
|
10667
|
+
}
|
|
10668
|
+
const chunk = truncateToBytes(rawSection, remaining);
|
|
10669
|
+
if (chunk.isTruncated) truncated = true;
|
|
10670
|
+
sections.push(
|
|
10671
|
+
"## " + title + " changes\n\nRun: git " + args.join(" ") + "\n\n```diff\n" + chunk.content + "\n```"
|
|
10672
|
+
);
|
|
10673
|
+
if (chunk.isTruncated) break;
|
|
10674
|
+
}
|
|
10593
10675
|
}
|
|
10594
10676
|
if (sections.length === 0) return null;
|
|
10595
10677
|
const paths = /* @__PURE__ */ new Set();
|
|
10596
|
-
for (const
|
|
10597
|
-
const
|
|
10678
|
+
for (const section of sections) for (const path28 of diffSectionPaths(section)) paths.add(path28);
|
|
10679
|
+
const joined = [
|
|
10598
10680
|
"# Uncommitted changes",
|
|
10599
10681
|
"",
|
|
10600
10682
|
"Generated from the repository at the moment the snapshot was written. Untracked files are not",
|
|
10601
10683
|
"in a diff until they are added; this artifact says what git reports, not what git ignores.",
|
|
10602
10684
|
"",
|
|
10685
|
+
...omittedSensitive > 0 ? [
|
|
10686
|
+
"> " + omittedSensitive + " file section(s) omitted: their path is credential-bearing or excluded from the snapshot.",
|
|
10687
|
+
""
|
|
10688
|
+
] : [],
|
|
10603
10689
|
...sections,
|
|
10604
10690
|
...truncated ? ["", "> Truncated at " + maxBytes + " bytes. Run git diff for the rest."] : [],
|
|
10605
10691
|
""
|
|
10606
10692
|
].join("\n");
|
|
10607
|
-
|
|
10693
|
+
const text2 = scanAndRedactSecrets(joined, options.secretRules ?? [], "reports/diff.md").redacted;
|
|
10694
|
+
return { text: text2, bytes: Buffer.byteLength(text2, "utf8"), truncated, paths: [...paths].sort() };
|
|
10608
10695
|
}
|
|
10609
10696
|
function generateLogReport(cwd, options = {}) {
|
|
10610
10697
|
const count = Math.max(1, Math.min(500, options.count ?? 20));
|
|
@@ -10618,13 +10705,15 @@ function generateLogReport(cwd, options = {}) {
|
|
|
10618
10705
|
const body = (result.stdout ?? "").trim();
|
|
10619
10706
|
if (body === "") return null;
|
|
10620
10707
|
const lines = body.split("\n");
|
|
10708
|
+
const redacted = scanAndRedactSecrets(body, options.secretRules ?? [], "reports/log.md").redacted;
|
|
10709
|
+
const joined = truncateToBytes(redacted, maxBytes).content;
|
|
10621
10710
|
const text2 = [
|
|
10622
10711
|
"# Recent commits",
|
|
10623
10712
|
"",
|
|
10624
10713
|
"The last " + count + " commits, newest first, one line each.",
|
|
10625
10714
|
"",
|
|
10626
10715
|
"```text",
|
|
10627
|
-
|
|
10716
|
+
joined,
|
|
10628
10717
|
"```",
|
|
10629
10718
|
""
|
|
10630
10719
|
].join("\n");
|
|
@@ -11487,24 +11576,93 @@ function readReleases(cwd) {
|
|
|
11487
11576
|
return headings.slice(0, MAX_RELEASES);
|
|
11488
11577
|
}
|
|
11489
11578
|
var HOST_PATTERN = /^[a-z0-9.-]+$/i;
|
|
11579
|
+
function parseIPv4(value) {
|
|
11580
|
+
const parts = value.split(".");
|
|
11581
|
+
if (parts.length !== 4) return null;
|
|
11582
|
+
const octets = [];
|
|
11583
|
+
for (const part of parts) {
|
|
11584
|
+
if (!/^\d{1,3}$/.test(part)) return null;
|
|
11585
|
+
const octet = Number(part);
|
|
11586
|
+
if (octet > 255) return null;
|
|
11587
|
+
octets.push(octet);
|
|
11588
|
+
}
|
|
11589
|
+
return octets;
|
|
11590
|
+
}
|
|
11591
|
+
function isPrivateIPv4(octets) {
|
|
11592
|
+
const [a, b] = octets;
|
|
11593
|
+
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 192 && b === 0 && octets[2] === 0 || a === 192 && b === 0 && octets[2] === 2 || a === 198 && (b === 18 || b === 19) || a === 198 && b === 51 && octets[2] === 100 || a === 203 && b === 0 && octets[2] === 113 || a >= 224;
|
|
11594
|
+
}
|
|
11595
|
+
function parseIPv6(value) {
|
|
11596
|
+
const withoutZone = value.split("%")[0] ?? value;
|
|
11597
|
+
if (!withoutZone.includes(":")) return null;
|
|
11598
|
+
const halves = withoutZone.split("::");
|
|
11599
|
+
if (halves.length > 2) return null;
|
|
11600
|
+
const left = halves[0] === "" ? [] : halves[0].split(":");
|
|
11601
|
+
const right = halves.length === 2 && halves[1] !== "" ? halves[1].split(":") : [];
|
|
11602
|
+
const groups = [...left, ...right];
|
|
11603
|
+
if (halves.length === 1 && groups.length !== 8) return null;
|
|
11604
|
+
if (halves.length === 2 && groups.length > 7) return null;
|
|
11605
|
+
const expand = (group) => {
|
|
11606
|
+
if (group.includes(".")) {
|
|
11607
|
+
const octets = parseIPv4(group);
|
|
11608
|
+
if (octets === null) return null;
|
|
11609
|
+
return [
|
|
11610
|
+
(octets[0] << 8 | octets[1]).toString(16),
|
|
11611
|
+
(octets[2] << 8 | octets[3]).toString(16)
|
|
11612
|
+
];
|
|
11613
|
+
}
|
|
11614
|
+
return [group];
|
|
11615
|
+
};
|
|
11616
|
+
const expanded = [];
|
|
11617
|
+
for (const group of groups) {
|
|
11618
|
+
const next = expand(group);
|
|
11619
|
+
if (next === null) return null;
|
|
11620
|
+
expanded.push(...next);
|
|
11621
|
+
}
|
|
11622
|
+
if (halves.length === 1 && expanded.length !== 8) return null;
|
|
11623
|
+
if (halves.length === 2 && expanded.length > 8) return null;
|
|
11624
|
+
const missing = 8 - expanded.length;
|
|
11625
|
+
const full = halves.length === 2 ? [...expanded.slice(0, left.length), ...Array(missing).fill("0"), ...expanded.slice(left.length)] : expanded;
|
|
11626
|
+
if (full.length !== 8) return null;
|
|
11627
|
+
const numbers = [];
|
|
11628
|
+
for (const group of full) {
|
|
11629
|
+
if (!/^[0-9a-f]{1,4}$/i.test(group)) return null;
|
|
11630
|
+
numbers.push(Number.parseInt(group, 16));
|
|
11631
|
+
}
|
|
11632
|
+
return numbers;
|
|
11633
|
+
}
|
|
11634
|
+
function isPrivateIPv6(groups) {
|
|
11635
|
+
const [first, second, third, fourth, fifth, sixth, seventh, eighth] = groups;
|
|
11636
|
+
const allZeroThrough = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
11637
|
+
if (groups.every((group) => group === 0)) return true;
|
|
11638
|
+
if (allZeroThrough(7) && eighth === 1) return true;
|
|
11639
|
+
if ((first & 65024) === 64512) return true;
|
|
11640
|
+
if ((first & 65472) === 65152) return true;
|
|
11641
|
+
if ((first & 65472) === 65216) return true;
|
|
11642
|
+
if ((first & 65280) === 65280) return true;
|
|
11643
|
+
if (first === 8193 && second === 3512) return true;
|
|
11644
|
+
const mapped = (offset) => isPrivateIPv4([
|
|
11645
|
+
groups[offset] >> 8,
|
|
11646
|
+
groups[offset] & 255,
|
|
11647
|
+
groups[offset + 1] >> 8,
|
|
11648
|
+
groups[offset + 1] & 255
|
|
11649
|
+
]);
|
|
11650
|
+
if (allZeroThrough(5) && sixth === 65535) return mapped(6);
|
|
11651
|
+
if (allZeroThrough(6) && (seventh !== 0 || eighth !== 0)) return mapped(6);
|
|
11652
|
+
if (first === 100 && second === 65435 && third === 0 && fourth === 0 && fifth === 0 && sixth === 0) {
|
|
11653
|
+
return mapped(6);
|
|
11654
|
+
}
|
|
11655
|
+
if (first === 8194) return mapped(1);
|
|
11656
|
+
return false;
|
|
11657
|
+
}
|
|
11490
11658
|
function isPrivateHost(host) {
|
|
11491
|
-
const value = host.toLowerCase().replace(/^\[|\]$/g, "");
|
|
11659
|
+
const value = host.toLowerCase().replace(/^\[|\]$/g, "").split("%")[0] ?? "";
|
|
11492
11660
|
if (value === "localhost" || value.endsWith(".localhost") || value.endsWith(".local")) return true;
|
|
11493
11661
|
if (value === "::1" || value === "0.0.0.0" || value === "::") return true;
|
|
11494
|
-
|
|
11495
|
-
if (
|
|
11496
|
-
const
|
|
11497
|
-
if (
|
|
11498
|
-
const octets = parts.map(Number);
|
|
11499
|
-
if (octets.some((octet) => octet > 255)) return true;
|
|
11500
|
-
if (octets[0] === 127) return true;
|
|
11501
|
-
if (octets[0] === 10) return true;
|
|
11502
|
-
if (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) return true;
|
|
11503
|
-
if (octets[0] === 192 && octets[1] === 168) return true;
|
|
11504
|
-
if (octets[0] === 169 && octets[1] === 254) return true;
|
|
11505
|
-
if (octets[0] === 100 && octets[1] >= 64 && octets[1] <= 127) return true;
|
|
11506
|
-
if (octets[0] === 0) return true;
|
|
11507
|
-
}
|
|
11662
|
+
const ipv4 = parseIPv4(value);
|
|
11663
|
+
if (ipv4 !== null) return isPrivateIPv4(ipv4);
|
|
11664
|
+
const ipv6 = parseIPv6(value);
|
|
11665
|
+
if (ipv6 !== null) return isPrivateIPv6(ipv6);
|
|
11508
11666
|
return false;
|
|
11509
11667
|
}
|
|
11510
11668
|
function parseRemoteSource(input, options = {}) {
|
|
@@ -11579,14 +11737,25 @@ async function assertPublicHost(host, allowPrivate) {
|
|
|
11579
11737
|
}
|
|
11580
11738
|
}
|
|
11581
11739
|
}
|
|
11740
|
+
function tokenHosts() {
|
|
11741
|
+
const configured = process.env.CODEBASE_SNAPSHOT_GITHUB_HOSTS;
|
|
11742
|
+
if (configured === void 0 || configured.trim() === "") return ["github.com"];
|
|
11743
|
+
return configured.split(",").map((entry) => entry.trim().toLowerCase()).filter((entry) => entry.length > 0);
|
|
11744
|
+
}
|
|
11745
|
+
function tokenAllowedForHost(host) {
|
|
11746
|
+
return tokenHosts().includes(host.toLowerCase().replace(/^\[|\]$/g, ""));
|
|
11747
|
+
}
|
|
11582
11748
|
function gitEnvironment(token, host) {
|
|
11583
11749
|
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_LFS_SKIP_SMUDGE: "1" };
|
|
11584
11750
|
delete env.GIT_ASKPASS;
|
|
11585
11751
|
delete env.SSH_ASKPASS;
|
|
11586
11752
|
if (token !== void 0 && token !== null && token !== "") {
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11753
|
+
const normalizedHost = host.toLowerCase().replace(/^\[|\]$/g, "");
|
|
11754
|
+
if (tokenAllowedForHost(normalizedHost)) {
|
|
11755
|
+
env.GIT_CONFIG_COUNT = "1";
|
|
11756
|
+
env.GIT_CONFIG_KEY_0 = "http.https://" + normalizedHost + "/.extraheader";
|
|
11757
|
+
env.GIT_CONFIG_VALUE_0 = "Authorization: Basic " + Buffer.from("x-access-token:" + token).toString("base64");
|
|
11758
|
+
}
|
|
11590
11759
|
}
|
|
11591
11760
|
return env;
|
|
11592
11761
|
}
|
|
@@ -11596,15 +11765,29 @@ async function cloneRepository(source, options) {
|
|
|
11596
11765
|
const dest = path27__namespace.resolve(options.dest);
|
|
11597
11766
|
fs24__namespace.rmSync(dest, { recursive: true, force: true });
|
|
11598
11767
|
fs24__namespace.mkdirSync(dest, { recursive: true });
|
|
11599
|
-
const
|
|
11600
|
-
|
|
11601
|
-
|
|
11768
|
+
const ref = options.ref ?? source.ref;
|
|
11769
|
+
const args = [
|
|
11770
|
+
"-c",
|
|
11771
|
+
"http.followRedirects=false",
|
|
11772
|
+
...source.kind === "https" ? ["-c", "protocol.file.allow=never", "-c", "protocol.ssh.allow=never"] : [],
|
|
11773
|
+
"clone",
|
|
11774
|
+
"--depth",
|
|
11775
|
+
"1",
|
|
11776
|
+
"--single-branch",
|
|
11777
|
+
"--no-tags",
|
|
11778
|
+
"--quiet"
|
|
11779
|
+
];
|
|
11780
|
+
if (ref !== void 0 && ref !== null && ref !== "") {
|
|
11781
|
+
args.push("--branch", ref);
|
|
11602
11782
|
}
|
|
11603
11783
|
args.push(source.url, dest);
|
|
11604
|
-
log("clone: " + source.url + (
|
|
11784
|
+
log("clone: " + source.url + (ref ? " (" + ref + ")" : ""));
|
|
11605
11785
|
const started = Date.now();
|
|
11606
11786
|
const result = childProcess.spawnSync("git", args, {
|
|
11607
|
-
env:
|
|
11787
|
+
env: {
|
|
11788
|
+
...gitEnvironment(options.token, source.host === "file" ? "localhost" : source.host),
|
|
11789
|
+
...source.kind === "https" ? { GIT_ALLOW_PROTOCOL: "https" } : {}
|
|
11790
|
+
},
|
|
11608
11791
|
timeout: options.timeoutMs ?? 18e4,
|
|
11609
11792
|
encoding: "utf8",
|
|
11610
11793
|
windowsHide: true
|
|
@@ -11632,7 +11815,7 @@ async function cloneRepository(source, options) {
|
|
|
11632
11815
|
host: source.host,
|
|
11633
11816
|
owner: source.owner,
|
|
11634
11817
|
repo: source.repo,
|
|
11635
|
-
ref:
|
|
11818
|
+
ref: ref !== void 0 && ref !== null && ref !== "" ? ref : null,
|
|
11636
11819
|
commit,
|
|
11637
11820
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11638
11821
|
}
|
|
@@ -12000,9 +12183,9 @@ function walk(dir, prefix = "") {
|
|
|
12000
12183
|
}
|
|
12001
12184
|
const files = [];
|
|
12002
12185
|
for (const entry of entries) {
|
|
12003
|
-
const
|
|
12004
|
-
if (entry.isDirectory()) files.push(...walk(path27__namespace.join(dir, entry.name),
|
|
12005
|
-
else if (entry.isFile()) files.push(
|
|
12186
|
+
const relative16 = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
12187
|
+
if (entry.isDirectory()) files.push(...walk(path27__namespace.join(dir, entry.name), relative16));
|
|
12188
|
+
else if (entry.isFile()) files.push(relative16);
|
|
12006
12189
|
}
|
|
12007
12190
|
return files;
|
|
12008
12191
|
}
|
|
@@ -12042,9 +12225,9 @@ function secretTokens(text2) {
|
|
|
12042
12225
|
}
|
|
12043
12226
|
function readArtifactTexts(snapshotDir) {
|
|
12044
12227
|
const texts = [];
|
|
12045
|
-
for (const
|
|
12046
|
-
if (!TEXT_ARTIFACT.test(
|
|
12047
|
-
const text2 = readText2(path27__namespace.join(snapshotDir,
|
|
12228
|
+
for (const relative16 of walk(snapshotDir)) {
|
|
12229
|
+
if (!TEXT_ARTIFACT.test(relative16)) continue;
|
|
12230
|
+
const text2 = readText2(path27__namespace.join(snapshotDir, relative16));
|
|
12048
12231
|
if (text2 !== null) texts.push(text2);
|
|
12049
12232
|
}
|
|
12050
12233
|
return texts;
|
|
@@ -12060,15 +12243,15 @@ function findHostPaths(snapshotDir, repoDir) {
|
|
|
12060
12243
|
];
|
|
12061
12244
|
const repoPattern = new RegExp(escapeRegExp(repoDir), "g");
|
|
12062
12245
|
const hits = /* @__PURE__ */ new Set();
|
|
12063
|
-
for (const
|
|
12064
|
-
if (!TEXT_ARTIFACT.test(
|
|
12065
|
-
const text2 = readText2(path27__namespace.join(snapshotDir,
|
|
12246
|
+
for (const relative16 of walk(snapshotDir)) {
|
|
12247
|
+
if (!TEXT_ARTIFACT.test(relative16)) continue;
|
|
12248
|
+
const text2 = readText2(path27__namespace.join(snapshotDir, relative16));
|
|
12066
12249
|
if (text2 === null) continue;
|
|
12067
12250
|
for (const pattern of patterns) {
|
|
12068
|
-
for (const match of text2.match(pattern) ?? []) hits.add(
|
|
12251
|
+
for (const match of text2.match(pattern) ?? []) hits.add(relative16 + ": " + match);
|
|
12069
12252
|
}
|
|
12070
12253
|
repoPattern.lastIndex = 0;
|
|
12071
|
-
if (repoPattern.test(text2)) hits.add(
|
|
12254
|
+
if (repoPattern.test(text2)) hits.add(relative16 + ": the repository absolute path");
|
|
12072
12255
|
}
|
|
12073
12256
|
return [...hits];
|
|
12074
12257
|
}
|
|
@@ -12315,13 +12498,13 @@ function auditSnapshot(options) {
|
|
|
12315
12498
|
let artifactCount = 0;
|
|
12316
12499
|
for (const [key, value] of Object.entries(artifacts)) {
|
|
12317
12500
|
if (value === null || value === void 0) continue;
|
|
12318
|
-
const
|
|
12319
|
-
if (
|
|
12501
|
+
const relative16 = ARTIFACT_FILES[key];
|
|
12502
|
+
if (relative16 === void 0) continue;
|
|
12320
12503
|
artifactCount += 1;
|
|
12321
|
-
const bytes = readBytes(path27__namespace.join(snapshotDir,
|
|
12322
|
-
if (bytes === null) artifactProblems.push(
|
|
12504
|
+
const bytes = readBytes(path27__namespace.join(snapshotDir, relative16));
|
|
12505
|
+
if (bytes === null) artifactProblems.push(relative16 + " is missing");
|
|
12323
12506
|
else if (typeof value.sha256 === "string" && sha256(bytes) !== value.sha256) {
|
|
12324
|
-
artifactProblems.push(
|
|
12507
|
+
artifactProblems.push(relative16 + " changed");
|
|
12325
12508
|
}
|
|
12326
12509
|
}
|
|
12327
12510
|
checks.push(
|
|
@@ -13051,25 +13234,25 @@ function auditSnapshot(options) {
|
|
|
13051
13234
|
const scanBudget = options.maxScanBytes ?? 32 * 1024 * 1024;
|
|
13052
13235
|
const leakHits = [];
|
|
13053
13236
|
let scannedBytes = 0;
|
|
13054
|
-
for (const
|
|
13055
|
-
if (!TEXT_ARTIFACT.test(
|
|
13056
|
-
if (
|
|
13057
|
-
const text2 = readText2(path27__namespace.join(snapshotDir,
|
|
13237
|
+
for (const relative16 of walk(snapshotDir)) {
|
|
13238
|
+
if (!TEXT_ARTIFACT.test(relative16) || scannedBytes > scanBudget) continue;
|
|
13239
|
+
if (relative16 === SIGNATURE_FILE) continue;
|
|
13240
|
+
const text2 = readText2(path27__namespace.join(snapshotDir, relative16));
|
|
13058
13241
|
if (text2 === null) continue;
|
|
13059
13242
|
scannedBytes += Buffer.byteLength(text2, "utf8");
|
|
13060
13243
|
let findingCount = 0;
|
|
13061
|
-
if (/^parts[\\/].*\.md$/i.test(
|
|
13244
|
+
if (/^parts[\\/].*\.md$/i.test(relative16)) {
|
|
13062
13245
|
let headerText = text2;
|
|
13063
13246
|
for (const section of parsePartSections(text2)) {
|
|
13064
13247
|
findingCount += scanAndRedactSecrets(section.body, rules, section.path).findings.length;
|
|
13065
13248
|
headerText = headerText.replace(section.body, "");
|
|
13066
13249
|
}
|
|
13067
|
-
findingCount += scanAndRedactSecrets(headerText, rules,
|
|
13250
|
+
findingCount += scanAndRedactSecrets(headerText, rules, relative16).findings.length;
|
|
13068
13251
|
} else {
|
|
13069
|
-
findingCount = scanAndRedactSecrets(text2, rules,
|
|
13252
|
+
findingCount = scanAndRedactSecrets(text2, rules, relative16).findings.length;
|
|
13070
13253
|
}
|
|
13071
13254
|
if (findingCount > 0) {
|
|
13072
|
-
leakHits.push(
|
|
13255
|
+
leakHits.push(relative16 + " (" + findingCount + " line(s))");
|
|
13073
13256
|
}
|
|
13074
13257
|
}
|
|
13075
13258
|
const signatureRecordPath = path27__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
@@ -13283,6 +13466,7 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
13283
13466
|
const manifest = mod.generateSnapshot(config, {
|
|
13284
13467
|
dryRun: workerData.dryRun === true,
|
|
13285
13468
|
...(workerData.narrow ?? {}),
|
|
13469
|
+
...(workerData.runId === undefined ? {} : { runId: workerData.runId }),
|
|
13286
13470
|
});
|
|
13287
13471
|
const skipCounts = new Map();
|
|
13288
13472
|
for (const record of manifest.skipped) {
|
|
@@ -13328,8 +13512,13 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
13328
13512
|
const finish = (result) => {
|
|
13329
13513
|
if (settled) return;
|
|
13330
13514
|
settled = true;
|
|
13331
|
-
|
|
13332
|
-
|
|
13515
|
+
const terminated = worker === null ? Promise.resolve(void 0) : worker.terminate();
|
|
13516
|
+
void terminated.catch(() => void 0).then(() => {
|
|
13517
|
+
if (!result.ok && options.runId !== void 0 && options.lockRoots !== void 0) {
|
|
13518
|
+
releaseAbandonedRun(options.lockRoots, options.runId);
|
|
13519
|
+
}
|
|
13520
|
+
resolve15(result);
|
|
13521
|
+
});
|
|
13333
13522
|
};
|
|
13334
13523
|
const isCjs = typeof __dirname !== "undefined";
|
|
13335
13524
|
const directory = isCjs ? __dirname : path27__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href))));
|
|
@@ -13341,7 +13530,8 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
13341
13530
|
cwd,
|
|
13342
13531
|
cliOptions,
|
|
13343
13532
|
dryRun: options.dryRun === true,
|
|
13344
|
-
narrow: options.narrow ?? {}
|
|
13533
|
+
narrow: options.narrow ?? {},
|
|
13534
|
+
...options.runId === void 0 ? {} : { runId: options.runId }
|
|
13345
13535
|
}
|
|
13346
13536
|
});
|
|
13347
13537
|
} catch (error) {
|
|
@@ -13506,7 +13696,16 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
13506
13696
|
if (overrides.withDependents === true) cliOptions.withDependents = true;
|
|
13507
13697
|
try {
|
|
13508
13698
|
const config = resolveConfig(loaded.config, cliOptions, root);
|
|
13509
|
-
return {
|
|
13699
|
+
return {
|
|
13700
|
+
ok: true,
|
|
13701
|
+
workspace: {
|
|
13702
|
+
root,
|
|
13703
|
+
config,
|
|
13704
|
+
configFile: loaded.file,
|
|
13705
|
+
sourceConfig: loaded.config ?? null,
|
|
13706
|
+
cliOptions
|
|
13707
|
+
}
|
|
13708
|
+
};
|
|
13510
13709
|
} catch (error) {
|
|
13511
13710
|
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
13512
13711
|
}
|
|
@@ -13520,8 +13719,8 @@ function partPathFor(workspace, filename) {
|
|
|
13520
13719
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
13521
13720
|
const partsDir = path27__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
13522
13721
|
const resolved = path27__namespace.resolve(partsDir, filename);
|
|
13523
|
-
const
|
|
13524
|
-
if (
|
|
13722
|
+
const relative16 = path27__namespace.relative(partsDir, resolved);
|
|
13723
|
+
if (relative16.length === 0 || relative16.includes(path27__namespace.sep) || relative16.includes("/") || relative16.includes("\\") || path27__namespace.isAbsolute(relative16)) {
|
|
13525
13724
|
return null;
|
|
13526
13725
|
}
|
|
13527
13726
|
let stats;
|
|
@@ -13695,11 +13894,11 @@ function toRelativePath(root, value) {
|
|
|
13695
13894
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
13696
13895
|
const resolvedRoot = path27__namespace.resolve(root);
|
|
13697
13896
|
const absolute = path27__namespace.resolve(resolvedRoot, cleaned);
|
|
13698
|
-
const
|
|
13699
|
-
if (
|
|
13897
|
+
const relative16 = path27__namespace.relative(resolvedRoot, absolute);
|
|
13898
|
+
if (relative16 === "" || relative16 === ".." || relative16.startsWith(`..${path27__namespace.sep}`) || path27__namespace.isAbsolute(relative16)) {
|
|
13700
13899
|
return null;
|
|
13701
13900
|
}
|
|
13702
|
-
return
|
|
13901
|
+
return relative16.split(path27__namespace.sep).join("/");
|
|
13703
13902
|
}
|
|
13704
13903
|
function symbolsOf(entry) {
|
|
13705
13904
|
const summary = entry.summary;
|
|
@@ -13913,7 +14112,9 @@ var testsTool = {
|
|
|
13913
14112
|
const cap = Math.max(1, typeof args.maxFiles === "number" ? args.maxFiles : 50);
|
|
13914
14113
|
const isTest2 = (filePath) => /(^|\/)(tests?|__tests__|spec)\//.test(filePath) || /\.(test|spec)\.[a-z0-9]+$/i.test(filePath);
|
|
13915
14114
|
const byPath = new Map(read.manifest.files.map((file) => [file.relativePath, file]));
|
|
13916
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
14115
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
14116
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
14117
|
+
});
|
|
13917
14118
|
const testFiles = read.manifest.files.filter((file) => isTest2(file.relativePath));
|
|
13918
14119
|
const importsOf = (filePath) => {
|
|
13919
14120
|
const entry = read.manifest.indexes.imports.byFile.find((candidate) => candidate.path === filePath);
|
|
@@ -13961,9 +14162,13 @@ var workspaceTool = {
|
|
|
13961
14162
|
},
|
|
13962
14163
|
annotations: READ_ONLY,
|
|
13963
14164
|
async handler(args, context) {
|
|
13964
|
-
const
|
|
13965
|
-
|
|
13966
|
-
const index = path27__namespace.resolve(
|
|
14165
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
14166
|
+
if (!prepared.ok) return prepared.outcome;
|
|
14167
|
+
const index = path27__namespace.resolve(
|
|
14168
|
+
prepared.workspace.root,
|
|
14169
|
+
prepared.workspace.config.outDir,
|
|
14170
|
+
"WORKSPACE.json"
|
|
14171
|
+
);
|
|
13967
14172
|
let text2;
|
|
13968
14173
|
try {
|
|
13969
14174
|
text2 = fs24__namespace.readFileSync(index, "utf8");
|
|
@@ -14020,7 +14225,9 @@ var neighborsTool = {
|
|
|
14020
14225
|
const file = read.manifest.files.find((candidate) => candidate.relativePath === wanted) ?? read.manifest.files.find((candidate) => candidate.relativePath.toLowerCase() === wanted.toLowerCase());
|
|
14021
14226
|
if (file === void 0) return { text: wanted + " is not in the snapshot; snapshot_explain says why.", isError: true };
|
|
14022
14227
|
const byPath = new Map(read.manifest.files.map((candidate) => [candidate.relativePath, candidate]));
|
|
14023
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
14228
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
14229
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
14230
|
+
});
|
|
14024
14231
|
const entry = read.manifest.indexes.imports.byFile.find((candidate) => candidate.path === file.relativePath);
|
|
14025
14232
|
const imports = [];
|
|
14026
14233
|
for (const specifier of entry?.imports ?? []) {
|
|
@@ -14162,7 +14369,9 @@ var cyclesTool = {
|
|
|
14162
14369
|
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
14163
14370
|
const cap = Math.max(1, typeof args.maxComponents === "number" ? args.maxComponents : 20);
|
|
14164
14371
|
const byPath = new Map(read.manifest.files.map((file) => [file.relativePath, file]));
|
|
14165
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
14372
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
14373
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
14374
|
+
});
|
|
14166
14375
|
const edges = /* @__PURE__ */ new Map();
|
|
14167
14376
|
for (const path28 of byPath.keys()) edges.set(path28, []);
|
|
14168
14377
|
for (const entry of read.manifest.indexes.imports.byFile) {
|
|
@@ -15362,10 +15571,17 @@ var generateTool = {
|
|
|
15362
15571
|
...typeof args.slice === "string" ? { slice: { question: args.slice, ...typeof args.sliceTokens === "number" ? { maxTokens: args.sliceTokens } : {} } } : {},
|
|
15363
15572
|
...typeof args.budgetTokens === "number" ? { budgetTokens: args.budgetTokens } : {}
|
|
15364
15573
|
};
|
|
15574
|
+
let lockRoots;
|
|
15575
|
+
try {
|
|
15576
|
+
const safe = resolveSafeOutputDirs(workspace.config);
|
|
15577
|
+
lockRoots = [safe.outDir, safe.tmpDir];
|
|
15578
|
+
} catch (error) {
|
|
15579
|
+
return failure(error instanceof Error ? error.message : String(error));
|
|
15580
|
+
}
|
|
15365
15581
|
const result = await generateInWorker(
|
|
15366
15582
|
workspace.root,
|
|
15367
15583
|
{ ...workspace.cliOptions, ...reportOptions },
|
|
15368
|
-
{ signal: controller.signal, narrow }
|
|
15584
|
+
{ signal: controller.signal, narrow, runId: crypto.randomUUID(), lockRoots }
|
|
15369
15585
|
);
|
|
15370
15586
|
if (!result.ok) return failure(result.message);
|
|
15371
15587
|
context.notify?.({ message: "writing the snapshot", progress: 2, total: 2 });
|
|
@@ -15399,16 +15615,42 @@ var generateTool = {
|
|
|
15399
15615
|
};
|
|
15400
15616
|
function configAsGenerated(workspace, manifest) {
|
|
15401
15617
|
const recorded = manifest.config;
|
|
15618
|
+
const cli = workspace.cliOptions;
|
|
15619
|
+
const source = workspace.sourceConfig;
|
|
15620
|
+
const configured = (key) => source !== null && Object.prototype.hasOwnProperty.call(source, key);
|
|
15621
|
+
const sourceArtifacts = source !== null && source.artifacts !== null && typeof source.artifacts === "object" ? source.artifacts : null;
|
|
15622
|
+
const artifacts = { ...workspace.config.artifacts };
|
|
15623
|
+
if (recorded?.artifacts !== void 0) {
|
|
15624
|
+
for (const [key, value] of Object.entries(recorded.artifacts)) {
|
|
15625
|
+
if (sourceArtifacts === null || !Object.prototype.hasOwnProperty.call(sourceArtifacts, key)) {
|
|
15626
|
+
artifacts[key] = value;
|
|
15627
|
+
}
|
|
15628
|
+
}
|
|
15629
|
+
}
|
|
15630
|
+
let artifactOverride = recorded?.artifacts !== void 0;
|
|
15631
|
+
if (cli.includeDiffs === true) {
|
|
15632
|
+
artifacts.diff = true;
|
|
15633
|
+
artifactOverride = true;
|
|
15634
|
+
}
|
|
15635
|
+
if (cli.includeLogs !== void 0) {
|
|
15636
|
+
artifacts.log = true;
|
|
15637
|
+
artifactOverride = true;
|
|
15638
|
+
}
|
|
15639
|
+
if (cli.tokenTree === true) {
|
|
15640
|
+
artifacts.tokenTree = true;
|
|
15641
|
+
artifactOverride = true;
|
|
15642
|
+
}
|
|
15643
|
+
const choose = (key, recordedValue, current, cliValue) => cliValue !== void 0 ? cliValue : configured(key) ? current : recordedValue ?? current;
|
|
15402
15644
|
return {
|
|
15403
15645
|
...workspace.config,
|
|
15404
|
-
...
|
|
15405
|
-
...recorded?.stripComments
|
|
15406
|
-
...recorded?.removeEmptyLines
|
|
15407
|
-
...recorded?.pack
|
|
15408
|
-
...recorded?.logCount
|
|
15409
|
-
...recorded?.skeleton
|
|
15410
|
-
...recorded?.sarif
|
|
15411
|
-
...recorded?.maxParts
|
|
15646
|
+
...artifactOverride ? { artifacts } : {},
|
|
15647
|
+
...cli.stripComments === true || configured("stripComments") || recorded?.stripComments !== void 0 ? { stripComments: choose("stripComments", recorded?.stripComments, workspace.config.stripComments, cli.stripComments === true ? true : void 0) } : {},
|
|
15648
|
+
...cli.removeEmptyLines === true || configured("removeEmptyLines") || recorded?.removeEmptyLines !== void 0 ? { removeEmptyLines: choose("removeEmptyLines", recorded?.removeEmptyLines, workspace.config.removeEmptyLines, cli.removeEmptyLines === true ? true : void 0) } : {},
|
|
15649
|
+
...cli.pack !== void 0 || configured("pack") || recorded?.pack !== void 0 ? { pack: choose("pack", recorded?.pack ?? void 0, workspace.config.pack, cli.pack) } : {},
|
|
15650
|
+
...cli.includeLogs !== void 0 || configured("logCount") || recorded?.logCount !== void 0 ? { logCount: choose("logCount", recorded?.logCount, workspace.config.logCount, cli.includeLogs) } : {},
|
|
15651
|
+
...cli.skeleton === true || configured("skeleton") || recorded?.skeleton !== void 0 ? { skeleton: choose("skeleton", recorded?.skeleton, workspace.config.skeleton, cli.skeleton === true ? true : void 0) } : {},
|
|
15652
|
+
...cli.sarif === true || configured("sarif") || recorded?.sarif !== void 0 ? { sarif: choose("sarif", recorded?.sarif, workspace.config.sarif, cli.sarif === true ? true : void 0) } : {},
|
|
15653
|
+
...configured("maxParts") || recorded?.maxParts !== void 0 ? { maxParts: choose("maxParts", recorded?.maxParts, workspace.config.maxParts) } : {}
|
|
15412
15654
|
};
|
|
15413
15655
|
}
|
|
15414
15656
|
var validateTool = {
|
|
@@ -15645,7 +15887,9 @@ var dependentsTool = {
|
|
|
15645
15887
|
}
|
|
15646
15888
|
const direction = args.direction === "imports" || args.direction === "imported-by" ? String(args.direction) : "both";
|
|
15647
15889
|
const limit = typeof args.limit === "number" && args.limit > 0 ? Math.floor(args.limit) : 50;
|
|
15648
|
-
const resolver = buildImportResolver(manifest.files
|
|
15890
|
+
const resolver = buildImportResolver(manifest.files, {
|
|
15891
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
15892
|
+
});
|
|
15649
15893
|
const imports = [];
|
|
15650
15894
|
const unresolved = [];
|
|
15651
15895
|
if (direction !== "imported-by") {
|
|
@@ -17123,6 +17367,10 @@ function buildAgentContract() {
|
|
|
17123
17367
|
{ key: "maxPartBytes", type: "number | string", default: 307200, summary: "Per-part byte budget." },
|
|
17124
17368
|
{ key: "maxPartTokens", type: "number | string | null", default: null, summary: "Per-part token ceiling; narrows maxPartBytes. Minimum 1024." },
|
|
17125
17369
|
{ key: "skeleton", type: "boolean", default: false, summary: "Collapse function bodies to `{ /* ... */ }` in TS, JS, TSX and JSX files." },
|
|
17370
|
+
{ key: "stripComments", type: "boolean", default: false, summary: "Remove comment text from JS/TS bodies." },
|
|
17371
|
+
{ key: "removeEmptyLines", type: "boolean", default: false, summary: "Drop blank lines from emitted bodies; the part's line numbers move, and files[] records emptyLinesRemoved." },
|
|
17372
|
+
{ key: "pack", type: '"single" | "xml" | "json" | null', default: null, summary: "Write one single-file pack in this format." },
|
|
17373
|
+
{ key: "logCount", type: "number", default: 20, summary: "Commit lines in reports/log.md (also set by --include-logs <n>)." },
|
|
17126
17374
|
{ key: "sarif", type: "boolean", default: false, summary: "Also write reports/audit.sarif." },
|
|
17127
17375
|
{ key: "changedSince", type: "string | null", default: null, summary: "Snapshot only files that differ from this git ref." },
|
|
17128
17376
|
{ key: "staged", type: "boolean", default: false, summary: "Snapshot only files staged in the index." },
|
|
@@ -18294,9 +18542,9 @@ function dosDateTime(date) {
|
|
|
18294
18542
|
function walkFiles(root, prefix = "") {
|
|
18295
18543
|
const files = [];
|
|
18296
18544
|
for (const entry of fs24__namespace.readdirSync(path27__namespace.join(root, prefix), { withFileTypes: true })) {
|
|
18297
|
-
const
|
|
18298
|
-
if (entry.isDirectory()) files.push(...walkFiles(root,
|
|
18299
|
-
else if (entry.isFile()) files.push(
|
|
18545
|
+
const relative16 = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
18546
|
+
if (entry.isDirectory()) files.push(...walkFiles(root, relative16));
|
|
18547
|
+
else if (entry.isFile()) files.push(relative16);
|
|
18300
18548
|
}
|
|
18301
18549
|
return files;
|
|
18302
18550
|
}
|
|
@@ -18304,11 +18552,11 @@ function writeZip(options) {
|
|
|
18304
18552
|
const entries = [...options.entries ?? []];
|
|
18305
18553
|
if (options.directory !== void 0) {
|
|
18306
18554
|
const root = options.directory;
|
|
18307
|
-
for (const
|
|
18308
|
-
if (options.skip !== void 0 && options.skip(
|
|
18309
|
-
const full = path27__namespace.join(root,
|
|
18555
|
+
for (const relative16 of walkFiles(root)) {
|
|
18556
|
+
if (options.skip !== void 0 && options.skip(relative16)) continue;
|
|
18557
|
+
const full = path27__namespace.join(root, relative16);
|
|
18310
18558
|
const stat = fs24__namespace.statSync(full);
|
|
18311
|
-
entries.push({ name:
|
|
18559
|
+
entries.push({ name: relative16, content: fs24__namespace.readFileSync(full), mtime: stat.mtime });
|
|
18312
18560
|
}
|
|
18313
18561
|
}
|
|
18314
18562
|
if (entries.length > 65535) {
|
|
@@ -18501,8 +18749,13 @@ var SERVE_PAGE = `<!doctype html>
|
|
|
18501
18749
|
$("counts").textContent = info.included + " included / " + info.skipped + " skipped";
|
|
18502
18750
|
$("files").innerHTML = "";
|
|
18503
18751
|
for (const file of info.files.slice(0, 400)) {
|
|
18752
|
+
// A manifest is untrusted input. Interpolating file.part (or a path) into innerHTML let a
|
|
18753
|
+
// crafted manifest run script in the serve origin and read the token from localStorage.
|
|
18504
18754
|
const li = document.createElement("li");
|
|
18505
|
-
|
|
18755
|
+
const name = document.createElement("b");
|
|
18756
|
+
name.textContent = file.path;
|
|
18757
|
+
li.appendChild(name);
|
|
18758
|
+
li.appendChild(document.createTextNode(" " + file.part));
|
|
18506
18759
|
$("files").appendChild(li);
|
|
18507
18760
|
}
|
|
18508
18761
|
}
|
|
@@ -18539,16 +18792,55 @@ async function startWebServer(options) {
|
|
|
18539
18792
|
if (token === null && !["127.0.0.1", "localhost", "::1"].includes(host)) {
|
|
18540
18793
|
throw new Error("Refusing to serve " + host + " without a token.");
|
|
18541
18794
|
}
|
|
18542
|
-
const
|
|
18795
|
+
const createMcp = () => createServer({ cwd: options.cwd, log });
|
|
18796
|
+
const mcpPerSocket = /* @__PURE__ */ new WeakMap();
|
|
18797
|
+
const mcpFor = (socket) => {
|
|
18798
|
+
let server2 = mcpPerSocket.get(socket);
|
|
18799
|
+
if (server2 === void 0) {
|
|
18800
|
+
server2 = createMcp();
|
|
18801
|
+
mcpPerSocket.set(socket, server2);
|
|
18802
|
+
}
|
|
18803
|
+
return server2;
|
|
18804
|
+
};
|
|
18543
18805
|
const temporaryClones = /* @__PURE__ */ new Set();
|
|
18544
18806
|
const allowedRoots = [path27__namespace.resolve(options.cwd)];
|
|
18807
|
+
const canonical = (candidate) => {
|
|
18808
|
+
try {
|
|
18809
|
+
return fs24__namespace.realpathSync(candidate);
|
|
18810
|
+
} catch {
|
|
18811
|
+
return null;
|
|
18812
|
+
}
|
|
18813
|
+
};
|
|
18814
|
+
const inside = (resolved) => allowedRoots.some((root) => {
|
|
18815
|
+
const canonicalRoot = canonical(root);
|
|
18816
|
+
if (canonicalRoot === null) return false;
|
|
18817
|
+
const relative16 = path27__namespace.relative(canonicalRoot, resolved);
|
|
18818
|
+
return relative16 === "" || !relative16.startsWith(`..${path27__namespace.sep}`) && relative16 !== ".." && !path27__namespace.isAbsolute(relative16);
|
|
18819
|
+
});
|
|
18545
18820
|
const insideAllowedRoots = (candidate) => {
|
|
18821
|
+
const resolved = canonical(candidate);
|
|
18822
|
+
return resolved === null ? false : inside(resolved);
|
|
18823
|
+
};
|
|
18824
|
+
const lexicallyInside = (candidate) => {
|
|
18546
18825
|
const resolved = path27__namespace.resolve(candidate);
|
|
18547
18826
|
return allowedRoots.some((root) => {
|
|
18548
|
-
const prefix =
|
|
18549
|
-
return resolved === root || resolved.startsWith(prefix);
|
|
18827
|
+
const prefix = path27__namespace.resolve(root) + path27__namespace.sep;
|
|
18828
|
+
return resolved === path27__namespace.resolve(root) || resolved.startsWith(prefix);
|
|
18550
18829
|
});
|
|
18551
18830
|
};
|
|
18831
|
+
const insideAllowedRootsForWrite = (candidate) => {
|
|
18832
|
+
let existing = path27__namespace.resolve(candidate);
|
|
18833
|
+
const tail = [];
|
|
18834
|
+
while (!fs24__namespace.existsSync(existing)) {
|
|
18835
|
+
tail.unshift(path27__namespace.basename(existing));
|
|
18836
|
+
const parent = path27__namespace.dirname(existing);
|
|
18837
|
+
if (parent === existing) break;
|
|
18838
|
+
existing = parent;
|
|
18839
|
+
}
|
|
18840
|
+
const resolved = canonical(existing);
|
|
18841
|
+
if (resolved === null) return false;
|
|
18842
|
+
return inside(tail.length === 0 ? resolved : path27__namespace.join(resolved, ...tail));
|
|
18843
|
+
};
|
|
18552
18844
|
const authorized = (request) => {
|
|
18553
18845
|
if (token === null) return true;
|
|
18554
18846
|
const header = request.headers.authorization ?? "";
|
|
@@ -18572,7 +18864,10 @@ async function startWebServer(options) {
|
|
|
18572
18864
|
cors["access-control-allow-headers"] = "authorization, content-type";
|
|
18573
18865
|
cors["access-control-allow-methods"] = "GET, POST, OPTIONS";
|
|
18574
18866
|
}
|
|
18867
|
+
let responseSent = false;
|
|
18575
18868
|
const send = (status, body, extra = {}) => {
|
|
18869
|
+
if (responseSent) return;
|
|
18870
|
+
responseSent = true;
|
|
18576
18871
|
const text2 = typeof body === "string" ? body : JSON.stringify(body);
|
|
18577
18872
|
response.writeHead(status, {
|
|
18578
18873
|
...cors,
|
|
@@ -18603,10 +18898,13 @@ async function startWebServer(options) {
|
|
|
18603
18898
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
18604
18899
|
if (request.method === "POST" && (request.url === "/mcp" || (request.url ?? "").startsWith("/mcp?"))) {
|
|
18605
18900
|
let received = 0;
|
|
18901
|
+
let tooLarge = false;
|
|
18606
18902
|
const chunks = [];
|
|
18607
18903
|
request.on("data", (chunk) => {
|
|
18904
|
+
if (tooLarge) return;
|
|
18608
18905
|
received += chunk.length;
|
|
18609
18906
|
if (received > 2 * 1024 * 1024) {
|
|
18907
|
+
tooLarge = true;
|
|
18610
18908
|
request.destroy();
|
|
18611
18909
|
send(413, { error: "request body too large" });
|
|
18612
18910
|
return;
|
|
@@ -18614,6 +18912,7 @@ async function startWebServer(options) {
|
|
|
18614
18912
|
chunks.push(chunk);
|
|
18615
18913
|
});
|
|
18616
18914
|
request.on("end", () => {
|
|
18915
|
+
if (tooLarge) return;
|
|
18617
18916
|
void (async () => {
|
|
18618
18917
|
let message;
|
|
18619
18918
|
try {
|
|
@@ -18623,9 +18922,14 @@ async function startWebServer(options) {
|
|
|
18623
18922
|
return;
|
|
18624
18923
|
}
|
|
18625
18924
|
const batch = Array.isArray(message) ? message : [message];
|
|
18925
|
+
if (batch.length > 100) {
|
|
18926
|
+
send(400, { error: "JSON-RPC batch is limited to 100 messages" });
|
|
18927
|
+
return;
|
|
18928
|
+
}
|
|
18929
|
+
const server2 = mcpFor(request.socket);
|
|
18626
18930
|
const answers = [];
|
|
18627
18931
|
for (const item of batch) {
|
|
18628
|
-
const answer = await
|
|
18932
|
+
const answer = await server2.handle(item);
|
|
18629
18933
|
if (answer !== null) answers.push(answer);
|
|
18630
18934
|
}
|
|
18631
18935
|
if (answers.length === 0) send(202, "");
|
|
@@ -18636,10 +18940,13 @@ async function startWebServer(options) {
|
|
|
18636
18940
|
}
|
|
18637
18941
|
if (request.method === "POST" && request.url === "/api/generate") {
|
|
18638
18942
|
let received = 0;
|
|
18943
|
+
let tooLarge = false;
|
|
18639
18944
|
const chunks = [];
|
|
18640
18945
|
request.on("data", (chunk) => {
|
|
18946
|
+
if (tooLarge) return;
|
|
18641
18947
|
received += chunk.length;
|
|
18642
18948
|
if (received > MAX_BODY) {
|
|
18949
|
+
tooLarge = true;
|
|
18643
18950
|
request.destroy();
|
|
18644
18951
|
send(413, { error: "request body too large" });
|
|
18645
18952
|
return;
|
|
@@ -18647,6 +18954,7 @@ async function startWebServer(options) {
|
|
|
18647
18954
|
chunks.push(chunk);
|
|
18648
18955
|
});
|
|
18649
18956
|
request.on("end", () => {
|
|
18957
|
+
if (tooLarge) return;
|
|
18650
18958
|
void (async () => {
|
|
18651
18959
|
let source = "";
|
|
18652
18960
|
let mode = "full";
|
|
@@ -18703,6 +19011,10 @@ async function startWebServer(options) {
|
|
|
18703
19011
|
}
|
|
18704
19012
|
} else {
|
|
18705
19013
|
target = path27__namespace.resolve(options.cwd, source);
|
|
19014
|
+
if (!insideAllowedRoots(target)) {
|
|
19015
|
+
send(403, { error: "outside the served directory: " + target });
|
|
19016
|
+
return;
|
|
19017
|
+
}
|
|
18706
19018
|
}
|
|
18707
19019
|
let stat;
|
|
18708
19020
|
try {
|
|
@@ -18720,15 +19032,26 @@ async function startWebServer(options) {
|
|
|
18720
19032
|
send(400, { error: loaded.errors.join("; ") });
|
|
18721
19033
|
return;
|
|
18722
19034
|
}
|
|
19035
|
+
const runConfig = isRemote ? {
|
|
19036
|
+
...loaded.config ?? {},
|
|
19037
|
+
outDir: "snapshot",
|
|
19038
|
+
tmpDir: "snapshot.tmp",
|
|
19039
|
+
hooks: {}
|
|
19040
|
+
} : loaded.config ?? {};
|
|
19041
|
+
const configuredOutDir = typeof runConfig.outDir === "string" && runConfig.outDir.trim() !== "" ? runConfig.outDir : "snapshot";
|
|
19042
|
+
const snapshotDir = path27__namespace.resolve(target, configuredOutDir);
|
|
19043
|
+
if (!insideAllowedRootsForWrite(snapshotDir)) {
|
|
19044
|
+
send(403, { error: "the configured outDir resolves outside the served directory" });
|
|
19045
|
+
return;
|
|
19046
|
+
}
|
|
18723
19047
|
const started = Date.now();
|
|
18724
19048
|
try {
|
|
18725
|
-
const manifest = generateSnapshot({ ...
|
|
19049
|
+
const manifest = generateSnapshot({ ...runConfig, cwd: target }, {
|
|
18726
19050
|
...provenance === void 0 ? {} : { source: provenance },
|
|
18727
19051
|
...mode === "slice" ? { slice: { question } } : {},
|
|
18728
19052
|
...mode === "budget" && budgetTokens !== void 0 ? { budgetTokens } : {}
|
|
18729
19053
|
});
|
|
18730
19054
|
const seconds = ((Date.now() - started) / 1e3).toFixed(2);
|
|
18731
|
-
const snapshotDir = path27__namespace.join(target, "snapshot");
|
|
18732
19055
|
const health = auditSnapshot({ snapshotDir, repoDir: target });
|
|
18733
19056
|
send(200, {
|
|
18734
19057
|
path: snapshotDir,
|
|
@@ -18756,7 +19079,7 @@ async function startWebServer(options) {
|
|
|
18756
19079
|
}
|
|
18757
19080
|
if (request.method === "GET" && request.url?.startsWith("/api/health?") === true) {
|
|
18758
19081
|
const target = path27__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
18759
|
-
if (!
|
|
19082
|
+
if (!lexicallyInside(target)) {
|
|
18760
19083
|
send(403, { error: "outside the served directory: " + target });
|
|
18761
19084
|
return;
|
|
18762
19085
|
}
|
|
@@ -18764,12 +19087,24 @@ async function startWebServer(options) {
|
|
|
18764
19087
|
send(404, { error: "no manifest.json under " + target });
|
|
18765
19088
|
return;
|
|
18766
19089
|
}
|
|
19090
|
+
if (!insideAllowedRoots(target)) {
|
|
19091
|
+
send(403, { error: "outside the served directory: " + target });
|
|
19092
|
+
return;
|
|
19093
|
+
}
|
|
18767
19094
|
const report2 = auditSnapshot({ snapshotDir: target, repoDir: path27__namespace.dirname(target) });
|
|
18768
19095
|
send(200, { score: report2.score, counts: report2.counts, checks: report2.checks });
|
|
18769
19096
|
return;
|
|
18770
19097
|
}
|
|
18771
19098
|
if (request.method === "GET" && (request.url?.startsWith("/api/snapshot?") === true || request.url === "/api/snapshot")) {
|
|
18772
19099
|
const target = path27__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
19100
|
+
if (!lexicallyInside(target)) {
|
|
19101
|
+
send(403, { error: "outside the served directory: " + target });
|
|
19102
|
+
return;
|
|
19103
|
+
}
|
|
19104
|
+
if (!fs24__namespace.existsSync(path27__namespace.join(target, "manifest.json"))) {
|
|
19105
|
+
send(404, { error: "no manifest.json under " + target });
|
|
19106
|
+
return;
|
|
19107
|
+
}
|
|
18773
19108
|
if (!insideAllowedRoots(target)) {
|
|
18774
19109
|
send(403, { error: "outside the served directory: " + target });
|
|
18775
19110
|
return;
|
|
@@ -18782,6 +19117,11 @@ async function startWebServer(options) {
|
|
|
18782
19117
|
send(404, { error: "no manifest.json under " + target });
|
|
18783
19118
|
return;
|
|
18784
19119
|
}
|
|
19120
|
+
const shapeProblem = describeManifestShapeProblem(manifest);
|
|
19121
|
+
if (shapeProblem !== null) {
|
|
19122
|
+
send(400, { error: "manifest.json is not a snapshot manifest: " + shapeProblem });
|
|
19123
|
+
return;
|
|
19124
|
+
}
|
|
18785
19125
|
let prompt = "";
|
|
18786
19126
|
try {
|
|
18787
19127
|
prompt = fs24__namespace.readFileSync(path27__namespace.join(target, "PROMPT.md"), "utf8").slice(0, MAX_PREVIEW);
|
|
@@ -18801,7 +19141,7 @@ async function startWebServer(options) {
|
|
|
18801
19141
|
}
|
|
18802
19142
|
if (request.method === "GET" && request.url?.startsWith("/api/snapshot.zip") === true) {
|
|
18803
19143
|
const target = path27__namespace.resolve(options.cwd, url.searchParams.get("path") ?? options.cwd);
|
|
18804
|
-
if (!
|
|
19144
|
+
if (!lexicallyInside(target)) {
|
|
18805
19145
|
send(403, { error: "outside the served directory: " + target });
|
|
18806
19146
|
return;
|
|
18807
19147
|
}
|
|
@@ -18809,6 +19149,10 @@ async function startWebServer(options) {
|
|
|
18809
19149
|
send(404, { error: "not a snapshot directory: " + target });
|
|
18810
19150
|
return;
|
|
18811
19151
|
}
|
|
19152
|
+
if (!insideAllowedRoots(target)) {
|
|
19153
|
+
send(403, { error: "outside the served directory: " + target });
|
|
19154
|
+
return;
|
|
19155
|
+
}
|
|
18812
19156
|
try {
|
|
18813
19157
|
const zip = writeZip({ directory: target });
|
|
18814
19158
|
response.writeHead(200, {
|
|
@@ -19118,8 +19462,8 @@ function gitDirectory(cwd) {
|
|
|
19118
19462
|
}
|
|
19119
19463
|
}
|
|
19120
19464
|
function isInside3(parent, child) {
|
|
19121
|
-
const
|
|
19122
|
-
return
|
|
19465
|
+
const relative16 = path27__namespace.relative(parent, child);
|
|
19466
|
+
return relative16 === "" || !relative16.startsWith("..") && !path27__namespace.isAbsolute(relative16);
|
|
19123
19467
|
}
|
|
19124
19468
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
19125
19469
|
try {
|
|
@@ -19571,7 +19915,7 @@ function maskPathText(value, secretRules) {
|
|
|
19571
19915
|
}
|
|
19572
19916
|
function maskOwnerBrief(brief, secretRules) {
|
|
19573
19917
|
if (brief === void 0) return void 0;
|
|
19574
|
-
const mask = (value) =>
|
|
19918
|
+
const mask = (value) => scanAndRedactSecrets(value, secretRules ?? [], "owner-brief").redacted;
|
|
19575
19919
|
return {
|
|
19576
19920
|
...brief,
|
|
19577
19921
|
path: mask(brief.path),
|
|
@@ -19617,9 +19961,9 @@ function listEntries(dir) {
|
|
|
19617
19961
|
return;
|
|
19618
19962
|
}
|
|
19619
19963
|
for (const child of children) {
|
|
19620
|
-
const
|
|
19621
|
-
entries.push(
|
|
19622
|
-
if (child.isDirectory()) walk2(path27__namespace.join(absolute, child.name),
|
|
19964
|
+
const relative16 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
19965
|
+
entries.push(relative16);
|
|
19966
|
+
if (child.isDirectory()) walk2(path27__namespace.join(absolute, child.name), relative16);
|
|
19623
19967
|
}
|
|
19624
19968
|
};
|
|
19625
19969
|
walk2(dir, "");
|
|
@@ -19654,7 +19998,7 @@ function markerInventory(dir, written) {
|
|
|
19654
19998
|
}
|
|
19655
19999
|
return { entries, files };
|
|
19656
20000
|
}
|
|
19657
|
-
function markerPayload(dir, state, id, createdAt, written) {
|
|
20001
|
+
function markerPayload(dir, state, id, createdAt, written, runId) {
|
|
19658
20002
|
const { entries, files } = markerInventory(dir, written);
|
|
19659
20003
|
const marker2 = {
|
|
19660
20004
|
generator: GENERATOR_NAME,
|
|
@@ -19663,6 +20007,7 @@ function markerPayload(dir, state, id, createdAt, written) {
|
|
|
19663
20007
|
createdAt,
|
|
19664
20008
|
state,
|
|
19665
20009
|
id,
|
|
20010
|
+
...runId === void 0 ? {} : { runId },
|
|
19666
20011
|
pid: process.pid,
|
|
19667
20012
|
entries,
|
|
19668
20013
|
files
|
|
@@ -19760,6 +20105,7 @@ function readOwnershipMarker(dir) {
|
|
|
19760
20105
|
createdAt: typeof candidate.createdAt === "string" ? candidate.createdAt : "unknown",
|
|
19761
20106
|
state: candidate.state,
|
|
19762
20107
|
id: candidate.id,
|
|
20108
|
+
runId: typeof candidate.runId === "string" ? candidate.runId : void 0,
|
|
19763
20109
|
pid: typeof candidate.pid === "number" ? candidate.pid : void 0,
|
|
19764
20110
|
manifestSha256: typeof candidate.manifestSha256 === "string" ? candidate.manifestSha256 : void 0,
|
|
19765
20111
|
entries: Array.isArray(candidate.entries) && candidate.entries.every((entry) => typeof entry === "string") ? candidate.entries : void 0,
|
|
@@ -19918,13 +20264,19 @@ function assessSnapshotDirectory(dir) {
|
|
|
19918
20264
|
};
|
|
19919
20265
|
}
|
|
19920
20266
|
const entries = listEntries(dir);
|
|
19921
|
-
|
|
20267
|
+
let foreignEntries = entries.filter(
|
|
19922
20268
|
(entry) => !recorded.has(entry) && !isIgnorableEntry(entry)
|
|
19923
20269
|
);
|
|
20270
|
+
const legacySignatureOnly = foreignEntries.length === 1 && foreignEntries[0] === SIGNATURE_FILE && verifySnapshotSignature(dir).ok;
|
|
20271
|
+
if (legacySignatureOnly) foreignEntries = [];
|
|
19924
20272
|
if (foreignEntries.length > 0) {
|
|
19925
20273
|
return { owned: false, problem: null, foreignEntries, marker: marker2 };
|
|
19926
20274
|
}
|
|
19927
|
-
const inventoryProblem = marker2.files === void 0 ? null : verifyMarkerInventory(
|
|
20275
|
+
const inventoryProblem = marker2.files === void 0 ? null : verifyMarkerInventory(
|
|
20276
|
+
dir,
|
|
20277
|
+
legacySignatureOnly ? entries.filter((entry) => entry !== SIGNATURE_FILE) : entries,
|
|
20278
|
+
marker2.files
|
|
20279
|
+
);
|
|
19928
20280
|
return {
|
|
19929
20281
|
owned: inventoryProblem === null,
|
|
19930
20282
|
problem: inventoryProblem,
|
|
@@ -20102,13 +20454,13 @@ function startLockHeartbeat(lockPath) {
|
|
|
20102
20454
|
return () => void 0;
|
|
20103
20455
|
}
|
|
20104
20456
|
}
|
|
20105
|
-
function acquireRunLock(stagingRoot) {
|
|
20457
|
+
function acquireRunLock(stagingRoot, runId) {
|
|
20106
20458
|
const lockPath = lockPathFor(stagingRoot);
|
|
20107
20459
|
const payload = `${JSON.stringify({
|
|
20108
20460
|
pid: process.pid,
|
|
20109
20461
|
stagingRoot,
|
|
20110
20462
|
host: os2__namespace.hostname(),
|
|
20111
|
-
runId
|
|
20463
|
+
runId,
|
|
20112
20464
|
heartbeatMs: LOCK_HEARTBEAT_MS,
|
|
20113
20465
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
20114
20466
|
})}
|
|
@@ -20162,6 +20514,33 @@ function canonicalLockTarget(targetPath2) {
|
|
|
20162
20514
|
function lockPathFor(stagingRoot) {
|
|
20163
20515
|
return path27__namespace.join(os2__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
20164
20516
|
}
|
|
20517
|
+
function releaseAbandonedRun(stagingRoots, runId) {
|
|
20518
|
+
if (runId.length === 0) return;
|
|
20519
|
+
for (const root of new Set(stagingRoots)) {
|
|
20520
|
+
const lockPath = lockPathFor(root);
|
|
20521
|
+
try {
|
|
20522
|
+
const payload = JSON.parse(fs24__namespace.readFileSync(lockPath, "utf8"));
|
|
20523
|
+
if (payload.runId === runId) fs24__namespace.rmSync(lockPath, { force: true });
|
|
20524
|
+
} catch {
|
|
20525
|
+
}
|
|
20526
|
+
let entries;
|
|
20527
|
+
try {
|
|
20528
|
+
entries = fs24__namespace.readdirSync(root);
|
|
20529
|
+
} catch {
|
|
20530
|
+
continue;
|
|
20531
|
+
}
|
|
20532
|
+
for (const name of entries) {
|
|
20533
|
+
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
20534
|
+
const directory = path27__namespace.join(root, name);
|
|
20535
|
+
const { marker: marker2 } = readOwnershipMarker(directory);
|
|
20536
|
+
if (marker2?.runId !== runId) continue;
|
|
20537
|
+
try {
|
|
20538
|
+
fs24__namespace.rmSync(directory, { recursive: true, force: true });
|
|
20539
|
+
} catch {
|
|
20540
|
+
}
|
|
20541
|
+
}
|
|
20542
|
+
}
|
|
20543
|
+
}
|
|
20165
20544
|
function lockHeartbeatAgeMs(lockPath) {
|
|
20166
20545
|
try {
|
|
20167
20546
|
return Date.now() - fs24__namespace.statSync(lockPath).mtimeMs;
|
|
@@ -20476,6 +20855,7 @@ function generateSnapshot(configInput, options) {
|
|
|
20476
20855
|
assertUsableConfigInput(configInput);
|
|
20477
20856
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
20478
20857
|
const dryRun = options?.dryRun ?? false;
|
|
20858
|
+
const runId = options?.runId ?? crypto__namespace.randomUUID();
|
|
20479
20859
|
const gitInfo = getGitInfo(config.cwd, config.branch);
|
|
20480
20860
|
const changedScope = config.changedSince !== void 0 || config.staged === true ? resolveChangedScope(config.cwd, {
|
|
20481
20861
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
@@ -20495,7 +20875,7 @@ function generateSnapshot(configInput, options) {
|
|
|
20495
20875
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
20496
20876
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
20497
20877
|
(directory) => path27__namespace.relative(config.cwd, path27__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
20498
|
-
).filter((
|
|
20878
|
+
).filter((relative16) => relative16.length > 0 && !relative16.startsWith("..")),
|
|
20499
20879
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
20500
20880
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
20501
20881
|
...stagedPaths.size > 0 ? { extraPaths: [...stagedPaths] } : {}
|
|
@@ -21182,9 +21562,13 @@ function generateSnapshot(configInput, options) {
|
|
|
21182
21562
|
if (navigationText !== null) manifest.artifacts.navigation = artifactRecord(navigationText);
|
|
21183
21563
|
const auditText = artifacts.audit ? generateAuditReport(manifest, secretFindings, config.secretRules) : null;
|
|
21184
21564
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
21185
|
-
const
|
|
21565
|
+
const reportExcludes = [...config.excludePatterns, ...config.presetExclude];
|
|
21566
|
+
const diffReport = artifacts.diff ? generateDiffReport(config.cwd, {
|
|
21567
|
+
secretRules: config.secretRules,
|
|
21568
|
+
excluded: (relativePath) => reportExcludes.some((pattern) => matchesExclude(relativePath, pattern))
|
|
21569
|
+
}) : null;
|
|
21186
21570
|
if (diffReport !== null) manifest.artifacts.diff = artifactRecord(diffReport.text);
|
|
21187
|
-
const logReport = artifacts.log ? generateLogReport(config.cwd, { count: config.logCount }) : null;
|
|
21571
|
+
const logReport = artifacts.log ? generateLogReport(config.cwd, { count: config.logCount, secretRules: config.secretRules }) : null;
|
|
21188
21572
|
if (artifacts.diff && diffReport === null && !isGitRepository(config.cwd)) {
|
|
21189
21573
|
manifest.warnings.push(
|
|
21190
21574
|
"--include-diffs was requested, but the generated directory is not a git repository; reports/diff.md was not written."
|
|
@@ -21228,7 +21612,8 @@ function generateSnapshot(configInput, options) {
|
|
|
21228
21612
|
const entry = {
|
|
21229
21613
|
...file,
|
|
21230
21614
|
content,
|
|
21231
|
-
inclusionMode: "full",
|
|
21615
|
+
inclusionMode: file.inclusionMode === "comments-stripped" ? "comments-stripped" : "full",
|
|
21616
|
+
...file.emptyLinesRemoved === true ? { emptyLinesRemoved: true } : {},
|
|
21232
21617
|
isPreviewTruncated: false,
|
|
21233
21618
|
includedBytes: Buffer.byteLength(content, "utf8"),
|
|
21234
21619
|
includedLines: countLines(content)
|
|
@@ -21296,7 +21681,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21296
21681
|
const lockKeys = Array.from(/* @__PURE__ */ new Set([tmpDir, outDir])).sort();
|
|
21297
21682
|
const releases = [];
|
|
21298
21683
|
try {
|
|
21299
|
-
for (const key of lockKeys) releases.push(acquireRunLock(key));
|
|
21684
|
+
for (const key of lockKeys) releases.push(acquireRunLock(key, runId));
|
|
21300
21685
|
} catch (error) {
|
|
21301
21686
|
for (const release of [...releases].reverse()) release();
|
|
21302
21687
|
throw error;
|
|
@@ -21323,6 +21708,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21323
21708
|
createdAt,
|
|
21324
21709
|
state: "staging",
|
|
21325
21710
|
id: snapshotId,
|
|
21711
|
+
runId,
|
|
21326
21712
|
pid: process.pid
|
|
21327
21713
|
});
|
|
21328
21714
|
const partsDir = path27__namespace.join(stagingDir, "parts");
|
|
@@ -21391,6 +21777,17 @@ function generateSnapshot(configInput, options) {
|
|
|
21391
21777
|
if (artifacts.manifest) {
|
|
21392
21778
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
21393
21779
|
}
|
|
21780
|
+
if (options?.sign !== void 0) {
|
|
21781
|
+
if (!artifacts.manifest) {
|
|
21782
|
+
throw new Error(
|
|
21783
|
+
"Refusing to sign: manifest.json is disabled for this run. Signing covers the manifest, so enable the manifest artifact or drop --sign."
|
|
21784
|
+
);
|
|
21785
|
+
}
|
|
21786
|
+
const record = signManifest(path27__namespace.join(stagingDir, "manifest.json"), {
|
|
21787
|
+
key: options.sign.key ?? null
|
|
21788
|
+
});
|
|
21789
|
+
writeArtifact(stagingDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
|
|
21790
|
+
}
|
|
21394
21791
|
if (monolithJson !== null) {
|
|
21395
21792
|
writeArtifact(stagingDir, "full-codebase.json", monolithJson);
|
|
21396
21793
|
}
|
|
@@ -21402,7 +21799,7 @@ function generateSnapshot(configInput, options) {
|
|
|
21402
21799
|
}
|
|
21403
21800
|
writeOwnershipMarker(
|
|
21404
21801
|
stagingDir,
|
|
21405
|
-
markerPayload(stagingDir, "complete", snapshotId, createdAt, writtenArtifacts)
|
|
21802
|
+
markerPayload(stagingDir, "complete", snapshotId, createdAt, writtenArtifacts, runId)
|
|
21406
21803
|
);
|
|
21407
21804
|
swapIntoPlace(stagingDir, outDir, () => assertReplaceable(outDir, "outDir", config.secretRules));
|
|
21408
21805
|
stagingDir = null;
|
|
@@ -21413,10 +21810,16 @@ function generateSnapshot(configInput, options) {
|
|
|
21413
21810
|
if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
|
|
21414
21811
|
writeManifestAtomically(path27__namespace.join(outDir, "manifest.json"), manifest);
|
|
21415
21812
|
recordArtifact(outDir, "manifest.json");
|
|
21813
|
+
if (options?.sign !== void 0) {
|
|
21814
|
+
const record = signManifest(path27__namespace.join(outDir, "manifest.json"), {
|
|
21815
|
+
key: options.sign.key ?? null
|
|
21816
|
+
});
|
|
21817
|
+
writeArtifact(outDir, SIGNATURE_FILE, JSON.stringify(record, null, 2) + "\n");
|
|
21818
|
+
}
|
|
21416
21819
|
}
|
|
21417
21820
|
writeOwnershipMarker(
|
|
21418
21821
|
outDir,
|
|
21419
|
-
markerPayload(outDir, "complete", snapshotId, createdAt, writtenArtifacts)
|
|
21822
|
+
markerPayload(outDir, "complete", snapshotId, createdAt, writtenArtifacts, runId)
|
|
21420
21823
|
);
|
|
21421
21824
|
};
|
|
21422
21825
|
if (config.hooks.afterGenerate) shipHookState();
|
|
@@ -21588,8 +21991,43 @@ async function startHttpTransport(options) {
|
|
|
21588
21991
|
"Refusing to serve " + host + " without a token: a repository reachable from the network must require Authorization. Drop --no-auth, or bind the loopback address."
|
|
21589
21992
|
);
|
|
21590
21993
|
}
|
|
21591
|
-
const
|
|
21994
|
+
const createMcp = () => createServer({ cwd: options.cwd, log });
|
|
21592
21995
|
const toolCount = buildTools().length;
|
|
21996
|
+
const mcpSessions = /* @__PURE__ */ new Map();
|
|
21997
|
+
const socketServers = /* @__PURE__ */ new WeakMap();
|
|
21998
|
+
const anonymousServers = /* @__PURE__ */ new Map();
|
|
21999
|
+
const serverFor = (request) => {
|
|
22000
|
+
const header = request.headers["mcp-session-id"];
|
|
22001
|
+
const supplied = typeof header === "string" ? header.trim() : "";
|
|
22002
|
+
if (supplied !== "") {
|
|
22003
|
+
let existing = mcpSessions.get(supplied);
|
|
22004
|
+
if (existing === void 0) {
|
|
22005
|
+
existing = createMcp();
|
|
22006
|
+
if (mcpSessions.size >= 64) {
|
|
22007
|
+
const oldest = mcpSessions.keys().next().value;
|
|
22008
|
+
if (oldest !== void 0) mcpSessions.delete(oldest);
|
|
22009
|
+
}
|
|
22010
|
+
mcpSessions.set(supplied, existing);
|
|
22011
|
+
}
|
|
22012
|
+
return existing;
|
|
22013
|
+
}
|
|
22014
|
+
const onSocket = socketServers.get(request.socket);
|
|
22015
|
+
if (onSocket !== void 0) return onSocket;
|
|
22016
|
+
const userAgent = typeof request.headers["user-agent"] === "string" ? request.headers["user-agent"] : "";
|
|
22017
|
+
const fallbackKey = (request.socket.remoteAddress ?? "unknown") + "\0" + userAgent;
|
|
22018
|
+
let fallback = anonymousServers.get(fallbackKey);
|
|
22019
|
+
if (fallback === void 0) {
|
|
22020
|
+
fallback = createMcp();
|
|
22021
|
+
if (anonymousServers.size >= 64) {
|
|
22022
|
+
const oldest = anonymousServers.keys().next().value;
|
|
22023
|
+
if (oldest !== void 0) anonymousServers.delete(oldest);
|
|
22024
|
+
}
|
|
22025
|
+
anonymousServers.set(fallbackKey, fallback);
|
|
22026
|
+
}
|
|
22027
|
+
socketServers.set(request.socket, fallback);
|
|
22028
|
+
return fallback;
|
|
22029
|
+
};
|
|
22030
|
+
const newSessionId = () => crypto__namespace.randomBytes(12).toString("hex");
|
|
21593
22031
|
const sseSessions = /* @__PURE__ */ new Map();
|
|
21594
22032
|
const tokenAccepted = (request, url) => {
|
|
21595
22033
|
if (token === null) return true;
|
|
@@ -21610,6 +22048,18 @@ async function startHttpTransport(options) {
|
|
|
21610
22048
|
const method = request.method ?? "UNKNOWN";
|
|
21611
22049
|
metrics.byMethod.set(method, (metrics.byMethod.get(method) ?? 0) + 1);
|
|
21612
22050
|
};
|
|
22051
|
+
const rateLimited = (request) => {
|
|
22052
|
+
const remote = request.socket.remoteAddress ?? "unknown";
|
|
22053
|
+
const now = Date.now();
|
|
22054
|
+
const window = sessions.get(remote);
|
|
22055
|
+
if (window === void 0 || window.resetAt <= now) {
|
|
22056
|
+
sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
22057
|
+
return false;
|
|
22058
|
+
}
|
|
22059
|
+
if (window.count >= RATE_LIMIT) return true;
|
|
22060
|
+
window.count += 1;
|
|
22061
|
+
return false;
|
|
22062
|
+
};
|
|
21613
22063
|
const allowedOrigin = (origin) => {
|
|
21614
22064
|
if (origin === void 0) return null;
|
|
21615
22065
|
if (isLoopbackOrigin(origin)) return origin;
|
|
@@ -21617,7 +22067,10 @@ async function startHttpTransport(options) {
|
|
|
21617
22067
|
};
|
|
21618
22068
|
const httpServer = http__namespace.createServer((request, response) => {
|
|
21619
22069
|
noteRequest(request);
|
|
22070
|
+
let responseSent = false;
|
|
21620
22071
|
const send = (status, body, extra = {}) => {
|
|
22072
|
+
if (responseSent) return;
|
|
22073
|
+
responseSent = true;
|
|
21621
22074
|
const text2 = typeof body === "string" ? body : JSON.stringify(body);
|
|
21622
22075
|
if (status >= 400 && status < 500 && status !== 429) metrics.refused += 1;
|
|
21623
22076
|
response.writeHead(status, {
|
|
@@ -21693,6 +22146,11 @@ async function startHttpTransport(options) {
|
|
|
21693
22146
|
send(401, { error: "unauthorized" }, { ...cors, "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
21694
22147
|
return;
|
|
21695
22148
|
}
|
|
22149
|
+
if (rateLimited(request)) {
|
|
22150
|
+
metrics.rateLimited += 1;
|
|
22151
|
+
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
22152
|
+
return;
|
|
22153
|
+
}
|
|
21696
22154
|
const id = crypto__namespace.randomBytes(12).toString("hex");
|
|
21697
22155
|
response.writeHead(200, {
|
|
21698
22156
|
...cors,
|
|
@@ -21704,7 +22162,7 @@ async function startHttpTransport(options) {
|
|
|
21704
22162
|
const write = (payload) => {
|
|
21705
22163
|
response.write(payload);
|
|
21706
22164
|
};
|
|
21707
|
-
sseSessions.set(id, { write, end: () => response.end() });
|
|
22165
|
+
sseSessions.set(id, { write, end: () => response.end(), server: createMcp() });
|
|
21708
22166
|
const heartbeat = setInterval(() => write(": ping\n\n"), 15e3);
|
|
21709
22167
|
const cleanup = () => {
|
|
21710
22168
|
clearInterval(heartbeat);
|
|
@@ -21720,6 +22178,11 @@ async function startHttpTransport(options) {
|
|
|
21720
22178
|
send(401, { error: "unauthorized" }, { ...cors, "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
21721
22179
|
return;
|
|
21722
22180
|
}
|
|
22181
|
+
if (rateLimited(request)) {
|
|
22182
|
+
metrics.rateLimited += 1;
|
|
22183
|
+
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
22184
|
+
return;
|
|
22185
|
+
}
|
|
21723
22186
|
const id = url.searchParams.get("sessionId") ?? "";
|
|
21724
22187
|
const stream = sseSessions.get(id);
|
|
21725
22188
|
if (stream === void 0) {
|
|
@@ -21728,9 +22191,12 @@ async function startHttpTransport(options) {
|
|
|
21728
22191
|
}
|
|
21729
22192
|
const chunks2 = [];
|
|
21730
22193
|
let received2 = 0;
|
|
22194
|
+
let tooLarge2 = false;
|
|
21731
22195
|
request.on("data", (chunk) => {
|
|
22196
|
+
if (tooLarge2) return;
|
|
21732
22197
|
received2 += chunk.length;
|
|
21733
22198
|
if (received2 > maxBody) {
|
|
22199
|
+
tooLarge2 = true;
|
|
21734
22200
|
request.destroy();
|
|
21735
22201
|
send(413, { error: "request body too large", limit: maxBody });
|
|
21736
22202
|
return;
|
|
@@ -21738,6 +22204,7 @@ async function startHttpTransport(options) {
|
|
|
21738
22204
|
chunks2.push(chunk);
|
|
21739
22205
|
});
|
|
21740
22206
|
request.on("end", () => {
|
|
22207
|
+
if (tooLarge2) return;
|
|
21741
22208
|
void (async () => {
|
|
21742
22209
|
let message;
|
|
21743
22210
|
try {
|
|
@@ -21746,7 +22213,7 @@ async function startHttpTransport(options) {
|
|
|
21746
22213
|
send(400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: String(error) } });
|
|
21747
22214
|
return;
|
|
21748
22215
|
}
|
|
21749
|
-
const answer = await server.handle(message);
|
|
22216
|
+
const answer = await stream.server.handle(message);
|
|
21750
22217
|
if (answer !== null) stream.write("event: message\ndata: " + JSON.stringify(answer) + "\n\n");
|
|
21751
22218
|
send(202, "", cors);
|
|
21752
22219
|
})();
|
|
@@ -21773,20 +22240,22 @@ async function startHttpTransport(options) {
|
|
|
21773
22240
|
return;
|
|
21774
22241
|
}
|
|
21775
22242
|
}
|
|
21776
|
-
|
|
21777
|
-
const now = Date.now();
|
|
21778
|
-
const window = sessions.get(remote);
|
|
21779
|
-
if (window === void 0 || window.resetAt <= now) sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
21780
|
-
else if (window.count >= RATE_LIMIT) {
|
|
22243
|
+
if (rateLimited(request)) {
|
|
21781
22244
|
metrics.rateLimited += 1;
|
|
21782
22245
|
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
21783
22246
|
return;
|
|
21784
|
-
}
|
|
22247
|
+
}
|
|
22248
|
+
const activeServer = serverFor(request);
|
|
22249
|
+
const sessionHeader = request.headers["mcp-session-id"];
|
|
22250
|
+
let sessionId = typeof sessionHeader === "string" ? sessionHeader.trim() : "";
|
|
21785
22251
|
let received = 0;
|
|
22252
|
+
let tooLarge = false;
|
|
21786
22253
|
const chunks = [];
|
|
21787
22254
|
request.on("data", (chunk) => {
|
|
22255
|
+
if (tooLarge) return;
|
|
21788
22256
|
received += chunk.length;
|
|
21789
22257
|
if (received > maxBody) {
|
|
22258
|
+
tooLarge = true;
|
|
21790
22259
|
request.destroy();
|
|
21791
22260
|
send(413, { error: "request body too large", limit: maxBody }, cors);
|
|
21792
22261
|
return;
|
|
@@ -21794,6 +22263,7 @@ async function startHttpTransport(options) {
|
|
|
21794
22263
|
chunks.push(chunk);
|
|
21795
22264
|
});
|
|
21796
22265
|
request.on("end", () => {
|
|
22266
|
+
if (tooLarge) return;
|
|
21797
22267
|
void (async () => {
|
|
21798
22268
|
let message;
|
|
21799
22269
|
try {
|
|
@@ -21802,17 +22272,26 @@ async function startHttpTransport(options) {
|
|
|
21802
22272
|
send(400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error: " + error.message } }, cors);
|
|
21803
22273
|
return;
|
|
21804
22274
|
}
|
|
21805
|
-
const answers = [];
|
|
21806
22275
|
const batch = Array.isArray(message) ? message : [message];
|
|
22276
|
+
if (batch.length > 100) {
|
|
22277
|
+
send(400, { error: "JSON-RPC batch is limited to 100 messages" }, cors);
|
|
22278
|
+
return;
|
|
22279
|
+
}
|
|
22280
|
+
if (sessionId === "" && !Array.isArray(message) && message.method === "initialize") {
|
|
22281
|
+
sessionId = newSessionId();
|
|
22282
|
+
mcpSessions.set(sessionId, activeServer);
|
|
22283
|
+
}
|
|
22284
|
+
const sessionHeaders = sessionId === "" ? cors : { ...cors, "mcp-session-id": sessionId };
|
|
22285
|
+
const answers = [];
|
|
21807
22286
|
for (const item of batch) {
|
|
21808
|
-
const answer = await
|
|
22287
|
+
const answer = await activeServer.handle(item);
|
|
21809
22288
|
if (answer !== null) answers.push(answer);
|
|
21810
22289
|
}
|
|
21811
22290
|
if (answers.length === 0) {
|
|
21812
|
-
send(202, "",
|
|
22291
|
+
send(202, "", sessionHeaders);
|
|
21813
22292
|
return;
|
|
21814
22293
|
}
|
|
21815
|
-
send(200, Array.isArray(message) ? answers : answers[0],
|
|
22294
|
+
send(200, Array.isArray(message) ? answers : answers[0], sessionHeaders);
|
|
21816
22295
|
})().catch((error) => {
|
|
21817
22296
|
log("mcp/http: " + error.message);
|
|
21818
22297
|
send(500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
|
|
@@ -22454,8 +22933,8 @@ function splitList(value) {
|
|
|
22454
22933
|
}
|
|
22455
22934
|
function displayOutPath(cwd, outDir, ...segments) {
|
|
22456
22935
|
const absolute = path27__namespace.resolve(cwd, outDir, ...segments);
|
|
22457
|
-
const
|
|
22458
|
-
if (
|
|
22936
|
+
const relative16 = path27__namespace.relative(cwd, absolute);
|
|
22937
|
+
if (relative16 && !relative16.startsWith("..") && !path27__namespace.isAbsolute(relative16)) return relative16;
|
|
22459
22938
|
return absolute;
|
|
22460
22939
|
}
|
|
22461
22940
|
function nextStepHint(cwd, scriptsAddedNow) {
|
|
@@ -22971,6 +23450,42 @@ ${formatUpdateNotice(notice, installKind())}
|
|
|
22971
23450
|
}
|
|
22972
23451
|
return code;
|
|
22973
23452
|
}
|
|
23453
|
+
function generateCliOptions(invocation) {
|
|
23454
|
+
return {
|
|
23455
|
+
mode: invocation.command,
|
|
23456
|
+
format: invocation.format,
|
|
23457
|
+
dryRun: invocation.dryRun,
|
|
23458
|
+
cwd: invocation.cwd,
|
|
23459
|
+
outDir: invocation.outDir,
|
|
23460
|
+
includeMonolith: invocation.includeMonolith,
|
|
23461
|
+
includeSensitiveFiles: invocation.includeSensitiveFiles,
|
|
23462
|
+
maxPartBytes: invocation.maxPartBytes,
|
|
23463
|
+
maxPartTokens: invocation.maxPartTokens,
|
|
23464
|
+
largeFileBytes: invocation.largeFileBytes,
|
|
23465
|
+
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
23466
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
23467
|
+
maxParts: invocation.maxParts,
|
|
23468
|
+
...invocation.includeDiffs === true ? { includeDiffs: true } : {},
|
|
23469
|
+
...invocation.includeLogs === void 0 ? {} : { includeLogs: invocation.includeLogs },
|
|
23470
|
+
...invocation.tokenTree === true ? { tokenTree: true } : {},
|
|
23471
|
+
...invocation.stripComments === true ? { stripComments: true } : {},
|
|
23472
|
+
...invocation.removeEmptyLines === true ? { removeEmptyLines: true } : {},
|
|
23473
|
+
...invocation.only === void 0 ? {} : { only: invocation.only },
|
|
23474
|
+
...invocation.ignore === void 0 ? {} : { ignore: invocation.ignore },
|
|
23475
|
+
...invocation.pack === void 0 ? {} : { pack: invocation.pack },
|
|
23476
|
+
...invocation.sign === true ? { sign: true } : {},
|
|
23477
|
+
brief: invocation.brief,
|
|
23478
|
+
promptTask: invocation.promptTask,
|
|
23479
|
+
skipArtifacts: invocation.skipArtifacts,
|
|
23480
|
+
onlyArtifacts: invocation.onlyArtifacts,
|
|
23481
|
+
discovery: invocation.discovery,
|
|
23482
|
+
changedSince: invocation.changedSince,
|
|
23483
|
+
staged: invocation.staged,
|
|
23484
|
+
withDependents: invocation.withDependents,
|
|
23485
|
+
skeleton: invocation.skeleton,
|
|
23486
|
+
sarif: invocation.sarif
|
|
23487
|
+
};
|
|
23488
|
+
}
|
|
22974
23489
|
async function runCommand(argv) {
|
|
22975
23490
|
let invocation;
|
|
22976
23491
|
try {
|
|
@@ -23124,42 +23639,7 @@ ${USAGE}
|
|
|
23124
23639
|
try {
|
|
23125
23640
|
resolved = resolveConfig(
|
|
23126
23641
|
loaded.config,
|
|
23127
|
-
|
|
23128
|
-
mode: invocation.command,
|
|
23129
|
-
format: invocation.format,
|
|
23130
|
-
dryRun: invocation.dryRun,
|
|
23131
|
-
cwd: invocation.cwd,
|
|
23132
|
-
outDir: invocation.outDir,
|
|
23133
|
-
includeMonolith: invocation.includeMonolith,
|
|
23134
|
-
includeSensitiveFiles: invocation.includeSensitiveFiles,
|
|
23135
|
-
maxPartBytes: invocation.maxPartBytes,
|
|
23136
|
-
maxPartTokens: invocation.maxPartTokens,
|
|
23137
|
-
largeFileBytes: invocation.largeFileBytes,
|
|
23138
|
-
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
23139
|
-
attachmentSlots: invocation.attachmentSlots,
|
|
23140
|
-
maxParts: invocation.maxParts,
|
|
23141
|
-
...invocation.includeDiffs === true ? { includeDiffs: true } : {},
|
|
23142
|
-
...invocation.includeLogs === void 0 ? {} : { includeLogs: invocation.includeLogs },
|
|
23143
|
-
...invocation.tokenTree === true ? { tokenTree: true } : {},
|
|
23144
|
-
...invocation.stripComments === true ? { stripComments: true } : {},
|
|
23145
|
-
...invocation.removeEmptyLines === true ? { removeEmptyLines: true } : {},
|
|
23146
|
-
...invocation.only === void 0 ? {} : { only: invocation.only },
|
|
23147
|
-
...invocation.ignore === void 0 ? {} : { ignore: invocation.ignore },
|
|
23148
|
-
...invocation.pack === void 0 ? {} : { pack: invocation.pack },
|
|
23149
|
-
brief: invocation.brief,
|
|
23150
|
-
promptTask: invocation.promptTask,
|
|
23151
|
-
skipArtifacts: invocation.skipArtifacts,
|
|
23152
|
-
// `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
|
|
23153
|
-
// suppression cannot switch an artifact *on*, so a config that had turned one of the
|
|
23154
|
-
// requested artifacts off left the run with nothing to write.
|
|
23155
|
-
onlyArtifacts: invocation.onlyArtifacts,
|
|
23156
|
-
discovery: invocation.discovery,
|
|
23157
|
-
changedSince: invocation.changedSince,
|
|
23158
|
-
staged: invocation.staged,
|
|
23159
|
-
withDependents: invocation.withDependents,
|
|
23160
|
-
skeleton: invocation.skeleton,
|
|
23161
|
-
sarif: invocation.sarif
|
|
23162
|
-
},
|
|
23642
|
+
generateCliOptions(invocation),
|
|
23163
23643
|
invocation.cwd
|
|
23164
23644
|
);
|
|
23165
23645
|
} catch (err) {
|
|
@@ -23195,7 +23675,11 @@ ${USAGE}
|
|
|
23195
23675
|
rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
|
|
23196
23676
|
continue;
|
|
23197
23677
|
}
|
|
23198
|
-
const report3 = auditSnapshot({
|
|
23678
|
+
const report3 = auditSnapshot({
|
|
23679
|
+
snapshotDir: snapshotDir2,
|
|
23680
|
+
repoDir,
|
|
23681
|
+
...invocation.deep === true ? { deep: true } : {}
|
|
23682
|
+
});
|
|
23199
23683
|
rows.push({
|
|
23200
23684
|
name,
|
|
23201
23685
|
score: report3.score,
|
|
@@ -23337,6 +23821,12 @@ ${USAGE}
|
|
|
23337
23821
|
if (invocation.watch) {
|
|
23338
23822
|
const problem = watchSupportProblem();
|
|
23339
23823
|
if (problem !== null) return fail(invocation.format, problem);
|
|
23824
|
+
if (invocation.delta !== void 0) {
|
|
23825
|
+
return fail(
|
|
23826
|
+
invocation.format,
|
|
23827
|
+
"--watch cannot track a fixed --delta base; run a one-shot generate --delta, or watch without it."
|
|
23828
|
+
);
|
|
23829
|
+
}
|
|
23340
23830
|
}
|
|
23341
23831
|
if (invocation.workspace !== void 0) {
|
|
23342
23832
|
const members = invocation.workspace.split(",").map((member) => member.trim()).filter((member) => member.length > 0);
|
|
@@ -23462,16 +23952,18 @@ ${USAGE}
|
|
|
23462
23952
|
question: invocation.slice,
|
|
23463
23953
|
...invocation.sliceTokens === void 0 ? {} : { maxTokens: invocation.sliceTokens }
|
|
23464
23954
|
}
|
|
23465
|
-
}
|
|
23955
|
+
},
|
|
23956
|
+
...invocation.sign === true && !invocation.dryRun ? { sign: { key: loadSigningKey() } } : {}
|
|
23466
23957
|
});
|
|
23467
23958
|
if (invocation.sign === true && !invocation.dryRun) {
|
|
23468
|
-
const
|
|
23959
|
+
const signaturePath = path27__namespace.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
|
|
23469
23960
|
try {
|
|
23470
|
-
const record =
|
|
23471
|
-
|
|
23472
|
-
|
|
23961
|
+
const record = JSON.parse(fs24__namespace.readFileSync(signaturePath, "utf8"));
|
|
23962
|
+
info(
|
|
23963
|
+
" Signature: ed25519, " + (record.keyOrigin ?? "unknown") + " key, " + (record.fingerprint ?? manifest.fingerprint).slice(0, 12)
|
|
23964
|
+
);
|
|
23473
23965
|
} catch (error) {
|
|
23474
|
-
return fail(invocation.format, "
|
|
23966
|
+
return fail(invocation.format, "The snapshot was written but its signature could not be read: " + error.message);
|
|
23475
23967
|
}
|
|
23476
23968
|
}
|
|
23477
23969
|
const elapsed = ((performance.now() - started) / 1e3).toFixed(2);
|
|
@@ -23623,8 +24115,8 @@ function comparablePath(value) {
|
|
|
23623
24115
|
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
23624
24116
|
}
|
|
23625
24117
|
function isSameOrInside(parent, candidate) {
|
|
23626
|
-
const
|
|
23627
|
-
return
|
|
24118
|
+
const relative16 = path27__namespace.relative(parent, candidate);
|
|
24119
|
+
return relative16 === "" || relative16 !== ".." && !relative16.startsWith(`..${path27__namespace.sep}`) && !path27__namespace.isAbsolute(relative16);
|
|
23628
24120
|
}
|
|
23629
24121
|
function isGeneratedWatchPath(candidate, paths) {
|
|
23630
24122
|
const absolute = comparablePath(path27__namespace.resolve(paths.cwd, candidate));
|
|
@@ -23699,34 +24191,20 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
23699
24191
|
for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
|
|
23700
24192
|
const next = resolveConfig(
|
|
23701
24193
|
loaded.config,
|
|
23702
|
-
|
|
23703
|
-
mode: invocation.command,
|
|
23704
|
-
format: invocation.format,
|
|
23705
|
-
dryRun: invocation.dryRun,
|
|
23706
|
-
cwd: invocation.cwd,
|
|
23707
|
-
outDir: invocation.outDir,
|
|
23708
|
-
includeMonolith: invocation.includeMonolith,
|
|
23709
|
-
includeSensitiveFiles: invocation.includeSensitiveFiles,
|
|
23710
|
-
maxPartBytes: invocation.maxPartBytes,
|
|
23711
|
-
maxPartTokens: invocation.maxPartTokens,
|
|
23712
|
-
largeFileBytes: invocation.largeFileBytes,
|
|
23713
|
-
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
23714
|
-
attachmentSlots: invocation.attachmentSlots,
|
|
23715
|
-
maxParts: invocation.maxParts,
|
|
23716
|
-
brief: invocation.brief,
|
|
23717
|
-
promptTask: invocation.promptTask,
|
|
23718
|
-
skipArtifacts: invocation.skipArtifacts,
|
|
23719
|
-
onlyArtifacts: invocation.onlyArtifacts,
|
|
23720
|
-
discovery: invocation.discovery,
|
|
23721
|
-
changedSince: invocation.changedSince,
|
|
23722
|
-
staged: invocation.staged,
|
|
23723
|
-
withDependents: invocation.withDependents,
|
|
23724
|
-
skeleton: invocation.skeleton,
|
|
23725
|
-
sarif: invocation.sarif
|
|
23726
|
-
},
|
|
24194
|
+
generateCliOptions(invocation),
|
|
23727
24195
|
invocation.cwd
|
|
23728
24196
|
);
|
|
23729
|
-
const manifest = generateSnapshot(next, {
|
|
24197
|
+
const manifest = generateSnapshot(next, {
|
|
24198
|
+
dryRun: invocation.dryRun,
|
|
24199
|
+
...invocation.budgetTokens === void 0 ? {} : { budgetTokens: invocation.budgetTokens },
|
|
24200
|
+
...invocation.slice === void 0 ? {} : {
|
|
24201
|
+
slice: {
|
|
24202
|
+
question: invocation.slice,
|
|
24203
|
+
...invocation.sliceTokens === void 0 ? {} : { maxTokens: invocation.sliceTokens }
|
|
24204
|
+
}
|
|
24205
|
+
},
|
|
24206
|
+
...invocation.sign === true && !invocation.dryRun ? { sign: { key: loadSigningKey() } } : {}
|
|
24207
|
+
});
|
|
23730
24208
|
paths = watchPathsFor(next);
|
|
23731
24209
|
const elapsed = ((performance.now() - started) / 1e3).toFixed(2);
|
|
23732
24210
|
info(
|
|
@@ -23810,6 +24288,7 @@ exports.buildAgentContract = buildAgentContract;
|
|
|
23810
24288
|
exports.cleanInstallEnv = cleanInstallEnv;
|
|
23811
24289
|
exports.decideWatchEvent = decideWatchEvent;
|
|
23812
24290
|
exports.finishWatchRun = finishWatchRun;
|
|
24291
|
+
exports.generateCliOptions = generateCliOptions;
|
|
23813
24292
|
exports.initialWatchState = initialWatchState;
|
|
23814
24293
|
exports.isGeneratedWatchPath = isGeneratedWatchPath;
|
|
23815
24294
|
exports.main = main;
|