codebase-snapshot 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +225 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +412 -92
- package/dist/{chunk-NESEHOPU.js → chunk-4OHQULCV.js} +41 -1
- package/dist/{chunk-BOJYZQFB.js → chunk-KHHUC6UT.js} +364 -92
- package/dist/cli.cjs +410 -92
- package/dist/cli.d.cts +11 -1
- package/dist/cli.d.ts +11 -1
- package/dist/cli.js +9 -3
- package/dist/index.cjs +364 -92
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +404 -92
- package/dist/mcp.d.cts +6 -15
- package/dist/mcp.d.ts +6 -15
- package/dist/mcp.js +2 -2
- package/dist/{types-CbD8yQRZ.d.cts → types-5G2Q6tWP.d.cts} +4 -0
- package/dist/{types-CbD8yQRZ.d.ts → types-5G2Q6tWP.d.ts} +4 -0
- package/docs/benchmarks.md +54 -9
- package/docs/cli.md +6 -4
- package/docs/deploy.md +2 -2
- package/docs/health.md +31 -0
- package/docs/mcp.md +9 -5
- package/docs/tools.md +3 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer, buildTools, GENERATOR_VERSION } from './chunk-
|
|
1
|
+
import { createServer, buildTools, GENERATOR_VERSION } from './chunk-KHHUC6UT.js';
|
|
2
2
|
import * as http from 'http';
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
4
|
|
|
@@ -49,12 +49,23 @@ async function startHttpTransport(options) {
|
|
|
49
49
|
return fromQuery !== null && timingSafeEqual2(fromQuery, token);
|
|
50
50
|
};
|
|
51
51
|
const sessions = /* @__PURE__ */ new Map();
|
|
52
|
+
const metrics = {
|
|
53
|
+
requests: 0,
|
|
54
|
+
byMethod: /* @__PURE__ */ new Map(),
|
|
55
|
+
refused: 0,
|
|
56
|
+
rateLimited: 0};
|
|
57
|
+
const noteRequest = (request) => {
|
|
58
|
+
metrics.requests += 1;
|
|
59
|
+
const method = request.method ?? "UNKNOWN";
|
|
60
|
+
metrics.byMethod.set(method, (metrics.byMethod.get(method) ?? 0) + 1);
|
|
61
|
+
};
|
|
52
62
|
const allowedOrigin = (origin) => {
|
|
53
63
|
if (origin === void 0) return null;
|
|
54
64
|
if (isLoopbackOrigin(origin)) return origin;
|
|
55
65
|
return extraOrigins.includes(origin) ? origin : null;
|
|
56
66
|
};
|
|
57
67
|
const httpServer = http.createServer((request, response) => {
|
|
68
|
+
noteRequest(request);
|
|
58
69
|
const send = (status, body, extra = {}) => {
|
|
59
70
|
const text = typeof body === "string" ? body : JSON.stringify(body);
|
|
60
71
|
response.writeHead(status, {
|
|
@@ -68,6 +79,7 @@ async function startHttpTransport(options) {
|
|
|
68
79
|
const origin = typeof request.headers.origin === "string" ? request.headers.origin : void 0;
|
|
69
80
|
const allowed = allowedOrigin(origin);
|
|
70
81
|
if (origin !== void 0 && allowed === null) {
|
|
82
|
+
metrics.refused += 1;
|
|
71
83
|
send(403, { error: "origin not allowed" });
|
|
72
84
|
return;
|
|
73
85
|
}
|
|
@@ -97,6 +109,33 @@ async function startHttpTransport(options) {
|
|
|
97
109
|
);
|
|
98
110
|
return;
|
|
99
111
|
}
|
|
112
|
+
if (request.method === "GET" && request.url === "/metrics") {
|
|
113
|
+
const lines = [
|
|
114
|
+
"# HELP snapshot_uptime_seconds Seconds since the process started.",
|
|
115
|
+
"# TYPE snapshot_uptime_seconds gauge",
|
|
116
|
+
"snapshot_uptime_seconds " + Math.round(process.uptime()),
|
|
117
|
+
"# HELP snapshot_requests_total HTTP requests received.",
|
|
118
|
+
"# TYPE snapshot_requests_total counter",
|
|
119
|
+
"snapshot_requests_total " + metrics.requests,
|
|
120
|
+
"# HELP snapshot_requests_refused_total Requests refused before dispatch.",
|
|
121
|
+
"# TYPE snapshot_requests_refused_total counter",
|
|
122
|
+
"snapshot_requests_refused_total " + metrics.refused,
|
|
123
|
+
"# HELP snapshot_requests_rate_limited_total Requests rejected by the rate limit.",
|
|
124
|
+
"# TYPE snapshot_requests_rate_limited_total counter",
|
|
125
|
+
"snapshot_requests_rate_limited_total " + metrics.rateLimited,
|
|
126
|
+
"# HELP snapshot_tools Number of tools this server serves.",
|
|
127
|
+
"# TYPE snapshot_tools gauge",
|
|
128
|
+
"snapshot_tools " + toolCount
|
|
129
|
+
];
|
|
130
|
+
for (const [method, count] of metrics.byMethod) {
|
|
131
|
+
lines.push('snapshot_requests_by_method_total{method="' + method + '"} ' + count);
|
|
132
|
+
}
|
|
133
|
+
send(200, lines.join("\n") + "\n", {
|
|
134
|
+
...cors,
|
|
135
|
+
"content-type": "text/plain; version=0.0.4; charset=utf-8"
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
100
139
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
101
140
|
if (request.method === "GET" && url.pathname === "/sse") {
|
|
102
141
|
if (!tokenAccepted(request, url)) {
|
|
@@ -188,6 +227,7 @@ async function startHttpTransport(options) {
|
|
|
188
227
|
const window = sessions.get(remote);
|
|
189
228
|
if (window === void 0 || window.resetAt <= now) sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
190
229
|
else if (window.count >= RATE_LIMIT) {
|
|
230
|
+
metrics.rateLimited += 1;
|
|
191
231
|
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
192
232
|
return;
|
|
193
233
|
} else window.count += 1;
|
|
@@ -3994,7 +3994,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
3994
3994
|
|
|
3995
3995
|
// src/version.ts
|
|
3996
3996
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3997
|
-
var GENERATOR_VERSION = "0.
|
|
3997
|
+
var GENERATOR_VERSION = "0.15.0";
|
|
3998
3998
|
var SCHEMA_VERSION = "3.0.0";
|
|
3999
3999
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
4000
4000
|
function isOurGeneratorName(name) {
|
|
@@ -5888,7 +5888,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5888
5888
|
logCount: resolveLogCount(
|
|
5889
5889
|
cliOptions?.logCount ?? cliOptions?.includeLogs ?? userConfig?.logCount
|
|
5890
5890
|
),
|
|
5891
|
-
|
|
5891
|
+
// `--only` replaces the allow-list for this run; `--ignore` adds to the deny-list. The two
|
|
5892
|
+
// directions are different on purpose: a narrower allow-list is a statement about the whole
|
|
5893
|
+
// run, while "also ignore this" is naturally cumulative with what the config already excludes.
|
|
5894
|
+
include: resolveInclude(
|
|
5895
|
+
cliOptions?.only ?? userConfig?.include
|
|
5896
|
+
),
|
|
5892
5897
|
preset: preset.presetName,
|
|
5893
5898
|
presetExclude,
|
|
5894
5899
|
artifacts,
|
|
@@ -5899,9 +5904,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5899
5904
|
kinds,
|
|
5900
5905
|
// `exclude` is the flag spelling of the same setting; writing it in a config used to
|
|
5901
5906
|
// be ignored without a word.
|
|
5902
|
-
excludePatterns:
|
|
5903
|
-
|
|
5904
|
-
|
|
5907
|
+
excludePatterns: [
|
|
5908
|
+
...resolveExcludePatterns(
|
|
5909
|
+
userConfig?.excludePatterns ?? userConfig?.exclude
|
|
5910
|
+
),
|
|
5911
|
+
...resolveExcludePatterns(cliOptions?.ignore)
|
|
5912
|
+
],
|
|
5905
5913
|
secretRules,
|
|
5906
5914
|
// Extra property rather than a `ResolvedSnapshotConfig` field: the resolved
|
|
5907
5915
|
// shape is owned elsewhere, and every scan reads it through the registry in
|
|
@@ -10039,6 +10047,92 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
10039
10047
|
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
10040
10048
|
}
|
|
10041
10049
|
|
|
10050
|
+
// src/partitioner/part-format.ts
|
|
10051
|
+
var FILE_HEADING = "### FILE: ";
|
|
10052
|
+
var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
|
|
10053
|
+
var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
|
|
10054
|
+
var META_PREFIX = "- Meta: ";
|
|
10055
|
+
var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
|
|
10056
|
+
var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
|
|
10057
|
+
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
|
|
10058
|
+
var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
|
|
10059
|
+
function readIncludedLines(fields) {
|
|
10060
|
+
const last = fields[fields.length - 1];
|
|
10061
|
+
if (last === void 0) return null;
|
|
10062
|
+
const counts = COMPACT_COUNTS.exec(last.trim());
|
|
10063
|
+
return counts === null ? null : Number(counts[1]);
|
|
10064
|
+
}
|
|
10065
|
+
function parsePartSections(partText) {
|
|
10066
|
+
const lines = partText.split("\n");
|
|
10067
|
+
const sections = [];
|
|
10068
|
+
let index = 0;
|
|
10069
|
+
while (index < lines.length) {
|
|
10070
|
+
if (!lines[index].startsWith(FILE_HEADING)) {
|
|
10071
|
+
index += 1;
|
|
10072
|
+
continue;
|
|
10073
|
+
}
|
|
10074
|
+
const heading = lines[index].slice(FILE_HEADING.length);
|
|
10075
|
+
const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
|
|
10076
|
+
let cursor = index + 1;
|
|
10077
|
+
let inclusion = null;
|
|
10078
|
+
let includedLines = null;
|
|
10079
|
+
while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
|
|
10080
|
+
const line = lines[cursor];
|
|
10081
|
+
if (line.startsWith(FILE_HEADING)) break;
|
|
10082
|
+
if (line.startsWith(META_PREFIX)) {
|
|
10083
|
+
const fields = line.slice(META_PREFIX.length).split("|");
|
|
10084
|
+
for (const field of fields) {
|
|
10085
|
+
const value = field.trim();
|
|
10086
|
+
if (INCLUSION_MODES.has(value)) inclusion = value;
|
|
10087
|
+
}
|
|
10088
|
+
includedLines = readIncludedLines(fields);
|
|
10089
|
+
} else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
|
|
10090
|
+
inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
|
|
10091
|
+
} else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
|
|
10092
|
+
const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
|
|
10093
|
+
includedLines = Number.isFinite(value) ? value : null;
|
|
10094
|
+
}
|
|
10095
|
+
cursor += 1;
|
|
10096
|
+
}
|
|
10097
|
+
if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
|
|
10098
|
+
index = cursor + 1;
|
|
10099
|
+
continue;
|
|
10100
|
+
}
|
|
10101
|
+
let fenceLine = cursor + 1;
|
|
10102
|
+
while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
|
|
10103
|
+
const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
|
|
10104
|
+
if (!fenceMatch) {
|
|
10105
|
+
index = cursor + 1;
|
|
10106
|
+
continue;
|
|
10107
|
+
}
|
|
10108
|
+
const fence = fenceMatch[1];
|
|
10109
|
+
const body = [];
|
|
10110
|
+
let bodyLine = fenceLine + 1;
|
|
10111
|
+
while (bodyLine < lines.length && lines[bodyLine] !== fence) {
|
|
10112
|
+
body.push(lines[bodyLine]);
|
|
10113
|
+
bodyLine += 1;
|
|
10114
|
+
}
|
|
10115
|
+
sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
|
|
10116
|
+
index = bodyLine + 1;
|
|
10117
|
+
}
|
|
10118
|
+
return sections;
|
|
10119
|
+
}
|
|
10120
|
+
function findSection(sections, relativePath) {
|
|
10121
|
+
const anchor = anchorForPath(relativePath);
|
|
10122
|
+
const byAnchor = sections.find((section) => section.anchor === anchor);
|
|
10123
|
+
if (byAnchor) return byAnchor;
|
|
10124
|
+
const rendered = displayPath(relativePath);
|
|
10125
|
+
const samePath = (section) => section.path === relativePath || section.path === rendered;
|
|
10126
|
+
const exact = sections.find(samePath);
|
|
10127
|
+
if (exact) return exact;
|
|
10128
|
+
const foldedPath = rendered.toLowerCase();
|
|
10129
|
+
const folded = sections.filter((section) => {
|
|
10130
|
+
const path26 = section.path.toLowerCase();
|
|
10131
|
+
return path26 === relativePath.toLowerCase() || path26 === foldedPath;
|
|
10132
|
+
});
|
|
10133
|
+
return folded.length === 1 ? folded[0] : null;
|
|
10134
|
+
}
|
|
10135
|
+
|
|
10042
10136
|
// src/auditor/health.ts
|
|
10043
10137
|
var ARTIFACT_FILES = {
|
|
10044
10138
|
readme: "README.md",
|
|
@@ -10348,6 +10442,206 @@ function auditSnapshot(options) {
|
|
|
10348
10442
|
)
|
|
10349
10443
|
);
|
|
10350
10444
|
}
|
|
10445
|
+
const bookkeeping = [];
|
|
10446
|
+
const expect = (name, recorded2, computed) => {
|
|
10447
|
+
if (recorded2 !== computed) bookkeeping.push(name + ": manifest says " + recorded2 + ", the data has " + computed);
|
|
10448
|
+
};
|
|
10449
|
+
expect("counts.totalFiles", manifest.counts.totalFiles, manifest.files.length);
|
|
10450
|
+
expect("counts.partsCount", manifest.counts.partsCount, manifest.parts.length);
|
|
10451
|
+
expect("counts.skippedCount", manifest.counts.skippedCount, manifest.skipped.length);
|
|
10452
|
+
if (typeof manifest.totals.includedFiles === "number") {
|
|
10453
|
+
expect("totals.includedFiles", manifest.totals.includedFiles, manifest.files.length);
|
|
10454
|
+
}
|
|
10455
|
+
const contentBytes = manifest.files.reduce((sum, file) => sum + file.includedBytes, 0);
|
|
10456
|
+
expect("totals.totalContentBytes", manifest.totals.totalContentBytes, contentBytes);
|
|
10457
|
+
const layerCounts = /* @__PURE__ */ new Map();
|
|
10458
|
+
for (const file of manifest.files) layerCounts.set(file.layer, (layerCounts.get(file.layer) ?? 0) + 1);
|
|
10459
|
+
for (const [layer2, count] of layerCounts) {
|
|
10460
|
+
expect("layers." + layer2, manifest.layers[layer2] ?? -1, count);
|
|
10461
|
+
}
|
|
10462
|
+
for (const layer2 of Object.keys(manifest.layers)) {
|
|
10463
|
+
if (!layerCounts.has(layer2)) expect("layers." + layer2, manifest.layers[layer2], 0);
|
|
10464
|
+
}
|
|
10465
|
+
checks.push(
|
|
10466
|
+
bookkeeping.length === 0 ? check(
|
|
10467
|
+
"bookkeeping",
|
|
10468
|
+
"The counts equal the data they summarise",
|
|
10469
|
+
"critical",
|
|
10470
|
+
"pass",
|
|
10471
|
+
"Files, parts, skips, content bytes and layer counts all agree."
|
|
10472
|
+
) : check(
|
|
10473
|
+
"bookkeeping",
|
|
10474
|
+
"The counts equal the data they summarise",
|
|
10475
|
+
"critical",
|
|
10476
|
+
"fail",
|
|
10477
|
+
bookkeeping.length + " mismatch(es): " + sample(bookkeeping)
|
|
10478
|
+
)
|
|
10479
|
+
);
|
|
10480
|
+
const packReaders = [
|
|
10481
|
+
{
|
|
10482
|
+
key: "fullJson",
|
|
10483
|
+
file: "full-codebase.json",
|
|
10484
|
+
label: "JSON",
|
|
10485
|
+
paths: (text2) => {
|
|
10486
|
+
try {
|
|
10487
|
+
const parsed = JSON.parse(text2);
|
|
10488
|
+
if (!Array.isArray(parsed?.files)) return null;
|
|
10489
|
+
return new Set(parsed.files.map((entry) => String(entry?.relativePath)));
|
|
10490
|
+
} catch {
|
|
10491
|
+
return null;
|
|
10492
|
+
}
|
|
10493
|
+
}
|
|
10494
|
+
},
|
|
10495
|
+
{
|
|
10496
|
+
key: "fullXml",
|
|
10497
|
+
file: "full-codebase.xml",
|
|
10498
|
+
label: "XML",
|
|
10499
|
+
paths: (text2) => {
|
|
10500
|
+
const found = [...text2.matchAll(/<file path="([^"]+)"/g)].map((match) => match[1]);
|
|
10501
|
+
if (found.length === 0) return null;
|
|
10502
|
+
return new Set(found.map((value) => value.replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")));
|
|
10503
|
+
}
|
|
10504
|
+
},
|
|
10505
|
+
{
|
|
10506
|
+
key: "fullMarkdown",
|
|
10507
|
+
file: "full-codebase.md",
|
|
10508
|
+
label: "markdown",
|
|
10509
|
+
paths: (text2) => {
|
|
10510
|
+
const found = [...text2.matchAll(/^## File: (.+)$/gm)].map((match) => match[1].trim());
|
|
10511
|
+
if (found.length === 0) return null;
|
|
10512
|
+
return new Set(found);
|
|
10513
|
+
}
|
|
10514
|
+
}
|
|
10515
|
+
];
|
|
10516
|
+
for (const reader of packReaders) {
|
|
10517
|
+
if (manifest.artifacts?.[reader.key] == null) continue;
|
|
10518
|
+
const packText = readText2(path25.join(snapshotDir, reader.file));
|
|
10519
|
+
const problems = [];
|
|
10520
|
+
if (packText === null) {
|
|
10521
|
+
problems.push(reader.file + " is recorded but unreadable");
|
|
10522
|
+
} else {
|
|
10523
|
+
const packed = reader.paths(packText);
|
|
10524
|
+
if (packed === null) {
|
|
10525
|
+
problems.push(reader.file + " could not be parsed for its file list");
|
|
10526
|
+
} else {
|
|
10527
|
+
const known2 = new Set(manifest.files.map((file) => file.relativePath));
|
|
10528
|
+
for (const file of manifest.files) {
|
|
10529
|
+
if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
|
|
10530
|
+
}
|
|
10531
|
+
for (const path26 of packed) {
|
|
10532
|
+
if (!known2.has(path26)) problems.push(path26 + " is in the pack but not the manifest");
|
|
10533
|
+
}
|
|
10534
|
+
}
|
|
10535
|
+
}
|
|
10536
|
+
const title = "The " + reader.label + " pack holds every file the manifest lists";
|
|
10537
|
+
checks.push(
|
|
10538
|
+
problems.length === 0 ? check(
|
|
10539
|
+
"pipeline.monolith",
|
|
10540
|
+
title,
|
|
10541
|
+
"critical",
|
|
10542
|
+
"pass",
|
|
10543
|
+
manifest.files.length + " file(s) present in " + reader.file + ", and nothing extra."
|
|
10544
|
+
) : check(
|
|
10545
|
+
"pipeline.monolith",
|
|
10546
|
+
title,
|
|
10547
|
+
"critical",
|
|
10548
|
+
"fail",
|
|
10549
|
+
problems.length + " problem(s): " + sample(problems)
|
|
10550
|
+
)
|
|
10551
|
+
);
|
|
10552
|
+
}
|
|
10553
|
+
const bodyProblems = [];
|
|
10554
|
+
let bodiesChecked = 0;
|
|
10555
|
+
for (const part of manifest.parts) {
|
|
10556
|
+
const partText = readText2(path25.join(snapshotDir, "parts", part.filename));
|
|
10557
|
+
if (partText === null) continue;
|
|
10558
|
+
const sections = parsePartSections(partText);
|
|
10559
|
+
for (const file of manifest.files) {
|
|
10560
|
+
if (file.part !== part.filename) continue;
|
|
10561
|
+
const section = findSection(sections, file.relativePath);
|
|
10562
|
+
if (section === null) {
|
|
10563
|
+
bodyProblems.push(file.relativePath + " has no section in " + part.filename);
|
|
10564
|
+
continue;
|
|
10565
|
+
}
|
|
10566
|
+
bodiesChecked += 1;
|
|
10567
|
+
const bytes = Buffer.byteLength(section.body, "utf8");
|
|
10568
|
+
const bodyLines = section.body === "" ? 0 : section.body.split("\n").length - (section.body.endsWith("\n") ? 1 : 0);
|
|
10569
|
+
if (bytes !== file.includedBytes) {
|
|
10570
|
+
bodyProblems.push(file.relativePath + ": manifest says " + file.includedBytes + " B, part holds " + bytes + " B");
|
|
10571
|
+
} else if (bodyLines !== file.includedLines) {
|
|
10572
|
+
bodyProblems.push(file.relativePath + ": manifest says " + file.includedLines + " line(s), part holds " + bodyLines);
|
|
10573
|
+
}
|
|
10574
|
+
}
|
|
10575
|
+
}
|
|
10576
|
+
checks.push(
|
|
10577
|
+
bodyProblems.length === 0 ? check(
|
|
10578
|
+
"pipeline.bodies",
|
|
10579
|
+
"Every file body matches the manifest accounting",
|
|
10580
|
+
"critical",
|
|
10581
|
+
"pass",
|
|
10582
|
+
bodiesChecked + " file body/bodies match their recorded bytes and lines."
|
|
10583
|
+
) : check(
|
|
10584
|
+
"pipeline.bodies",
|
|
10585
|
+
"Every file body matches the manifest accounting",
|
|
10586
|
+
"critical",
|
|
10587
|
+
"fail",
|
|
10588
|
+
bodyProblems.length + " file(s) disagree: " + sample(bodyProblems)
|
|
10589
|
+
)
|
|
10590
|
+
);
|
|
10591
|
+
const indexParent = path25.dirname(snapshotDir);
|
|
10592
|
+
const indexPath = path25.join(indexParent, "WORKSPACE.json");
|
|
10593
|
+
if (fs24.existsSync(indexPath)) {
|
|
10594
|
+
const indexText = readText2(indexPath);
|
|
10595
|
+
let members = [];
|
|
10596
|
+
let problem2 = null;
|
|
10597
|
+
try {
|
|
10598
|
+
const parsed = JSON.parse(indexText ?? "null");
|
|
10599
|
+
if (!Array.isArray(parsed?.members)) problem2 = "its members field is not an array";
|
|
10600
|
+
else members = parsed.members;
|
|
10601
|
+
} catch (error) {
|
|
10602
|
+
problem2 = error.message;
|
|
10603
|
+
}
|
|
10604
|
+
const memberName = path25.basename(snapshotDir);
|
|
10605
|
+
const member = members.find((entry) => entry.name === memberName);
|
|
10606
|
+
if (problem2 !== null) {
|
|
10607
|
+
checks.push(check(
|
|
10608
|
+
"workspace.index",
|
|
10609
|
+
"The workspace index agrees with this member",
|
|
10610
|
+
"warning",
|
|
10611
|
+
"warn",
|
|
10612
|
+
"WORKSPACE.json could not be read: " + problem2
|
|
10613
|
+
));
|
|
10614
|
+
} else if (member === void 0) {
|
|
10615
|
+
checks.push(check(
|
|
10616
|
+
"workspace.index",
|
|
10617
|
+
"The workspace index agrees with this member",
|
|
10618
|
+
"warning",
|
|
10619
|
+
"skip",
|
|
10620
|
+
"WORKSPACE.json lists no member named " + memberName + "."
|
|
10621
|
+
));
|
|
10622
|
+
} else {
|
|
10623
|
+
const disagreements = [];
|
|
10624
|
+
if (member.fingerprint !== manifest.fingerprint) disagreements.push("fingerprint");
|
|
10625
|
+
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
10626
|
+
disagreements.push("file count");
|
|
10627
|
+
}
|
|
10628
|
+
checks.push(
|
|
10629
|
+
disagreements.length === 0 ? check(
|
|
10630
|
+
"workspace.index",
|
|
10631
|
+
"The workspace index agrees with this member",
|
|
10632
|
+
"warning",
|
|
10633
|
+
"pass",
|
|
10634
|
+
"Member " + memberName + " matches the index fingerprint and file count."
|
|
10635
|
+
) : check(
|
|
10636
|
+
"workspace.index",
|
|
10637
|
+
"The workspace index agrees with this member",
|
|
10638
|
+
"warning",
|
|
10639
|
+
"warn",
|
|
10640
|
+
"The index disagrees with this member on: " + disagreements.join(", ") + ". Regenerate the workspace."
|
|
10641
|
+
)
|
|
10642
|
+
);
|
|
10643
|
+
}
|
|
10644
|
+
}
|
|
10351
10645
|
const rules = [...compileSecretRules(DEFAULT_SECRET_PATTERNS), ...options.secretRules ?? []];
|
|
10352
10646
|
const scanBudget = options.maxScanBytes ?? 32 * 1024 * 1024;
|
|
10353
10647
|
const leakHits = [];
|
|
@@ -10859,90 +11153,6 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
10859
11153
|
}
|
|
10860
11154
|
|
|
10861
11155
|
// src/mcp/part.ts
|
|
10862
|
-
var FILE_HEADING = "### FILE: ";
|
|
10863
|
-
var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
|
|
10864
|
-
var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
|
|
10865
|
-
var META_PREFIX = "- Meta: ";
|
|
10866
|
-
var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
|
|
10867
|
-
var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
|
|
10868
|
-
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
|
|
10869
|
-
var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
|
|
10870
|
-
function readIncludedLines(fields) {
|
|
10871
|
-
const last = fields[fields.length - 1];
|
|
10872
|
-
if (last === void 0) return null;
|
|
10873
|
-
const counts = COMPACT_COUNTS.exec(last.trim());
|
|
10874
|
-
return counts === null ? null : Number(counts[1]);
|
|
10875
|
-
}
|
|
10876
|
-
function parsePartSections(partText) {
|
|
10877
|
-
const lines = partText.split("\n");
|
|
10878
|
-
const sections = [];
|
|
10879
|
-
let index = 0;
|
|
10880
|
-
while (index < lines.length) {
|
|
10881
|
-
if (!lines[index].startsWith(FILE_HEADING)) {
|
|
10882
|
-
index += 1;
|
|
10883
|
-
continue;
|
|
10884
|
-
}
|
|
10885
|
-
const heading = lines[index].slice(FILE_HEADING.length);
|
|
10886
|
-
const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
|
|
10887
|
-
let cursor = index + 1;
|
|
10888
|
-
let inclusion = null;
|
|
10889
|
-
let includedLines = null;
|
|
10890
|
-
while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
|
|
10891
|
-
const line = lines[cursor];
|
|
10892
|
-
if (line.startsWith(FILE_HEADING)) break;
|
|
10893
|
-
if (line.startsWith(META_PREFIX)) {
|
|
10894
|
-
const fields = line.slice(META_PREFIX.length).split("|");
|
|
10895
|
-
for (const field of fields) {
|
|
10896
|
-
const value = field.trim();
|
|
10897
|
-
if (INCLUSION_MODES.has(value)) inclusion = value;
|
|
10898
|
-
}
|
|
10899
|
-
includedLines = readIncludedLines(fields);
|
|
10900
|
-
} else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
|
|
10901
|
-
inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
|
|
10902
|
-
} else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
|
|
10903
|
-
const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
|
|
10904
|
-
includedLines = Number.isFinite(value) ? value : null;
|
|
10905
|
-
}
|
|
10906
|
-
cursor += 1;
|
|
10907
|
-
}
|
|
10908
|
-
if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
|
|
10909
|
-
index = cursor + 1;
|
|
10910
|
-
continue;
|
|
10911
|
-
}
|
|
10912
|
-
let fenceLine = cursor + 1;
|
|
10913
|
-
while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
|
|
10914
|
-
const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
|
|
10915
|
-
if (!fenceMatch) {
|
|
10916
|
-
index = cursor + 1;
|
|
10917
|
-
continue;
|
|
10918
|
-
}
|
|
10919
|
-
const fence = fenceMatch[1];
|
|
10920
|
-
const body = [];
|
|
10921
|
-
let bodyLine = fenceLine + 1;
|
|
10922
|
-
while (bodyLine < lines.length && lines[bodyLine] !== fence) {
|
|
10923
|
-
body.push(lines[bodyLine]);
|
|
10924
|
-
bodyLine += 1;
|
|
10925
|
-
}
|
|
10926
|
-
sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
|
|
10927
|
-
index = bodyLine + 1;
|
|
10928
|
-
}
|
|
10929
|
-
return sections;
|
|
10930
|
-
}
|
|
10931
|
-
function findSection(sections, relativePath) {
|
|
10932
|
-
const anchor = anchorForPath(relativePath);
|
|
10933
|
-
const byAnchor = sections.find((section) => section.anchor === anchor);
|
|
10934
|
-
if (byAnchor) return byAnchor;
|
|
10935
|
-
const rendered = displayPath(relativePath);
|
|
10936
|
-
const samePath = (section) => section.path === relativePath || section.path === rendered;
|
|
10937
|
-
const exact = sections.find(samePath);
|
|
10938
|
-
if (exact) return exact;
|
|
10939
|
-
const foldedPath = rendered.toLowerCase();
|
|
10940
|
-
const folded = sections.filter((section) => {
|
|
10941
|
-
const path26 = section.path.toLowerCase();
|
|
10942
|
-
return path26 === relativePath.toLowerCase() || path26 === foldedPath;
|
|
10943
|
-
});
|
|
10944
|
-
return folded.length === 1 ? folded[0] : null;
|
|
10945
|
-
}
|
|
10946
11156
|
function windowText(body, fromLine, lineCount) {
|
|
10947
11157
|
const lines = body.split("\n");
|
|
10948
11158
|
const total = body.length === 0 ? 0 : lines.length;
|
|
@@ -12060,6 +12270,11 @@ var symbolTool = {
|
|
|
12060
12270
|
name: { type: "string", description: "Symbol name, case-insensitive." },
|
|
12061
12271
|
lines: { type: "integer", description: "Window size around the definition (default 40).", minimum: 5 },
|
|
12062
12272
|
maxFiles: { type: "integer", description: "Cap on files searched (default 5).", minimum: 1 },
|
|
12273
|
+
references: {
|
|
12274
|
+
type: "boolean",
|
|
12275
|
+
description: "Also report call sites: other files whose body mentions the name (default true)."
|
|
12276
|
+
},
|
|
12277
|
+
maxReferences: { type: "integer", description: "Cap on reported call sites (default 20).", minimum: 1 },
|
|
12063
12278
|
root: ROOT_PROPERTY,
|
|
12064
12279
|
outDir: OUT_DIR_PROPERTY
|
|
12065
12280
|
},
|
|
@@ -12070,7 +12285,8 @@ var symbolTool = {
|
|
|
12070
12285
|
type: "object",
|
|
12071
12286
|
properties: {
|
|
12072
12287
|
found: { type: "integer" },
|
|
12073
|
-
matches: { type: "array", items: { type: "object" } }
|
|
12288
|
+
matches: { type: "array", items: { type: "object" } },
|
|
12289
|
+
references: { type: "array", items: { type: "object" } }
|
|
12074
12290
|
}
|
|
12075
12291
|
},
|
|
12076
12292
|
annotations: READ_ONLY,
|
|
@@ -12123,8 +12339,44 @@ var symbolTool = {
|
|
|
12123
12339
|
structured: { found: 0, matches: [] }
|
|
12124
12340
|
};
|
|
12125
12341
|
}
|
|
12126
|
-
const
|
|
12127
|
-
|
|
12342
|
+
const callSites = [];
|
|
12343
|
+
if (args.references !== false) {
|
|
12344
|
+
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
12345
|
+
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
12346
|
+
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
12347
|
+
const parts = /* @__PURE__ */ new Map();
|
|
12348
|
+
let scanned = 0;
|
|
12349
|
+
for (const file of read.manifest.files) {
|
|
12350
|
+
if (callSites.length >= limit) break;
|
|
12351
|
+
const partPath = partPathFor(workspace, file.part);
|
|
12352
|
+
if (partPath === null) continue;
|
|
12353
|
+
let partText = parts.get(partPath);
|
|
12354
|
+
if (partText === void 0) {
|
|
12355
|
+
try {
|
|
12356
|
+
partText = fs24.readFileSync(partPath, "utf8");
|
|
12357
|
+
} catch {
|
|
12358
|
+
continue;
|
|
12359
|
+
}
|
|
12360
|
+
parts.set(partPath, partText);
|
|
12361
|
+
}
|
|
12362
|
+
if (scanned > MAX_SEARCH_BYTES) break;
|
|
12363
|
+
scanned += Buffer.byteLength(partText, "utf8");
|
|
12364
|
+
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
12365
|
+
if (section === null) continue;
|
|
12366
|
+
const bodyLines = section.body.split("\n");
|
|
12367
|
+
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
12368
|
+
if (!word.test(bodyLines[index])) continue;
|
|
12369
|
+
callSites.push({
|
|
12370
|
+
path: file.relativePath,
|
|
12371
|
+
line: index + 1,
|
|
12372
|
+
text: bodyLines[index].trim().slice(0, 200),
|
|
12373
|
+
definition: definitionKeys.has(file.relativePath + ":" + (index + 1))
|
|
12374
|
+
});
|
|
12375
|
+
}
|
|
12376
|
+
}
|
|
12377
|
+
}
|
|
12378
|
+
const text2 = matches.map((match) => "### " + match.path + " (" + match.part + ", line " + match.line + ")\n" + match.text).join("\n\n") + (args.references === false ? "" : "\n\n" + (callSites.length === 0 ? "No call site was found in the snapshot." : "Call sites (" + callSites.length + "):\n" + callSites.map((site) => " " + site.path + ":" + site.line + " " + site.text).join("\n")));
|
|
12379
|
+
return { text: text2, structured: { found: matches.length, matches, references: callSites } };
|
|
12128
12380
|
}
|
|
12129
12381
|
};
|
|
12130
12382
|
var contextTool = {
|
|
@@ -13428,6 +13680,8 @@ var VALIDATE_OPTIONS = [
|
|
|
13428
13680
|
"sarif",
|
|
13429
13681
|
"strip-comments",
|
|
13430
13682
|
"remove-empty-lines",
|
|
13683
|
+
"only",
|
|
13684
|
+
"ignore",
|
|
13431
13685
|
"pack",
|
|
13432
13686
|
// The opt-in reports change the artifact selection the manifest records, so validate must accept
|
|
13433
13687
|
// them to compare like with like: without the flags it reports the selection as drift.
|
|
@@ -13463,6 +13717,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13463
13717
|
generate: [
|
|
13464
13718
|
"strip-comments",
|
|
13465
13719
|
"remove-empty-lines",
|
|
13720
|
+
"only",
|
|
13721
|
+
"ignore",
|
|
13466
13722
|
"workspace",
|
|
13467
13723
|
"budget-tokens",
|
|
13468
13724
|
"sign",
|
|
@@ -13543,6 +13799,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13543
13799
|
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
13544
13800
|
// this table exists to prevent.
|
|
13545
13801
|
"large-file-bytes",
|
|
13802
|
+
// `--only` and `--ignore` change which files are scanned, so they change what `explain` can say
|
|
13803
|
+
// about a path; without them the answer for an ignored file is "included: true".
|
|
13804
|
+
"only",
|
|
13805
|
+
"ignore",
|
|
13546
13806
|
"include-sensitive-files",
|
|
13547
13807
|
"no-config",
|
|
13548
13808
|
"discovery",
|
|
@@ -14084,6 +14344,18 @@ function buildAgentContract() {
|
|
|
14084
14344
|
appliesTo: optionAppliesTo("allow-origin"),
|
|
14085
14345
|
summary: "mcp --http: comma-separated extra CORS origins. Loopback origins are always allowed."
|
|
14086
14346
|
},
|
|
14347
|
+
{
|
|
14348
|
+
flag: "--only",
|
|
14349
|
+
type: "string",
|
|
14350
|
+
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
14351
|
+
appliesTo: optionAppliesTo("only")
|
|
14352
|
+
},
|
|
14353
|
+
{
|
|
14354
|
+
flag: "--ignore",
|
|
14355
|
+
type: "string",
|
|
14356
|
+
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
14357
|
+
appliesTo: optionAppliesTo("ignore")
|
|
14358
|
+
},
|
|
14087
14359
|
{
|
|
14088
14360
|
flag: "--remove-empty-lines",
|
|
14089
14361
|
type: "boolean",
|