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/mcp.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var fs8 = require('fs');
|
|
4
|
+
var path6 = require('path');
|
|
5
|
+
var crypto5 = require('crypto');
|
|
6
6
|
var module$1 = require('module');
|
|
7
7
|
var url = require('url');
|
|
8
8
|
var childProcess = require('child_process');
|
|
9
9
|
var worker_threads = require('worker_threads');
|
|
10
|
-
require('os');
|
|
10
|
+
var os = require('os');
|
|
11
11
|
var ts = require('typescript');
|
|
12
12
|
var http = require('http');
|
|
13
13
|
|
|
@@ -32,10 +32,11 @@ function _interopNamespace(e) {
|
|
|
32
32
|
return Object.freeze(n);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
35
|
+
var fs8__namespace = /*#__PURE__*/_interopNamespace(fs8);
|
|
36
|
+
var path6__namespace = /*#__PURE__*/_interopNamespace(path6);
|
|
37
|
+
var crypto5__namespace = /*#__PURE__*/_interopNamespace(crypto5);
|
|
38
38
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
39
|
+
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
39
40
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
40
41
|
var http__namespace = /*#__PURE__*/_interopNamespace(http);
|
|
41
42
|
|
|
@@ -363,7 +364,7 @@ function parseOwnerBrief(filePath, text) {
|
|
|
363
364
|
return {
|
|
364
365
|
brief: {
|
|
365
366
|
path: filePath,
|
|
366
|
-
digest:
|
|
367
|
+
digest: crypto5.createHash("sha256").update(text, "utf8").digest("hex"),
|
|
367
368
|
...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
|
|
368
369
|
...recognised["The system"] ? { system: recognised["The system"] } : {},
|
|
369
370
|
...recognised["What came before"] ? { history: recognised["What came before"] } : {},
|
|
@@ -421,15 +422,15 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
421
422
|
]);
|
|
422
423
|
function readSmallFile(fullPath) {
|
|
423
424
|
try {
|
|
424
|
-
const stats =
|
|
425
|
+
const stats = fs8__namespace.statSync(fullPath);
|
|
425
426
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
426
|
-
return
|
|
427
|
+
return fs8__namespace.readFileSync(fullPath, "utf8");
|
|
427
428
|
} catch {
|
|
428
429
|
return null;
|
|
429
430
|
}
|
|
430
431
|
}
|
|
431
432
|
function readManifest(cwd, name) {
|
|
432
|
-
return readSmallFile(
|
|
433
|
+
return readSmallFile(path6__namespace.join(cwd, name));
|
|
433
434
|
}
|
|
434
435
|
function dependenciesFromPackageJson(raw) {
|
|
435
436
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -489,7 +490,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
489
490
|
function childDirectories(cwd, parent) {
|
|
490
491
|
let entries;
|
|
491
492
|
try {
|
|
492
|
-
entries =
|
|
493
|
+
entries = fs8__namespace.readdirSync(path6__namespace.join(cwd, parent), { withFileTypes: true });
|
|
493
494
|
} catch {
|
|
494
495
|
return [];
|
|
495
496
|
}
|
|
@@ -525,12 +526,12 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
525
526
|
const files = /* @__PURE__ */ new Set();
|
|
526
527
|
const dependencies = /* @__PURE__ */ new Set();
|
|
527
528
|
for (const relative9 of workspacePackageDirs(cwd, patterns)) {
|
|
528
|
-
const full =
|
|
529
|
+
const full = path6__namespace.join(cwd, relative9);
|
|
529
530
|
try {
|
|
530
|
-
for (const entry of
|
|
531
|
+
for (const entry of fs8__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
531
532
|
} catch {
|
|
532
533
|
}
|
|
533
|
-
const raw = readSmallFile(
|
|
534
|
+
const raw = readSmallFile(path6__namespace.join(full, "package.json"));
|
|
534
535
|
if (raw !== null) {
|
|
535
536
|
for (const name of dependenciesFromPackageJson(raw)) dependencies.add(name);
|
|
536
537
|
}
|
|
@@ -540,7 +541,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
540
541
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
541
542
|
function isToolOwnedDirectory(dir) {
|
|
542
543
|
try {
|
|
543
|
-
return
|
|
544
|
+
return fs8__namespace.statSync(dir).isDirectory() && fs8__namespace.existsSync(path6__namespace.join(dir, SNAPSHOT_MARKER));
|
|
544
545
|
} catch {
|
|
545
546
|
return false;
|
|
546
547
|
}
|
|
@@ -555,7 +556,7 @@ function countMarkdownFiles(cwd) {
|
|
|
555
556
|
directoriesSeen += 1;
|
|
556
557
|
let entries;
|
|
557
558
|
try {
|
|
558
|
-
entries =
|
|
559
|
+
entries = fs8__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
559
560
|
} catch {
|
|
560
561
|
continue;
|
|
561
562
|
}
|
|
@@ -566,7 +567,7 @@ function countMarkdownFiles(cwd) {
|
|
|
566
567
|
}
|
|
567
568
|
if (!entry.isDirectory() || current.depth >= 2) continue;
|
|
568
569
|
if (entry.name.startsWith(".") || SKIPPED_WALK_DIRS.has(entry.name)) continue;
|
|
569
|
-
const child =
|
|
570
|
+
const child = path6__namespace.join(current.dir, entry.name);
|
|
570
571
|
if (isToolOwnedDirectory(child)) continue;
|
|
571
572
|
queue.push({ dir: child, depth: current.depth + 1 });
|
|
572
573
|
}
|
|
@@ -577,7 +578,7 @@ function buildPresetContext(cwd) {
|
|
|
577
578
|
const files = /* @__PURE__ */ new Set();
|
|
578
579
|
const dirs = /* @__PURE__ */ new Set();
|
|
579
580
|
try {
|
|
580
|
-
for (const entry of
|
|
581
|
+
for (const entry of fs8__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
581
582
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
582
583
|
else if (entry.isFile()) files.add(entry.name);
|
|
583
584
|
}
|
|
@@ -594,7 +595,7 @@ function buildPresetContext(cwd) {
|
|
|
594
595
|
const isWorkspace = files.has("pnpm-workspace.yaml") || files.has("nx.json") || files.has("turbo.json") || files.has("lerna.json") || packageJson !== void 0 && packageJson.includes('"workspaces"') || declaredWorkspaces.length > 0;
|
|
595
596
|
let workspace = { files: /* @__PURE__ */ new Set(), dependencies: /* @__PURE__ */ new Set() };
|
|
596
597
|
if (isWorkspace) {
|
|
597
|
-
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(
|
|
598
|
+
const pnpmRaw = files.has("pnpm-workspace.yaml") ? readSmallFile(path6__namespace.join(cwd, "pnpm-workspace.yaml")) : null;
|
|
598
599
|
const declared = pnpmRaw === null ? [] : pnpmWorkspacePatterns(pnpmRaw);
|
|
599
600
|
const patterns = declared.length > 0 ? declared : declaredWorkspaces.length > 0 ? declaredWorkspaces : DEFAULT_WORKSPACE_PATTERNS;
|
|
600
601
|
workspace = scanWorkspacePackages(cwd, patterns);
|
|
@@ -2553,10 +2554,43 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2553
2554
|
out += line.slice(cursor);
|
|
2554
2555
|
return out;
|
|
2555
2556
|
}
|
|
2557
|
+
var SIGNATURE_FILE = "signature.json";
|
|
2558
|
+
function verifySnapshotSignature(snapshotDir) {
|
|
2559
|
+
const signaturePath = path6__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
2560
|
+
const manifestPath = path6__namespace.join(snapshotDir, "manifest.json");
|
|
2561
|
+
if (!fs8__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
2562
|
+
let record;
|
|
2563
|
+
try {
|
|
2564
|
+
record = JSON.parse(fs8__namespace.readFileSync(signaturePath, "utf8"));
|
|
2565
|
+
} catch (error) {
|
|
2566
|
+
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
2567
|
+
}
|
|
2568
|
+
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
2569
|
+
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
2570
|
+
}
|
|
2571
|
+
let bytes;
|
|
2572
|
+
try {
|
|
2573
|
+
bytes = fs8__namespace.readFileSync(manifestPath);
|
|
2574
|
+
} catch {
|
|
2575
|
+
return { ok: false, reason: "the signed manifest is missing" };
|
|
2576
|
+
}
|
|
2577
|
+
const sha2562 = crypto5__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
2578
|
+
if (sha2562 !== record.manifestSha256) {
|
|
2579
|
+
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
2580
|
+
}
|
|
2581
|
+
let verified = false;
|
|
2582
|
+
try {
|
|
2583
|
+
const key = crypto5__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
2584
|
+
verified = crypto5__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
2585
|
+
} catch (error) {
|
|
2586
|
+
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
2587
|
+
}
|
|
2588
|
+
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
2589
|
+
}
|
|
2556
2590
|
|
|
2557
2591
|
// src/version.ts
|
|
2558
2592
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2559
|
-
var GENERATOR_VERSION = "0.20.
|
|
2593
|
+
var GENERATOR_VERSION = "0.20.4";
|
|
2560
2594
|
var SCHEMA_VERSION = "3.0.0";
|
|
2561
2595
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2562
2596
|
function isOurGeneratorName(name) {
|
|
@@ -2573,14 +2607,14 @@ var PRESET_IGNORES = new Set(
|
|
|
2573
2607
|
);
|
|
2574
2608
|
function readLinkTarget(linkPath, fallback) {
|
|
2575
2609
|
try {
|
|
2576
|
-
return
|
|
2610
|
+
return fs8__namespace.readlinkSync(linkPath);
|
|
2577
2611
|
} catch {
|
|
2578
2612
|
return fallback;
|
|
2579
2613
|
}
|
|
2580
2614
|
}
|
|
2581
2615
|
function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
2582
2616
|
const rawTarget = readLinkTarget(linkPath, linkPath);
|
|
2583
|
-
const resolvedFallback =
|
|
2617
|
+
const resolvedFallback = path6__namespace.resolve(path6__namespace.dirname(linkPath), rawTarget);
|
|
2584
2618
|
return isInside(rootReal, resolvedFallback) ? { path: relativePath, reason: "read-error", detail: "broken symlink" } : {
|
|
2585
2619
|
path: relativePath,
|
|
2586
2620
|
reason: "outside-root",
|
|
@@ -2588,8 +2622,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
2588
2622
|
};
|
|
2589
2623
|
}
|
|
2590
2624
|
function isInside(root, candidate) {
|
|
2591
|
-
const relative9 =
|
|
2592
|
-
return relative9 === "" || !relative9.startsWith(`..${
|
|
2625
|
+
const relative9 = path6__namespace.relative(root, candidate);
|
|
2626
|
+
return relative9 === "" || !relative9.startsWith(`..${path6__namespace.sep}`) && relative9 !== ".." && !path6__namespace.isAbsolute(relative9);
|
|
2593
2627
|
}
|
|
2594
2628
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
2595
2629
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -2849,10 +2883,10 @@ function trimUnescapedTrailingSpaces(line) {
|
|
|
2849
2883
|
return line.slice(0, end);
|
|
2850
2884
|
}
|
|
2851
2885
|
function readGitignoreRules(dir) {
|
|
2852
|
-
const gitignorePath =
|
|
2886
|
+
const gitignorePath = path6__namespace.join(dir, ".gitignore");
|
|
2853
2887
|
let raw;
|
|
2854
2888
|
try {
|
|
2855
|
-
raw =
|
|
2889
|
+
raw = fs8__namespace.readFileSync(gitignorePath, "utf8");
|
|
2856
2890
|
} catch {
|
|
2857
2891
|
return [];
|
|
2858
2892
|
}
|
|
@@ -3025,7 +3059,7 @@ function listIgnoredPaths(cwd) {
|
|
|
3025
3059
|
}
|
|
3026
3060
|
function hasSnapshotMarker(target) {
|
|
3027
3061
|
try {
|
|
3028
|
-
return
|
|
3062
|
+
return fs8__namespace.statSync(target).isDirectory() && isToolOwnedDirectory2(target);
|
|
3029
3063
|
} catch {
|
|
3030
3064
|
return false;
|
|
3031
3065
|
}
|
|
@@ -3034,7 +3068,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
3034
3068
|
function isToolOwnedDirectory2(dir) {
|
|
3035
3069
|
let raw;
|
|
3036
3070
|
try {
|
|
3037
|
-
raw =
|
|
3071
|
+
raw = fs8__namespace.readFileSync(path6__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
3038
3072
|
} catch {
|
|
3039
3073
|
return false;
|
|
3040
3074
|
}
|
|
@@ -3061,12 +3095,14 @@ function isToolOwnedDirectory2(dir) {
|
|
|
3061
3095
|
}
|
|
3062
3096
|
let entries;
|
|
3063
3097
|
try {
|
|
3064
|
-
entries =
|
|
3098
|
+
entries = fs8__namespace.readdirSync(dir);
|
|
3065
3099
|
} catch {
|
|
3066
3100
|
return false;
|
|
3067
3101
|
}
|
|
3068
3102
|
return entries.every(
|
|
3069
|
-
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) ||
|
|
3103
|
+
(entry) => entry === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry) || // A snapshot signed before signing moved into staging has a valid signature.json the old
|
|
3104
|
+
// marker could not record. It is our artifact when the signature verifies.
|
|
3105
|
+
entry === "signature.json" && verifySnapshotSignature(dir).ok || accounted.has(entry)
|
|
3070
3106
|
);
|
|
3071
3107
|
}
|
|
3072
3108
|
function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
@@ -3078,7 +3114,7 @@ function makeToolOwnedDecider(cwd, toolOwnedPaths) {
|
|
|
3078
3114
|
const prefix = parts.slice(0, depth).join("/");
|
|
3079
3115
|
let hasMarker = markers.get(prefix);
|
|
3080
3116
|
if (hasMarker === void 0) {
|
|
3081
|
-
hasMarker = isToolOwnedDirectory2(
|
|
3117
|
+
hasMarker = isToolOwnedDirectory2(path6__namespace.join(cwd, prefix));
|
|
3082
3118
|
markers.set(prefix, hasMarker);
|
|
3083
3119
|
}
|
|
3084
3120
|
if (hasMarker) return true;
|
|
@@ -3093,7 +3129,7 @@ function makeLinkProbe() {
|
|
|
3093
3129
|
let known = cache.get(absolutePath);
|
|
3094
3130
|
if (known === void 0) {
|
|
3095
3131
|
try {
|
|
3096
|
-
known =
|
|
3132
|
+
known = fs8__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
3097
3133
|
} catch {
|
|
3098
3134
|
known = false;
|
|
3099
3135
|
}
|
|
@@ -3106,7 +3142,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3106
3142
|
const isLink = makeLinkProbe();
|
|
3107
3143
|
let rootReal = cwd;
|
|
3108
3144
|
try {
|
|
3109
|
-
rootReal =
|
|
3145
|
+
rootReal = fs8__namespace.realpathSync(cwd);
|
|
3110
3146
|
} catch {
|
|
3111
3147
|
}
|
|
3112
3148
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -3121,7 +3157,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3121
3157
|
let linkedPath = null;
|
|
3122
3158
|
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
3123
3159
|
const prefix = parts.slice(0, depth).join("/");
|
|
3124
|
-
if (isLink(
|
|
3160
|
+
if (isLink(path6__namespace.join(cwd, prefix))) {
|
|
3125
3161
|
linkedPath = prefix;
|
|
3126
3162
|
break;
|
|
3127
3163
|
}
|
|
@@ -3130,11 +3166,11 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3130
3166
|
kept.push(candidate);
|
|
3131
3167
|
continue;
|
|
3132
3168
|
}
|
|
3133
|
-
const absolute =
|
|
3169
|
+
const absolute = path6__namespace.join(cwd, linkedPath);
|
|
3134
3170
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
3135
3171
|
let targetReal = null;
|
|
3136
3172
|
try {
|
|
3137
|
-
targetReal =
|
|
3173
|
+
targetReal = fs8__namespace.realpathSync(absolute);
|
|
3138
3174
|
} catch {
|
|
3139
3175
|
targetReal = null;
|
|
3140
3176
|
}
|
|
@@ -3152,7 +3188,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3152
3188
|
}
|
|
3153
3189
|
let stats = null;
|
|
3154
3190
|
try {
|
|
3155
|
-
stats =
|
|
3191
|
+
stats = fs8__namespace.statSync(absolute);
|
|
3156
3192
|
} catch {
|
|
3157
3193
|
stats = null;
|
|
3158
3194
|
}
|
|
@@ -3176,6 +3212,15 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3176
3212
|
});
|
|
3177
3213
|
continue;
|
|
3178
3214
|
}
|
|
3215
|
+
const targetRelative = path6__namespace.relative(rootReal, targetReal).split(path6__namespace.sep).join("/");
|
|
3216
|
+
if (isSensitivePath(targetRelative)) {
|
|
3217
|
+
report2(linkedPath, {
|
|
3218
|
+
path: linkedPath,
|
|
3219
|
+
reason: "sensitive-file",
|
|
3220
|
+
detail: "link target is a credential-bearing file; not followed"
|
|
3221
|
+
});
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3179
3224
|
kept.push(candidate);
|
|
3180
3225
|
}
|
|
3181
3226
|
return kept;
|
|
@@ -3240,7 +3285,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
3240
3285
|
"Discovery mode is `git`, but git could not list this directory's files. Run inside a working repository, or pass --discovery walk (or auto) to scan the tree directly."
|
|
3241
3286
|
);
|
|
3242
3287
|
}
|
|
3243
|
-
if (
|
|
3288
|
+
if (fs8__namespace.existsSync(path6__namespace.join(cwd, ".git"))) {
|
|
3244
3289
|
throw new Error(
|
|
3245
3290
|
"This directory is a git repository, but git could not list its files. A plain walk honours .gitignore files, but git also applies .git/info/exclude and your global excludes file, includes files that are tracked although a .gitignore now matches them, and treats a submodule as a single entry. Fix the repository (git status should work), run outside git, or pass --discovery walk to accept those differences."
|
|
3246
3291
|
);
|
|
@@ -3308,7 +3353,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
3308
3353
|
}
|
|
3309
3354
|
function rootRealFor(root) {
|
|
3310
3355
|
try {
|
|
3311
|
-
return
|
|
3356
|
+
return fs8__namespace.realpathSync(root);
|
|
3312
3357
|
} catch {
|
|
3313
3358
|
return root;
|
|
3314
3359
|
}
|
|
@@ -3317,18 +3362,18 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3317
3362
|
const results = { files: [], skipped: [] };
|
|
3318
3363
|
const stack = [];
|
|
3319
3364
|
const toolDirNames = toolDirNamesFor(reservedPaths);
|
|
3320
|
-
const relativeToBase = (target) =>
|
|
3365
|
+
const relativeToBase = (target) => path6__namespace.relative(baseDir, target).replace(/\\/g, "/") || ".";
|
|
3321
3366
|
const enter = (current, layers) => {
|
|
3322
3367
|
if (visited.has(current)) return false;
|
|
3323
3368
|
visited.add(current);
|
|
3324
3369
|
const localRules = readGitignoreRules(current);
|
|
3325
3370
|
const gitignoreLayers = localRules.length === 0 ? layers : [
|
|
3326
3371
|
...layers,
|
|
3327
|
-
{ prefix:
|
|
3372
|
+
{ prefix: path6__namespace.relative(baseDir, current).replace(/\\/g, "/"), rules: localRules }
|
|
3328
3373
|
];
|
|
3329
3374
|
let entries;
|
|
3330
3375
|
try {
|
|
3331
|
-
entries =
|
|
3376
|
+
entries = fs8__namespace.readdirSync(current, { withFileTypes: true });
|
|
3332
3377
|
} catch {
|
|
3333
3378
|
results.skipped.push({
|
|
3334
3379
|
path: relativeToBase(current),
|
|
@@ -3350,8 +3395,8 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3350
3395
|
}
|
|
3351
3396
|
const entry = frame.entries[frame.index];
|
|
3352
3397
|
frame.index += 1;
|
|
3353
|
-
const fullPath =
|
|
3354
|
-
const relPath =
|
|
3398
|
+
const fullPath = path6__namespace.join(frame.dir, entry.name);
|
|
3399
|
+
const relPath = path6__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
3355
3400
|
if (reservedPaths.has(relPath)) continue;
|
|
3356
3401
|
if (entry.isDirectory() && DEFAULT_IGNORED_DIRS.includes(entry.name)) {
|
|
3357
3402
|
results.skipped.push({
|
|
@@ -3384,14 +3429,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3384
3429
|
if (entry.isSymbolicLink()) {
|
|
3385
3430
|
let targetReal;
|
|
3386
3431
|
try {
|
|
3387
|
-
targetReal =
|
|
3432
|
+
targetReal = fs8__namespace.realpathSync(fullPath);
|
|
3388
3433
|
} catch {
|
|
3389
3434
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
3390
3435
|
continue;
|
|
3391
3436
|
}
|
|
3392
3437
|
let stats;
|
|
3393
3438
|
try {
|
|
3394
|
-
stats =
|
|
3439
|
+
stats = fs8__namespace.statSync(fullPath);
|
|
3395
3440
|
} catch {
|
|
3396
3441
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
3397
3442
|
continue;
|
|
@@ -3421,7 +3466,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3421
3466
|
});
|
|
3422
3467
|
continue;
|
|
3423
3468
|
}
|
|
3424
|
-
const targetRelative =
|
|
3469
|
+
const targetRelative = path6__namespace.relative(rootReal, targetReal).split(path6__namespace.sep).join("/");
|
|
3425
3470
|
if (isSensitivePath(targetRelative)) {
|
|
3426
3471
|
results.skipped.push({
|
|
3427
3472
|
path: relPath,
|
|
@@ -3617,21 +3662,25 @@ var CONFIG_KEY_NAMES = [
|
|
|
3617
3662
|
"kinds",
|
|
3618
3663
|
"largeFileBytes",
|
|
3619
3664
|
"layers",
|
|
3665
|
+
"logCount",
|
|
3620
3666
|
"layersMode",
|
|
3621
3667
|
"maxMonolithBytes",
|
|
3622
3668
|
"maxPartBytes",
|
|
3623
3669
|
"maxParts",
|
|
3624
3670
|
"maxPartTokens",
|
|
3625
3671
|
"outDir",
|
|
3672
|
+
"pack",
|
|
3626
3673
|
"preset",
|
|
3627
3674
|
"previewHeadLines",
|
|
3628
3675
|
"promptTask",
|
|
3629
3676
|
"staged",
|
|
3630
3677
|
"previewTailLines",
|
|
3678
|
+
"removeEmptyLines",
|
|
3631
3679
|
"secretRules",
|
|
3632
3680
|
"secrets",
|
|
3633
3681
|
"sarif",
|
|
3634
3682
|
"skeleton",
|
|
3683
|
+
"stripComments",
|
|
3635
3684
|
"tmpDir",
|
|
3636
3685
|
"withDependents"
|
|
3637
3686
|
];
|
|
@@ -3676,10 +3725,10 @@ function readConfigExport(exported, file) {
|
|
|
3676
3725
|
var lastModuleConfig = null;
|
|
3677
3726
|
function moduleConfigKey(fullPath) {
|
|
3678
3727
|
try {
|
|
3679
|
-
return
|
|
3728
|
+
return crypto5.createHash("sha256").update(fs8__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
3680
3729
|
} catch {
|
|
3681
3730
|
try {
|
|
3682
|
-
const stats =
|
|
3731
|
+
const stats = fs8__namespace.statSync(fullPath);
|
|
3683
3732
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
3684
3733
|
} catch {
|
|
3685
3734
|
return "unreadable";
|
|
@@ -3705,7 +3754,7 @@ async function importConfigModule(fullPath) {
|
|
|
3705
3754
|
function attachConfigDir(config, filePath) {
|
|
3706
3755
|
if (typeof config === "object" && config !== null) {
|
|
3707
3756
|
Object.defineProperty(config, CONFIG_DIR_SYMBOL, {
|
|
3708
|
-
value:
|
|
3757
|
+
value: path6__namespace.dirname(filePath),
|
|
3709
3758
|
enumerable: false,
|
|
3710
3759
|
configurable: true
|
|
3711
3760
|
});
|
|
@@ -3717,12 +3766,12 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3717
3766
|
const errors = [];
|
|
3718
3767
|
const configDirectories = [];
|
|
3719
3768
|
for (const filename of CONFIG_FILENAMES) {
|
|
3720
|
-
const fullPath =
|
|
3769
|
+
const fullPath = path6__namespace.join(cwd, filename);
|
|
3721
3770
|
let candidateStats = null;
|
|
3722
3771
|
try {
|
|
3723
|
-
candidateStats =
|
|
3772
|
+
candidateStats = fs8__namespace.statSync(fullPath);
|
|
3724
3773
|
} catch {
|
|
3725
|
-
if (!
|
|
3774
|
+
if (!fs8__namespace.existsSync(fullPath)) continue;
|
|
3726
3775
|
}
|
|
3727
3776
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
3728
3777
|
configDirectories.push(fullPath);
|
|
@@ -3730,7 +3779,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3730
3779
|
}
|
|
3731
3780
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
3732
3781
|
try {
|
|
3733
|
-
const config = parseJsonish(
|
|
3782
|
+
const config = parseJsonish(fs8__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
3734
3783
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
3735
3784
|
throw new Error(
|
|
3736
3785
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -3770,10 +3819,10 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3770
3819
|
continue;
|
|
3771
3820
|
}
|
|
3772
3821
|
}
|
|
3773
|
-
const pkgJsonPath =
|
|
3774
|
-
if (
|
|
3822
|
+
const pkgJsonPath = path6__namespace.join(cwd, "package.json");
|
|
3823
|
+
if (fs8__namespace.existsSync(pkgJsonPath)) {
|
|
3775
3824
|
try {
|
|
3776
|
-
const parsed = parseJsonish(
|
|
3825
|
+
const parsed = parseJsonish(fs8__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
3777
3826
|
const snapshotKey = parsed.snapshot;
|
|
3778
3827
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
3779
3828
|
assertKnownConfigKeys(
|
|
@@ -3939,11 +3988,38 @@ function readConfiguredBrief(cwd, value) {
|
|
|
3939
3988
|
"brief must be a path to a markdown file (received " + describeValue2(value) + ")."
|
|
3940
3989
|
);
|
|
3941
3990
|
}
|
|
3942
|
-
const
|
|
3991
|
+
const rootReal = (() => {
|
|
3992
|
+
try {
|
|
3993
|
+
return fs8__namespace.realpathSync(cwd);
|
|
3994
|
+
} catch {
|
|
3995
|
+
return path6__namespace.resolve(cwd);
|
|
3996
|
+
}
|
|
3997
|
+
})();
|
|
3998
|
+
const requested = path6__namespace.resolve(cwd, value);
|
|
3999
|
+
let filePath;
|
|
4000
|
+
try {
|
|
4001
|
+
filePath = fs8__namespace.realpathSync(requested);
|
|
4002
|
+
} catch {
|
|
4003
|
+
throw new Error(
|
|
4004
|
+
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
4005
|
+
);
|
|
4006
|
+
}
|
|
4007
|
+
const relative9 = path6__namespace.relative(rootReal, filePath);
|
|
4008
|
+
if (relative9.length === 0 || relative9 === ".." || relative9.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative9)) {
|
|
4009
|
+
throw new Error(
|
|
4010
|
+
'brief "' + value + '" resolves outside the repository. A brief must be a file inside the repository being described; an absolute or parent path is refused.'
|
|
4011
|
+
);
|
|
4012
|
+
}
|
|
4013
|
+
const posixRelative = relative9.split(path6__namespace.sep).join("/");
|
|
4014
|
+
if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
|
|
4015
|
+
throw new Error(
|
|
4016
|
+
'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
|
|
4017
|
+
);
|
|
4018
|
+
}
|
|
3943
4019
|
let text;
|
|
3944
4020
|
try {
|
|
3945
|
-
if (!
|
|
3946
|
-
text =
|
|
4021
|
+
if (!fs8__namespace.statSync(filePath).isFile()) throw new Error("not a file");
|
|
4022
|
+
text = fs8__namespace.readFileSync(filePath, "utf8");
|
|
3947
4023
|
} catch {
|
|
3948
4024
|
throw new Error(
|
|
3949
4025
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
@@ -4055,9 +4131,9 @@ function resolveKindRules(value) {
|
|
|
4055
4131
|
function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
4056
4132
|
const patterns = [];
|
|
4057
4133
|
for (const dir of [outDir, tmpDir]) {
|
|
4058
|
-
const absolute =
|
|
4059
|
-
const relative9 =
|
|
4060
|
-
if (!relative9 || relative9 === ".." || relative9.startsWith(`..${
|
|
4134
|
+
const absolute = path6__namespace.resolve(cwd, dir);
|
|
4135
|
+
const relative9 = path6__namespace.relative(cwd, absolute);
|
|
4136
|
+
if (!relative9 || relative9 === ".." || relative9.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative9)) {
|
|
4061
4137
|
continue;
|
|
4062
4138
|
}
|
|
4063
4139
|
patterns.push(`${relative9.replace(/\\/g, "/")}/**`);
|
|
@@ -4190,11 +4266,11 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
4190
4266
|
);
|
|
4191
4267
|
}
|
|
4192
4268
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
4193
|
-
const resolved =
|
|
4194
|
-
if (!
|
|
4269
|
+
const resolved = path6__namespace.resolve(candidate);
|
|
4270
|
+
if (!fs8__namespace.existsSync(resolved)) {
|
|
4195
4271
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
4196
4272
|
}
|
|
4197
|
-
if (!
|
|
4273
|
+
if (!fs8__namespace.statSync(resolved).isDirectory()) {
|
|
4198
4274
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
4199
4275
|
}
|
|
4200
4276
|
return resolved;
|
|
@@ -4524,7 +4600,7 @@ function configDigest(config) {
|
|
|
4524
4600
|
(rule) => `${rule.rule}:${rule.pattern.source}/${rule.pattern.flags}:${rule.valueGroup ?? ""}`
|
|
4525
4601
|
).sort()
|
|
4526
4602
|
};
|
|
4527
|
-
return
|
|
4603
|
+
return crypto5.createHash("sha256").update(JSON.stringify(material)).digest("hex");
|
|
4528
4604
|
}
|
|
4529
4605
|
|
|
4530
4606
|
// src/ast/profiles/shared.ts
|
|
@@ -5722,7 +5798,7 @@ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
5722
5798
|
".so"
|
|
5723
5799
|
]);
|
|
5724
5800
|
function isBinaryExtension(filePath) {
|
|
5725
|
-
const ext =
|
|
5801
|
+
const ext = path6__namespace.extname(filePath).toLowerCase();
|
|
5726
5802
|
return BINARY_EXTENSIONS.has(ext);
|
|
5727
5803
|
}
|
|
5728
5804
|
function countControlBytes(buffer) {
|
|
@@ -5889,13 +5965,13 @@ function isBinaryFile(absolutePath) {
|
|
|
5889
5965
|
if (isBinaryExtension(absolutePath)) return true;
|
|
5890
5966
|
let fd;
|
|
5891
5967
|
try {
|
|
5892
|
-
fd =
|
|
5968
|
+
fd = fs8__namespace.openSync(absolutePath, "r");
|
|
5893
5969
|
const buffer = Buffer.alloc(CHUNK);
|
|
5894
5970
|
let sample2;
|
|
5895
5971
|
let position = 0;
|
|
5896
5972
|
while (position < BINARY_SCAN_BYTES) {
|
|
5897
5973
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
5898
|
-
const bytesRead =
|
|
5974
|
+
const bytesRead = fs8__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
5899
5975
|
if (bytesRead === 0) return false;
|
|
5900
5976
|
const chunk = buffer.subarray(0, bytesRead);
|
|
5901
5977
|
if (sample2 === void 0) {
|
|
@@ -5913,7 +5989,7 @@ function isBinaryFile(absolutePath) {
|
|
|
5913
5989
|
} finally {
|
|
5914
5990
|
if (fd !== void 0) {
|
|
5915
5991
|
try {
|
|
5916
|
-
|
|
5992
|
+
fs8__namespace.closeSync(fd);
|
|
5917
5993
|
} catch {
|
|
5918
5994
|
}
|
|
5919
5995
|
}
|
|
@@ -5935,9 +6011,9 @@ function importsOfText(relativePath, text) {
|
|
|
5935
6011
|
function importsOfFile(relativePath, absolutePath) {
|
|
5936
6012
|
let buffer;
|
|
5937
6013
|
try {
|
|
5938
|
-
const stats =
|
|
6014
|
+
const stats = fs8__namespace.statSync(absolutePath);
|
|
5939
6015
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
5940
|
-
buffer =
|
|
6016
|
+
buffer = fs8__namespace.readFileSync(absolutePath);
|
|
5941
6017
|
} catch {
|
|
5942
6018
|
return [];
|
|
5943
6019
|
}
|
|
@@ -6093,7 +6169,7 @@ function emittedBody(content) {
|
|
|
6093
6169
|
}
|
|
6094
6170
|
function anchorForPath(filePath) {
|
|
6095
6171
|
const slug = filePath.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6096
|
-
const digest =
|
|
6172
|
+
const digest = crypto5__namespace.createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
6097
6173
|
return `${slug || "file"}-${digest}`;
|
|
6098
6174
|
}
|
|
6099
6175
|
|
|
@@ -6450,6 +6526,17 @@ function gitPaths(cwd, args) {
|
|
|
6450
6526
|
}
|
|
6451
6527
|
return output.split("\0").filter((entry) => entry.length > 0);
|
|
6452
6528
|
}
|
|
6529
|
+
function readStagedBlob(cwd, relativePath) {
|
|
6530
|
+
try {
|
|
6531
|
+
return childProcess.execFileSync("git", ["cat-file", "blob", `:${relativePath}`], {
|
|
6532
|
+
cwd,
|
|
6533
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
6534
|
+
maxBuffer: 512 * 1024 * 1024
|
|
6535
|
+
});
|
|
6536
|
+
} catch {
|
|
6537
|
+
return null;
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6453
6540
|
function assertUsableRef(ref) {
|
|
6454
6541
|
if (ref.startsWith("-")) {
|
|
6455
6542
|
throw new Error(
|
|
@@ -6548,10 +6635,10 @@ var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
|
6548
6635
|
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
6549
6636
|
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
6550
6637
|
function tsconfigPathsFor(cwd) {
|
|
6551
|
-
const configPath =
|
|
6638
|
+
const configPath = path6__namespace.join(cwd, "tsconfig.json");
|
|
6552
6639
|
let stats;
|
|
6553
6640
|
try {
|
|
6554
|
-
stats =
|
|
6641
|
+
stats = fs8__namespace.statSync(configPath);
|
|
6555
6642
|
} catch (err) {
|
|
6556
6643
|
if (err.code === "ENOENT") return null;
|
|
6557
6644
|
return null;
|
|
@@ -6585,8 +6672,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
6585
6672
|
return value;
|
|
6586
6673
|
}
|
|
6587
6674
|
function repositoryRelative(cwd, target) {
|
|
6588
|
-
const relative9 =
|
|
6589
|
-
return relative9.length === 0 || !relative9.startsWith("..") && !
|
|
6675
|
+
const relative9 = path6__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
6676
|
+
return relative9.length === 0 || !relative9.startsWith("..") && !path6__namespace.isAbsolute(relative9) ? relative9 : null;
|
|
6590
6677
|
}
|
|
6591
6678
|
function rememberFirst(map, key, value) {
|
|
6592
6679
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -6601,15 +6688,15 @@ function buildImportResolver(files, options = {}) {
|
|
|
6601
6688
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
6602
6689
|
rememberFirst(byPathFolded, relativePath.toLowerCase(), relativePath);
|
|
6603
6690
|
}
|
|
6604
|
-
const extension =
|
|
6691
|
+
const extension = path6__namespace.posix.extname(relativePath);
|
|
6605
6692
|
if (!SOURCE_EXTENSIONS.has(extension)) return;
|
|
6606
6693
|
const stem = relativePath.slice(0, -extension.length);
|
|
6607
6694
|
rememberFirst(byStem, stem, relativePath);
|
|
6608
6695
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
6609
6696
|
rememberFirst(byStemFolded, stem.toLowerCase(), relativePath);
|
|
6610
6697
|
}
|
|
6611
|
-
if (
|
|
6612
|
-
const directory =
|
|
6698
|
+
if (path6__namespace.posix.basename(stem) === "index") {
|
|
6699
|
+
const directory = path6__namespace.posix.dirname(stem);
|
|
6613
6700
|
rememberFirst(byStem, directory, relativePath);
|
|
6614
6701
|
if (CASE_INSENSITIVE_FILESYSTEM) {
|
|
6615
6702
|
rememberFirst(byStemFolded, directory.toLowerCase(), relativePath);
|
|
@@ -6625,7 +6712,7 @@ function buildImportResolver(files, options = {}) {
|
|
|
6625
6712
|
return { byPath, byPathFolded, byStem, byStemFolded, tsconfig: options.tsconfig ?? null };
|
|
6626
6713
|
}
|
|
6627
6714
|
function resolveSpecifier(fromFile, specifier, resolver) {
|
|
6628
|
-
const extension =
|
|
6715
|
+
const extension = path6__namespace.posix.extname(fromFile).toLowerCase();
|
|
6629
6716
|
const exact = (key) => resolver.byPath.get(key) ?? (CASE_INSENSITIVE_FILESYSTEM ? resolver.byPathFolded.get(key.toLowerCase()) : void 0) ?? null;
|
|
6630
6717
|
const firstOf = (candidates) => {
|
|
6631
6718
|
for (const candidate of candidates) {
|
|
@@ -6648,34 +6735,34 @@ function resolveSpecifier(fromFile, specifier, resolver) {
|
|
|
6648
6735
|
if (PYTHON_EXTENSIONS.has(extension) && specifier.startsWith(".")) {
|
|
6649
6736
|
const dots = /^\.+/.exec(specifier)?.[0].length ?? 0;
|
|
6650
6737
|
const rest = specifier.slice(dots).replace(/\./g, "/");
|
|
6651
|
-
let base =
|
|
6652
|
-
for (let up = 1; up < dots; up += 1) base =
|
|
6653
|
-
const joined2 = rest ?
|
|
6738
|
+
let base = path6__namespace.posix.dirname(fromFile);
|
|
6739
|
+
for (let up = 1; up < dots; up += 1) base = path6__namespace.posix.dirname(base);
|
|
6740
|
+
const joined2 = rest ? path6__namespace.posix.normalize(path6__namespace.posix.join(base, rest)) : base;
|
|
6654
6741
|
return firstOf([joined2, ...PYTHON_SUFFIXES.map((suffix) => `${joined2}${suffix}`)]);
|
|
6655
6742
|
}
|
|
6656
6743
|
if (RUBY_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
6657
|
-
const joined2 =
|
|
6658
|
-
|
|
6744
|
+
const joined2 = path6__namespace.posix.normalize(
|
|
6745
|
+
path6__namespace.posix.join(path6__namespace.posix.dirname(fromFile), specifier)
|
|
6659
6746
|
);
|
|
6660
6747
|
return firstOf([`${joined2}.rb`, joined2]);
|
|
6661
6748
|
}
|
|
6662
6749
|
if (C_EXTENSIONS.has(extension) && specifier.startsWith("./")) {
|
|
6663
|
-
const joined2 =
|
|
6664
|
-
|
|
6750
|
+
const joined2 = path6__namespace.posix.normalize(
|
|
6751
|
+
path6__namespace.posix.join(path6__namespace.posix.dirname(fromFile), specifier)
|
|
6665
6752
|
);
|
|
6666
6753
|
return exact(joined2);
|
|
6667
6754
|
}
|
|
6668
6755
|
if (extension === ".dart" && !specifier.includes(":")) {
|
|
6669
|
-
const joined2 =
|
|
6670
|
-
|
|
6756
|
+
const joined2 = path6__namespace.posix.normalize(
|
|
6757
|
+
path6__namespace.posix.join(path6__namespace.posix.dirname(fromFile), specifier)
|
|
6671
6758
|
);
|
|
6672
6759
|
return firstOf([joined2, `${joined2}.dart`]);
|
|
6673
6760
|
}
|
|
6674
6761
|
if (!RELATIVE_SPECIFIER.test(specifier)) {
|
|
6675
6762
|
return resolveTsconfigSpecifier(specifier, resolver, lookupPath);
|
|
6676
6763
|
}
|
|
6677
|
-
const joined =
|
|
6678
|
-
|
|
6764
|
+
const joined = path6__namespace.posix.normalize(
|
|
6765
|
+
path6__namespace.posix.join(path6__namespace.posix.dirname(fromFile), specifier)
|
|
6679
6766
|
);
|
|
6680
6767
|
return lookupPath(joined);
|
|
6681
6768
|
}
|
|
@@ -6699,13 +6786,13 @@ function resolveTsconfigSpecifier(specifier, resolver, lookupPath) {
|
|
|
6699
6786
|
if (captured === null) continue;
|
|
6700
6787
|
for (const target of rule.targets) {
|
|
6701
6788
|
const substituted = target.split("*").join(captured);
|
|
6702
|
-
const base = config.baseUrl === null ? substituted :
|
|
6703
|
-
const hit = lookupPath(
|
|
6789
|
+
const base = config.baseUrl === null ? substituted : path6__namespace.posix.join(config.baseUrl, substituted);
|
|
6790
|
+
const hit = lookupPath(path6__namespace.posix.normalize(base));
|
|
6704
6791
|
if (hit) return hit;
|
|
6705
6792
|
}
|
|
6706
6793
|
}
|
|
6707
6794
|
if (config.baseUrl !== null) {
|
|
6708
|
-
return lookupPath(
|
|
6795
|
+
return lookupPath(path6__namespace.posix.normalize(path6__namespace.posix.join(config.baseUrl, specifier)));
|
|
6709
6796
|
}
|
|
6710
6797
|
return null;
|
|
6711
6798
|
}
|
|
@@ -6773,79 +6860,44 @@ var LANGUAGE_BY_BASENAME = {
|
|
|
6773
6860
|
};
|
|
6774
6861
|
function detectLanguage(filePath) {
|
|
6775
6862
|
const normalized = filePath.replace(/\\/g, "/");
|
|
6776
|
-
const base =
|
|
6863
|
+
const base = path6__namespace.posix.basename(normalized);
|
|
6777
6864
|
if (LANGUAGE_BY_BASENAME[base]) return LANGUAGE_BY_BASENAME[base];
|
|
6778
6865
|
if (base === ".env" || base.startsWith(".env.")) return "dotenv";
|
|
6779
|
-
const ext =
|
|
6866
|
+
const ext = path6__namespace.posix.extname(base).toLowerCase();
|
|
6780
6867
|
return LANGUAGE_BY_EXTENSION[ext] ?? "text";
|
|
6781
6868
|
}
|
|
6782
|
-
var SIGNATURE_FILE = "signature.json";
|
|
6783
|
-
function verifySnapshotSignature(snapshotDir) {
|
|
6784
|
-
const signaturePath = path5__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
6785
|
-
const manifestPath = path5__namespace.join(snapshotDir, "manifest.json");
|
|
6786
|
-
if (!fs2__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
6787
|
-
let record;
|
|
6788
|
-
try {
|
|
6789
|
-
record = JSON.parse(fs2__namespace.readFileSync(signaturePath, "utf8"));
|
|
6790
|
-
} catch (error) {
|
|
6791
|
-
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
6792
|
-
}
|
|
6793
|
-
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
6794
|
-
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
6795
|
-
}
|
|
6796
|
-
let bytes;
|
|
6797
|
-
try {
|
|
6798
|
-
bytes = fs2__namespace.readFileSync(manifestPath);
|
|
6799
|
-
} catch {
|
|
6800
|
-
return { ok: false, reason: "the signed manifest is missing" };
|
|
6801
|
-
}
|
|
6802
|
-
const sha2562 = crypto2__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
6803
|
-
if (sha2562 !== record.manifestSha256) {
|
|
6804
|
-
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
6805
|
-
}
|
|
6806
|
-
let verified = false;
|
|
6807
|
-
try {
|
|
6808
|
-
const key = crypto2__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
6809
|
-
verified = crypto2__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
6810
|
-
} catch (error) {
|
|
6811
|
-
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
6812
|
-
}
|
|
6813
|
-
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
6814
|
-
}
|
|
6815
|
-
|
|
6816
|
-
// src/validator/validate.ts
|
|
6817
6869
|
function maskedPath(value, secretRules) {
|
|
6818
6870
|
return findSecretInPath(value, secretRules)?.masked ?? value;
|
|
6819
6871
|
}
|
|
6820
6872
|
function confineToDirectory(directory, filename) {
|
|
6821
6873
|
if (filename.includes("\0")) return null;
|
|
6822
|
-
if (
|
|
6823
|
-
const base =
|
|
6824
|
-
const resolved =
|
|
6874
|
+
if (path6__namespace.isAbsolute(filename)) return null;
|
|
6875
|
+
const base = path6__namespace.resolve(directory);
|
|
6876
|
+
const resolved = path6__namespace.resolve(base, filename);
|
|
6825
6877
|
const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
|
|
6826
|
-
const prefix = caseInsensitive ? `${base}${
|
|
6878
|
+
const prefix = caseInsensitive ? `${base}${path6__namespace.sep}`.toLowerCase() : `${base}${path6__namespace.sep}`;
|
|
6827
6879
|
const candidate = caseInsensitive ? resolved.toLowerCase() : resolved;
|
|
6828
6880
|
return candidate.startsWith(prefix) ? resolved : null;
|
|
6829
6881
|
}
|
|
6830
6882
|
function findStagingDirectory(config) {
|
|
6831
|
-
const tmpDir =
|
|
6883
|
+
const tmpDir = path6__namespace.resolve(config.cwd, config.tmpDir);
|
|
6832
6884
|
let entries;
|
|
6833
6885
|
try {
|
|
6834
|
-
entries =
|
|
6886
|
+
entries = fs8__namespace.readdirSync(tmpDir);
|
|
6835
6887
|
} catch {
|
|
6836
6888
|
return null;
|
|
6837
6889
|
}
|
|
6838
6890
|
const runs = entries.filter((name) => name.startsWith("run-")).sort();
|
|
6839
6891
|
const newest = runs[runs.length - 1];
|
|
6840
|
-
return newest ?
|
|
6892
|
+
return newest ? path6__namespace.join(tmpDir, newest) : null;
|
|
6841
6893
|
}
|
|
6842
6894
|
function describeMissingManifest(config, manifestPath) {
|
|
6843
|
-
const outDir =
|
|
6844
|
-
const markerPath =
|
|
6895
|
+
const outDir = path6__namespace.resolve(config.cwd, config.outDir);
|
|
6896
|
+
const markerPath = path6__namespace.join(outDir, ".codebase-snapshot");
|
|
6845
6897
|
let marker = null;
|
|
6846
6898
|
try {
|
|
6847
|
-
if (
|
|
6848
|
-
const parsed = JSON.parse(
|
|
6899
|
+
if (fs8__namespace.existsSync(markerPath)) {
|
|
6900
|
+
const parsed = JSON.parse(fs8__namespace.readFileSync(markerPath, "utf8"));
|
|
6849
6901
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
6850
6902
|
marker = parsed;
|
|
6851
6903
|
}
|
|
@@ -6877,16 +6929,16 @@ function emptyDrift() {
|
|
|
6877
6929
|
};
|
|
6878
6930
|
}
|
|
6879
6931
|
function sha256Hex(buffer) {
|
|
6880
|
-
return
|
|
6932
|
+
return crypto5__namespace.createHash("sha256").update(buffer).digest("hex");
|
|
6881
6933
|
}
|
|
6882
6934
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
6883
|
-
const absolutePath =
|
|
6935
|
+
const absolutePath = path6__namespace.join(cwd, relativePath);
|
|
6884
6936
|
try {
|
|
6885
|
-
const stats =
|
|
6937
|
+
const stats = fs8__namespace.statSync(absolutePath);
|
|
6886
6938
|
if (!stats.isFile()) return false;
|
|
6887
6939
|
if (isBinaryExtension(absolutePath)) return false;
|
|
6888
6940
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
6889
|
-
return !decodeText(
|
|
6941
|
+
return !decodeText(fs8__namespace.readFileSync(absolutePath)).binary;
|
|
6890
6942
|
} catch {
|
|
6891
6943
|
return false;
|
|
6892
6944
|
}
|
|
@@ -6898,7 +6950,7 @@ var TRUNCATION_REASONS = /* @__PURE__ */ new Set([
|
|
|
6898
6950
|
]);
|
|
6899
6951
|
function isConfinedRelative(value) {
|
|
6900
6952
|
if (value.length === 0 || value.includes("\0") || value.includes("\\")) return false;
|
|
6901
|
-
if (
|
|
6953
|
+
if (path6__namespace.isAbsolute(value)) return false;
|
|
6902
6954
|
return !value.split("/").includes("..");
|
|
6903
6955
|
}
|
|
6904
6956
|
function describeManifestShapeProblem(value) {
|
|
@@ -7092,7 +7144,7 @@ function describeManifestShapeProblem(value) {
|
|
|
7092
7144
|
if (typeof filename !== "string" || filename.trim() === "") {
|
|
7093
7145
|
return 'a "parts" entry has no "filename"';
|
|
7094
7146
|
}
|
|
7095
|
-
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." ||
|
|
7147
|
+
if (filename.includes("/") || filename.includes("\\") || filename.includes("\0") || filename === "." || filename === ".." || path6__namespace.isAbsolute(filename)) {
|
|
7096
7148
|
return 'a "parts" entry "filename" must be a bare filename inside parts/';
|
|
7097
7149
|
}
|
|
7098
7150
|
if (currentSchema) {
|
|
@@ -7118,8 +7170,8 @@ function describeManifestShapeProblem(value) {
|
|
|
7118
7170
|
function validateSnapshot(configInput) {
|
|
7119
7171
|
assertUsableConfigInput(configInput);
|
|
7120
7172
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
7121
|
-
const manifestPath =
|
|
7122
|
-
if (!
|
|
7173
|
+
const manifestPath = path6__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
7174
|
+
if (!fs8__namespace.existsSync(manifestPath)) {
|
|
7123
7175
|
return {
|
|
7124
7176
|
valid: false,
|
|
7125
7177
|
manifestPresent: false,
|
|
@@ -7130,7 +7182,7 @@ function validateSnapshot(configInput) {
|
|
|
7130
7182
|
}
|
|
7131
7183
|
let manifest;
|
|
7132
7184
|
try {
|
|
7133
|
-
manifest = JSON.parse(
|
|
7185
|
+
manifest = JSON.parse(fs8__namespace.readFileSync(manifestPath, "utf8"));
|
|
7134
7186
|
} catch (err) {
|
|
7135
7187
|
return {
|
|
7136
7188
|
valid: false,
|
|
@@ -7152,7 +7204,7 @@ function validateSnapshot(configInput) {
|
|
|
7152
7204
|
}
|
|
7153
7205
|
const drift = emptyDrift();
|
|
7154
7206
|
const warnings = [];
|
|
7155
|
-
const snapshotDir =
|
|
7207
|
+
const snapshotDir = path6__namespace.resolve(config.cwd, config.outDir);
|
|
7156
7208
|
const unreadableSkips = manifest.skipped.filter(
|
|
7157
7209
|
(entry) => entry.reason === "missing" || entry.reason === "read-error"
|
|
7158
7210
|
);
|
|
@@ -7230,17 +7282,18 @@ function validateSnapshot(configInput) {
|
|
|
7230
7282
|
return skippedReasons.get(maskedPath(diskFile, config.secretRules)) ?? null;
|
|
7231
7283
|
};
|
|
7232
7284
|
let unchangedScope = null;
|
|
7285
|
+
let stagedScope = null;
|
|
7233
7286
|
const recordedChangedSince = manifest.config?.changedSince;
|
|
7234
7287
|
const recordedStaged = manifest.config?.staged === true;
|
|
7235
7288
|
const recordedWithDependents = manifest.config?.withDependents === true;
|
|
7236
7289
|
if (recordedChangedSince !== void 0 || recordedStaged) {
|
|
7237
7290
|
try {
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
);
|
|
7291
|
+
const scope = resolveChangedScope(config.cwd, {
|
|
7292
|
+
...recordedChangedSince === void 0 ? {} : { changedSince: recordedChangedSince },
|
|
7293
|
+
...recordedStaged ? { staged: true } : {}
|
|
7294
|
+
});
|
|
7295
|
+
unchangedScope = new Set(scope.paths);
|
|
7296
|
+
if (recordedStaged) stagedScope = new Set(scope.stagedPaths);
|
|
7244
7297
|
} catch {
|
|
7245
7298
|
warnings.push(
|
|
7246
7299
|
"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."
|
|
@@ -7251,11 +7304,15 @@ function validateSnapshot(configInput) {
|
|
|
7251
7304
|
function becameDependent(diskFile) {
|
|
7252
7305
|
if (!recordedWithDependents || unchangedScope === null) return false;
|
|
7253
7306
|
dependentResolver ??= buildImportResolver(
|
|
7254
|
-
collection.files.map((file) => ({ relativePath: file }))
|
|
7307
|
+
collection.files.map((file) => ({ relativePath: file })),
|
|
7308
|
+
{
|
|
7309
|
+
tsconfig: tsconfigPathsFor(config.cwd),
|
|
7310
|
+
...unchangedScope === null ? {} : { extraPaths: unchangedScope }
|
|
7311
|
+
}
|
|
7255
7312
|
);
|
|
7256
7313
|
return importsChangedFile(
|
|
7257
7314
|
diskFile,
|
|
7258
|
-
importsOfFile(diskFile,
|
|
7315
|
+
importsOfFile(diskFile, path6__namespace.join(config.cwd, diskFile)),
|
|
7259
7316
|
unchangedScope,
|
|
7260
7317
|
dependentResolver
|
|
7261
7318
|
);
|
|
@@ -7273,7 +7330,7 @@ function validateSnapshot(configInput) {
|
|
|
7273
7330
|
// own output directory as a set of files missing from the snapshot, so a correct
|
|
7274
7331
|
// snapshot was reported as drifting.
|
|
7275
7332
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7276
|
-
(directory) =>
|
|
7333
|
+
(directory) => path6__namespace.relative(config.cwd, path6__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7277
7334
|
).filter((relative9) => relative9.length > 0 && !relative9.startsWith(".."))
|
|
7278
7335
|
});
|
|
7279
7336
|
for (const diskFile of collection.files) {
|
|
@@ -7300,7 +7357,8 @@ function validateSnapshot(configInput) {
|
|
|
7300
7357
|
}
|
|
7301
7358
|
let diskHash;
|
|
7302
7359
|
try {
|
|
7303
|
-
|
|
7360
|
+
const stagedBlob = recordedStaged && stagedScope?.has(diskFile) === true ? readStagedBlob(config.cwd, diskFile) : null;
|
|
7361
|
+
diskHash = sha256Hex(stagedBlob ?? fs8__namespace.readFileSync(path6__namespace.join(config.cwd, diskFile)));
|
|
7304
7362
|
} catch (err) {
|
|
7305
7363
|
if (err.code === "ENOENT") {
|
|
7306
7364
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -7324,7 +7382,7 @@ function validateSnapshot(configInput) {
|
|
|
7324
7382
|
}
|
|
7325
7383
|
let statFailure = null;
|
|
7326
7384
|
try {
|
|
7327
|
-
|
|
7385
|
+
fs8__namespace.statSync(confined);
|
|
7328
7386
|
} catch (err) {
|
|
7329
7387
|
statFailure = err;
|
|
7330
7388
|
}
|
|
@@ -7344,7 +7402,7 @@ function validateSnapshot(configInput) {
|
|
|
7344
7402
|
...Object.values(config.budgets.byLayer)
|
|
7345
7403
|
);
|
|
7346
7404
|
const partNames = /* @__PURE__ */ new Set();
|
|
7347
|
-
const partsDir =
|
|
7405
|
+
const partsDir = path6__namespace.join(snapshotDir, "parts");
|
|
7348
7406
|
for (const part of manifest.parts) {
|
|
7349
7407
|
if (!part || typeof part.filename !== "string") continue;
|
|
7350
7408
|
partNames.add(part.filename);
|
|
@@ -7359,7 +7417,7 @@ function validateSnapshot(configInput) {
|
|
|
7359
7417
|
}
|
|
7360
7418
|
let buffer;
|
|
7361
7419
|
try {
|
|
7362
|
-
buffer =
|
|
7420
|
+
buffer = fs8__namespace.readFileSync(partPath);
|
|
7363
7421
|
} catch {
|
|
7364
7422
|
drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
|
|
7365
7423
|
continue;
|
|
@@ -7736,11 +7794,11 @@ function validateSnapshot(configInput) {
|
|
|
7736
7794
|
];
|
|
7737
7795
|
for (const [key, artifact] of declaredArtifacts) {
|
|
7738
7796
|
if (!artifact) continue;
|
|
7739
|
-
const artifactPath =
|
|
7797
|
+
const artifactPath = path6__namespace.join(snapshotDir, ...key.split("/"));
|
|
7740
7798
|
let buffer;
|
|
7741
7799
|
try {
|
|
7742
|
-
if (!
|
|
7743
|
-
buffer =
|
|
7800
|
+
if (!fs8__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
|
|
7801
|
+
buffer = fs8__namespace.readFileSync(artifactPath);
|
|
7744
7802
|
} catch {
|
|
7745
7803
|
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
7746
7804
|
continue;
|
|
@@ -7753,9 +7811,9 @@ function validateSnapshot(configInput) {
|
|
|
7753
7811
|
for (const match of buffer.toString("utf8").matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
7754
7812
|
const target = match[1].split("#")[0];
|
|
7755
7813
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7756
|
-
const resolved =
|
|
7757
|
-
const relative9 =
|
|
7758
|
-
if (relative9.startsWith("..") ||
|
|
7814
|
+
const resolved = path6__namespace.resolve(snapshotDir, "reports", target);
|
|
7815
|
+
const relative9 = path6__namespace.relative(snapshotDir, resolved);
|
|
7816
|
+
if (relative9.startsWith("..") || path6__namespace.isAbsolute(relative9) || !fs8__namespace.existsSync(resolved)) {
|
|
7759
7817
|
drift.partIssues.push({
|
|
7760
7818
|
part: key,
|
|
7761
7819
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -7768,7 +7826,7 @@ function validateSnapshot(configInput) {
|
|
|
7768
7826
|
if (sarifArtifact) {
|
|
7769
7827
|
const sarifKey = "reports/audit.sarif";
|
|
7770
7828
|
try {
|
|
7771
|
-
const buffer =
|
|
7829
|
+
const buffer = fs8__namespace.readFileSync(path6__namespace.join(snapshotDir, "reports", "audit.sarif"));
|
|
7772
7830
|
if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
|
|
7773
7831
|
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
7774
7832
|
}
|
|
@@ -7814,9 +7872,9 @@ function validateSnapshot(configInput) {
|
|
|
7814
7872
|
`${drift.configMismatches.length} configuration mismatch(es) between the manifest and this run.`
|
|
7815
7873
|
);
|
|
7816
7874
|
}
|
|
7817
|
-
const signaturePath =
|
|
7818
|
-
if (
|
|
7819
|
-
const outcome = verifySnapshotSignature(
|
|
7875
|
+
const signaturePath = path6__namespace.join(path6__namespace.dirname(manifestPath), "signature.json");
|
|
7876
|
+
if (fs8__namespace.existsSync(signaturePath)) {
|
|
7877
|
+
const outcome = verifySnapshotSignature(path6__namespace.dirname(manifestPath));
|
|
7820
7878
|
if (!outcome.ok) errors.push("signature: " + outcome.reason + ".");
|
|
7821
7879
|
}
|
|
7822
7880
|
if (manifest.slice !== void 0 || manifest.budget !== void 0) {
|
|
@@ -8218,18 +8276,18 @@ var ARTIFACT_FILES = {
|
|
|
8218
8276
|
};
|
|
8219
8277
|
var TEXT_ARTIFACT = /\.(md|json|txt|sarif)$/i;
|
|
8220
8278
|
function sha256(buffer) {
|
|
8221
|
-
return
|
|
8279
|
+
return crypto5.createHash("sha256").update(buffer).digest("hex");
|
|
8222
8280
|
}
|
|
8223
8281
|
function readBytes(file) {
|
|
8224
8282
|
try {
|
|
8225
|
-
return
|
|
8283
|
+
return fs8__namespace.readFileSync(file);
|
|
8226
8284
|
} catch {
|
|
8227
8285
|
return null;
|
|
8228
8286
|
}
|
|
8229
8287
|
}
|
|
8230
8288
|
function readText(file) {
|
|
8231
8289
|
try {
|
|
8232
|
-
return
|
|
8290
|
+
return fs8__namespace.readFileSync(file, "utf8");
|
|
8233
8291
|
} catch {
|
|
8234
8292
|
return null;
|
|
8235
8293
|
}
|
|
@@ -8246,14 +8304,14 @@ function readJson(file) {
|
|
|
8246
8304
|
function walk(dir, prefix = "") {
|
|
8247
8305
|
let entries;
|
|
8248
8306
|
try {
|
|
8249
|
-
entries =
|
|
8307
|
+
entries = fs8__namespace.readdirSync(dir, { withFileTypes: true });
|
|
8250
8308
|
} catch {
|
|
8251
8309
|
return [];
|
|
8252
8310
|
}
|
|
8253
8311
|
const files = [];
|
|
8254
8312
|
for (const entry of entries) {
|
|
8255
8313
|
const relative9 = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
8256
|
-
if (entry.isDirectory()) files.push(...walk(
|
|
8314
|
+
if (entry.isDirectory()) files.push(...walk(path6__namespace.join(dir, entry.name), relative9));
|
|
8257
8315
|
else if (entry.isFile()) files.push(relative9);
|
|
8258
8316
|
}
|
|
8259
8317
|
return files;
|
|
@@ -8296,7 +8354,7 @@ function readArtifactTexts(snapshotDir) {
|
|
|
8296
8354
|
const texts = [];
|
|
8297
8355
|
for (const relative9 of walk(snapshotDir)) {
|
|
8298
8356
|
if (!TEXT_ARTIFACT.test(relative9)) continue;
|
|
8299
|
-
const text = readText(
|
|
8357
|
+
const text = readText(path6__namespace.join(snapshotDir, relative9));
|
|
8300
8358
|
if (text !== null) texts.push(text);
|
|
8301
8359
|
}
|
|
8302
8360
|
return texts;
|
|
@@ -8314,7 +8372,7 @@ function findHostPaths(snapshotDir, repoDir) {
|
|
|
8314
8372
|
const hits = /* @__PURE__ */ new Set();
|
|
8315
8373
|
for (const relative9 of walk(snapshotDir)) {
|
|
8316
8374
|
if (!TEXT_ARTIFACT.test(relative9)) continue;
|
|
8317
|
-
const text = readText(
|
|
8375
|
+
const text = readText(path6__namespace.join(snapshotDir, relative9));
|
|
8318
8376
|
if (text === null) continue;
|
|
8319
8377
|
for (const pattern of patterns) {
|
|
8320
8378
|
for (const match of text.match(pattern) ?? []) hits.add(relative9 + ": " + match);
|
|
@@ -8470,10 +8528,10 @@ function markdownPackBodies(text) {
|
|
|
8470
8528
|
return bodies.size === 0 ? null : bodies;
|
|
8471
8529
|
}
|
|
8472
8530
|
function auditSnapshot(options) {
|
|
8473
|
-
const snapshotDir =
|
|
8474
|
-
const repoDir =
|
|
8531
|
+
const snapshotDir = path6__namespace.resolve(options.snapshotDir);
|
|
8532
|
+
const repoDir = path6__namespace.resolve(options.repoDir);
|
|
8475
8533
|
const checks = [];
|
|
8476
|
-
const manifestFile =
|
|
8534
|
+
const manifestFile = path6__namespace.join(snapshotDir, "manifest.json");
|
|
8477
8535
|
const raw = readJson(manifestFile);
|
|
8478
8536
|
const problem = raw === null ? "the file is missing or is not valid JSON" : describeManifestShapeProblem(raw);
|
|
8479
8537
|
if (raw === null || problem !== null) {
|
|
@@ -8502,7 +8560,7 @@ function auditSnapshot(options) {
|
|
|
8502
8560
|
const missingParts = [];
|
|
8503
8561
|
const mismatched = [];
|
|
8504
8562
|
for (const part of manifest.parts) {
|
|
8505
|
-
const bytes = readBytes(
|
|
8563
|
+
const bytes = readBytes(path6__namespace.join(snapshotDir, "parts", part.filename));
|
|
8506
8564
|
if (bytes === null) {
|
|
8507
8565
|
missingParts.push(part.filename);
|
|
8508
8566
|
continue;
|
|
@@ -8570,7 +8628,7 @@ function auditSnapshot(options) {
|
|
|
8570
8628
|
const relative9 = ARTIFACT_FILES[key];
|
|
8571
8629
|
if (relative9 === void 0) continue;
|
|
8572
8630
|
artifactCount += 1;
|
|
8573
|
-
const bytes = readBytes(
|
|
8631
|
+
const bytes = readBytes(path6__namespace.join(snapshotDir, relative9));
|
|
8574
8632
|
if (bytes === null) artifactProblems.push(relative9 + " is missing");
|
|
8575
8633
|
else if (typeof value.sha256 === "string" && sha256(bytes) !== value.sha256) {
|
|
8576
8634
|
artifactProblems.push(relative9 + " changed");
|
|
@@ -8617,8 +8675,8 @@ function auditSnapshot(options) {
|
|
|
8617
8675
|
unexpected.length + " unexpected path(s): " + sample(unexpected)
|
|
8618
8676
|
)
|
|
8619
8677
|
);
|
|
8620
|
-
const signaturePath =
|
|
8621
|
-
if (
|
|
8678
|
+
const signaturePath = path6__namespace.join(snapshotDir, "signature.json");
|
|
8679
|
+
if (fs8__namespace.existsSync(signaturePath)) {
|
|
8622
8680
|
const outcome = verifySnapshotSignature(snapshotDir);
|
|
8623
8681
|
checks.push(
|
|
8624
8682
|
outcome.ok ? check(
|
|
@@ -8683,7 +8741,7 @@ function auditSnapshot(options) {
|
|
|
8683
8741
|
manifest.files.map((file) => [anchorForPath(file.relativePath), file.relativePath])
|
|
8684
8742
|
);
|
|
8685
8743
|
for (const part of manifest.parts) {
|
|
8686
|
-
const partText = readText(
|
|
8744
|
+
const partText = readText(path6__namespace.join(snapshotDir, "parts", part.filename));
|
|
8687
8745
|
if (partText === null) continue;
|
|
8688
8746
|
const sections = parsePartSections(partText);
|
|
8689
8747
|
partTexts.set(part.filename, partText);
|
|
@@ -8750,7 +8808,7 @@ function auditSnapshot(options) {
|
|
|
8750
8808
|
}
|
|
8751
8809
|
};
|
|
8752
8810
|
if (manifest.artifacts?.readme != null) {
|
|
8753
|
-
const text = readText(
|
|
8811
|
+
const text = readText(path6__namespace.join(snapshotDir, "README.md"));
|
|
8754
8812
|
if (text === null) {
|
|
8755
8813
|
reportProblems.push("README.md is recorded but unreadable");
|
|
8756
8814
|
} else {
|
|
@@ -8790,7 +8848,7 @@ function auditSnapshot(options) {
|
|
|
8790
8848
|
}
|
|
8791
8849
|
}
|
|
8792
8850
|
if (manifest.artifacts?.prompt != null) {
|
|
8793
|
-
const text = readText(
|
|
8851
|
+
const text = readText(path6__namespace.join(snapshotDir, "PROMPT.md"));
|
|
8794
8852
|
if (text === null) {
|
|
8795
8853
|
reportProblems.push("PROMPT.md is recorded but unreadable");
|
|
8796
8854
|
} else {
|
|
@@ -8979,7 +9037,7 @@ function auditSnapshot(options) {
|
|
|
8979
9037
|
];
|
|
8980
9038
|
for (const reader of packReaders) {
|
|
8981
9039
|
if (manifest.artifacts?.[reader.key] == null) continue;
|
|
8982
|
-
const packText = readText(
|
|
9040
|
+
const packText = readText(path6__namespace.join(snapshotDir, reader.file));
|
|
8983
9041
|
const problems = [];
|
|
8984
9042
|
if (packText === null) {
|
|
8985
9043
|
problems.push(reader.file + " is recorded but unreadable");
|
|
@@ -9142,7 +9200,7 @@ function auditSnapshot(options) {
|
|
|
9142
9200
|
let packBodies = 0;
|
|
9143
9201
|
let packSkipped = 0;
|
|
9144
9202
|
for (const pack of packsWanted) {
|
|
9145
|
-
const text = readText(
|
|
9203
|
+
const text = readText(path6__namespace.join(snapshotDir, pack.file));
|
|
9146
9204
|
if (text === null) continue;
|
|
9147
9205
|
const bodies = pack.read(text);
|
|
9148
9206
|
if (bodies === null) {
|
|
@@ -9206,7 +9264,7 @@ function auditSnapshot(options) {
|
|
|
9206
9264
|
unreplayable += 1;
|
|
9207
9265
|
continue;
|
|
9208
9266
|
}
|
|
9209
|
-
const bytes = readBytes(
|
|
9267
|
+
const bytes = readBytes(path6__namespace.join(repoDir, file.relativePath));
|
|
9210
9268
|
if (bytes === null || sha256(bytes) !== file.hashSha256) {
|
|
9211
9269
|
unreplayable += 1;
|
|
9212
9270
|
continue;
|
|
@@ -9244,9 +9302,9 @@ function auditSnapshot(options) {
|
|
|
9244
9302
|
)
|
|
9245
9303
|
);
|
|
9246
9304
|
}
|
|
9247
|
-
const indexParent =
|
|
9248
|
-
const indexPath =
|
|
9249
|
-
if (
|
|
9305
|
+
const indexParent = path6__namespace.dirname(snapshotDir);
|
|
9306
|
+
const indexPath = path6__namespace.join(indexParent, "WORKSPACE.json");
|
|
9307
|
+
if (fs8__namespace.existsSync(indexPath)) {
|
|
9250
9308
|
const indexText = readText(indexPath);
|
|
9251
9309
|
let members = [];
|
|
9252
9310
|
let problem2 = null;
|
|
@@ -9257,7 +9315,7 @@ function auditSnapshot(options) {
|
|
|
9257
9315
|
} catch (error) {
|
|
9258
9316
|
problem2 = error.message;
|
|
9259
9317
|
}
|
|
9260
|
-
const memberName =
|
|
9318
|
+
const memberName = path6__namespace.basename(snapshotDir);
|
|
9261
9319
|
const member = members.find((entry) => entry.name === memberName);
|
|
9262
9320
|
if (problem2 !== null) {
|
|
9263
9321
|
checks.push(check(
|
|
@@ -9281,7 +9339,7 @@ function auditSnapshot(options) {
|
|
|
9281
9339
|
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
9282
9340
|
disagreements.push("file count");
|
|
9283
9341
|
}
|
|
9284
|
-
const sourceGone = typeof member.path === "string" && !
|
|
9342
|
+
const sourceGone = typeof member.path === "string" && !fs8__namespace.existsSync(member.path) ? "Member " + memberName + " source directory is gone (" + member.path + "); the snapshot still describes it. Regenerate the workspace." : null;
|
|
9285
9343
|
checks.push(
|
|
9286
9344
|
sourceGone !== null ? check("workspace.index", "The workspace index agrees with this member", "warning", "warn", sourceGone) : disagreements.length === 0 ? check(
|
|
9287
9345
|
"workspace.index",
|
|
@@ -9306,7 +9364,7 @@ function auditSnapshot(options) {
|
|
|
9306
9364
|
for (const relative9 of walk(snapshotDir)) {
|
|
9307
9365
|
if (!TEXT_ARTIFACT.test(relative9) || scannedBytes > scanBudget) continue;
|
|
9308
9366
|
if (relative9 === SIGNATURE_FILE) continue;
|
|
9309
|
-
const text = readText(
|
|
9367
|
+
const text = readText(path6__namespace.join(snapshotDir, relative9));
|
|
9310
9368
|
if (text === null) continue;
|
|
9311
9369
|
scannedBytes += Buffer.byteLength(text, "utf8");
|
|
9312
9370
|
let findingCount = 0;
|
|
@@ -9324,8 +9382,8 @@ function auditSnapshot(options) {
|
|
|
9324
9382
|
leakHits.push(relative9 + " (" + findingCount + " line(s))");
|
|
9325
9383
|
}
|
|
9326
9384
|
}
|
|
9327
|
-
const signatureRecordPath =
|
|
9328
|
-
if (
|
|
9385
|
+
const signatureRecordPath = path6__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
9386
|
+
if (fs8__namespace.existsSync(signatureRecordPath)) {
|
|
9329
9387
|
const recordText = readText(signatureRecordPath);
|
|
9330
9388
|
if (recordText !== null) {
|
|
9331
9389
|
scannedBytes += Buffer.byteLength(recordText, "utf8");
|
|
@@ -9370,7 +9428,7 @@ function auditSnapshot(options) {
|
|
|
9370
9428
|
const artifactContains = (token) => artifactTexts.some((text) => text.includes(token));
|
|
9371
9429
|
for (const record of skippedSensitive.slice(0, 40)) {
|
|
9372
9430
|
if (record.path.includes("[REDACTED") || compared > 400) continue;
|
|
9373
|
-
const text = readText(
|
|
9431
|
+
const text = readText(path6__namespace.join(repoDir, record.path));
|
|
9374
9432
|
if (text === null) continue;
|
|
9375
9433
|
for (const token of secretTokens(text)) {
|
|
9376
9434
|
compared += 1;
|
|
@@ -9522,13 +9580,13 @@ function describeMatcher(matcher) {
|
|
|
9522
9580
|
return String(matcher);
|
|
9523
9581
|
}
|
|
9524
9582
|
function normalizeTarget(cwd, target) {
|
|
9525
|
-
const resolvedCwd =
|
|
9526
|
-
const absolute =
|
|
9527
|
-
const relative9 =
|
|
9528
|
-
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${
|
|
9583
|
+
const resolvedCwd = path6__namespace.resolve(cwd);
|
|
9584
|
+
const absolute = path6__namespace.resolve(resolvedCwd, target);
|
|
9585
|
+
const relative9 = path6__namespace.relative(resolvedCwd, absolute);
|
|
9586
|
+
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative9)) {
|
|
9529
9587
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
9530
9588
|
}
|
|
9531
|
-
return { relative: relative9.split(
|
|
9589
|
+
return { relative: relative9.split(path6__namespace.sep).join("/"), outsideRoot: false };
|
|
9532
9590
|
}
|
|
9533
9591
|
function findRuleMatch(rules, relativePath) {
|
|
9534
9592
|
return rules.find(
|
|
@@ -9547,9 +9605,9 @@ function findRecordedAncestor(skipped, relative9, maskedPath2) {
|
|
|
9547
9605
|
return nearest;
|
|
9548
9606
|
}
|
|
9549
9607
|
function readManifest2(config) {
|
|
9550
|
-
const manifestPath =
|
|
9608
|
+
const manifestPath = path6__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
9551
9609
|
try {
|
|
9552
|
-
return JSON.parse(
|
|
9610
|
+
return JSON.parse(fs8__namespace.readFileSync(manifestPath, "utf8"));
|
|
9553
9611
|
} catch {
|
|
9554
9612
|
return null;
|
|
9555
9613
|
}
|
|
@@ -9567,10 +9625,10 @@ function explainPath(config, target) {
|
|
|
9567
9625
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
9568
9626
|
};
|
|
9569
9627
|
}
|
|
9570
|
-
const absolute =
|
|
9628
|
+
const absolute = path6__namespace.join(config.cwd, relative9);
|
|
9571
9629
|
const result = {
|
|
9572
9630
|
path: maskedPath2,
|
|
9573
|
-
exists:
|
|
9631
|
+
exists: fs8__namespace.existsSync(absolute),
|
|
9574
9632
|
included: false
|
|
9575
9633
|
};
|
|
9576
9634
|
const collection = collectFiles(config.cwd, {
|
|
@@ -9584,7 +9642,7 @@ function explainPath(config, target) {
|
|
|
9584
9642
|
// Same exclusion `generate` applies, so `explain` never says "not-discovered" about a file
|
|
9585
9643
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
9586
9644
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
9587
|
-
(directory) =>
|
|
9645
|
+
(directory) => path6__namespace.relative(config.cwd, path6__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
9588
9646
|
).filter((relative10) => relative10.length > 0 && !relative10.startsWith(".."))
|
|
9589
9647
|
});
|
|
9590
9648
|
if (!collection.files.includes(relative9)) {
|
|
@@ -9624,7 +9682,9 @@ function explainPath(config, target) {
|
|
|
9624
9682
|
relative9,
|
|
9625
9683
|
importsOfFile(relative9, absolute),
|
|
9626
9684
|
scope.paths,
|
|
9627
|
-
buildImportResolver(collection.files.map((file) => ({ relativePath: file }))
|
|
9685
|
+
buildImportResolver(collection.files.map((file) => ({ relativePath: file })), {
|
|
9686
|
+
tsconfig: tsconfigPathsFor(config.cwd)
|
|
9687
|
+
})
|
|
9628
9688
|
);
|
|
9629
9689
|
}
|
|
9630
9690
|
scopeDetail = scope.detail;
|
|
@@ -9649,7 +9709,7 @@ function explainPath(config, target) {
|
|
|
9649
9709
|
}
|
|
9650
9710
|
let sizeOnDisk = null;
|
|
9651
9711
|
try {
|
|
9652
|
-
sizeOnDisk =
|
|
9712
|
+
sizeOnDisk = fs8__namespace.statSync(absolute).size;
|
|
9653
9713
|
} catch {
|
|
9654
9714
|
sizeOnDisk = null;
|
|
9655
9715
|
}
|
|
@@ -9659,10 +9719,10 @@ function explainPath(config, target) {
|
|
|
9659
9719
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
9660
9720
|
return result;
|
|
9661
9721
|
}
|
|
9662
|
-
if (
|
|
9722
|
+
if (fs8__namespace.existsSync(absolute) && fs8__namespace.statSync(absolute).isFile()) {
|
|
9663
9723
|
let buffer;
|
|
9664
9724
|
try {
|
|
9665
|
-
buffer =
|
|
9725
|
+
buffer = fs8__namespace.readFileSync(absolute);
|
|
9666
9726
|
} catch (err) {
|
|
9667
9727
|
result.included = false;
|
|
9668
9728
|
result.reason = "read-error";
|
|
@@ -9752,7 +9812,7 @@ function renderExplainText(result) {
|
|
|
9752
9812
|
return lines.join("\n");
|
|
9753
9813
|
}
|
|
9754
9814
|
function workerEntry(directory, isCjs) {
|
|
9755
|
-
const entry =
|
|
9815
|
+
const entry = path6__namespace.join(directory, isCjs ? "index.cjs" : "index.js");
|
|
9756
9816
|
return { path: entry, url: url.pathToFileURL(entry).href };
|
|
9757
9817
|
}
|
|
9758
9818
|
var WORKER_SOURCE = `
|
|
@@ -9773,6 +9833,7 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
9773
9833
|
const manifest = mod.generateSnapshot(config, {
|
|
9774
9834
|
dryRun: workerData.dryRun === true,
|
|
9775
9835
|
...(workerData.narrow ?? {}),
|
|
9836
|
+
...(workerData.runId === undefined ? {} : { runId: workerData.runId }),
|
|
9776
9837
|
});
|
|
9777
9838
|
const skipCounts = new Map();
|
|
9778
9839
|
for (const record of manifest.skipped) {
|
|
@@ -9818,11 +9879,16 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
9818
9879
|
const finish = (result) => {
|
|
9819
9880
|
if (settled) return;
|
|
9820
9881
|
settled = true;
|
|
9821
|
-
|
|
9822
|
-
|
|
9882
|
+
const terminated = worker === null ? Promise.resolve(void 0) : worker.terminate();
|
|
9883
|
+
void terminated.catch(() => void 0).then(() => {
|
|
9884
|
+
if (!result.ok && options.runId !== void 0 && options.lockRoots !== void 0) {
|
|
9885
|
+
releaseAbandonedRun(options.lockRoots, options.runId);
|
|
9886
|
+
}
|
|
9887
|
+
resolve10(result);
|
|
9888
|
+
});
|
|
9823
9889
|
};
|
|
9824
9890
|
const isCjs = typeof __dirname !== "undefined";
|
|
9825
|
-
const directory = isCjs ? __dirname :
|
|
9891
|
+
const directory = isCjs ? __dirname : path6__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('mcp.cjs', document.baseURI).href))));
|
|
9826
9892
|
try {
|
|
9827
9893
|
worker = new worker_threads.Worker(WORKER_SOURCE, {
|
|
9828
9894
|
eval: true,
|
|
@@ -9831,7 +9897,8 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
9831
9897
|
cwd,
|
|
9832
9898
|
cliOptions,
|
|
9833
9899
|
dryRun: options.dryRun === true,
|
|
9834
|
-
narrow: options.narrow ?? {}
|
|
9900
|
+
narrow: options.narrow ?? {},
|
|
9901
|
+
...options.runId === void 0 ? {} : { runId: options.runId }
|
|
9835
9902
|
}
|
|
9836
9903
|
});
|
|
9837
9904
|
} catch (error) {
|
|
@@ -9887,9 +9954,9 @@ function foldForComparison(value) {
|
|
|
9887
9954
|
return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
9888
9955
|
}
|
|
9889
9956
|
function canonicalPath(value) {
|
|
9890
|
-
const absolute =
|
|
9957
|
+
const absolute = path6__namespace.resolve(value);
|
|
9891
9958
|
try {
|
|
9892
|
-
return
|
|
9959
|
+
return fs8__namespace.realpathSync(absolute);
|
|
9893
9960
|
} catch {
|
|
9894
9961
|
return absolute;
|
|
9895
9962
|
}
|
|
@@ -9897,29 +9964,29 @@ function canonicalPath(value) {
|
|
|
9897
9964
|
function isInside2(parent, child) {
|
|
9898
9965
|
const foldedParent = foldForComparison(parent);
|
|
9899
9966
|
const foldedChild = foldForComparison(child);
|
|
9900
|
-
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${
|
|
9967
|
+
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path6__namespace.sep}`);
|
|
9901
9968
|
}
|
|
9902
9969
|
function resolveThroughExistingAncestor(target) {
|
|
9903
9970
|
let existing = target;
|
|
9904
9971
|
const missing = [];
|
|
9905
|
-
while (!
|
|
9906
|
-
missing.unshift(
|
|
9907
|
-
const parent =
|
|
9972
|
+
while (!fs8__namespace.existsSync(existing)) {
|
|
9973
|
+
missing.unshift(path6__namespace.basename(existing));
|
|
9974
|
+
const parent = path6__namespace.dirname(existing);
|
|
9908
9975
|
if (parent === existing) break;
|
|
9909
9976
|
existing = parent;
|
|
9910
9977
|
}
|
|
9911
9978
|
const resolved = canonicalPath(existing);
|
|
9912
|
-
return missing.length === 0 ? resolved :
|
|
9979
|
+
return missing.length === 0 ? resolved : path6__namespace.join(resolved, ...missing);
|
|
9913
9980
|
}
|
|
9914
9981
|
function resolveRoot(requested, context) {
|
|
9915
9982
|
if (requested !== void 0 && (typeof requested !== "string" || requested.trim().length === 0)) {
|
|
9916
9983
|
return { ok: false, message: '"root" must be a non-empty string when provided.' };
|
|
9917
9984
|
}
|
|
9918
9985
|
const wanted = typeof requested === "string" ? requested.trim() : context.cwd;
|
|
9919
|
-
const absolute =
|
|
9986
|
+
const absolute = path6__namespace.resolve(context.cwd, wanted);
|
|
9920
9987
|
let stats;
|
|
9921
9988
|
try {
|
|
9922
|
-
stats =
|
|
9989
|
+
stats = fs8__namespace.statSync(absolute);
|
|
9923
9990
|
} catch {
|
|
9924
9991
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
9925
9992
|
}
|
|
@@ -9971,7 +10038,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
9971
10038
|
}
|
|
9972
10039
|
const requested = overrides.outDir.trim();
|
|
9973
10040
|
const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
|
|
9974
|
-
const resolved = resolveThroughExistingAncestor(
|
|
10041
|
+
const resolved = resolveThroughExistingAncestor(path6__namespace.resolve(root, requested));
|
|
9975
10042
|
if (!permitted.some((allowed) => isInside2(canonicalPath(allowed), resolved))) {
|
|
9976
10043
|
const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
|
|
9977
10044
|
return {
|
|
@@ -9996,7 +10063,16 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
9996
10063
|
if (overrides.withDependents === true) cliOptions.withDependents = true;
|
|
9997
10064
|
try {
|
|
9998
10065
|
const config = resolveConfig(loaded.config, cliOptions, root);
|
|
9999
|
-
return {
|
|
10066
|
+
return {
|
|
10067
|
+
ok: true,
|
|
10068
|
+
workspace: {
|
|
10069
|
+
root,
|
|
10070
|
+
config,
|
|
10071
|
+
configFile: loaded.file,
|
|
10072
|
+
sourceConfig: loaded.config ?? null,
|
|
10073
|
+
cliOptions
|
|
10074
|
+
}
|
|
10075
|
+
};
|
|
10000
10076
|
} catch (error) {
|
|
10001
10077
|
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
10002
10078
|
}
|
|
@@ -10004,25 +10080,25 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
10004
10080
|
var MANIFEST_CACHE_LIMIT = 8;
|
|
10005
10081
|
var manifestCache = /* @__PURE__ */ new Map();
|
|
10006
10082
|
function manifestPathFor(workspace) {
|
|
10007
|
-
return
|
|
10083
|
+
return path6__namespace.resolve(workspace.root, workspace.config.outDir, "manifest.json");
|
|
10008
10084
|
}
|
|
10009
10085
|
function partPathFor(workspace, filename) {
|
|
10010
10086
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
10011
|
-
const partsDir =
|
|
10012
|
-
const resolved =
|
|
10013
|
-
const relative9 =
|
|
10014
|
-
if (relative9.length === 0 || relative9.includes(
|
|
10087
|
+
const partsDir = path6__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
10088
|
+
const resolved = path6__namespace.resolve(partsDir, filename);
|
|
10089
|
+
const relative9 = path6__namespace.relative(partsDir, resolved);
|
|
10090
|
+
if (relative9.length === 0 || relative9.includes(path6__namespace.sep) || relative9.includes("/") || relative9.includes("\\") || path6__namespace.isAbsolute(relative9)) {
|
|
10015
10091
|
return null;
|
|
10016
10092
|
}
|
|
10017
10093
|
let stats;
|
|
10018
10094
|
try {
|
|
10019
|
-
stats =
|
|
10095
|
+
stats = fs8__namespace.lstatSync(resolved);
|
|
10020
10096
|
} catch {
|
|
10021
10097
|
return null;
|
|
10022
10098
|
}
|
|
10023
10099
|
if (!stats.isFile()) return null;
|
|
10024
10100
|
try {
|
|
10025
|
-
if (
|
|
10101
|
+
if (path6__namespace.dirname(fs8__namespace.realpathSync(resolved)) !== fs8__namespace.realpathSync(partsDir)) return null;
|
|
10026
10102
|
} catch {
|
|
10027
10103
|
return null;
|
|
10028
10104
|
}
|
|
@@ -10030,10 +10106,10 @@ function partPathFor(workspace, filename) {
|
|
|
10030
10106
|
}
|
|
10031
10107
|
function readManifest3(workspace) {
|
|
10032
10108
|
const file = manifestPathFor(workspace);
|
|
10033
|
-
const shown =
|
|
10109
|
+
const shown = path6__namespace.relative(workspace.root, file).split(path6__namespace.sep).join("/") || file;
|
|
10034
10110
|
let stats;
|
|
10035
10111
|
try {
|
|
10036
|
-
stats =
|
|
10112
|
+
stats = fs8__namespace.statSync(file);
|
|
10037
10113
|
} catch {
|
|
10038
10114
|
return {
|
|
10039
10115
|
ok: false,
|
|
@@ -10047,7 +10123,7 @@ function readManifest3(workspace) {
|
|
|
10047
10123
|
}
|
|
10048
10124
|
let raw;
|
|
10049
10125
|
try {
|
|
10050
|
-
raw =
|
|
10126
|
+
raw = fs8__namespace.readFileSync(file, "utf8");
|
|
10051
10127
|
} catch (error) {
|
|
10052
10128
|
return {
|
|
10053
10129
|
ok: false,
|
|
@@ -10164,7 +10240,7 @@ function formatBytes2(bytes) {
|
|
|
10164
10240
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
10165
10241
|
}
|
|
10166
10242
|
function relativeFor(workspace, absolute) {
|
|
10167
|
-
return
|
|
10243
|
+
return path6__namespace.relative(workspace.root, absolute).split(path6__namespace.sep).join("/");
|
|
10168
10244
|
}
|
|
10169
10245
|
function capped(values, limit = 20) {
|
|
10170
10246
|
return { count: values.length, sample: values.slice(0, limit) };
|
|
@@ -10183,13 +10259,13 @@ function summarizeDrift(drift) {
|
|
|
10183
10259
|
function toRelativePath(root, value) {
|
|
10184
10260
|
const cleaned = value.trim();
|
|
10185
10261
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
10186
|
-
const resolvedRoot =
|
|
10187
|
-
const absolute =
|
|
10188
|
-
const relative9 =
|
|
10189
|
-
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${
|
|
10262
|
+
const resolvedRoot = path6__namespace.resolve(root);
|
|
10263
|
+
const absolute = path6__namespace.resolve(resolvedRoot, cleaned);
|
|
10264
|
+
const relative9 = path6__namespace.relative(resolvedRoot, absolute);
|
|
10265
|
+
if (relative9 === "" || relative9 === ".." || relative9.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative9)) {
|
|
10190
10266
|
return null;
|
|
10191
10267
|
}
|
|
10192
|
-
return relative9.split(
|
|
10268
|
+
return relative9.split(path6__namespace.sep).join("/");
|
|
10193
10269
|
}
|
|
10194
10270
|
function symbolsOf(entry) {
|
|
10195
10271
|
const summary = entry.summary;
|
|
@@ -10282,10 +10358,10 @@ var historyTool = {
|
|
|
10282
10358
|
async handler(args, context) {
|
|
10283
10359
|
const prepared = await prepare(args, context, outDirOverride(args));
|
|
10284
10360
|
if (!prepared.ok) return prepared.outcome;
|
|
10285
|
-
const reportPath =
|
|
10361
|
+
const reportPath = path6__namespace.resolve(prepared.workspace.root, prepared.workspace.config.outDir, "reports", "log.md");
|
|
10286
10362
|
let text;
|
|
10287
10363
|
try {
|
|
10288
|
-
text =
|
|
10364
|
+
text = fs8__namespace.readFileSync(reportPath, "utf8");
|
|
10289
10365
|
} catch {
|
|
10290
10366
|
return {
|
|
10291
10367
|
text: "This snapshot has no reports/log.md. Generate it with `snapshot_generate { includeLogs: 20 }`, or `generate --include-logs 20` on the command line; the report is opt-in because the commit subjects are repository content.",
|
|
@@ -10295,7 +10371,7 @@ var historyTool = {
|
|
|
10295
10371
|
const manifestRead = readManifest3(prepared.workspace);
|
|
10296
10372
|
const recordedLog = manifestRead.ok ? manifestRead.manifest.artifacts?.log : void 0;
|
|
10297
10373
|
if (recordedLog !== void 0 && recordedLog !== null) {
|
|
10298
|
-
const digest =
|
|
10374
|
+
const digest = crypto5.createHash("sha256").update(text, "utf8").digest("hex");
|
|
10299
10375
|
if (digest !== recordedLog.sha256) {
|
|
10300
10376
|
return {
|
|
10301
10377
|
text: "reports/log.md changed after the snapshot was generated (its digest no longer matches the manifest). Regenerate the snapshot rather than trusting this history.",
|
|
@@ -10403,7 +10479,9 @@ var testsTool = {
|
|
|
10403
10479
|
const cap = Math.max(1, typeof args.maxFiles === "number" ? args.maxFiles : 50);
|
|
10404
10480
|
const isTest2 = (filePath) => /(^|\/)(tests?|__tests__|spec)\//.test(filePath) || /\.(test|spec)\.[a-z0-9]+$/i.test(filePath);
|
|
10405
10481
|
const byPath = new Map(read.manifest.files.map((file) => [file.relativePath, file]));
|
|
10406
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
10482
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
10483
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
10484
|
+
});
|
|
10407
10485
|
const testFiles = read.manifest.files.filter((file) => isTest2(file.relativePath));
|
|
10408
10486
|
const importsOf = (filePath) => {
|
|
10409
10487
|
const entry = read.manifest.indexes.imports.byFile.find((candidate) => candidate.path === filePath);
|
|
@@ -10451,12 +10529,16 @@ var workspaceTool = {
|
|
|
10451
10529
|
},
|
|
10452
10530
|
annotations: READ_ONLY,
|
|
10453
10531
|
async handler(args, context) {
|
|
10454
|
-
const
|
|
10455
|
-
|
|
10456
|
-
const index =
|
|
10532
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
10533
|
+
if (!prepared.ok) return prepared.outcome;
|
|
10534
|
+
const index = path6__namespace.resolve(
|
|
10535
|
+
prepared.workspace.root,
|
|
10536
|
+
prepared.workspace.config.outDir,
|
|
10537
|
+
"WORKSPACE.json"
|
|
10538
|
+
);
|
|
10457
10539
|
let text;
|
|
10458
10540
|
try {
|
|
10459
|
-
text =
|
|
10541
|
+
text = fs8__namespace.readFileSync(index, "utf8");
|
|
10460
10542
|
} catch {
|
|
10461
10543
|
return {
|
|
10462
10544
|
text: "No workspace index at " + index + ". Generate one with `generate --workspace member-a,member-b`; a single snapshot has no members to list.",
|
|
@@ -10510,7 +10592,9 @@ var neighborsTool = {
|
|
|
10510
10592
|
const file = read.manifest.files.find((candidate) => candidate.relativePath === wanted) ?? read.manifest.files.find((candidate) => candidate.relativePath.toLowerCase() === wanted.toLowerCase());
|
|
10511
10593
|
if (file === void 0) return { text: wanted + " is not in the snapshot; snapshot_explain says why.", isError: true };
|
|
10512
10594
|
const byPath = new Map(read.manifest.files.map((candidate) => [candidate.relativePath, candidate]));
|
|
10513
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
10595
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
10596
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
10597
|
+
});
|
|
10514
10598
|
const entry = read.manifest.indexes.imports.byFile.find((candidate) => candidate.path === file.relativePath);
|
|
10515
10599
|
const imports = [];
|
|
10516
10600
|
for (const specifier of entry?.imports ?? []) {
|
|
@@ -10652,7 +10736,9 @@ var cyclesTool = {
|
|
|
10652
10736
|
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
10653
10737
|
const cap = Math.max(1, typeof args.maxComponents === "number" ? args.maxComponents : 20);
|
|
10654
10738
|
const byPath = new Map(read.manifest.files.map((file) => [file.relativePath, file]));
|
|
10655
|
-
const resolver = buildImportResolver(read.manifest.files, {
|
|
10739
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
10740
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
10741
|
+
});
|
|
10656
10742
|
const edges = /* @__PURE__ */ new Map();
|
|
10657
10743
|
for (const path16 of byPath.keys()) edges.set(path16, []);
|
|
10658
10744
|
for (const entry of read.manifest.indexes.imports.byFile) {
|
|
@@ -10760,7 +10846,7 @@ var searchTool = {
|
|
|
10760
10846
|
if (partPath === null) continue;
|
|
10761
10847
|
let text;
|
|
10762
10848
|
try {
|
|
10763
|
-
text =
|
|
10849
|
+
text = fs8__namespace.readFileSync(partPath, "utf8");
|
|
10764
10850
|
} catch {
|
|
10765
10851
|
continue;
|
|
10766
10852
|
}
|
|
@@ -10891,7 +10977,7 @@ var reviewTool = {
|
|
|
10891
10977
|
return { text: error.message, isError: true };
|
|
10892
10978
|
}
|
|
10893
10979
|
const report2 = auditSnapshot({
|
|
10894
|
-
snapshotDir:
|
|
10980
|
+
snapshotDir: path6__namespace.resolve(workspace.root, workspace.config.outDir),
|
|
10895
10981
|
repoDir: workspace.root
|
|
10896
10982
|
});
|
|
10897
10983
|
const failed = report2.checks.filter((check2) => check2.status === "fail").map((check2) => check2.id + ": " + check2.detail);
|
|
@@ -10913,7 +10999,7 @@ var reviewTool = {
|
|
|
10913
10999
|
}
|
|
10914
11000
|
let section = null;
|
|
10915
11001
|
try {
|
|
10916
|
-
section = findSection(parsePartSections(
|
|
11002
|
+
section = findSection(parsePartSections(fs8__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
10917
11003
|
} catch {
|
|
10918
11004
|
section = null;
|
|
10919
11005
|
}
|
|
@@ -11016,7 +11102,7 @@ var diffContextTool = {
|
|
|
11016
11102
|
}
|
|
11017
11103
|
let section;
|
|
11018
11104
|
try {
|
|
11019
|
-
section = findSection(parsePartSections(
|
|
11105
|
+
section = findSection(parsePartSections(fs8__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
11020
11106
|
} catch {
|
|
11021
11107
|
section = null;
|
|
11022
11108
|
}
|
|
@@ -11102,7 +11188,7 @@ var symbolTool = {
|
|
|
11102
11188
|
if (partPath === null) continue;
|
|
11103
11189
|
let partText;
|
|
11104
11190
|
try {
|
|
11105
|
-
partText =
|
|
11191
|
+
partText = fs8__namespace.readFileSync(partPath, "utf8");
|
|
11106
11192
|
} catch {
|
|
11107
11193
|
continue;
|
|
11108
11194
|
}
|
|
@@ -11147,7 +11233,7 @@ var symbolTool = {
|
|
|
11147
11233
|
let partText = parts.get(partPath);
|
|
11148
11234
|
if (partText === void 0) {
|
|
11149
11235
|
try {
|
|
11150
|
-
partText =
|
|
11236
|
+
partText = fs8__namespace.readFileSync(partPath, "utf8");
|
|
11151
11237
|
} catch {
|
|
11152
11238
|
continue;
|
|
11153
11239
|
}
|
|
@@ -11243,7 +11329,7 @@ var contextTool = {
|
|
|
11243
11329
|
}
|
|
11244
11330
|
if (!sectionsByPart.has(file.part)) {
|
|
11245
11331
|
try {
|
|
11246
|
-
sectionsByPart.set(file.part, parsePartSections(
|
|
11332
|
+
sectionsByPart.set(file.part, parsePartSections(fs8__namespace.readFileSync(partPath, "utf8")));
|
|
11247
11333
|
} catch {
|
|
11248
11334
|
sectionsByPart.set(file.part, null);
|
|
11249
11335
|
}
|
|
@@ -11477,7 +11563,7 @@ var answerTool = {
|
|
|
11477
11563
|
let partText = parts.get(partPath);
|
|
11478
11564
|
if (partText === void 0) {
|
|
11479
11565
|
try {
|
|
11480
|
-
partText =
|
|
11566
|
+
partText = fs8__namespace.readFileSync(partPath, "utf8");
|
|
11481
11567
|
} catch {
|
|
11482
11568
|
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
11483
11569
|
continue;
|
|
@@ -11574,7 +11660,7 @@ var healthTool = {
|
|
|
11574
11660
|
if (!prepared.ok) return prepared.outcome;
|
|
11575
11661
|
const workspace = prepared.workspace;
|
|
11576
11662
|
const report2 = auditSnapshot({
|
|
11577
|
-
snapshotDir:
|
|
11663
|
+
snapshotDir: path6__namespace.resolve(workspace.root, workspace.config.outDir),
|
|
11578
11664
|
repoDir: workspace.root,
|
|
11579
11665
|
...typeof args.maxScanBytes === "number" ? { maxScanBytes: args.maxScanBytes } : {},
|
|
11580
11666
|
...args.deep === true ? { deep: true } : {}
|
|
@@ -11852,16 +11938,23 @@ var generateTool = {
|
|
|
11852
11938
|
...typeof args.slice === "string" ? { slice: { question: args.slice, ...typeof args.sliceTokens === "number" ? { maxTokens: args.sliceTokens } : {} } } : {},
|
|
11853
11939
|
...typeof args.budgetTokens === "number" ? { budgetTokens: args.budgetTokens } : {}
|
|
11854
11940
|
};
|
|
11941
|
+
let lockRoots;
|
|
11942
|
+
try {
|
|
11943
|
+
const safe = resolveSafeOutputDirs(workspace.config);
|
|
11944
|
+
lockRoots = [safe.outDir, safe.tmpDir];
|
|
11945
|
+
} catch (error) {
|
|
11946
|
+
return failure(error instanceof Error ? error.message : String(error));
|
|
11947
|
+
}
|
|
11855
11948
|
const result = await generateInWorker(
|
|
11856
11949
|
workspace.root,
|
|
11857
11950
|
{ ...workspace.cliOptions, ...reportOptions },
|
|
11858
|
-
{ signal: controller.signal, narrow }
|
|
11951
|
+
{ signal: controller.signal, narrow, runId: crypto5.randomUUID(), lockRoots }
|
|
11859
11952
|
);
|
|
11860
11953
|
if (!result.ok) return failure(result.message);
|
|
11861
11954
|
context.notify?.({ message: "writing the snapshot", progress: 2, total: 2 });
|
|
11862
11955
|
const summary = result.summary;
|
|
11863
11956
|
forgetManifest(manifestPathFor(workspace));
|
|
11864
|
-
const written = relativeFor(workspace,
|
|
11957
|
+
const written = relativeFor(workspace, path6__namespace.resolve(workspace.root, workspace.config.outDir));
|
|
11865
11958
|
const lines = [
|
|
11866
11959
|
`Wrote ${written}/`,
|
|
11867
11960
|
`Files: ${summary.totalFiles} included, ${summary.skippedCount} skipped, ${plural(summary.partsCount, "part")}`,
|
|
@@ -11889,16 +11982,42 @@ var generateTool = {
|
|
|
11889
11982
|
};
|
|
11890
11983
|
function configAsGenerated(workspace, manifest) {
|
|
11891
11984
|
const recorded = manifest.config;
|
|
11985
|
+
const cli = workspace.cliOptions;
|
|
11986
|
+
const source = workspace.sourceConfig;
|
|
11987
|
+
const configured = (key) => source !== null && Object.prototype.hasOwnProperty.call(source, key);
|
|
11988
|
+
const sourceArtifacts = source !== null && source.artifacts !== null && typeof source.artifacts === "object" ? source.artifacts : null;
|
|
11989
|
+
const artifacts = { ...workspace.config.artifacts };
|
|
11990
|
+
if (recorded?.artifacts !== void 0) {
|
|
11991
|
+
for (const [key, value] of Object.entries(recorded.artifacts)) {
|
|
11992
|
+
if (sourceArtifacts === null || !Object.prototype.hasOwnProperty.call(sourceArtifacts, key)) {
|
|
11993
|
+
artifacts[key] = value;
|
|
11994
|
+
}
|
|
11995
|
+
}
|
|
11996
|
+
}
|
|
11997
|
+
let artifactOverride = recorded?.artifacts !== void 0;
|
|
11998
|
+
if (cli.includeDiffs === true) {
|
|
11999
|
+
artifacts.diff = true;
|
|
12000
|
+
artifactOverride = true;
|
|
12001
|
+
}
|
|
12002
|
+
if (cli.includeLogs !== void 0) {
|
|
12003
|
+
artifacts.log = true;
|
|
12004
|
+
artifactOverride = true;
|
|
12005
|
+
}
|
|
12006
|
+
if (cli.tokenTree === true) {
|
|
12007
|
+
artifacts.tokenTree = true;
|
|
12008
|
+
artifactOverride = true;
|
|
12009
|
+
}
|
|
12010
|
+
const choose = (key, recordedValue, current, cliValue) => cliValue !== void 0 ? cliValue : configured(key) ? current : recordedValue ?? current;
|
|
11892
12011
|
return {
|
|
11893
12012
|
...workspace.config,
|
|
11894
|
-
...
|
|
11895
|
-
...recorded?.stripComments
|
|
11896
|
-
...recorded?.removeEmptyLines
|
|
11897
|
-
...recorded?.pack
|
|
11898
|
-
...recorded?.logCount
|
|
11899
|
-
...recorded?.skeleton
|
|
11900
|
-
...recorded?.sarif
|
|
11901
|
-
...recorded?.maxParts
|
|
12013
|
+
...artifactOverride ? { artifacts } : {},
|
|
12014
|
+
...cli.stripComments === true || configured("stripComments") || recorded?.stripComments !== void 0 ? { stripComments: choose("stripComments", recorded?.stripComments, workspace.config.stripComments, cli.stripComments === true ? true : void 0) } : {},
|
|
12015
|
+
...cli.removeEmptyLines === true || configured("removeEmptyLines") || recorded?.removeEmptyLines !== void 0 ? { removeEmptyLines: choose("removeEmptyLines", recorded?.removeEmptyLines, workspace.config.removeEmptyLines, cli.removeEmptyLines === true ? true : void 0) } : {},
|
|
12016
|
+
...cli.pack !== void 0 || configured("pack") || recorded?.pack !== void 0 ? { pack: choose("pack", recorded?.pack ?? void 0, workspace.config.pack, cli.pack) } : {},
|
|
12017
|
+
...cli.includeLogs !== void 0 || configured("logCount") || recorded?.logCount !== void 0 ? { logCount: choose("logCount", recorded?.logCount, workspace.config.logCount, cli.includeLogs) } : {},
|
|
12018
|
+
...cli.skeleton === true || configured("skeleton") || recorded?.skeleton !== void 0 ? { skeleton: choose("skeleton", recorded?.skeleton, workspace.config.skeleton, cli.skeleton === true ? true : void 0) } : {},
|
|
12019
|
+
...cli.sarif === true || configured("sarif") || recorded?.sarif !== void 0 ? { sarif: choose("sarif", recorded?.sarif, workspace.config.sarif, cli.sarif === true ? true : void 0) } : {},
|
|
12020
|
+
...configured("maxParts") || recorded?.maxParts !== void 0 ? { maxParts: choose("maxParts", recorded?.maxParts, workspace.config.maxParts) } : {}
|
|
11902
12021
|
};
|
|
11903
12022
|
}
|
|
11904
12023
|
var validateTool = {
|
|
@@ -12135,7 +12254,9 @@ var dependentsTool = {
|
|
|
12135
12254
|
}
|
|
12136
12255
|
const direction = args.direction === "imports" || args.direction === "imported-by" ? String(args.direction) : "both";
|
|
12137
12256
|
const limit = typeof args.limit === "number" && args.limit > 0 ? Math.floor(args.limit) : 50;
|
|
12138
|
-
const resolver = buildImportResolver(manifest.files
|
|
12257
|
+
const resolver = buildImportResolver(manifest.files, {
|
|
12258
|
+
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
12259
|
+
});
|
|
12139
12260
|
const imports = [];
|
|
12140
12261
|
const unresolved = [];
|
|
12141
12262
|
if (direction !== "imported-by") {
|
|
@@ -12278,7 +12399,7 @@ var readTool = {
|
|
|
12278
12399
|
}
|
|
12279
12400
|
let partText;
|
|
12280
12401
|
try {
|
|
12281
|
-
partText =
|
|
12402
|
+
partText = fs8__namespace.readFileSync(partPath, "utf8");
|
|
12282
12403
|
} catch {
|
|
12283
12404
|
return failure(
|
|
12284
12405
|
`${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
|
|
@@ -12598,6 +12719,171 @@ async function runStdioServer(options) {
|
|
|
12598
12719
|
await writeChain;
|
|
12599
12720
|
return code;
|
|
12600
12721
|
}
|
|
12722
|
+
function sha256Hex2(input) {
|
|
12723
|
+
return crypto5__namespace.createHash("sha256").update(input).digest("hex");
|
|
12724
|
+
}
|
|
12725
|
+
function resolveSafeOutputDirs(config) {
|
|
12726
|
+
const cwd = path6__namespace.resolve(config.cwd);
|
|
12727
|
+
const outDir = path6__namespace.resolve(cwd, config.outDir);
|
|
12728
|
+
const tmpDir = path6__namespace.resolve(cwd, config.tmpDir);
|
|
12729
|
+
const root = path6__namespace.parse(cwd).root;
|
|
12730
|
+
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path6__namespace.sep}`);
|
|
12731
|
+
const reject = (reason) => {
|
|
12732
|
+
throw new Error(
|
|
12733
|
+
`Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
|
|
12734
|
+
);
|
|
12735
|
+
};
|
|
12736
|
+
if (outDir === root) reject("outDir resolves to the filesystem root");
|
|
12737
|
+
if (outDir === cwd || contains(outDir, cwd)) {
|
|
12738
|
+
reject("outDir is the working directory or one of its ancestors");
|
|
12739
|
+
}
|
|
12740
|
+
if (tmpDir === root) reject("tmpDir resolves to the filesystem root");
|
|
12741
|
+
if (tmpDir === cwd || contains(tmpDir, cwd)) {
|
|
12742
|
+
reject("tmpDir is the working directory or one of its ancestors");
|
|
12743
|
+
}
|
|
12744
|
+
if (tmpDir === outDir) reject("outDir and tmpDir are the same directory");
|
|
12745
|
+
if (contains(outDir, tmpDir)) reject("tmpDir is inside outDir");
|
|
12746
|
+
if (contains(tmpDir, outDir)) reject("outDir is inside tmpDir");
|
|
12747
|
+
return { outDir, tmpDir };
|
|
12748
|
+
}
|
|
12749
|
+
var RUN_DIR_PREFIX = "run-";
|
|
12750
|
+
var OWNERSHIP_MARKER = ".codebase-snapshot";
|
|
12751
|
+
var SUPPORTED_MARKER_SCHEMAS = /* @__PURE__ */ new Set([SCHEMA_VERSION]);
|
|
12752
|
+
var SNAPSHOT_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12753
|
+
var SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
12754
|
+
function readOwnershipMarker(dir) {
|
|
12755
|
+
const markerPath = path6__namespace.join(dir, OWNERSHIP_MARKER);
|
|
12756
|
+
if (!fs8__namespace.existsSync(markerPath)) {
|
|
12757
|
+
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
12758
|
+
}
|
|
12759
|
+
let raw;
|
|
12760
|
+
try {
|
|
12761
|
+
raw = fs8__namespace.readFileSync(markerPath, "utf8");
|
|
12762
|
+
} catch {
|
|
12763
|
+
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
12764
|
+
}
|
|
12765
|
+
if (raw.trim().length === 0) {
|
|
12766
|
+
return { marker: null, problem: "its .codebase-snapshot marker is empty" };
|
|
12767
|
+
}
|
|
12768
|
+
let parsed;
|
|
12769
|
+
try {
|
|
12770
|
+
parsed = JSON.parse(raw);
|
|
12771
|
+
} catch {
|
|
12772
|
+
return { marker: null, problem: "its .codebase-snapshot marker is not valid JSON" };
|
|
12773
|
+
}
|
|
12774
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
12775
|
+
return { marker: null, problem: "its .codebase-snapshot marker is not a JSON object" };
|
|
12776
|
+
}
|
|
12777
|
+
const candidate = parsed;
|
|
12778
|
+
if (!isOurGeneratorName(candidate.generator)) {
|
|
12779
|
+
return { marker: null, problem: "its .codebase-snapshot marker names a different generator" };
|
|
12780
|
+
}
|
|
12781
|
+
if (typeof candidate.schemaVersion !== "string" || !SUPPORTED_MARKER_SCHEMAS.has(candidate.schemaVersion)) {
|
|
12782
|
+
return {
|
|
12783
|
+
marker: null,
|
|
12784
|
+
problem: `its .codebase-snapshot marker has a schema version this build does not understand (${String(candidate.schemaVersion)})`
|
|
12785
|
+
};
|
|
12786
|
+
}
|
|
12787
|
+
if (typeof candidate.id !== "string" || !SNAPSHOT_ID_PATTERN.test(candidate.id)) {
|
|
12788
|
+
return { marker: null, problem: "its .codebase-snapshot marker carries no snapshot id" };
|
|
12789
|
+
}
|
|
12790
|
+
if (candidate.state !== "staging" && candidate.state !== "complete") {
|
|
12791
|
+
return { marker: null, problem: "its .codebase-snapshot marker records no run state" };
|
|
12792
|
+
}
|
|
12793
|
+
const rawFiles = candidate.files;
|
|
12794
|
+
let files;
|
|
12795
|
+
if (rawFiles !== void 0) {
|
|
12796
|
+
if (!Array.isArray(rawFiles)) {
|
|
12797
|
+
return {
|
|
12798
|
+
marker: null,
|
|
12799
|
+
problem: "its .codebase-snapshot marker's file inventory is not an array"
|
|
12800
|
+
};
|
|
12801
|
+
}
|
|
12802
|
+
files = [];
|
|
12803
|
+
for (const item of rawFiles) {
|
|
12804
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
12805
|
+
return {
|
|
12806
|
+
marker: null,
|
|
12807
|
+
problem: "its .codebase-snapshot marker's file inventory holds an entry that is not an object"
|
|
12808
|
+
};
|
|
12809
|
+
}
|
|
12810
|
+
const record = item;
|
|
12811
|
+
if (typeof record.path !== "string" || typeof record.bytes !== "number" || !Number.isInteger(record.bytes) || record.bytes < 0 || typeof record.sha256 !== "string" || !SHA256_HEX_PATTERN.test(record.sha256)) {
|
|
12812
|
+
return {
|
|
12813
|
+
marker: null,
|
|
12814
|
+
problem: "its .codebase-snapshot marker's file inventory holds an entry this build cannot read"
|
|
12815
|
+
};
|
|
12816
|
+
}
|
|
12817
|
+
files.push({ path: record.path, bytes: record.bytes, sha256: record.sha256 });
|
|
12818
|
+
}
|
|
12819
|
+
}
|
|
12820
|
+
return {
|
|
12821
|
+
marker: {
|
|
12822
|
+
generator: GENERATOR_NAME,
|
|
12823
|
+
version: typeof candidate.version === "string" ? candidate.version : "unknown",
|
|
12824
|
+
schemaVersion: candidate.schemaVersion,
|
|
12825
|
+
createdAt: typeof candidate.createdAt === "string" ? candidate.createdAt : "unknown",
|
|
12826
|
+
state: candidate.state,
|
|
12827
|
+
id: candidate.id,
|
|
12828
|
+
runId: typeof candidate.runId === "string" ? candidate.runId : void 0,
|
|
12829
|
+
pid: typeof candidate.pid === "number" ? candidate.pid : void 0,
|
|
12830
|
+
manifestSha256: typeof candidate.manifestSha256 === "string" ? candidate.manifestSha256 : void 0,
|
|
12831
|
+
entries: Array.isArray(candidate.entries) && candidate.entries.every((entry) => typeof entry === "string") ? candidate.entries : void 0,
|
|
12832
|
+
files
|
|
12833
|
+
},
|
|
12834
|
+
problem: null
|
|
12835
|
+
};
|
|
12836
|
+
}
|
|
12837
|
+
function lockKeyFor(stagingRoot) {
|
|
12838
|
+
let key = canonicalLockTarget(stagingRoot);
|
|
12839
|
+
if (process.platform === "win32" || process.platform === "darwin") key = key.toLowerCase();
|
|
12840
|
+
return sha256Hex2(key).slice(0, 16);
|
|
12841
|
+
}
|
|
12842
|
+
function canonicalLockTarget(targetPath) {
|
|
12843
|
+
const resolved = path6__namespace.resolve(targetPath);
|
|
12844
|
+
let existing = resolved;
|
|
12845
|
+
const tail = [];
|
|
12846
|
+
for (; ; ) {
|
|
12847
|
+
try {
|
|
12848
|
+
return path6__namespace.join(fs8__namespace.realpathSync(existing), ...tail);
|
|
12849
|
+
} catch {
|
|
12850
|
+
const parent = path6__namespace.dirname(existing);
|
|
12851
|
+
if (parent === existing) return resolved;
|
|
12852
|
+
tail.unshift(path6__namespace.basename(existing));
|
|
12853
|
+
existing = parent;
|
|
12854
|
+
}
|
|
12855
|
+
}
|
|
12856
|
+
}
|
|
12857
|
+
function lockPathFor(stagingRoot) {
|
|
12858
|
+
return path6__namespace.join(os__namespace.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
12859
|
+
}
|
|
12860
|
+
function releaseAbandonedRun(stagingRoots, runId) {
|
|
12861
|
+
if (runId.length === 0) return;
|
|
12862
|
+
for (const root of new Set(stagingRoots)) {
|
|
12863
|
+
const lockPath = lockPathFor(root);
|
|
12864
|
+
try {
|
|
12865
|
+
const payload = JSON.parse(fs8__namespace.readFileSync(lockPath, "utf8"));
|
|
12866
|
+
if (payload.runId === runId) fs8__namespace.rmSync(lockPath, { force: true });
|
|
12867
|
+
} catch {
|
|
12868
|
+
}
|
|
12869
|
+
let entries;
|
|
12870
|
+
try {
|
|
12871
|
+
entries = fs8__namespace.readdirSync(root);
|
|
12872
|
+
} catch {
|
|
12873
|
+
continue;
|
|
12874
|
+
}
|
|
12875
|
+
for (const name of entries) {
|
|
12876
|
+
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
12877
|
+
const directory = path6__namespace.join(root, name);
|
|
12878
|
+
const { marker } = readOwnershipMarker(directory);
|
|
12879
|
+
if (marker?.runId !== runId) continue;
|
|
12880
|
+
try {
|
|
12881
|
+
fs8__namespace.rmSync(directory, { recursive: true, force: true });
|
|
12882
|
+
} catch {
|
|
12883
|
+
}
|
|
12884
|
+
}
|
|
12885
|
+
}
|
|
12886
|
+
}
|
|
12601
12887
|
|
|
12602
12888
|
// src/mcp/uris.ts
|
|
12603
12889
|
var STATIC_RESOURCE_URIS = [
|
|
@@ -13513,6 +13799,10 @@ function buildAgentContract() {
|
|
|
13513
13799
|
{ key: "maxPartBytes", type: "number | string", default: 307200, summary: "Per-part byte budget." },
|
|
13514
13800
|
{ key: "maxPartTokens", type: "number | string | null", default: null, summary: "Per-part token ceiling; narrows maxPartBytes. Minimum 1024." },
|
|
13515
13801
|
{ key: "skeleton", type: "boolean", default: false, summary: "Collapse function bodies to `{ /* ... */ }` in TS, JS, TSX and JSX files." },
|
|
13802
|
+
{ key: "stripComments", type: "boolean", default: false, summary: "Remove comment text from JS/TS bodies." },
|
|
13803
|
+
{ key: "removeEmptyLines", type: "boolean", default: false, summary: "Drop blank lines from emitted bodies; the part's line numbers move, and files[] records emptyLinesRemoved." },
|
|
13804
|
+
{ key: "pack", type: '"single" | "xml" | "json" | null', default: null, summary: "Write one single-file pack in this format." },
|
|
13805
|
+
{ key: "logCount", type: "number", default: 20, summary: "Commit lines in reports/log.md (also set by --include-logs <n>)." },
|
|
13516
13806
|
{ key: "sarif", type: "boolean", default: false, summary: "Also write reports/audit.sarif." },
|
|
13517
13807
|
{ key: "changedSince", type: "string | null", default: null, summary: "Snapshot only files that differ from this git ref." },
|
|
13518
13808
|
{ key: "staged", type: "boolean", default: false, summary: "Snapshot only files staged in the index." },
|
|
@@ -13852,7 +14142,7 @@ async function workspaceFor(context) {
|
|
|
13852
14142
|
}
|
|
13853
14143
|
function readFileIfPresent(file) {
|
|
13854
14144
|
try {
|
|
13855
|
-
return
|
|
14145
|
+
return fs8__namespace.readFileSync(file, "utf8");
|
|
13856
14146
|
} catch {
|
|
13857
14147
|
return null;
|
|
13858
14148
|
}
|
|
@@ -13891,9 +14181,9 @@ function buildResourceProvider() {
|
|
|
13891
14181
|
}
|
|
13892
14182
|
];
|
|
13893
14183
|
const workspace = await workspaceFor(context);
|
|
13894
|
-
const reportsDir = "error" in workspace ? null :
|
|
14184
|
+
const reportsDir = "error" in workspace ? null : path6__namespace.resolve(workspace.root, workspace.config.outDir, "reports");
|
|
13895
14185
|
for (const [uri, report2] of REPORT_URIS) {
|
|
13896
|
-
const present = reportsDir !== null &&
|
|
14186
|
+
const present = reportsDir !== null && fs8__namespace.existsSync(path6__namespace.join(reportsDir, report2.file));
|
|
13897
14187
|
if (!present) continue;
|
|
13898
14188
|
resources.push({
|
|
13899
14189
|
uri,
|
|
@@ -13957,7 +14247,7 @@ function buildResourceProvider() {
|
|
|
13957
14247
|
if ("error" in workspace) return null;
|
|
13958
14248
|
if (uri === PROMPT_URI) {
|
|
13959
14249
|
const text = readFileIfPresent(
|
|
13960
|
-
|
|
14250
|
+
path6__namespace.resolve(workspace.root, workspace.config.outDir, "PROMPT.md")
|
|
13961
14251
|
);
|
|
13962
14252
|
if (text === null) {
|
|
13963
14253
|
throw new ResourceNotFoundError(
|
|
@@ -13970,7 +14260,7 @@ function buildResourceProvider() {
|
|
|
13970
14260
|
const report2 = REPORT_URIS.get(uri);
|
|
13971
14261
|
if (report2) {
|
|
13972
14262
|
const text = readFileIfPresent(
|
|
13973
|
-
|
|
14263
|
+
path6__namespace.resolve(workspace.root, workspace.config.outDir, "reports", report2.file)
|
|
13974
14264
|
);
|
|
13975
14265
|
if (text === null) {
|
|
13976
14266
|
throw new ResourceNotFoundError(
|
|
@@ -13997,7 +14287,7 @@ function buildResourceProvider() {
|
|
|
13997
14287
|
if (partPath === null) return null;
|
|
13998
14288
|
let partBytes;
|
|
13999
14289
|
try {
|
|
14000
|
-
partBytes =
|
|
14290
|
+
partBytes = fs8__namespace.statSync(partPath).size;
|
|
14001
14291
|
} catch {
|
|
14002
14292
|
return null;
|
|
14003
14293
|
}
|
|
@@ -14443,7 +14733,7 @@ var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
|
|
|
14443
14733
|
var RATE_LIMIT = 60;
|
|
14444
14734
|
var RATE_WINDOW_MS = 1e4;
|
|
14445
14735
|
function generateToken() {
|
|
14446
|
-
return
|
|
14736
|
+
return crypto5__namespace.randomBytes(24).toString("base64url");
|
|
14447
14737
|
}
|
|
14448
14738
|
function isLoopbackOrigin(origin) {
|
|
14449
14739
|
try {
|
|
@@ -14459,7 +14749,7 @@ function timingSafeEqual2(left, right) {
|
|
|
14459
14749
|
const a = Buffer.from(left, "utf8");
|
|
14460
14750
|
const b = Buffer.from(right, "utf8");
|
|
14461
14751
|
if (a.length !== b.length) return false;
|
|
14462
|
-
return
|
|
14752
|
+
return crypto5__namespace.timingSafeEqual(a, b);
|
|
14463
14753
|
}
|
|
14464
14754
|
async function startHttpTransport(options) {
|
|
14465
14755
|
const host = options.host ?? "127.0.0.1";
|
|
@@ -14473,8 +14763,43 @@ async function startHttpTransport(options) {
|
|
|
14473
14763
|
"Refusing to serve " + host + " without a token: a repository reachable from the network must require Authorization. Drop --no-auth, or bind the loopback address."
|
|
14474
14764
|
);
|
|
14475
14765
|
}
|
|
14476
|
-
const
|
|
14766
|
+
const createMcp = () => createServer({ cwd: options.cwd, log });
|
|
14477
14767
|
const toolCount = buildTools().length;
|
|
14768
|
+
const mcpSessions = /* @__PURE__ */ new Map();
|
|
14769
|
+
const socketServers = /* @__PURE__ */ new WeakMap();
|
|
14770
|
+
const anonymousServers = /* @__PURE__ */ new Map();
|
|
14771
|
+
const serverFor = (request) => {
|
|
14772
|
+
const header = request.headers["mcp-session-id"];
|
|
14773
|
+
const supplied = typeof header === "string" ? header.trim() : "";
|
|
14774
|
+
if (supplied !== "") {
|
|
14775
|
+
let existing = mcpSessions.get(supplied);
|
|
14776
|
+
if (existing === void 0) {
|
|
14777
|
+
existing = createMcp();
|
|
14778
|
+
if (mcpSessions.size >= 64) {
|
|
14779
|
+
const oldest = mcpSessions.keys().next().value;
|
|
14780
|
+
if (oldest !== void 0) mcpSessions.delete(oldest);
|
|
14781
|
+
}
|
|
14782
|
+
mcpSessions.set(supplied, existing);
|
|
14783
|
+
}
|
|
14784
|
+
return existing;
|
|
14785
|
+
}
|
|
14786
|
+
const onSocket = socketServers.get(request.socket);
|
|
14787
|
+
if (onSocket !== void 0) return onSocket;
|
|
14788
|
+
const userAgent = typeof request.headers["user-agent"] === "string" ? request.headers["user-agent"] : "";
|
|
14789
|
+
const fallbackKey = (request.socket.remoteAddress ?? "unknown") + "\0" + userAgent;
|
|
14790
|
+
let fallback = anonymousServers.get(fallbackKey);
|
|
14791
|
+
if (fallback === void 0) {
|
|
14792
|
+
fallback = createMcp();
|
|
14793
|
+
if (anonymousServers.size >= 64) {
|
|
14794
|
+
const oldest = anonymousServers.keys().next().value;
|
|
14795
|
+
if (oldest !== void 0) anonymousServers.delete(oldest);
|
|
14796
|
+
}
|
|
14797
|
+
anonymousServers.set(fallbackKey, fallback);
|
|
14798
|
+
}
|
|
14799
|
+
socketServers.set(request.socket, fallback);
|
|
14800
|
+
return fallback;
|
|
14801
|
+
};
|
|
14802
|
+
const newSessionId = () => crypto5__namespace.randomBytes(12).toString("hex");
|
|
14478
14803
|
const sseSessions = /* @__PURE__ */ new Map();
|
|
14479
14804
|
const tokenAccepted = (request, url) => {
|
|
14480
14805
|
if (token === null) return true;
|
|
@@ -14495,6 +14820,18 @@ async function startHttpTransport(options) {
|
|
|
14495
14820
|
const method = request.method ?? "UNKNOWN";
|
|
14496
14821
|
metrics.byMethod.set(method, (metrics.byMethod.get(method) ?? 0) + 1);
|
|
14497
14822
|
};
|
|
14823
|
+
const rateLimited = (request) => {
|
|
14824
|
+
const remote = request.socket.remoteAddress ?? "unknown";
|
|
14825
|
+
const now = Date.now();
|
|
14826
|
+
const window = sessions.get(remote);
|
|
14827
|
+
if (window === void 0 || window.resetAt <= now) {
|
|
14828
|
+
sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
14829
|
+
return false;
|
|
14830
|
+
}
|
|
14831
|
+
if (window.count >= RATE_LIMIT) return true;
|
|
14832
|
+
window.count += 1;
|
|
14833
|
+
return false;
|
|
14834
|
+
};
|
|
14498
14835
|
const allowedOrigin = (origin) => {
|
|
14499
14836
|
if (origin === void 0) return null;
|
|
14500
14837
|
if (isLoopbackOrigin(origin)) return origin;
|
|
@@ -14502,7 +14839,10 @@ async function startHttpTransport(options) {
|
|
|
14502
14839
|
};
|
|
14503
14840
|
const httpServer = http__namespace.createServer((request, response) => {
|
|
14504
14841
|
noteRequest(request);
|
|
14842
|
+
let responseSent = false;
|
|
14505
14843
|
const send = (status, body, extra = {}) => {
|
|
14844
|
+
if (responseSent) return;
|
|
14845
|
+
responseSent = true;
|
|
14506
14846
|
const text = typeof body === "string" ? body : JSON.stringify(body);
|
|
14507
14847
|
if (status >= 400 && status < 500 && status !== 429) metrics.refused += 1;
|
|
14508
14848
|
response.writeHead(status, {
|
|
@@ -14578,7 +14918,12 @@ async function startHttpTransport(options) {
|
|
|
14578
14918
|
send(401, { error: "unauthorized" }, { ...cors, "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
14579
14919
|
return;
|
|
14580
14920
|
}
|
|
14581
|
-
|
|
14921
|
+
if (rateLimited(request)) {
|
|
14922
|
+
metrics.rateLimited += 1;
|
|
14923
|
+
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
14924
|
+
return;
|
|
14925
|
+
}
|
|
14926
|
+
const id = crypto5__namespace.randomBytes(12).toString("hex");
|
|
14582
14927
|
response.writeHead(200, {
|
|
14583
14928
|
...cors,
|
|
14584
14929
|
"content-type": "text/event-stream",
|
|
@@ -14589,7 +14934,7 @@ async function startHttpTransport(options) {
|
|
|
14589
14934
|
const write = (payload) => {
|
|
14590
14935
|
response.write(payload);
|
|
14591
14936
|
};
|
|
14592
|
-
sseSessions.set(id, { write, end: () => response.end() });
|
|
14937
|
+
sseSessions.set(id, { write, end: () => response.end(), server: createMcp() });
|
|
14593
14938
|
const heartbeat = setInterval(() => write(": ping\n\n"), 15e3);
|
|
14594
14939
|
const cleanup = () => {
|
|
14595
14940
|
clearInterval(heartbeat);
|
|
@@ -14605,6 +14950,11 @@ async function startHttpTransport(options) {
|
|
|
14605
14950
|
send(401, { error: "unauthorized" }, { ...cors, "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
14606
14951
|
return;
|
|
14607
14952
|
}
|
|
14953
|
+
if (rateLimited(request)) {
|
|
14954
|
+
metrics.rateLimited += 1;
|
|
14955
|
+
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
14956
|
+
return;
|
|
14957
|
+
}
|
|
14608
14958
|
const id = url.searchParams.get("sessionId") ?? "";
|
|
14609
14959
|
const stream = sseSessions.get(id);
|
|
14610
14960
|
if (stream === void 0) {
|
|
@@ -14613,9 +14963,12 @@ async function startHttpTransport(options) {
|
|
|
14613
14963
|
}
|
|
14614
14964
|
const chunks2 = [];
|
|
14615
14965
|
let received2 = 0;
|
|
14966
|
+
let tooLarge2 = false;
|
|
14616
14967
|
request.on("data", (chunk) => {
|
|
14968
|
+
if (tooLarge2) return;
|
|
14617
14969
|
received2 += chunk.length;
|
|
14618
14970
|
if (received2 > maxBody) {
|
|
14971
|
+
tooLarge2 = true;
|
|
14619
14972
|
request.destroy();
|
|
14620
14973
|
send(413, { error: "request body too large", limit: maxBody });
|
|
14621
14974
|
return;
|
|
@@ -14623,6 +14976,7 @@ async function startHttpTransport(options) {
|
|
|
14623
14976
|
chunks2.push(chunk);
|
|
14624
14977
|
});
|
|
14625
14978
|
request.on("end", () => {
|
|
14979
|
+
if (tooLarge2) return;
|
|
14626
14980
|
void (async () => {
|
|
14627
14981
|
let message;
|
|
14628
14982
|
try {
|
|
@@ -14631,7 +14985,7 @@ async function startHttpTransport(options) {
|
|
|
14631
14985
|
send(400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: String(error) } });
|
|
14632
14986
|
return;
|
|
14633
14987
|
}
|
|
14634
|
-
const answer = await server.handle(message);
|
|
14988
|
+
const answer = await stream.server.handle(message);
|
|
14635
14989
|
if (answer !== null) stream.write("event: message\ndata: " + JSON.stringify(answer) + "\n\n");
|
|
14636
14990
|
send(202, "", cors);
|
|
14637
14991
|
})();
|
|
@@ -14658,20 +15012,22 @@ async function startHttpTransport(options) {
|
|
|
14658
15012
|
return;
|
|
14659
15013
|
}
|
|
14660
15014
|
}
|
|
14661
|
-
|
|
14662
|
-
const now = Date.now();
|
|
14663
|
-
const window = sessions.get(remote);
|
|
14664
|
-
if (window === void 0 || window.resetAt <= now) sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
14665
|
-
else if (window.count >= RATE_LIMIT) {
|
|
15015
|
+
if (rateLimited(request)) {
|
|
14666
15016
|
metrics.rateLimited += 1;
|
|
14667
15017
|
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
14668
15018
|
return;
|
|
14669
|
-
}
|
|
15019
|
+
}
|
|
15020
|
+
const activeServer = serverFor(request);
|
|
15021
|
+
const sessionHeader = request.headers["mcp-session-id"];
|
|
15022
|
+
let sessionId = typeof sessionHeader === "string" ? sessionHeader.trim() : "";
|
|
14670
15023
|
let received = 0;
|
|
15024
|
+
let tooLarge = false;
|
|
14671
15025
|
const chunks = [];
|
|
14672
15026
|
request.on("data", (chunk) => {
|
|
15027
|
+
if (tooLarge) return;
|
|
14673
15028
|
received += chunk.length;
|
|
14674
15029
|
if (received > maxBody) {
|
|
15030
|
+
tooLarge = true;
|
|
14675
15031
|
request.destroy();
|
|
14676
15032
|
send(413, { error: "request body too large", limit: maxBody }, cors);
|
|
14677
15033
|
return;
|
|
@@ -14679,6 +15035,7 @@ async function startHttpTransport(options) {
|
|
|
14679
15035
|
chunks.push(chunk);
|
|
14680
15036
|
});
|
|
14681
15037
|
request.on("end", () => {
|
|
15038
|
+
if (tooLarge) return;
|
|
14682
15039
|
void (async () => {
|
|
14683
15040
|
let message;
|
|
14684
15041
|
try {
|
|
@@ -14687,17 +15044,26 @@ async function startHttpTransport(options) {
|
|
|
14687
15044
|
send(400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error: " + error.message } }, cors);
|
|
14688
15045
|
return;
|
|
14689
15046
|
}
|
|
14690
|
-
const answers = [];
|
|
14691
15047
|
const batch = Array.isArray(message) ? message : [message];
|
|
15048
|
+
if (batch.length > 100) {
|
|
15049
|
+
send(400, { error: "JSON-RPC batch is limited to 100 messages" }, cors);
|
|
15050
|
+
return;
|
|
15051
|
+
}
|
|
15052
|
+
if (sessionId === "" && !Array.isArray(message) && message.method === "initialize") {
|
|
15053
|
+
sessionId = newSessionId();
|
|
15054
|
+
mcpSessions.set(sessionId, activeServer);
|
|
15055
|
+
}
|
|
15056
|
+
const sessionHeaders = sessionId === "" ? cors : { ...cors, "mcp-session-id": sessionId };
|
|
15057
|
+
const answers = [];
|
|
14692
15058
|
for (const item of batch) {
|
|
14693
|
-
const answer = await
|
|
15059
|
+
const answer = await activeServer.handle(item);
|
|
14694
15060
|
if (answer !== null) answers.push(answer);
|
|
14695
15061
|
}
|
|
14696
15062
|
if (answers.length === 0) {
|
|
14697
|
-
send(202, "",
|
|
15063
|
+
send(202, "", sessionHeaders);
|
|
14698
15064
|
return;
|
|
14699
15065
|
}
|
|
14700
|
-
send(200, Array.isArray(message) ? answers : answers[0],
|
|
15066
|
+
send(200, Array.isArray(message) ? answers : answers[0], sessionHeaders);
|
|
14701
15067
|
})().catch((error) => {
|
|
14702
15068
|
log("mcp/http: " + error.message);
|
|
14703
15069
|
send(500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
|