codebase-snapshot 0.22.0 → 0.22.1
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 +14 -0
- package/README.md +27 -18
- package/dist/bin.js +1830 -1019
- package/dist/{chunk-NPCDJBE4.js → chunk-7AAXOTKS.js} +1451 -724
- package/dist/cli.cjs +1954 -1146
- package/dist/cli.js +164 -83
- package/dist/index.cjs +1426 -710
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +827 -346
- package/dist/mcp.d.cts +5 -2
- package/dist/mcp.d.ts +5 -2
- package/dist/mcp.js +1 -1
- package/docs/about.md +3 -2
- package/docs/agent.md +2 -1
- package/docs/cli.md +17 -16
- package/docs/deploy.md +10 -4
- package/docs/guard.md +47 -4
- package/docs/impact.md +3 -2
- package/docs/mcp-server-for-codebase.md +2 -2
- package/docs/mcp.md +4 -4
- package/docs/security-review.md +3 -2
- package/docs/troubleshooting.md +2 -2
- package/package.json +1 -1
package/dist/mcp.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var fs18 = require('fs');
|
|
4
4
|
var path7 = require('path');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var module$1 = require('module');
|
|
@@ -34,7 +34,7 @@ function _interopNamespace(e) {
|
|
|
34
34
|
return Object.freeze(n);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
var
|
|
37
|
+
var fs18__namespace = /*#__PURE__*/_interopNamespace(fs18);
|
|
38
38
|
var path7__namespace = /*#__PURE__*/_interopNamespace(path7);
|
|
39
39
|
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
40
40
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
@@ -536,9 +536,9 @@ var SKIPPED_WALK_DIRS = /* @__PURE__ */ new Set([
|
|
|
536
536
|
]);
|
|
537
537
|
function readSmallFile(fullPath) {
|
|
538
538
|
try {
|
|
539
|
-
const stats =
|
|
539
|
+
const stats = fs18__namespace.statSync(fullPath);
|
|
540
540
|
if (!stats.isFile() || stats.size > MANIFEST_MAX_BYTES) return null;
|
|
541
|
-
return
|
|
541
|
+
return fs18__namespace.readFileSync(fullPath, "utf8");
|
|
542
542
|
} catch {
|
|
543
543
|
return null;
|
|
544
544
|
}
|
|
@@ -604,7 +604,7 @@ function pnpmWorkspacePatterns(raw) {
|
|
|
604
604
|
function childDirectories(cwd, parent) {
|
|
605
605
|
let entries;
|
|
606
606
|
try {
|
|
607
|
-
entries =
|
|
607
|
+
entries = fs18__namespace.readdirSync(path7__namespace.join(cwd, parent), { withFileTypes: true });
|
|
608
608
|
} catch {
|
|
609
609
|
return [];
|
|
610
610
|
}
|
|
@@ -639,10 +639,10 @@ function workspacePackageDirs(cwd, patterns) {
|
|
|
639
639
|
function scanWorkspacePackages(cwd, patterns) {
|
|
640
640
|
const files = /* @__PURE__ */ new Set();
|
|
641
641
|
const dependencies = /* @__PURE__ */ new Set();
|
|
642
|
-
for (const
|
|
643
|
-
const full = path7__namespace.join(cwd,
|
|
642
|
+
for (const relative14 of workspacePackageDirs(cwd, patterns)) {
|
|
643
|
+
const full = path7__namespace.join(cwd, relative14);
|
|
644
644
|
try {
|
|
645
|
-
for (const entry of
|
|
645
|
+
for (const entry of fs18__namespace.readdirSync(full, { withFileTypes: true })) files.add(entry.name);
|
|
646
646
|
} catch {
|
|
647
647
|
}
|
|
648
648
|
const raw = readSmallFile(path7__namespace.join(full, "package.json"));
|
|
@@ -655,7 +655,7 @@ function scanWorkspacePackages(cwd, patterns) {
|
|
|
655
655
|
var SNAPSHOT_MARKER = ".codebase-snapshot";
|
|
656
656
|
function isToolOwnedDirectory(dir) {
|
|
657
657
|
try {
|
|
658
|
-
return
|
|
658
|
+
return fs18__namespace.statSync(dir).isDirectory() && fs18__namespace.existsSync(path7__namespace.join(dir, SNAPSHOT_MARKER));
|
|
659
659
|
} catch {
|
|
660
660
|
return false;
|
|
661
661
|
}
|
|
@@ -670,7 +670,7 @@ function countMarkdownFiles(cwd) {
|
|
|
670
670
|
directoriesSeen += 1;
|
|
671
671
|
let entries;
|
|
672
672
|
try {
|
|
673
|
-
entries =
|
|
673
|
+
entries = fs18__namespace.readdirSync(current.dir, { withFileTypes: true });
|
|
674
674
|
} catch {
|
|
675
675
|
continue;
|
|
676
676
|
}
|
|
@@ -692,7 +692,7 @@ function buildPresetContext(cwd) {
|
|
|
692
692
|
const files = /* @__PURE__ */ new Set();
|
|
693
693
|
const dirs = /* @__PURE__ */ new Set();
|
|
694
694
|
try {
|
|
695
|
-
for (const entry of
|
|
695
|
+
for (const entry of fs18__namespace.readdirSync(cwd, { withFileTypes: true })) {
|
|
696
696
|
if (entry.isDirectory()) dirs.add(entry.name);
|
|
697
697
|
else if (entry.isFile()) files.add(entry.name);
|
|
698
698
|
}
|
|
@@ -1823,7 +1823,7 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1823
1823
|
// query parameter or `$VARIABLE` reference is not an assignment).
|
|
1824
1824
|
rule: "credential-assignment-unquoted",
|
|
1825
1825
|
pattern: new RegExp(
|
|
1826
|
-
`(?:${QUOTED_CREDENTIAL_KEY}|${UNQUOTED_STRONG_NAME})\\s{0,8}${ASSIGN}\\s{0,8}${NOT_A_LITERAL_VALUE}${UNQUOTED_LITERAL}|(?<=${UNQUOTED_STRONG_NAME}
|
|
1826
|
+
`(?:${QUOTED_CREDENTIAL_KEY}|${UNQUOTED_STRONG_NAME})\\s{0,8}${ASSIGN}\\s{0,8}${NOT_A_LITERAL_VALUE}${UNQUOTED_LITERAL}|(?<=${UNQUOTED_STRONG_NAME}["']?\\s{0,8}=(?!=)\\s{0,8})(?![\\s#$"'\`])[^\\s]{1,}|(?<=${UNQUOTED_STRONG_NAME}["']?\\s{0,8}:[ ]{1,8})(?![ ]*["'\`])(?![ ]*[|>])(?![ ]*\\$\\{[A-Za-z_][A-Za-z0-9_]*[:}#%/])${NOT_A_LITERAL_VALUE}[^\r
|
|
1827
1827
|
#]{1,300}`,
|
|
1828
1828
|
"i"
|
|
1829
1829
|
),
|
|
@@ -1883,7 +1883,12 @@ var DEFAULT_SECRET_PATTERNS = [
|
|
|
1883
1883
|
pattern: new RegExp(
|
|
1884
1884
|
// The operator set deliberately omits `?`: `${VAR:?message}` is an error message in shell
|
|
1885
1885
|
// and Compose, not a fallback value, and masking it hid the sentence a user is meant to read.
|
|
1886
|
-
|
|
1886
|
+
// The fallback may itself be quoted — `${VAR:-"prodSecret"}` is standard POSIX shell
|
|
1887
|
+
// and Docker Compose — so the capture takes everything between the operator and the
|
|
1888
|
+
// closing brace. Quotes are part of the value here: masking the whole fallback is
|
|
1889
|
+
// correct, and it keeps a quoted default from slipping between the two quote-aware
|
|
1890
|
+
// rules.
|
|
1891
|
+
`(?:["']${STRONG_CREDENTIAL_NAME}["']|${NOT_AFTER_QUOTE}${STRONG_CREDENTIAL_NAME})\\s{0,8}${ASSIGN}\\s{0,8}["'\`]?\\$\\{[A-Za-z_][A-Za-z0-9_]*:?[-=+]([^}\\r\\n]{2,512})\\}["'\`]?`,
|
|
1887
1892
|
"i"
|
|
1888
1893
|
),
|
|
1889
1894
|
valueGroup: 1
|
|
@@ -2375,7 +2380,19 @@ function maskValueLine(line) {
|
|
|
2375
2380
|
return `${indent}${REDACTION_MARKER}`;
|
|
2376
2381
|
}
|
|
2377
2382
|
var STRUCTURED_KEY = /^([ \t]*)(?:-[ \t]+)?["']?([A-Za-z0-9_$.-]{1,128})["']?[ \t]*([:=])[ \t]*(.*)$/;
|
|
2378
|
-
var BLOCK_SCALAR = /^[|>][+-]
|
|
2383
|
+
var BLOCK_SCALAR = /^[|>](?:[+-]\d*|\d[+-]?)?[ \t]*(?:#.*)?$/;
|
|
2384
|
+
var YAML_LIST_ITEM = /^([ \t]*-[ \t]+)(.*)$/;
|
|
2385
|
+
function isJsonFile(filePath) {
|
|
2386
|
+
return filePath !== void 0 && /\.(?:json|jsonc|json5)$/i.test(filePath);
|
|
2387
|
+
}
|
|
2388
|
+
function maskJsonStrings(line) {
|
|
2389
|
+
let changed = false;
|
|
2390
|
+
const text = line.replace(/"(?:[^"\\]|\\.)*"/g, () => {
|
|
2391
|
+
changed = true;
|
|
2392
|
+
return `"${REDACTION_MARKER}"`;
|
|
2393
|
+
});
|
|
2394
|
+
return { text, changed };
|
|
2395
|
+
}
|
|
2379
2396
|
function redactStructuredValues(text, filePath, recordFinding) {
|
|
2380
2397
|
if (!isStructuredFile(filePath)) return text;
|
|
2381
2398
|
const segments = text.split(LINE_BREAK);
|
|
@@ -2388,6 +2405,7 @@ function redactStructuredValues(text, filePath, recordFinding) {
|
|
|
2388
2405
|
if (!CREDENTIAL_KEY_TAIL.test(key)) continue;
|
|
2389
2406
|
const baseIndent = (match[1] ?? "").length;
|
|
2390
2407
|
const rest = (match[4] ?? "").trim();
|
|
2408
|
+
const restIsComment = rest.startsWith("#");
|
|
2391
2409
|
if (BLOCK_SCALAR.test(rest)) {
|
|
2392
2410
|
let cursor2 = index + 2;
|
|
2393
2411
|
let masked2 = false;
|
|
@@ -2404,14 +2422,67 @@ function redactStructuredValues(text, filePath, recordFinding) {
|
|
|
2404
2422
|
if (masked2) recordFinding(index / 2 + 1, ["credential-block-scalar"]);
|
|
2405
2423
|
continue;
|
|
2406
2424
|
}
|
|
2407
|
-
if (
|
|
2425
|
+
if (isJsonFile(filePath) && rest.startsWith("[") && !rest.startsWith(REDACTION_MARKER)) {
|
|
2426
|
+
let cursor2 = index;
|
|
2427
|
+
let masked2 = false;
|
|
2428
|
+
let depth = 0;
|
|
2429
|
+
do {
|
|
2430
|
+
const body = segments[cursor2] ?? "";
|
|
2431
|
+
const start = cursor2 === index ? body.length - (match[4] ?? "").length : 0;
|
|
2432
|
+
const head = body.slice(0, start);
|
|
2433
|
+
const tail = body.slice(start);
|
|
2434
|
+
const maskedTail = maskJsonStrings(tail);
|
|
2435
|
+
if (maskedTail.changed) {
|
|
2436
|
+
masked2 = true;
|
|
2437
|
+
segments[cursor2] = head + maskedTail.text;
|
|
2438
|
+
}
|
|
2439
|
+
depth += (tail.match(/\[/g)?.length ?? 0) - (tail.match(/\]/g)?.length ?? 0);
|
|
2440
|
+
cursor2 += 2;
|
|
2441
|
+
} while (cursor2 < segments.length && depth > 0);
|
|
2442
|
+
if (masked2) recordFinding(index / 2 + 1, ["credential-array-value"]);
|
|
2443
|
+
continue;
|
|
2444
|
+
}
|
|
2445
|
+
const quotedKey = /^["']/.test(line.slice((match[1] ?? "").length));
|
|
2446
|
+
const commentAt = rest.search(/[ \t]#/);
|
|
2447
|
+
const valueText = commentAt >= 0 ? rest.slice(0, commentAt) : rest;
|
|
2448
|
+
const valueSuffix = commentAt >= 0 ? rest.slice(commentAt) : "";
|
|
2449
|
+
const markerOnly = valueText === REDACTION_MARKER || valueText === `"${REDACTION_MARKER}"` || valueText.replace(REDACTION_MARKER, "").trim() === "";
|
|
2450
|
+
if (valueText !== "" && !restIsComment && !/^["'`]/.test(valueText) && (quotedKey || valueText.includes("&") || valueText.startsWith(REDACTION_MARKER))) {
|
|
2451
|
+
if (markerOnly) continue;
|
|
2452
|
+
const prefix = line.slice(0, line.length - rest.length);
|
|
2453
|
+
segments[index] = prefix + (isJsonFile(filePath) ? `"${REDACTION_MARKER}"` : REDACTION_MARKER) + valueSuffix;
|
|
2454
|
+
recordFinding(index / 2 + 1, ["credential-scalar-value"]);
|
|
2455
|
+
continue;
|
|
2456
|
+
}
|
|
2457
|
+
if (rest !== "" && !restIsComment) continue;
|
|
2408
2458
|
let cursor = index + 2;
|
|
2409
2459
|
while (cursor < segments.length && (segments[cursor] ?? "").trim() === "") cursor += 2;
|
|
2410
2460
|
const firstValue = segments[cursor];
|
|
2411
2461
|
if (firstValue === void 0) continue;
|
|
2412
2462
|
const valueIndent = (/^[ \t]*/.exec(firstValue)?.[0] ?? "").length;
|
|
2413
2463
|
if (valueIndent <= baseIndent) continue;
|
|
2414
|
-
if (STRUCTURED_KEY.test(firstValue)
|
|
2464
|
+
if (STRUCTURED_KEY.test(firstValue) && !YAML_LIST_ITEM.test(firstValue)) continue;
|
|
2465
|
+
if (YAML_LIST_ITEM.test(firstValue)) {
|
|
2466
|
+
let masked2 = false;
|
|
2467
|
+
while (cursor < segments.length) {
|
|
2468
|
+
const body = segments[cursor] ?? "";
|
|
2469
|
+
if (body.trim() === "") {
|
|
2470
|
+
cursor += 2;
|
|
2471
|
+
continue;
|
|
2472
|
+
}
|
|
2473
|
+
const item = YAML_LIST_ITEM.exec(body);
|
|
2474
|
+
const indent = (/^[ \t]*/.exec(body)?.[0] ?? "").length;
|
|
2475
|
+
if (indent < valueIndent || item === null) break;
|
|
2476
|
+
const content = (item[2] ?? "").trim();
|
|
2477
|
+
if (content !== "" && !/^[A-Za-z0-9_$.-]+:/.test(content)) {
|
|
2478
|
+
if (!isMarkerLine(content)) masked2 = true;
|
|
2479
|
+
segments[cursor] = (item[1] ?? "") + REDACTION_MARKER;
|
|
2480
|
+
}
|
|
2481
|
+
cursor += 2;
|
|
2482
|
+
}
|
|
2483
|
+
if (masked2) recordFinding(index / 2 + 1, ["credential-list-value"]);
|
|
2484
|
+
continue;
|
|
2485
|
+
}
|
|
2415
2486
|
let masked = false;
|
|
2416
2487
|
while (cursor < segments.length) {
|
|
2417
2488
|
const body = segments[cursor] ?? "";
|
|
@@ -2428,20 +2499,118 @@ function redactStructuredValues(text, filePath, recordFinding) {
|
|
|
2428
2499
|
return segments.join("");
|
|
2429
2500
|
}
|
|
2430
2501
|
var DOCKERFILE_ENV = /^([ \t]*)(ENV|ARG)([ \t]+)([A-Za-z_][A-Za-z0-9_]*)([ \t]*=[ \t]*|[ \t]+)(\S.*)$/i;
|
|
2502
|
+
var DOCKERFILE_LEADING_CONTINUATION = /^([ \t]*)(ENV|ARG)[ \t]*\\[ \t]*$/i;
|
|
2431
2503
|
function endsWithDockerContinuation(line) {
|
|
2432
|
-
|
|
2504
|
+
let end = line.length;
|
|
2505
|
+
while (end > 0 && (line[end - 1] === " " || line[end - 1] === " ")) end -= 1;
|
|
2506
|
+
const trimmed = line.slice(0, end);
|
|
2433
2507
|
let count = 0;
|
|
2434
|
-
while (count <
|
|
2508
|
+
while (count < trimmed.length && trimmed[trimmed.length - 1 - count] === "\\") count += 1;
|
|
2435
2509
|
return count % 2 === 1;
|
|
2436
2510
|
}
|
|
2511
|
+
function isBenignDockerValue(value) {
|
|
2512
|
+
return value === "" || isMarkerLine(value) || isPlaceholderValue(value) || isShellReference(value);
|
|
2513
|
+
}
|
|
2514
|
+
function firstSensitiveAssignment(segments, start, end) {
|
|
2515
|
+
const assignment = /(?:^|[ \t])([A-Za-z_][A-Za-z0-9_]*)[ \t]*=[ \t]*/g;
|
|
2516
|
+
for (let at = start; at <= end; at += 2) {
|
|
2517
|
+
const line = segments[at] ?? "";
|
|
2518
|
+
assignment.lastIndex = 0;
|
|
2519
|
+
let match;
|
|
2520
|
+
while ((match = assignment.exec(line)) !== null) {
|
|
2521
|
+
const key = match[1] ?? "";
|
|
2522
|
+
if (!CREDENTIAL_KEY_TAIL.test(key)) continue;
|
|
2523
|
+
const valueStart = match.index + match[0].length;
|
|
2524
|
+
const parts = [];
|
|
2525
|
+
const first = line.slice(valueStart).replace(/\\[ \t]*$/, "").trim();
|
|
2526
|
+
if (first !== "") parts.push(first);
|
|
2527
|
+
if (first === "" && !endsWithDockerContinuation(line)) continue;
|
|
2528
|
+
for (let next = at + 2; next <= end; next += 2) {
|
|
2529
|
+
const part = (segments[next] ?? "").replace(/\\[ \t]*$/, "").trim();
|
|
2530
|
+
if (part !== "") parts.push(part);
|
|
2531
|
+
}
|
|
2532
|
+
if (parts.length === 0) continue;
|
|
2533
|
+
if (parts.every(isBenignDockerValue)) continue;
|
|
2534
|
+
return { at, valueStart };
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
return null;
|
|
2538
|
+
}
|
|
2539
|
+
function maskDockerAssignment(segments, start, end, found) {
|
|
2540
|
+
for (let at = start; at <= end; at += 2) {
|
|
2541
|
+
if (at < found.at) continue;
|
|
2542
|
+
const body = segments[at] ?? "";
|
|
2543
|
+
const keep = endsWithDockerContinuation(body);
|
|
2544
|
+
segments[at] = at === found.at ? body.slice(0, found.valueStart) + REDACTION_MARKER + (keep ? " \\" : "") : maskLineContent(body.replace(/\\[ \t]*$/, "")) + (keep ? " \\" : "");
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
function firstSpaceSeparatedSecret(segments, start, end) {
|
|
2548
|
+
for (let at = start; at <= end; at += 2) {
|
|
2549
|
+
const body = segments[at] ?? "";
|
|
2550
|
+
const match = /^([ \t]*)([A-Za-z_][A-Za-z0-9_]*)([ \t]+)(\S.*)$/.exec(body);
|
|
2551
|
+
if (match === null) continue;
|
|
2552
|
+
if (!CREDENTIAL_KEY_TAIL.test(match[2] ?? "")) continue;
|
|
2553
|
+
const first = (match[4] ?? "").replace(/\\[ \t]*$/, "").trim();
|
|
2554
|
+
const parts = [];
|
|
2555
|
+
if (first !== "") parts.push(first);
|
|
2556
|
+
if (first === "" && !endsWithDockerContinuation(body)) continue;
|
|
2557
|
+
for (let next = at + 2; next <= end; next += 2) {
|
|
2558
|
+
const part = (segments[next] ?? "").replace(/\\[ \t]*$/, "").trim();
|
|
2559
|
+
if (part !== "") parts.push(part);
|
|
2560
|
+
}
|
|
2561
|
+
if (parts.length === 0 || parts.every(isBenignDockerValue)) continue;
|
|
2562
|
+
return {
|
|
2563
|
+
at,
|
|
2564
|
+
valueStart: (match[1] ?? "").length + (match[2] ?? "").length + (match[3] ?? "").length
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
return null;
|
|
2568
|
+
}
|
|
2437
2569
|
function redactDockerfileEnv(text, filePath, recordFinding) {
|
|
2438
2570
|
if (!isDockerfile(filePath)) return text;
|
|
2439
2571
|
const segments = text.split(LINE_BREAK);
|
|
2440
2572
|
for (let index = 0; index < segments.length; index += 2) {
|
|
2441
2573
|
const line = segments[index];
|
|
2442
2574
|
if (line === void 0) continue;
|
|
2575
|
+
const leading = DOCKERFILE_LEADING_CONTINUATION.exec(line);
|
|
2576
|
+
if (leading !== null) {
|
|
2577
|
+
let end = index;
|
|
2578
|
+
let current2 = line;
|
|
2579
|
+
while (endsWithDockerContinuation(current2) && end + 2 < segments.length) {
|
|
2580
|
+
end += 2;
|
|
2581
|
+
current2 = segments[end] ?? "";
|
|
2582
|
+
}
|
|
2583
|
+
const found = firstSensitiveAssignment(segments, index, end);
|
|
2584
|
+
if (found !== null) {
|
|
2585
|
+
maskDockerAssignment(segments, index, end, found);
|
|
2586
|
+
recordFinding(found.at / 2 + 1, ["dockerfile-env-secret"]);
|
|
2587
|
+
} else {
|
|
2588
|
+
const spaced = firstSpaceSeparatedSecret(segments, index + 2, end);
|
|
2589
|
+
if (spaced !== null) {
|
|
2590
|
+
maskDockerAssignment(segments, index, end, spaced);
|
|
2591
|
+
recordFinding(spaced.at / 2 + 1, ["dockerfile-env-secret"]);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
index = end;
|
|
2595
|
+
continue;
|
|
2596
|
+
}
|
|
2443
2597
|
const match = DOCKERFILE_ENV.exec(line);
|
|
2444
2598
|
if (match === null) continue;
|
|
2599
|
+
const assignmentForm = (match[5] ?? "").includes("=");
|
|
2600
|
+
if (assignmentForm) {
|
|
2601
|
+
let end = index;
|
|
2602
|
+
let current2 = line;
|
|
2603
|
+
while (endsWithDockerContinuation(current2) && end + 2 < segments.length) {
|
|
2604
|
+
end += 2;
|
|
2605
|
+
current2 = segments[end] ?? "";
|
|
2606
|
+
}
|
|
2607
|
+
const found = firstSensitiveAssignment(segments, index, end);
|
|
2608
|
+
if (found === null) continue;
|
|
2609
|
+
maskDockerAssignment(segments, index, end, found);
|
|
2610
|
+
recordFinding(found.at / 2 + 1, ["dockerfile-env-secret"]);
|
|
2611
|
+
index = end;
|
|
2612
|
+
continue;
|
|
2613
|
+
}
|
|
2445
2614
|
if (!CREDENTIAL_KEY_TAIL.test(match[4] ?? "")) continue;
|
|
2446
2615
|
const value = (match[6] ?? "").trim();
|
|
2447
2616
|
const continuationLines = [];
|
|
@@ -2458,9 +2627,7 @@ function redactDockerfileEnv(text, filePath, recordFinding) {
|
|
|
2458
2627
|
}
|
|
2459
2628
|
combined = combined.trim();
|
|
2460
2629
|
const keepContinuation = endsWithDockerContinuation(line);
|
|
2461
|
-
if (markerOnly ||
|
|
2462
|
-
continue;
|
|
2463
|
-
}
|
|
2630
|
+
if (markerOnly || isBenignDockerValue(combined)) continue;
|
|
2464
2631
|
const separator = match[5] ?? "";
|
|
2465
2632
|
segments[index] = `${match[1]}${match[2]}${match[3]}${match[4]}${separator}${REDACTION_MARKER}`;
|
|
2466
2633
|
if (keepContinuation) segments[index] += " \\";
|
|
@@ -2577,7 +2744,12 @@ function isMarkerLine(value) {
|
|
|
2577
2744
|
return trimmed === REDACTION_MARKER || trimmed === PEM_REDACTION_MARKER;
|
|
2578
2745
|
}
|
|
2579
2746
|
function isPlaceholderValue(value) {
|
|
2580
|
-
const
|
|
2747
|
+
const base = value.trim();
|
|
2748
|
+
let start = 0;
|
|
2749
|
+
while (start < base.length && (base[start] === '"' || base[start] === "'" || base[start] === "`")) start += 1;
|
|
2750
|
+
let end = base.length;
|
|
2751
|
+
while (end > start && (base[end - 1] === '"' || base[end - 1] === "'" || base[end - 1] === "`")) end -= 1;
|
|
2752
|
+
const trimmed = base.slice(start, end);
|
|
2581
2753
|
if (trimmed.length === 0) return false;
|
|
2582
2754
|
if (PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
|
|
2583
2755
|
if (trimmed === REDACTION_MARKER || trimmed === PEM_REDACTION_MARKER) return true;
|
|
@@ -2635,7 +2807,7 @@ function isShellFile(filePath) {
|
|
|
2635
2807
|
return SHELL_FILE.test(normalised) || SHELL_BASENAME.test(normalised.slice(normalised.lastIndexOf("/") + 1));
|
|
2636
2808
|
}
|
|
2637
2809
|
function isShellReference(value) {
|
|
2638
|
-
return /^\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[
|
|
2810
|
+
return /^\$(?:[A-Za-z_][A-Za-z0-9_]*|\{[A-Za-z_][A-Za-z0-9_]*\}|\([^)]*\))$/.test(value);
|
|
2639
2811
|
}
|
|
2640
2812
|
function isUnquotedValue(line, start) {
|
|
2641
2813
|
const before = start > 0 ? line[start - 1] : "";
|
|
@@ -2841,8 +3013,8 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2841
3013
|
return out;
|
|
2842
3014
|
}
|
|
2843
3015
|
function isInside(parent, child) {
|
|
2844
|
-
const
|
|
2845
|
-
return
|
|
3016
|
+
const relative14 = path7__namespace.relative(parent, child);
|
|
3017
|
+
return relative14 === "" || relative14 !== ".." && !relative14.startsWith(`..${path7__namespace.sep}`) && !relative14.startsWith("../") && !path7__namespace.isAbsolute(relative14);
|
|
2846
3018
|
}
|
|
2847
3019
|
function resolveConfined(baseDir, relativePath) {
|
|
2848
3020
|
if (relativePath.length === 0 || relativePath.includes("\0")) {
|
|
@@ -2853,7 +3025,7 @@ function resolveConfined(baseDir, relativePath) {
|
|
|
2853
3025
|
}
|
|
2854
3026
|
let baseReal;
|
|
2855
3027
|
try {
|
|
2856
|
-
baseReal =
|
|
3028
|
+
baseReal = fs18__namespace.realpathSync(path7__namespace.resolve(baseDir));
|
|
2857
3029
|
} catch {
|
|
2858
3030
|
return { ok: false, reason: "missing", message: "the snapshot directory does not exist" };
|
|
2859
3031
|
}
|
|
@@ -2863,7 +3035,7 @@ function resolveConfined(baseDir, relativePath) {
|
|
|
2863
3035
|
}
|
|
2864
3036
|
let stats;
|
|
2865
3037
|
try {
|
|
2866
|
-
stats =
|
|
3038
|
+
stats = fs18__namespace.lstatSync(candidate);
|
|
2867
3039
|
} catch (error) {
|
|
2868
3040
|
const code = error.code;
|
|
2869
3041
|
return {
|
|
@@ -2880,7 +3052,7 @@ function resolveConfined(baseDir, relativePath) {
|
|
|
2880
3052
|
}
|
|
2881
3053
|
let real;
|
|
2882
3054
|
try {
|
|
2883
|
-
real =
|
|
3055
|
+
real = fs18__namespace.realpathSync(candidate);
|
|
2884
3056
|
} catch {
|
|
2885
3057
|
return { ok: false, reason: "unreadable", message: "the file could not be resolved" };
|
|
2886
3058
|
}
|
|
@@ -2900,7 +3072,7 @@ function readConfinedBytes(baseDir, relativePath, maxBytes) {
|
|
|
2900
3072
|
};
|
|
2901
3073
|
}
|
|
2902
3074
|
try {
|
|
2903
|
-
const bytes =
|
|
3075
|
+
const bytes = fs18__namespace.readFileSync(resolved.path);
|
|
2904
3076
|
return { ok: true, bytes, path: resolved.path, stats: resolved.stats };
|
|
2905
3077
|
} catch {
|
|
2906
3078
|
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
@@ -2917,7 +3089,7 @@ function readConfinedText(baseDir, relativePath, maxBytes) {
|
|
|
2917
3089
|
};
|
|
2918
3090
|
}
|
|
2919
3091
|
try {
|
|
2920
|
-
const text =
|
|
3092
|
+
const text = fs18__namespace.readFileSync(resolved.path, "utf8");
|
|
2921
3093
|
return { ok: true, text, path: resolved.path, stats: resolved.stats };
|
|
2922
3094
|
} catch {
|
|
2923
3095
|
return { ok: false, reason: "unreadable", message: "the file could not be read" };
|
|
@@ -2980,7 +3152,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
2980
3152
|
|
|
2981
3153
|
// src/version.ts
|
|
2982
3154
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2983
|
-
var GENERATOR_VERSION = "0.22.
|
|
3155
|
+
var GENERATOR_VERSION = "0.22.1";
|
|
2984
3156
|
var SCHEMA_VERSION = "3.0.0";
|
|
2985
3157
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2986
3158
|
function isOurGeneratorName(name) {
|
|
@@ -2997,7 +3169,7 @@ var PRESET_IGNORES = new Set(
|
|
|
2997
3169
|
);
|
|
2998
3170
|
function readLinkTarget(linkPath, fallback) {
|
|
2999
3171
|
try {
|
|
3000
|
-
return
|
|
3172
|
+
return fs18__namespace.readlinkSync(linkPath);
|
|
3001
3173
|
} catch {
|
|
3002
3174
|
return fallback;
|
|
3003
3175
|
}
|
|
@@ -3012,8 +3184,8 @@ function brokenLinkRecord(linkPath, relativePath, rootReal) {
|
|
|
3012
3184
|
};
|
|
3013
3185
|
}
|
|
3014
3186
|
function isInside2(root, candidate) {
|
|
3015
|
-
const
|
|
3016
|
-
return
|
|
3187
|
+
const relative14 = path7__namespace.relative(root, candidate);
|
|
3188
|
+
return relative14 === "" || !relative14.startsWith(`..${path7__namespace.sep}`) && relative14 !== ".." && !path7__namespace.isAbsolute(relative14);
|
|
3017
3189
|
}
|
|
3018
3190
|
var GIT_OUTPUT_LIMIT = 68157440;
|
|
3019
3191
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
@@ -3335,7 +3507,7 @@ function readGitignoreRules(dir) {
|
|
|
3335
3507
|
const gitignorePath = path7__namespace.join(dir, ".gitignore");
|
|
3336
3508
|
let raw;
|
|
3337
3509
|
try {
|
|
3338
|
-
raw =
|
|
3510
|
+
raw = fs18__namespace.readFileSync(gitignorePath, "utf8");
|
|
3339
3511
|
} catch {
|
|
3340
3512
|
return [];
|
|
3341
3513
|
}
|
|
@@ -3427,12 +3599,7 @@ function compileGitignorePattern(pattern) {
|
|
|
3427
3599
|
}
|
|
3428
3600
|
function matchesGitignoreRule(rule, scoped, isDirectory) {
|
|
3429
3601
|
if (!rule.dirOnly) return matchGitignorePattern(scoped, rule.pattern);
|
|
3430
|
-
|
|
3431
|
-
const limit = isDirectory ? segments.length : segments.length - 1;
|
|
3432
|
-
for (let depth = 1; depth <= limit; depth += 1) {
|
|
3433
|
-
if (matchGitignorePattern(segments.slice(0, depth).join("/"), rule.pattern)) return true;
|
|
3434
|
-
}
|
|
3435
|
-
return false;
|
|
3602
|
+
return isDirectory && matchGitignorePattern(scoped, rule.pattern);
|
|
3436
3603
|
}
|
|
3437
3604
|
function gitignoreVerdict(layers, relativePath, isDirectory) {
|
|
3438
3605
|
let verdict = null;
|
|
@@ -3509,7 +3676,7 @@ function listIgnoredPaths(cwd) {
|
|
|
3509
3676
|
}
|
|
3510
3677
|
function hasSnapshotMarker(target) {
|
|
3511
3678
|
try {
|
|
3512
|
-
return
|
|
3679
|
+
return fs18__namespace.statSync(target).isDirectory() && isToolOwnedDirectory2(target);
|
|
3513
3680
|
} catch {
|
|
3514
3681
|
return false;
|
|
3515
3682
|
}
|
|
@@ -3518,7 +3685,7 @@ var IGNORABLE_DIRECTORY_ENTRIES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
|
3518
3685
|
function isToolOwnedDirectory2(dir) {
|
|
3519
3686
|
let raw;
|
|
3520
3687
|
try {
|
|
3521
|
-
raw =
|
|
3688
|
+
raw = fs18__namespace.readFileSync(path7__namespace.join(dir, ".codebase-snapshot"), "utf8");
|
|
3522
3689
|
} catch {
|
|
3523
3690
|
return false;
|
|
3524
3691
|
}
|
|
@@ -3535,7 +3702,7 @@ function isToolOwnedDirectory2(dir) {
|
|
|
3535
3702
|
}
|
|
3536
3703
|
let manifestBytes;
|
|
3537
3704
|
try {
|
|
3538
|
-
manifestBytes =
|
|
3705
|
+
manifestBytes = fs18__namespace.readFileSync(path7__namespace.join(dir, "manifest.json"));
|
|
3539
3706
|
} catch {
|
|
3540
3707
|
return false;
|
|
3541
3708
|
}
|
|
@@ -3553,14 +3720,14 @@ function isToolOwnedDirectory2(dir) {
|
|
|
3553
3720
|
const full = path7__namespace.join(dir, ...entry.split("/"));
|
|
3554
3721
|
let stats;
|
|
3555
3722
|
try {
|
|
3556
|
-
stats =
|
|
3723
|
+
stats = fs18__namespace.lstatSync(full);
|
|
3557
3724
|
} catch {
|
|
3558
3725
|
return false;
|
|
3559
3726
|
}
|
|
3560
3727
|
if (!stats.isFile() || stats.size !== record.bytes) return false;
|
|
3561
3728
|
let digest;
|
|
3562
3729
|
try {
|
|
3563
|
-
digest = crypto.createHash("sha256").update(
|
|
3730
|
+
digest = crypto.createHash("sha256").update(fs18__namespace.readFileSync(full)).digest("hex");
|
|
3564
3731
|
} catch {
|
|
3565
3732
|
return false;
|
|
3566
3733
|
}
|
|
@@ -3572,22 +3739,22 @@ function isToolOwnedDirectory2(dir) {
|
|
|
3572
3739
|
const current = stack.pop();
|
|
3573
3740
|
let entries;
|
|
3574
3741
|
try {
|
|
3575
|
-
entries =
|
|
3742
|
+
entries = fs18__namespace.readdirSync(path7__namespace.join(dir, current), { withFileTypes: true });
|
|
3576
3743
|
} catch {
|
|
3577
3744
|
return false;
|
|
3578
3745
|
}
|
|
3579
3746
|
for (const entry of entries) {
|
|
3580
|
-
const
|
|
3581
|
-
if (
|
|
3747
|
+
const relative14 = current === "" ? entry.name : current + "/" + entry.name;
|
|
3748
|
+
if (relative14 === ".codebase-snapshot" || IGNORABLE_DIRECTORY_ENTRIES.has(entry.name)) continue;
|
|
3582
3749
|
if (entry.isDirectory()) {
|
|
3583
|
-
stack.push(
|
|
3750
|
+
stack.push(relative14);
|
|
3584
3751
|
continue;
|
|
3585
3752
|
}
|
|
3586
3753
|
if (!entry.isFile()) return false;
|
|
3587
|
-
if (
|
|
3754
|
+
if (relative14 === "signature.json" && !recordedFiles.has(relative14) && verifySnapshotSignature(dir).ok) {
|
|
3588
3755
|
continue;
|
|
3589
3756
|
}
|
|
3590
|
-
if (!recordedFiles.has(
|
|
3757
|
+
if (!recordedFiles.has(relative14)) return false;
|
|
3591
3758
|
}
|
|
3592
3759
|
}
|
|
3593
3760
|
return true;
|
|
@@ -3619,7 +3786,7 @@ function makeLinkProbe() {
|
|
|
3619
3786
|
let known = cache.get(absolutePath);
|
|
3620
3787
|
if (known === void 0) {
|
|
3621
3788
|
try {
|
|
3622
|
-
known =
|
|
3789
|
+
known = fs18__namespace.lstatSync(absolutePath).isSymbolicLink();
|
|
3623
3790
|
} catch {
|
|
3624
3791
|
known = false;
|
|
3625
3792
|
}
|
|
@@ -3632,7 +3799,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3632
3799
|
const isLink = makeLinkProbe();
|
|
3633
3800
|
let rootReal = cwd;
|
|
3634
3801
|
try {
|
|
3635
|
-
rootReal =
|
|
3802
|
+
rootReal = fs18__namespace.realpathSync(cwd);
|
|
3636
3803
|
} catch {
|
|
3637
3804
|
}
|
|
3638
3805
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -3660,7 +3827,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3660
3827
|
const rawTarget = readLinkTarget(absolute, absolute);
|
|
3661
3828
|
let targetReal = null;
|
|
3662
3829
|
try {
|
|
3663
|
-
targetReal =
|
|
3830
|
+
targetReal = fs18__namespace.realpathSync(absolute);
|
|
3664
3831
|
} catch {
|
|
3665
3832
|
targetReal = null;
|
|
3666
3833
|
}
|
|
@@ -3678,7 +3845,7 @@ function dropLinkedDirectories(cwd, candidates, skipped) {
|
|
|
3678
3845
|
}
|
|
3679
3846
|
let stats = null;
|
|
3680
3847
|
try {
|
|
3681
|
-
stats =
|
|
3848
|
+
stats = fs18__namespace.statSync(absolute);
|
|
3682
3849
|
} catch {
|
|
3683
3850
|
stats = null;
|
|
3684
3851
|
}
|
|
@@ -3784,7 +3951,7 @@ function collectFiles(cwd, options = {}) {
|
|
|
3784
3951
|
"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."
|
|
3785
3952
|
);
|
|
3786
3953
|
}
|
|
3787
|
-
if (
|
|
3954
|
+
if (fs18__namespace.existsSync(path7__namespace.join(cwd, ".git"))) {
|
|
3788
3955
|
throw new Error(
|
|
3789
3956
|
"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."
|
|
3790
3957
|
);
|
|
@@ -3864,7 +4031,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
3864
4031
|
const aliases = /* @__PURE__ */ new Set();
|
|
3865
4032
|
for (const file of files) {
|
|
3866
4033
|
try {
|
|
3867
|
-
if (
|
|
4034
|
+
if (fs18__namespace.lstatSync(path7__namespace.join(cwd, file)).isSymbolicLink()) aliases.add(file);
|
|
3868
4035
|
} catch {
|
|
3869
4036
|
}
|
|
3870
4037
|
}
|
|
@@ -3873,7 +4040,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
3873
4040
|
for (const file of files) {
|
|
3874
4041
|
if (aliases.has(file)) continue;
|
|
3875
4042
|
try {
|
|
3876
|
-
includedTargets.add(
|
|
4043
|
+
includedTargets.add(fs18__namespace.realpathSync(path7__namespace.join(cwd, file)));
|
|
3877
4044
|
} catch {
|
|
3878
4045
|
}
|
|
3879
4046
|
}
|
|
@@ -3885,7 +4052,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
3885
4052
|
}
|
|
3886
4053
|
let target;
|
|
3887
4054
|
try {
|
|
3888
|
-
target =
|
|
4055
|
+
target = fs18__namespace.realpathSync(path7__namespace.join(cwd, file));
|
|
3889
4056
|
} catch {
|
|
3890
4057
|
skipped.push({ path: file, reason: "read-error", detail: "symlink target could not be resolved" });
|
|
3891
4058
|
continue;
|
|
@@ -3904,7 +4071,7 @@ function dropSymlinksToUnincludedTargets(cwd, files, skipped) {
|
|
|
3904
4071
|
}
|
|
3905
4072
|
function rootRealFor(root) {
|
|
3906
4073
|
try {
|
|
3907
|
-
return
|
|
4074
|
+
return fs18__namespace.realpathSync(root);
|
|
3908
4075
|
} catch {
|
|
3909
4076
|
return root;
|
|
3910
4077
|
}
|
|
@@ -3924,7 +4091,7 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3924
4091
|
];
|
|
3925
4092
|
let entries;
|
|
3926
4093
|
try {
|
|
3927
|
-
entries =
|
|
4094
|
+
entries = fs18__namespace.readdirSync(current, { withFileTypes: true });
|
|
3928
4095
|
} catch {
|
|
3929
4096
|
results.skipped.push({
|
|
3930
4097
|
path: relativeToBase(current),
|
|
@@ -3988,14 +4155,14 @@ function walkDirectory(dir, baseDir, rootReal, visited, reservedPaths = /* @__PU
|
|
|
3988
4155
|
if (entry.isSymbolicLink()) {
|
|
3989
4156
|
let targetReal;
|
|
3990
4157
|
try {
|
|
3991
|
-
targetReal =
|
|
4158
|
+
targetReal = fs18__namespace.realpathSync(fullPath);
|
|
3992
4159
|
} catch {
|
|
3993
4160
|
results.skipped.push(brokenLinkRecord(fullPath, relPath, rootReal));
|
|
3994
4161
|
continue;
|
|
3995
4162
|
}
|
|
3996
4163
|
let stats;
|
|
3997
4164
|
try {
|
|
3998
|
-
stats =
|
|
4165
|
+
stats = fs18__namespace.statSync(fullPath);
|
|
3999
4166
|
} catch {
|
|
4000
4167
|
results.skipped.push({ path: relPath, reason: "read-error", detail: "unreadable symlink" });
|
|
4001
4168
|
continue;
|
|
@@ -4263,6 +4430,17 @@ function assertServerSafeConfig(config, source = "The configuration") {
|
|
|
4263
4430
|
source + " enables includeSensitiveFiles. The MCP and serve transports never emit sensitive files; remove that setting or run the CLI directly."
|
|
4264
4431
|
);
|
|
4265
4432
|
}
|
|
4433
|
+
if (config.cwd !== void 0) {
|
|
4434
|
+
if (typeof config.cwd !== "string" || config.cwd.trim() === "") {
|
|
4435
|
+
throw new Error(source + " has an invalid cwd; it must be a non-empty path string.");
|
|
4436
|
+
}
|
|
4437
|
+
const normalized = config.cwd.replace(/\\/g, "/");
|
|
4438
|
+
if (path7__namespace.isAbsolute(config.cwd) || normalized.split("/").includes("..")) {
|
|
4439
|
+
throw new Error(
|
|
4440
|
+
source + " sets cwd to " + config.cwd + ". The MCP and serve transports confine every run to the repository they were started for; remove cwd or make it a relative subdirectory."
|
|
4441
|
+
);
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4266
4444
|
if (config.secrets !== void 0 && config.secrets !== null) {
|
|
4267
4445
|
if (config.secrets.disableDefaultPatterns === true) {
|
|
4268
4446
|
throw new Error(
|
|
@@ -4354,20 +4532,25 @@ function normalizeResolvedConfig(config) {
|
|
|
4354
4532
|
`maxPartBytes must be at least ${MIN_MAX_PART_BYTES} bytes (received ${String(config.maxPartBytes)}).`
|
|
4355
4533
|
);
|
|
4356
4534
|
}
|
|
4357
|
-
if (!Number.isSafeInteger(config.largeFileBytes) || config.largeFileBytes <
|
|
4535
|
+
if (!Number.isSafeInteger(config.largeFileBytes) || config.largeFileBytes < 1) {
|
|
4536
|
+
throw new Error(
|
|
4537
|
+
`largeFileBytes must be a positive integer; received ${String(config.largeFileBytes)}.`
|
|
4538
|
+
);
|
|
4539
|
+
}
|
|
4540
|
+
if (config.largeFileBytes > config.maxPartBytes) {
|
|
4358
4541
|
throw new Error(
|
|
4359
|
-
`largeFileBytes
|
|
4542
|
+
`largeFileBytes (${config.largeFileBytes} B) is larger than maxPartBytes (${config.maxPartBytes} B). Raise maxPartBytes, or lower largeFileBytes.`
|
|
4360
4543
|
);
|
|
4361
4544
|
}
|
|
4362
|
-
const maxPartTokens = config.maxPartTokens
|
|
4363
|
-
if (!Number.isSafeInteger(maxPartTokens) || maxPartTokens < MIN_MAX_PART_TOKENS) {
|
|
4545
|
+
const maxPartTokens = config.maxPartTokens;
|
|
4546
|
+
if (maxPartTokens !== void 0 && (!Number.isSafeInteger(maxPartTokens) || maxPartTokens < MIN_MAX_PART_TOKENS)) {
|
|
4364
4547
|
throw new Error(
|
|
4365
4548
|
`maxPartTokens must be at least ${MIN_MAX_PART_TOKENS} tokens; received ${String(maxPartTokens)}.`
|
|
4366
4549
|
);
|
|
4367
4550
|
}
|
|
4368
4551
|
return markResolvedConfig({
|
|
4369
4552
|
...config,
|
|
4370
|
-
maxPartTokens,
|
|
4553
|
+
...maxPartTokens === void 0 ? {} : { maxPartTokens },
|
|
4371
4554
|
discovery,
|
|
4372
4555
|
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
4373
4556
|
// is re-validated because the number reaches a rendered artifact.
|
|
@@ -4523,10 +4706,10 @@ function readConfigExport(exported, file) {
|
|
|
4523
4706
|
var lastModuleConfig = null;
|
|
4524
4707
|
function moduleConfigKey(fullPath) {
|
|
4525
4708
|
try {
|
|
4526
|
-
return crypto.createHash("sha256").update(
|
|
4709
|
+
return crypto.createHash("sha256").update(fs18__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
4527
4710
|
} catch {
|
|
4528
4711
|
try {
|
|
4529
|
-
const stats =
|
|
4712
|
+
const stats = fs18__namespace.statSync(fullPath);
|
|
4530
4713
|
return `stat-${stats.mtimeMs}-${stats.size}`;
|
|
4531
4714
|
} catch {
|
|
4532
4715
|
return "unreadable";
|
|
@@ -4568,9 +4751,9 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
4568
4751
|
const fullPath = path7__namespace.join(cwd, filename);
|
|
4569
4752
|
let candidateStats = null;
|
|
4570
4753
|
try {
|
|
4571
|
-
candidateStats =
|
|
4754
|
+
candidateStats = fs18__namespace.statSync(fullPath);
|
|
4572
4755
|
} catch {
|
|
4573
|
-
if (!
|
|
4756
|
+
if (!fs18__namespace.existsSync(fullPath)) continue;
|
|
4574
4757
|
}
|
|
4575
4758
|
if (candidateStats !== null && !candidateStats.isFile()) {
|
|
4576
4759
|
configDirectories.push(fullPath);
|
|
@@ -4578,7 +4761,7 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
4578
4761
|
}
|
|
4579
4762
|
if (filename.endsWith(".json") || filename === ".snapshotrc") {
|
|
4580
4763
|
try {
|
|
4581
|
-
const config = parseJsonish(
|
|
4764
|
+
const config = parseJsonish(fs18__namespace.readFileSync(fullPath, "utf8"), fullPath);
|
|
4582
4765
|
if (config === null || typeof config !== "object" || Array.isArray(config)) {
|
|
4583
4766
|
throw new Error(
|
|
4584
4767
|
`${fullPath} does not hold a configuration object (received ${describeValue2(config)}).`
|
|
@@ -4624,9 +4807,9 @@ async function loadConfigFileDetailed(cwd, options = {}) {
|
|
|
4624
4807
|
}
|
|
4625
4808
|
}
|
|
4626
4809
|
const pkgJsonPath = path7__namespace.join(cwd, "package.json");
|
|
4627
|
-
if (
|
|
4810
|
+
if (fs18__namespace.existsSync(pkgJsonPath)) {
|
|
4628
4811
|
try {
|
|
4629
|
-
const parsed = parseJsonish(
|
|
4812
|
+
const parsed = parseJsonish(fs18__namespace.readFileSync(pkgJsonPath, "utf8"), pkgJsonPath);
|
|
4630
4813
|
const snapshotKey = parsed.snapshot;
|
|
4631
4814
|
if (snapshotKey && typeof snapshotKey === "object" && !Array.isArray(snapshotKey)) {
|
|
4632
4815
|
assertKnownConfigKeys(
|
|
@@ -4798,7 +4981,7 @@ function readConfiguredBrief(cwd, value) {
|
|
|
4798
4981
|
}
|
|
4799
4982
|
const rootReal = (() => {
|
|
4800
4983
|
try {
|
|
4801
|
-
return
|
|
4984
|
+
return fs18__namespace.realpathSync(cwd);
|
|
4802
4985
|
} catch {
|
|
4803
4986
|
return path7__namespace.resolve(cwd);
|
|
4804
4987
|
}
|
|
@@ -4806,19 +4989,19 @@ function readConfiguredBrief(cwd, value) {
|
|
|
4806
4989
|
const requested = path7__namespace.resolve(cwd, value);
|
|
4807
4990
|
let filePath;
|
|
4808
4991
|
try {
|
|
4809
|
-
filePath =
|
|
4992
|
+
filePath = fs18__namespace.realpathSync(requested);
|
|
4810
4993
|
} catch {
|
|
4811
4994
|
throw new Error(
|
|
4812
4995
|
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
4813
4996
|
);
|
|
4814
4997
|
}
|
|
4815
|
-
const
|
|
4816
|
-
if (
|
|
4998
|
+
const relative14 = path7__namespace.relative(rootReal, filePath);
|
|
4999
|
+
if (relative14.length === 0 || relative14 === ".." || relative14.startsWith(`..${path7__namespace.sep}`) || path7__namespace.isAbsolute(relative14)) {
|
|
4817
5000
|
throw new Error(
|
|
4818
5001
|
'brief "' + value + '" resolves outside the repository. A brief must be a file inside the repository being described; an absolute or parent path is refused.'
|
|
4819
5002
|
);
|
|
4820
5003
|
}
|
|
4821
|
-
const posixRelative =
|
|
5004
|
+
const posixRelative = relative14.split(path7__namespace.sep).join("/");
|
|
4822
5005
|
if (isSensitivePath(posixRelative) || isSensitivePath(value)) {
|
|
4823
5006
|
throw new Error(
|
|
4824
5007
|
'brief "' + value + '" is a credential-bearing file. A snapshot must not reproduce secrets, so it cannot be used as the owner brief.'
|
|
@@ -4832,14 +5015,14 @@ function readConfiguredBrief(cwd, value) {
|
|
|
4832
5015
|
}
|
|
4833
5016
|
let text;
|
|
4834
5017
|
try {
|
|
4835
|
-
const stats =
|
|
5018
|
+
const stats = fs18__namespace.statSync(filePath);
|
|
4836
5019
|
if (!stats.isFile()) throw new Error("not a file");
|
|
4837
5020
|
if (stats.size > MAX_BRIEF_BYTES) {
|
|
4838
5021
|
throw new Error(
|
|
4839
5022
|
'brief "' + value + '" is ' + stats.size + " bytes; the limit is " + MAX_BRIEF_BYTES + ". Keep it to what a reader can act on, or move the detail into a document the snapshot carries."
|
|
4840
5023
|
);
|
|
4841
5024
|
}
|
|
4842
|
-
text =
|
|
5025
|
+
text = fs18__namespace.readFileSync(filePath, "utf8");
|
|
4843
5026
|
} catch (error) {
|
|
4844
5027
|
if (error instanceof Error && error.message.startsWith('brief "')) throw error;
|
|
4845
5028
|
throw new Error(
|
|
@@ -4966,11 +5149,11 @@ function outputExcludePatterns(cwd, outDir, tmpDir) {
|
|
|
4966
5149
|
const patterns = [];
|
|
4967
5150
|
for (const dir of [outDir, tmpDir]) {
|
|
4968
5151
|
const absolute = path7__namespace.resolve(cwd, dir);
|
|
4969
|
-
const
|
|
4970
|
-
if (!
|
|
5152
|
+
const relative14 = path7__namespace.relative(cwd, absolute);
|
|
5153
|
+
if (!relative14 || relative14 === ".." || relative14.startsWith(`..${path7__namespace.sep}`) || path7__namespace.isAbsolute(relative14)) {
|
|
4971
5154
|
continue;
|
|
4972
5155
|
}
|
|
4973
|
-
patterns.push(`${
|
|
5156
|
+
patterns.push(`${relative14.replace(/\\/g, "/")}/**`);
|
|
4974
5157
|
}
|
|
4975
5158
|
return patterns;
|
|
4976
5159
|
}
|
|
@@ -5108,10 +5291,10 @@ function resolveCandidateCwd(userConfig, cliOptions, baseDir) {
|
|
|
5108
5291
|
}
|
|
5109
5292
|
const candidate = cliOptions?.cwd || userConfig?.cwd || baseDir || process.cwd();
|
|
5110
5293
|
const resolved = path7__namespace.resolve(candidate);
|
|
5111
|
-
if (!
|
|
5294
|
+
if (!fs18__namespace.existsSync(resolved)) {
|
|
5112
5295
|
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
5113
5296
|
}
|
|
5114
|
-
if (!
|
|
5297
|
+
if (!fs18__namespace.statSync(resolved).isDirectory()) {
|
|
5115
5298
|
throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
5116
5299
|
}
|
|
5117
5300
|
return resolved;
|
|
@@ -5265,10 +5448,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5265
5448
|
outDir,
|
|
5266
5449
|
tmpDir,
|
|
5267
5450
|
maxPartBytes: resolvedMaxPartBytes,
|
|
5268
|
-
// Record the
|
|
5269
|
-
//
|
|
5270
|
-
//
|
|
5271
|
-
maxPartTokens
|
|
5451
|
+
// Record only the token ceiling the user named. The byte budget is the enforced limit; a
|
|
5452
|
+
// derived token number is an estimate, and writing it into the manifest made a default run
|
|
5453
|
+
// look like it had chosen one.
|
|
5454
|
+
...maxPartTokens === void 0 ? {} : { maxPartTokens },
|
|
5272
5455
|
largeFileBytes: largeFileBytesFor(resolvedMaxPartBytes, cliOptions, userConfig),
|
|
5273
5456
|
previewHeadLines: strictPositiveInteger(userConfig?.previewHeadLines, 80, "`previewHeadLines`"),
|
|
5274
5457
|
previewTailLines: strictPositiveInteger(userConfig?.previewTailLines, 40, "`previewTailLines`"),
|
|
@@ -5385,7 +5568,7 @@ function configDigest(config) {
|
|
|
5385
5568
|
// The user's own unit. `maxPartBytes` above already reflects the converted ceiling, but
|
|
5386
5569
|
// recording the token number means changing 32k to 64k moves the digest even in the
|
|
5387
5570
|
// corner where both round to the same byte budget.
|
|
5388
|
-
maxPartTokens: config.maxPartTokens
|
|
5571
|
+
maxPartTokens: config.maxPartTokens === void 0 || config.maxPartTokens === Math.floor(config.maxPartBytes / 4) ? null : config.maxPartTokens,
|
|
5389
5572
|
// A changed-files scope decides which files are in the snapshot at all, so a snapshot
|
|
5390
5573
|
// taken over a different scope is a different snapshot.
|
|
5391
5574
|
changedSince: config.changedSince ?? null,
|
|
@@ -5776,9 +5959,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
5776
5959
|
var jvmProfile = {
|
|
5777
5960
|
id: "jvm",
|
|
5778
5961
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
5779
|
-
summarize(
|
|
5962
|
+
summarize(path22, content) {
|
|
5780
5963
|
const summary = emptySummary();
|
|
5781
|
-
const lower =
|
|
5964
|
+
const lower = path22.toLowerCase();
|
|
5782
5965
|
const isJava = lower.endsWith(".java");
|
|
5783
5966
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
5784
5967
|
eachLine(content, (line) => {
|
|
@@ -6001,9 +6184,9 @@ var rubyProfile = {
|
|
|
6001
6184
|
eachLine(content, (line) => {
|
|
6002
6185
|
const trimmed = line.trim();
|
|
6003
6186
|
if (!trimmed || trimmed.startsWith("#")) return;
|
|
6004
|
-
const
|
|
6005
|
-
if (
|
|
6006
|
-
summary.imports.push(`./${
|
|
6187
|
+
const relative14 = REQUIRE_RELATIVE.exec(trimmed);
|
|
6188
|
+
if (relative14) {
|
|
6189
|
+
summary.imports.push(`./${relative14[1]}`);
|
|
6007
6190
|
return;
|
|
6008
6191
|
}
|
|
6009
6192
|
const required = REQUIRE.exec(trimmed);
|
|
@@ -6552,17 +6735,17 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
6552
6735
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script(?:\s[^>]*)?>/gi;
|
|
6553
6736
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
6554
6737
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
6555
|
-
function componentName(
|
|
6556
|
-
const base =
|
|
6738
|
+
function componentName(path22) {
|
|
6739
|
+
const base = path22.split("/").pop() ?? path22;
|
|
6557
6740
|
return base.replace(/\.[^.]+$/, "");
|
|
6558
6741
|
}
|
|
6559
6742
|
var sfcProfile = {
|
|
6560
6743
|
id: "sfc",
|
|
6561
6744
|
extensions: [".vue", ".svelte", ".astro"],
|
|
6562
|
-
summarize(
|
|
6745
|
+
summarize(path22, content) {
|
|
6563
6746
|
let script = "";
|
|
6564
|
-
let usesJsx =
|
|
6565
|
-
if (
|
|
6747
|
+
let usesJsx = path22.toLowerCase().endsWith(".astro");
|
|
6748
|
+
if (path22.toLowerCase().endsWith(".astro")) {
|
|
6566
6749
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
6567
6750
|
if (frontmatter) script += `${frontmatter[1]}
|
|
6568
6751
|
`;
|
|
@@ -6572,7 +6755,7 @@ var sfcProfile = {
|
|
|
6572
6755
|
script += `${match[2]}
|
|
6573
6756
|
`;
|
|
6574
6757
|
}
|
|
6575
|
-
const name = componentName(
|
|
6758
|
+
const name = componentName(path22);
|
|
6576
6759
|
if (!script.trim()) {
|
|
6577
6760
|
const summary2 = emptySummary();
|
|
6578
6761
|
if (name) {
|
|
@@ -6763,15 +6946,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
6763
6946
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
6764
6947
|
}
|
|
6765
6948
|
}
|
|
6766
|
-
function profileForPath(
|
|
6767
|
-
const lower =
|
|
6949
|
+
function profileForPath(path22) {
|
|
6950
|
+
const lower = path22.toLowerCase();
|
|
6768
6951
|
const dot = lower.lastIndexOf(".");
|
|
6769
6952
|
if (dot === -1) return null;
|
|
6770
6953
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
6771
6954
|
}
|
|
6772
|
-
function summarizeWithProfile(
|
|
6773
|
-
const profile = profileForPath(
|
|
6774
|
-
return profile ? profile.summarize(
|
|
6955
|
+
function summarizeWithProfile(path22, content) {
|
|
6956
|
+
const profile = profileForPath(path22);
|
|
6957
|
+
return profile ? profile.summarize(path22, content) : null;
|
|
6775
6958
|
}
|
|
6776
6959
|
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6777
6960
|
".png",
|
|
@@ -6983,13 +7166,13 @@ function isBinaryFile(absolutePath) {
|
|
|
6983
7166
|
if (isBinaryExtension(absolutePath)) return true;
|
|
6984
7167
|
let fd;
|
|
6985
7168
|
try {
|
|
6986
|
-
fd =
|
|
7169
|
+
fd = fs18__namespace.openSync(absolutePath, "r");
|
|
6987
7170
|
const buffer = Buffer.alloc(CHUNK);
|
|
6988
7171
|
let sample;
|
|
6989
7172
|
let position = 0;
|
|
6990
7173
|
while (position < BINARY_SCAN_BYTES) {
|
|
6991
7174
|
const wanted = Math.min(CHUNK, BINARY_SCAN_BYTES - position);
|
|
6992
|
-
const bytesRead =
|
|
7175
|
+
const bytesRead = fs18__namespace.readSync(fd, buffer, 0, wanted, position);
|
|
6993
7176
|
if (bytesRead === 0) return false;
|
|
6994
7177
|
const chunk = buffer.subarray(0, bytesRead);
|
|
6995
7178
|
if (sample === void 0) {
|
|
@@ -7007,7 +7190,7 @@ function isBinaryFile(absolutePath) {
|
|
|
7007
7190
|
} finally {
|
|
7008
7191
|
if (fd !== void 0) {
|
|
7009
7192
|
try {
|
|
7010
|
-
|
|
7193
|
+
fs18__namespace.closeSync(fd);
|
|
7011
7194
|
} catch {
|
|
7012
7195
|
}
|
|
7013
7196
|
}
|
|
@@ -7205,13 +7388,16 @@ var TOKEN_LINE_SLACK = 32;
|
|
|
7205
7388
|
function truncateWithBudgetMarker(content, maxBytes, budget, originalLines) {
|
|
7206
7389
|
const base = content.replace(BUDGET_MARKER_SUFFIX, "");
|
|
7207
7390
|
const truncated = truncateToBytes(base, Math.max(0, maxBytes));
|
|
7208
|
-
if (!truncated.isTruncated) return { content: base, isTruncated: false };
|
|
7391
|
+
if (!truncated.isTruncated) return { content: base, isTruncated: false, cutMidLine: false };
|
|
7209
7392
|
const keptLines = countLines(truncated.content);
|
|
7210
7393
|
const omitted = Math.max(1, Math.max(countLines(base), originalLines) - keptLines);
|
|
7394
|
+
const next = base[truncated.content.length];
|
|
7395
|
+
const cutMidLine = next !== void 0 && next !== "\n" && next !== "\r";
|
|
7396
|
+
const separator = truncated.content.endsWith("\n") || truncated.content.endsWith("\r") ? "" : "\n";
|
|
7211
7397
|
return {
|
|
7212
|
-
content: `${truncated.content}
|
|
7213
|
-
|
|
7214
|
-
|
|
7398
|
+
content: `${truncated.content}${separator}... [${omitted} lines omitted: part budget ${budget} B] ...`,
|
|
7399
|
+
isTruncated: true,
|
|
7400
|
+
cutMidLine
|
|
7215
7401
|
};
|
|
7216
7402
|
}
|
|
7217
7403
|
function partitionFiles(files, maxPartBytes, contentFingerprint) {
|
|
@@ -7283,7 +7469,7 @@ function partitionFilesForBuckets(buckets, contentFingerprint) {
|
|
|
7283
7469
|
section.file.originalLines
|
|
7284
7470
|
);
|
|
7285
7471
|
if (shrunk.isTruncated) {
|
|
7286
|
-
applyTruncatedContent(section.file, shrunk.content, "part-budget");
|
|
7472
|
+
applyTruncatedContent(section.file, shrunk.content, "part-budget", shrunk.cutMidLine);
|
|
7287
7473
|
section.text = renderFileSection(section.file);
|
|
7288
7474
|
section.byteSize = Buffer.byteLength(section.text, "utf8");
|
|
7289
7475
|
assemblies.delete(group);
|
|
@@ -7357,7 +7543,7 @@ function prepareSection(file, sectionBudget, partBudget) {
|
|
|
7357
7543
|
file.originalLines
|
|
7358
7544
|
);
|
|
7359
7545
|
if (!truncated.isTruncated) return;
|
|
7360
|
-
applyTruncatedContent(file, truncated.content, "part-budget");
|
|
7546
|
+
applyTruncatedContent(file, truncated.content, "part-budget", truncated.cutMidLine);
|
|
7361
7547
|
text = renderFileSection(file);
|
|
7362
7548
|
byteSize = Buffer.byteLength(text, "utf8");
|
|
7363
7549
|
};
|
|
@@ -7424,7 +7610,7 @@ function fenceIsOpen(text, fence) {
|
|
|
7424
7610
|
return open;
|
|
7425
7611
|
}
|
|
7426
7612
|
var OMISSION_NOTICE_LINE = /^\.\.\. \[\d+ lines omitted: [^\]]*\] \.\.\.$/;
|
|
7427
|
-
function applyTruncatedContent(file, content, reason) {
|
|
7613
|
+
function applyTruncatedContent(file, content, reason, cutMidLine = false) {
|
|
7428
7614
|
const keptLines = content.split("\n").filter(
|
|
7429
7615
|
(line) => !OMISSION_NOTICE_LINE.test(line) && line.trim() !== SECTION_TRUNCATION_NOTICE
|
|
7430
7616
|
).length;
|
|
@@ -7437,22 +7623,26 @@ function applyTruncatedContent(file, content, reason) {
|
|
|
7437
7623
|
const noticeAt = lines.findIndex(
|
|
7438
7624
|
(line) => OMISSION_NOTICE_LINE.test(line) || line.trim() === SECTION_TRUNCATION_NOTICE
|
|
7439
7625
|
);
|
|
7440
|
-
if (noticeAt >= 0 && priorGap !== void 0 && priorGap.length
|
|
7626
|
+
if (noticeAt >= 0 && priorGap !== void 0 && priorGap.length >= 1 && priorGap[0] !== void 0) {
|
|
7441
7627
|
const headKept = lines.slice(0, noticeAt).filter((line) => !OMISSION_NOTICE_LINE.test(line) && line.trim() !== SECTION_TRUNCATION_NOTICE).length;
|
|
7442
7628
|
const tailKept = lines.slice(noticeAt + 1).filter((line) => !OMISSION_NOTICE_LINE.test(line) && line.trim() !== SECTION_TRUNCATION_NOTICE).length;
|
|
7443
7629
|
const gapEnd = priorGap[0][1];
|
|
7444
|
-
const headStart = Math.min(
|
|
7630
|
+
const headStart = Math.min(
|
|
7631
|
+
file.originalLines,
|
|
7632
|
+
cutMidLine ? Math.max(1, headKept) : headKept + 1
|
|
7633
|
+
);
|
|
7445
7634
|
const ranges = [];
|
|
7446
7635
|
if (tailKept === 0) {
|
|
7447
7636
|
ranges.push([headStart, file.originalLines]);
|
|
7448
7637
|
} else {
|
|
7449
7638
|
if (headStart <= gapEnd) ranges.push([headStart, gapEnd]);
|
|
7450
|
-
const tailStart = gapEnd + tailKept + 1;
|
|
7639
|
+
const tailStart = cutMidLine ? gapEnd + tailKept : gapEnd + tailKept + 1;
|
|
7451
7640
|
if (tailStart <= file.originalLines) ranges.push([tailStart, file.originalLines]);
|
|
7452
7641
|
}
|
|
7453
7642
|
file.omittedRanges = ranges.length === 0 ? [[file.originalLines, file.originalLines]] : ranges;
|
|
7454
7643
|
} else {
|
|
7455
|
-
|
|
7644
|
+
const firstOmitted = cutMidLine ? Math.max(1, keptLines) : keptLines + 1;
|
|
7645
|
+
file.omittedRanges = keptLines >= file.originalLines ? file.originalLines > 0 ? [[file.originalLines, file.originalLines]] : [] : [[Math.min(firstOmitted, file.originalLines), file.originalLines]];
|
|
7456
7646
|
}
|
|
7457
7647
|
file.includedBytes = Buffer.byteLength(content, "utf8");
|
|
7458
7648
|
file.includedLines = countBodyLines(content);
|
|
@@ -7663,8 +7853,8 @@ var MAX_CONFIG_BYTES = 4 * 1024 * 1024;
|
|
|
7663
7853
|
var MAX_PACKAGE_BYTES = 1 * 1024 * 1024;
|
|
7664
7854
|
function repositoryRelative(cwd, target) {
|
|
7665
7855
|
const absolute = path7__namespace.isAbsolute(target) ? target : path7__namespace.resolve(cwd, target);
|
|
7666
|
-
const
|
|
7667
|
-
return
|
|
7856
|
+
const relative14 = path7__namespace.relative(cwd, absolute).replace(/\\/g, "/");
|
|
7857
|
+
return relative14.length === 0 || relative14 !== ".." && !relative14.startsWith(".." + path7__namespace.sep) && !relative14.startsWith("../") && !path7__namespace.isAbsolute(relative14) ? relative14 : null;
|
|
7668
7858
|
}
|
|
7669
7859
|
function insideCwd(cwd, file) {
|
|
7670
7860
|
return repositoryRelative(cwd, file);
|
|
@@ -7720,8 +7910,8 @@ function parseImports(value) {
|
|
|
7720
7910
|
return Object.entries(record).filter(([key]) => key.startsWith("#")).map(([pattern, target]) => ({ pattern, targets: targetList(target) }));
|
|
7721
7911
|
}
|
|
7722
7912
|
function readPackageJson(cwd, packageDir) {
|
|
7723
|
-
const
|
|
7724
|
-
const parsed = asRecord(readJson(cwd,
|
|
7913
|
+
const relative14 = packageDir.length === 0 ? "package.json" : packageDir + "/package.json";
|
|
7914
|
+
const parsed = asRecord(readJson(cwd, relative14, MAX_PACKAGE_BYTES));
|
|
7725
7915
|
if (parsed === null) return null;
|
|
7726
7916
|
const exportsMap = parseExports(parsed.exports);
|
|
7727
7917
|
if (exportsMap.length === 0) {
|
|
@@ -7763,18 +7953,18 @@ function parsePnpmWorkspace(cwd) {
|
|
|
7763
7953
|
}
|
|
7764
7954
|
function listChildDirectories(cwd, relativeDir) {
|
|
7765
7955
|
const absolute = path7__namespace.resolve(cwd, relativeDir);
|
|
7766
|
-
const
|
|
7767
|
-
if (
|
|
7956
|
+
const relative14 = repositoryRelative(cwd, absolute);
|
|
7957
|
+
if (relative14 === null) return [];
|
|
7768
7958
|
let entries;
|
|
7769
7959
|
try {
|
|
7770
|
-
entries =
|
|
7960
|
+
entries = fs18__namespace.readdirSync(absolute === cwd ? cwd : absolute, { withFileTypes: true });
|
|
7771
7961
|
} catch {
|
|
7772
7962
|
return [];
|
|
7773
7963
|
}
|
|
7774
7964
|
const out = [];
|
|
7775
7965
|
for (const entry of entries) {
|
|
7776
7966
|
if (!entry.isDirectory()) continue;
|
|
7777
|
-
const child =
|
|
7967
|
+
const child = relative14.length === 0 ? entry.name : relative14 + "/" + entry.name;
|
|
7778
7968
|
if (child.split("/").includes("node_modules")) continue;
|
|
7779
7969
|
out.push(child);
|
|
7780
7970
|
}
|
|
@@ -7787,15 +7977,15 @@ function expandWorkspacePattern(cwd, rawPattern) {
|
|
|
7787
7977
|
if (pattern.endsWith("/*")) {
|
|
7788
7978
|
const base = pattern.slice(0, -2);
|
|
7789
7979
|
return listChildDirectories(cwd, base).filter(
|
|
7790
|
-
(dir) =>
|
|
7980
|
+
(dir) => fs18__namespace.existsSync(path7__namespace.join(cwd, dir, "package.json"))
|
|
7791
7981
|
);
|
|
7792
7982
|
}
|
|
7793
7983
|
if (pattern.includes("*")) {
|
|
7794
7984
|
const base = path7__namespace.posix.dirname(pattern);
|
|
7795
7985
|
const direct = listChildDirectories(cwd, base === "." ? "" : base);
|
|
7796
|
-
return direct.filter((dir) =>
|
|
7986
|
+
return direct.filter((dir) => fs18__namespace.existsSync(path7__namespace.join(cwd, dir, "package.json")));
|
|
7797
7987
|
}
|
|
7798
|
-
return
|
|
7988
|
+
return fs18__namespace.existsSync(path7__namespace.join(cwd, pattern, "package.json")) ? [pattern] : [];
|
|
7799
7989
|
}
|
|
7800
7990
|
function workspaceDirectories(cwd, files) {
|
|
7801
7991
|
const root = asRecord(readJson(cwd, "package.json", MAX_PACKAGE_BYTES));
|
|
@@ -7894,7 +8084,7 @@ function configCandidates(cwd, files, packageDirs) {
|
|
|
7894
8084
|
for (const dir of packageDirs) {
|
|
7895
8085
|
for (const base of ["tsconfig.json", "jsconfig.json"]) {
|
|
7896
8086
|
const candidate = dir.length === 0 ? base : dir + "/" + base;
|
|
7897
|
-
if (
|
|
8087
|
+
if (fs18__namespace.existsSync(path7__namespace.join(cwd, candidate))) candidates.add(candidate);
|
|
7898
8088
|
}
|
|
7899
8089
|
}
|
|
7900
8090
|
for (const relativePath of files) {
|
|
@@ -7903,14 +8093,14 @@ function configCandidates(cwd, files, packageDirs) {
|
|
|
7903
8093
|
while (dir !== "." && dir.length > 0) {
|
|
7904
8094
|
for (const base of ["tsconfig.json", "jsconfig.json"]) {
|
|
7905
8095
|
const candidate = dir + "/" + base;
|
|
7906
|
-
if (
|
|
8096
|
+
if (fs18__namespace.existsSync(path7__namespace.join(cwd, candidate))) candidates.add(candidate);
|
|
7907
8097
|
}
|
|
7908
8098
|
dir = path7__namespace.posix.dirname(dir);
|
|
7909
8099
|
}
|
|
7910
8100
|
}
|
|
7911
8101
|
return [...candidates].filter((relativePath) => {
|
|
7912
|
-
if (!
|
|
7913
|
-
const stat =
|
|
8102
|
+
if (!fs18__namespace.existsSync(path7__namespace.join(cwd, relativePath))) return false;
|
|
8103
|
+
const stat = fs18__namespace.lstatSync(path7__namespace.join(cwd, relativePath));
|
|
7914
8104
|
return stat.isFile() && !stat.isSymbolicLink();
|
|
7915
8105
|
}).slice(0, MAX_CONFIG_FILES * 2);
|
|
7916
8106
|
}
|
|
@@ -8333,12 +8523,12 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
8333
8523
|
const scored = [];
|
|
8334
8524
|
for (const file of manifest.files) {
|
|
8335
8525
|
if (isTest(file) && !wantsTests) continue;
|
|
8336
|
-
const
|
|
8337
|
-
const words =
|
|
8526
|
+
const path22 = file.relativePath.toLowerCase();
|
|
8527
|
+
const words = path22.split(/[^a-z0-9_]+/).filter((word) => word.length >= 3);
|
|
8338
8528
|
let score = 0;
|
|
8339
8529
|
const reasons = [];
|
|
8340
8530
|
for (const term of terms) {
|
|
8341
|
-
if (
|
|
8531
|
+
if (path22.includes(term)) {
|
|
8342
8532
|
score += 8;
|
|
8343
8533
|
reasons.push("path:" + term);
|
|
8344
8534
|
continue;
|
|
@@ -8636,6 +8826,7 @@ function resolveDiffChangedLines(cwd, ref, files) {
|
|
|
8636
8826
|
"--no-color",
|
|
8637
8827
|
"--no-ext-diff",
|
|
8638
8828
|
"--no-renames",
|
|
8829
|
+
"--relative",
|
|
8639
8830
|
base,
|
|
8640
8831
|
...files === void 0 || files.length === 0 ? [] : ["--", ...files]
|
|
8641
8832
|
];
|
|
@@ -8663,8 +8854,8 @@ function resolveDiffChangedLines(cwd, ref, files) {
|
|
|
8663
8854
|
continue;
|
|
8664
8855
|
}
|
|
8665
8856
|
const withoutPrefix = raw.startsWith("b/") ? raw.slice(2) : raw;
|
|
8666
|
-
const
|
|
8667
|
-
current =
|
|
8857
|
+
const path22 = withoutPrefix.split(" ")[0];
|
|
8858
|
+
current = path22.length > 0 ? path22 : null;
|
|
8668
8859
|
if (current !== null && !ranges.has(current)) ranges.set(current, []);
|
|
8669
8860
|
continue;
|
|
8670
8861
|
}
|
|
@@ -8693,11 +8884,11 @@ function resolveChangedScope(cwd, request) {
|
|
|
8693
8884
|
if (request.changedSince !== void 0) {
|
|
8694
8885
|
assertUsableRef(request.changedSince);
|
|
8695
8886
|
if (request.changedSince === "HEAD" && !hasHeadCommit(cwd)) {
|
|
8696
|
-
for (const
|
|
8697
|
-
paths.add(
|
|
8887
|
+
for (const path22 of gitPaths(cwd, ["ls-files", "--cached", "-z", "--"])) {
|
|
8888
|
+
paths.add(path22);
|
|
8698
8889
|
}
|
|
8699
|
-
for (const
|
|
8700
|
-
paths.add(
|
|
8890
|
+
for (const path22 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
8891
|
+
paths.add(path22);
|
|
8701
8892
|
}
|
|
8702
8893
|
descriptions.push("changed since HEAD (unborn)");
|
|
8703
8894
|
} else {
|
|
@@ -8710,7 +8901,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
8710
8901
|
);
|
|
8711
8902
|
}
|
|
8712
8903
|
if (base !== null) {
|
|
8713
|
-
for (const
|
|
8904
|
+
for (const path22 of gitPaths(cwd, [
|
|
8714
8905
|
"-c",
|
|
8715
8906
|
"core.quotepath=false",
|
|
8716
8907
|
"-c",
|
|
@@ -8727,17 +8918,17 @@ function resolveChangedScope(cwd, request) {
|
|
|
8727
8918
|
base,
|
|
8728
8919
|
"--"
|
|
8729
8920
|
])) {
|
|
8730
|
-
paths.add(
|
|
8921
|
+
paths.add(path22);
|
|
8731
8922
|
}
|
|
8732
8923
|
}
|
|
8733
|
-
for (const
|
|
8734
|
-
paths.add(
|
|
8924
|
+
for (const path22 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
8925
|
+
paths.add(path22);
|
|
8735
8926
|
}
|
|
8736
8927
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
8737
8928
|
}
|
|
8738
8929
|
}
|
|
8739
8930
|
if (request.staged === true) {
|
|
8740
|
-
for (const
|
|
8931
|
+
for (const path22 of gitPaths(cwd, [
|
|
8741
8932
|
"-c",
|
|
8742
8933
|
"core.quotepath=false",
|
|
8743
8934
|
"diff",
|
|
@@ -8748,10 +8939,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
8748
8939
|
"--no-renames",
|
|
8749
8940
|
"--"
|
|
8750
8941
|
])) {
|
|
8751
|
-
paths.add(
|
|
8752
|
-
stagedPaths.add(
|
|
8942
|
+
paths.add(path22);
|
|
8943
|
+
stagedPaths.add(path22);
|
|
8753
8944
|
}
|
|
8754
|
-
for (const
|
|
8945
|
+
for (const path22 of gitPaths(cwd, [
|
|
8755
8946
|
"-c",
|
|
8756
8947
|
"core.quotepath=false",
|
|
8757
8948
|
"diff",
|
|
@@ -8763,7 +8954,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
8763
8954
|
"--diff-filter=D",
|
|
8764
8955
|
"--"
|
|
8765
8956
|
])) {
|
|
8766
|
-
deletedPaths.add(
|
|
8957
|
+
deletedPaths.add(path22);
|
|
8767
8958
|
}
|
|
8768
8959
|
descriptions.push("staged");
|
|
8769
8960
|
}
|
|
@@ -8967,8 +9158,8 @@ function describeManifestShapeProblem(value) {
|
|
|
8967
9158
|
}
|
|
8968
9159
|
}
|
|
8969
9160
|
const lines = fields.lines;
|
|
8970
|
-
if (fields.includedLines > lines) {
|
|
8971
|
-
return 'an "incomplete" entry "includedLines" exceeds its "lines"';
|
|
9161
|
+
if (fields.includedLines > lines + 1) {
|
|
9162
|
+
return 'an "incomplete" entry "includedLines" exceeds its "lines" by more than the notice line';
|
|
8972
9163
|
}
|
|
8973
9164
|
const ranges = fields.omittedRanges;
|
|
8974
9165
|
if (!Array.isArray(ranges)) return 'an "incomplete" entry has no "omittedRanges" array';
|
|
@@ -9123,11 +9314,11 @@ var MAX_LINE_BYTES = 32 * 1024 * 1024;
|
|
|
9123
9314
|
function createWriter(output) {
|
|
9124
9315
|
return {
|
|
9125
9316
|
write(value) {
|
|
9126
|
-
return new Promise((
|
|
9317
|
+
return new Promise((resolve15, reject) => {
|
|
9127
9318
|
output.write(`${JSON.stringify(value)}
|
|
9128
9319
|
`, (error) => {
|
|
9129
9320
|
if (error) reject(error);
|
|
9130
|
-
else
|
|
9321
|
+
else resolve15();
|
|
9131
9322
|
});
|
|
9132
9323
|
});
|
|
9133
9324
|
}
|
|
@@ -9435,7 +9626,15 @@ function resolveImpactChanges(cwd, request) {
|
|
|
9435
9626
|
throw new Error("impact needs --diff <ref> or --paths <path,...>.");
|
|
9436
9627
|
}
|
|
9437
9628
|
function isTestPath(filePath) {
|
|
9438
|
-
|
|
9629
|
+
const base = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
9630
|
+
return (
|
|
9631
|
+
// Jest/Vitest/Mocha and their Ruby equivalents.
|
|
9632
|
+
/\.(?:test|spec)\.[a-z0-9]+$/i.test(base) || // Python: test_auth.py, auth_test.py, auth_tests.py.
|
|
9633
|
+
/^test_.*\.py$/i.test(base) || /_tests?\.py$/i.test(base) || // Go and Rust put the suffix before the extension.
|
|
9634
|
+
/_test\.(?:go|rs|exs?)$/i.test(base) || // Ruby spec files.
|
|
9635
|
+
/_spec\.rb$/i.test(base) || // JUnit/NUnit/XCTest/PHPUnit class names.
|
|
9636
|
+
/(?:Test|Tests)\.(?:java|kt|cs|swift|php)$/.test(base)
|
|
9637
|
+
);
|
|
9439
9638
|
}
|
|
9440
9639
|
function isTestSupportPath(filePath) {
|
|
9441
9640
|
return !isTestPath(filePath) && /(^|\/)(tests?|__tests__|spec)\//.test(filePath);
|
|
@@ -9487,10 +9686,10 @@ function internalSpecifier(specifier, resolver) {
|
|
|
9487
9686
|
}
|
|
9488
9687
|
function manifestLabel(cwd, manifestPath) {
|
|
9489
9688
|
if (manifestPath === void 0) return "manifest.json";
|
|
9490
|
-
const
|
|
9491
|
-
if (
|
|
9492
|
-
if (
|
|
9493
|
-
return
|
|
9689
|
+
const relative14 = path7__namespace.relative(cwd, manifestPath).replace(/\\/g, "/");
|
|
9690
|
+
if (relative14.length === 0) return "manifest.json";
|
|
9691
|
+
if (relative14.startsWith("../") || path7__namespace.isAbsolute(relative14)) return path7__namespace.basename(manifestPath);
|
|
9692
|
+
return relative14;
|
|
9494
9693
|
}
|
|
9495
9694
|
function isPureBarrel(summary, file) {
|
|
9496
9695
|
if (summary.parseErrors !== void 0 && summary.parseErrors > 0) return false;
|
|
@@ -9540,18 +9739,20 @@ function matchEdge(fromSummary, fromFile, specifier, incoming) {
|
|
|
9540
9739
|
const named = reExports2.filter(
|
|
9541
9740
|
(binding) => binding.kind !== "star" && binding.kind !== "namespace"
|
|
9542
9741
|
);
|
|
9543
|
-
|
|
9742
|
+
const onlyNamedReExports = reExports2.every((binding) => binding.kind === "named");
|
|
9743
|
+
if (named.length > 0 && imports2.length === 0 && onlyNamedReExports) {
|
|
9544
9744
|
const next2 = /* @__PURE__ */ new Set();
|
|
9545
9745
|
for (const binding of named) {
|
|
9546
9746
|
for (const entry of binding.entries ?? []) next2.add(entry.exported);
|
|
9547
9747
|
}
|
|
9548
9748
|
if (next2.size > 0) {
|
|
9749
|
+
const typeOnly = named.every((binding) => binding.typeOnly);
|
|
9549
9750
|
return {
|
|
9550
9751
|
fired: true,
|
|
9551
|
-
kind: "reexport",
|
|
9752
|
+
kind: typeOnly ? "type-only" : "reexport",
|
|
9552
9753
|
next: next2,
|
|
9553
9754
|
matched: [...next2].sort((left, right) => left.localeCompare(right)),
|
|
9554
|
-
typeOnly
|
|
9755
|
+
typeOnly
|
|
9555
9756
|
};
|
|
9556
9757
|
}
|
|
9557
9758
|
}
|
|
@@ -9742,7 +9943,7 @@ function computeImpact(input) {
|
|
|
9742
9943
|
);
|
|
9743
9944
|
const skippedByPath = new Map(manifest.skipped.map((skip) => [skip.path, skip]));
|
|
9744
9945
|
const changed = input.changes.paths.map((changedPath) => {
|
|
9745
|
-
const deleted2 = !
|
|
9946
|
+
const deleted2 = !fs18__namespace.existsSync(path7__namespace.resolve(input.cwd, changedPath));
|
|
9746
9947
|
const direct = filesByPath.get(changedPath);
|
|
9747
9948
|
if (direct !== void 0) return { path: direct.relativePath, inSnapshot: true, deleted: deleted2 };
|
|
9748
9949
|
const folded = filesByFoldedPath.get(changedPath.toLowerCase());
|
|
@@ -9838,7 +10039,7 @@ function computeImpact(input) {
|
|
|
9838
10039
|
const widened = !(previous.has("*") && merged.size === previous.size) && !(previous.size === merged.size && [...merged].every((name) => previous.has(name)));
|
|
9839
10040
|
if (widened) {
|
|
9840
10041
|
visitedSymbols.set(edge.from, merged);
|
|
9841
|
-
if (match.kind !== "type-only") {
|
|
10042
|
+
if (match.kind !== "type-only" || fromSummary !== null && isPureBarrel(fromSummary, fromFile)) {
|
|
9842
10043
|
queue.push({ path: edge.from, symbols: merged, distance: current.distance + 1 });
|
|
9843
10044
|
}
|
|
9844
10045
|
}
|
|
@@ -9887,8 +10088,8 @@ function computeImpact(input) {
|
|
|
9887
10088
|
}
|
|
9888
10089
|
}
|
|
9889
10090
|
const impacted = /* @__PURE__ */ new Set([...changedSet, ...affected.keys()]);
|
|
9890
|
-
for (const
|
|
9891
|
-
if (!isTestPath(
|
|
10091
|
+
for (const path22 of visitedSymbols.keys()) {
|
|
10092
|
+
if (!isTestPath(path22) && !isTestSupportPath(path22)) impacted.add(path22);
|
|
9892
10093
|
}
|
|
9893
10094
|
const tests = [...testHits.entries()].map(([testPath, hit]) => ({
|
|
9894
10095
|
path: testPath,
|
|
@@ -9945,7 +10146,8 @@ function computeImpact(input) {
|
|
|
9945
10146
|
])
|
|
9946
10147
|
)
|
|
9947
10148
|
) : void 0;
|
|
9948
|
-
const
|
|
10149
|
+
const impactPartial = truncated || depthTruncated || notInSnapshot.length > 0;
|
|
10150
|
+
const coverage = input.trust?.coverage === "partial" || impactPartial ? "partial" : "complete";
|
|
9949
10151
|
const trust = {
|
|
9950
10152
|
indexSource: input.trust?.indexSource ?? "snapshot",
|
|
9951
10153
|
freshness: input.trust?.freshness ?? "unknown",
|
|
@@ -9954,7 +10156,7 @@ function computeImpact(input) {
|
|
|
9954
10156
|
...input.trust?.overlayStats === void 0 ? {} : { overlayStats: input.trust.overlayStats },
|
|
9955
10157
|
sensitiveExcludedCount: input.trust?.sensitiveExcludedCount ?? manifest.skipped.filter((skip) => skip.reason === "sensitive-file").length,
|
|
9956
10158
|
redactedLines: input.trust?.redactedLines ?? manifest.totals.redactedLines,
|
|
9957
|
-
omittedCount: input.trust?.omittedCount ?? notInSnapshot.length + (truncated ? 1 : 0),
|
|
10159
|
+
omittedCount: (input.trust?.omittedCount ?? 0) + notInSnapshot.length + (truncated || depthTruncated ? 1 : 0),
|
|
9958
10160
|
unresolvedCount: unresolved.length,
|
|
9959
10161
|
reasons: [...input.trust?.reasons ?? [], ...warnings]
|
|
9960
10162
|
};
|
|
@@ -10199,8 +10401,8 @@ function findSection(sections, relativePath) {
|
|
|
10199
10401
|
if (exact) return exact;
|
|
10200
10402
|
const foldedPath = rendered.toLowerCase();
|
|
10201
10403
|
const folded = sections.filter((section) => {
|
|
10202
|
-
const
|
|
10203
|
-
return
|
|
10404
|
+
const path22 = section.path.toLowerCase();
|
|
10405
|
+
return path22 === relativePath.toLowerCase() || path22 === foldedPath;
|
|
10204
10406
|
});
|
|
10205
10407
|
return folded.length === 1 ? folded[0] : null;
|
|
10206
10408
|
}
|
|
@@ -10296,7 +10498,7 @@ var WORKER_SOURCE = `
|
|
|
10296
10498
|
})();
|
|
10297
10499
|
`;
|
|
10298
10500
|
function generateInWorker(cwd, cliOptions, options = {}) {
|
|
10299
|
-
return new Promise((
|
|
10501
|
+
return new Promise((resolve15) => {
|
|
10300
10502
|
let settled = false;
|
|
10301
10503
|
let worker = null;
|
|
10302
10504
|
const finish = (result) => {
|
|
@@ -10307,7 +10509,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
10307
10509
|
if (!result.ok && options.runId !== void 0 && options.lockRoots !== void 0) {
|
|
10308
10510
|
releaseAbandonedRun(options.lockRoots, options.runId);
|
|
10309
10511
|
}
|
|
10310
|
-
|
|
10512
|
+
resolve15(result);
|
|
10311
10513
|
});
|
|
10312
10514
|
};
|
|
10313
10515
|
const isCjs = typeof __dirname !== "undefined";
|
|
@@ -10420,21 +10622,30 @@ var WORKER_SOURCE2 = `
|
|
|
10420
10622
|
}
|
|
10421
10623
|
})();
|
|
10422
10624
|
`;
|
|
10423
|
-
function analysisInWorker(request) {
|
|
10424
|
-
return new Promise((
|
|
10625
|
+
function analysisInWorker(request, signal) {
|
|
10626
|
+
return new Promise((resolve15) => {
|
|
10425
10627
|
let settled = false;
|
|
10426
10628
|
let worker = null;
|
|
10427
10629
|
const timer = setTimeout(() => {
|
|
10428
10630
|
finish({ ok: false, message: "The analysis worker exceeded its two-minute timeout." });
|
|
10429
10631
|
}, 12e4);
|
|
10430
10632
|
timer.unref();
|
|
10633
|
+
const onAbort = () => {
|
|
10634
|
+
finish({ ok: false, message: "The analysis was cancelled." });
|
|
10635
|
+
};
|
|
10431
10636
|
const finish = (result) => {
|
|
10432
10637
|
if (settled) return;
|
|
10433
10638
|
settled = true;
|
|
10434
10639
|
clearTimeout(timer);
|
|
10640
|
+
signal?.removeEventListener("abort", onAbort);
|
|
10435
10641
|
const terminated = worker === null ? Promise.resolve(void 0) : worker.terminate();
|
|
10436
|
-
void terminated.catch(() => void 0).then(() =>
|
|
10642
|
+
void terminated.catch(() => void 0).then(() => resolve15(result));
|
|
10437
10643
|
};
|
|
10644
|
+
if (signal?.aborted === true) {
|
|
10645
|
+
finish({ ok: false, message: "The analysis was cancelled." });
|
|
10646
|
+
return;
|
|
10647
|
+
}
|
|
10648
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
10438
10649
|
const isCjs = typeof __dirname !== "undefined";
|
|
10439
10650
|
const directory = isCjs ? __dirname : path7__namespace.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('mcp.cjs', document.baseURI).href))));
|
|
10440
10651
|
try {
|
|
@@ -10499,6 +10710,7 @@ function baselineUsable(manifest, config) {
|
|
|
10499
10710
|
if (manifest.generator.version !== GENERATOR_VERSION) return false;
|
|
10500
10711
|
if (manifest.config.digest === void 0 || manifest.config.digest !== configDigest(config)) return false;
|
|
10501
10712
|
if (manifest.slice !== void 0 || manifest.budget !== void 0 || manifest.delta !== void 0) return false;
|
|
10713
|
+
if (manifest.config.artifacts.parts === false) return false;
|
|
10502
10714
|
return true;
|
|
10503
10715
|
}
|
|
10504
10716
|
function gitWorkingState(cwd) {
|
|
@@ -10557,6 +10769,26 @@ function collectStatStamps(config, manifest, gitState) {
|
|
|
10557
10769
|
for (const dirty of gitState.dirtyPaths) candidates.add(dirty);
|
|
10558
10770
|
} else {
|
|
10559
10771
|
if (manifest.files.length > 500) return [];
|
|
10772
|
+
const directories = [];
|
|
10773
|
+
const pending = [""];
|
|
10774
|
+
while (pending.length > 0) {
|
|
10775
|
+
const directory = pending.shift();
|
|
10776
|
+
let entries;
|
|
10777
|
+
try {
|
|
10778
|
+
entries = fs18__namespace.readdirSync(path7__namespace.join(config.cwd, directory), { withFileTypes: true });
|
|
10779
|
+
} catch {
|
|
10780
|
+
continue;
|
|
10781
|
+
}
|
|
10782
|
+
for (const entry of entries) {
|
|
10783
|
+
if (!entry.isDirectory()) continue;
|
|
10784
|
+
if (entry.name === ".git" || entry.name === "node_modules") continue;
|
|
10785
|
+
const relative14 = directory === "" ? entry.name : directory + "/" + entry.name;
|
|
10786
|
+
directories.push(relative14);
|
|
10787
|
+
pending.push(relative14);
|
|
10788
|
+
if (directories.length > 500) return [];
|
|
10789
|
+
}
|
|
10790
|
+
}
|
|
10791
|
+
for (const directory of directories) candidates.add(directory);
|
|
10560
10792
|
for (const file of manifest.files) {
|
|
10561
10793
|
candidates.add(file.relativePath);
|
|
10562
10794
|
let dir = path7__namespace.posix.dirname(file.relativePath);
|
|
@@ -10569,18 +10801,18 @@ function collectStatStamps(config, manifest, gitState) {
|
|
|
10569
10801
|
}
|
|
10570
10802
|
}
|
|
10571
10803
|
const stamps = [];
|
|
10572
|
-
for (const
|
|
10573
|
-
const target =
|
|
10804
|
+
for (const relative14 of [...candidates].sort((left, right) => left.localeCompare(right))) {
|
|
10805
|
+
const target = relative14.length === 0 ? config.cwd : path7__namespace.join(config.cwd, relative14);
|
|
10574
10806
|
try {
|
|
10575
|
-
const stat =
|
|
10807
|
+
const stat = fs18__namespace.lstatSync(target);
|
|
10576
10808
|
stamps.push({
|
|
10577
|
-
path:
|
|
10809
|
+
path: relative14,
|
|
10578
10810
|
exists: true,
|
|
10579
10811
|
mtimeMs: stat.mtimeMs,
|
|
10580
10812
|
size: stat.size
|
|
10581
10813
|
});
|
|
10582
10814
|
} catch {
|
|
10583
|
-
stamps.push({ path:
|
|
10815
|
+
stamps.push({ path: relative14, exists: false, mtimeMs: 0, size: 0 });
|
|
10584
10816
|
}
|
|
10585
10817
|
}
|
|
10586
10818
|
return stamps;
|
|
@@ -10590,7 +10822,7 @@ function stampsMatch(cwd, stamps) {
|
|
|
10590
10822
|
for (const stamp of stamps) {
|
|
10591
10823
|
const target = stamp.path.length === 0 ? cwd : path7__namespace.join(cwd, stamp.path);
|
|
10592
10824
|
try {
|
|
10593
|
-
const stat =
|
|
10825
|
+
const stat = fs18__namespace.lstatSync(target);
|
|
10594
10826
|
if (!stamp.exists || stat.mtimeMs !== stamp.mtimeMs || stat.size !== stamp.size) {
|
|
10595
10827
|
return false;
|
|
10596
10828
|
}
|
|
@@ -10618,7 +10850,7 @@ function readCache(config) {
|
|
|
10618
10850
|
const file = liveIndexCachePath(config);
|
|
10619
10851
|
let raw;
|
|
10620
10852
|
try {
|
|
10621
|
-
raw =
|
|
10853
|
+
raw = fs18__namespace.readFileSync(file, "utf8");
|
|
10622
10854
|
} catch {
|
|
10623
10855
|
return null;
|
|
10624
10856
|
}
|
|
@@ -10651,12 +10883,12 @@ function readCache(config) {
|
|
|
10651
10883
|
function writeCache(config, payload) {
|
|
10652
10884
|
try {
|
|
10653
10885
|
const file = liveIndexCachePath(config);
|
|
10654
|
-
|
|
10886
|
+
fs18__namespace.mkdirSync(path7__namespace.dirname(file), { recursive: true, mode: 448 });
|
|
10655
10887
|
const temporary = file + "." + process.pid + "." + Date.now() + ".tmp";
|
|
10656
|
-
|
|
10657
|
-
|
|
10888
|
+
fs18__namespace.writeFileSync(temporary, JSON.stringify(payload), { encoding: "utf8", mode: 384 });
|
|
10889
|
+
fs18__namespace.renameSync(temporary, file);
|
|
10658
10890
|
try {
|
|
10659
|
-
|
|
10891
|
+
fs18__namespace.chmodSync(file, 384);
|
|
10660
10892
|
} catch {
|
|
10661
10893
|
return;
|
|
10662
10894
|
}
|
|
@@ -10741,7 +10973,25 @@ function readRedacted(config, allowedFiles, relativePath) {
|
|
|
10741
10973
|
if (isSensitivePath(normalized)) return null;
|
|
10742
10974
|
const lookup = CASE_INSENSITIVE_PATHS2 ? normalized.toLowerCase() : normalized;
|
|
10743
10975
|
if (!allowedFiles.has(lookup)) return null;
|
|
10744
|
-
|
|
10976
|
+
let read = readConfinedBytes(config.cwd, normalized, MAX_READ_BYTES);
|
|
10977
|
+
if (!read.ok && read.reason === "not-file") {
|
|
10978
|
+
try {
|
|
10979
|
+
const alias = path7__namespace.join(config.cwd, normalized);
|
|
10980
|
+
if (fs18__namespace.lstatSync(alias).isSymbolicLink()) {
|
|
10981
|
+
const rootReal = fs18__namespace.realpathSync(config.cwd);
|
|
10982
|
+
const targetReal = fs18__namespace.realpathSync(alias);
|
|
10983
|
+
const targetRelative = path7__namespace.relative(rootReal, targetReal).split(path7__namespace.sep).join("/");
|
|
10984
|
+
if (targetRelative === "" || targetRelative === ".." || targetRelative.startsWith("../") || path7__namespace.isAbsolute(targetRelative) || isSensitivePath(targetRelative)) {
|
|
10985
|
+
return null;
|
|
10986
|
+
}
|
|
10987
|
+
const targetLookup = CASE_INSENSITIVE_PATHS2 ? targetRelative.toLowerCase() : targetRelative;
|
|
10988
|
+
if (!allowedFiles.has(targetLookup)) return null;
|
|
10989
|
+
read = readConfinedBytes(config.cwd, targetRelative, MAX_READ_BYTES);
|
|
10990
|
+
}
|
|
10991
|
+
} catch {
|
|
10992
|
+
return null;
|
|
10993
|
+
}
|
|
10994
|
+
}
|
|
10745
10995
|
if (!read.ok) return null;
|
|
10746
10996
|
const decoded = decodeText(read.bytes);
|
|
10747
10997
|
if (decoded.binary) return null;
|
|
@@ -10830,7 +11080,7 @@ function foldForComparison(value) {
|
|
|
10830
11080
|
function canonicalPath(value) {
|
|
10831
11081
|
const absolute = path7__namespace.resolve(value);
|
|
10832
11082
|
try {
|
|
10833
|
-
return
|
|
11083
|
+
return fs18__namespace.realpathSync(absolute);
|
|
10834
11084
|
} catch {
|
|
10835
11085
|
return absolute;
|
|
10836
11086
|
}
|
|
@@ -10843,7 +11093,7 @@ function isInside3(parent, child) {
|
|
|
10843
11093
|
function resolveThroughExistingAncestor(target) {
|
|
10844
11094
|
let existing = target;
|
|
10845
11095
|
const missing = [];
|
|
10846
|
-
while (!
|
|
11096
|
+
while (!fs18__namespace.existsSync(existing)) {
|
|
10847
11097
|
missing.unshift(path7__namespace.basename(existing));
|
|
10848
11098
|
const parent = path7__namespace.dirname(existing);
|
|
10849
11099
|
if (parent === existing) break;
|
|
@@ -10872,7 +11122,7 @@ function resolveRoot(requested, context) {
|
|
|
10872
11122
|
if (!lexicalRoots.some((allowed) => isInside3(allowed, absolute))) return outside();
|
|
10873
11123
|
let linkStats;
|
|
10874
11124
|
try {
|
|
10875
|
-
linkStats =
|
|
11125
|
+
linkStats = fs18__namespace.lstatSync(absolute);
|
|
10876
11126
|
} catch {
|
|
10877
11127
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
10878
11128
|
}
|
|
@@ -10884,7 +11134,7 @@ function resolveRoot(requested, context) {
|
|
|
10884
11134
|
}
|
|
10885
11135
|
let stats;
|
|
10886
11136
|
try {
|
|
10887
|
-
stats =
|
|
11137
|
+
stats = fs18__namespace.statSync(absolute);
|
|
10888
11138
|
} catch {
|
|
10889
11139
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
10890
11140
|
}
|
|
@@ -10963,6 +11213,21 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
10963
11213
|
if (typeof overrides.sarif === "boolean") cliOptions.sarif = overrides.sarif;
|
|
10964
11214
|
if (typeof overrides.staged === "boolean") cliOptions.staged = overrides.staged;
|
|
10965
11215
|
if (typeof overrides.withDependents === "boolean") cliOptions.withDependents = overrides.withDependents;
|
|
11216
|
+
for (const key of ["includeDiffs", "tokenTree", "stripComments", "removeEmptyLines"]) {
|
|
11217
|
+
if (typeof overrides[key] === "boolean") cliOptions[key] = overrides[key];
|
|
11218
|
+
}
|
|
11219
|
+
if (overrides.includeLogs !== void 0) {
|
|
11220
|
+
if (typeof overrides.includeLogs !== "number" || !Number.isSafeInteger(overrides.includeLogs) || overrides.includeLogs < 1 || overrides.includeLogs > 500) {
|
|
11221
|
+
return { ok: false, message: '"includeLogs" must be an integer from 1 to 500.' };
|
|
11222
|
+
}
|
|
11223
|
+
cliOptions.includeLogs = overrides.includeLogs;
|
|
11224
|
+
}
|
|
11225
|
+
if (overrides.pack !== void 0) {
|
|
11226
|
+
if (overrides.pack !== "single" && overrides.pack !== "xml" && overrides.pack !== "json") {
|
|
11227
|
+
return { ok: false, message: '"pack" must be "single", "xml" or "json".' };
|
|
11228
|
+
}
|
|
11229
|
+
cliOptions.pack = overrides.pack;
|
|
11230
|
+
}
|
|
10966
11231
|
for (const key of ["only", "ignore"]) {
|
|
10967
11232
|
const value = overrides[key];
|
|
10968
11233
|
if (value === void 0) continue;
|
|
@@ -11017,21 +11282,21 @@ function partPathFor(workspace, filename) {
|
|
|
11017
11282
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
11018
11283
|
const partsDir = path7__namespace.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
11019
11284
|
const resolved = path7__namespace.resolve(partsDir, filename);
|
|
11020
|
-
const
|
|
11021
|
-
if (
|
|
11285
|
+
const relative14 = path7__namespace.relative(partsDir, resolved);
|
|
11286
|
+
if (relative14.length === 0 || relative14.includes(path7__namespace.sep) || relative14.includes("/") || relative14.includes("\\") || path7__namespace.isAbsolute(relative14)) {
|
|
11022
11287
|
return null;
|
|
11023
11288
|
}
|
|
11024
11289
|
let stats;
|
|
11025
11290
|
try {
|
|
11026
|
-
stats =
|
|
11291
|
+
stats = fs18__namespace.lstatSync(resolved);
|
|
11027
11292
|
} catch {
|
|
11028
11293
|
return null;
|
|
11029
11294
|
}
|
|
11030
11295
|
if (!stats.isFile()) return null;
|
|
11031
11296
|
try {
|
|
11032
|
-
const snapshotReal =
|
|
11033
|
-
const partsReal =
|
|
11034
|
-
const resolvedReal =
|
|
11297
|
+
const snapshotReal = fs18__namespace.realpathSync(path7__namespace.resolve(workspace.root, workspace.config.outDir));
|
|
11298
|
+
const partsReal = fs18__namespace.realpathSync(partsDir);
|
|
11299
|
+
const resolvedReal = fs18__namespace.realpathSync(resolved);
|
|
11035
11300
|
if (!isInside3(snapshotReal, partsReal)) return null;
|
|
11036
11301
|
if (!isInside3(partsReal, resolvedReal)) return null;
|
|
11037
11302
|
if (path7__namespace.dirname(resolvedReal) !== partsReal) return null;
|
|
@@ -11125,8 +11390,8 @@ var WRITES = {
|
|
|
11125
11390
|
var MAX_RESULT_BYTES = 64 * 1024;
|
|
11126
11391
|
var MAX_SEARCH_BYTES = 4 * 1024 * 1024;
|
|
11127
11392
|
var MAX_PART_READ_BYTES = 16 * 1024 * 1024;
|
|
11128
|
-
function capResultText(text) {
|
|
11129
|
-
const clipped = truncateToBytes(text,
|
|
11393
|
+
function capResultText(text, maxBytes = MAX_RESULT_BYTES) {
|
|
11394
|
+
const clipped = truncateToBytes(text, maxBytes);
|
|
11130
11395
|
return { text: clipped.isTruncated ? clipped.content : text, clipped: clipped.isTruncated };
|
|
11131
11396
|
}
|
|
11132
11397
|
function capResponseText(text) {
|
|
@@ -11175,9 +11440,21 @@ function workspaceOverrides(args) {
|
|
|
11175
11440
|
staged: args.staged,
|
|
11176
11441
|
withDependents: args.withDependents,
|
|
11177
11442
|
only: args.only,
|
|
11178
|
-
ignore: args.ignore
|
|
11443
|
+
ignore: args.ignore,
|
|
11444
|
+
includeDiffs: args.includeDiffs,
|
|
11445
|
+
includeLogs: args.includeLogs,
|
|
11446
|
+
tokenTree: args.tokenTree,
|
|
11447
|
+
stripComments: args.stripComments,
|
|
11448
|
+
removeEmptyLines: args.removeEmptyLines,
|
|
11449
|
+
pack: args.pack
|
|
11179
11450
|
};
|
|
11180
11451
|
}
|
|
11452
|
+
function cancellationSignal(context) {
|
|
11453
|
+
if (context.onCancel === void 0) return void 0;
|
|
11454
|
+
const controller = new AbortController();
|
|
11455
|
+
context.onCancel(() => controller.abort());
|
|
11456
|
+
return controller.signal;
|
|
11457
|
+
}
|
|
11181
11458
|
function failure(message) {
|
|
11182
11459
|
return { text: message, isError: true };
|
|
11183
11460
|
}
|
|
@@ -11211,11 +11488,11 @@ function toRelativePath(root, value) {
|
|
|
11211
11488
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
11212
11489
|
const resolvedRoot = path7__namespace.resolve(root);
|
|
11213
11490
|
const absolute = path7__namespace.resolve(resolvedRoot, cleaned);
|
|
11214
|
-
const
|
|
11215
|
-
if (
|
|
11491
|
+
const relative14 = path7__namespace.relative(resolvedRoot, absolute);
|
|
11492
|
+
if (relative14 === "" || relative14 === ".." || relative14.startsWith(".." + path7__namespace.sep) || path7__namespace.isAbsolute(relative14)) {
|
|
11216
11493
|
return null;
|
|
11217
11494
|
}
|
|
11218
|
-
return
|
|
11495
|
+
return relative14.split(path7__namespace.sep).join("/");
|
|
11219
11496
|
}
|
|
11220
11497
|
function symbolsOf(entry) {
|
|
11221
11498
|
const summary = entry.summary;
|
|
@@ -11291,25 +11568,75 @@ function partTooLargeFor(workspace, entry) {
|
|
|
11291
11568
|
const partPath = partPathFor(workspace, entry.part);
|
|
11292
11569
|
if (partPath === null) return false;
|
|
11293
11570
|
try {
|
|
11294
|
-
return
|
|
11571
|
+
return fs18__namespace.statSync(partPath).size > MAX_PART_READ_BYTES;
|
|
11295
11572
|
} catch {
|
|
11296
11573
|
return false;
|
|
11297
11574
|
}
|
|
11298
11575
|
}
|
|
11299
|
-
|
|
11576
|
+
var partCaches = /* @__PURE__ */ new WeakMap();
|
|
11577
|
+
function sha256Of(bytes) {
|
|
11578
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
11579
|
+
}
|
|
11580
|
+
function noteUnverifiedPart(index, detail) {
|
|
11581
|
+
index.trust.coverage = "partial";
|
|
11582
|
+
index.trust.reasons = [.../* @__PURE__ */ new Set([...index.trust.reasons, detail])];
|
|
11583
|
+
}
|
|
11584
|
+
function liveBody(index, entry) {
|
|
11585
|
+
return index.live?.readRedactedFile(entry.relativePath)?.text ?? null;
|
|
11586
|
+
}
|
|
11587
|
+
function bodyFor(workspace, index, entry, cache) {
|
|
11300
11588
|
if (index.live !== null && index.trust.indexSource !== "snapshot") {
|
|
11301
11589
|
return index.live.readRedactedFile(entry.relativePath)?.text ?? null;
|
|
11302
11590
|
}
|
|
11303
11591
|
const partPath = partPathFor(workspace, entry.part);
|
|
11304
|
-
if (partPath === null)
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
return section === null ? null : section.body;
|
|
11310
|
-
} catch {
|
|
11592
|
+
if (partPath === null) {
|
|
11593
|
+
if (index.live !== null) {
|
|
11594
|
+
noteUnverifiedPart(index, entry.part + " is missing; live bytes used");
|
|
11595
|
+
return liveBody(index, entry);
|
|
11596
|
+
}
|
|
11311
11597
|
return null;
|
|
11312
11598
|
}
|
|
11599
|
+
const store = partCaches.get(index) ?? (() => {
|
|
11600
|
+
const created = /* @__PURE__ */ new Map();
|
|
11601
|
+
partCaches.set(index, created);
|
|
11602
|
+
return created;
|
|
11603
|
+
})();
|
|
11604
|
+
let sections = store.get(entry.part);
|
|
11605
|
+
if (sections === void 0) {
|
|
11606
|
+
try {
|
|
11607
|
+
if (fs18__namespace.statSync(partPath).size > MAX_PART_READ_BYTES) {
|
|
11608
|
+
store.set(entry.part, null);
|
|
11609
|
+
return null;
|
|
11610
|
+
}
|
|
11611
|
+
const bytes = fs18__namespace.readFileSync(partPath);
|
|
11612
|
+
const recorded = index.manifest.parts.find((part) => part.filename === entry.part);
|
|
11613
|
+
if (recorded === void 0 || bytes.length !== recorded.byteSize || sha256Of(bytes) !== recorded.sha256) {
|
|
11614
|
+
store.set(entry.part, null);
|
|
11615
|
+
noteUnverifiedPart(
|
|
11616
|
+
index,
|
|
11617
|
+
entry.part + " does not match its recorded digest; live bytes used"
|
|
11618
|
+
);
|
|
11619
|
+
return liveBody(index, entry);
|
|
11620
|
+
}
|
|
11621
|
+
sections = parsePartSections(bytes.toString("utf8"));
|
|
11622
|
+
store.set(entry.part, sections);
|
|
11623
|
+
} catch {
|
|
11624
|
+
store.set(entry.part, null);
|
|
11625
|
+
noteUnverifiedPart(index, entry.part + " could not be read; live bytes used");
|
|
11626
|
+
return liveBody(index, entry);
|
|
11627
|
+
}
|
|
11628
|
+
}
|
|
11629
|
+
if (sections === null) return liveBody(index, entry);
|
|
11630
|
+
const section = findSection(sections, entry.relativePath);
|
|
11631
|
+
if (section === null) {
|
|
11632
|
+
noteUnverifiedPart(index, entry.relativePath + " is absent from " + entry.part + "; live bytes used");
|
|
11633
|
+
return liveBody(index, entry);
|
|
11634
|
+
}
|
|
11635
|
+
return section.body;
|
|
11636
|
+
}
|
|
11637
|
+
function numberWindow(text) {
|
|
11638
|
+
if (text.length === 0) return text;
|
|
11639
|
+
return text.split("\n").map((line, index) => index + 1 + ": " + line).join("\n");
|
|
11313
11640
|
}
|
|
11314
11641
|
var impactTool = {
|
|
11315
11642
|
name: "snapshot_impact",
|
|
@@ -11425,7 +11752,18 @@ var impactTool = {
|
|
|
11425
11752
|
targetPath: entry.path
|
|
11426
11753
|
}));
|
|
11427
11754
|
});
|
|
11428
|
-
|
|
11755
|
+
const lossyBodies = index.trust.indexSource === "snapshot" && tsEntries.some(
|
|
11756
|
+
(entry) => entry.inclusionMode === "preview" || entry.inclusionMode === "signatures"
|
|
11757
|
+
);
|
|
11758
|
+
if (lossyBodies) {
|
|
11759
|
+
const reason = "TypeScript compiler pass skipped: the snapshot holds previewed or skeletonised bodies; run snapshot_impact with live: true for compiler-resolved references";
|
|
11760
|
+
report = {
|
|
11761
|
+
...report,
|
|
11762
|
+
precise: { references: [], coverage: "partial", reasons: [reason] }
|
|
11763
|
+
};
|
|
11764
|
+
report.trust.coverage = "partial";
|
|
11765
|
+
report.trust.reasons = [.../* @__PURE__ */ new Set([...report.trust.reasons, reason])];
|
|
11766
|
+
} else if (tsEntries.length > DEFAULT_MAX_PROGRAM_FILES) {
|
|
11429
11767
|
const reason = "TypeScript compiler pass skipped: " + tsEntries.length + " TS/JS files exceed the " + DEFAULT_MAX_PROGRAM_FILES + "-file cap; fell back to import-binding results";
|
|
11430
11768
|
report = {
|
|
11431
11769
|
...report,
|
|
@@ -11443,14 +11781,17 @@ var impactTool = {
|
|
|
11443
11781
|
const body = bodyFor(workspace, index, entry);
|
|
11444
11782
|
return body === null ? null : { relativePath: entry.relativePath, content: body };
|
|
11445
11783
|
}).filter((entry) => entry !== null);
|
|
11446
|
-
const workerResult = await analysisInWorker(
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11784
|
+
const workerResult = await analysisInWorker(
|
|
11785
|
+
{
|
|
11786
|
+
task: "ts-batch-refs",
|
|
11787
|
+
options: {
|
|
11788
|
+
root: workspace.root,
|
|
11789
|
+
files,
|
|
11790
|
+
targets
|
|
11791
|
+
}
|
|
11792
|
+
},
|
|
11793
|
+
cancellationSignal(context)
|
|
11794
|
+
);
|
|
11454
11795
|
if (!workerResult.ok) return failure(workerResult.message);
|
|
11455
11796
|
const result = workerResult.result;
|
|
11456
11797
|
const references = [];
|
|
@@ -11504,6 +11845,8 @@ var contextTool = {
|
|
|
11504
11845
|
usedTokens: { type: "integer" },
|
|
11505
11846
|
files: { type: "array", items: { type: "object" } },
|
|
11506
11847
|
omitted: { type: "array", items: { type: "object" } },
|
|
11848
|
+
skipped: { type: "array", items: { type: "object" } },
|
|
11849
|
+
notes: { type: "array", items: { type: "string" } },
|
|
11507
11850
|
trust: { type: "object" }
|
|
11508
11851
|
}
|
|
11509
11852
|
},
|
|
@@ -11540,16 +11883,16 @@ var contextTool = {
|
|
|
11540
11883
|
}
|
|
11541
11884
|
}
|
|
11542
11885
|
for (const wanted of wantedFiles) {
|
|
11543
|
-
const
|
|
11544
|
-
if (
|
|
11886
|
+
const relative14 = toRelativePath(workspace.root, wanted);
|
|
11887
|
+
if (relative14 === null) {
|
|
11545
11888
|
preOmitted.push({ path: wanted, reason: "outside the served repository" });
|
|
11546
11889
|
continue;
|
|
11547
11890
|
}
|
|
11548
|
-
if (isSensitivePath(
|
|
11549
|
-
preOmitted.push({ path:
|
|
11891
|
+
if (isSensitivePath(relative14)) {
|
|
11892
|
+
preOmitted.push({ path: relative14, reason: "sensitive-file" });
|
|
11550
11893
|
continue;
|
|
11551
11894
|
}
|
|
11552
|
-
targets.set(
|
|
11895
|
+
targets.set(relative14, "requested file");
|
|
11553
11896
|
}
|
|
11554
11897
|
for (const symbol of wantedSymbols) {
|
|
11555
11898
|
const needle = symbol.toLowerCase();
|
|
@@ -11639,8 +11982,9 @@ var contextTool = {
|
|
|
11639
11982
|
});
|
|
11640
11983
|
continue;
|
|
11641
11984
|
}
|
|
11642
|
-
|
|
11643
|
-
let
|
|
11985
|
+
let window = windowText(body, 1, linesPerFile);
|
|
11986
|
+
let capped2 = capResultText(numberWindow(window.text));
|
|
11987
|
+
let text = capped2.text;
|
|
11644
11988
|
let tokens = Math.max(1, estimateTokens(text));
|
|
11645
11989
|
if (used + tokens > budget) {
|
|
11646
11990
|
const keep = Math.max(4, Math.floor((budget - used) / tokens * linesPerFile));
|
|
@@ -11648,17 +11992,30 @@ var contextTool = {
|
|
|
11648
11992
|
omitted.push({ path: relativePath, reason: "budget" });
|
|
11649
11993
|
continue;
|
|
11650
11994
|
}
|
|
11651
|
-
|
|
11652
|
-
|
|
11995
|
+
window = windowText(body, 1, keep);
|
|
11996
|
+
capped2 = capResultText(numberWindow(window.text));
|
|
11997
|
+
text = capped2.text;
|
|
11653
11998
|
tokens = Math.max(1, estimateTokens(text));
|
|
11654
11999
|
if (used + tokens > budget || text.length === 0) {
|
|
11655
12000
|
omitted.push({ path: relativePath, reason: "budget" });
|
|
11656
12001
|
continue;
|
|
11657
12002
|
}
|
|
11658
12003
|
}
|
|
11659
|
-
|
|
12004
|
+
const returnedLines = text.length === 0 ? 0 : text.split("\n").length;
|
|
12005
|
+
const truncated = window.truncated || capped2.clipped;
|
|
12006
|
+
sections.push(
|
|
12007
|
+
"### " + relativePath + " (" + entry.part + ", lines 1\u2013" + returnedLines + " of " + window.totalLines + (truncated ? "; more remains" : "") + ")"
|
|
12008
|
+
);
|
|
11660
12009
|
sections.push(text);
|
|
11661
|
-
blocks.push({
|
|
12010
|
+
blocks.push({
|
|
12011
|
+
path: relativePath,
|
|
12012
|
+
tokens,
|
|
12013
|
+
why,
|
|
12014
|
+
fromLine: 1,
|
|
12015
|
+
returnedLines,
|
|
12016
|
+
totalLines: window.totalLines,
|
|
12017
|
+
truncated
|
|
12018
|
+
});
|
|
11662
12019
|
used += tokens;
|
|
11663
12020
|
}
|
|
11664
12021
|
const notes = omitted.length === 0 ? [] : ["Not returned: " + omitted.map((entry) => entry.path + " (" + entry.reason + ")").join(", ") + "."];
|
|
@@ -11809,11 +12166,17 @@ var locateTool = {
|
|
|
11809
12166
|
for (const entry of index.manifest.files) add(entry, "filter");
|
|
11810
12167
|
}
|
|
11811
12168
|
const shouldText = by === "text" || by === "auto" && matches.length === 0 && rawQuery.length >= 3;
|
|
12169
|
+
let textCapReason = null;
|
|
11812
12170
|
if (shouldText) {
|
|
11813
12171
|
let scanned = 0;
|
|
11814
12172
|
for (const entry of index.manifest.files) {
|
|
11815
12173
|
if (!allowed(entry)) continue;
|
|
11816
|
-
if (scanned >= MAX_SEARCH_BYTES)
|
|
12174
|
+
if (scanned >= MAX_SEARCH_BYTES) {
|
|
12175
|
+
textCapReason = "text search stopped after 4 MiB of indexed bodies; later files were not scanned";
|
|
12176
|
+
index.trust.coverage = "partial";
|
|
12177
|
+
index.trust.reasons = [.../* @__PURE__ */ new Set([...index.trust.reasons, textCapReason])];
|
|
12178
|
+
break;
|
|
12179
|
+
}
|
|
11817
12180
|
const body = bodyFor(workspace, index, entry);
|
|
11818
12181
|
if (body === null) continue;
|
|
11819
12182
|
scanned += Buffer.byteLength(body, "utf8");
|
|
@@ -11845,7 +12208,15 @@ var locateTool = {
|
|
|
11845
12208
|
let referenceReasons = [];
|
|
11846
12209
|
if (args.includeReferences === true && rawQuery.length > 0) {
|
|
11847
12210
|
const tsEntries = index.manifest.files.filter((entry) => /\.(?:[cm]?[jt]sx?)$/i.test(entry.relativePath));
|
|
11848
|
-
|
|
12211
|
+
const lossyBodies = index.trust.indexSource === "snapshot" && tsEntries.some(
|
|
12212
|
+
(entry) => entry.inclusionMode === "preview" || entry.inclusionMode === "signatures"
|
|
12213
|
+
);
|
|
12214
|
+
const lossyReason = "TypeScript compiler pass skipped: the snapshot holds previewed or skeletonised bodies; run snapshot_locate with live: true for compiler-resolved references";
|
|
12215
|
+
if (lossyBodies) {
|
|
12216
|
+
referenceReasons = [lossyReason];
|
|
12217
|
+
index.trust.coverage = "partial";
|
|
12218
|
+
index.trust.reasons = [.../* @__PURE__ */ new Set([...index.trust.reasons, lossyReason])];
|
|
12219
|
+
} else if (tsEntries.length > DEFAULT_MAX_PROGRAM_FILES) {
|
|
11849
12220
|
const reason = "TypeScript compiler pass skipped: " + tsEntries.length + " TS/JS files exceed the " + DEFAULT_MAX_PROGRAM_FILES + "-file cap; fell back to syntactic matches";
|
|
11850
12221
|
referenceReasons = [reason];
|
|
11851
12222
|
index.trust.coverage = "partial";
|
|
@@ -11859,15 +12230,18 @@ var locateTool = {
|
|
|
11859
12230
|
(entry) => entry.matchedBy === "symbol" && (pattern === null ? entry.detail?.toLowerCase() === needle : entry.detail === rawQuery)
|
|
11860
12231
|
);
|
|
11861
12232
|
const target = exact?.path;
|
|
11862
|
-
const workerResult = await analysisInWorker(
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
12233
|
+
const workerResult = await analysisInWorker(
|
|
12234
|
+
{
|
|
12235
|
+
task: "ts-refs",
|
|
12236
|
+
options: {
|
|
12237
|
+
root: workspace.root,
|
|
12238
|
+
files,
|
|
12239
|
+
symbolName: rawQuery,
|
|
12240
|
+
...target === void 0 ? {} : { targetPath: target }
|
|
12241
|
+
}
|
|
12242
|
+
},
|
|
12243
|
+
cancellationSignal(context)
|
|
12244
|
+
);
|
|
11871
12245
|
if (!workerResult.ok) return failure(workerResult.message);
|
|
11872
12246
|
const result = workerResult.result;
|
|
11873
12247
|
references = result.references;
|
|
@@ -11884,6 +12258,7 @@ var locateTool = {
|
|
|
11884
12258
|
(match) => match.line === void 0 ? " - " + match.path + " [" + match.matchedBy + (match.detail === void 0 ? "" : ": " + match.detail) + "]" : " - " + match.path + ":" + match.line + " " + (match.text ?? "")
|
|
11885
12259
|
),
|
|
11886
12260
|
...references.length === 0 ? [] : ["", "References:", ...references.slice(0, 25).map((reference) => " - " + reference.path + ":" + reference.line + " (" + reference.name + ")")],
|
|
12261
|
+
...textCapReason === null ? [] : ["Note: " + textCapReason],
|
|
11887
12262
|
...referenceReasons.slice(0, 3).map((reason) => "Note: " + reason)
|
|
11888
12263
|
];
|
|
11889
12264
|
return {
|
|
@@ -11967,29 +12342,34 @@ var readTool = {
|
|
|
11967
12342
|
return failure(relativePath + " is recorded in " + entry.part + " but its body could not be read. Run snapshot_generate.");
|
|
11968
12343
|
}
|
|
11969
12344
|
const window = windowText(body, fromLine, lineCount);
|
|
11970
|
-
const cappedText = capResultText(window.text);
|
|
11971
|
-
const
|
|
12345
|
+
const cappedText = capResultText(window.text, MAX_RESULT_BYTES - 1024);
|
|
12346
|
+
const bodyLines = cappedText.text.length === 0 ? 0 : cappedText.text.split("\n").length;
|
|
11972
12347
|
const header2 = [
|
|
11973
12348
|
relativePath + " \u2014 " + entry.part + ", " + entry.layer + "/" + entry.kind + ", " + entry.language,
|
|
11974
|
-
window.totalLines === 0 ? "This file is empty." : window.pastEnd ? "This file has " + window.totalLines + " line(s); fromLine=" + window.fromLine + " is past its end." : "Lines " + window.fromLine + "\u2013" + (window.fromLine +
|
|
12349
|
+
window.totalLines === 0 ? "This file is empty." : window.pastEnd ? "This file has " + window.totalLines + " line(s); fromLine=" + window.fromLine + " is past its end." : "Lines " + window.fromLine + "\u2013" + (window.fromLine + bodyLines - 1) + " of " + window.totalLines + ".",
|
|
11975
12350
|
...index.trust.indexSource === "snapshot" && entry.inclusionMode === "preview" ? ["Bounded preview: the snapshot holds this file's head and tail only."] : [],
|
|
11976
12351
|
...cappedText.clipped ? ["Truncated: a line is longer than one result can carry, so this page may end mid-line."] : []
|
|
11977
12352
|
];
|
|
11978
12353
|
const text = [...header2, "", cappedText.text];
|
|
11979
|
-
if (
|
|
11980
|
-
text.push("", "Truncated. Call snapshot_read with fromLine=" + (window.fromLine +
|
|
11981
|
-
}
|
|
12354
|
+
if (!cappedText.clipped && window.truncated) {
|
|
12355
|
+
text.push("", "Truncated. Call snapshot_read with fromLine=" + (window.fromLine + bodyLines) + " for the rest.");
|
|
12356
|
+
}
|
|
12357
|
+
const response = capResponseText(text.join("\n"));
|
|
12358
|
+
const clipped = cappedText.clipped || response.clipped;
|
|
12359
|
+
const headerPrefix = header2.join("\n") + "\n\n";
|
|
12360
|
+
const delivered = response.text.startsWith(headerPrefix) ? response.text.slice(headerPrefix.length) : "";
|
|
12361
|
+
const returnedLines = response.clipped ? delivered.length === 0 ? 0 : delivered.split("\n").length : bodyLines;
|
|
11982
12362
|
return {
|
|
11983
|
-
text:
|
|
12363
|
+
text: response.text,
|
|
11984
12364
|
structured: {
|
|
11985
12365
|
path: entry.relativePath,
|
|
11986
12366
|
part: entry.part,
|
|
11987
12367
|
fromLine: window.fromLine,
|
|
11988
12368
|
returnedLines,
|
|
11989
12369
|
totalLines: window.totalLines,
|
|
11990
|
-
...!
|
|
11991
|
-
truncated: window.truncated ||
|
|
11992
|
-
pageable: !
|
|
12370
|
+
...!clipped && window.truncated ? { nextFromLine: window.fromLine + returnedLines } : {},
|
|
12371
|
+
truncated: window.truncated || clipped,
|
|
12372
|
+
pageable: !clipped,
|
|
11993
12373
|
trust: index.trust
|
|
11994
12374
|
}
|
|
11995
12375
|
};
|
|
@@ -12005,6 +12385,19 @@ var validateTool = {
|
|
|
12005
12385
|
mode: { type: "string", enum: ["status", "drift", "audit"], default: "drift" },
|
|
12006
12386
|
deep: { type: "boolean", description: "With audit, replay every full body." },
|
|
12007
12387
|
maxScanBytes: { type: "integer", minimum: 1, description: "Cap the audit text scan." },
|
|
12388
|
+
// `snapshot_generate` accepts every option below, and each one enters `configDigest`.
|
|
12389
|
+
// A validator that did not accept them reported permanent drift for a snapshot the same
|
|
12390
|
+
// server had just written.
|
|
12391
|
+
maxPartBytes: { type: ["string", "number"], description: 'Byte budget per part, for example 307200 or "300k".' },
|
|
12392
|
+
maxPartTokens: { type: ["string", "number"], description: 'Token budget per part, for example 32000 or "32k".' },
|
|
12393
|
+
skeleton: { type: "boolean", description: "Signature-compress JS/TS bodies." },
|
|
12394
|
+
sarif: { type: "boolean", description: "Also write reports/audit.sarif." },
|
|
12395
|
+
stripComments: { type: "boolean", description: "Remove comments from JS/TS bodies." },
|
|
12396
|
+
removeEmptyLines: { type: "boolean", description: "Drop blank lines from bodies." },
|
|
12397
|
+
pack: { type: "string", enum: ["single", "xml", "json"], description: "Write one full-repository file." },
|
|
12398
|
+
includeDiffs: { type: "boolean", description: "Also write reports/diff.md." },
|
|
12399
|
+
includeLogs: { type: "integer", minimum: 1, maximum: 500, description: "Also write reports/log.md." },
|
|
12400
|
+
tokenTree: { type: "boolean", description: "Also write reports/tokens.md." },
|
|
12008
12401
|
root: ROOT_PROPERTY,
|
|
12009
12402
|
outDir: OUT_DIR_PROPERTY,
|
|
12010
12403
|
...SCOPE_PROPERTIES
|
|
@@ -12055,19 +12448,22 @@ var validateTool = {
|
|
|
12055
12448
|
};
|
|
12056
12449
|
}
|
|
12057
12450
|
if (mode === "audit") {
|
|
12058
|
-
const analysis2 = await analysisInWorker(
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12068
|
-
|
|
12069
|
-
|
|
12070
|
-
|
|
12451
|
+
const analysis2 = await analysisInWorker(
|
|
12452
|
+
{
|
|
12453
|
+
task: "health",
|
|
12454
|
+
options: {
|
|
12455
|
+
snapshotDir: path7__namespace.resolve(workspace.root, workspace.config.outDir),
|
|
12456
|
+
repoDir: workspace.root,
|
|
12457
|
+
// Only the project's own rules: `auditSnapshot` adds the built-in set itself for the
|
|
12458
|
+
// section scan. Passing all 32 here re-scans every raw part under its Markdown path,
|
|
12459
|
+
// where an unquoted TypeScript expression looks like an unmasked credential.
|
|
12460
|
+
...(workspace.config.customSecretRules ?? []).length === 0 ? {} : { secretRules: workspace.config.customSecretRules },
|
|
12461
|
+
deep: args.deep === true,
|
|
12462
|
+
...typeof args.maxScanBytes === "number" ? { maxScanBytes: args.maxScanBytes } : {}
|
|
12463
|
+
}
|
|
12464
|
+
},
|
|
12465
|
+
cancellationSignal(context)
|
|
12466
|
+
);
|
|
12071
12467
|
if (!analysis2.ok) return failure(analysis2.message);
|
|
12072
12468
|
const report = analysis2.result;
|
|
12073
12469
|
const failed = report.checks.filter((check) => check.status === "fail");
|
|
@@ -12087,12 +12483,15 @@ var validateTool = {
|
|
|
12087
12483
|
}
|
|
12088
12484
|
};
|
|
12089
12485
|
}
|
|
12090
|
-
const analysis = await analysisInWorker(
|
|
12091
|
-
|
|
12092
|
-
|
|
12093
|
-
|
|
12094
|
-
|
|
12095
|
-
|
|
12486
|
+
const analysis = await analysisInWorker(
|
|
12487
|
+
{
|
|
12488
|
+
task: "validate-workspace",
|
|
12489
|
+
root: workspace.root,
|
|
12490
|
+
sourceConfig: workspace.sourceConfig,
|
|
12491
|
+
cliOptions: workspace.cliOptions
|
|
12492
|
+
},
|
|
12493
|
+
cancellationSignal(context)
|
|
12494
|
+
);
|
|
12096
12495
|
if (!analysis.ok) return failure(analysis.message);
|
|
12097
12496
|
const result = analysis.result;
|
|
12098
12497
|
const lines = [result.valid ? "The snapshot matches the repository." : "The snapshot is out of date."];
|
|
@@ -12151,13 +12550,16 @@ var explainTool = {
|
|
|
12151
12550
|
if (typeof args.path !== "string") return failure('"path" must be a string.');
|
|
12152
12551
|
const relativePath = toRelativePath(workspace.root, args.path);
|
|
12153
12552
|
if (relativePath === null) return failure('"' + args.path + '" is outside ' + workspace.root + ".");
|
|
12154
|
-
const analysis = await analysisInWorker(
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12553
|
+
const analysis = await analysisInWorker(
|
|
12554
|
+
{
|
|
12555
|
+
task: "explain",
|
|
12556
|
+
root: workspace.root,
|
|
12557
|
+
sourceConfig: workspace.sourceConfig,
|
|
12558
|
+
cliOptions: workspace.cliOptions,
|
|
12559
|
+
path: relativePath
|
|
12560
|
+
},
|
|
12561
|
+
cancellationSignal(context)
|
|
12562
|
+
);
|
|
12161
12563
|
if (!analysis.ok) return failure(analysis.message);
|
|
12162
12564
|
const result = analysis.result;
|
|
12163
12565
|
return {
|
|
@@ -12381,8 +12783,8 @@ async function runStdioServer(options) {
|
|
|
12381
12783
|
let inFlight = 0;
|
|
12382
12784
|
let inputEnded = false;
|
|
12383
12785
|
let resolveDone = () => void 0;
|
|
12384
|
-
const finished = new Promise((
|
|
12385
|
-
resolveDone =
|
|
12786
|
+
const finished = new Promise((resolve15) => {
|
|
12787
|
+
resolveDone = resolve15;
|
|
12386
12788
|
});
|
|
12387
12789
|
const finishIfIdle = () => {
|
|
12388
12790
|
if (inputEnded && inFlight === 0) resolveDone(0);
|
|
@@ -12717,14 +13119,51 @@ function createMcpHttpHandler(options) {
|
|
|
12717
13119
|
const token = options.token;
|
|
12718
13120
|
const maxBody = options.maxBodyBytes ?? DEFAULT_MAX_BODY;
|
|
12719
13121
|
const extraOrigins = options.allowedOrigins ?? [];
|
|
12720
|
-
const
|
|
13122
|
+
const modernCancellations = /* @__PURE__ */ new Map();
|
|
13123
|
+
const MAX_MODERN_SCOPES = 64;
|
|
13124
|
+
const modernCancellationMap = (scope) => {
|
|
13125
|
+
let map = modernCancellations.get(scope);
|
|
13126
|
+
if (map !== void 0) return map;
|
|
13127
|
+
if (modernCancellations.size >= MAX_MODERN_SCOPES) {
|
|
13128
|
+
const oldest = modernCancellations.keys().next().value;
|
|
13129
|
+
if (oldest !== void 0) modernCancellations.delete(oldest);
|
|
13130
|
+
}
|
|
13131
|
+
map = /* @__PURE__ */ new Map();
|
|
13132
|
+
modernCancellations.set(scope, map);
|
|
13133
|
+
return map;
|
|
13134
|
+
};
|
|
13135
|
+
const createMcp = (cancellations) => createServer({
|
|
12721
13136
|
cwd: options.cwd,
|
|
12722
13137
|
log,
|
|
12723
|
-
// Each server owns its cancellation map. A map shared by every HTTP and SSE
|
|
12724
|
-
// only by the JSON-RPC id let one client's `id: 1` overwrite another's, and
|
|
12725
|
-
// cancel the other's in-flight tool call.
|
|
13138
|
+
// Each non-modern server owns its cancellation map. A map shared by every HTTP and SSE
|
|
13139
|
+
// session keyed only by the JSON-RPC id let one client's `id: 1` overwrite another's, and
|
|
13140
|
+
// let either one cancel the other's in-flight tool call.
|
|
13141
|
+
...cancellations === void 0 ? {} : { cancellations },
|
|
12726
13142
|
...options.noConfig === true ? { noConfig: true } : {}
|
|
12727
13143
|
});
|
|
13144
|
+
const clientScopeHint = (message) => {
|
|
13145
|
+
const items = Array.isArray(message) ? message : [message];
|
|
13146
|
+
for (const item of items) {
|
|
13147
|
+
if (!isJsonObject(item)) continue;
|
|
13148
|
+
const params = item.params;
|
|
13149
|
+
if (!isJsonObject(params)) continue;
|
|
13150
|
+
const meta = params._meta;
|
|
13151
|
+
if (!isJsonObject(meta)) continue;
|
|
13152
|
+
const info = meta[META_KEYS.clientInfo];
|
|
13153
|
+
if (!isJsonObject(info)) continue;
|
|
13154
|
+
const name = typeof info.name === "string" ? info.name : "";
|
|
13155
|
+
const version = typeof info.version === "string" ? info.version : "";
|
|
13156
|
+
if (name !== "" || version !== "") return "client:" + name + "@" + version;
|
|
13157
|
+
}
|
|
13158
|
+
return "";
|
|
13159
|
+
};
|
|
13160
|
+
const messageMethod = (message) => {
|
|
13161
|
+
const items = Array.isArray(message) ? message : [message];
|
|
13162
|
+
for (const item of items) {
|
|
13163
|
+
if (isJsonObject(item) && typeof item.method === "string") return item.method;
|
|
13164
|
+
}
|
|
13165
|
+
return "";
|
|
13166
|
+
};
|
|
12728
13167
|
const toolCount = buildTools().length;
|
|
12729
13168
|
const mcpSessions = /* @__PURE__ */ new Map();
|
|
12730
13169
|
const socketServers = /* @__PURE__ */ new WeakMap();
|
|
@@ -13073,7 +13512,30 @@ function createMcpHttpHandler(options) {
|
|
|
13073
13512
|
responseSession = newSessionId();
|
|
13074
13513
|
rememberSession(responseSession, server, Date.now());
|
|
13075
13514
|
} else if (modern) {
|
|
13076
|
-
|
|
13515
|
+
const hint = clientScopeHint(message);
|
|
13516
|
+
const anonymous = "anonymous:" + anonymousKey(request);
|
|
13517
|
+
let cancellations;
|
|
13518
|
+
if (supplied !== "") {
|
|
13519
|
+
cancellations = modernCancellationMap("session:" + supplied);
|
|
13520
|
+
} else if (messageMethod(message) === "notifications/cancelled" && hint === "") {
|
|
13521
|
+
cancellations = /* @__PURE__ */ new Map();
|
|
13522
|
+
for (const [scope, map] of modernCancellations) {
|
|
13523
|
+
if (scope !== anonymous && !scope.startsWith(anonymous + "|")) continue;
|
|
13524
|
+
for (const [id, pending] of map) {
|
|
13525
|
+
let merged = cancellations.get(id);
|
|
13526
|
+
if (merged === void 0) {
|
|
13527
|
+
merged = /* @__PURE__ */ new Set();
|
|
13528
|
+
cancellations.set(id, merged);
|
|
13529
|
+
}
|
|
13530
|
+
for (const cancel of pending) merged.add(cancel);
|
|
13531
|
+
}
|
|
13532
|
+
}
|
|
13533
|
+
} else {
|
|
13534
|
+
cancellations = modernCancellationMap(
|
|
13535
|
+
hint === "" ? anonymous : anonymous + "|" + hint
|
|
13536
|
+
);
|
|
13537
|
+
}
|
|
13538
|
+
server = createMcp(cancellations);
|
|
13077
13539
|
} else if (supplied !== "") {
|
|
13078
13540
|
const now = Date.now();
|
|
13079
13541
|
pruneSessions(now);
|
|
@@ -13306,11 +13768,11 @@ async function startHttpTransport(options) {
|
|
|
13306
13768
|
}
|
|
13307
13769
|
send(405, { error: "method not allowed" }, { ...cors, allow: "POST, GET, OPTIONS, DELETE" });
|
|
13308
13770
|
});
|
|
13309
|
-
await new Promise((
|
|
13771
|
+
await new Promise((resolve15, reject) => {
|
|
13310
13772
|
httpServer.once("error", reject);
|
|
13311
13773
|
httpServer.listen(port, host, () => {
|
|
13312
13774
|
httpServer.removeListener("error", reject);
|
|
13313
|
-
|
|
13775
|
+
resolve15();
|
|
13314
13776
|
});
|
|
13315
13777
|
});
|
|
13316
13778
|
const address = httpServer.address();
|
|
@@ -13323,8 +13785,8 @@ async function startHttpTransport(options) {
|
|
|
13323
13785
|
token,
|
|
13324
13786
|
close: async () => {
|
|
13325
13787
|
await mcp.close();
|
|
13326
|
-
await new Promise((
|
|
13327
|
-
httpServer.close(() =>
|
|
13788
|
+
await new Promise((resolve15) => {
|
|
13789
|
+
httpServer.close(() => resolve15());
|
|
13328
13790
|
httpServer.closeAllConnections();
|
|
13329
13791
|
});
|
|
13330
13792
|
}
|
|
@@ -13336,16 +13798,16 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
|
13336
13798
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
13337
13799
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
13338
13800
|
var fileDerivationBytes = 0;
|
|
13339
|
-
function takeDerivation(
|
|
13340
|
-
const key =
|
|
13801
|
+
function takeDerivation(path22, relativePath, hash, settings) {
|
|
13802
|
+
const key = path22 + "\0" + relativePath;
|
|
13341
13803
|
const cached = FILE_DERIVATIONS.get(key);
|
|
13342
13804
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
13343
13805
|
FILE_DERIVATIONS.delete(key);
|
|
13344
13806
|
FILE_DERIVATIONS.set(key, cached);
|
|
13345
13807
|
return cached;
|
|
13346
13808
|
}
|
|
13347
|
-
function rememberDerivation(
|
|
13348
|
-
const key =
|
|
13809
|
+
function rememberDerivation(path22, relativePath, hash, settings, derivation) {
|
|
13810
|
+
const key = path22 + "\0" + relativePath;
|
|
13349
13811
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
13350
13812
|
const bytes = bodyBytes * 2 + 512;
|
|
13351
13813
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
@@ -13612,6 +14074,11 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
13612
14074
|
);
|
|
13613
14075
|
}
|
|
13614
14076
|
}
|
|
14077
|
+
if (typeof file.includedLines === "number" && file.includedLines > file.lines + 1) {
|
|
14078
|
+
errors.push(
|
|
14079
|
+
`${file.relativePath} records ${file.includedLines} included line(s) for a ${file.lines}-line file.`
|
|
14080
|
+
);
|
|
14081
|
+
}
|
|
13615
14082
|
}
|
|
13616
14083
|
const partNames = new Set(parts.map((part) => part.filename));
|
|
13617
14084
|
for (const file of files) {
|
|
@@ -13705,12 +14172,12 @@ var SNAPSHOT_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9
|
|
|
13705
14172
|
var SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
13706
14173
|
function readOwnershipMarker(dir) {
|
|
13707
14174
|
const markerPath = path7__namespace.join(dir, OWNERSHIP_MARKER);
|
|
13708
|
-
if (!
|
|
14175
|
+
if (!fs18__namespace.existsSync(markerPath)) {
|
|
13709
14176
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
13710
14177
|
}
|
|
13711
14178
|
let raw;
|
|
13712
14179
|
try {
|
|
13713
|
-
raw =
|
|
14180
|
+
raw = fs18__namespace.readFileSync(markerPath, "utf8");
|
|
13714
14181
|
} catch {
|
|
13715
14182
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
13716
14183
|
}
|
|
@@ -13797,7 +14264,7 @@ function canonicalLockTarget(targetPath) {
|
|
|
13797
14264
|
const tail = [];
|
|
13798
14265
|
for (; ; ) {
|
|
13799
14266
|
try {
|
|
13800
|
-
return path7__namespace.join(
|
|
14267
|
+
return path7__namespace.join(fs18__namespace.realpathSync(existing), ...tail);
|
|
13801
14268
|
} catch {
|
|
13802
14269
|
const parent = path7__namespace.dirname(existing);
|
|
13803
14270
|
if (parent === existing) return resolved;
|
|
@@ -13814,13 +14281,13 @@ function releaseAbandonedRun(stagingRoots, runId) {
|
|
|
13814
14281
|
for (const root of new Set(stagingRoots)) {
|
|
13815
14282
|
const lockPath = lockPathFor(root);
|
|
13816
14283
|
try {
|
|
13817
|
-
const payload = JSON.parse(
|
|
13818
|
-
if (payload.runId === runId)
|
|
14284
|
+
const payload = JSON.parse(fs18__namespace.readFileSync(lockPath, "utf8"));
|
|
14285
|
+
if (payload.runId === runId) fs18__namespace.rmSync(lockPath, { force: true });
|
|
13819
14286
|
} catch {
|
|
13820
14287
|
}
|
|
13821
14288
|
let entries;
|
|
13822
14289
|
try {
|
|
13823
|
-
entries =
|
|
14290
|
+
entries = fs18__namespace.readdirSync(root);
|
|
13824
14291
|
} catch {
|
|
13825
14292
|
continue;
|
|
13826
14293
|
}
|
|
@@ -13830,7 +14297,7 @@ function releaseAbandonedRun(stagingRoots, runId) {
|
|
|
13830
14297
|
const { marker } = readOwnershipMarker(directory);
|
|
13831
14298
|
if (marker?.runId !== runId) continue;
|
|
13832
14299
|
try {
|
|
13833
|
-
|
|
14300
|
+
fs18__namespace.rmSync(directory, { recursive: true, force: true });
|
|
13834
14301
|
} catch {
|
|
13835
14302
|
}
|
|
13836
14303
|
}
|
|
@@ -13975,7 +14442,7 @@ function generateSnapshot(configInput, options) {
|
|
|
13975
14442
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
13976
14443
|
(directory) => path7__namespace.relative(config.cwd, path7__namespace.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
13977
14444
|
).filter(
|
|
13978
|
-
(
|
|
14445
|
+
(relative14) => relative14.length > 0 && relative14 !== ".." && !relative14.startsWith(`..${path7__namespace.sep}`) && !relative14.startsWith("../") && !path7__namespace.isAbsolute(relative14)
|
|
13979
14446
|
),
|
|
13980
14447
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
13981
14448
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
@@ -14035,9 +14502,9 @@ function generateSnapshot(configInput, options) {
|
|
|
14035
14502
|
} else {
|
|
14036
14503
|
let stats;
|
|
14037
14504
|
try {
|
|
14038
|
-
stats =
|
|
14505
|
+
stats = fs18__namespace.statSync(absolutePath);
|
|
14039
14506
|
if (!stats.isFile()) {
|
|
14040
|
-
const nestedRepository = stats.isDirectory() &&
|
|
14507
|
+
const nestedRepository = stats.isDirectory() && fs18__namespace.existsSync(path7__namespace.join(absolutePath, ".git"));
|
|
14041
14508
|
skipped.push(
|
|
14042
14509
|
nestedRepository ? {
|
|
14043
14510
|
path: relativePath,
|
|
@@ -14073,7 +14540,7 @@ function generateSnapshot(configInput, options) {
|
|
|
14073
14540
|
continue;
|
|
14074
14541
|
}
|
|
14075
14542
|
try {
|
|
14076
|
-
buffer =
|
|
14543
|
+
buffer = fs18__namespace.readFileSync(absolutePath);
|
|
14077
14544
|
} catch (err) {
|
|
14078
14545
|
const code = err.code;
|
|
14079
14546
|
skipped.push({
|
|
@@ -14190,14 +14657,14 @@ function generateSnapshot(configInput, options) {
|
|
|
14190
14657
|
}
|
|
14191
14658
|
retain(secretFindings, (finding) => finding.path === void 0 || keep.has(finding.path));
|
|
14192
14659
|
retain(encodingNotes, (note) => keep.has(note.path));
|
|
14193
|
-
retain(oversizeSummaryPaths, (
|
|
14194
|
-
retain(previewSummaryPaths, (
|
|
14660
|
+
retain(oversizeSummaryPaths, (path22) => keep.has(path22));
|
|
14661
|
+
retain(previewSummaryPaths, (path22) => keep.has(path22));
|
|
14195
14662
|
retain(fileWarnings, (warning) => keep.has(warning.path));
|
|
14196
|
-
for (const
|
|
14197
|
-
if (!keep.has(
|
|
14663
|
+
for (const path22 of [...monolithBodies.keys()]) {
|
|
14664
|
+
if (!keep.has(path22)) monolithBodies.delete(path22);
|
|
14198
14665
|
}
|
|
14199
|
-
for (const
|
|
14200
|
-
if (!keep.has(
|
|
14666
|
+
for (const path22 of [...skippedSummaryImports.keys()]) {
|
|
14667
|
+
if (!keep.has(path22)) skippedSummaryImports.delete(path22);
|
|
14201
14668
|
}
|
|
14202
14669
|
};
|
|
14203
14670
|
if (changedScope !== null && changedPaths !== null && config.withDependents === true) {
|
|
@@ -14458,7 +14925,8 @@ function generateSnapshot(configInput, options) {
|
|
|
14458
14925
|
);
|
|
14459
14926
|
}
|
|
14460
14927
|
}
|
|
14461
|
-
const
|
|
14928
|
+
const partitionConfig = { ...config, maxParts: null } ;
|
|
14929
|
+
const partitioned = partitionByBudget(files, partitionConfig, fingerprint);
|
|
14462
14930
|
const parts = partitioned.parts;
|
|
14463
14931
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
14464
14932
|
const incomplete = files.flatMap((file) => {
|
|
@@ -14764,7 +15232,7 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
14764
15232
|
],
|
|
14765
15233
|
// The health audit resolves the config only to find the output directory; --strict decides the
|
|
14766
15234
|
// exit code, and every other setting would be a promise the command does not keep.
|
|
14767
|
-
health: ["cwd", "out-dir", "format", "strict", "all-members", "deep", "mode", "no-update-check", "help", "version"],
|
|
15235
|
+
health: ["cwd", "out-dir", "format", "strict", "all-members", "deep", "no-config", "mode", "no-update-check", "help", "version"],
|
|
14768
15236
|
// `impact` reads the existing manifest and the working tree. It deliberately takes no
|
|
14769
15237
|
// generation settings: accepting one would imply the report regenerated or re-scoped the
|
|
14770
15238
|
// snapshot, which it never does.
|
|
@@ -15210,42 +15678,42 @@ function buildAgentContract() {
|
|
|
15210
15678
|
type: "string",
|
|
15211
15679
|
default: null,
|
|
15212
15680
|
appliesTo: optionAppliesTo("diff"),
|
|
15213
|
-
summary: "impact and brief: compare the working tree against this git ref. The set includes committed, staged, unstaged and untracked changes relative to the ref."
|
|
15681
|
+
summary: "impact, guard and brief: compare the working tree against this git ref. The set includes committed, staged, unstaged and untracked changes relative to the ref."
|
|
15214
15682
|
},
|
|
15215
15683
|
{
|
|
15216
15684
|
flag: "--paths",
|
|
15217
15685
|
type: "string",
|
|
15218
15686
|
default: null,
|
|
15219
15687
|
appliesTo: optionAppliesTo("paths"),
|
|
15220
|
-
summary: "impact and brief: comma-separated repository-relative paths to treat as the change. Mutually exclusive with --diff."
|
|
15688
|
+
summary: "impact, guard and brief: comma-separated repository-relative paths to treat as the change. Mutually exclusive with --diff."
|
|
15221
15689
|
},
|
|
15222
15690
|
{
|
|
15223
15691
|
flag: "--depth",
|
|
15224
15692
|
type: "number",
|
|
15225
15693
|
default: 3,
|
|
15226
15694
|
appliesTo: optionAppliesTo("depth"),
|
|
15227
|
-
summary: "impact and brief: reverse-import hops to follow, 1-8 (default 3)."
|
|
15695
|
+
summary: "impact, guard and brief: reverse-import hops to follow, 1-8 (default 3)."
|
|
15228
15696
|
},
|
|
15229
15697
|
{
|
|
15230
15698
|
flag: "--max-results",
|
|
15231
15699
|
type: "number",
|
|
15232
15700
|
default: 200,
|
|
15233
15701
|
appliesTo: optionAppliesTo("max-results"),
|
|
15234
|
-
summary: "impact and brief: maximum affected files, 1-1000 (default 200)."
|
|
15702
|
+
summary: "impact, guard and brief: maximum affected files, 1-1000 (default 200)."
|
|
15235
15703
|
},
|
|
15236
15704
|
{
|
|
15237
15705
|
flag: "--no-cache",
|
|
15238
15706
|
type: "boolean",
|
|
15239
15707
|
default: false,
|
|
15240
15708
|
appliesTo: optionAppliesTo("no-cache"),
|
|
15241
|
-
summary: "impact
|
|
15709
|
+
summary: "impact, guard and brief: bypass the OS live-index summary cache."
|
|
15242
15710
|
},
|
|
15243
15711
|
{
|
|
15244
15712
|
flag: "--no-live",
|
|
15245
15713
|
type: "boolean",
|
|
15246
15714
|
default: false,
|
|
15247
15715
|
appliesTo: optionAppliesTo("no-live"),
|
|
15248
|
-
summary: "impact
|
|
15716
|
+
summary: "impact, guard and brief: require the generated snapshot instead of using the live index."
|
|
15249
15717
|
},
|
|
15250
15718
|
{
|
|
15251
15719
|
flag: "--tests-paths",
|
|
@@ -15488,7 +15956,7 @@ function buildAgentContract() {
|
|
|
15488
15956
|
{
|
|
15489
15957
|
flag: "--port",
|
|
15490
15958
|
type: "string",
|
|
15491
|
-
default: "4789",
|
|
15959
|
+
default: "4789 (mcp) / 4788 (serve)",
|
|
15492
15960
|
appliesTo: optionAppliesTo("port"),
|
|
15493
15961
|
summary: "mcp --http: port to bind. 0 picks an ephemeral port and prints it."
|
|
15494
15962
|
},
|
|
@@ -15674,7 +16142,7 @@ function buildAgentContract() {
|
|
|
15674
16142
|
type: "string",
|
|
15675
16143
|
default: "generate",
|
|
15676
16144
|
appliesTo: optionAppliesTo("mode"),
|
|
15677
|
-
summary: "Select the command when no command word is given. Values: generate, validate, check, report, init, setup, explain, diff, describe, skill, mcp, health,
|
|
16145
|
+
summary: "Select the command when no command word is given. Values: generate, validate, check, report, impact, guard, brief, init, setup, explain, diff, describe, skill, mcp, health, update, serve. A command word and --mode must name the same command; a contradiction is a usage error (exit 2)."
|
|
15678
16146
|
},
|
|
15679
16147
|
{
|
|
15680
16148
|
flag: "--cwd",
|
|
@@ -15833,7 +16301,7 @@ function buildAgentContract() {
|
|
|
15833
16301
|
{ key: "maxParts", type: "number | null", default: null, summary: "Experimental: the most parts a snapshot may have. The per-part budget grows to fit, up to the run's own needs; the effective ceiling is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes." },
|
|
15834
16302
|
{ key: "attachmentSlots", type: "number", default: 10, summary: "Files the destination accepts in one message (0 = no limit); PROMPT.md plans the delivery to fit. It does not change the payload, and it is not part of the config digest." },
|
|
15835
16303
|
{ key: "discovery", type: '"auto" | "git" | "walk"', default: "auto", summary: "How files are discovered; `walk` scans the tree and reads .gitignore directly when a .git directory cannot be listed." },
|
|
15836
|
-
{ key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
|
|
16304
|
+
{ key: "artifacts", type: "object", default: "all on except monolith, diff, log and tokenTree", summary: "Per-artifact opt-out." },
|
|
15837
16305
|
{ key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
|
|
15838
16306
|
{ key: "layersMode", type: '"merge" | "replace"', default: "merge", summary: "Whether custom layers extend or replace the preset's." },
|
|
15839
16307
|
{ key: "layers", type: "array", default: "preset layers", summary: "Custom layer rules (glob or RegExp)." },
|
|
@@ -16169,7 +16637,7 @@ async function workspaceFor(context) {
|
|
|
16169
16637
|
}
|
|
16170
16638
|
function readFileIfPresent(file) {
|
|
16171
16639
|
try {
|
|
16172
|
-
return
|
|
16640
|
+
return fs18__namespace.readFileSync(file, "utf8");
|
|
16173
16641
|
} catch {
|
|
16174
16642
|
return null;
|
|
16175
16643
|
}
|
|
@@ -16213,7 +16681,7 @@ function buildResourceProvider() {
|
|
|
16213
16681
|
const read = readManifest2(workspace);
|
|
16214
16682
|
if (!read.ok) return resources;
|
|
16215
16683
|
for (const [uri, report] of REPORT_URIS) {
|
|
16216
|
-
const present = reportsDir !== null &&
|
|
16684
|
+
const present = reportsDir !== null && fs18__namespace.existsSync(path7__namespace.join(reportsDir, report.file));
|
|
16217
16685
|
if (!present) continue;
|
|
16218
16686
|
resources.push({
|
|
16219
16687
|
uri,
|
|
@@ -16354,7 +16822,7 @@ function buildResourceProvider() {
|
|
|
16354
16822
|
}
|
|
16355
16823
|
let partBytes;
|
|
16356
16824
|
try {
|
|
16357
|
-
partBytes =
|
|
16825
|
+
partBytes = fs18__namespace.statSync(partPath).size;
|
|
16358
16826
|
} catch {
|
|
16359
16827
|
throw new ResourceNotFoundError(uri, part.filename + " is missing from this snapshot.");
|
|
16360
16828
|
}
|
|
@@ -16392,41 +16860,41 @@ function validateArguments(schema, value) {
|
|
|
16392
16860
|
}
|
|
16393
16861
|
return problems;
|
|
16394
16862
|
}
|
|
16395
|
-
function checkValue(
|
|
16863
|
+
function checkValue(path22, schema, value) {
|
|
16396
16864
|
if (schema.enum && !schema.enum.includes(value)) {
|
|
16397
|
-
return [`"${
|
|
16865
|
+
return [`"${path22}" must be one of: ${schema.enum.join(", ")}`];
|
|
16398
16866
|
}
|
|
16399
16867
|
const declared = schema.type === void 0 ? [] : Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
16400
16868
|
if (declared.length > 0 && !declared.some((type) => matchesType(type, value))) {
|
|
16401
16869
|
if (declared.length === 1 && declared[0] === "integer" && typeof value !== "number") {
|
|
16402
|
-
return [`"${
|
|
16870
|
+
return [`"${path22}" must be a number`];
|
|
16403
16871
|
}
|
|
16404
16872
|
const article = (type) => type === "integer" || type === "object" || type === "array" ? `an ${type}` : `a ${type}`;
|
|
16405
|
-
return [`"${
|
|
16873
|
+
return [`"${path22}" must be ${declared.map(article).join(" or ")}`];
|
|
16406
16874
|
}
|
|
16407
16875
|
const problems = [];
|
|
16408
16876
|
if (declared.includes("string") && typeof value === "string") {
|
|
16409
16877
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
16410
|
-
problems.push(`"${
|
|
16878
|
+
problems.push(`"${path22}" must be at least ${schema.minLength} character(s)`);
|
|
16411
16879
|
}
|
|
16412
16880
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
16413
|
-
problems.push(`"${
|
|
16881
|
+
problems.push(`"${path22}" must be at most ${schema.maxLength} character(s)`);
|
|
16414
16882
|
}
|
|
16415
16883
|
}
|
|
16416
16884
|
if ((declared.includes("number") || declared.includes("integer")) && typeof value === "number" && !Number.isNaN(value)) {
|
|
16417
16885
|
if (declared.includes("integer") && !declared.includes("number") && !Number.isInteger(value)) {
|
|
16418
|
-
problems.push(`"${
|
|
16886
|
+
problems.push(`"${path22}" must be an integer`);
|
|
16419
16887
|
}
|
|
16420
16888
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
16421
|
-
problems.push(`"${
|
|
16889
|
+
problems.push(`"${path22}" must be >= ${schema.minimum}`);
|
|
16422
16890
|
}
|
|
16423
16891
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
16424
|
-
problems.push(`"${
|
|
16892
|
+
problems.push(`"${path22}" must be <= ${schema.maximum}`);
|
|
16425
16893
|
}
|
|
16426
16894
|
}
|
|
16427
16895
|
if (declared.includes("array") && Array.isArray(value) && schema.items) {
|
|
16428
16896
|
value.forEach((item, index) => {
|
|
16429
|
-
problems.push(...checkValue(`${
|
|
16897
|
+
problems.push(...checkValue(`${path22}[${index}]`, schema.items, item));
|
|
16430
16898
|
});
|
|
16431
16899
|
}
|
|
16432
16900
|
return problems;
|
|
@@ -16506,10 +16974,10 @@ function createMcpServer(options) {
|
|
|
16506
16974
|
if (method === "notifications/cancelled") {
|
|
16507
16975
|
const requestId2 = params?.requestId;
|
|
16508
16976
|
if (typeof requestId2 === "string" || typeof requestId2 === "number") {
|
|
16509
|
-
const
|
|
16510
|
-
if (
|
|
16977
|
+
const pending = cancellations.get(requestId2);
|
|
16978
|
+
if (pending !== void 0) {
|
|
16511
16979
|
cancellations.delete(requestId2);
|
|
16512
|
-
cancel();
|
|
16980
|
+
for (const cancel of pending) cancel();
|
|
16513
16981
|
}
|
|
16514
16982
|
}
|
|
16515
16983
|
}
|
|
@@ -16590,7 +17058,13 @@ function createMcpServer(options) {
|
|
|
16590
17058
|
...options.context,
|
|
16591
17059
|
// Always offered, so a long tool can be stopped whether or not the client asked for progress.
|
|
16592
17060
|
onCancel: (cancel) => {
|
|
16593
|
-
|
|
17061
|
+
registeredCancel = cancel;
|
|
17062
|
+
let pending = cancellations.get(id);
|
|
17063
|
+
if (pending === void 0) {
|
|
17064
|
+
pending = /* @__PURE__ */ new Set();
|
|
17065
|
+
cancellations.set(id, pending);
|
|
17066
|
+
}
|
|
17067
|
+
pending.add(cancel);
|
|
16594
17068
|
},
|
|
16595
17069
|
...progressToken === void 0 || options.notify === void 0 ? {} : {
|
|
16596
17070
|
notify: (event) => {
|
|
@@ -16605,6 +17079,7 @@ function createMcpServer(options) {
|
|
|
16605
17079
|
}
|
|
16606
17080
|
};
|
|
16607
17081
|
let outcome;
|
|
17082
|
+
let registeredCancel;
|
|
16608
17083
|
try {
|
|
16609
17084
|
outcome = await tool.handler(args, callContext);
|
|
16610
17085
|
} catch (error) {
|
|
@@ -16616,7 +17091,13 @@ function createMcpServer(options) {
|
|
|
16616
17091
|
modern
|
|
16617
17092
|
);
|
|
16618
17093
|
} finally {
|
|
16619
|
-
|
|
17094
|
+
if (registeredCancel !== void 0) {
|
|
17095
|
+
const pending = cancellations.get(id);
|
|
17096
|
+
if (pending !== void 0) {
|
|
17097
|
+
pending.delete(registeredCancel);
|
|
17098
|
+
if (pending.size === 0) cancellations.delete(id);
|
|
17099
|
+
}
|
|
17100
|
+
}
|
|
16620
17101
|
}
|
|
16621
17102
|
return ok(
|
|
16622
17103
|
id,
|