codebase-snapshot 0.20.4 → 0.20.5
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 +45 -0
- package/README.md +1 -1
- package/dist/bin.js +1241 -687
- package/dist/{chunk-AQZNT3QL.js → chunk-C3WVC4FV.js} +1230 -761
- package/dist/{chunk-QB5TNXMZ.js → chunk-HYTY6T7P.js} +67 -12
- package/dist/cli.cjs +1426 -875
- package/dist/cli.d.cts +4 -2
- package/dist/cli.d.ts +4 -2
- package/dist/cli.js +35 -9
- package/dist/index.cjs +1222 -753
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +628 -331
- package/dist/mcp.js +2 -2
- package/dist/{types-Drw1J0e0.d.cts → types-DnYsA6_Y.d.cts} +4 -0
- package/dist/{types-Drw1J0e0.d.ts → types-DnYsA6_Y.d.ts} +4 -0
- package/docs/cli.md +5 -5
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +4 -4
- package/docs/security-review.md +26 -1
- package/docs/workspace.md +3 -0
- package/package.json +1 -1
package/dist/mcp.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var fs3 = require('fs');
|
|
4
4
|
var path6 = require('path');
|
|
5
5
|
var crypto5 = require('crypto');
|
|
6
6
|
var module$1 = require('module');
|
|
@@ -32,7 +32,7 @@ function _interopNamespace(e) {
|
|
|
32
32
|
return Object.freeze(n);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
var
|
|
35
|
+
var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
|
|
36
36
|
var path6__namespace = /*#__PURE__*/_interopNamespace(path6);
|
|
37
37
|
var crypto5__namespace = /*#__PURE__*/_interopNamespace(crypto5);
|
|
38
38
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
@@ -422,9 +422,9 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
422
422
|
]);
|
|
423
423
|
function readSmallFile(fullPath) {
|
|
424
424
|
try {
|
|
425
|
-
const stats =
|
|
425
|
+
const stats = fs3__namespace.statSync(fullPath);
|
|
426
426
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
427
|
-
return
|
|
427
|
+
return fs3__namespace.readFileSync(fullPath, "utf8");
|
|
428
428
|
} catch {
|
|
429
429
|
return null;
|
|
430
430
|
}
|
|
@@ -490,7 +490,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
490
490
|
function childDirectories(cwd, parent) {
|
|
491
491
|
let entries;
|
|
492
492
|
try {
|
|
493
|
-
entries =
|
|
493
|
+
entries = fs3__namespace.readdirSync(path6__namespace.join(cwd, parent), { withFileTypes: true });
|
|
494
494
|
} catch {
|
|
495
495
|
return [];
|
|
496
496
|
}
|
|
@@ -525,10 +525,10 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
525
525
|
function scanWorkspacePackages(cwd, patterns) {
|
|
526
526
|
const files = /* @__PURE__ */ new Set();
|
|
527
527
|
const dependencies = /* @__PURE__ */ new Set();
|
|
528
|
-
for (const
|
|
529
|
-
const full = path6__namespace.join(cwd,
|
|
528
|
+
for (const relative10 of workspacePackageDirs(cwd, patterns)) {
|
|
529
|
+
const full = path6__namespace.join(cwd, relative10);
|
|
530
530
|
try {
|
|
531
|
-
for (const entry of
|
|
531
|
+
for (const entry of fs3__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
532
532
|
} catch {
|
|
533
533
|
}
|
|
534
534
|
const raw = readSmallFile(path6__namespace.join(full, "package.json"));
|
|
@@ -541,7 +541,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
541
541
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
542
542
|
function isToolOwnedDirectory(dir) {
|
|
543
543
|
try {
|
|
544
|
-
return
|
|
544
|
+
return fs3__namespace.statSync(dir).isDirectory() && fs3__namespace.existsSync(path6__namespace.join(dir, SNAPSHOT_MARKER));
|
|
545
545
|
} catch {
|
|
546
546
|
return false;
|
|
547
547
|
}
|
|
@@ -556,7 +556,7 @@ function countMarkdownFiles(cwd) {
|
|
|
556
556
|
directoriesSeen += 1;
|
|
557
557
|
let entries;
|
|
558
558
|
try {
|
|
559
|
-
entries =
|
|
559
|
+
entries = fs3__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
560
560
|
} catch {
|
|
561
561
|
continue;
|
|
562
562
|
}
|
|
@@ -578,7 +578,7 @@ function buildPresetContext(cwd) {
|
|
|
578
578
|
const files = /* @__PURE__ */ new Set();
|
|
579
579
|
const dirs = /* @__PURE__ */ new Set();
|
|
580
580
|
try {
|
|
581
|
-
for (const entry of
|
|
581
|
+
for (const entry of fs3__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
582
582
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
583
583
|
else if (entry.isFile()) files.add(entry.name);
|
|
584
584
|
}
|
|
@@ -1740,7 +1740,7 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1740
1740
|
// rendering of textual userinfo mixes cases, while the prose the earlier rules were
|
|
1741
1741
|
// protecting (`Bearer authentication`) is a lowercase word.
|
|
1742
1742
|
rule: "authorization-header",
|
|
1743
|
-
pattern: /(?<=[Aa]
|
|
1743
|
+
pattern: /(?<=[Aa][Uu][Tt][Hh][Oo][Rr][Ii][Zz][Aa][Tt][Ii][Oo][Nn]["']?\s*[:=]\s*["']?[A-Za-z][A-Za-z0-9._~+/-]{0,31}\s{1,8})(?:[A-Za-z0-9_.+/-]{0,31}[0-9][A-Za-z0-9_.+/-]{0,1024}|[A-Za-z0-9_.+/-]{32,1024}|[A-Za-z0-9_.+/-]{8,1024}={1,2}|(?=[A-Za-z0-9_.+/-]{0,1023}[A-Z])(?=[A-Za-z0-9_.+/-]{0,1023}[a-z])[A-Za-z0-9_.+/-]{12,1024})(?![A-Za-z0-9_.+/=-])/
|
|
1744
1744
|
},
|
|
1745
1745
|
{
|
|
1746
1746
|
// Broader names than before (`apiKey`, `clientSecret`, `privateKey` were
|
|
@@ -2318,6 +2318,7 @@ function redactStructuredValues(text, filePath, recordFinding) {
|
|
|
2318
2318
|
if (firstValue === void 0) continue;
|
|
2319
2319
|
const valueIndent = (/^[ \t]*/.exec(firstValue)?.[0] ?? "").length;
|
|
2320
2320
|
if (valueIndent <= baseIndent) continue;
|
|
2321
|
+
if (STRUCTURED_KEY.test(firstValue) || /^[ \t]*-[ \t]/.test(firstValue)) continue;
|
|
2321
2322
|
let masked = false;
|
|
2322
2323
|
while (cursor < segments.length) {
|
|
2323
2324
|
const body = segments[cursor] ?? "";
|
|
@@ -2558,10 +2559,10 @@ var SIGNATURE_FILE = "signature.json";
|
|
|
2558
2559
|
function verifySnapshotSignature(snapshotDir) {
|
|
2559
2560
|
const signaturePath = path6__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
2560
2561
|
const manifestPath = path6__namespace.join(snapshotDir, "manifest.json");
|
|
2561
|
-
if (!
|
|
2562
|
+
if (!fs3__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
2562
2563
|
let record;
|
|
2563
2564
|
try {
|
|
2564
|
-
record = JSON.parse(
|
|
2565
|
+
record = JSON.parse(fs3__namespace.readFileSync(signaturePath, "utf8"));
|
|
2565
2566
|
} catch (error) {
|
|
2566
2567
|
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
2567
2568
|
}
|
|
@@ -2570,7 +2571,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
2570
2571
|
}
|
|
2571
2572
|
let bytes;
|
|
2572
2573
|
try {
|
|
2573
|
-
bytes =
|
|
2574
|
+
bytes = fs3__namespace.readFileSync(manifestPath);
|
|
2574
2575
|
} catch {
|
|
2575
2576
|
return { ok: false, reason: "the signed manifest is missing" };
|
|
2576
2577
|
}
|
|
@@ -2590,7 +2591,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
2590
2591
|
|
|
2591
2592
|
// src/version.ts
|
|
2592
2593
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2593
|
-
var GENERATOR_VERSION = "0.20.
|
|
2594
|
+
var GENERATOR_VERSION = "0.20.5";
|
|
2594
2595
|
var SCHEMA_VERSION = "3.0.0";
|
|
2595
2596
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2596
2597
|
function isOurGeneratorName(name) {
|
|
@@ -2607,7 +2608,7 @@ var PRESET_IGNORES = new Set(
|
|
|
2607
2608
|
);
|
|
2608
2609
|
function readLinkTarget(linkPath, fallback) {
|
|
2609
2610
|
try {
|
|
2610
|
-
return
|
|
2611
|
+
return fs3__namespace.readlinkSync(linkPath);
|
|
2611
2612
|
} catch {
|
|
2612
2613
|
return fallback;
|
|
2613
2614
|
}
|
|
@@ -2622,8 +2623,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
2622
2623
|
};
|
|
2623
2624
|
}
|
|
2624
2625
|
function isInside(root, candidate) {
|
|
2625
|
-
const
|
|
2626
|
-
return
|
|
2626
|
+
const relative10 = path6__namespace.relative(root, candidate);
|
|
2627
|
+
return relative10 === "" || !relative10.startsWith(`..${path6__namespace.sep}`) && relative10 !== ".." && !path6__namespace.isAbsolute(relative10);
|
|
2627
2628
|
}
|
|
2628
2629
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
2629
2630
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -2886,7 +2887,7 @@ function readGitignoreRules(dir) {
|
|
|
2886
2887
|
const gitignorePath = path6__namespace.join(dir, ".gitignore");
|
|
2887
2888
|
let raw;
|
|
2888
2889
|
try {
|
|
2889
|
-
raw =
|
|
2890
|
+
raw = fs3__namespace.readFileSync(gitignorePath, "utf8");
|
|
2890
2891
|
} catch {
|
|
2891
2892
|
return [];
|
|
2892
2893
|
}
|
|
@@ -3059,7 +3060,7 @@ function listIgnoredPaths(cwd) {
|
|
|
3059
3060
|
}
|
|
3060
3061
|
function hasSnapshotMarker(target) {
|
|
3061
3062
|
try {
|
|
3062
|
-
return
|
|
3063
|
+
return fs3__namespace.statSync(target).isDirectory() && isToolOwnedDirectory2(target);
|
|
3063
3064
|
} catch {
|
|
3064
3065
|
return false;
|
|
3065
3066
|
}
|
|
@@ -3068,7 +3069,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
3068
3069
|
function isToolOwnedDirectory2(dir) {
|
|
3069
3070
|
let raw;
|
|
3070
3071
|
try {
|
|
3071
|
-
raw =
|
|
3072
|
+
raw = fs3__namespace.readFileSync(path6__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
3072
3073
|
} catch {
|
|
3073
3074
|
return false;
|
|
3074
3075
|
}
|
|
@@ -3095,7 +3096,7 @@ function isToolOwnedDirectory2(dir) {
|
|
|
3095
3096
|
}
|
|
3096
3097
|
let entries;
|
|
3097
3098
|
try {
|
|
3098
|
-
entries =
|
|
3099
|
+
entries = fs3__namespace.readdirSync(dir);
|
|
3099
3100
|
} catch {
|
|
3100
3101
|
return false;
|
|
3101
3102
|
}
|
|
@@ -3129,7 +3130,7 @@ function makeLinkProbe() {
|
|
|
3129
3130
|
let known = cache.get(absolutePath);
|
|
3130
3131
|
if (known === void 0) {
|
|
3131
3132
|
try {
|
|
3132
|
-
known =
|
|
3133
|
+
known = fs3__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
3133
3134
|
} catch {
|
|
3134
3135
|
known = false;
|
|
3135
3136
|
}
|
|
@@ -3142,7 +3143,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3142
3143
|
const isLink = makeLinkProbe();
|
|
3143
3144
|
let rootReal = cwd;
|
|
3144
3145
|
try {
|
|
3145
|
-
rootReal =
|
|
3146
|
+
rootReal = fs3__namespace.realpathSync(cwd);
|
|
3146
3147
|
} catch {
|
|
3147
3148
|
}
|
|
3148
3149
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -3170,7 +3171,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3170
3171
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
3171
3172
|
let targetReal = null;
|
|
3172
3173
|
try {
|
|
3173
|
-
targetReal =
|
|
3174
|
+
targetReal = fs3__namespace.realpathSync(absolute);
|
|
3174
3175
|
} catch {
|
|
3175
3176
|
targetReal = null;
|
|
3176
3177
|
}
|
|
@@ -3188,7 +3189,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3188
3189
|
}
|
|
3189
3190
|
let stats = null;
|
|
3190
3191
|
try {
|
|
3191
|
-
stats =
|
|
3192
|
+
stats = fs3__namespace.statSync(absolute);
|
|
3192
3193
|
} catch {
|
|
3193
3194
|
stats = null;
|
|
3194
3195
|
}
|
|
@@ -3285,7 +3286,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
3285
3286
|
"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."
|
|
3286
3287
|
);
|
|
3287
3288
|
}
|
|
3288
|
-
if (
|
|
3289
|
+
if (fs3__namespace.existsSync(path6__namespace.join(cwd, ".git"))) {
|
|
3289
3290
|
throw new Error(
|
|
3290
3291
|
"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."
|
|
3291
3292
|
);
|
|
@@ -3304,7 +3305,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
3304
3305
|
candidates.push(extra);
|
|
3305
3306
|
}
|
|
3306
3307
|
}
|
|
3307
|
-
|
|
3308
|
+
let files = candidates.filter((file) => {
|
|
3308
3309
|
if (isToolOwned(file)) return false;
|
|
3309
3310
|
const ignored = defaultIgnoreReason(file, toolDirNames);
|
|
3310
3311
|
if (ignored) {
|
|
@@ -3349,11 +3350,53 @@ function collectFiles(cwd, options = {}) {
|
|
|
3349
3350
|
}
|
|
3350
3351
|
return true;
|
|
3351
3352
|
}).sort();
|
|
3353
|
+
files = dropSymlinksToUnincludedTargets(cwd, files, skipped);
|
|
3352
3354
|
return { files, skipped: maskSkipPaths(skipped, pathRules) };
|
|
3353
3355
|
}
|
|
3356
|
+
function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
3357
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
3358
|
+
for (const file of files) {
|
|
3359
|
+
try {
|
|
3360
|
+
if (fs3__namespace.lstatSync(path6__namespace.join(cwd, file)).isSymbolicLink()) aliases.add(file);
|
|
3361
|
+
} catch {
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
if (aliases.size === 0) return [...files];
|
|
3365
|
+
const includedTargets = /* @__PURE__ */ new Set();
|
|
3366
|
+
for (const file of files) {
|
|
3367
|
+
try {
|
|
3368
|
+
includedTargets.add(fs3__namespace.realpathSync(path6__namespace.join(cwd, file)));
|
|
3369
|
+
} catch {
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
const kept = [];
|
|
3373
|
+
for (const file of files) {
|
|
3374
|
+
if (!aliases.has(file)) {
|
|
3375
|
+
kept.push(file);
|
|
3376
|
+
continue;
|
|
3377
|
+
}
|
|
3378
|
+
let target;
|
|
3379
|
+
try {
|
|
3380
|
+
target = fs3__namespace.realpathSync(path6__namespace.join(cwd, file));
|
|
3381
|
+
} catch {
|
|
3382
|
+
skipped.push({ path: file, reason: "read-error", detail: "symlink target could not be resolved" });
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3385
|
+
if (includedTargets.has(target)) {
|
|
3386
|
+
kept.push(file);
|
|
3387
|
+
continue;
|
|
3388
|
+
}
|
|
3389
|
+
skipped.push({
|
|
3390
|
+
path: file,
|
|
3391
|
+
reason: "symlink",
|
|
3392
|
+
detail: "link target was excluded from the snapshot; not followed"
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
return kept;
|
|
3396
|
+
}
|
|
3354
3397
|
function rootRealFor(root) {
|
|
3355
3398
|
try {
|
|
3356
|
-
return
|
|
3399
|
+
return fs3__namespace.realpathSync(root);
|
|
3357
3400
|
} catch {
|
|
3358
3401
|
return root;
|
|
3359
3402
|
}
|
|
@@ -3373,7 +3416,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3373
3416
|
];
|
|
3374
3417
|
let entries;
|
|
3375
3418
|
try {
|
|
3376
|
-
entries =
|
|
3419
|
+
entries = fs3__namespace.readdirSync(current, { withFileTypes: true });
|
|
3377
3420
|
} catch {
|
|
3378
3421
|
results.skipped.push({
|
|
3379
3422
|
path: relativeToBase(current),
|
|
@@ -3429,14 +3472,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3429
3472
|
if (entry.isSymbolicLink()) {
|
|
3430
3473
|
let targetReal;
|
|
3431
3474
|
try {
|
|
3432
|
-
targetReal =
|
|
3475
|
+
targetReal = fs3__namespace.realpathSync(fullPath);
|
|
3433
3476
|
} catch {
|
|
3434
3477
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
3435
3478
|
continue;
|
|
3436
3479
|
}
|
|
3437
3480
|
let stats;
|
|
3438
3481
|
try {
|
|
3439
|
-
stats =
|
|
3482
|
+
stats = fs3__namespace.statSync(fullPath);
|
|
3440
3483
|
} catch {
|
|
3441
3484
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
3442
3485
|
continue;
|
|
@@ -3725,10 +3768,10 @@ function readConfigExport(exported, file) {
|
|
|
3725
3768
|
var lastModuleConfig = null;
|
|
3726
3769
|
function moduleConfigKey(fullPath) {
|
|
3727
3770
|
try {
|
|
3728
|
-
return crypto5.createHash("sha256").update(
|
|
3771
|
+
return crypto5.createHash("sha256").update(fs3__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
3729
3772
|
} catch {
|
|
3730
3773
|
try {
|
|
3731
|
-
const stats =
|
|
3774
|
+
const stats = fs3__namespace.statSync(fullPath);
|
|
3732
3775
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
3733
3776
|
} catch {
|
|
3734
3777
|
return "unreadable";
|
|
@@ -3769,9 +3812,9 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3769
3812
|
const fullPath = path6__namespace.join(cwd, filename);
|
|
3770
3813
|
let candidateStats = null;
|
|
3771
3814
|
try {
|
|
3772
|
-
candidateStats =
|
|
3815
|
+
candidateStats = fs3__namespace.statSync(fullPath);
|
|
3773
3816
|
} catch {
|
|
3774
|
-
if (!
|
|
3817
|
+
if (!fs3__namespace.existsSync(fullPath)) continue;
|
|
3775
3818
|
}
|
|
3776
3819
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
3777
3820
|
configDirectories.push(fullPath);
|
|
@@ -3779,7 +3822,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3779
3822
|
}
|
|
3780
3823
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
3781
3824
|
try {
|
|
3782
|
-
const config = parseJsonish(
|
|
3825
|
+
const config = parseJsonish(fs3__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
3783
3826
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
3784
3827
|
throw new Error(
|
|
3785
3828
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -3820,9 +3863,9 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
3820
3863
|
}
|
|
3821
3864
|
}
|
|
3822
3865
|
const pkgJsonPath = path6__namespace.join(cwd, "package.json");
|
|
3823
|
-
if (
|
|
3866
|
+
if (fs3__namespace.existsSync(pkgJsonPath)) {
|
|
3824
3867
|
try {
|
|
3825
|
-
const parsed = parseJsonish(
|
|
3868
|
+
const parsed = parseJsonish(fs3__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
3826
3869
|
const snapshotKey = parsed.snapshot;
|
|
3827
3870
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
3828
3871
|
assertKnownConfigKeys(
|
|
@@ -3990,7 +4033,7 @@ function readConfiguredBrief(cwd, value) {
|
|
|
3990
4033
|
}
|
|
3991
4034
|
const rootReal = (() => {
|
|
3992
4035
|
try {
|
|
3993
|
-
return
|
|
4036
|
+
return fs3__namespace.realpathSync(cwd);
|
|
3994
4037
|
} catch {
|
|
3995
4038
|
return path6__namespace.resolve(cwd);
|
|
3996
4039
|
}
|
|
@@ -3998,19 +4041,19 @@ function readConfiguredBrief(cwd, value) {
|
|
|
3998
4041
|
const requested = path6__namespace.resolve(cwd, value);
|
|
3999
4042
|
let filePath;
|
|
4000
4043
|
try {
|
|
4001
|
-
filePath =
|
|
4044
|
+
filePath = fs3__namespace.realpathSync(requested);
|
|
4002
4045
|
} catch {
|
|
4003
4046
|
throw new Error(
|
|
4004
4047
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
4005
4048
|
);
|
|
4006
4049
|
}
|
|
4007
|
-
const
|
|
4008
|
-
if (
|
|
4050
|
+
const relative10 = path6__namespace.relative(rootReal, filePath);
|
|
4051
|
+
if (relative10.length === 0 || relative10 === ".." || relative10.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative10)) {
|
|
4009
4052
|
throw new Error(
|
|
4010
4053
|
'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
4054
|
);
|
|
4012
4055
|
}
|
|
4013
|
-
const posixRelative =
|
|
4056
|
+
const posixRelative = relative10.split(path6__namespace.sep).join("/");
|
|
4014
4057
|
if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
|
|
4015
4058
|
throw new Error(
|
|
4016
4059
|
'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
|
|
@@ -4018,8 +4061,8 @@ function readConfiguredBrief(cwd, value) {
|
|
|
4018
4061
|
}
|
|
4019
4062
|
let text;
|
|
4020
4063
|
try {
|
|
4021
|
-
if (!
|
|
4022
|
-
text =
|
|
4064
|
+
if (!fs3__namespace.statSync(filePath).isFile()) throw new Error("not a file");
|
|
4065
|
+
text = fs3__namespace.readFileSync(filePath, "utf8");
|
|
4023
4066
|
} catch {
|
|
4024
4067
|
throw new Error(
|
|
4025
4068
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
@@ -4132,11 +4175,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
4132
4175
|
const patterns = [];
|
|
4133
4176
|
for (const dir of [outDir, tmpDir]) {
|
|
4134
4177
|
const absolute = path6__namespace.resolve(cwd, dir);
|
|
4135
|
-
const
|
|
4136
|
-
if (!
|
|
4178
|
+
const relative10 = path6__namespace.relative(cwd, absolute);
|
|
4179
|
+
if (!relative10 || relative10 === ".." || relative10.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative10)) {
|
|
4137
4180
|
continue;
|
|
4138
4181
|
}
|
|
4139
|
-
patterns.push(`${
|
|
4182
|
+
patterns.push(`${relative10.replace(/\\/g, "/")}/**`);
|
|
4140
4183
|
}
|
|
4141
4184
|
return patterns;
|
|
4142
4185
|
}
|
|
@@ -4267,10 +4310,10 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
4267
4310
|
}
|
|
4268
4311
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
4269
4312
|
const resolved = path6__namespace.resolve(candidate);
|
|
4270
|
-
if (!
|
|
4313
|
+
if (!fs3__namespace.existsSync(resolved)) {
|
|
4271
4314
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
4272
4315
|
}
|
|
4273
|
-
if (!
|
|
4316
|
+
if (!fs3__namespace.statSync(resolved).isDirectory()) {
|
|
4274
4317
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
4275
4318
|
}
|
|
4276
4319
|
return resolved;
|
|
@@ -4924,9 +4967,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
4924
4967
|
var jvmProfile = {
|
|
4925
4968
|
id: "jvm",
|
|
4926
4969
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
4927
|
-
summarize(
|
|
4970
|
+
summarize(path17, content) {
|
|
4928
4971
|
const summary = emptySummary();
|
|
4929
|
-
const lower =
|
|
4972
|
+
const lower = path17.toLowerCase();
|
|
4930
4973
|
const isJava = lower.endsWith(".java");
|
|
4931
4974
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
4932
4975
|
eachLine(content, (line) => {
|
|
@@ -5149,9 +5192,9 @@ var rubyProfile = {
|
|
|
5149
5192
|
eachLine(content, (line) => {
|
|
5150
5193
|
const trimmed = line.trim();
|
|
5151
5194
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
5152
|
-
const
|
|
5153
|
-
if (
|
|
5154
|
-
summary.imports.push(`./${
|
|
5195
|
+
const relative10 = REQUIRE_RELATIVE.exec(trimmed);
|
|
5196
|
+
if (relative10) {
|
|
5197
|
+
summary.imports.push(`./${relative10[1]}`);
|
|
5155
5198
|
return;
|
|
5156
5199
|
}
|
|
5157
5200
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -5534,17 +5577,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
5534
5577
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
5535
5578
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
5536
5579
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
5537
|
-
function componentName(
|
|
5538
|
-
const base =
|
|
5580
|
+
function componentName(path17) {
|
|
5581
|
+
const base = path17.split("/").pop() ?? path17;
|
|
5539
5582
|
return base.replace(/\.[^.]+$/, "");
|
|
5540
5583
|
}
|
|
5541
5584
|
var sfcProfile = {
|
|
5542
5585
|
id: "sfc",
|
|
5543
5586
|
extensions: [".vue", ".svelte", ".astro"],
|
|
5544
|
-
summarize(
|
|
5587
|
+
summarize(path17, content) {
|
|
5545
5588
|
let script = "";
|
|
5546
|
-
let usesJsx =
|
|
5547
|
-
if (
|
|
5589
|
+
let usesJsx = path17.toLowerCase().endsWith(".astro");
|
|
5590
|
+
if (path17.toLowerCase().endsWith(".astro")) {
|
|
5548
5591
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
5549
5592
|
if (frontmatter) script += `${frontmatter[1]}
|
|
5550
5593
|
`;
|
|
@@ -5554,7 +5597,7 @@ var sfcProfile = {
|
|
|
5554
5597
|
script += `${match[2]}
|
|
5555
5598
|
`;
|
|
5556
5599
|
}
|
|
5557
|
-
const name = componentName(
|
|
5600
|
+
const name = componentName(path17);
|
|
5558
5601
|
if (!script.trim()) {
|
|
5559
5602
|
const summary2 = emptySummary();
|
|
5560
5603
|
if (name) {
|
|
@@ -5745,15 +5788,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
5745
5788
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
5746
5789
|
}
|
|
5747
5790
|
}
|
|
5748
|
-
function profileForPath(
|
|
5749
|
-
const lower =
|
|
5791
|
+
function profileForPath(path17) {
|
|
5792
|
+
const lower = path17.toLowerCase();
|
|
5750
5793
|
const dot = lower.lastIndexOf(".");
|
|
5751
5794
|
if (dot === -1) return null;
|
|
5752
5795
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
5753
5796
|
}
|
|
5754
|
-
function summarizeWithProfile(
|
|
5755
|
-
const profile = profileForPath(
|
|
5756
|
-
return profile ? profile.summarize(
|
|
5797
|
+
function summarizeWithProfile(path17, content) {
|
|
5798
|
+
const profile = profileForPath(path17);
|
|
5799
|
+
return profile ? profile.summarize(path17, content) : null;
|
|
5757
5800
|
}
|
|
5758
5801
|
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
5759
5802
|
".png",
|
|
@@ -5965,13 +6008,13 @@ function isBinaryFile(absolutePath) {
|
|
|
5965
6008
|
if (isBinaryExtension(absolutePath)) return true;
|
|
5966
6009
|
let fd;
|
|
5967
6010
|
try {
|
|
5968
|
-
fd =
|
|
6011
|
+
fd = fs3__namespace.openSync(absolutePath, "r");
|
|
5969
6012
|
const buffer = Buffer.alloc(CHUNK);
|
|
5970
6013
|
let sample2;
|
|
5971
6014
|
let position = 0;
|
|
5972
6015
|
while (position < BINARY_SCAN_BYTES) {
|
|
5973
6016
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
5974
|
-
const bytesRead =
|
|
6017
|
+
const bytesRead = fs3__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
5975
6018
|
if (bytesRead === 0) return false;
|
|
5976
6019
|
const chunk = buffer.subarray(0, bytesRead);
|
|
5977
6020
|
if (sample2 === void 0) {
|
|
@@ -5989,7 +6032,7 @@ function isBinaryFile(absolutePath) {
|
|
|
5989
6032
|
} finally {
|
|
5990
6033
|
if (fd !== void 0) {
|
|
5991
6034
|
try {
|
|
5992
|
-
|
|
6035
|
+
fs3__namespace.closeSync(fd);
|
|
5993
6036
|
} catch {
|
|
5994
6037
|
}
|
|
5995
6038
|
}
|
|
@@ -6011,9 +6054,9 @@ function importsOfText(relativePath, text) {
|
|
|
6011
6054
|
function importsOfFile(relativePath, absolutePath) {
|
|
6012
6055
|
let buffer;
|
|
6013
6056
|
try {
|
|
6014
|
-
const stats =
|
|
6057
|
+
const stats = fs3__namespace.statSync(absolutePath);
|
|
6015
6058
|
if (!stats.isFile() || stats.size > SUMMARY_MAX_SOURCE_BYTES) return [];
|
|
6016
|
-
buffer =
|
|
6059
|
+
buffer = fs3__namespace.readFileSync(absolutePath);
|
|
6017
6060
|
} catch {
|
|
6018
6061
|
return [];
|
|
6019
6062
|
}
|
|
@@ -6112,6 +6155,9 @@ function countLines(content) {
|
|
|
6112
6155
|
const last = content.charCodeAt(content.length - 1);
|
|
6113
6156
|
return last === 10 || last === 13 ? breaks : breaks + 1;
|
|
6114
6157
|
}
|
|
6158
|
+
function countBodyLines(content) {
|
|
6159
|
+
return content.length === 0 ? 0 : content.split("\n").length;
|
|
6160
|
+
}
|
|
6115
6161
|
function truncateToBytes(content, maxBytes) {
|
|
6116
6162
|
const buffer = Buffer.from(content, "utf8");
|
|
6117
6163
|
if (buffer.length <= maxBytes) return { content, isTruncated: false };
|
|
@@ -6265,10 +6311,10 @@ function resolveImport(from, specifier, byPath) {
|
|
|
6265
6311
|
if (segment === "..") parts.pop();
|
|
6266
6312
|
else parts.push(segment);
|
|
6267
6313
|
}
|
|
6268
|
-
const
|
|
6269
|
-
const withoutExtension =
|
|
6314
|
+
const path17 = parts.join("/");
|
|
6315
|
+
const withoutExtension = path17.replace(/\.[cm]?[jt]sx?$/, "");
|
|
6270
6316
|
const candidates = [
|
|
6271
|
-
|
|
6317
|
+
path17,
|
|
6272
6318
|
withoutExtension + ".ts",
|
|
6273
6319
|
withoutExtension + ".tsx",
|
|
6274
6320
|
withoutExtension + ".js",
|
|
@@ -6277,18 +6323,18 @@ function resolveImport(from, specifier, byPath) {
|
|
|
6277
6323
|
withoutExtension + ".go",
|
|
6278
6324
|
withoutExtension + ".rs",
|
|
6279
6325
|
withoutExtension + "/index.ts",
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6326
|
+
path17 + ".ts",
|
|
6327
|
+
path17 + ".tsx",
|
|
6328
|
+
path17 + ".js",
|
|
6329
|
+
path17 + ".jsx",
|
|
6330
|
+
path17 + ".mjs",
|
|
6331
|
+
path17 + ".cjs",
|
|
6332
|
+
path17 + ".py",
|
|
6333
|
+
path17 + ".go",
|
|
6334
|
+
path17 + ".rs",
|
|
6335
|
+
path17 + ".java",
|
|
6336
|
+
path17 + "/index.ts",
|
|
6337
|
+
path17 + "/index.js"
|
|
6292
6338
|
];
|
|
6293
6339
|
for (const candidate of candidates) {
|
|
6294
6340
|
const found = byPath.get(candidate);
|
|
@@ -6317,12 +6363,12 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
6317
6363
|
const scored = [];
|
|
6318
6364
|
for (const file of manifest.files) {
|
|
6319
6365
|
if (isTest(file) && !wantsTests) continue;
|
|
6320
|
-
const
|
|
6321
|
-
const words =
|
|
6366
|
+
const path17 = file.relativePath.toLowerCase();
|
|
6367
|
+
const words = path17.split(/[^a-z0-9_]+/).filter((word) => word.length >= 3);
|
|
6322
6368
|
let score = 0;
|
|
6323
6369
|
const reasons = [];
|
|
6324
6370
|
for (const term of terms) {
|
|
6325
|
-
if (
|
|
6371
|
+
if (path17.includes(term)) {
|
|
6326
6372
|
score += 8;
|
|
6327
6373
|
reasons.push("path:" + term);
|
|
6328
6374
|
continue;
|
|
@@ -6551,7 +6597,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6551
6597
|
const descriptions = [];
|
|
6552
6598
|
if (request.changedSince !== void 0) {
|
|
6553
6599
|
assertUsableRef(request.changedSince);
|
|
6554
|
-
for (const
|
|
6600
|
+
for (const path17 of gitPaths(cwd, [
|
|
6555
6601
|
"diff",
|
|
6556
6602
|
"--name-only",
|
|
6557
6603
|
"-z",
|
|
@@ -6559,9 +6605,9 @@ function resolveChangedScope(cwd, request) {
|
|
|
6559
6605
|
`${request.changedSince}...HEAD`,
|
|
6560
6606
|
"--"
|
|
6561
6607
|
])) {
|
|
6562
|
-
paths.add(
|
|
6608
|
+
paths.add(path17);
|
|
6563
6609
|
}
|
|
6564
|
-
for (const
|
|
6610
|
+
for (const path17 of gitPaths(cwd, [
|
|
6565
6611
|
"diff",
|
|
6566
6612
|
"--name-only",
|
|
6567
6613
|
"-z",
|
|
@@ -6569,15 +6615,15 @@ function resolveChangedScope(cwd, request) {
|
|
|
6569
6615
|
"HEAD",
|
|
6570
6616
|
"--"
|
|
6571
6617
|
])) {
|
|
6572
|
-
paths.add(
|
|
6618
|
+
paths.add(path17);
|
|
6573
6619
|
}
|
|
6574
|
-
for (const
|
|
6575
|
-
paths.add(
|
|
6620
|
+
for (const path17 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
6621
|
+
paths.add(path17);
|
|
6576
6622
|
}
|
|
6577
6623
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
6578
6624
|
}
|
|
6579
6625
|
if (request.staged === true) {
|
|
6580
|
-
for (const
|
|
6626
|
+
for (const path17 of gitPaths(cwd, [
|
|
6581
6627
|
"diff",
|
|
6582
6628
|
"--cached",
|
|
6583
6629
|
"--name-only",
|
|
@@ -6585,10 +6631,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
6585
6631
|
"--relative",
|
|
6586
6632
|
"--"
|
|
6587
6633
|
])) {
|
|
6588
|
-
paths.add(
|
|
6589
|
-
stagedPaths.add(
|
|
6634
|
+
paths.add(path17);
|
|
6635
|
+
stagedPaths.add(path17);
|
|
6590
6636
|
}
|
|
6591
|
-
for (const
|
|
6637
|
+
for (const path17 of gitPaths(cwd, [
|
|
6592
6638
|
"diff",
|
|
6593
6639
|
"--cached",
|
|
6594
6640
|
"--name-only",
|
|
@@ -6597,7 +6643,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
6597
6643
|
"--diff-filter=D",
|
|
6598
6644
|
"--"
|
|
6599
6645
|
])) {
|
|
6600
|
-
deletedPaths.add(
|
|
6646
|
+
deletedPaths.add(path17);
|
|
6601
6647
|
}
|
|
6602
6648
|
descriptions.push("staged");
|
|
6603
6649
|
}
|
|
@@ -6638,7 +6684,7 @@ function tsconfigPathsFor(cwd) {
|
|
|
6638
6684
|
const configPath = path6__namespace.join(cwd, "tsconfig.json");
|
|
6639
6685
|
let stats;
|
|
6640
6686
|
try {
|
|
6641
|
-
stats =
|
|
6687
|
+
stats = fs3__namespace.statSync(configPath);
|
|
6642
6688
|
} catch (err) {
|
|
6643
6689
|
if (err.code === "ENOENT") return null;
|
|
6644
6690
|
return null;
|
|
@@ -6672,8 +6718,8 @@ function tsconfigPathsFor(cwd) {
|
|
|
6672
6718
|
return value;
|
|
6673
6719
|
}
|
|
6674
6720
|
function repositoryRelative(cwd, target) {
|
|
6675
|
-
const
|
|
6676
|
-
return
|
|
6721
|
+
const relative10 = path6__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
6722
|
+
return relative10.length === 0 || !relative10.startsWith("..") && !path6__namespace.isAbsolute(relative10) ? relative10 : null;
|
|
6677
6723
|
}
|
|
6678
6724
|
function rememberFirst(map, key, value) {
|
|
6679
6725
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -6883,7 +6929,7 @@ function findStagingDirectory(config) {
|
|
|
6883
6929
|
const tmpDir = path6__namespace.resolve(config.cwd, config.tmpDir);
|
|
6884
6930
|
let entries;
|
|
6885
6931
|
try {
|
|
6886
|
-
entries =
|
|
6932
|
+
entries = fs3__namespace.readdirSync(tmpDir);
|
|
6887
6933
|
} catch {
|
|
6888
6934
|
return null;
|
|
6889
6935
|
}
|
|
@@ -6896,8 +6942,8 @@ function describeMissingManifest(config, manifestPath) {
|
|
|
6896
6942
|
const markerPath = path6__namespace.join(outDir, ".codebase-snapshot");
|
|
6897
6943
|
let marker = null;
|
|
6898
6944
|
try {
|
|
6899
|
-
if (
|
|
6900
|
-
const parsed = JSON.parse(
|
|
6945
|
+
if (fs3__namespace.existsSync(markerPath)) {
|
|
6946
|
+
const parsed = JSON.parse(fs3__namespace.readFileSync(markerPath, "utf8"));
|
|
6901
6947
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
6902
6948
|
marker = parsed;
|
|
6903
6949
|
}
|
|
@@ -6934,11 +6980,11 @@ function sha256Hex(buffer) {
|
|
|
6934
6980
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
6935
6981
|
const absolutePath = path6__namespace.join(cwd, relativePath);
|
|
6936
6982
|
try {
|
|
6937
|
-
const stats =
|
|
6983
|
+
const stats = fs3__namespace.statSync(absolutePath);
|
|
6938
6984
|
if (!stats.isFile()) return false;
|
|
6939
6985
|
if (isBinaryExtension(absolutePath)) return false;
|
|
6940
6986
|
if (stats.size > BINARY_SCAN_BYTES && isBinaryFile(absolutePath)) return false;
|
|
6941
|
-
return !decodeText(
|
|
6987
|
+
return !decodeText(fs3__namespace.readFileSync(absolutePath)).binary;
|
|
6942
6988
|
} catch {
|
|
6943
6989
|
return false;
|
|
6944
6990
|
}
|
|
@@ -7171,7 +7217,7 @@ function validateSnapshot(configInput) {
|
|
|
7171
7217
|
assertUsableConfigInput(configInput);
|
|
7172
7218
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput);
|
|
7173
7219
|
const manifestPath = path6__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
7174
|
-
if (!
|
|
7220
|
+
if (!fs3__namespace.existsSync(manifestPath)) {
|
|
7175
7221
|
return {
|
|
7176
7222
|
valid: false,
|
|
7177
7223
|
manifestPresent: false,
|
|
@@ -7182,7 +7228,7 @@ function validateSnapshot(configInput) {
|
|
|
7182
7228
|
}
|
|
7183
7229
|
let manifest;
|
|
7184
7230
|
try {
|
|
7185
|
-
manifest = JSON.parse(
|
|
7231
|
+
manifest = JSON.parse(fs3__namespace.readFileSync(manifestPath, "utf8"));
|
|
7186
7232
|
} catch (err) {
|
|
7187
7233
|
return {
|
|
7188
7234
|
valid: false,
|
|
@@ -7326,12 +7372,16 @@ function validateSnapshot(configInput) {
|
|
|
7326
7372
|
// discovery mode" meant `validate` could enumerate files one way while the snapshot
|
|
7327
7373
|
// had been generated another way, and then blame the difference on drift.
|
|
7328
7374
|
discovery: config.discovery,
|
|
7375
|
+
// `generate --staged` adds index-only paths to the candidate list. Without the same
|
|
7376
|
+
// extra paths, a staged file that is absent from the working tree was invisible to
|
|
7377
|
+
// this scan and then reported as deleted, although the snapshot matched the index.
|
|
7378
|
+
...stagedScope === null ? {} : { extraPaths: [...stagedScope] },
|
|
7329
7379
|
// The same exclusion `generate` applies: without it, `validate` recounted the tool's
|
|
7330
7380
|
// own output directory as a set of files missing from the snapshot, so a correct
|
|
7331
7381
|
// snapshot was reported as drifting.
|
|
7332
7382
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
7333
7383
|
(directory) => path6__namespace.relative(config.cwd, path6__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
7334
|
-
).filter((
|
|
7384
|
+
).filter((relative10) => relative10.length > 0 && !relative10.startsWith(".."))
|
|
7335
7385
|
});
|
|
7336
7386
|
for (const diskFile of collection.files) {
|
|
7337
7387
|
const snapshotHash = manifestFileMap.get(diskFile);
|
|
@@ -7358,7 +7408,7 @@ function validateSnapshot(configInput) {
|
|
|
7358
7408
|
let diskHash;
|
|
7359
7409
|
try {
|
|
7360
7410
|
const stagedBlob = recordedStaged && stagedScope?.has(diskFile) === true ? readStagedBlob(config.cwd, diskFile) : null;
|
|
7361
|
-
diskHash = sha256Hex(stagedBlob ??
|
|
7411
|
+
diskHash = sha256Hex(stagedBlob ?? fs3__namespace.readFileSync(path6__namespace.join(config.cwd, diskFile)));
|
|
7362
7412
|
} catch (err) {
|
|
7363
7413
|
if (err.code === "ENOENT") {
|
|
7364
7414
|
drift.missingOnDisk.push(diskFile);
|
|
@@ -7372,6 +7422,12 @@ function validateSnapshot(configInput) {
|
|
|
7372
7422
|
}
|
|
7373
7423
|
}
|
|
7374
7424
|
for (const snapshotFile of manifestFileMap.keys()) {
|
|
7425
|
+
if (recordedStaged && stagedScope?.has(snapshotFile)) {
|
|
7426
|
+
if (readStagedBlob(config.cwd, snapshotFile) === null) {
|
|
7427
|
+
drift.missingOnDisk.push(snapshotFile);
|
|
7428
|
+
}
|
|
7429
|
+
continue;
|
|
7430
|
+
}
|
|
7375
7431
|
const confined = confineToDirectory(config.cwd, snapshotFile);
|
|
7376
7432
|
if (confined === null) {
|
|
7377
7433
|
drift.partIssues.push({
|
|
@@ -7382,7 +7438,7 @@ function validateSnapshot(configInput) {
|
|
|
7382
7438
|
}
|
|
7383
7439
|
let statFailure = null;
|
|
7384
7440
|
try {
|
|
7385
|
-
|
|
7441
|
+
fs3__namespace.statSync(confined);
|
|
7386
7442
|
} catch (err) {
|
|
7387
7443
|
statFailure = err;
|
|
7388
7444
|
}
|
|
@@ -7417,7 +7473,7 @@ function validateSnapshot(configInput) {
|
|
|
7417
7473
|
}
|
|
7418
7474
|
let buffer;
|
|
7419
7475
|
try {
|
|
7420
|
-
buffer =
|
|
7476
|
+
buffer = fs3__namespace.readFileSync(partPath);
|
|
7421
7477
|
} catch {
|
|
7422
7478
|
drift.partIssues.push({ part: part.filename, issue: "missing from snapshot/parts" });
|
|
7423
7479
|
continue;
|
|
@@ -7797,8 +7853,8 @@ function validateSnapshot(configInput) {
|
|
|
7797
7853
|
const artifactPath = path6__namespace.join(snapshotDir, ...key.split("/"));
|
|
7798
7854
|
let buffer;
|
|
7799
7855
|
try {
|
|
7800
|
-
if (!
|
|
7801
|
-
buffer =
|
|
7856
|
+
if (!fs3__namespace.statSync(artifactPath).isFile()) throw new Error("not a regular file");
|
|
7857
|
+
buffer = fs3__namespace.readFileSync(artifactPath);
|
|
7802
7858
|
} catch {
|
|
7803
7859
|
drift.partIssues.push({ part: key, issue: "declared artifact is missing" });
|
|
7804
7860
|
continue;
|
|
@@ -7812,8 +7868,8 @@ function validateSnapshot(configInput) {
|
|
|
7812
7868
|
const target = match[1].split("#")[0];
|
|
7813
7869
|
if (target.length === 0 || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
7814
7870
|
const resolved = path6__namespace.resolve(snapshotDir, "reports", target);
|
|
7815
|
-
const
|
|
7816
|
-
if (
|
|
7871
|
+
const relative10 = path6__namespace.relative(snapshotDir, resolved);
|
|
7872
|
+
if (relative10.startsWith("..") || path6__namespace.isAbsolute(relative10) || !fs3__namespace.existsSync(resolved)) {
|
|
7817
7873
|
drift.partIssues.push({
|
|
7818
7874
|
part: key,
|
|
7819
7875
|
issue: `links to ${maskedPath(target, config.secretRules)}, which does not exist in the snapshot`
|
|
@@ -7826,7 +7882,7 @@ function validateSnapshot(configInput) {
|
|
|
7826
7882
|
if (sarifArtifact) {
|
|
7827
7883
|
const sarifKey = "reports/audit.sarif";
|
|
7828
7884
|
try {
|
|
7829
|
-
const buffer =
|
|
7885
|
+
const buffer = fs3__namespace.readFileSync(path6__namespace.join(snapshotDir, "reports", "audit.sarif"));
|
|
7830
7886
|
if (sha256Hex(buffer) !== sarifArtifact.sha256 || buffer.length !== sarifArtifact.byteSize) {
|
|
7831
7887
|
drift.partIssues.push({ part: sarifKey, issue: "artifact does not match its recorded digest" });
|
|
7832
7888
|
}
|
|
@@ -7873,7 +7929,7 @@ function validateSnapshot(configInput) {
|
|
|
7873
7929
|
);
|
|
7874
7930
|
}
|
|
7875
7931
|
const signaturePath = path6__namespace.join(path6__namespace.dirname(manifestPath), "signature.json");
|
|
7876
|
-
if (
|
|
7932
|
+
if (fs3__namespace.existsSync(signaturePath)) {
|
|
7877
7933
|
const outcome = verifySnapshotSignature(path6__namespace.dirname(manifestPath));
|
|
7878
7934
|
if (!outcome.ok) errors.push("signature: " + outcome.reason + ".");
|
|
7879
7935
|
}
|
|
@@ -7930,11 +7986,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
|
7930
7986
|
function createWriter(output) {
|
|
7931
7987
|
return {
|
|
7932
7988
|
write(value) {
|
|
7933
|
-
return new Promise((
|
|
7989
|
+
return new Promise((resolve11, reject) => {
|
|
7934
7990
|
output.write(`${JSON.stringify(value)}
|
|
7935
7991
|
`, (error) => {
|
|
7936
7992
|
if (error) reject(error);
|
|
7937
|
-
else
|
|
7993
|
+
else resolve11();
|
|
7938
7994
|
});
|
|
7939
7995
|
});
|
|
7940
7996
|
}
|
|
@@ -8252,8 +8308,8 @@ function findSection(sections, relativePath) {
|
|
|
8252
8308
|
if (exact) return exact;
|
|
8253
8309
|
const foldedPath = rendered.toLowerCase();
|
|
8254
8310
|
const folded = sections.filter((section) => {
|
|
8255
|
-
const
|
|
8256
|
-
return
|
|
8311
|
+
const path17 = section.path.toLowerCase();
|
|
8312
|
+
return path17 === relativePath.toLowerCase() || path17 === foldedPath;
|
|
8257
8313
|
});
|
|
8258
8314
|
return folded.length === 1 ? folded[0] : null;
|
|
8259
8315
|
}
|
|
@@ -8280,14 +8336,14 @@ function sha256(buffer) {
|
|
|
8280
8336
|
}
|
|
8281
8337
|
function readBytes(file) {
|
|
8282
8338
|
try {
|
|
8283
|
-
return
|
|
8339
|
+
return fs3__namespace.readFileSync(file);
|
|
8284
8340
|
} catch {
|
|
8285
8341
|
return null;
|
|
8286
8342
|
}
|
|
8287
8343
|
}
|
|
8288
8344
|
function readText(file) {
|
|
8289
8345
|
try {
|
|
8290
|
-
return
|
|
8346
|
+
return fs3__namespace.readFileSync(file, "utf8");
|
|
8291
8347
|
} catch {
|
|
8292
8348
|
return null;
|
|
8293
8349
|
}
|
|
@@ -8304,15 +8360,15 @@ function readJson(file) {
|
|
|
8304
8360
|
function walk(dir, prefix = "") {
|
|
8305
8361
|
let entries;
|
|
8306
8362
|
try {
|
|
8307
|
-
entries =
|
|
8363
|
+
entries = fs3__namespace.readdirSync(dir, { withFileTypes: true });
|
|
8308
8364
|
} catch {
|
|
8309
8365
|
return [];
|
|
8310
8366
|
}
|
|
8311
8367
|
const files = [];
|
|
8312
8368
|
for (const entry of entries) {
|
|
8313
|
-
const
|
|
8314
|
-
if (entry.isDirectory()) files.push(...walk(path6__namespace.join(dir, entry.name),
|
|
8315
|
-
else if (entry.isFile()) files.push(
|
|
8369
|
+
const relative10 = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
8370
|
+
if (entry.isDirectory()) files.push(...walk(path6__namespace.join(dir, entry.name), relative10));
|
|
8371
|
+
else if (entry.isFile()) files.push(relative10);
|
|
8316
8372
|
}
|
|
8317
8373
|
return files;
|
|
8318
8374
|
}
|
|
@@ -8352,9 +8408,9 @@ function secretTokens(text) {
|
|
|
8352
8408
|
}
|
|
8353
8409
|
function readArtifactTexts(snapshotDir) {
|
|
8354
8410
|
const texts = [];
|
|
8355
|
-
for (const
|
|
8356
|
-
if (!TEXT_ARTIFACT.test(
|
|
8357
|
-
const text = readText(path6__namespace.join(snapshotDir,
|
|
8411
|
+
for (const relative10 of walk(snapshotDir)) {
|
|
8412
|
+
if (!TEXT_ARTIFACT.test(relative10)) continue;
|
|
8413
|
+
const text = readText(path6__namespace.join(snapshotDir, relative10));
|
|
8358
8414
|
if (text !== null) texts.push(text);
|
|
8359
8415
|
}
|
|
8360
8416
|
return texts;
|
|
@@ -8370,15 +8426,15 @@ function findHostPaths(snapshotDir, repoDir) {
|
|
|
8370
8426
|
];
|
|
8371
8427
|
const repoPattern = new RegExp(escapeRegExp(repoDir), "g");
|
|
8372
8428
|
const hits = /* @__PURE__ */ new Set();
|
|
8373
|
-
for (const
|
|
8374
|
-
if (!TEXT_ARTIFACT.test(
|
|
8375
|
-
const text = readText(path6__namespace.join(snapshotDir,
|
|
8429
|
+
for (const relative10 of walk(snapshotDir)) {
|
|
8430
|
+
if (!TEXT_ARTIFACT.test(relative10)) continue;
|
|
8431
|
+
const text = readText(path6__namespace.join(snapshotDir, relative10));
|
|
8376
8432
|
if (text === null) continue;
|
|
8377
8433
|
for (const pattern of patterns) {
|
|
8378
|
-
for (const match of text.match(pattern) ?? []) hits.add(
|
|
8434
|
+
for (const match of text.match(pattern) ?? []) hits.add(relative10 + ": " + match);
|
|
8379
8435
|
}
|
|
8380
8436
|
repoPattern.lastIndex = 0;
|
|
8381
|
-
if (repoPattern.test(text)) hits.add(
|
|
8437
|
+
if (repoPattern.test(text)) hits.add(relative10 + ": the repository absolute path");
|
|
8382
8438
|
}
|
|
8383
8439
|
return [...hits];
|
|
8384
8440
|
}
|
|
@@ -8625,13 +8681,13 @@ function auditSnapshot(options) {
|
|
|
8625
8681
|
let artifactCount = 0;
|
|
8626
8682
|
for (const [key, value] of Object.entries(artifacts)) {
|
|
8627
8683
|
if (value === null || value === void 0) continue;
|
|
8628
|
-
const
|
|
8629
|
-
if (
|
|
8684
|
+
const relative10 = ARTIFACT_FILES[key];
|
|
8685
|
+
if (relative10 === void 0) continue;
|
|
8630
8686
|
artifactCount += 1;
|
|
8631
|
-
const bytes = readBytes(path6__namespace.join(snapshotDir,
|
|
8632
|
-
if (bytes === null) artifactProblems.push(
|
|
8687
|
+
const bytes = readBytes(path6__namespace.join(snapshotDir, relative10));
|
|
8688
|
+
if (bytes === null) artifactProblems.push(relative10 + " is missing");
|
|
8633
8689
|
else if (typeof value.sha256 === "string" && sha256(bytes) !== value.sha256) {
|
|
8634
|
-
artifactProblems.push(
|
|
8690
|
+
artifactProblems.push(relative10 + " changed");
|
|
8635
8691
|
}
|
|
8636
8692
|
}
|
|
8637
8693
|
checks.push(
|
|
@@ -8676,7 +8732,7 @@ function auditSnapshot(options) {
|
|
|
8676
8732
|
)
|
|
8677
8733
|
);
|
|
8678
8734
|
const signaturePath = path6__namespace.join(snapshotDir, "signature.json");
|
|
8679
|
-
if (
|
|
8735
|
+
if (fs3__namespace.existsSync(signaturePath)) {
|
|
8680
8736
|
const outcome = verifySnapshotSignature(snapshotDir);
|
|
8681
8737
|
checks.push(
|
|
8682
8738
|
outcome.ok ? check(
|
|
@@ -9050,8 +9106,8 @@ function auditSnapshot(options) {
|
|
|
9050
9106
|
for (const file of manifest.files) {
|
|
9051
9107
|
if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
|
|
9052
9108
|
}
|
|
9053
|
-
for (const
|
|
9054
|
-
if (!known2.has(
|
|
9109
|
+
for (const path17 of packed) {
|
|
9110
|
+
if (!known2.has(path17)) problems.push(path17 + " is in the pack but not the manifest");
|
|
9055
9111
|
}
|
|
9056
9112
|
}
|
|
9057
9113
|
}
|
|
@@ -9087,7 +9143,7 @@ function auditSnapshot(options) {
|
|
|
9087
9143
|
bodyByPath.set(file.relativePath, section.body);
|
|
9088
9144
|
bodiesChecked += 1;
|
|
9089
9145
|
const bytes = Buffer.byteLength(section.body, "utf8");
|
|
9090
|
-
const bodyLines =
|
|
9146
|
+
const bodyLines = countBodyLines(section.body);
|
|
9091
9147
|
if (bytes !== file.includedBytes) {
|
|
9092
9148
|
bodyProblems.push(file.relativePath + ": manifest says " + file.includedBytes + " B, part holds " + bytes + " B");
|
|
9093
9149
|
} else if (bodyLines !== file.includedLines) {
|
|
@@ -9304,7 +9360,7 @@ function auditSnapshot(options) {
|
|
|
9304
9360
|
}
|
|
9305
9361
|
const indexParent = path6__namespace.dirname(snapshotDir);
|
|
9306
9362
|
const indexPath = path6__namespace.join(indexParent, "WORKSPACE.json");
|
|
9307
|
-
if (
|
|
9363
|
+
if (fs3__namespace.existsSync(indexPath)) {
|
|
9308
9364
|
const indexText = readText(indexPath);
|
|
9309
9365
|
let members = [];
|
|
9310
9366
|
let problem2 = null;
|
|
@@ -9339,7 +9395,7 @@ function auditSnapshot(options) {
|
|
|
9339
9395
|
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
9340
9396
|
disagreements.push("file count");
|
|
9341
9397
|
}
|
|
9342
|
-
const sourceGone = typeof member.path === "string" && !
|
|
9398
|
+
const sourceGone = typeof member.path === "string" && !fs3__namespace.existsSync(member.path) ? "Member " + memberName + " source directory is gone (" + member.path + "); the snapshot still describes it. Regenerate the workspace." : null;
|
|
9343
9399
|
checks.push(
|
|
9344
9400
|
sourceGone !== null ? check("workspace.index", "The workspace index agrees with this member", "warning", "warn", sourceGone) : disagreements.length === 0 ? check(
|
|
9345
9401
|
"workspace.index",
|
|
@@ -9361,29 +9417,29 @@ function auditSnapshot(options) {
|
|
|
9361
9417
|
const scanBudget = options.maxScanBytes ?? 32 * 1024 * 1024;
|
|
9362
9418
|
const leakHits = [];
|
|
9363
9419
|
let scannedBytes = 0;
|
|
9364
|
-
for (const
|
|
9365
|
-
if (!TEXT_ARTIFACT.test(
|
|
9366
|
-
if (
|
|
9367
|
-
const text = readText(path6__namespace.join(snapshotDir,
|
|
9420
|
+
for (const relative10 of walk(snapshotDir)) {
|
|
9421
|
+
if (!TEXT_ARTIFACT.test(relative10) || scannedBytes > scanBudget) continue;
|
|
9422
|
+
if (relative10 === SIGNATURE_FILE) continue;
|
|
9423
|
+
const text = readText(path6__namespace.join(snapshotDir, relative10));
|
|
9368
9424
|
if (text === null) continue;
|
|
9369
9425
|
scannedBytes += Buffer.byteLength(text, "utf8");
|
|
9370
9426
|
let findingCount = 0;
|
|
9371
|
-
if (/^parts[\\/].*\.md$/i.test(
|
|
9427
|
+
if (/^parts[\\/].*\.md$/i.test(relative10)) {
|
|
9372
9428
|
let headerText = text;
|
|
9373
9429
|
for (const section of parsePartSections(text)) {
|
|
9374
9430
|
findingCount += scanAndRedactSecrets(section.body, rules, section.path).findings.length;
|
|
9375
9431
|
headerText = headerText.replace(section.body, "");
|
|
9376
9432
|
}
|
|
9377
|
-
findingCount += scanAndRedactSecrets(headerText, rules,
|
|
9433
|
+
findingCount += scanAndRedactSecrets(headerText, rules, relative10).findings.length;
|
|
9378
9434
|
} else {
|
|
9379
|
-
findingCount = scanAndRedactSecrets(text, rules,
|
|
9435
|
+
findingCount = scanAndRedactSecrets(text, rules, relative10).findings.length;
|
|
9380
9436
|
}
|
|
9381
9437
|
if (findingCount > 0) {
|
|
9382
|
-
leakHits.push(
|
|
9438
|
+
leakHits.push(relative10 + " (" + findingCount + " line(s))");
|
|
9383
9439
|
}
|
|
9384
9440
|
}
|
|
9385
9441
|
const signatureRecordPath = path6__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
9386
|
-
if (
|
|
9442
|
+
if (fs3__namespace.existsSync(signatureRecordPath)) {
|
|
9387
9443
|
const recordText = readText(signatureRecordPath);
|
|
9388
9444
|
if (recordText !== null) {
|
|
9389
9445
|
scannedBytes += Buffer.byteLength(recordText, "utf8");
|
|
@@ -9582,23 +9638,23 @@ function describeMatcher(matcher) {
|
|
|
9582
9638
|
function normalizeTarget(cwd, target) {
|
|
9583
9639
|
const resolvedCwd = path6__namespace.resolve(cwd);
|
|
9584
9640
|
const absolute = path6__namespace.resolve(resolvedCwd, target);
|
|
9585
|
-
const
|
|
9586
|
-
if (
|
|
9641
|
+
const relative10 = path6__namespace.relative(resolvedCwd, absolute);
|
|
9642
|
+
if (relative10 === "" || relative10 === ".." || relative10.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative10)) {
|
|
9587
9643
|
return { relative: target.replace(/\\/g, "/"), outsideRoot: true };
|
|
9588
9644
|
}
|
|
9589
|
-
return { relative:
|
|
9645
|
+
return { relative: relative10.split(path6__namespace.sep).join("/"), outsideRoot: false };
|
|
9590
9646
|
}
|
|
9591
9647
|
function findRuleMatch(rules, relativePath) {
|
|
9592
9648
|
return rules.find(
|
|
9593
9649
|
(rule) => matchRule(relativePath, rule.match)
|
|
9594
9650
|
);
|
|
9595
9651
|
}
|
|
9596
|
-
function findRecordedAncestor(skipped,
|
|
9652
|
+
function findRecordedAncestor(skipped, relative10, maskedPath2) {
|
|
9597
9653
|
let nearest;
|
|
9598
9654
|
for (const record of skipped) {
|
|
9599
9655
|
const ancestorPath = record.path;
|
|
9600
9656
|
if (ancestorPath.length === 0) continue;
|
|
9601
|
-
const isAncestor =
|
|
9657
|
+
const isAncestor = relative10.startsWith(`${ancestorPath}/`) || maskedPath2.startsWith(`${ancestorPath}/`);
|
|
9602
9658
|
if (!isAncestor) continue;
|
|
9603
9659
|
if (!nearest || ancestorPath.length > nearest.path.length) nearest = record;
|
|
9604
9660
|
}
|
|
@@ -9607,15 +9663,15 @@ function findRecordedAncestor(skipped, relative9, maskedPath2) {
|
|
|
9607
9663
|
function readManifest2(config) {
|
|
9608
9664
|
const manifestPath = path6__namespace.resolve(config.cwd, config.outDir, "manifest.json");
|
|
9609
9665
|
try {
|
|
9610
|
-
return JSON.parse(
|
|
9666
|
+
return JSON.parse(fs3__namespace.readFileSync(manifestPath, "utf8"));
|
|
9611
9667
|
} catch {
|
|
9612
9668
|
return null;
|
|
9613
9669
|
}
|
|
9614
9670
|
}
|
|
9615
9671
|
function explainPath(config, target) {
|
|
9616
9672
|
const normalized = normalizeTarget(config.cwd, target);
|
|
9617
|
-
const
|
|
9618
|
-
const maskedPath2 = findSecretInPath(
|
|
9673
|
+
const relative10 = normalized.relative;
|
|
9674
|
+
const maskedPath2 = findSecretInPath(relative10, config.secretRules)?.masked ?? relative10;
|
|
9619
9675
|
if (normalized.outsideRoot) {
|
|
9620
9676
|
return {
|
|
9621
9677
|
path: maskedPath2,
|
|
@@ -9625,10 +9681,10 @@ function explainPath(config, target) {
|
|
|
9625
9681
|
detail: "path resolves outside the configured repository root and was not inspected"
|
|
9626
9682
|
};
|
|
9627
9683
|
}
|
|
9628
|
-
const absolute = path6__namespace.join(config.cwd,
|
|
9684
|
+
const absolute = path6__namespace.join(config.cwd, relative10);
|
|
9629
9685
|
const result = {
|
|
9630
9686
|
path: maskedPath2,
|
|
9631
|
-
exists:
|
|
9687
|
+
exists: fs3__namespace.existsSync(absolute),
|
|
9632
9688
|
included: false
|
|
9633
9689
|
};
|
|
9634
9690
|
const collection = collectFiles(config.cwd, {
|
|
@@ -9643,11 +9699,11 @@ function explainPath(config, target) {
|
|
|
9643
9699
|
// that is only missing because the walker dropped the tool's own output directory.
|
|
9644
9700
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
9645
9701
|
(directory) => path6__namespace.relative(config.cwd, path6__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
9646
|
-
).filter((
|
|
9702
|
+
).filter((relative11) => relative11.length > 0 && !relative11.startsWith(".."))
|
|
9647
9703
|
});
|
|
9648
|
-
if (!collection.files.includes(
|
|
9704
|
+
if (!collection.files.includes(relative10)) {
|
|
9649
9705
|
const record = collection.skipped.find(
|
|
9650
|
-
(entry2) => entry2.path ===
|
|
9706
|
+
(entry2) => entry2.path === relative10 || entry2.path === maskedPath2
|
|
9651
9707
|
);
|
|
9652
9708
|
if (record) {
|
|
9653
9709
|
result.reason = record.reason;
|
|
@@ -9656,7 +9712,7 @@ function explainPath(config, target) {
|
|
|
9656
9712
|
result.reason = "missing";
|
|
9657
9713
|
result.detail = "no such file or directory, relative to the configured cwd";
|
|
9658
9714
|
} else {
|
|
9659
|
-
const ancestor = findRecordedAncestor(collection.skipped,
|
|
9715
|
+
const ancestor = findRecordedAncestor(collection.skipped, relative10, maskedPath2);
|
|
9660
9716
|
if (ancestor) {
|
|
9661
9717
|
result.reason = ancestor.reason;
|
|
9662
9718
|
result.detail = ancestor.detail ? `${ancestor.detail} \u2014 inherited from the skipped directory \`${ancestor.path}\`` : `inside the skipped directory \`${ancestor.path}\``;
|
|
@@ -9676,11 +9732,11 @@ function explainPath(config, target) {
|
|
|
9676
9732
|
...config.changedSince === void 0 ? {} : { changedSince: config.changedSince },
|
|
9677
9733
|
...config.staged === true ? { staged: true } : {}
|
|
9678
9734
|
});
|
|
9679
|
-
inScope = scope.paths.has(
|
|
9735
|
+
inScope = scope.paths.has(relative10);
|
|
9680
9736
|
if (!inScope && config.withDependents === true) {
|
|
9681
9737
|
inScope = importsChangedFile(
|
|
9682
|
-
|
|
9683
|
-
importsOfFile(
|
|
9738
|
+
relative10,
|
|
9739
|
+
importsOfFile(relative10, absolute),
|
|
9684
9740
|
scope.paths,
|
|
9685
9741
|
buildImportResolver(collection.files.map((file) => ({ relativePath: file })), {
|
|
9686
9742
|
tsconfig: tsconfigPathsFor(config.cwd)
|
|
@@ -9709,7 +9765,7 @@ function explainPath(config, target) {
|
|
|
9709
9765
|
}
|
|
9710
9766
|
let sizeOnDisk = null;
|
|
9711
9767
|
try {
|
|
9712
|
-
sizeOnDisk =
|
|
9768
|
+
sizeOnDisk = fs3__namespace.statSync(absolute).size;
|
|
9713
9769
|
} catch {
|
|
9714
9770
|
sizeOnDisk = null;
|
|
9715
9771
|
}
|
|
@@ -9719,10 +9775,10 @@ function explainPath(config, target) {
|
|
|
9719
9775
|
result.detail = "binary content; generate skips it and records `binary` in manifest.skipped[]";
|
|
9720
9776
|
return result;
|
|
9721
9777
|
}
|
|
9722
|
-
if (
|
|
9778
|
+
if (fs3__namespace.existsSync(absolute) && fs3__namespace.statSync(absolute).isFile()) {
|
|
9723
9779
|
let buffer;
|
|
9724
9780
|
try {
|
|
9725
|
-
buffer =
|
|
9781
|
+
buffer = fs3__namespace.readFileSync(absolute);
|
|
9726
9782
|
} catch (err) {
|
|
9727
9783
|
result.included = false;
|
|
9728
9784
|
result.reason = "read-error";
|
|
@@ -9740,15 +9796,15 @@ function explainPath(config, target) {
|
|
|
9740
9796
|
result.bytes = buffer.length;
|
|
9741
9797
|
result.lines = countLines(text);
|
|
9742
9798
|
if (decoded.encoding !== "utf-8") result.encoding = decoded.encoding;
|
|
9743
|
-
const { findings } = scanAndRedactSecrets(text, config.secretRules,
|
|
9799
|
+
const { findings } = scanAndRedactSecrets(text, config.secretRules, relative10);
|
|
9744
9800
|
result.secretCount = findings.length;
|
|
9745
9801
|
result.secrets = findings.slice(0, 20).map((finding) => ({ rules: finding.rules, line: finding.line }));
|
|
9746
9802
|
let inclusionMode = "full";
|
|
9747
|
-
if (config.skeleton === true && isSkeletonizable(
|
|
9748
|
-
const skeleton = skeletonizeTypeScript(text,
|
|
9803
|
+
if (config.skeleton === true && isSkeletonizable(relative10)) {
|
|
9804
|
+
const skeleton = skeletonizeTypeScript(text, relative10);
|
|
9749
9805
|
if (skeleton.collapsed > 0) inclusionMode = "signatures";
|
|
9750
9806
|
}
|
|
9751
|
-
if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(
|
|
9807
|
+
if (inclusionMode === "full" && config.stripComments === true && isCommentStrippable(relative10) && stripComments2(text, relative10).removed > 0) {
|
|
9752
9808
|
inclusionMode = "comments-stripped";
|
|
9753
9809
|
}
|
|
9754
9810
|
if (inclusionMode !== "signatures" && buffer.length > config.largeFileBytes) {
|
|
@@ -9757,18 +9813,18 @@ function explainPath(config, target) {
|
|
|
9757
9813
|
}
|
|
9758
9814
|
result.inclusionMode = inclusionMode;
|
|
9759
9815
|
}
|
|
9760
|
-
result.layer = classifyLayer(
|
|
9761
|
-
result.kind = classifyKind(
|
|
9762
|
-
result.language = detectLanguage(
|
|
9763
|
-
const layerRule = findRuleMatch(config.layers,
|
|
9816
|
+
result.layer = classifyLayer(relative10, config.layers);
|
|
9817
|
+
result.kind = classifyKind(relative10, config.kinds);
|
|
9818
|
+
result.language = detectLanguage(relative10);
|
|
9819
|
+
const layerRule = findRuleMatch(config.layers, relative10);
|
|
9764
9820
|
if (layerRule) result.layerMatch = describeMatcher(layerRule.match);
|
|
9765
|
-
const kindRule = findRuleMatch(config.kinds,
|
|
9821
|
+
const kindRule = findRuleMatch(config.kinds, relative10);
|
|
9766
9822
|
if (kindRule) result.kindMatch = describeMatcher(kindRule.match);
|
|
9767
9823
|
const manifest = readManifest2(config);
|
|
9768
|
-
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath ===
|
|
9824
|
+
const entry = Array.isArray(manifest?.files) ? manifest.files.find((file) => file.relativePath === relative10) : void 0;
|
|
9769
9825
|
result.part = entry?.part ?? null;
|
|
9770
9826
|
if (entry === void 0) {
|
|
9771
|
-
const record = manifest?.skipped?.find((skip) => skip.path ===
|
|
9827
|
+
const record = manifest?.skipped?.find((skip) => skip.path === relative10);
|
|
9772
9828
|
if (record !== void 0 && (record.reason === "not-selected" || record.reason === "unchanged")) {
|
|
9773
9829
|
result.included = false;
|
|
9774
9830
|
result.reason = record.reason;
|
|
@@ -9873,7 +9929,7 @@ const { parentPort, workerData } = require("node:worker_threads");
|
|
|
9873
9929
|
})();
|
|
9874
9930
|
`;
|
|
9875
9931
|
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
9876
|
-
return new Promise((
|
|
9932
|
+
return new Promise((resolve11) => {
|
|
9877
9933
|
let settled = false;
|
|
9878
9934
|
let worker = null;
|
|
9879
9935
|
const finish = (result) => {
|
|
@@ -9884,7 +9940,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
9884
9940
|
if (!result.ok && options.runId !== void 0 && options.lockRoots !== void 0) {
|
|
9885
9941
|
releaseAbandonedRun(options.lockRoots, options.runId);
|
|
9886
9942
|
}
|
|
9887
|
-
|
|
9943
|
+
resolve11(result);
|
|
9888
9944
|
});
|
|
9889
9945
|
};
|
|
9890
9946
|
const isCjs = typeof __dirname !== "undefined";
|
|
@@ -9950,18 +10006,74 @@ function windowText(body, fromLine, lineCount) {
|
|
|
9950
10006
|
pastEnd
|
|
9951
10007
|
};
|
|
9952
10008
|
}
|
|
10009
|
+
function isInside2(parent, child) {
|
|
10010
|
+
const relative10 = path6__namespace.relative(parent, child);
|
|
10011
|
+
return relative10 === "" || !relative10.startsWith("..") && !path6__namespace.isAbsolute(relative10);
|
|
10012
|
+
}
|
|
10013
|
+
function readConfinedText(baseDir, relativePath) {
|
|
10014
|
+
if (relativePath.length === 0 || relativePath.includes("\0")) {
|
|
10015
|
+
return { ok: false, reason: "not-file", message: "the file name is empty or contains a NUL byte" };
|
|
10016
|
+
}
|
|
10017
|
+
if (path6__namespace.isAbsolute(relativePath)) {
|
|
10018
|
+
return { ok: false, reason: "outside", message: "an absolute path is not a snapshot-relative file" };
|
|
10019
|
+
}
|
|
10020
|
+
let baseReal;
|
|
10021
|
+
try {
|
|
10022
|
+
baseReal = fs3__namespace.realpathSync(path6__namespace.resolve(baseDir));
|
|
10023
|
+
} catch {
|
|
10024
|
+
return { ok: false, reason: "missing", message: "the snapshot directory does not exist" };
|
|
10025
|
+
}
|
|
10026
|
+
const candidate = path6__namespace.resolve(baseReal, relativePath);
|
|
10027
|
+
if (!isInside2(baseReal, candidate)) {
|
|
10028
|
+
return { ok: false, reason: "outside", message: "the path resolves outside the snapshot directory" };
|
|
10029
|
+
}
|
|
10030
|
+
let stats;
|
|
10031
|
+
try {
|
|
10032
|
+
stats = fs3__namespace.lstatSync(candidate);
|
|
10033
|
+
} catch (error) {
|
|
10034
|
+
const code = error.code;
|
|
10035
|
+
return {
|
|
10036
|
+
ok: false,
|
|
10037
|
+
reason: code === "ENOENT" || code === "ENOTDIR" ? "missing" : "unreadable",
|
|
10038
|
+
message: code === "ENOENT" || code === "ENOTDIR" ? "the file does not exist" : "the file could not be inspected"
|
|
10039
|
+
};
|
|
10040
|
+
}
|
|
10041
|
+
if (stats.isSymbolicLink()) {
|
|
10042
|
+
return { ok: false, reason: "not-file", message: "the file is a symbolic link" };
|
|
10043
|
+
}
|
|
10044
|
+
if (!stats.isFile()) {
|
|
10045
|
+
return { ok: false, reason: "not-file", message: "the path is not a regular file" };
|
|
10046
|
+
}
|
|
10047
|
+
let real;
|
|
10048
|
+
try {
|
|
10049
|
+
real = fs3__namespace.realpathSync(candidate);
|
|
10050
|
+
} catch {
|
|
10051
|
+
return { ok: false, reason: "unreadable", message: "the file could not be resolved" };
|
|
10052
|
+
}
|
|
10053
|
+
if (!isInside2(baseReal, real)) {
|
|
10054
|
+
return { ok: false, reason: "outside", message: "the file resolves outside the snapshot directory" };
|
|
10055
|
+
}
|
|
10056
|
+
try {
|
|
10057
|
+
const text = fs3__namespace.readFileSync(real, "utf8");
|
|
10058
|
+
return { ok: true, text, path: real, stats: fs3__namespace.statSync(real) };
|
|
10059
|
+
} catch {
|
|
10060
|
+
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
10061
|
+
}
|
|
10062
|
+
}
|
|
10063
|
+
|
|
10064
|
+
// src/mcp/workspace.ts
|
|
9953
10065
|
function foldForComparison(value) {
|
|
9954
10066
|
return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
9955
10067
|
}
|
|
9956
10068
|
function canonicalPath(value) {
|
|
9957
10069
|
const absolute = path6__namespace.resolve(value);
|
|
9958
10070
|
try {
|
|
9959
|
-
return
|
|
10071
|
+
return fs3__namespace.realpathSync(absolute);
|
|
9960
10072
|
} catch {
|
|
9961
10073
|
return absolute;
|
|
9962
10074
|
}
|
|
9963
10075
|
}
|
|
9964
|
-
function
|
|
10076
|
+
function isInside3(parent, child) {
|
|
9965
10077
|
const foldedParent = foldForComparison(parent);
|
|
9966
10078
|
const foldedChild = foldForComparison(child);
|
|
9967
10079
|
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path6__namespace.sep}`);
|
|
@@ -9969,7 +10081,7 @@ function isInside2(parent, child) {
|
|
|
9969
10081
|
function resolveThroughExistingAncestor(target) {
|
|
9970
10082
|
let existing = target;
|
|
9971
10083
|
const missing = [];
|
|
9972
|
-
while (!
|
|
10084
|
+
while (!fs3__namespace.existsSync(existing)) {
|
|
9973
10085
|
missing.unshift(path6__namespace.basename(existing));
|
|
9974
10086
|
const parent = path6__namespace.dirname(existing);
|
|
9975
10087
|
if (parent === existing) break;
|
|
@@ -9986,7 +10098,7 @@ function resolveRoot(requested, context) {
|
|
|
9986
10098
|
const absolute = path6__namespace.resolve(context.cwd, wanted);
|
|
9987
10099
|
let stats;
|
|
9988
10100
|
try {
|
|
9989
|
-
stats =
|
|
10101
|
+
stats = fs3__namespace.statSync(absolute);
|
|
9990
10102
|
} catch {
|
|
9991
10103
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
9992
10104
|
}
|
|
@@ -9995,7 +10107,7 @@ function resolveRoot(requested, context) {
|
|
|
9995
10107
|
}
|
|
9996
10108
|
const resolved = canonicalPath(absolute);
|
|
9997
10109
|
for (const allowed of context.roots) {
|
|
9998
|
-
if (
|
|
10110
|
+
if (isInside3(canonicalPath(allowed), resolved)) return { ok: true, root: resolved };
|
|
9999
10111
|
}
|
|
10000
10112
|
const shown = context.roots.join(", ");
|
|
10001
10113
|
return {
|
|
@@ -10039,7 +10151,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
10039
10151
|
const requested = overrides.outDir.trim();
|
|
10040
10152
|
const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
|
|
10041
10153
|
const resolved = resolveThroughExistingAncestor(path6__namespace.resolve(root, requested));
|
|
10042
|
-
if (!permitted.some((allowed) =>
|
|
10154
|
+
if (!permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) {
|
|
10043
10155
|
const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
|
|
10044
10156
|
return {
|
|
10045
10157
|
ok: false,
|
|
@@ -10061,6 +10173,14 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
10061
10173
|
if (overrides.sarif === true) cliOptions.sarif = true;
|
|
10062
10174
|
if (overrides.staged === true) cliOptions.staged = true;
|
|
10063
10175
|
if (overrides.withDependents === true) cliOptions.withDependents = true;
|
|
10176
|
+
for (const key of ["only", "ignore"]) {
|
|
10177
|
+
const value = overrides[key];
|
|
10178
|
+
if (value === void 0) continue;
|
|
10179
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
10180
|
+
return { ok: false, message: `"${key}" must be an array of glob strings.` };
|
|
10181
|
+
}
|
|
10182
|
+
cliOptions[key] = value;
|
|
10183
|
+
}
|
|
10064
10184
|
try {
|
|
10065
10185
|
const config = resolveConfig(loaded.config, cliOptions, root);
|
|
10066
10186
|
return {
|
|
@@ -10086,19 +10206,19 @@ function partPathFor(workspace, filename) {
|
|
|
10086
10206
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
10087
10207
|
const partsDir = path6__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
10088
10208
|
const resolved = path6__namespace.resolve(partsDir, filename);
|
|
10089
|
-
const
|
|
10090
|
-
if (
|
|
10209
|
+
const relative10 = path6__namespace.relative(partsDir, resolved);
|
|
10210
|
+
if (relative10.length === 0 || relative10.includes(path6__namespace.sep) || relative10.includes("/") || relative10.includes("\\") || path6__namespace.isAbsolute(relative10)) {
|
|
10091
10211
|
return null;
|
|
10092
10212
|
}
|
|
10093
10213
|
let stats;
|
|
10094
10214
|
try {
|
|
10095
|
-
stats =
|
|
10215
|
+
stats = fs3__namespace.lstatSync(resolved);
|
|
10096
10216
|
} catch {
|
|
10097
10217
|
return null;
|
|
10098
10218
|
}
|
|
10099
10219
|
if (!stats.isFile()) return null;
|
|
10100
10220
|
try {
|
|
10101
|
-
if (path6__namespace.dirname(
|
|
10221
|
+
if (path6__namespace.dirname(fs3__namespace.realpathSync(resolved)) !== fs3__namespace.realpathSync(partsDir)) return null;
|
|
10102
10222
|
} catch {
|
|
10103
10223
|
return null;
|
|
10104
10224
|
}
|
|
@@ -10107,30 +10227,27 @@ function partPathFor(workspace, filename) {
|
|
|
10107
10227
|
function readManifest3(workspace) {
|
|
10108
10228
|
const file = manifestPathFor(workspace);
|
|
10109
10229
|
const shown = path6__namespace.relative(workspace.root, file).split(path6__namespace.sep).join("/") || file;
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10230
|
+
const confined = readConfinedText(path6__namespace.dirname(file), path6__namespace.basename(file));
|
|
10231
|
+
if (!confined.ok) {
|
|
10232
|
+
if (confined.reason === "missing") {
|
|
10233
|
+
return {
|
|
10234
|
+
ok: false,
|
|
10235
|
+
missing: true,
|
|
10236
|
+
message: `There is no snapshot manifest at ${shown}. Call snapshot_plan to preview what would be included, or snapshot_generate to write it.`
|
|
10237
|
+
};
|
|
10238
|
+
}
|
|
10114
10239
|
return {
|
|
10115
10240
|
ok: false,
|
|
10116
|
-
missing:
|
|
10117
|
-
message:
|
|
10241
|
+
missing: false,
|
|
10242
|
+
message: `${shown} could not be read as a snapshot manifest: ${confined.message}.`
|
|
10118
10243
|
};
|
|
10119
10244
|
}
|
|
10245
|
+
const stats = confined.stats;
|
|
10246
|
+
const raw = confined.text;
|
|
10120
10247
|
const cached = manifestCache.get(file);
|
|
10121
10248
|
if (cached && cached.mtimeMs === stats.mtimeMs && cached.ctimeMs === stats.ctimeMs && cached.size === stats.size) {
|
|
10122
10249
|
return { ok: true, manifest: cached.manifest, file };
|
|
10123
10250
|
}
|
|
10124
|
-
let raw;
|
|
10125
|
-
try {
|
|
10126
|
-
raw = fs8__namespace.readFileSync(file, "utf8");
|
|
10127
|
-
} catch (error) {
|
|
10128
|
-
return {
|
|
10129
|
-
ok: false,
|
|
10130
|
-
missing: false,
|
|
10131
|
-
message: `${shown} exists but could not be read: ${error instanceof Error ? error.message : String(error)}`
|
|
10132
|
-
};
|
|
10133
|
-
}
|
|
10134
10251
|
let parsed;
|
|
10135
10252
|
try {
|
|
10136
10253
|
parsed = JSON.parse(raw);
|
|
@@ -10160,6 +10277,96 @@ function forgetManifest(file) {
|
|
|
10160
10277
|
manifestCache.delete(file);
|
|
10161
10278
|
}
|
|
10162
10279
|
|
|
10280
|
+
// src/security/regex.ts
|
|
10281
|
+
var MAX_PATTERN_LENGTH = 256;
|
|
10282
|
+
var MAX_QUANTIFIER_REPEAT = 1e4;
|
|
10283
|
+
function unsafeRegExpReason(source) {
|
|
10284
|
+
if (source.length === 0) return null;
|
|
10285
|
+
if (source.length > MAX_PATTERN_LENGTH) {
|
|
10286
|
+
return `the pattern is longer than ${MAX_PATTERN_LENGTH} characters`;
|
|
10287
|
+
}
|
|
10288
|
+
let inClass = false;
|
|
10289
|
+
let unbounded = 0;
|
|
10290
|
+
const groups = [];
|
|
10291
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
10292
|
+
const char = source[index];
|
|
10293
|
+
if (char === "\\") {
|
|
10294
|
+
index += 1;
|
|
10295
|
+
continue;
|
|
10296
|
+
}
|
|
10297
|
+
if (inClass) {
|
|
10298
|
+
if (char === "]") inClass = false;
|
|
10299
|
+
continue;
|
|
10300
|
+
}
|
|
10301
|
+
if (char === "[") {
|
|
10302
|
+
inClass = true;
|
|
10303
|
+
continue;
|
|
10304
|
+
}
|
|
10305
|
+
if (char === "(") {
|
|
10306
|
+
groups.push({ quantified: false, alternation: false });
|
|
10307
|
+
continue;
|
|
10308
|
+
}
|
|
10309
|
+
if (char === ")") {
|
|
10310
|
+
const group = groups.pop();
|
|
10311
|
+
if (group === void 0) continue;
|
|
10312
|
+
const next = source[index + 1];
|
|
10313
|
+
if (next === "*" || next === "+" || next === "{" && isUnboundedBrace(source, index + 1)) {
|
|
10314
|
+
if (group.quantified || group.alternation) {
|
|
10315
|
+
return "a quantified group contains another quantifier or an alternation";
|
|
10316
|
+
}
|
|
10317
|
+
}
|
|
10318
|
+
continue;
|
|
10319
|
+
}
|
|
10320
|
+
if (char === "|") {
|
|
10321
|
+
const group = groups[groups.length - 1];
|
|
10322
|
+
if (group !== void 0) group.alternation = true;
|
|
10323
|
+
continue;
|
|
10324
|
+
}
|
|
10325
|
+
if (char === "?") {
|
|
10326
|
+
const previous = source[index - 1];
|
|
10327
|
+
if (previous !== "(" && previous !== "?" && previous !== "*" && previous !== "+" && previous !== "}") {
|
|
10328
|
+
const group = groups[groups.length - 1];
|
|
10329
|
+
if (group !== void 0) group.quantified = true;
|
|
10330
|
+
}
|
|
10331
|
+
continue;
|
|
10332
|
+
}
|
|
10333
|
+
if (char === "*" || char === "+") {
|
|
10334
|
+
unbounded += 1;
|
|
10335
|
+
const group = groups[groups.length - 1];
|
|
10336
|
+
if (group !== void 0) group.quantified = true;
|
|
10337
|
+
continue;
|
|
10338
|
+
}
|
|
10339
|
+
if (char === "{") {
|
|
10340
|
+
const close = source.indexOf("}", index + 1);
|
|
10341
|
+
if (close === -1) continue;
|
|
10342
|
+
const body = source.slice(index + 1, close);
|
|
10343
|
+
const match = /^(\d+)(?:,(\d*))?$/.exec(body);
|
|
10344
|
+
if (match === null) {
|
|
10345
|
+
index = close;
|
|
10346
|
+
continue;
|
|
10347
|
+
}
|
|
10348
|
+
const max = match[2] === void 0 ? Number(match[1]) : match[2] === "" ? Infinity : Number(match[2]);
|
|
10349
|
+
if (max > MAX_QUANTIFIER_REPEAT) {
|
|
10350
|
+
return "a repetition bound is larger than the search budget can evaluate safely";
|
|
10351
|
+
}
|
|
10352
|
+
if (max === Infinity) unbounded += 1;
|
|
10353
|
+
const group = groups[groups.length - 1];
|
|
10354
|
+
if (group !== void 0) group.quantified = true;
|
|
10355
|
+
index = close;
|
|
10356
|
+
}
|
|
10357
|
+
}
|
|
10358
|
+
if (unbounded > 1) {
|
|
10359
|
+
return "the pattern has more than one unbounded repetition";
|
|
10360
|
+
}
|
|
10361
|
+
return null;
|
|
10362
|
+
}
|
|
10363
|
+
function isUnboundedBrace(source, start) {
|
|
10364
|
+
const close = source.indexOf("}", start + 1);
|
|
10365
|
+
if (close === -1) return false;
|
|
10366
|
+
const body = source.slice(start + 1, close);
|
|
10367
|
+
return /^\d+,$/.test(body);
|
|
10368
|
+
}
|
|
10369
|
+
|
|
10163
10370
|
// src/mcp/tools.ts
|
|
10164
10371
|
var MAX_SEARCH_BYTES = 4 * 1024 * 1024;
|
|
10165
10372
|
var READ_ONLY = {
|
|
@@ -10191,6 +10398,16 @@ var OUT_DIR_PROPERTY = {
|
|
|
10191
10398
|
};
|
|
10192
10399
|
var outDirOverride = (args) => ({ outDir: args.outDir });
|
|
10193
10400
|
var SCOPE_PROPERTIES = {
|
|
10401
|
+
only: {
|
|
10402
|
+
type: "array",
|
|
10403
|
+
items: { type: "string" },
|
|
10404
|
+
description: "Globs to include: replaces the config allow-list for this run."
|
|
10405
|
+
},
|
|
10406
|
+
ignore: {
|
|
10407
|
+
type: "array",
|
|
10408
|
+
items: { type: "string" },
|
|
10409
|
+
description: "Globs to exclude, added to the config deny-list for this run."
|
|
10410
|
+
},
|
|
10194
10411
|
maxPartTokens: {
|
|
10195
10412
|
type: "string",
|
|
10196
10413
|
description: 'Token ceiling per part, for example 32000 or "32k". Narrower than maxPartBytes; it converts at four bytes per token.'
|
|
@@ -10225,7 +10442,9 @@ function workspaceOverrides(args) {
|
|
|
10225
10442
|
sarif: args.sarif,
|
|
10226
10443
|
changedSince: args.changedSince,
|
|
10227
10444
|
staged: args.staged,
|
|
10228
|
-
withDependents: args.withDependents
|
|
10445
|
+
withDependents: args.withDependents,
|
|
10446
|
+
only: args.only,
|
|
10447
|
+
ignore: args.ignore
|
|
10229
10448
|
};
|
|
10230
10449
|
}
|
|
10231
10450
|
function failure(message) {
|
|
@@ -10261,11 +10480,11 @@ function toRelativePath(root, value) {
|
|
|
10261
10480
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
10262
10481
|
const resolvedRoot = path6__namespace.resolve(root);
|
|
10263
10482
|
const absolute = path6__namespace.resolve(resolvedRoot, cleaned);
|
|
10264
|
-
const
|
|
10265
|
-
if (
|
|
10483
|
+
const relative10 = path6__namespace.relative(resolvedRoot, absolute);
|
|
10484
|
+
if (relative10 === "" || relative10 === ".." || relative10.startsWith(`..${path6__namespace.sep}`) || path6__namespace.isAbsolute(relative10)) {
|
|
10266
10485
|
return null;
|
|
10267
10486
|
}
|
|
10268
|
-
return
|
|
10487
|
+
return relative10.split(path6__namespace.sep).join("/");
|
|
10269
10488
|
}
|
|
10270
10489
|
function symbolsOf(entry) {
|
|
10271
10490
|
const summary = entry.summary;
|
|
@@ -10358,16 +10577,15 @@ var historyTool = {
|
|
|
10358
10577
|
async handler(args, context) {
|
|
10359
10578
|
const prepared = await prepare(args, context, outDirOverride(args));
|
|
10360
10579
|
if (!prepared.ok) return prepared.outcome;
|
|
10361
|
-
const
|
|
10362
|
-
|
|
10363
|
-
|
|
10364
|
-
text = fs8__namespace.readFileSync(reportPath, "utf8");
|
|
10365
|
-
} catch {
|
|
10580
|
+
const snapshotDir = path6__namespace.resolve(prepared.workspace.root, prepared.workspace.config.outDir);
|
|
10581
|
+
const reportRead = readConfinedText(snapshotDir, path6__namespace.posix.join("reports", "log.md"));
|
|
10582
|
+
if (!reportRead.ok) {
|
|
10366
10583
|
return {
|
|
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.",
|
|
10584
|
+
text: "This snapshot has no readable reports/log.md. Generate it with `snapshot_generate { includeLogs: 20 }`, or `generate --include-logs 20` on the command line; the report is opt-in because the commit subjects are repository content, and it must be a regular file inside the snapshot.",
|
|
10368
10585
|
isError: true
|
|
10369
10586
|
};
|
|
10370
10587
|
}
|
|
10588
|
+
const text = reportRead.text;
|
|
10371
10589
|
const manifestRead = readManifest3(prepared.workspace);
|
|
10372
10590
|
const recordedLog = manifestRead.ok ? manifestRead.manifest.artifacts?.log : void 0;
|
|
10373
10591
|
if (recordedLog !== void 0 && recordedLog !== null) {
|
|
@@ -10428,7 +10646,7 @@ var budgetTool = {
|
|
|
10428
10646
|
...args.includeTests === true ? { includeTests: true } : {}
|
|
10429
10647
|
});
|
|
10430
10648
|
const paths = new Set(plan.files.map((file) => file.path));
|
|
10431
|
-
const gained = [...paths].filter((
|
|
10649
|
+
const gained = [...paths].filter((path17) => !previous.has(path17)).sort();
|
|
10432
10650
|
previous = paths;
|
|
10433
10651
|
rows.push({
|
|
10434
10652
|
budget,
|
|
@@ -10531,20 +10749,16 @@ var workspaceTool = {
|
|
|
10531
10749
|
async handler(args, context) {
|
|
10532
10750
|
const prepared = await prepare(args, context, outDirOverride(args));
|
|
10533
10751
|
if (!prepared.ok) return prepared.outcome;
|
|
10534
|
-
const
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
);
|
|
10539
|
-
let text;
|
|
10540
|
-
try {
|
|
10541
|
-
text = fs8__namespace.readFileSync(index, "utf8");
|
|
10542
|
-
} catch {
|
|
10752
|
+
const snapshotDir = path6__namespace.resolve(prepared.workspace.root, prepared.workspace.config.outDir);
|
|
10753
|
+
const index = path6__namespace.join(snapshotDir, "WORKSPACE.json");
|
|
10754
|
+
const read = readConfinedText(snapshotDir, "WORKSPACE.json");
|
|
10755
|
+
if (!read.ok) {
|
|
10543
10756
|
return {
|
|
10544
|
-
text: "No workspace index at " + index + ". Generate one with `generate --workspace member-a,member-b`; a single snapshot has no members to list.",
|
|
10757
|
+
text: "No workspace index at " + index + " (the file is absent, or it is not a regular file inside the snapshot). Generate one with `generate --workspace member-a,member-b`; a single snapshot has no members to list.",
|
|
10545
10758
|
isError: true
|
|
10546
10759
|
};
|
|
10547
10760
|
}
|
|
10761
|
+
const text = read.text;
|
|
10548
10762
|
const document = JSON.parse(text);
|
|
10549
10763
|
const members = document.members ?? [];
|
|
10550
10764
|
const links = document.links ?? [];
|
|
@@ -10685,6 +10899,10 @@ var routesTool = {
|
|
|
10685
10899
|
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
10686
10900
|
let filter = null;
|
|
10687
10901
|
if (typeof args.pattern === "string") {
|
|
10902
|
+
const unsafe = unsafeRegExpReason(args.pattern);
|
|
10903
|
+
if (unsafe !== null) {
|
|
10904
|
+
return { text: "pattern is refused: " + unsafe + ".", isError: true };
|
|
10905
|
+
}
|
|
10688
10906
|
try {
|
|
10689
10907
|
filter = new RegExp(args.pattern, "i");
|
|
10690
10908
|
} catch (error) {
|
|
@@ -10740,7 +10958,7 @@ var cyclesTool = {
|
|
|
10740
10958
|
tsconfig: tsconfigPathsFor(prepared.workspace.root)
|
|
10741
10959
|
});
|
|
10742
10960
|
const edges = /* @__PURE__ */ new Map();
|
|
10743
|
-
for (const
|
|
10961
|
+
for (const path17 of byPath.keys()) edges.set(path17, []);
|
|
10744
10962
|
for (const entry of read.manifest.indexes.imports.byFile) {
|
|
10745
10963
|
const targets = edges.get(entry.path);
|
|
10746
10964
|
if (targets === void 0) continue;
|
|
@@ -10828,6 +11046,12 @@ var searchTool = {
|
|
|
10828
11046
|
const cap = Math.max(1, Math.min(500, typeof args.maxMatches === "number" ? args.maxMatches : 50));
|
|
10829
11047
|
const contextLines = Math.max(0, Math.min(10, typeof args.contextLines === "number" ? args.contextLines : 0));
|
|
10830
11048
|
let pattern;
|
|
11049
|
+
if (args.regex === true) {
|
|
11050
|
+
const unsafe = unsafeRegExpReason(query);
|
|
11051
|
+
if (unsafe !== null) {
|
|
11052
|
+
return { text: "regex is refused: " + unsafe + ".", isError: true };
|
|
11053
|
+
}
|
|
11054
|
+
}
|
|
10831
11055
|
try {
|
|
10832
11056
|
pattern = args.regex === true ? new RegExp(query, "i") : new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
|
|
10833
11057
|
} catch (error) {
|
|
@@ -10846,7 +11070,7 @@ var searchTool = {
|
|
|
10846
11070
|
if (partPath === null) continue;
|
|
10847
11071
|
let text;
|
|
10848
11072
|
try {
|
|
10849
|
-
text =
|
|
11073
|
+
text = fs3__namespace.readFileSync(partPath, "utf8");
|
|
10850
11074
|
} catch {
|
|
10851
11075
|
continue;
|
|
10852
11076
|
}
|
|
@@ -10999,7 +11223,7 @@ var reviewTool = {
|
|
|
10999
11223
|
}
|
|
11000
11224
|
let section = null;
|
|
11001
11225
|
try {
|
|
11002
|
-
section = findSection(parsePartSections(
|
|
11226
|
+
section = findSection(parsePartSections(fs3__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
11003
11227
|
} catch {
|
|
11004
11228
|
section = null;
|
|
11005
11229
|
}
|
|
@@ -11089,31 +11313,31 @@ var diffContextTool = {
|
|
|
11089
11313
|
const changed = [];
|
|
11090
11314
|
const text = [];
|
|
11091
11315
|
let used = 0;
|
|
11092
|
-
for (const
|
|
11093
|
-
const file = byPath.get(
|
|
11316
|
+
for (const path17 of wanted) {
|
|
11317
|
+
const file = byPath.get(path17.toLowerCase());
|
|
11094
11318
|
if (file === void 0) {
|
|
11095
|
-
missing.push(
|
|
11319
|
+
missing.push(path17);
|
|
11096
11320
|
continue;
|
|
11097
11321
|
}
|
|
11098
11322
|
const partPath = partPathFor(workspace, file.part);
|
|
11099
11323
|
if (partPath === null) {
|
|
11100
|
-
missing.push(
|
|
11324
|
+
missing.push(path17 + " (part missing)");
|
|
11101
11325
|
continue;
|
|
11102
11326
|
}
|
|
11103
11327
|
let section;
|
|
11104
11328
|
try {
|
|
11105
|
-
section = findSection(parsePartSections(
|
|
11329
|
+
section = findSection(parsePartSections(fs3__namespace.readFileSync(partPath, "utf8")), file.relativePath);
|
|
11106
11330
|
} catch {
|
|
11107
11331
|
section = null;
|
|
11108
11332
|
}
|
|
11109
11333
|
if (section === null) {
|
|
11110
|
-
missing.push(
|
|
11334
|
+
missing.push(path17 + " (section not found)");
|
|
11111
11335
|
continue;
|
|
11112
11336
|
}
|
|
11113
11337
|
const window = windowText(section.body, 1, linesPerFile);
|
|
11114
11338
|
const tokens = Math.max(1, Math.ceil(Buffer.byteLength(window.text, "utf8") / 4));
|
|
11115
11339
|
if (used + tokens > budget) {
|
|
11116
|
-
missing.push(
|
|
11340
|
+
missing.push(path17 + " (budget)");
|
|
11117
11341
|
continue;
|
|
11118
11342
|
}
|
|
11119
11343
|
used += tokens;
|
|
@@ -11188,7 +11412,7 @@ var symbolTool = {
|
|
|
11188
11412
|
if (partPath === null) continue;
|
|
11189
11413
|
let partText;
|
|
11190
11414
|
try {
|
|
11191
|
-
partText =
|
|
11415
|
+
partText = fs3__namespace.readFileSync(partPath, "utf8");
|
|
11192
11416
|
} catch {
|
|
11193
11417
|
continue;
|
|
11194
11418
|
}
|
|
@@ -11220,28 +11444,39 @@ var symbolTool = {
|
|
|
11220
11444
|
};
|
|
11221
11445
|
}
|
|
11222
11446
|
const callSites = [];
|
|
11447
|
+
let referencesTruncated = false;
|
|
11223
11448
|
if (args.references !== false) {
|
|
11224
11449
|
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
11225
11450
|
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
11226
11451
|
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
11227
|
-
const
|
|
11452
|
+
const sectionsByPart = /* @__PURE__ */ new Map();
|
|
11228
11453
|
let scanned = 0;
|
|
11229
11454
|
for (const file of read.manifest.files) {
|
|
11230
11455
|
if (callSites.length >= limit) break;
|
|
11231
11456
|
const partPath = partPathFor(workspace, file.part);
|
|
11232
11457
|
if (partPath === null) continue;
|
|
11233
|
-
let
|
|
11234
|
-
if (
|
|
11458
|
+
let sections = sectionsByPart.get(partPath);
|
|
11459
|
+
if (sections === void 0) {
|
|
11460
|
+
if (scanned >= MAX_SEARCH_BYTES) {
|
|
11461
|
+
referencesTruncated = true;
|
|
11462
|
+
break;
|
|
11463
|
+
}
|
|
11464
|
+
let partText;
|
|
11235
11465
|
try {
|
|
11236
|
-
partText =
|
|
11466
|
+
partText = fs3__namespace.readFileSync(partPath, "utf8");
|
|
11237
11467
|
} catch {
|
|
11238
11468
|
continue;
|
|
11239
11469
|
}
|
|
11240
|
-
|
|
11470
|
+
const bytes = Buffer.byteLength(partText, "utf8");
|
|
11471
|
+
if (scanned + bytes > MAX_SEARCH_BYTES) {
|
|
11472
|
+
referencesTruncated = true;
|
|
11473
|
+
break;
|
|
11474
|
+
}
|
|
11475
|
+
scanned += bytes;
|
|
11476
|
+
sections = parsePartSections(partText);
|
|
11477
|
+
sectionsByPart.set(partPath, sections);
|
|
11241
11478
|
}
|
|
11242
|
-
|
|
11243
|
-
scanned += Buffer.byteLength(partText, "utf8");
|
|
11244
|
-
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
11479
|
+
const section = findSection(sections, file.relativePath);
|
|
11245
11480
|
if (section === null) continue;
|
|
11246
11481
|
const bodyLines = section.body.split("\n");
|
|
11247
11482
|
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
@@ -11255,8 +11490,11 @@ var symbolTool = {
|
|
|
11255
11490
|
}
|
|
11256
11491
|
}
|
|
11257
11492
|
}
|
|
11258
|
-
const text = matches.map((match) => "### " + match.path + " (" + match.part + ", line " + match.line + ")\n" + match.text).join("\n\n") + (args.references === false ? "" : "\n\n" + (callSites.length === 0 ? "No call site was found in the snapshot." : "Call sites (" + callSites.length + "):\n" + callSites.map((site) => " " + site.path + ":" + site.line + " " + site.text).join("\n")));
|
|
11259
|
-
return {
|
|
11493
|
+
const text = matches.map((match) => "### " + match.path + " (" + match.part + ", line " + match.line + ")\n" + match.text).join("\n\n") + (args.references === false ? "" : "\n\n" + (callSites.length === 0 ? "No call site was found in the snapshot." : "Call sites (" + callSites.length + "):\n" + callSites.map((site) => " " + site.path + ":" + site.line + " " + site.text).join("\n"))) + (referencesTruncated ? "\n\nSearch stopped at the 4 MB part budget; call sites in later parts were not read. Narrow the name or inspect the remaining parts directly." : "");
|
|
11494
|
+
return {
|
|
11495
|
+
text,
|
|
11496
|
+
structured: { found: matches.length, matches, references: callSites, truncated: referencesTruncated }
|
|
11497
|
+
};
|
|
11260
11498
|
}
|
|
11261
11499
|
};
|
|
11262
11500
|
var contextTool = {
|
|
@@ -11329,7 +11567,7 @@ var contextTool = {
|
|
|
11329
11567
|
}
|
|
11330
11568
|
if (!sectionsByPart.has(file.part)) {
|
|
11331
11569
|
try {
|
|
11332
|
-
sectionsByPart.set(file.part, parsePartSections(
|
|
11570
|
+
sectionsByPart.set(file.part, parsePartSections(fs3__namespace.readFileSync(partPath, "utf8")));
|
|
11333
11571
|
} catch {
|
|
11334
11572
|
sectionsByPart.set(file.part, null);
|
|
11335
11573
|
}
|
|
@@ -11414,6 +11652,10 @@ var queryTool = {
|
|
|
11414
11652
|
const maxFiles = typeof args.maxFiles === "number" ? Math.min(200, Math.max(1, args.maxFiles)) : 40;
|
|
11415
11653
|
let pattern = null;
|
|
11416
11654
|
if (typeof args.pathPattern === "string") {
|
|
11655
|
+
const unsafe = unsafeRegExpReason(args.pathPattern);
|
|
11656
|
+
if (unsafe !== null) {
|
|
11657
|
+
return { text: "pathPattern is refused: " + unsafe + ".", isError: true };
|
|
11658
|
+
}
|
|
11417
11659
|
try {
|
|
11418
11660
|
pattern = new RegExp(args.pathPattern, "i");
|
|
11419
11661
|
} catch (error) {
|
|
@@ -11563,7 +11805,7 @@ var answerTool = {
|
|
|
11563
11805
|
let partText = parts.get(partPath);
|
|
11564
11806
|
if (partText === void 0) {
|
|
11565
11807
|
try {
|
|
11566
|
-
partText =
|
|
11808
|
+
partText = fs3__namespace.readFileSync(partPath, "utf8");
|
|
11567
11809
|
} catch {
|
|
11568
11810
|
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
11569
11811
|
continue;
|
|
@@ -11889,16 +12131,6 @@ var generateTool = {
|
|
|
11889
12131
|
minimum: 500,
|
|
11890
12132
|
description: "Fit the snapshot into this token budget, highest value first."
|
|
11891
12133
|
},
|
|
11892
|
-
only: {
|
|
11893
|
-
type: "array",
|
|
11894
|
-
items: { type: "string" },
|
|
11895
|
-
description: "Globs to include: replaces the config allow-list for this run."
|
|
11896
|
-
},
|
|
11897
|
-
ignore: {
|
|
11898
|
-
type: "array",
|
|
11899
|
-
items: { type: "string" },
|
|
11900
|
-
description: "Globs to exclude, added to the config deny-list for this run."
|
|
11901
|
-
},
|
|
11902
12134
|
...SCOPE_PROPERTIES
|
|
11903
12135
|
},
|
|
11904
12136
|
additionalProperties: false
|
|
@@ -12399,7 +12631,7 @@ var readTool = {
|
|
|
12399
12631
|
}
|
|
12400
12632
|
let partText;
|
|
12401
12633
|
try {
|
|
12402
|
-
partText =
|
|
12634
|
+
partText = fs3__namespace.readFileSync(partPath, "utf8");
|
|
12403
12635
|
} catch {
|
|
12404
12636
|
return failure(
|
|
12405
12637
|
`${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
|
|
@@ -12652,12 +12884,12 @@ async function runStdioServer(options) {
|
|
|
12652
12884
|
});
|
|
12653
12885
|
return writeChain;
|
|
12654
12886
|
};
|
|
12655
|
-
const
|
|
12887
|
+
const MAX_IN_FLIGHT2 = 4;
|
|
12656
12888
|
let inFlight = 0;
|
|
12657
12889
|
let inputEnded = false;
|
|
12658
12890
|
let resolveDone = () => void 0;
|
|
12659
|
-
const finished = new Promise((
|
|
12660
|
-
resolveDone =
|
|
12891
|
+
const finished = new Promise((resolve11) => {
|
|
12892
|
+
resolveDone = resolve11;
|
|
12661
12893
|
});
|
|
12662
12894
|
const finishIfIdle = () => {
|
|
12663
12895
|
if (inputEnded && inFlight === 0) resolveDone(0);
|
|
@@ -12687,14 +12919,14 @@ async function runStdioServer(options) {
|
|
|
12687
12919
|
errorResponse(
|
|
12688
12920
|
id,
|
|
12689
12921
|
ERROR_CODES.overloaded,
|
|
12690
|
-
`The server is already handling ${
|
|
12922
|
+
`The server is already handling ${MAX_IN_FLIGHT2} requests; retry this one when it is free.`
|
|
12691
12923
|
)
|
|
12692
12924
|
);
|
|
12693
12925
|
};
|
|
12694
12926
|
const stopReading = createLineReader(process.stdin, {
|
|
12695
12927
|
onOverflow: (bytes) => log(`mcp: discarded an oversized message (${bytes} bytes)`),
|
|
12696
12928
|
onLine: (line) => {
|
|
12697
|
-
if (inFlight >=
|
|
12929
|
+
if (inFlight >= MAX_IN_FLIGHT2) {
|
|
12698
12930
|
rejectOverloaded(line);
|
|
12699
12931
|
return;
|
|
12700
12932
|
}
|
|
@@ -12753,12 +12985,12 @@ var SNAPSHOT_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9
|
|
|
12753
12985
|
var SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
12754
12986
|
function readOwnershipMarker(dir) {
|
|
12755
12987
|
const markerPath = path6__namespace.join(dir, OWNERSHIP_MARKER);
|
|
12756
|
-
if (!
|
|
12988
|
+
if (!fs3__namespace.existsSync(markerPath)) {
|
|
12757
12989
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
12758
12990
|
}
|
|
12759
12991
|
let raw;
|
|
12760
12992
|
try {
|
|
12761
|
-
raw =
|
|
12993
|
+
raw = fs3__namespace.readFileSync(markerPath, "utf8");
|
|
12762
12994
|
} catch {
|
|
12763
12995
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
12764
12996
|
}
|
|
@@ -12845,7 +13077,7 @@ function canonicalLockTarget(targetPath) {
|
|
|
12845
13077
|
const tail = [];
|
|
12846
13078
|
for (; ; ) {
|
|
12847
13079
|
try {
|
|
12848
|
-
return path6__namespace.join(
|
|
13080
|
+
return path6__namespace.join(fs3__namespace.realpathSync(existing), ...tail);
|
|
12849
13081
|
} catch {
|
|
12850
13082
|
const parent = path6__namespace.dirname(existing);
|
|
12851
13083
|
if (parent === existing) return resolved;
|
|
@@ -12862,13 +13094,13 @@ function releaseAbandonedRun(stagingRoots, runId) {
|
|
|
12862
13094
|
for (const root of new Set(stagingRoots)) {
|
|
12863
13095
|
const lockPath = lockPathFor(root);
|
|
12864
13096
|
try {
|
|
12865
|
-
const payload = JSON.parse(
|
|
12866
|
-
if (payload.runId === runId)
|
|
13097
|
+
const payload = JSON.parse(fs3__namespace.readFileSync(lockPath, "utf8"));
|
|
13098
|
+
if (payload.runId === runId) fs3__namespace.rmSync(lockPath, { force: true });
|
|
12867
13099
|
} catch {
|
|
12868
13100
|
}
|
|
12869
13101
|
let entries;
|
|
12870
13102
|
try {
|
|
12871
|
-
entries =
|
|
13103
|
+
entries = fs3__namespace.readdirSync(root);
|
|
12872
13104
|
} catch {
|
|
12873
13105
|
continue;
|
|
12874
13106
|
}
|
|
@@ -12878,7 +13110,7 @@ function releaseAbandonedRun(stagingRoots, runId) {
|
|
|
12878
13110
|
const { marker } = readOwnershipMarker(directory);
|
|
12879
13111
|
if (marker?.runId !== runId) continue;
|
|
12880
13112
|
try {
|
|
12881
|
-
|
|
13113
|
+
fs3__namespace.rmSync(directory, { recursive: true, force: true });
|
|
12882
13114
|
} catch {
|
|
12883
13115
|
}
|
|
12884
13116
|
}
|
|
@@ -14142,7 +14374,7 @@ async function workspaceFor(context) {
|
|
|
14142
14374
|
}
|
|
14143
14375
|
function readFileIfPresent(file) {
|
|
14144
14376
|
try {
|
|
14145
|
-
return
|
|
14377
|
+
return fs3__namespace.readFileSync(file, "utf8");
|
|
14146
14378
|
} catch {
|
|
14147
14379
|
return null;
|
|
14148
14380
|
}
|
|
@@ -14183,7 +14415,7 @@ function buildResourceProvider() {
|
|
|
14183
14415
|
const workspace = await workspaceFor(context);
|
|
14184
14416
|
const reportsDir = "error" in workspace ? null : path6__namespace.resolve(workspace.root, workspace.config.outDir, "reports");
|
|
14185
14417
|
for (const [uri, report2] of REPORT_URIS) {
|
|
14186
|
-
const present = reportsDir !== null &&
|
|
14418
|
+
const present = reportsDir !== null && fs3__namespace.existsSync(path6__namespace.join(reportsDir, report2.file));
|
|
14187
14419
|
if (!present) continue;
|
|
14188
14420
|
resources.push({
|
|
14189
14421
|
uri,
|
|
@@ -14245,36 +14477,46 @@ function buildResourceProvider() {
|
|
|
14245
14477
|
}
|
|
14246
14478
|
const workspace = await workspaceFor(context);
|
|
14247
14479
|
if ("error" in workspace) return null;
|
|
14480
|
+
const snapshotDir = path6__namespace.resolve(workspace.root, workspace.config.outDir);
|
|
14248
14481
|
if (uri === PROMPT_URI) {
|
|
14249
|
-
const
|
|
14250
|
-
|
|
14251
|
-
);
|
|
14252
|
-
if (text === null) {
|
|
14482
|
+
const read = readConfinedText(snapshotDir, "PROMPT.md");
|
|
14483
|
+
if (!read.ok) {
|
|
14253
14484
|
throw new ResourceNotFoundError(
|
|
14254
14485
|
uri,
|
|
14255
|
-
"This snapshot contains no PROMPT.md: the prompt artifact was disabled (artifacts.prompt = false or --skip-artifacts prompt),
|
|
14486
|
+
"This snapshot contains no readable PROMPT.md: the prompt artifact was disabled (artifacts.prompt = false or --skip-artifacts prompt), nothing has been generated yet, or the file is not a regular file inside the snapshot. Run snapshot_generate first."
|
|
14256
14487
|
);
|
|
14257
14488
|
}
|
|
14258
|
-
return {
|
|
14489
|
+
return {
|
|
14490
|
+
uri,
|
|
14491
|
+
mimeType: "text/markdown",
|
|
14492
|
+
text: ensureSingleRead(uri, read.text, PROMPT_ADVICE)
|
|
14493
|
+
};
|
|
14259
14494
|
}
|
|
14260
14495
|
const report2 = REPORT_URIS.get(uri);
|
|
14261
14496
|
if (report2) {
|
|
14262
|
-
const
|
|
14263
|
-
|
|
14264
|
-
);
|
|
14265
|
-
if (text === null) {
|
|
14497
|
+
const read = readConfinedText(snapshotDir, path6__namespace.posix.join("reports", report2.file));
|
|
14498
|
+
if (!read.ok) {
|
|
14266
14499
|
throw new ResourceNotFoundError(
|
|
14267
14500
|
uri,
|
|
14268
|
-
"This snapshot contains no " + report2.file + ": that report was disabled,
|
|
14501
|
+
"This snapshot contains no readable " + report2.file + ": that report was disabled, nothing has been generated yet, or the file is not a regular file inside the snapshot. Run snapshot_generate first."
|
|
14269
14502
|
);
|
|
14270
14503
|
}
|
|
14271
|
-
return {
|
|
14504
|
+
return {
|
|
14505
|
+
uri,
|
|
14506
|
+
mimeType: "text/markdown",
|
|
14507
|
+
text: ensureSingleRead(uri, read.text, REPORT_ADVICE)
|
|
14508
|
+
};
|
|
14272
14509
|
}
|
|
14273
14510
|
if (uri === "snapshot://manifest") {
|
|
14274
14511
|
const read = readManifest3(workspace);
|
|
14275
14512
|
if (!read.ok) return null;
|
|
14276
|
-
const
|
|
14277
|
-
|
|
14513
|
+
const confined = readConfinedText(path6__namespace.dirname(read.file), path6__namespace.basename(read.file));
|
|
14514
|
+
if (!confined.ok) return null;
|
|
14515
|
+
return {
|
|
14516
|
+
uri,
|
|
14517
|
+
mimeType: "application/json",
|
|
14518
|
+
text: ensureSingleRead(uri, confined.text, MANIFEST_ADVICE)
|
|
14519
|
+
};
|
|
14278
14520
|
}
|
|
14279
14521
|
const partMatch = PART_URI.exec(uri);
|
|
14280
14522
|
if (partMatch) {
|
|
@@ -14287,7 +14529,7 @@ function buildResourceProvider() {
|
|
|
14287
14529
|
if (partPath === null) return null;
|
|
14288
14530
|
let partBytes;
|
|
14289
14531
|
try {
|
|
14290
|
-
partBytes =
|
|
14532
|
+
partBytes = fs3__namespace.statSync(partPath).size;
|
|
14291
14533
|
} catch {
|
|
14292
14534
|
return null;
|
|
14293
14535
|
}
|
|
@@ -14323,52 +14565,52 @@ function validateArguments(schema, value) {
|
|
|
14323
14565
|
}
|
|
14324
14566
|
return problems;
|
|
14325
14567
|
}
|
|
14326
|
-
function checkValue(
|
|
14568
|
+
function checkValue(path17, schema, value) {
|
|
14327
14569
|
if (schema.enum && !schema.enum.includes(value)) {
|
|
14328
|
-
return [`"${
|
|
14570
|
+
return [`"${path17}" must be one of: ${schema.enum.join(", ")}`];
|
|
14329
14571
|
}
|
|
14330
14572
|
switch (schema.type) {
|
|
14331
14573
|
case "string": {
|
|
14332
|
-
if (typeof value !== "string") return [`"${
|
|
14574
|
+
if (typeof value !== "string") return [`"${path17}" must be a string`];
|
|
14333
14575
|
const problems = [];
|
|
14334
14576
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
14335
|
-
problems.push(`"${
|
|
14577
|
+
problems.push(`"${path17}" must be at least ${schema.minLength} character(s)`);
|
|
14336
14578
|
}
|
|
14337
14579
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
14338
|
-
problems.push(`"${
|
|
14580
|
+
problems.push(`"${path17}" must be at most ${schema.maxLength} character(s)`);
|
|
14339
14581
|
}
|
|
14340
14582
|
return problems;
|
|
14341
14583
|
}
|
|
14342
14584
|
case "number":
|
|
14343
14585
|
case "integer": {
|
|
14344
14586
|
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
14345
|
-
return [`"${
|
|
14587
|
+
return [`"${path17}" must be a number`];
|
|
14346
14588
|
}
|
|
14347
14589
|
if (schema.type === "integer" && !Number.isInteger(value)) {
|
|
14348
|
-
return [`"${
|
|
14590
|
+
return [`"${path17}" must be an integer`];
|
|
14349
14591
|
}
|
|
14350
14592
|
const problems = [];
|
|
14351
14593
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
14352
|
-
problems.push(`"${
|
|
14594
|
+
problems.push(`"${path17}" must be >= ${schema.minimum}`);
|
|
14353
14595
|
}
|
|
14354
14596
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
14355
|
-
problems.push(`"${
|
|
14597
|
+
problems.push(`"${path17}" must be <= ${schema.maximum}`);
|
|
14356
14598
|
}
|
|
14357
14599
|
return problems;
|
|
14358
14600
|
}
|
|
14359
14601
|
case "boolean":
|
|
14360
|
-
return typeof value === "boolean" ? [] : [`"${
|
|
14602
|
+
return typeof value === "boolean" ? [] : [`"${path17}" must be a boolean`];
|
|
14361
14603
|
case "array": {
|
|
14362
|
-
if (!Array.isArray(value)) return [`"${
|
|
14604
|
+
if (!Array.isArray(value)) return [`"${path17}" must be an array`];
|
|
14363
14605
|
if (!schema.items) return [];
|
|
14364
14606
|
const problems = [];
|
|
14365
14607
|
value.forEach((item, index) => {
|
|
14366
|
-
problems.push(...checkValue(`${
|
|
14608
|
+
problems.push(...checkValue(`${path17}[${index}]`, schema.items, item));
|
|
14367
14609
|
});
|
|
14368
14610
|
return problems;
|
|
14369
14611
|
}
|
|
14370
14612
|
case "object":
|
|
14371
|
-
return isJsonObject(value) ? [] : [`"${
|
|
14613
|
+
return isJsonObject(value) ? [] : [`"${path17}" must be an object`];
|
|
14372
14614
|
default:
|
|
14373
14615
|
return [];
|
|
14374
14616
|
}
|
|
@@ -14732,6 +14974,9 @@ var DEFAULT_PORT = 4789;
|
|
|
14732
14974
|
var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
|
|
14733
14975
|
var RATE_LIMIT = 60;
|
|
14734
14976
|
var RATE_WINDOW_MS = 1e4;
|
|
14977
|
+
var MAX_IN_FLIGHT = 4;
|
|
14978
|
+
var MAX_SESSION_ENTRIES = 64;
|
|
14979
|
+
var MAX_RATE_WINDOWS = 1024;
|
|
14735
14980
|
function generateToken() {
|
|
14736
14981
|
return crypto5__namespace.randomBytes(24).toString("base64url");
|
|
14737
14982
|
}
|
|
@@ -14767,6 +15012,13 @@ async function startHttpTransport(options) {
|
|
|
14767
15012
|
const toolCount = buildTools().length;
|
|
14768
15013
|
const mcpSessions = /* @__PURE__ */ new Map();
|
|
14769
15014
|
const socketServers = /* @__PURE__ */ new WeakMap();
|
|
15015
|
+
const rememberSession = (id, server) => {
|
|
15016
|
+
if (!mcpSessions.has(id) && mcpSessions.size >= MAX_SESSION_ENTRIES) {
|
|
15017
|
+
const oldest = mcpSessions.keys().next().value;
|
|
15018
|
+
if (oldest !== void 0) mcpSessions.delete(oldest);
|
|
15019
|
+
}
|
|
15020
|
+
mcpSessions.set(id, server);
|
|
15021
|
+
};
|
|
14770
15022
|
const anonymousServers = /* @__PURE__ */ new Map();
|
|
14771
15023
|
const serverFor = (request) => {
|
|
14772
15024
|
const header = request.headers["mcp-session-id"];
|
|
@@ -14775,11 +15027,7 @@ async function startHttpTransport(options) {
|
|
|
14775
15027
|
let existing = mcpSessions.get(supplied);
|
|
14776
15028
|
if (existing === void 0) {
|
|
14777
15029
|
existing = createMcp();
|
|
14778
|
-
|
|
14779
|
-
const oldest = mcpSessions.keys().next().value;
|
|
14780
|
-
if (oldest !== void 0) mcpSessions.delete(oldest);
|
|
14781
|
-
}
|
|
14782
|
-
mcpSessions.set(supplied, existing);
|
|
15030
|
+
rememberSession(supplied, existing);
|
|
14783
15031
|
}
|
|
14784
15032
|
return existing;
|
|
14785
15033
|
}
|
|
@@ -14810,6 +15058,35 @@ async function startHttpTransport(options) {
|
|
|
14810
15058
|
return fromQuery !== null && timingSafeEqual2(fromQuery, token);
|
|
14811
15059
|
};
|
|
14812
15060
|
const sessions = /* @__PURE__ */ new Map();
|
|
15061
|
+
let inFlight = 0;
|
|
15062
|
+
const acquireToolSlot = () => {
|
|
15063
|
+
if (inFlight >= MAX_IN_FLIGHT) return false;
|
|
15064
|
+
inFlight += 1;
|
|
15065
|
+
return true;
|
|
15066
|
+
};
|
|
15067
|
+
const releaseToolSlot = () => {
|
|
15068
|
+
if (inFlight > 0) inFlight -= 1;
|
|
15069
|
+
};
|
|
15070
|
+
const busyResponse = (id) => ({
|
|
15071
|
+
jsonrpc: "2.0",
|
|
15072
|
+
id: typeof id === "string" || typeof id === "number" || id === null ? id : null,
|
|
15073
|
+
error: {
|
|
15074
|
+
code: -32001,
|
|
15075
|
+
message: "server busy: too many tool calls are already in flight"
|
|
15076
|
+
}
|
|
15077
|
+
});
|
|
15078
|
+
const isToolCall = (message) => message !== null && typeof message === "object" && message.method === "tools/call";
|
|
15079
|
+
const rememberRateWindow = (remote, now) => {
|
|
15080
|
+
if (!sessions.has(remote) && sessions.size >= MAX_RATE_WINDOWS) {
|
|
15081
|
+
for (const [key, value] of sessions) if (value.resetAt <= now) sessions.delete(key);
|
|
15082
|
+
while (sessions.size >= MAX_RATE_WINDOWS) {
|
|
15083
|
+
const oldest = sessions.keys().next().value;
|
|
15084
|
+
if (oldest === void 0) break;
|
|
15085
|
+
sessions.delete(oldest);
|
|
15086
|
+
}
|
|
15087
|
+
}
|
|
15088
|
+
sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
15089
|
+
};
|
|
14813
15090
|
const metrics = {
|
|
14814
15091
|
requests: 0,
|
|
14815
15092
|
byMethod: /* @__PURE__ */ new Map(),
|
|
@@ -14825,7 +15102,7 @@ async function startHttpTransport(options) {
|
|
|
14825
15102
|
const now = Date.now();
|
|
14826
15103
|
const window = sessions.get(remote);
|
|
14827
15104
|
if (window === void 0 || window.resetAt <= now) {
|
|
14828
|
-
|
|
15105
|
+
rememberRateWindow(remote, now);
|
|
14829
15106
|
return false;
|
|
14830
15107
|
}
|
|
14831
15108
|
if (window.count >= RATE_LIMIT) return true;
|
|
@@ -14985,8 +15262,19 @@ async function startHttpTransport(options) {
|
|
|
14985
15262
|
send(400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: String(error) } });
|
|
14986
15263
|
return;
|
|
14987
15264
|
}
|
|
14988
|
-
const
|
|
14989
|
-
if (
|
|
15265
|
+
const gated = isToolCall(message);
|
|
15266
|
+
if (gated && !acquireToolSlot()) {
|
|
15267
|
+
const answer = busyResponse(message.id);
|
|
15268
|
+
stream.write("event: message\ndata: " + JSON.stringify(answer) + "\n\n");
|
|
15269
|
+
send(202, "", cors);
|
|
15270
|
+
return;
|
|
15271
|
+
}
|
|
15272
|
+
try {
|
|
15273
|
+
const answer = await stream.server.handle(message);
|
|
15274
|
+
if (answer !== null) stream.write("event: message\ndata: " + JSON.stringify(answer) + "\n\n");
|
|
15275
|
+
} finally {
|
|
15276
|
+
if (gated) releaseToolSlot();
|
|
15277
|
+
}
|
|
14990
15278
|
send(202, "", cors);
|
|
14991
15279
|
})();
|
|
14992
15280
|
});
|
|
@@ -15051,13 +15339,22 @@ async function startHttpTransport(options) {
|
|
|
15051
15339
|
}
|
|
15052
15340
|
if (sessionId === "" && !Array.isArray(message) && message.method === "initialize") {
|
|
15053
15341
|
sessionId = newSessionId();
|
|
15054
|
-
|
|
15342
|
+
rememberSession(sessionId, activeServer);
|
|
15055
15343
|
}
|
|
15056
15344
|
const sessionHeaders = sessionId === "" ? cors : { ...cors, "mcp-session-id": sessionId };
|
|
15057
15345
|
const answers = [];
|
|
15058
15346
|
for (const item of batch) {
|
|
15059
|
-
const
|
|
15060
|
-
if (
|
|
15347
|
+
const gated = isToolCall(item);
|
|
15348
|
+
if (gated && !acquireToolSlot()) {
|
|
15349
|
+
answers.push(busyResponse(item.id));
|
|
15350
|
+
continue;
|
|
15351
|
+
}
|
|
15352
|
+
try {
|
|
15353
|
+
const answer = await activeServer.handle(item);
|
|
15354
|
+
if (answer !== null) answers.push(answer);
|
|
15355
|
+
} finally {
|
|
15356
|
+
if (gated) releaseToolSlot();
|
|
15357
|
+
}
|
|
15061
15358
|
}
|
|
15062
15359
|
if (answers.length === 0) {
|
|
15063
15360
|
send(202, "", sessionHeaders);
|
|
@@ -15076,11 +15373,11 @@ async function startHttpTransport(options) {
|
|
|
15076
15373
|
}
|
|
15077
15374
|
});
|
|
15078
15375
|
});
|
|
15079
|
-
await new Promise((
|
|
15376
|
+
await new Promise((resolve11, reject) => {
|
|
15080
15377
|
httpServer.once("error", reject);
|
|
15081
15378
|
httpServer.listen(port, host, () => {
|
|
15082
15379
|
httpServer.removeListener("error", reject);
|
|
15083
|
-
|
|
15380
|
+
resolve11();
|
|
15084
15381
|
});
|
|
15085
15382
|
});
|
|
15086
15383
|
const address = httpServer.address();
|
|
@@ -15091,7 +15388,7 @@ async function startHttpTransport(options) {
|
|
|
15091
15388
|
port: actualPort,
|
|
15092
15389
|
host,
|
|
15093
15390
|
token,
|
|
15094
|
-
close: () => new Promise((
|
|
15391
|
+
close: () => new Promise((resolve11) => {
|
|
15095
15392
|
for (const [, session] of sseSessions) {
|
|
15096
15393
|
try {
|
|
15097
15394
|
session.end();
|
|
@@ -15099,7 +15396,7 @@ async function startHttpTransport(options) {
|
|
|
15099
15396
|
}
|
|
15100
15397
|
}
|
|
15101
15398
|
sseSessions.clear();
|
|
15102
|
-
httpServer.close(() =>
|
|
15399
|
+
httpServer.close(() => resolve11());
|
|
15103
15400
|
httpServer.closeAllConnections();
|
|
15104
15401
|
})
|
|
15105
15402
|
};
|