cverdict-mcp 0.1.6 → 0.2.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.
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import process$1 from "node:process";
3
+ import { lstatSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
4
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
5
  // node_modules/@modelcontextprotocol/server/dist/chunk-vYduTEsO.mjs
4
6
  var __create = Object.create;
5
7
  var __defProp = Object.defineProperty;
@@ -5006,12 +5008,12 @@ var initializer = (inst, issues) => {
5006
5008
  };
5007
5009
  var ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
5008
5010
  // node_modules/zod/v4/classic/parse.js
5009
- var parse$1 = /* @__PURE__ */ _parse(ZodRealError);
5011
+ var parse$2 = /* @__PURE__ */ _parse(ZodRealError);
5010
5012
  var parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
5011
5013
  var safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
5012
5014
  var safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
5013
5015
  var encode = /* @__PURE__ */ _encode(ZodRealError);
5014
- var decode = /* @__PURE__ */ _decode(ZodRealError);
5016
+ var decode$1 = /* @__PURE__ */ _decode(ZodRealError);
5015
5017
  var encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
5016
5018
  var decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
5017
5019
  var safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
@@ -5137,7 +5139,7 @@ var ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
5137
5139
  own(this, "~standard", value);
5138
5140
  },
5139
5141
  parse: function _parse(data, params) {
5140
- return parse$1(this, data, params, { callee: _parse });
5142
+ return parse$2(this, data, params, { callee: _parse });
5141
5143
  },
5142
5144
  parseAsync: async function _parseAsync(data, params) {
5143
5145
  return await parseAsync(this, data, params, { callee: _parseAsync });
@@ -5164,7 +5166,7 @@ var ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
5164
5166
  return encode(this, data, params, { callee: _encode });
5165
5167
  },
5166
5168
  decode: function _decode(data, params) {
5167
- return decode(this, data, params, { callee: _decode });
5169
+ return decode$1(this, data, params, { callee: _decode });
5168
5170
  },
5169
5171
  encodeAsync: async function _encodeAsync(data, params) {
5170
5172
  return await encodeAsync(this, data, params, { callee: _encodeAsync });
@@ -24126,13 +24128,22 @@ var MCP_SERVER = {
24126
24128
  name: `io.github.${BRAND.repo}`,
24127
24129
  title: BRAND.name,
24128
24130
  /** Same as mcp/package.json (checked by a test). */
24129
- version: "0.1.6",
24131
+ version: "0.2.1",
24130
24132
  /** npm package name: `npx -y cverdict-mcp`. */
24131
24133
  npm: `${BRAND.slug}-mcp`,
24132
24134
  /** Where the server is documented. */
24133
24135
  docs: `${REPO_URL}/blob/main/mcp/README.md`
24134
24136
  };
24135
24137
  var CLONE_DIR = BRAND.repo.split("/")[1];
24138
+ JSON.stringify({ mcpServers: { [BRAND.slug]: {
24139
+ command: "npx",
24140
+ args: ["-y", MCP_SERVER.npm]
24141
+ } } });
24142
+ `${BRAND.slug}${MCP_SERVER.npm}`, `${BRAND.slug}${MCP_SERVER.npm}`, `${JSON.stringify({
24143
+ name: BRAND.slug,
24144
+ command: "npx",
24145
+ args: ["-y", MCP_SERVER.npm]
24146
+ })}`, `${BRAND.slug}${MCP_SERVER.npm}`;
24136
24147
  `${BRAND.slug}${BRAND.slug}`, `${BRAND.slug}${BRAND.slug}`, `${REPO_URL}${CLONE_DIR}${BRAND.slug}`;
24137
24148
  /** Data bases the server tries, in order: the data branch on GitHub, then the site's /data/ rewrite. */
24138
24149
  var MCP_DATA_BASES = [`${RAW_DATA_URL}/v1/`, `${BRAND.siteUrl}/data/v1/`];
@@ -24183,6 +24194,11 @@ var MCP_TOOLS = [
24183
24194
  title: "Check a list of vendors and products",
24184
24195
  description: "Which tracked CVEs hit a list of vendors or products (1 to 200 names, e.g. from an asset inventory): per name, the matching CVEs most urgent first (tier, then soonest CISA KEV due date, then score) with verdict, score and KEV due date, plus the Atom feed for the name's slug (it may also carry other spellings). A name must equal a CVE's vendor or product, ignoring case, as the site's watchlist matches; no_match: true flags a name with no tracked CVE (check the spelling, or try search_cves). omitted counts what was left out (per_name, or the size budget)." + UNTRUSTED
24185
24196
  },
24197
+ {
24198
+ name: "check_dependencies",
24199
+ title: "Check lockfiles and SBOMs",
24200
+ description: "Which of the project's dependencies have CVEs, most exploited first: reads the lockfiles and SBOMs (eight ecosystems) under paths inside the server's working directory, and matches every CVE an OSV.dev advisory ties to a package version, with tier, file, line and fixed version. Files stay local; only the public index is downloaded." + UNTRUSTED
24201
+ },
24186
24202
  {
24187
24203
  name: "changes_since",
24188
24204
  title: "What changed since a time",
@@ -24198,6 +24214,12 @@ var VERDICT = {
24198
24214
  };
24199
24215
  /** Messages the server answers with. Failures come back as tool results with isError: true. */
24200
24216
  var MCP_MSG = {
24217
+ /** check_dependencies: a path that is not inside the working directory, or not a lockfile or SBOM. */
24218
+ outsideRoot: (p) => `${p}: only paths inside the server's working directory can be checked.`,
24219
+ notCheckable: (p) => `${p}: not a lockfile or SBOM name this tool reads (see its description). Pass the folder that holds it instead.`,
24220
+ noDependencyFiles: (paths) => `No lockfile or SBOM found under ${paths}. Pass the folder or file to check, relative to the server's working directory.`,
24221
+ dependenciesCut: (shown, total) => `Showing the ${shown} most urgent of ${total} findings, to stay within the size budget; counts cover them all.`,
24222
+ olderMissing: (why) => `Older CVEs were not checked (${why}): only CVEs published in the last 30 days, in CISA KEV, listed as exploited or woken up.`,
24201
24223
  notFound: "Not in CVErdict's data: it was published before the 30-day window and is not in CISA KEV, ENISA EU KEV (as exploited), the CIRCL catalog (as exploited) or Woke Up, or it has no published record. That says nothing either way about the CVE.",
24202
24224
  notCveId: "Not a CVE ID. Expected CVE-YYYY-NNNN.",
24203
24225
  detailTooMany: (max) => `detail: true takes at most ${max} IDs; ask again in groups of ${max}.`,
@@ -24268,6 +24290,23 @@ var WAKE_KINDS = [
24268
24290
  "poc",
24269
24291
  "epss"
24270
24292
  ];
24293
+ var PACKAGE_ECOSYSTEMS = [
24294
+ "npm",
24295
+ "PyPI",
24296
+ "Maven",
24297
+ "Go",
24298
+ "crates.io",
24299
+ "RubyGems",
24300
+ "Packagist",
24301
+ "NuGet"
24302
+ ];
24303
+ var OS_ECOSYSTEMS = [
24304
+ "Debian",
24305
+ "Ubuntu",
24306
+ "Alpine"
24307
+ ];
24308
+ var ALL_ECOSYSTEMS = [...PACKAGE_ECOSYSTEMS, ...OS_ECOSYSTEMS];
24309
+ var isOsEcosystem = (eco) => OS_ECOSYSTEMS.includes(eco);
24271
24310
  /** Tier for a score at a given knob. Shared so the site and pipeline always agree. */
24272
24311
  function tierFor(score, exploited, weaponized, knob) {
24273
24312
  if (exploited) return "exploited";
@@ -24283,6 +24322,1221 @@ function rowFromColumns(cols, values) {
24283
24322
  function rowsFromTable(table) {
24284
24323
  return table.rows.map((r) => rowFromColumns(table.cols, r));
24285
24324
  }
24325
+ // shared/os.ts
24326
+ /** Debian releases by codename (OSV names them by number: "Debian:12"). sid has no number. */
24327
+ var DEBIAN_CODENAMES = {
24328
+ buzz: "1.1",
24329
+ hamm: "2.0",
24330
+ slink: "2.1",
24331
+ potato: "2.2",
24332
+ woody: "3.0",
24333
+ sarge: "3.1",
24334
+ etch: "4.0",
24335
+ lenny: "5.0",
24336
+ squeeze: "6.0",
24337
+ wheezy: "7",
24338
+ jessie: "8",
24339
+ stretch: "9",
24340
+ buster: "10",
24341
+ bullseye: "11",
24342
+ bookworm: "12",
24343
+ trixie: "13",
24344
+ forky: "14",
24345
+ duke: "15"
24346
+ };
24347
+ /** Ubuntu releases by codename (OSV names them by number: "Ubuntu:22.04:LTS"). */
24348
+ var UBUNTU_CODENAMES = {
24349
+ trusty: "14.04",
24350
+ xenial: "16.04",
24351
+ bionic: "18.04",
24352
+ focal: "20.04",
24353
+ jammy: "22.04",
24354
+ kinetic: "22.10",
24355
+ lunar: "23.04",
24356
+ mantic: "23.10",
24357
+ noble: "24.04",
24358
+ oracular: "24.10",
24359
+ plucky: "25.04",
24360
+ questing: "25.10",
24361
+ resolute: "26.04"
24362
+ };
24363
+ /** The distro of a package URL type and namespace (`pkg:deb/debian/…`, `pkg:apk/alpine/…`), or null. */
24364
+ function osEcosystemOfPurl(type, namespace) {
24365
+ const t = type.toLowerCase();
24366
+ const ns = (namespace ?? "").toLowerCase();
24367
+ if (t === "deb" && ns === "debian") return "Debian";
24368
+ if (t === "deb" && ns === "ubuntu") return "Ubuntu";
24369
+ if (t === "apk" && ns === "alpine") return "Alpine";
24370
+ return null;
24371
+ }
24372
+ /** A distro name as SBOMs write it ("debian", "Ubuntu", "alpine"), or null. */
24373
+ function osEcosystemOfName(name) {
24374
+ const n = name.trim().toLowerCase();
24375
+ return n === "debian" ? "Debian" : n === "ubuntu" ? "Ubuntu" : n === "alpine" ? "Alpine" : null;
24376
+ }
24377
+ /**
24378
+ * The release key v1/os/ uses ("12", "22.04", "v3.20") from what an SBOM says: a package URL's
24379
+ * `distro` qualifier ("debian-12", "debian-12.8", "bookworm", "ubuntu-22.04", "jammy",
24380
+ * "alpine-3.20.3", "3.20.3") or an operating-system component's version. Null when it names no
24381
+ * release we can read (sid, edge, or nothing).
24382
+ */
24383
+ function osRelease(eco, text) {
24384
+ if (!text) return null;
24385
+ let t = text.trim().toLowerCase();
24386
+ if (t.length > 64) return null;
24387
+ t = t.replace(/^(?:debian|ubuntu|alpine)[-_ ]?/, "");
24388
+ if (eco === "Debian") {
24389
+ if (Object.hasOwn(DEBIAN_CODENAMES, t)) return DEBIAN_CODENAMES[t];
24390
+ const m = /^(\d{1,2})(?:\.\d+)*$/.exec(t);
24391
+ if (!m) return null;
24392
+ return Number(m[1]) >= 7 ? m[1] : /^\d\.\d/.test(t) ? t.slice(0, 3) : null;
24393
+ }
24394
+ if (eco === "Ubuntu") {
24395
+ if (Object.hasOwn(UBUNTU_CODENAMES, t)) return UBUNTU_CODENAMES[t];
24396
+ const m = /^(\d{2}\.\d{2})(?:\.\d+)?(?:[ -]?lts)?$/.exec(t);
24397
+ return m ? m[1] : null;
24398
+ }
24399
+ const m = /^v?(\d{1,2}\.\d{1,3})(?:\.\d+)?$/.exec(t);
24400
+ return m ? `v${m[1]}` : null;
24401
+ }
24402
+ /** The package key in a v1/os/ file: "<release>/<source package>". */
24403
+ var osPackageKey = (release, source) => `${release}/${source}`;
24404
+ /** The v1/os/ file of a release, relative to v1/: "os/debian-12.json". */
24405
+ var osFile = (eco, release) => `os/${eco.toLowerCase()}-${release}.json`;
24406
+ /** Release keys are short and plain, so they are safe in a file name. */
24407
+ var OS_RELEASE_RE = /^(?:\d{1,2}(?:\.\d{1,2})?|v\d{1,2}\.\d{1,3})$/;
24408
+ /** Userland source packages whose names start with "linux-": checked like any other package. */
24409
+ var LINUX_USERLAND = /* @__PURE__ */ new Set([
24410
+ "linux-atm",
24411
+ "linux-entra-sso",
24412
+ "linux-ftpd",
24413
+ "linux-ftpd-ssl",
24414
+ "linux-pam"
24415
+ ]);
24416
+ /**
24417
+ * The Linux kernel's source packages: "linux" itself (whose linux-libc-dev headers are what a
24418
+ * container image holds) and the kernel builds ("linux-6.1", "linux-lts", "linux-aws",
24419
+ * "linux-signed-amd64"). A container runs on its host's kernel, so v1/os/ leaves the kernel out and
24420
+ * a check reports these packages as not checked, never clean. An unknown "linux-…" name counts as a
24421
+ * kernel build, so it too is not checked rather than wrongly clean.
24422
+ */
24423
+ function isKernelSource(name) {
24424
+ if (name === "linux") return true;
24425
+ return name.startsWith("linux-") && !LINUX_USERLAND.has(name) && !name.startsWith("linux-firmware");
24426
+ }
24427
+ // shared/os-load.ts
24428
+ /**
24429
+ * Which v1/os/ release files a check needs, and how they join the package index: shared by the
24430
+ * Check page, the CLI and the MCP server, which each fetch the files their own way. Only the
24431
+ * releases the user's packages name are fetched, so a check without distro packages fetches nothing.
24432
+ */
24433
+ /** A compact OS entry (OsAffect) as the PackageAffect the matcher reads: its advisory, and ">=0" back at the start of each range. */
24434
+ function expandAffect(entry, prefix) {
24435
+ if (!Array.isArray(entry) || typeof entry[0] !== "string" || !Array.isArray(entry[1])) return null;
24436
+ const [cve, ranges, advisory] = entry;
24437
+ const out = [];
24438
+ for (const r of ranges) {
24439
+ if (!Array.isArray(r) || !r.every((e) => typeof e === "string")) return null;
24440
+ out.push(r.length > 0 && r[0].startsWith(">=") ? [...r] : [">=0", ...r]);
24441
+ }
24442
+ return [
24443
+ cve,
24444
+ typeof advisory === "string" ? advisory : `${prefix}-${cve}`,
24445
+ out
24446
+ ];
24447
+ }
24448
+ /** The distro releases a list of packages names (packages without a release, or skipped, need none). */
24449
+ function osNeeds(components) {
24450
+ const out = /* @__PURE__ */ new Map();
24451
+ for (const c of components) {
24452
+ if (!c.eco || c.skip || !c.release || !isOsEcosystem(c.eco)) continue;
24453
+ const eco = c.eco;
24454
+ out.set(`${eco}/${c.release}`, {
24455
+ eco,
24456
+ release: c.release
24457
+ });
24458
+ }
24459
+ return [...out.values()];
24460
+ }
24461
+ function osPlan(index, needs) {
24462
+ const plan = {
24463
+ files: /* @__PURE__ */ new Map(),
24464
+ notFollowed: /* @__PURE__ */ new Set(),
24465
+ failed: /* @__PURE__ */ new Set()
24466
+ };
24467
+ for (const n of needs) {
24468
+ const tag = `${n.eco}/${n.release}`;
24469
+ const source = index?.sources?.find((s) => s.ecosystem === n.eco);
24470
+ if (!index || !source?.ok) {
24471
+ plan.failed.add(tag);
24472
+ continue;
24473
+ }
24474
+ const entry = index.releases.find((r) => r.ecosystem === n.eco && r.release === n.release);
24475
+ if (!entry) continue;
24476
+ const file = OS_RELEASE_RE.test(n.release) ? osFile(n.eco, n.release) : null;
24477
+ if (!entry.followed || entry.file !== file || file === null) plan.notFollowed.add(tag);
24478
+ else plan.files.set(tag, file);
24479
+ }
24480
+ return plan;
24481
+ }
24482
+ /**
24483
+ * The package index with distro release files merged in: their packages, their source status (so
24484
+ * the ecosystem counts as available) and the rows of CVEs the index does not have yet. `noPage`:
24485
+ * the CVEs added that have no CVE page (no detail shard), which link to cve.org.
24486
+ */
24487
+ function mergeOsFiles(base, files) {
24488
+ if (files.length === 0) return {
24489
+ file: base,
24490
+ noPage: /* @__PURE__ */ new Set()
24491
+ };
24492
+ const have = new Set(rowsFromTable(base.cves).map((r) => r.id));
24493
+ const packages = { ...base.packages };
24494
+ const sources = [...base.sources];
24495
+ const rows = [...base.cves.rows];
24496
+ const noPage = /* @__PURE__ */ new Set();
24497
+ for (const f of files) {
24498
+ const eco = f.ecosystem;
24499
+ const merged = new Map(Object.entries(packages[eco] ?? {}));
24500
+ for (const [key, list] of Object.entries(f.packages ?? {})) {
24501
+ if (!Array.isArray(list)) continue;
24502
+ merged.set(key, list.map((e) => expandAffect(e, f.prefix)).filter((e) => e !== null));
24503
+ }
24504
+ packages[eco] = Object.fromEntries(merged);
24505
+ for (const s of f.sources) if (!sources.some((x) => x.ecosystem === s.ecosystem)) sources.push(s);
24506
+ const tracked = new Set(f.tracked);
24507
+ const order = base.cves.cols.map((c) => f.cves.cols.indexOf(c));
24508
+ const idCol = f.cves.cols.indexOf("id");
24509
+ for (const r of f.cves.rows) {
24510
+ const id = r[idCol];
24511
+ if (have.has(id)) continue;
24512
+ have.add(id);
24513
+ rows.push(order.map((j) => j < 0 ? null : r[j]));
24514
+ if (!tracked.has(id)) noPage.add(id);
24515
+ }
24516
+ }
24517
+ return {
24518
+ file: {
24519
+ ...base,
24520
+ packages,
24521
+ sources,
24522
+ cves: {
24523
+ cols: base.cves.cols,
24524
+ rows
24525
+ }
24526
+ },
24527
+ noPage
24528
+ };
24529
+ }
24530
+ var DIGITS = /^\d+$/;
24531
+ /** Numeric comparison of two digit strings of any length (leading zeros allowed). */
24532
+ function cmpDigits(a, b) {
24533
+ let i = 0;
24534
+ let j = 0;
24535
+ while (i < a.length - 1 && a[i] === "0") i++;
24536
+ while (j < b.length - 1 && b[j] === "0") j++;
24537
+ const la = a.length - i;
24538
+ const lb = b.length - j;
24539
+ if (la !== lb) return la < lb ? -1 : 1;
24540
+ for (; i < a.length; i++, j++) if (a[i] !== b[j]) return a[i] < b[j] ? -1 : 1;
24541
+ return 0;
24542
+ }
24543
+ var cmpText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
24544
+ /** Wrap a parser with the length cap and trimming every comparator shares. */
24545
+ function capped(parse) {
24546
+ return (v) => {
24547
+ if (typeof v !== "string" || v.length > 128) return null;
24548
+ const s = v.trim();
24549
+ return s === "" ? null : parse(s);
24550
+ };
24551
+ }
24552
+ /** SemVer 2.0 prerelease identifiers (null: a release). Numeric < alphanumeric; more identifiers win. */
24553
+ function cmpPrerelease(a, b) {
24554
+ if (!a || !b) return a ? -1 : b ? 1 : 0;
24555
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24556
+ const x = a[i];
24557
+ const y = b[i];
24558
+ if (x === void 0) return -1;
24559
+ if (y === void 0) return 1;
24560
+ const xn = DIGITS.test(x);
24561
+ const yn = DIGITS.test(y);
24562
+ const c = xn && yn ? cmpDigits(x, y) : xn !== yn ? xn ? -1 : 1 : cmpText(x, y);
24563
+ if (c !== 0) return c;
24564
+ }
24565
+ return 0;
24566
+ }
24567
+ var SEMVER_RE = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24568
+ var semver = {
24569
+ parse: capped((s) => {
24570
+ const m = SEMVER_RE.exec(s);
24571
+ return m ? {
24572
+ n: [
24573
+ m[1],
24574
+ m[2],
24575
+ m[3]
24576
+ ],
24577
+ pre: m[4] ? m[4].split(".") : null
24578
+ } : null;
24579
+ }),
24580
+ cmp(a, b) {
24581
+ for (let i = 0; i < 3; i++) {
24582
+ const c = cmpDigits(a.n[i], b.n[i]);
24583
+ if (c !== 0) return c;
24584
+ }
24585
+ return cmpPrerelease(a.pre, b.pre);
24586
+ }
24587
+ };
24588
+ var PEP440_RE = /^v?(?:(\d+)!)?(\d+(?:\.\d+)*)(?:[-_.]?(alpha|beta|preview|pre|rc|a|b|c)[-_.]?(\d+)?)?(?:-(\d+)|[-_.]?(post|rev|r)[-_.]?(\d+)?)?(?:[-_.]?(dev)[-_.]?(\d+)?)?(?:\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/i;
24589
+ var PRE_RANK = {
24590
+ a: 0,
24591
+ alpha: 0,
24592
+ b: 1,
24593
+ beta: 1,
24594
+ c: 2,
24595
+ rc: 2,
24596
+ pre: 2,
24597
+ preview: 2
24598
+ };
24599
+ /** Rank of the pre-release part: a dev-only release sorts first, then pre-releases, then none. */
24600
+ function pepPreKey(k) {
24601
+ if (k.pre) return [
24602
+ 1,
24603
+ k.pre[0],
24604
+ k.pre[1]
24605
+ ];
24606
+ return k.post === null && k.dev !== null ? [
24607
+ 0,
24608
+ 0,
24609
+ "0"
24610
+ ] : [
24611
+ 2,
24612
+ 0,
24613
+ "0"
24614
+ ];
24615
+ }
24616
+ var pep440 = {
24617
+ parse: capped((s) => {
24618
+ const m = PEP440_RE.exec(s);
24619
+ if (!m) return null;
24620
+ const release = m[2].split(".");
24621
+ while (release.length > 1 && /^0+$/.test(release[release.length - 1])) release.pop();
24622
+ return {
24623
+ epoch: m[1] ?? "0",
24624
+ release,
24625
+ pre: m[3] ? [PRE_RANK[m[3].toLowerCase()], m[4] ?? "0"] : null,
24626
+ post: m[5] !== void 0 ? m[5] : m[6] ? m[7] ?? "0" : null,
24627
+ dev: m[8] ? m[9] ?? "0" : null,
24628
+ local: m[10] ? m[10].toLowerCase().split(/[-_.]/) : null
24629
+ };
24630
+ }),
24631
+ cmp(a, b) {
24632
+ let c = cmpDigits(a.epoch, b.epoch);
24633
+ if (c !== 0) return c;
24634
+ for (let i = 0; i < Math.max(a.release.length, b.release.length); i++) {
24635
+ c = cmpDigits(a.release[i] ?? "0", b.release[i] ?? "0");
24636
+ if (c !== 0) return c;
24637
+ }
24638
+ const pa = pepPreKey(a);
24639
+ const pb = pepPreKey(b);
24640
+ c = pa[0] - pb[0] || pa[1] - pb[1] || cmpDigits(pa[2], pb[2]);
24641
+ if (c !== 0) return c;
24642
+ if (a.post === null !== (b.post === null)) return a.post === null ? -1 : 1;
24643
+ if (a.post !== null && b.post !== null) {
24644
+ c = cmpDigits(a.post, b.post);
24645
+ if (c !== 0) return c;
24646
+ }
24647
+ if (a.dev === null !== (b.dev === null)) return a.dev === null ? 1 : -1;
24648
+ if (a.dev !== null && b.dev !== null) {
24649
+ c = cmpDigits(a.dev, b.dev);
24650
+ if (c !== 0) return c;
24651
+ }
24652
+ if (a.local === null !== (b.local === null)) return a.local === null ? -1 : 1;
24653
+ if (a.local && b.local) for (let i = 0; i < Math.max(a.local.length, b.local.length); i++) {
24654
+ const x = a.local[i];
24655
+ const y = b.local[i];
24656
+ if (x === void 0) return -1;
24657
+ if (y === void 0) return 1;
24658
+ const xn = DIGITS.test(x);
24659
+ const yn = DIGITS.test(y);
24660
+ c = xn && yn ? cmpDigits(x, y) : xn !== yn ? xn ? 1 : -1 : cmpText(x, y);
24661
+ if (c !== 0) return c;
24662
+ }
24663
+ return 0;
24664
+ }
24665
+ };
24666
+ var GEM_RE = /^[0-9]+(?:\.[0-9a-zA-Z]+)*(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24667
+ var isNumSeg = (s) => s.charCodeAt(0) >= 48 && s.charCodeAt(0) <= 57;
24668
+ var rubygems = {
24669
+ parse: capped((s) => {
24670
+ if (!GEM_RE.test(s)) return null;
24671
+ const segs = s.replace(/-/g, ".pre.").match(/[0-9]+|[a-z]+/gi) ?? [];
24672
+ let split = segs.findIndex((x) => !isNumSeg(x));
24673
+ if (split < 0) split = segs.length;
24674
+ const trim = (xs) => {
24675
+ while (xs.length > 0 && isNumSeg(xs[xs.length - 1]) && /^0+$/.test(xs[xs.length - 1])) xs.pop();
24676
+ return xs;
24677
+ };
24678
+ return [...trim(segs.slice(0, split)), ...trim(segs.slice(split))];
24679
+ }),
24680
+ cmp(a, b) {
24681
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24682
+ const x = a[i] ?? "0";
24683
+ const y = b[i] ?? "0";
24684
+ const xn = isNumSeg(x);
24685
+ const yn = isNumSeg(y);
24686
+ if (xn && yn) {
24687
+ const c = cmpDigits(x, y);
24688
+ if (c !== 0) return c;
24689
+ } else if (xn !== yn) return xn ? 1 : -1;
24690
+ else if (x !== y) return x < y ? -1 : 1;
24691
+ }
24692
+ return 0;
24693
+ }
24694
+ };
24695
+ var NUGET_RE = /^v?(\d+(?:\.\d+){0,3})(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
24696
+ var nuget = {
24697
+ parse: capped((s) => {
24698
+ const m = NUGET_RE.exec(s);
24699
+ if (!m) return null;
24700
+ const parts = m[1].split(".");
24701
+ while (parts.length < 4) parts.push("0");
24702
+ return {
24703
+ n: parts,
24704
+ pre: m[2] ? m[2].toLowerCase().split(".") : null
24705
+ };
24706
+ }),
24707
+ cmp(a, b) {
24708
+ for (let i = 0; i < 4; i++) {
24709
+ const c = cmpDigits(a.n[i], b.n[i]);
24710
+ if (c !== 0) return c;
24711
+ }
24712
+ return cmpPrerelease(a.pre, b.pre);
24713
+ }
24714
+ };
24715
+ /** Known qualifiers in order; "" is the release. Unknown qualifiers sort after all of them. */
24716
+ var MAVEN_QUALIFIERS = [
24717
+ "alpha",
24718
+ "beta",
24719
+ "milestone",
24720
+ "rc",
24721
+ "snapshot",
24722
+ "",
24723
+ "sp"
24724
+ ];
24725
+ var MAVEN_ALIASES = {
24726
+ ga: "",
24727
+ final: "",
24728
+ release: "",
24729
+ cr: "rc"
24730
+ };
24731
+ var MAVEN_SHORT = {
24732
+ a: "alpha",
24733
+ b: "beta",
24734
+ m: "milestone"
24735
+ };
24736
+ function mavenQualifier(q) {
24737
+ return Object.hasOwn(MAVEN_ALIASES, q) ? MAVEN_ALIASES[q] : q;
24738
+ }
24739
+ function cmpQualifier(a, b) {
24740
+ const ia = MAVEN_QUALIFIERS.indexOf(a);
24741
+ const ib = MAVEN_QUALIFIERS.indexOf(b);
24742
+ if (ia >= 0 && ib >= 0) return ia - ib;
24743
+ if (ia >= 0 || ib >= 0) return ia >= 0 ? -1 : 1;
24744
+ return cmpText(a, b);
24745
+ }
24746
+ var isMavenNull = (t) => t.num !== null ? /^0+$/.test(t.num) : t.qual === "";
24747
+ /** Qualifier < "-" number < "." number; numbers by value, qualifiers by the known order. */
24748
+ function cmpMavenToken(a, b) {
24749
+ if (a.num === null && b.num === null) return cmpQualifier(a.qual, b.qual);
24750
+ if (a.num === null || b.num === null) return a.num === null ? -1 : 1;
24751
+ if (a.sep !== b.sep) return a.sep === "-" ? -1 : 1;
24752
+ return cmpDigits(a.num, b.num);
24753
+ }
24754
+ /**
24755
+ * A token compared with nothing (the shorter version ran out): a number with 0, a qualifier with
24756
+ * the release qualifier "", whatever the separator. So "7.2.2.v20101205" is above "7.2.2" and
24757
+ * "1-SNAPSHOT" below "1", as Maven and OSV.dev order them.
24758
+ */
24759
+ function cmpMavenToNull(t) {
24760
+ return t.num !== null ? /^0+$/.test(t.num) ? 0 : 1 : cmpQualifier(t.qual, "");
24761
+ }
24762
+ var maven = {
24763
+ parse: capped((raw) => {
24764
+ if (/\s/.test(raw)) return null;
24765
+ const s = raw.toLowerCase();
24766
+ const tokens = [];
24767
+ let sep = ".";
24768
+ let start = 0;
24769
+ const push = (end, nextSep, followedByDigit) => {
24770
+ const text = s.slice(start, end);
24771
+ if (text === "") tokens.push({
24772
+ sep,
24773
+ num: "0",
24774
+ qual: ""
24775
+ });
24776
+ else if (/^\d/.test(text)) tokens.push({
24777
+ sep,
24778
+ num: text,
24779
+ qual: ""
24780
+ });
24781
+ else {
24782
+ const q = followedByDigit && Object.hasOwn(MAVEN_SHORT, text) ? MAVEN_SHORT[text] : text;
24783
+ tokens.push({
24784
+ sep,
24785
+ num: null,
24786
+ qual: mavenQualifier(q)
24787
+ });
24788
+ }
24789
+ sep = nextSep;
24790
+ };
24791
+ for (let i = 0; i < s.length; i++) {
24792
+ const ch = s[i];
24793
+ if (ch === "." || ch === "-") {
24794
+ push(i, ch, false);
24795
+ start = i + 1;
24796
+ } else if (i > start) {
24797
+ const digit = ch >= "0" && ch <= "9";
24798
+ if (digit !== (s[i - 1] >= "0" && s[i - 1] <= "9")) {
24799
+ push(i, "-", digit);
24800
+ start = i;
24801
+ }
24802
+ }
24803
+ }
24804
+ if (start < s.length) push(s.length, ".", false);
24805
+ else if (s.length > 0 && (s.endsWith(".") || s.endsWith("-"))) push(s.length, ".", false);
24806
+ let i = tokens.length - 1;
24807
+ while (i > 0) {
24808
+ if (isMavenNull(tokens[i])) {
24809
+ tokens.splice(i, 1);
24810
+ i--;
24811
+ continue;
24812
+ }
24813
+ while (i >= 0 && tokens[i].sep !== "-") i--;
24814
+ i--;
24815
+ }
24816
+ return tokens;
24817
+ }),
24818
+ cmp(a, b) {
24819
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
24820
+ const c = i >= a.length ? -cmpMavenToNull(b[i]) : i >= b.length ? cmpMavenToNull(a[i]) : cmpMavenToken(a[i], b[i]);
24821
+ if (c !== 0) return c;
24822
+ }
24823
+ return 0;
24824
+ }
24825
+ };
24826
+ var COMPOSER_RE = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:[._-]?(stable|beta|b|rc|alpha|a|patch|pl|p)(\d*(?:[.-]\d+)*))?([._-]?dev)?$/;
24827
+ var COMPOSER_STABILITY = {
24828
+ alpha: 1,
24829
+ a: 1,
24830
+ beta: 2,
24831
+ b: 2,
24832
+ rc: 3,
24833
+ stable: 4,
24834
+ patch: 5,
24835
+ pl: 5,
24836
+ p: 5
24837
+ };
24838
+ var composer = {
24839
+ parse: capped((raw) => {
24840
+ const m = COMPOSER_RE.exec(raw.toLowerCase());
24841
+ if (!m) return null;
24842
+ const dev = m[7] !== void 0;
24843
+ const stability = m[5] ? COMPOSER_STABILITY[m[5]] : dev ? 0 : 4;
24844
+ return {
24845
+ n: [
24846
+ m[1],
24847
+ m[2] ?? "0",
24848
+ m[3] ?? "0",
24849
+ m[4] ?? "0"
24850
+ ],
24851
+ stability,
24852
+ numbers: (m[6] ?? "").split(/[.-]/).filter((x) => x !== ""),
24853
+ dev: dev && m[5] !== void 0
24854
+ };
24855
+ }),
24856
+ cmp(a, b) {
24857
+ for (let i = 0; i < 4; i++) {
24858
+ const c = cmpDigits(a.n[i], b.n[i]);
24859
+ if (c !== 0) return c;
24860
+ }
24861
+ if (a.stability !== b.stability) return a.stability - b.stability;
24862
+ for (let i = 0; i < Math.max(a.numbers.length, b.numbers.length); i++) {
24863
+ const c = cmpDigits(a.numbers[i] ?? "0", b.numbers[i] ?? "0");
24864
+ if (c !== 0) return c;
24865
+ }
24866
+ if (a.dev !== b.dev) return a.dev ? -1 : 1;
24867
+ return 0;
24868
+ }
24869
+ };
24870
+ var DPKG_UPSTREAM = /^[0-9][0-9A-Za-z.+~:-]*$/;
24871
+ var DPKG_REVISION = /^[0-9A-Za-z.+~]+$/;
24872
+ /** dpkg's character order: "~" before everything (even the end), letters before other symbols. */
24873
+ function dpkgOrder(c) {
24874
+ if (c === void 0 || c >= "0" && c <= "9") return 0;
24875
+ if (c >= "A" && c <= "Z" || c >= "a" && c <= "z") return c.charCodeAt(0);
24876
+ if (c === "~") return -1;
24877
+ return c.charCodeAt(0) + 256;
24878
+ }
24879
+ var isDigit = (c) => c !== void 0 && c >= "0" && c <= "9";
24880
+ /** dpkg's verrevcmp: alternating non-digit and digit runs, digits compared as numbers. */
24881
+ function verrevcmp(a, b) {
24882
+ let i = 0;
24883
+ let j = 0;
24884
+ while (i < a.length || j < b.length) {
24885
+ while (i < a.length && !isDigit(a[i]) || j < b.length && !isDigit(b[j])) {
24886
+ const ac = dpkgOrder(a[i]);
24887
+ const bc = dpkgOrder(b[j]);
24888
+ if (ac !== bc) return ac - bc;
24889
+ i++;
24890
+ j++;
24891
+ }
24892
+ let x = "";
24893
+ let y = "";
24894
+ while (isDigit(a[i])) x += a[i++];
24895
+ while (isDigit(b[j])) y += b[j++];
24896
+ const c = cmpDigits(x || "0", y || "0");
24897
+ if (c !== 0) return c;
24898
+ }
24899
+ return 0;
24900
+ }
24901
+ var dpkg = {
24902
+ parse: capped((s) => {
24903
+ const colon = s.indexOf(":");
24904
+ const epoch = colon >= 0 ? s.slice(0, colon) : "0";
24905
+ if (!/^\d{1,9}$/.test(epoch)) return null;
24906
+ const rest = colon >= 0 ? s.slice(colon + 1) : s;
24907
+ const hyphen = rest.lastIndexOf("-");
24908
+ const upstream = hyphen >= 0 ? rest.slice(0, hyphen) : rest;
24909
+ const revision = hyphen >= 0 ? rest.slice(hyphen + 1) : "";
24910
+ if (!DPKG_UPSTREAM.test(upstream) || hyphen >= 0 && !DPKG_REVISION.test(revision)) return null;
24911
+ return {
24912
+ epoch,
24913
+ upstream,
24914
+ revision
24915
+ };
24916
+ }),
24917
+ cmp(a, b) {
24918
+ return cmpDigits(a.epoch, b.epoch) || verrevcmp(a.upstream, b.upstream) || verrevcmp(a.revision, b.revision);
24919
+ }
24920
+ };
24921
+ /** Pre-release suffixes sort before the release, post-release ones after it. */
24922
+ var APK_SUFFIX = {
24923
+ alpha: 0,
24924
+ beta: 1,
24925
+ pre: 2,
24926
+ rc: 3,
24927
+ cvs: 5,
24928
+ svn: 6,
24929
+ git: 7,
24930
+ hg: 8,
24931
+ p: 9
24932
+ };
24933
+ var APK_PRE = 4;
24934
+ var APK_RE = /^(\d+(?:\.\d+)*)([a-z]?)((?:_(?:alpha|beta|pre|rc|cvs|svn|git|hg|p)\d*)*)(?:~[0-9a-f]+)?(?:-r(\d+))?$/;
24935
+ var COMPARATORS = {
24936
+ npm: semver,
24937
+ "crates.io": semver,
24938
+ Go: semver,
24939
+ PyPI: pep440,
24940
+ RubyGems: rubygems,
24941
+ NuGet: nuget,
24942
+ Maven: maven,
24943
+ Packagist: composer,
24944
+ Debian: dpkg,
24945
+ Ubuntu: dpkg,
24946
+ Alpine: {
24947
+ parse: capped((s) => {
24948
+ const m = APK_RE.exec(s);
24949
+ if (!m) return null;
24950
+ const out = m[1].split(".").map((v, i) => ({
24951
+ t: 1,
24952
+ v,
24953
+ first: i === 0
24954
+ }));
24955
+ if (m[2]) out.push({
24956
+ t: 2,
24957
+ v: m[2]
24958
+ });
24959
+ for (const sfx of m[3].split("_").slice(1)) {
24960
+ const name = /^[a-z]+/.exec(sfx)[0];
24961
+ out.push({
24962
+ t: 3,
24963
+ rank: APK_SUFFIX[name],
24964
+ n: sfx.slice(name.length) || "0"
24965
+ });
24966
+ }
24967
+ if (m[4] !== void 0) out.push({
24968
+ t: 5,
24969
+ n: m[4]
24970
+ });
24971
+ out.push({ t: 6 });
24972
+ return out;
24973
+ }),
24974
+ cmp(a, b) {
24975
+ for (let i = 0;; i++) {
24976
+ const x = a[i];
24977
+ const y = b[i];
24978
+ if (x.t !== y.t) {
24979
+ if (x.t === 3 && x.rank < APK_PRE) return -1;
24980
+ if (y.t === 3 && y.rank < APK_PRE) return 1;
24981
+ return x.t > y.t ? -1 : 1;
24982
+ }
24983
+ let c = 0;
24984
+ if (x.t === 1 && y.t === 1) c = !x.first && (x.v[0] === "0" || y.v[0] === "0") ? cmpText(x.v, y.v) : cmpDigits(x.v, y.v);
24985
+ else if (x.t === 2 && y.t === 2) c = cmpText(x.v, y.v);
24986
+ else if (x.t === 3 && y.t === 3) c = x.rank - y.rank || cmpDigits(x.n, y.n);
24987
+ else if (x.t === 5 && y.t === 5) c = cmpDigits(x.n, y.n);
24988
+ else return 0;
24989
+ if (c !== 0) return c;
24990
+ }
24991
+ }
24992
+ }
24993
+ };
24994
+ /** ">=V" introduced, "<V" fixed, "<=V" last affected, "?kind=V" anything else; null if malformed. */
24995
+ function parseEvent(event) {
24996
+ if (typeof event !== "string") return null;
24997
+ if (event.startsWith(">=")) return {
24998
+ op: ">=",
24999
+ v: event.slice(2)
25000
+ };
25001
+ if (event.startsWith("<=")) return {
25002
+ op: "<=",
25003
+ v: event.slice(2)
25004
+ };
25005
+ if (event.startsWith("<")) return {
25006
+ op: "<",
25007
+ v: event.slice(1)
25008
+ };
25009
+ const m = /^\?([a-z_]{1,32})=([^\s]{0,128})$/.exec(event);
25010
+ return m ? {
25011
+ op: "?",
25012
+ kind: m[1],
25013
+ v: m[2]
25014
+ } : null;
25015
+ }
25016
+ /** Parse a range's events once; null when one of them cannot be evaluated. */
25017
+ function compileRange(c, events) {
25018
+ if (events.length === 0) return null;
25019
+ const out = [];
25020
+ for (const e of events) {
25021
+ const p = parseEvent(e);
25022
+ if (!p || p.op === "?") return null;
25023
+ if (p.op === ">=" && p.v === "0") {
25024
+ out.push({
25025
+ op: ">=",
25026
+ key: null
25027
+ });
25028
+ continue;
25029
+ }
25030
+ const key = c.parse(p.v);
25031
+ if (key === null) return null;
25032
+ out.push({
25033
+ op: p.op,
25034
+ key
25035
+ });
25036
+ }
25037
+ return out.sort((x, y) => x.key === null ? y.key === null ? 0 : -1 : y.key === null ? 1 : c.cmp(x.key, y.key));
25038
+ }
25039
+ /**
25040
+ * The OSV evaluation of `ranges` for one ecosystem, compiled once. Per range, walk the events in
25041
+ * version order: an introduced event at or below the version turns "affected" on, a fixed event
25042
+ * at or below it turns it off, a last-affected event below it turns it off. The version is
25043
+ * affected when any range ends on; otherwise unknown (null) when a range could not be evaluated
25044
+ * (an unparseable bound or a "?" event) or the version does not parse; otherwise not affected.
25045
+ */
25046
+ function compileRanges(eco, ranges) {
25047
+ const c = COMPARATORS[eco];
25048
+ const compiled = ranges.map((r) => compileRange(c, r));
25049
+ const someUnknown = compiled.includes(null);
25050
+ return (version) => {
25051
+ const v = c.parse(version);
25052
+ if (v === null) return null;
25053
+ for (const events of compiled) {
25054
+ if (!events) continue;
25055
+ let affected = false;
25056
+ for (const { op, key } of events) if (op === ">=") {
25057
+ if (key === null || c.cmp(v, key) >= 0) affected = true;
25058
+ } else if (op === "<") {
25059
+ if (c.cmp(v, key) >= 0) affected = false;
25060
+ } else if (c.cmp(v, key) > 0) affected = false;
25061
+ if (affected) return true;
25062
+ }
25063
+ return someUnknown ? null : false;
25064
+ };
25065
+ }
25066
+ /**
25067
+ * `version` null means "no exact version". A listed extra version matches as an exact string, or
25068
+ * as an equal version when both parse; then the ranges decide. An entry with no range and no
25069
+ * listed version cannot be evaluated, so it is "unchecked", never "not affected".
25070
+ */
25071
+ function matchAffect(eco, version, ranges, extra = []) {
25072
+ if (version === null || version === "") return "unchecked";
25073
+ if (extra.includes(version)) return "affected";
25074
+ const c = COMPARATORS[eco];
25075
+ const v = c.parse(version);
25076
+ if (v !== null && extra.some((x) => {
25077
+ const k = c.parse(x);
25078
+ return k !== null && c.cmp(v, k) === 0;
25079
+ })) return "affected";
25080
+ if (ranges.length === 0) return extra.length > 0 && v !== null ? "not_affected" : "unchecked";
25081
+ const r = compileRanges(eco, ranges)(version);
25082
+ return r === true ? "affected" : r === null ? "unchecked" : "not_affected";
25083
+ }
25084
+ // shared/packages.ts
25085
+ /**
25086
+ * Package keys, advisory IDs, licences and range wording for v1/packages.json, shared by the
25087
+ * pipeline (which builds and validates the file) and the site (which matches an SBOM against it).
25088
+ * No Node or DOM APIs.
25089
+ */
25090
+ /**
25091
+ * How a package name is compared within an ecosystem, applied both to OSV names and to names from
25092
+ * the user's file. PyPI per PEP 503; crates.io treats case and "-"/"_" as equal; NuGet and
25093
+ * Packagist are case-insensitive; npm, Go module paths, Maven group:artifact and RubyGems as given.
25094
+ */
25095
+ function packageKey(eco, name) {
25096
+ switch (eco) {
25097
+ case "PyPI": return name.replace(/[-_.]+/g, "-").toLowerCase();
25098
+ case "crates.io": return name.toLowerCase().replace(/_/g, "-");
25099
+ case "NuGet":
25100
+ case "Packagist": return name.toLowerCase();
25101
+ default: return name;
25102
+ }
25103
+ }
25104
+ var PURL_TYPES = /* @__PURE__ */ new Map([
25105
+ ["npm", "npm"],
25106
+ ["pypi", "PyPI"],
25107
+ ["maven", "Maven"],
25108
+ ["golang", "Go"],
25109
+ ["cargo", "crates.io"],
25110
+ ["gem", "RubyGems"],
25111
+ ["composer", "Packagist"],
25112
+ ["nuget", "NuGet"]
25113
+ ]);
25114
+ /** The ecosystem of a package URL type (`pkg:<type>/…`), or null when it is not covered. */
25115
+ function ecosystemOfPurlType(type) {
25116
+ return PURL_TYPES.get(type.toLowerCase()) ?? null;
25117
+ }
25118
+ /**
25119
+ * The advisory databases whose records may be published, with their licences. A record whose ID
25120
+ * prefix is not listed here is never published, so this list is always complete. Adding a
25121
+ * database means adding it here together with any notice its licence requires.
25122
+ */
25123
+ var ATTRIBUTION = [
25124
+ {
25125
+ name: "GitHub Advisory Database",
25126
+ url: "https://github.com/advisories",
25127
+ license: "CC-BY-4.0",
25128
+ prefixes: ["GHSA"],
25129
+ notice: null
25130
+ },
25131
+ {
25132
+ name: "PyPI Advisory Database",
25133
+ url: "https://github.com/pypa/advisory-database",
25134
+ license: "CC-BY-4.0",
25135
+ prefixes: ["PYSEC"],
25136
+ notice: null
25137
+ },
25138
+ {
25139
+ name: "Go Vulnerability Database",
25140
+ url: "https://pkg.go.dev/vuln/",
25141
+ license: "CC-BY-4.0",
25142
+ prefixes: ["GO"],
25143
+ notice: null
25144
+ },
25145
+ {
25146
+ name: "RustSec Advisory Database",
25147
+ url: "https://rustsec.org/",
25148
+ license: "CC0-1.0 (content imported from the GitHub Advisory Database: CC-BY-4.0)",
25149
+ prefixes: ["RUSTSEC"],
25150
+ notice: null
25151
+ },
25152
+ {
25153
+ name: "Drupal security advisories (OSV)",
25154
+ url: "https://github.com/DrupalSecurityTeam/drupal-advisory-database",
25155
+ license: "MIT, Copyright (c) 2025 Ackama",
25156
+ prefixes: ["DRUPAL-CORE", "DRUPAL-CONTRIB"],
25157
+ notice: `The MIT License (MIT)
25158
+
25159
+ Copyright (c) 2025 Ackama
25160
+
25161
+ Permission is hereby granted, free of charge, to any person obtaining a copy
25162
+ of this software and associated documentation files (the "Software"), to deal
25163
+ in the Software without restriction, including without limitation the rights
25164
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25165
+ copies of the Software, and to permit persons to whom the Software is
25166
+ furnished to do so, subject to the following conditions:
25167
+
25168
+ The above copyright notice and this permission notice shall be included in
25169
+ all copies or substantial portions of the Software.
25170
+
25171
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25172
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25173
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25174
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25175
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25176
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25177
+ THE SOFTWARE.`
25178
+ }
25179
+ ];
25180
+ /**
25181
+ * The distro advisory databases behind v1/os/ (OS_ECOSYSTEMS), one record type each: the per-CVE
25182
+ * tracker records, which cover every release. Their licences differ from ATTRIBUTION's, so their
25183
+ * data is never merged into v1/packages.json: Ubuntu's and Alpine's are share-alike (CC-BY-SA-4.0),
25184
+ * and Debian states no licence for its tracker data (OSV.dev issue 6430), so only facts are kept
25185
+ * (package names, version ranges, CVE IDs) and the data is removed if Debian asks.
25186
+ */
25187
+ var OS_ATTRIBUTION = [
25188
+ {
25189
+ name: "Debian Security Tracker (via OSV.dev)",
25190
+ url: "https://security-tracker.debian.org/",
25191
+ license: "No licence stated by Debian; only facts are kept (package names, version ranges, CVE IDs), removed on request",
25192
+ prefixes: ["DEBIAN-CVE"],
25193
+ notice: null
25194
+ },
25195
+ {
25196
+ name: "Ubuntu CVE Tracker (Canonical, via OSV.dev)",
25197
+ url: "https://github.com/canonical/ubuntu-security-notices",
25198
+ license: "CC-BY-SA-4.0",
25199
+ prefixes: ["UBUNTU-CVE"],
25200
+ notice: "Ubuntu security data © Canonical Ltd., licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/). Changes: reduced to package names, version ranges and CVE IDs."
25201
+ },
25202
+ {
25203
+ name: "Alpine SecDB (via OSV.dev)",
25204
+ url: "https://secdb.alpinelinux.org/",
25205
+ license: "CC-BY-SA-4.0",
25206
+ prefixes: ["ALPINE-CVE"],
25207
+ notice: "Alpine Linux security database, licensed under CC BY-SA 4.0 (https://secdb.alpinelinux.org/license.txt). Changes: reduced to package names, version ranges and CVE IDs."
25208
+ }
25209
+ ];
25210
+ [...ATTRIBUTION, ...OS_ATTRIBUTION];
25211
+ /**
25212
+ * packages.json and packages-older.json as one index for the matcher: rows of both, and per ecosystem
25213
+ * and package key the entries of both. `older` may be null (an older data tree, or a failed load): the
25214
+ * result then is `tracked` as is. When the two come from different runs, a CVE in both keeps its
25215
+ * tracked row and entries only. Objects are built with Object.fromEntries, so a package key such as
25216
+ * `__proto__` stays a plain own key. `sources` (health) comes from `tracked`, with `matched` added up.
25217
+ */
25218
+ function mergePackageFiles(tracked, older) {
25219
+ if (!older) return tracked;
25220
+ const idCol = tracked.cves.cols.indexOf("id");
25221
+ const trackedIds = new Set(tracked.cves.rows.map((r) => r[idCol]));
25222
+ const olderIdCol = older.cves.cols.indexOf("id");
25223
+ const packages = {};
25224
+ for (const eco of PACKAGE_ECOSYSTEMS) {
25225
+ const a = tracked.packages[eco];
25226
+ const b = older.packages[eco];
25227
+ if (!a && !b) continue;
25228
+ const merged = new Map(Object.entries(a ?? {}));
25229
+ for (const [key, list] of Object.entries(b ?? {})) {
25230
+ const extra = Array.isArray(list) ? list.filter((e) => !trackedIds.has(e[0])) : [];
25231
+ if (extra.length) merged.set(key, [...merged.get(key) ?? [], ...extra]);
25232
+ }
25233
+ packages[eco] = Object.fromEntries(merged);
25234
+ }
25235
+ const olderMatched = new Map(older.sources.map((s) => [s.ecosystem, s.matched]));
25236
+ const cols = tracked.cves.cols;
25237
+ const order = cols.map((c) => older.cves.cols.indexOf(c));
25238
+ const rows = older.cves.rows.filter((r) => !trackedIds.has(r[olderIdCol])).map((r) => order.map((j) => j < 0 ? null : r[j]));
25239
+ return {
25240
+ ...tracked,
25241
+ sources: tracked.sources.map((s) => ({
25242
+ ...s,
25243
+ matched: s.matched + (olderMatched.get(s.ecosystem) ?? 0)
25244
+ })),
25245
+ distinct: {
25246
+ advisories: Math.max(tracked.distinct.advisories, older.distinct.advisories),
25247
+ matched: tracked.distinct.matched + older.distinct.matched
25248
+ },
25249
+ cves: {
25250
+ cols,
25251
+ rows: [...tracked.cves.rows, ...rows]
25252
+ },
25253
+ packages
25254
+ };
25255
+ }
25256
+ // site/src/check/match.ts
25257
+ /**
25258
+ * Matches parsed packages against v1/packages.json: which tracked CVEs affect which versions.
25259
+ *
25260
+ * The rule is OSV's, through shared/versions.ts (the pipeline uses the same code): a version is
25261
+ * affected when an advisory lists it or one of its ranges contains it. Anything that cannot be
25262
+ * compared is "possibly affected", never clean. Lookups go through Maps built once from the file,
25263
+ * so a package named `__proto__` or `constructor` cannot reach Object.prototype.
25264
+ */
25265
+ /** "Debian/12": how a distro release is named in OsCoverage. */
25266
+ var osTag = (eco, release) => `${eco}/${release}`;
25267
+ var NOT_CHECKED_ORDER = [
25268
+ "eco-down",
25269
+ "os-eol",
25270
+ "os-unknown",
25271
+ "os-release",
25272
+ "os-kernel",
25273
+ "ecosystem",
25274
+ "no-purl",
25275
+ "bad-purl",
25276
+ "not-registry",
25277
+ "dev-branch",
25278
+ "go-stdlib"
25279
+ ];
25280
+ /** The fixed version the matching range names next above `version`, if any. */
25281
+ function fixedIn(eco, version, ranges) {
25282
+ const c = COMPARATORS[eco];
25283
+ const v = c.parse(version);
25284
+ if (v === null) return null;
25285
+ for (const range of ranges) {
25286
+ if (compileRanges(eco, [range])(version) !== true) continue;
25287
+ let best = null;
25288
+ for (const e of range) {
25289
+ const p = parseEvent(e);
25290
+ if (p?.op !== "<") continue;
25291
+ const key = c.parse(p.v);
25292
+ if (key !== null && c.cmp(key, v) > 0 && (best === null || c.cmp(key, best.key) < 0)) best = {
25293
+ key,
25294
+ text: p.v
25295
+ };
25296
+ }
25297
+ if (best) return best.text;
25298
+ }
25299
+ return null;
25300
+ }
25301
+ var isAffect = (a) => Array.isArray(a) && typeof a[0] === "string" && typeof a[1] === "string" && Array.isArray(a[2]);
25302
+ var GO_MAJOR = /^v[0-9]+$/;
25303
+ /**
25304
+ * Go paths an advisory names that may belong to a module in the file: the same path in other
25305
+ * letter case, and paths inside the module. A path belongs to the longest module of the file that
25306
+ * is a prefix of it (Go's rule), never across a /vN major-version element, which starts another
25307
+ * module. Prefixes compare in any letter case, so a lowercased package URL of a module owns the
25308
+ * paths inside it too. Built once per check from the file's own Go modules.
25309
+ */
25310
+ function goLookups(go, modules) {
25311
+ const lower = /* @__PURE__ */ new Map();
25312
+ const inside = /* @__PURE__ */ new Map();
25313
+ const add = (m, k, v) => {
25314
+ const list = m.get(k);
25315
+ if (list) list.push(v);
25316
+ else m.set(k, [v]);
25317
+ };
25318
+ const byLower = /* @__PURE__ */ new Map();
25319
+ for (const m of modules) add(byLower, m.toLowerCase(), m);
25320
+ for (const [key, list] of go) {
25321
+ if (!Array.isArray(list)) continue;
25322
+ add(lower, key.toLowerCase(), {
25323
+ key,
25324
+ list,
25325
+ reason: "name-case"
25326
+ });
25327
+ if (byLower.has(key.toLowerCase())) continue;
25328
+ const parts = key.split("/");
25329
+ for (let i = parts.length - 1; i > 0; i--) {
25330
+ if (GO_MAJOR.test(parts[i])) break;
25331
+ const owners = byLower.get(parts.slice(0, i).join("/").toLowerCase());
25332
+ if (owners) {
25333
+ for (const owner of owners) add(inside, owner, {
25334
+ key,
25335
+ list,
25336
+ reason: "go-package"
25337
+ });
25338
+ break;
25339
+ }
25340
+ }
25341
+ }
25342
+ return {
25343
+ lower,
25344
+ inside
25345
+ };
25346
+ }
25347
+ /** The key a component has in the index: its package key, after its release for a distro package. */
25348
+ var keyOf = (c, eco) => isOsEcosystem(eco) ? osPackageKey(c.release ?? "", c.name) : packageKey(eco, c.name);
25349
+ /** Check every package of `parsed` against the index. Pure: no I/O. */
25350
+ function checkComponents(parsed, file, os = null) {
25351
+ const rows = new Map(rowsFromTable(file.cves).map((r) => [r.id, r]));
25352
+ const index = /* @__PURE__ */ new Map();
25353
+ const ok = new Set(file.sources.filter((s) => s.ok).map((s) => s.ecosystem));
25354
+ for (const eco of ALL_ECOSYSTEMS) {
25355
+ const pkgs = file.packages?.[eco];
25356
+ if (ok.has(eco) && typeof pkgs === "object" && pkgs !== null) index.set(eco, new Map(Object.entries(pkgs)));
25357
+ }
25358
+ const distinct = /* @__PURE__ */ new Map();
25359
+ const binaries = /* @__PURE__ */ new Map();
25360
+ for (const c of parsed.components) {
25361
+ const k = [
25362
+ c.eco ?? `~${c.type ?? ""}`,
25363
+ c.eco ? keyOf(c, c.eco) : c.name,
25364
+ c.version ?? "",
25365
+ c.skip ?? c.noVersion ?? ""
25366
+ ].join("\0");
25367
+ if (!distinct.get(k)) distinct.set(k, c.eco && isOsEcosystem(c.eco) ? { ...c } : c);
25368
+ if (c.eco && isOsEcosystem(c.eco)) {
25369
+ const list = binaries.get(k) ?? [];
25370
+ if (!list.includes(c.binary ?? c.name)) list.push(c.binary ?? c.name);
25371
+ binaries.set(k, list);
25372
+ }
25373
+ }
25374
+ for (const [k, list] of binaries) {
25375
+ const c = distinct.get(k);
25376
+ if (list.length === 1 && list[0] === c.name) delete c.binary;
25377
+ else c.binary = list.join(", ");
25378
+ }
25379
+ const goIndex = index.get("Go");
25380
+ const goModules = /* @__PURE__ */ new Set();
25381
+ for (const c of distinct.values()) if (c.eco === "Go" && !c.skip) goModules.add(packageKey("Go", c.name));
25382
+ const go = goIndex ? goLookups(goIndex, goModules) : null;
25383
+ const notChecked = /* @__PURE__ */ new Map();
25384
+ const skip = (reason, c, eco, release) => {
25385
+ const k = `${reason}:${eco ?? ""}:${release ?? ""}`;
25386
+ let g = notChecked.get(k);
25387
+ if (!g) notChecked.set(k, g = release === void 0 ? {
25388
+ reason,
25389
+ eco,
25390
+ items: []
25391
+ } : {
25392
+ reason,
25393
+ eco,
25394
+ release,
25395
+ items: []
25396
+ });
25397
+ g.items.push(c);
25398
+ };
25399
+ const byCve = /* @__PURE__ */ new Map();
25400
+ const clean = [];
25401
+ const affectedKeys = /* @__PURE__ */ new Set();
25402
+ const possibleKeys = /* @__PURE__ */ new Set();
25403
+ for (const c of distinct.values()) {
25404
+ if (c.skip || !c.eco) {
25405
+ skip(c.skip ?? "ecosystem", c);
25406
+ continue;
25407
+ }
25408
+ const eco = c.eco;
25409
+ if (isOsEcosystem(eco)) {
25410
+ const release = c.release ?? "";
25411
+ if (isKernelSource(c.name)) {
25412
+ skip("os-kernel", c, eco, release);
25413
+ continue;
25414
+ }
25415
+ const tag = osTag(eco, release);
25416
+ if (!os || !os.loaded.has(tag)) {
25417
+ skip(!os || os.failed.has(tag) ? "eco-down" : os.notFollowed.has(tag) ? "os-eol" : "os-unknown", c, eco, release);
25418
+ continue;
25419
+ }
25420
+ }
25421
+ const pkgs = index.get(eco);
25422
+ if (!pkgs) {
25423
+ skip("eco-down", c, eco);
25424
+ continue;
25425
+ }
25426
+ const key = keyOf(c, eco);
25427
+ const found = pkgs.get(key);
25428
+ const exact = Array.isArray(found) ? found : void 0;
25429
+ const lookups = exact ? [{
25430
+ key,
25431
+ list: exact,
25432
+ reason: null
25433
+ }] : [];
25434
+ if (eco === "Go" && go) {
25435
+ if (!exact) lookups.push(...go.lower.get(key.toLowerCase()) ?? []);
25436
+ lookups.push(...go.inside.get(key) ?? []);
25437
+ }
25438
+ const named = new Set((exact ?? []).filter(isAffect).map((a) => a[0]));
25439
+ const perCve = /* @__PURE__ */ new Map();
25440
+ for (const via of lookups) for (const a of via.list) {
25441
+ if (!isAffect(a)) continue;
25442
+ const [cve, id, ranges, versions = []] = a;
25443
+ if (via.reason && named.has(cve)) continue;
25444
+ const verdict = matchAffect(eco, c.version, ranges, versions);
25445
+ if (verdict === "not_affected") continue;
25446
+ let e = perCve.get(cve);
25447
+ if (e && e.via !== via) continue;
25448
+ if (!e) perCve.set(cve, e = {
25449
+ affected: [],
25450
+ unchecked: [],
25451
+ via
25452
+ });
25453
+ const listed = c.version !== null && versions.includes(c.version);
25454
+ const hit = {
25455
+ id,
25456
+ ranges,
25457
+ versions,
25458
+ listed,
25459
+ fixedIn: verdict === "affected" && c.version !== null && !listed ? fixedIn(eco, c.version, ranges) : null
25460
+ };
25461
+ (verdict === "affected" ? e.affected : e.unchecked).push(hit);
25462
+ }
25463
+ const id = `${eco}\u0000${key}\u0000${c.version ?? ""}`;
25464
+ let any = false;
25465
+ for (const [cve, e] of perCve) {
25466
+ if (!rows.has(cve)) continue;
25467
+ any = true;
25468
+ const inRange = e.affected.length > 0;
25469
+ const affected = inRange && e.via.reason === null;
25470
+ const unchecked = affected ? null : e.via.reason ?? c.noVersion ?? (c.version !== null && COMPARATORS[eco].parse(c.version) === null ? "version" : "range");
25471
+ let hits = byCve.get(cve);
25472
+ if (!hits) byCve.set(cve, hits = []);
25473
+ const hit = {
25474
+ eco,
25475
+ name: c.name,
25476
+ version: c.version,
25477
+ unchecked,
25478
+ advisories: inRange ? e.affected : e.unchecked
25479
+ };
25480
+ if (c.release) hit.release = c.release;
25481
+ if (c.binary) hit.binary = c.binary;
25482
+ if (e.via.reason) hit.named = e.via.key;
25483
+ hits.push(hit);
25484
+ (affected ? affectedKeys : possibleKeys).add(id);
25485
+ }
25486
+ if (!any) clean.push(c);
25487
+ }
25488
+ const cves = [];
25489
+ for (const [cve, packages] of byCve) {
25490
+ const row = rows.get(cve);
25491
+ if (row) cves.push({
25492
+ row,
25493
+ affected: packages.some((p) => p.unchecked === null),
25494
+ packages
25495
+ });
25496
+ }
25497
+ for (const k of affectedKeys) possibleKeys.delete(k);
25498
+ const groups = [...notChecked.values()].sort((a, b) => NOT_CHECKED_ORDER.indexOf(a.reason) - NOT_CHECKED_ORDER.indexOf(b.reason) || (a.eco ?? "").localeCompare(b.eco ?? ""));
25499
+ const skipped = groups.reduce((n, g) => n + g.items.length, 0);
25500
+ return {
25501
+ format: parsed.format,
25502
+ total: parsed.components.length,
25503
+ distinct: distinct.size,
25504
+ checked: distinct.size - skipped,
25505
+ indexCves: rows.size,
25506
+ cves,
25507
+ affectedPackages: affectedKeys.size,
25508
+ possiblePackages: possibleKeys.size,
25509
+ notChecked: groups,
25510
+ clean,
25511
+ notes: parsed.notes
25512
+ };
25513
+ }
25514
+ var GROUP_ORDER = [
25515
+ "exploited",
25516
+ "likely",
25517
+ "watch",
25518
+ "quiet",
25519
+ "possible"
25520
+ ];
25521
+ /** CVEs grouped by tier at `knob` (possibly affected ones apart), each group by score, then newest. */
25522
+ function groupByTier(cves, knob) {
25523
+ const out = new Map(GROUP_ORDER.map((g) => [g, []]));
25524
+ for (const c of cves) out.get(c.affected ? tierFor(c.row.s, c.row.x === 1, c.row.w === 1, knob) : "possible").push(c);
25525
+ for (const list of out.values()) list.sort((a, b) => b.row.s - a.row.s || b.row.pub.localeCompare(a.row.pub) || a.row.id.localeCompare(b.row.id));
25526
+ return out;
25527
+ }
25528
+ // cli/src/data.ts
25529
+ /** A packages.json that matches the contract well enough to match against; else the reason it does not. */
25530
+ function checkPackagesFile(doc) {
25531
+ if (typeof doc !== "object" || doc === null || Array.isArray(doc)) return "not a JSON object";
25532
+ const d = doc;
25533
+ if (d.schema_version !== 1) return `schema_version ${String(d.schema_version)}, this tool reads 1`;
25534
+ if (typeof d.generated_at !== "string" || Number.isNaN(Date.parse(d.generated_at))) return "no generated_at";
25535
+ if (!Array.isArray(d.sources)) return "no sources";
25536
+ if (!d.cves || !Array.isArray(d.cves.cols) || d.cves.cols.join() !== ROW_COLS.join() || !Array.isArray(d.cves.rows)) return "cves columns do not match";
25537
+ if (typeof d.packages !== "object" || d.packages === null) return "no packages";
25538
+ return d;
25539
+ }
24286
25540
  // mcp/src/data.ts
24287
25541
  /**
24288
25542
  * Reads the published data tree (shared/contract.ts) for the MCP tools.
@@ -24336,7 +25590,7 @@ function isEvent(i) {
24336
25590
  function need(ok, why) {
24337
25591
  if (!ok) throw new BadData(why);
24338
25592
  }
24339
- var parse = {
25593
+ var parse$1 = {
24340
25594
  meta: (j) => {
24341
25595
  need(isObject(j.window) && Array.isArray(j.sources) && typeof j.knob_default === "number", "missing window, sources or knob_default");
24342
25596
  return j;
@@ -24372,6 +25626,16 @@ var parse = {
24372
25626
  need(j.items.every(isEvent), "an item has a field of the wrong type");
24373
25627
  return j;
24374
25628
  },
25629
+ /** packages.json and packages-older.json: the shape the matcher needs, with the exact row columns. */
25630
+ osIndex: (j) => {
25631
+ need(Array.isArray(j.releases) && Array.isArray(j.sources), "missing releases or sources");
25632
+ return j;
25633
+ },
25634
+ packages: (j) => {
25635
+ const checked = checkPackagesFile(j);
25636
+ need(typeof checked !== "string", typeof checked === "string" ? checked : "");
25637
+ return checked;
25638
+ },
24375
25639
  receipts: (j) => {
24376
25640
  need(isObject(j.forward) && Array.isArray(j.forward.items), "forward log missing");
24377
25641
  return j;
@@ -24434,6 +25698,11 @@ var DataClient = class {
24434
25698
  /** Fetches in progress, shared by concurrent calls, with the signal of the call that started each. */
24435
25699
  inflight = /* @__PURE__ */ new Map();
24436
25700
  skipUntil = /* @__PURE__ */ new Map();
25701
+ /** Each running call's deadline, for the messages that name it. */
25702
+ deadlines = /* @__PURE__ */ new WeakMap();
25703
+ deadlineOf(signal) {
25704
+ return this.deadlines.get(signal) ?? this.o.callTimeoutMs;
25705
+ }
24437
25706
  /** Requests sent, for tests and measurements. */
24438
25707
  requests = 0;
24439
25708
  constructor(opts) {
@@ -24457,9 +25726,11 @@ var DataClient = class {
24457
25726
  * Runs one tool call under its deadline. When the call ends, anything it left in flight (a
24458
25727
  * shard fetch after another one failed) is aborted, so nothing keeps running between calls.
24459
25728
  */
24460
- async run(fn) {
25729
+ /** Run one tool call under a deadline: callTimeoutMs, or `timeoutMs` for a tool that reads larger files. */
25730
+ async run(fn, timeoutMs = this.o.callTimeoutMs) {
24461
25731
  const ac = new AbortController();
24462
- const timer = setTimeout(() => ac.abort(new Deadline()), this.o.callTimeoutMs);
25732
+ this.deadlines.set(ac.signal, timeoutMs);
25733
+ const timer = setTimeout(() => ac.abort(new Deadline()), timeoutMs);
24463
25734
  try {
24464
25735
  return await fn(new DataCall(this, ac.signal));
24465
25736
  } finally {
@@ -24546,7 +25817,7 @@ var DataClient = class {
24546
25817
  };
24547
25818
  } catch (e) {
24548
25819
  if (e instanceof DataError) throw e;
24549
- if (signal.aborted) throw new DataError(MCP_MSG.deadline([...reasons, `${host(url)}: no answer within ${this.o.callTimeoutMs / 1e3} s for ${path}`]), reasons);
25820
+ if (signal.aborted) throw new DataError(MCP_MSG.deadline([...reasons, `${host(url)}: no answer within ${this.deadlineOf(signal) / 1e3} s for ${path}`]), reasons);
24550
25821
  if (e instanceof AttemptTimeout) this.skipUntil.set(base, this.o.now() + this.o.skipMs);
24551
25822
  reasons.push(`${host(url)}: ${e instanceof SyntaxError ? "not valid JSON" : why(e)} for ${path}`);
24552
25823
  }
@@ -24585,7 +25856,7 @@ var DataClient = class {
24585
25856
  return await (stop ? Promise.race([f.p, stop.promise]) : f.p);
24586
25857
  } catch (err) {
24587
25858
  if (joined && f.signal.aborted && !signal.aborted && !(err instanceof DataUnavailable) && !(err instanceof SchemaMismatch)) return this.load(path, parser, gen, signal);
24588
- const e = joined && signal.aborted && !(err instanceof DataError) ? new DataError(MCP_MSG.deadline([`no answer within ${this.o.callTimeoutMs / 1e3} s for ${path}`])) : err;
25859
+ const e = joined && signal.aborted && !(err instanceof DataError) ? new DataError(MCP_MSG.deadline([`no answer within ${this.deadlineOf(signal) / 1e3} s for ${path}`])) : err;
24589
25860
  if (!hit || e instanceof DataUnavailable || e instanceof SchemaMismatch || !(e instanceof DataError)) throw e;
24590
25861
  hit.checkedAt = this.o.now();
24591
25862
  hit.warning = MCP_MSG.refreshFailed(e.reasons.length ? e.reasons : ["no answer in time"], new Date(hit.loadedAt).toISOString());
@@ -24616,7 +25887,7 @@ var DataCall = class {
24616
25887
  return e.value;
24617
25888
  }
24618
25889
  async meta() {
24619
- this.metaEntry ??= await this.dc.load("meta.json", parse.meta, null, this.signal);
25890
+ this.metaEntry ??= await this.dc.load("meta.json", parse$1.meta, null, this.signal);
24620
25891
  return this.use("meta.json", this.metaEntry);
24621
25892
  }
24622
25893
  async file(path, parser) {
@@ -24630,7 +25901,7 @@ var DataCall = class {
24630
25901
  const queue = [...new Set(names)];
24631
25902
  const entries = /* @__PURE__ */ new Map();
24632
25903
  const worker = async () => {
24633
- for (let name = queue.shift(); name !== void 0; name = queue.shift()) entries.set(name, await this.dc.load(`cve/${name}.json`, parse.shard, meta.generated_at, this.signal));
25904
+ for (let name = queue.shift(); name !== void 0; name = queue.shift()) entries.set(name, await this.dc.load(`cve/${name}.json`, parse$1.shard, meta.generated_at, this.signal));
24634
25905
  };
24635
25906
  await Promise.all(Array.from({ length: Math.min(this.dc.shardConcurrency, queue.length) }, worker));
24636
25907
  for (const name of [...new Set(names)]) {
@@ -24758,60 +26029,1415 @@ function matchesName(list, vendor, product) {
24758
26029
  if (list.length === 0) return false;
24759
26030
  return vendor !== "" && list.includes(normalizeName(vendor)) || product !== "" && list.includes(normalizeName(product));
24760
26031
  }
24761
- // mcp/src/tools.ts
24762
- /**
24763
- * The MCP tools as plain functions over the published files: (call, args, now) -> result.
24764
- * No SDK imports, so they are unit-tested with a fake fetch. Every result starts with `data`, which
24765
- * names the run and every file the answer came from (McpData in shared/contract.ts).
24766
- */
24767
- /** A request the tool cannot answer as asked (isError: true). A filter is never silently dropped. */
24768
- var InputError = class extends Error {};
24769
- var LIMITS = {
24770
- ids: 15,
24771
- detailIds: 5,
24772
- page: 50,
24773
- offset: 1e5,
24774
- queryWords: 8,
24775
- withinDays: 60,
24776
- overdueDays: 14,
24777
- names: 200,
24778
- nameChars: 80,
24779
- perName: 25
26032
+ /** Why a file could not be read. `detail` quotes the file (the JSON error), so it is rendered as file text. */
26033
+ var ParseError = class extends Error {
26034
+ kind;
26035
+ detail;
26036
+ constructor(kind, detail = "") {
26037
+ super(parseErrorText(kind, detail));
26038
+ this.kind = kind;
26039
+ this.detail = detail;
26040
+ this.name = "ParseError";
26041
+ }
24780
26042
  };
24781
- /** Bytes of JSON check_inventory answers with at most (about 17,000 tokens); the least urgent CVEs are left out to fit. */
24782
- var INVENTORY_BUDGET = 61440;
24783
- var DAY_MS = 864e5;
24784
- var TITLE_MAX = 160;
24785
- /** Pipeline event details run to about 120 characters; a mirror may send more. */
24786
- var DETAIL_MAX = 300;
24787
- /** UTC date or date-time: anchored, no nested quantifiers; applied after a length cap of 30. */
24788
- var DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?Z)?$/;
24789
- /** Milliseconds for a DATE_RE string, or NaN when it does not match or does not exist (2026-02-30). */
24790
- function parseUtc(s) {
24791
- if (s.length > 30 || !DATE_RE.test(s)) return NaN;
24792
- const ms = Date.parse(s);
24793
- if (Number.isNaN(ms)) return NaN;
24794
- const iso = new Date(ms).toISOString();
24795
- if (iso.slice(0, 10) !== s.slice(0, 10) || s.length > 10 && iso.slice(11, 16) !== s.slice(11, 16)) return NaN;
24796
- return ms;
26043
+ /** Build files people try first, which name the versions asked for, not the ones installed. */
26044
+ var MANIFEST_TEXT = /* @__PURE__ */ new Map([
26045
+ ["pom", "pom.xml lists the versions you ask for, not the ones your build resolves. Make an SBOM instead: mvn org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom (it writes target/bom.json)."],
26046
+ ["gradle", "build.gradle lists the versions you ask for, not the ones your build resolves. Make an SBOM with the CycloneDX Gradle plugin (gradle cyclonedxBom), or check gradle.lockfile with dependency locking turned on."],
26047
+ ["npm", "package.json lists version ranges, not the versions you install. Check package-lock.json, yarn.lock or pnpm-lock.yaml instead, or make an SBOM: npm sbom --sbom-format cyclonedx."]
26048
+ ]);
26049
+ function parseErrorText(kind, detail = "") {
26050
+ if (kind === "json") return `This looks like JSON, but it could not be read: ${detail}. Check that the whole file was pasted.`;
26051
+ if (kind === "manifest") return MANIFEST_TEXT.get(detail) ?? parseErrorText("unknown");
26052
+ if (kind === "unknown") return "We could not tell what kind of file this is. Pick it under Read as, or see the accepted files below.";
26053
+ return "No packages found in this file.";
26054
+ }
26055
+ var MAX_PURL = 2048;
26056
+ var GO_SUM_NOTE = "go.sum can list module versions your build does not use, so this may show versions you do not run. go.mod is more exact.";
26057
+ var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
26058
+ var str = (v) => typeof v === "string" && v.trim() !== "" ? v.trim() : null;
26059
+ var entries = (v) => isObj(v) ? Object.entries(v) : [];
26060
+ function decode(s) {
26061
+ try {
26062
+ return decodeURIComponent(s);
26063
+ } catch {
26064
+ return s;
26065
+ }
24797
26066
  }
24798
- function dateArg(field, s) {
24799
- const ms = parseUtc(s);
24800
- if (Number.isNaN(ms)) throw new InputError(MCP_MSG.badDate(field));
24801
- return ms;
26067
+ function unquote(s) {
26068
+ const t = s.trim();
26069
+ return t.length >= 2 && (t[0] === "\"" || t[0] === "'") && t[t.length - 1] === t[0] ? t.slice(1, -1) : t;
24802
26070
  }
24803
- var oneLine = (s) => s.replace(/\s+/g, " ").trim();
24804
- var cut = (s, max) => s.length <= max ? s : `${s.slice(0, max - 1).trimEnd()}…`;
24805
- var cveOrg = (id) => `https://www.cve.org/CVERecord?id=${id}`;
24806
- /** Highest score first, then newest, then id: the pipeline's order (byScoreThenNewest). */
24807
- var byScore = (a, b) => b.s - a.s || b.pub.localeCompare(a.pub) || a.id.localeCompare(b.id);
24808
- function mcpRow(r, knob) {
24809
- return {
24810
- id: r.id,
24811
- tier: tierFor(r.s, r.x === 1, r.w === 1, knob),
24812
- score: r.s,
24813
- published: r.pub,
24814
- cna: r.cna,
26071
+ /** Lines of a line-oriented format; lines over MAX_LINE are skipped and counted. */
26072
+ function lines(text, notes) {
26073
+ const out = [];
26074
+ let long = 0;
26075
+ for (const raw of text.split("\n")) {
26076
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
26077
+ if (line.length > 65536) long++;
26078
+ else out.push(line);
26079
+ }
26080
+ if (long) notes.push(`Skipped ${long === 1 ? "a line" : `${long} lines`} longer than 64 KB.`);
26081
+ return out;
26082
+ }
26083
+ /** The qualifiers of a package URL, by lowercased key; the last of a repeated key wins. */
26084
+ function purlQualifiers(query) {
26085
+ const out = /* @__PURE__ */ new Map();
26086
+ for (const pair of query.split("&")) {
26087
+ const eq = pair.indexOf("=");
26088
+ if (eq > 0) out.set(pair.slice(0, eq).toLowerCase(), decode(pair.slice(eq + 1)));
26089
+ }
26090
+ return out;
26091
+ }
26092
+ /**
26093
+ * A Debian, Ubuntu or Alpine package: the source package (Syft's `upstream=name` or
26094
+ * `upstream=name@version`, or Trivy's SrcName) and the version to compare (the source version when
26095
+ * given, else the installed one, with the `epoch` qualifier put back when the version lacks it).
26096
+ */
26097
+ function osComponent(eco, binary, version, q, src) {
26098
+ const upstream = q.get("upstream") ?? "";
26099
+ const at = upstream.indexOf("@");
26100
+ const sourceName = str(src?.name) ?? str(at >= 0 ? upstream.slice(0, at) : upstream);
26101
+ const sourceVersion = str(src?.version) ?? (at >= 0 ? str(upstream.slice(at + 1)) : null);
26102
+ const epoch = q.get("epoch");
26103
+ let v = sourceVersion ?? version;
26104
+ if (v && eco !== "Alpine" && epoch && /^[1-9]\d{0,8}$/.test(epoch) && !v.includes(":")) v = `${epoch}:${v}`;
26105
+ const name = sourceName ?? binary;
26106
+ const c = {
26107
+ eco,
26108
+ name,
26109
+ version: v,
26110
+ release: osRelease(eco, q.get("distro"))
26111
+ };
26112
+ if (name !== binary) c.binary = binary;
26113
+ if (v === null) c.noVersion = "no-version";
26114
+ return c;
26115
+ }
26116
+ /** A package URL (`pkg:type/namespace/name@version?qualifiers#subpath`) as a component; null when malformed. */
26117
+ function purlComponent(raw, src = null) {
26118
+ const full = raw.trim();
26119
+ if (full.length > MAX_PURL || full.slice(0, 4).toLowerCase() !== "pkg:") return null;
26120
+ let s = full.slice(4);
26121
+ while (s.startsWith("/")) s = s.slice(1);
26122
+ const hash = s.indexOf("#");
26123
+ if (hash >= 0) s = s.slice(0, hash);
26124
+ const query = s.indexOf("?");
26125
+ const qualifiers = query >= 0 ? s.slice(query + 1) : "";
26126
+ if (query >= 0) s = s.slice(0, query);
26127
+ const slash = s.indexOf("/");
26128
+ if (slash <= 0) return null;
26129
+ const type = s.slice(0, slash).toLowerCase();
26130
+ if (!/^[a-z][a-z0-9.+-]{0,31}$/.test(type)) return null;
26131
+ let rest = s.slice(slash + 1);
26132
+ while (rest.endsWith("/")) rest = rest.slice(0, -1);
26133
+ let version = null;
26134
+ const at = rest.lastIndexOf("@");
26135
+ if (at > 0 && at > rest.lastIndexOf("/")) {
26136
+ version = str(decode(rest.slice(at + 1)));
26137
+ rest = rest.slice(0, at);
26138
+ }
26139
+ const parts = rest.split("/").filter(Boolean).map(decode);
26140
+ if (parts.length === 0) return null;
26141
+ const name = parts[parts.length - 1];
26142
+ const ns = parts.slice(0, -1);
26143
+ const os = osEcosystemOfPurl(type, ns[0] ?? null);
26144
+ if (os) return osComponent(os, name, version, purlQualifiers(qualifiers), src);
26145
+ const eco = ecosystemOfPurlType(type);
26146
+ if (!eco) return {
26147
+ eco: null,
26148
+ type,
26149
+ name: parts.join("/"),
26150
+ version,
26151
+ skip: "ecosystem"
26152
+ };
26153
+ let pkgName;
26154
+ if (eco === "npm") pkgName = ns.length ? `${ns[0].startsWith("@") ? "" : "@"}${ns.join("/")}/${name}` : name;
26155
+ else if (eco === "Maven") pkgName = ns.length ? `${ns.join(".")}:${name}` : name;
26156
+ else pkgName = parts.join("/");
26157
+ if (eco === "Go" && (pkgName === "stdlib" || pkgName === "toolchain") && version?.startsWith("go")) version = version.slice(2);
26158
+ return version === null ? {
26159
+ eco,
26160
+ name: pkgName,
26161
+ version: null,
26162
+ noVersion: "no-version"
26163
+ } : {
26164
+ eco,
26165
+ name: pkgName,
26166
+ version
26167
+ };
26168
+ }
26169
+ /** An SBOM entry: its package URL when there is one, otherwise "not checked" under its own name. */
26170
+ function sbomEntry(purl, name, version, src = null) {
26171
+ const ver = str(version);
26172
+ const p = str(purl);
26173
+ if (p) {
26174
+ const c = purlComponent(p, src);
26175
+ if (c) {
26176
+ if (c.version === null && c.eco && ver) return {
26177
+ eco: c.eco,
26178
+ name: c.name,
26179
+ version: ver
26180
+ };
26181
+ return c;
26182
+ }
26183
+ return {
26184
+ eco: null,
26185
+ name: str(name) ?? p,
26186
+ version: ver,
26187
+ skip: "bad-purl"
26188
+ };
26189
+ }
26190
+ return {
26191
+ eco: null,
26192
+ name: str(name) ?? "(no name)",
26193
+ version: ver,
26194
+ skip: "no-purl"
26195
+ };
26196
+ }
26197
+ /** Trivy's source package properties on a CycloneDX component (SrcName, SrcVersion, SrcRelease, SrcEpoch). */
26198
+ function trivySource(props) {
26199
+ if (!Array.isArray(props)) return null;
26200
+ const get = (k) => {
26201
+ const p = props.find((x) => isObj(x) && x.name === `aquasecurity:trivy:${k}`);
26202
+ return isObj(p) ? str(p.value) : null;
26203
+ };
26204
+ const name = get("SrcName");
26205
+ const version = get("SrcVersion");
26206
+ if (!name && !version) return null;
26207
+ const release = get("SrcRelease");
26208
+ const epoch = get("SrcEpoch");
26209
+ return {
26210
+ name,
26211
+ version: version ? `${epoch && epoch !== "0" ? `${epoch}:` : ""}${version}${release ? `-${release}` : ""}` : null
26212
+ };
26213
+ }
26214
+ function cyclonedxJson(doc, os) {
26215
+ const out = [];
26216
+ const meta = isObj(doc.metadata) ? doc.metadata : null;
26217
+ const stack = [doc.components, meta && isObj(meta.component) ? [meta.component] : null];
26218
+ while (stack.length) {
26219
+ const list = stack.pop();
26220
+ if (!Array.isArray(list)) continue;
26221
+ for (const c of list) {
26222
+ if (!isObj(c)) continue;
26223
+ const group = str(c.group);
26224
+ const name = str(c.name);
26225
+ if (str(c.type) === "operating-system") {
26226
+ const eco = name ? osEcosystemOfName(name) : null;
26227
+ if (eco && os) os.push({
26228
+ eco,
26229
+ release: osRelease(eco, str(c.version))
26230
+ });
26231
+ if (c.components) stack.push(c.components);
26232
+ continue;
26233
+ }
26234
+ out.push(sbomEntry(c.purl, group && name ? `${group}/${name}` : name, c.version, trivySource(c.properties)));
26235
+ if (c.components) stack.push(c.components);
26236
+ }
26237
+ }
26238
+ return out;
26239
+ }
26240
+ function spdxJson(doc, os) {
26241
+ const out = [];
26242
+ if (Array.isArray(doc.packages)) for (const p of doc.packages) {
26243
+ if (!isObj(p)) continue;
26244
+ if (str(p.primaryPackagePurpose) === "OPERATING-SYSTEM") {
26245
+ const eco = osEcosystemOfName(str(p.name) ?? "");
26246
+ if (eco && os) os.push({
26247
+ eco,
26248
+ release: osRelease(eco, str(p.versionInfo))
26249
+ });
26250
+ continue;
26251
+ }
26252
+ const ref = (Array.isArray(p.externalRefs) ? p.externalRefs : []).find((r) => isObj(r) && typeof r.referenceType === "string" && r.referenceType.toLowerCase() === "purl");
26253
+ out.push(sbomEntry(isObj(ref) ? ref.referenceLocator : null, p.name, p.versionInfo));
26254
+ }
26255
+ if (Array.isArray(doc["@graph"])) for (const e of doc["@graph"]) {
26256
+ if (!isObj(e)) continue;
26257
+ if ((str(e.type) ?? str(e["@type"])) !== "software_Package") continue;
26258
+ const id = (Array.isArray(e.externalIdentifier) ? e.externalIdentifier : []).find((x) => isObj(x) && x.externalIdentifierType === "packageUrl");
26259
+ out.push(sbomEntry(e.software_packageUrl ?? (isObj(id) ? id.identifier : null), e.name, e.software_packageVersion));
26260
+ }
26261
+ return out;
26262
+ }
26263
+ function spdxTag(text, notes) {
26264
+ const out = [];
26265
+ let cur = null;
26266
+ let inText = false;
26267
+ const flush = () => cur && out.push(sbomEntry(cur.purl, cur.name, cur.version));
26268
+ for (const line of lines(text, notes)) {
26269
+ if (inText) {
26270
+ if (line.includes("</text>")) inText = false;
26271
+ continue;
26272
+ }
26273
+ const colon = line.indexOf(":");
26274
+ if (colon <= 0) continue;
26275
+ const tag = line.slice(0, colon).trim();
26276
+ const value = line.slice(colon + 1).trim();
26277
+ if (value.startsWith("<text>") && !value.includes("</text>")) {
26278
+ inText = true;
26279
+ continue;
26280
+ }
26281
+ if (tag === "PackageName") {
26282
+ flush();
26283
+ cur = {
26284
+ name: value,
26285
+ version: null,
26286
+ purl: null
26287
+ };
26288
+ } else if (cur && tag === "PackageVersion") cur.version = value;
26289
+ else if (cur && tag === "ExternalRef") {
26290
+ const [, type, locator] = value.split(/\s+/);
26291
+ if (type?.toLowerCase() === "purl" && locator) cur.purl = locator;
26292
+ }
26293
+ }
26294
+ flush();
26295
+ return out;
26296
+ }
26297
+ var XML_ENTITIES = /* @__PURE__ */ new Map([
26298
+ ["amp", "&"],
26299
+ ["lt", "<"],
26300
+ ["gt", ">"],
26301
+ ["quot", "\""],
26302
+ ["apos", "'"]
26303
+ ]);
26304
+ /** The five predefined XML entities and numeric references; nothing else is expanded. */
26305
+ function xmlText(s) {
26306
+ return s.replace(/&(#x[0-9a-fA-F]{1,6}|#[0-9]{1,7}|[a-z]{2,4});/g, (whole, ref) => {
26307
+ if (ref[0] !== "#") return XML_ENTITIES.get(ref) ?? whole;
26308
+ const code = ref[1] === "x" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
26309
+ return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
26310
+ });
26311
+ }
26312
+ var XML_TAG = /<(\/?)(?:[A-Za-z_][\w.-]{0,31}:)?([A-Za-z_][\w.-]{0,63})((?:\s[^<>]*?)?)(\/?)>|<!--|<!\[CDATA\[/g;
26313
+ var XML_FIELDS = /* @__PURE__ */ new Set([
26314
+ "group",
26315
+ "name",
26316
+ "version",
26317
+ "purl"
26318
+ ]);
26319
+ var XML_MAX_DEPTH = 256;
26320
+ /**
26321
+ * The same components as CycloneDX JSON: those under the top-level <components> (nested ones
26322
+ * included) and the subject in <metadata>, not the tools in <metadata><tools> or the build
26323
+ * components in <formulation>. Each component's own <group>, <name>, <version> and <purl> are read.
26324
+ */
26325
+ function cyclonedxXml(text) {
26326
+ const found = [];
26327
+ const stack = [];
26328
+ const open = [];
26329
+ let field = null;
26330
+ XML_TAG.lastIndex = 0;
26331
+ for (let m = XML_TAG.exec(text); m; m = XML_TAG.exec(text)) {
26332
+ const [whole, close, local, , self] = m;
26333
+ if (local === void 0) {
26334
+ const end = text.indexOf(whole === "<!--" ? "-->" : "]]>", XML_TAG.lastIndex);
26335
+ if (end < 0) break;
26336
+ XML_TAG.lastIndex = end + 3;
26337
+ continue;
26338
+ }
26339
+ if (close) {
26340
+ const at = stack.lastIndexOf(local);
26341
+ if (at < 0) continue;
26342
+ if (field && field.depth === at && field.name === local) {
26343
+ const value = text.slice(field.start, m.index);
26344
+ const into = open[at - 1];
26345
+ if (into && value.length <= 2048 && !value.includes("<")) into[local] = xmlText(value).trim();
26346
+ }
26347
+ if (field && field.depth >= at) field = null;
26348
+ stack.length = at;
26349
+ open.length = at;
26350
+ continue;
26351
+ }
26352
+ if (self || stack.length >= XML_MAX_DEPTH) continue;
26353
+ const depth = stack.length;
26354
+ stack.push(local);
26355
+ let comp = null;
26356
+ if (local === "component") {
26357
+ let i = depth - 1;
26358
+ while (i >= 0 && (stack[i] === "component" || stack[i] === "components")) i--;
26359
+ if (i < 0 || stack[i] === "bom" || stack[i] === "metadata") found.push(comp = { depth });
26360
+ } else if (XML_FIELDS.has(local) && open[depth - 1]) field = {
26361
+ name: local,
26362
+ start: m.index + whole.length,
26363
+ depth
26364
+ };
26365
+ open.push(comp);
26366
+ }
26367
+ return found.map((c) => sbomEntry(c.purl, c.group && c.name ? `${c.group}/${c.name}` : c.name, c.version));
26368
+ }
26369
+ function purlList(text, notes) {
26370
+ const out = [];
26371
+ let other = 0;
26372
+ for (const line of lines(text, notes)) {
26373
+ const t = line.trim();
26374
+ if (t === "" || t.startsWith("#")) continue;
26375
+ if (t.slice(0, 4).toLowerCase() !== "pkg:") {
26376
+ other++;
26377
+ continue;
26378
+ }
26379
+ out.push(purlComponent(t) ?? {
26380
+ eco: null,
26381
+ name: t,
26382
+ version: null,
26383
+ skip: "bad-purl"
26384
+ });
26385
+ }
26386
+ if (other) notes.push(`Ignored ${other === 1 ? "a line" : `${other} lines`} that ${other === 1 ? "is not a package URL" : "are not package URLs"}.`);
26387
+ return out;
26388
+ }
26389
+ var isRegistryTarball = (url) => /^https?:\/\//i.test(url) && url.split(/[?#]/)[0].toLowerCase().endsWith(".tgz");
26390
+ function npmEntry(name, version, resolved) {
26391
+ const ver = str(version);
26392
+ if (ver === null) return {
26393
+ eco: "npm",
26394
+ name,
26395
+ version: null,
26396
+ noVersion: "no-version"
26397
+ };
26398
+ if (ver.startsWith("npm:")) {
26399
+ const real = ver.slice(4);
26400
+ const at = real.lastIndexOf("@");
26401
+ if (at > 0) return npmEntry(real.slice(0, at), real.slice(at + 1), resolved);
26402
+ }
26403
+ if (/^[a-z][a-z+]*:/i.test(ver) || ver.includes("/") || typeof resolved === "string" && resolved !== "" && !isRegistryTarball(resolved)) return {
26404
+ eco: "npm",
26405
+ name,
26406
+ version: null,
26407
+ skip: "not-registry"
26408
+ };
26409
+ return {
26410
+ eco: "npm",
26411
+ name,
26412
+ version: ver
26413
+ };
26414
+ }
26415
+ function npmLock(doc) {
26416
+ const out = [];
26417
+ if (isObj(doc.packages)) {
26418
+ for (const [path, v] of entries(doc.packages)) {
26419
+ if (path === "" || !isObj(v) || v.link === true) continue;
26420
+ const i = path.lastIndexOf("node_modules/");
26421
+ const name = str(v.name) ?? (i >= 0 ? path.slice(i + 13) : path);
26422
+ if (i < 0) out.push({
26423
+ eco: "npm",
26424
+ name,
26425
+ version: str(v.version),
26426
+ skip: "not-registry"
26427
+ });
26428
+ else out.push(npmEntry(name, v.version, v.resolved));
26429
+ }
26430
+ return out;
26431
+ }
26432
+ const stack = [doc.dependencies];
26433
+ while (stack.length) for (const [name, v] of entries(stack.pop())) {
26434
+ if (!isObj(v)) continue;
26435
+ out.push(npmEntry(name, v.version, v.resolved));
26436
+ if (v.dependencies) stack.push(v.dependencies);
26437
+ }
26438
+ return out;
26439
+ }
26440
+ /** yarn.lock v1 ("version \"1.2.3\"") and Berry ("version: 1.2.3", "resolution: \"name@npm:1.2.3\""). */
26441
+ function yarnLock(text, notes) {
26442
+ const out = [];
26443
+ let head = null;
26444
+ let version = null;
26445
+ let resolution = null;
26446
+ const flush = () => {
26447
+ if (head !== null && head !== "__metadata") out.push(yarnEntry(head, version, resolution));
26448
+ head = version = resolution = null;
26449
+ };
26450
+ for (const line of lines(text, notes)) {
26451
+ if (line === "" || line.startsWith("#")) continue;
26452
+ if (line[0] !== " ") {
26453
+ flush();
26454
+ if (line.endsWith(":")) head = line.slice(0, -1);
26455
+ continue;
26456
+ }
26457
+ if (head === null || line[2] === " ") continue;
26458
+ const m = /^ {2}(version|resolution):? +(\S.*)$/.exec(line);
26459
+ if (!m) continue;
26460
+ if (m[1] === "version") version = unquote(m[2]);
26461
+ else resolution = unquote(m[2]);
26462
+ }
26463
+ flush();
26464
+ return out;
26465
+ }
26466
+ /** "name@range" → [name, range]; the name may start with "@". */
26467
+ function splitDescriptor(d) {
26468
+ const at = d.indexOf("@", 1);
26469
+ return at > 0 ? [d.slice(0, at), d.slice(at + 1)] : [d, ""];
26470
+ }
26471
+ function yarnEntry(head, version, resolution) {
26472
+ if (resolution !== null) {
26473
+ const [name, ref] = splitDescriptor(resolution);
26474
+ if (!(ref.startsWith("npm:") || ref.startsWith("patch:") && (ref.includes("@npm%3A") || ref.includes("@npm:")))) return {
26475
+ eco: "npm",
26476
+ name,
26477
+ version: null,
26478
+ skip: "not-registry"
26479
+ };
26480
+ return version ? {
26481
+ eco: "npm",
26482
+ name,
26483
+ version
26484
+ } : {
26485
+ eco: "npm",
26486
+ name,
26487
+ version: null,
26488
+ noVersion: "no-version"
26489
+ };
26490
+ }
26491
+ let [name, range] = splitDescriptor(unquote(head.split(",")[0]));
26492
+ if (range.startsWith("npm:")) [name, range] = splitDescriptor(range.slice(4));
26493
+ if (/^[a-z][a-z+]*:/i.test(range) || range.includes("/")) return {
26494
+ eco: "npm",
26495
+ name,
26496
+ version: null,
26497
+ skip: "not-registry"
26498
+ };
26499
+ return version ? {
26500
+ eco: "npm",
26501
+ name,
26502
+ version
26503
+ } : {
26504
+ eco: "npm",
26505
+ name,
26506
+ version: null,
26507
+ noVersion: "no-version"
26508
+ };
26509
+ }
26510
+ /** pnpm-lock.yaml v5 ("/name/1.0.0_peer"), v6 ("/name@1.0.0(peer)") and v9 ("name@1.0.0"). */
26511
+ function pnpmLock(text, notes) {
26512
+ const out = [];
26513
+ const seen = /* @__PURE__ */ new Set();
26514
+ let section = "";
26515
+ let major = 9;
26516
+ for (const line of lines(text, notes)) {
26517
+ if (line === "" || line.trimStart().startsWith("#")) continue;
26518
+ if (line[0] !== " ") {
26519
+ section = line.trim();
26520
+ if (section.startsWith("lockfileVersion:")) major = parseFloat(unquote(section.slice(16))) || 9;
26521
+ continue;
26522
+ }
26523
+ if (section !== "packages:" && section !== "snapshots:" || line[2] === " ") continue;
26524
+ let body = line.trim();
26525
+ if (body.endsWith(" {}")) body = body.slice(0, -3);
26526
+ if (!body.endsWith(":")) continue;
26527
+ let key = unquote(body.slice(0, -1));
26528
+ const fromRegistry = major >= 9 || key.startsWith("/");
26529
+ if (key.startsWith("/")) key = key.slice(1);
26530
+ const paren = key.indexOf("(");
26531
+ if (paren > 0) key = key.slice(0, paren);
26532
+ let name;
26533
+ let version;
26534
+ if (major < 6) {
26535
+ const slash = key.lastIndexOf("/");
26536
+ name = key.slice(0, Math.max(0, slash));
26537
+ version = key.slice(slash + 1);
26538
+ const u = version.indexOf("_");
26539
+ if (u > 0) version = version.slice(0, u);
26540
+ } else [name, version] = splitDescriptor(key);
26541
+ if (!name || !fromRegistry || /[:/]/.test(version)) {
26542
+ const id = `?${key}`;
26543
+ if (!seen.has(id)) out.push({
26544
+ eco: "npm",
26545
+ name: name || key,
26546
+ version: null,
26547
+ skip: "not-registry"
26548
+ });
26549
+ seen.add(id);
26550
+ continue;
26551
+ }
26552
+ const id = `${name}@${version}`;
26553
+ if (seen.has(id)) continue;
26554
+ seen.add(id);
26555
+ out.push(version ? {
26556
+ eco: "npm",
26557
+ name,
26558
+ version
26559
+ } : {
26560
+ eco: "npm",
26561
+ name,
26562
+ version: null,
26563
+ noVersion: "no-version"
26564
+ });
26565
+ }
26566
+ return out;
26567
+ }
26568
+ function requirements(text, notes) {
26569
+ const out = [];
26570
+ let includes = 0;
26571
+ let ignored = 0;
26572
+ const joined = [];
26573
+ let buf = "";
26574
+ for (const line of lines(text, notes)) {
26575
+ if (line.endsWith("\\")) {
26576
+ buf += `${line.slice(0, -1)} `;
26577
+ if (buf.length > 65536) buf = "";
26578
+ continue;
26579
+ }
26580
+ joined.push(buf + line);
26581
+ buf = "";
26582
+ }
26583
+ if (buf) joined.push(buf);
26584
+ for (const raw of joined) {
26585
+ const hash = raw.search(/(?:^|\s)#/);
26586
+ const line = (hash >= 0 ? raw.slice(0, hash) : raw).trim();
26587
+ if (line === "") continue;
26588
+ if (line.startsWith("-")) {
26589
+ if (/^(?:-r|-c|--requirement|--constraint)\b/.test(line)) includes++;
26590
+ else if (/^(?:-e|--editable)\b/.test(line)) {
26591
+ const egg = /[#&]egg=([A-Za-z0-9._-]{1,200})/.exec(raw);
26592
+ out.push({
26593
+ eco: "PyPI",
26594
+ name: egg ? egg[1] : line.replace(/^(?:-e|--editable)[\s=]*/, ""),
26595
+ version: null,
26596
+ skip: "not-registry"
26597
+ });
26598
+ }
26599
+ continue;
26600
+ }
26601
+ const m = /^[A-Za-z0-9][A-Za-z0-9._-]*/.exec(line);
26602
+ if (!m) {
26603
+ ignored++;
26604
+ continue;
26605
+ }
26606
+ const name = m[0];
26607
+ let rest = line.slice(name.length).trimStart();
26608
+ if (rest.startsWith("[")) {
26609
+ const close = rest.indexOf("]");
26610
+ rest = close >= 0 ? rest.slice(close + 1).trimStart() : "";
26611
+ }
26612
+ if (rest !== "" && !/^[=<>!~;@]/.test(rest)) {
26613
+ ignored++;
26614
+ continue;
26615
+ }
26616
+ if (rest.startsWith("@")) {
26617
+ out.push({
26618
+ eco: "PyPI",
26619
+ name,
26620
+ version: null,
26621
+ skip: "not-registry"
26622
+ });
26623
+ continue;
26624
+ }
26625
+ const semi = rest.indexOf(";");
26626
+ let spec = semi >= 0 ? rest.slice(0, semi) : rest;
26627
+ const option = spec.search(/\s-/);
26628
+ if (option >= 0) spec = spec.slice(0, option);
26629
+ spec = spec.replace(/\s+/g, "");
26630
+ const exact = /^===?([^,*=<>!~]+)$/.exec(spec);
26631
+ out.push(exact ? {
26632
+ eco: "PyPI",
26633
+ name,
26634
+ version: exact[1]
26635
+ } : {
26636
+ eco: "PyPI",
26637
+ name,
26638
+ version: null,
26639
+ noVersion: "not-exact"
26640
+ });
26641
+ }
26642
+ if (includes) notes.push(`${includes === 1 ? "A line includes" : `${includes} lines include`} another requirements file (-r or -c). Check that file too.`);
26643
+ if (ignored) notes.push(`Ignored ${ignored === 1 ? "a line" : `${ignored} lines`} that ${ignored === 1 ? "is not a requirement" : "are not requirements"}.`);
26644
+ return out;
26645
+ }
26646
+ function pipfileLock(doc) {
26647
+ const out = [];
26648
+ for (const group of ["default", "develop"]) for (const [name, v] of entries(doc[group])) {
26649
+ if (!isObj(v)) continue;
26650
+ if (v.git || v.path || v.file || v.editable) out.push({
26651
+ eco: "PyPI",
26652
+ name,
26653
+ version: null,
26654
+ skip: "not-registry"
26655
+ });
26656
+ else {
26657
+ const spec = str(v.version);
26658
+ const exact = spec && /^===?([^,*=<>!~\s]+)$/.exec(spec);
26659
+ out.push(exact ? {
26660
+ eco: "PyPI",
26661
+ name,
26662
+ version: exact[1]
26663
+ } : {
26664
+ eco: "PyPI",
26665
+ name,
26666
+ version: null,
26667
+ noVersion: "not-exact"
26668
+ });
26669
+ }
26670
+ }
26671
+ return out;
26672
+ }
26673
+ function tomlString(v) {
26674
+ const q = v[0];
26675
+ if (q !== "\"" && q !== "'") return null;
26676
+ const end = v.indexOf(q, 1);
26677
+ return end > 0 ? v.slice(1, end) : null;
26678
+ }
26679
+ function tomlPackages(text, notes, kind) {
26680
+ const eco = kind === "cargo" ? "crates.io" : "PyPI";
26681
+ const pkgs = [];
26682
+ let cur = null;
26683
+ let sub = "";
26684
+ for (const line of lines(text, notes)) {
26685
+ if (line.startsWith("[")) {
26686
+ const h = line.trim();
26687
+ if (h === "[[package]]") {
26688
+ cur = {
26689
+ name: null,
26690
+ version: null,
26691
+ source: null,
26692
+ type: null
26693
+ };
26694
+ pkgs.push(cur);
26695
+ sub = "";
26696
+ } else if (cur && (h.startsWith("[package.") || h.startsWith("[[package."))) sub = h;
26697
+ else cur = null;
26698
+ continue;
26699
+ }
26700
+ if (!cur) continue;
26701
+ const m = /^([A-Za-z0-9_-]+) *= *(\S.*)$/.exec(line);
26702
+ if (!m) continue;
26703
+ const value = m[2].trim();
26704
+ if (sub === "") {
26705
+ if (m[1] === "name") cur.name = tomlString(value);
26706
+ else if (m[1] === "version") cur.version = tomlString(value);
26707
+ else if (m[1] === "source") cur.source = value;
26708
+ } else if (sub === "[package.source]" && m[1] === "type") cur.type = tomlString(value);
26709
+ }
26710
+ const out = [];
26711
+ for (const p of pkgs) {
26712
+ if (!p.name) continue;
26713
+ let registry;
26714
+ if (kind === "cargo") {
26715
+ const src = p.source === null ? null : tomlString(p.source);
26716
+ registry = src !== null && (src.startsWith("registry+https://github.com/rust-lang/crates.io-index") || src.startsWith("sparse+https://index.crates.io/"));
26717
+ } else if (kind === "uv") registry = p.source === null || /^\{ *registry *=/.test(p.source);
26718
+ else registry = p.type === null || p.type === "legacy";
26719
+ if (!registry) out.push({
26720
+ eco,
26721
+ name: p.name,
26722
+ version: null,
26723
+ skip: "not-registry"
26724
+ });
26725
+ else if (!p.version) out.push({
26726
+ eco,
26727
+ name: p.name,
26728
+ version: null,
26729
+ noVersion: "no-version"
26730
+ });
26731
+ else out.push({
26732
+ eco,
26733
+ name: p.name,
26734
+ version: p.version
26735
+ });
26736
+ }
26737
+ return out;
26738
+ }
26739
+ var goToken = (s) => s.length >= 2 && (s[0] === "\"" || s[0] === "`") && s[s.length - 1] === s[0] ? s.slice(1, -1) : s;
26740
+ var isLocalPath = (p) => p.startsWith("./") || p.startsWith("../") || p === "." || p === ".." || p.startsWith("/") || /^[A-Za-z]:[\\/]/.test(p);
26741
+ function goMod(text, notes) {
26742
+ const requires = [];
26743
+ const replaces = [];
26744
+ let block = null;
26745
+ const handle = (verb, args) => {
26746
+ if (verb === "require" && args.length >= 2) requires.push([goToken(args[0]), args[1]]);
26747
+ else if (verb === "replace") {
26748
+ const arrow = args.indexOf("=>");
26749
+ if (arrow < 1 || arrow + 1 >= args.length) return;
26750
+ replaces.push({
26751
+ from: goToken(args[0]),
26752
+ fromVersion: arrow > 1 ? args[1] : null,
26753
+ to: goToken(args[arrow + 1]),
26754
+ toVersion: args[arrow + 2] ?? null
26755
+ });
26756
+ }
26757
+ };
26758
+ for (const line of lines(text, notes)) {
26759
+ const comment = line.indexOf("//");
26760
+ const t = (comment >= 0 ? line.slice(0, comment) : line).trim();
26761
+ if (t === "") continue;
26762
+ if (block !== null) {
26763
+ if (t === ")") block = null;
26764
+ else handle(block, t.split(/\s+/));
26765
+ continue;
26766
+ }
26767
+ const [verb, ...args] = t.split(/\s+/);
26768
+ if (args.length === 1 && args[0] === "(") block = verb;
26769
+ else handle(verb, args);
26770
+ }
26771
+ const out = requires.map(([path, version]) => {
26772
+ let r;
26773
+ for (const x of replaces) if (x.from === path && (x.fromVersion === null || x.fromVersion === version)) r = x;
26774
+ if (!r) return {
26775
+ eco: "Go",
26776
+ name: path,
26777
+ version
26778
+ };
26779
+ if (isLocalPath(r.to)) return {
26780
+ eco: "Go",
26781
+ name: path,
26782
+ version: null,
26783
+ noVersion: "go-local"
26784
+ };
26785
+ return {
26786
+ eco: "Go",
26787
+ name: r.to,
26788
+ version: r.toVersion ?? version
26789
+ };
26790
+ });
26791
+ out.push({
26792
+ eco: "Go",
26793
+ name: "stdlib",
26794
+ version: null,
26795
+ skip: "go-stdlib"
26796
+ });
26797
+ return out;
26798
+ }
26799
+ function goSum(text, notes) {
26800
+ const out = [];
26801
+ const seen = /* @__PURE__ */ new Set();
26802
+ for (const line of lines(text, notes)) {
26803
+ const [path, version, hash] = line.trim().split(/\s+/);
26804
+ if (!path || !version || !hash || version.endsWith("/go.mod")) continue;
26805
+ const id = `${path} ${version}`;
26806
+ if (seen.has(id)) continue;
26807
+ seen.add(id);
26808
+ out.push({
26809
+ eco: "Go",
26810
+ name: path,
26811
+ version
26812
+ });
26813
+ }
26814
+ notes.push(GO_SUM_NOTE);
26815
+ return out;
26816
+ }
26817
+ /** Platform gems ("nokogiri (1.15.4-x86_64-linux)"): the platform is not part of the version. */
26818
+ var GEM_PLATFORM = /^(?:x86_64|x86|x64|i[3-6]86|aarch64|arm64|arm|armv\d\w*|universal|java|jruby|mingw|mswin|mswin64|darwin|linux|powerpc|ppc64le|s390x|riscv64|wasm32)(?:-|$)/i;
26819
+ function gemfileLock(text, notes) {
26820
+ const out = [];
26821
+ let section = "";
26822
+ let specs = false;
26823
+ for (const line of lines(text, notes)) {
26824
+ if (line.trim() === "") continue;
26825
+ if (line[0] !== " ") {
26826
+ section = line.trim();
26827
+ specs = false;
26828
+ continue;
26829
+ }
26830
+ if (line === " specs:") {
26831
+ specs = true;
26832
+ continue;
26833
+ }
26834
+ if (line[2] !== " ") {
26835
+ specs = false;
26836
+ continue;
26837
+ }
26838
+ if (!specs) continue;
26839
+ const m = /^ {4}([^\s(]+) \(([^)\s]+)\)$/.exec(line);
26840
+ if (!m) continue;
26841
+ let version = m[2];
26842
+ const dash = version.indexOf("-");
26843
+ if (dash > 0 && GEM_PLATFORM.test(version.slice(dash + 1))) version = version.slice(0, dash);
26844
+ out.push(section === "GEM" ? {
26845
+ eco: "RubyGems",
26846
+ name: m[1],
26847
+ version
26848
+ } : {
26849
+ eco: "RubyGems",
26850
+ name: m[1],
26851
+ version: null,
26852
+ skip: "not-registry"
26853
+ });
26854
+ }
26855
+ return out;
26856
+ }
26857
+ function composerLock(doc) {
26858
+ const out = [];
26859
+ for (const list of [doc.packages, doc["packages-dev"]]) {
26860
+ if (!Array.isArray(list)) continue;
26861
+ for (const p of list) {
26862
+ if (!isObj(p)) continue;
26863
+ const name = str(p.name);
26864
+ if (!name) continue;
26865
+ const version = str(p.version);
26866
+ if (isObj(p.dist) && p.dist.type === "path") out.push({
26867
+ eco: "Packagist",
26868
+ name,
26869
+ version: null,
26870
+ skip: "not-registry"
26871
+ });
26872
+ else if (version && (version.startsWith("dev-") || version.endsWith("-dev"))) out.push({
26873
+ eco: "Packagist",
26874
+ name,
26875
+ version: null,
26876
+ skip: "dev-branch"
26877
+ });
26878
+ else out.push(version ? {
26879
+ eco: "Packagist",
26880
+ name,
26881
+ version
26882
+ } : {
26883
+ eco: "Packagist",
26884
+ name,
26885
+ version: null,
26886
+ noVersion: "no-version"
26887
+ });
26888
+ }
26889
+ }
26890
+ return out;
26891
+ }
26892
+ function nugetLock(doc) {
26893
+ const out = [];
26894
+ for (const [, deps] of entries(doc.dependencies)) for (const [name, v] of entries(deps)) {
26895
+ if (!isObj(v)) continue;
26896
+ const version = str(v.resolved);
26897
+ if (v.type === "Project") out.push({
26898
+ eco: "NuGet",
26899
+ name,
26900
+ version: null,
26901
+ skip: "not-registry"
26902
+ });
26903
+ else out.push(version ? {
26904
+ eco: "NuGet",
26905
+ name,
26906
+ version
26907
+ } : {
26908
+ eco: "NuGet",
26909
+ name,
26910
+ version: null,
26911
+ noVersion: "no-version"
26912
+ });
26913
+ }
26914
+ return out;
26915
+ }
26916
+ function gradleLock(text, notes) {
26917
+ const out = [];
26918
+ for (const line of lines(text, notes)) {
26919
+ const m = /^([^#\s:=]+):([^:=\s]+):([^:=\s]+)=/.exec(line);
26920
+ if (m) out.push({
26921
+ eco: "Maven",
26922
+ name: `${m[1]}:${m[2]}`,
26923
+ version: m[3]
26924
+ });
26925
+ }
26926
+ return out;
26927
+ }
26928
+ var BY_FILENAME = [
26929
+ [/^(?:package-lock|npm-shrinkwrap)\.json$/, "npm-lock"],
26930
+ [/^yarn\.lock$/, "yarn"],
26931
+ [/^pnpm-lock\.ya?ml$/, "pnpm"],
26932
+ [/^poetry\.lock$/, "poetry"],
26933
+ [/^uv\.lock$/, "uv"],
26934
+ [/^pipfile\.lock$/, "pipfile"],
26935
+ [/^go\.mod$/, "gomod"],
26936
+ [/^go\.sum$/, "gosum"],
26937
+ [/^cargo\.lock$/, "cargo"],
26938
+ [/^(?:gemfile\.lock|gems\.locked)$/, "gemfile"],
26939
+ [/^composer\.lock$/, "composer"],
26940
+ [/^packages\.lock\.json$/, "nuget"],
26941
+ [/\.lockfile$/, "gradle"],
26942
+ [/^(?:requirements|constraints)[\w.-]*\.txt$/, "requirements"]
26943
+ ];
26944
+ var JSON_PARSERS = /* @__PURE__ */ new Map([
26945
+ ["cyclonedx-json", cyclonedxJson],
26946
+ ["spdx-json", spdxJson],
26947
+ ["npm-lock", npmLock],
26948
+ ["pipfile", pipfileLock],
26949
+ ["composer", composerLock],
26950
+ ["nuget", nugetLock]
26951
+ ]);
26952
+ var TEXT_PARSERS = /* @__PURE__ */ new Map([
26953
+ ["cyclonedx-xml", (text) => cyclonedxXml(text)],
26954
+ ["spdx-tag", spdxTag],
26955
+ ["purl", purlList],
26956
+ ["yarn", yarnLock],
26957
+ ["pnpm", pnpmLock],
26958
+ ["requirements", requirements],
26959
+ ["poetry", (t, n) => tomlPackages(t, n, "poetry")],
26960
+ ["uv", (t, n) => tomlPackages(t, n, "uv")],
26961
+ ["cargo", (t, n) => tomlPackages(t, n, "cargo")],
26962
+ ["gomod", goMod],
26963
+ ["gosum", goSum],
26964
+ ["gemfile", gemfileLock],
26965
+ ["gradle", gradleLock]
26966
+ ]);
26967
+ /** The format a file name alone says (lockfiles; SBOMs are told by content), or null. Also used by the CLI. */
26968
+ function formatOfFilename(filename) {
26969
+ return byFilename(filename);
26970
+ }
26971
+ function byFilename(filename) {
26972
+ const base = filename.split(/[\\/]/).pop()?.toLowerCase().slice(0, 255) ?? "";
26973
+ for (const [re, f] of BY_FILENAME) if (re.test(base)) return f;
26974
+ return null;
26975
+ }
26976
+ /**
26977
+ * SPDX 3 JSON-LD names its context by URL: a string, an array holding it, or an inline object. Only
26978
+ * that shallow shape is read: a context nested a million levels deep must not overflow the stack.
26979
+ */
26980
+ function spdxContext(ctx) {
26981
+ return (Array.isArray(ctx) ? ctx : [ctx]).flatMap((c) => isObj(c) ? [...Object.keys(c), ...Object.values(c)] : [c]).some((c) => typeof c === "string" && c.toLowerCase().includes("spdx"));
26982
+ }
26983
+ function jsonFormat(doc) {
26984
+ if (!isObj(doc)) return null;
26985
+ if (doc.bomFormat === "CycloneDX") return "cyclonedx-json";
26986
+ if (typeof doc.spdxVersion === "string" || Array.isArray(doc["@graph"]) && spdxContext(doc["@context"])) return "spdx-json";
26987
+ if ("lockfileVersion" in doc && (isObj(doc.packages) || isObj(doc.dependencies))) return "npm-lock";
26988
+ if (isObj(doc._meta) && (isObj(doc.default) || isObj(doc.develop))) return "pipfile";
26989
+ if (Array.isArray(doc.packages) && ("content-hash" in doc || "packages-dev" in doc || "_readme" in doc)) return "composer";
26990
+ if (typeof doc.version === "number" && isObj(doc.dependencies)) return "nuget";
26991
+ return null;
26992
+ }
26993
+ /** The format of a text file, from its first 64 KB. */
26994
+ function textFormat(head) {
26995
+ if (head.trimStart().startsWith("<")) return /cyclonedx|<(?:[\w.-]{1,32}:)?purl>/i.test(head) ? "cyclonedx-xml" : null;
26996
+ if (/^SPDXVersion:/m.test(head)) return "spdx-tag";
26997
+ if (/^# yarn lockfile v1|^__metadata:/m.test(head)) return "yarn";
26998
+ if (/^lockfileVersion:/m.test(head)) return "pnpm";
26999
+ if (/^\[\[package\]\]/m.test(head)) {
27000
+ if (/^# This file is automatically @generated by Cargo|^source = "(?:registry|sparse|git)\+|^checksum = "/m.test(head)) return "cargo";
27001
+ if (/^requires-python = |^source = \{ ?(?:registry|editable|virtual|path|directory|git|url) = /m.test(head)) return "uv";
27002
+ return "poetry";
27003
+ }
27004
+ if (/^module\s+\S/m.test(head)) return "gomod";
27005
+ if (/^\S+ v\S+ h1:/m.test(head)) return "gosum";
27006
+ if (/^(?:GEM|GIT|PATH)\r?$/m.test(head) && /^ {2}specs:\r?$/m.test(head)) return "gemfile";
27007
+ if (/^[^\s#:=]+:[^\s:=]+:[^\s:=]+=/m.test(head)) return "gradle";
27008
+ if (/^[ \t]*pkg:[a-z]/im.test(head)) return "purl";
27009
+ if (/^(?:-[rce] |--[a-z]|[A-Za-z0-9][A-Za-z0-9._-]*[ \t]*(?:\[[^\]\n]{0,200}\][ \t]*)?(?:===?|~=|>=|<=|!=|<|>|;|@ ))/m.test(head)) return "requirements";
27010
+ return null;
27011
+ }
27012
+ /** A Maven POM: a <project> element in the POM namespace, before any CycloneDX <bom> element. */
27013
+ function isPom(head) {
27014
+ const project = head.search(/<project[\s>]/);
27015
+ if (project < 0 || !head.includes("maven.apache.org/POM")) return false;
27016
+ const bom = head.search(/<(?:[A-Za-z_][\w.-]{0,31}:)?bom[\s>]/);
27017
+ return bom < 0 || project < bom;
27018
+ }
27019
+ /** A top-level block of a Gradle build script, Groovy or Kotlin; no accepted text format has one. */
27020
+ var GRADLE_BLOCK = /^(?:plugins|dependencies|buildscript|repositories|allprojects|subprojects)[ \t]*\{/m;
27021
+ /** A build manifest the page does not read, from the file name or the content; null otherwise. */
27022
+ function manifest(filename, head, doc) {
27023
+ const base = filename.split(/[\\/]/).pop()?.toLowerCase() ?? "";
27024
+ if (base === "pom.xml" || isPom(head)) return "pom";
27025
+ if (/^build\.gradle(?:\.kts)?$/.test(base) || GRADLE_BLOCK.test(head)) return "gradle";
27026
+ if (base === "package.json" || isObj(doc) && typeof doc.name === "string" && !("lockfileVersion" in doc) && (isObj(doc.dependencies) || isObj(doc.devDependencies))) return "npm";
27027
+ return null;
27028
+ }
27029
+ function parseJson(text) {
27030
+ try {
27031
+ return JSON.parse(text);
27032
+ } catch (e) {
27033
+ throw new ParseError("json", e instanceof RangeError ? "it is nested too deeply" : e instanceof Error ? e.message.replace(/\.$/, "").slice(0, 300) : "unknown error");
27034
+ }
27035
+ }
27036
+ /**
27037
+ * Read `text` as the format `forced` names, or detect it from the file name and the content. Throws
27038
+ * ParseError when the format cannot be told or the file holds no packages. Names longer than
27039
+ * MAX_NAME are dropped (with a note); everything else is kept, including duplicates.
27040
+ */
27041
+ /**
27042
+ * Distro packages take their release from the package URL's `distro` qualifier, else from the
27043
+ * operating system the SBOM describes; one with neither is "not checked", never matched against a
27044
+ * guessed release.
27045
+ */
27046
+ function osReleases(components, os) {
27047
+ for (const c of components) {
27048
+ if (!c.eco || !isOsEcosystem(c.eco) || c.skip || c.release) continue;
27049
+ const found = os.find((o) => o.eco === c.eco && o.release)?.release ?? null;
27050
+ if (found) c.release = found;
27051
+ else {
27052
+ c.skip = "os-release";
27053
+ delete c.noVersion;
27054
+ }
27055
+ }
27056
+ }
27057
+ function parse(input, filename = "", forced = null) {
27058
+ const text = input.charCodeAt(0) === 65279 ? input.slice(1) : input;
27059
+ if (text.trim() === "") throw new ParseError("empty");
27060
+ const head = text.slice(0, 65536);
27061
+ const looksJson = /^\s*\{/.test(head);
27062
+ let doc;
27063
+ let format = forced ?? byFilename(filename);
27064
+ const decided = format !== null;
27065
+ if (format === null && looksJson) {
27066
+ doc = parseJson(text);
27067
+ format = jsonFormat(doc);
27068
+ } else if (format === null) format = textFormat(head);
27069
+ if (!decided && (format === null || format === "cyclonedx-xml" || format === "requirements")) {
27070
+ const m = manifest(filename, head, doc);
27071
+ if (m) throw new ParseError("manifest", m);
27072
+ }
27073
+ if (format === null) throw new ParseError("unknown");
27074
+ const notes = [];
27075
+ let components;
27076
+ const sbomOs = [];
27077
+ const fromJson = JSON_PARSERS.get(format);
27078
+ if (fromJson) {
27079
+ doc ??= parseJson(text);
27080
+ components = fromJson(isObj(doc) ? doc : {}, sbomOs);
27081
+ } else components = (TEXT_PARSERS.get(format) ?? gradleLock)(text, notes);
27082
+ osReleases(components, sbomOs);
27083
+ const kept = components.filter((c) => c.name !== "" && c.name.length <= 512);
27084
+ if (kept.length < components.length) {
27085
+ const n = components.length - kept.length;
27086
+ notes.push(`Skipped ${n === 1 ? "an entry" : `${n} entries`} with no name or a name longer than 512 characters.`);
27087
+ }
27088
+ if (kept.every((c) => c.skip === "go-stdlib")) throw new ParseError("empty");
27089
+ return {
27090
+ format,
27091
+ components: kept,
27092
+ notes
27093
+ };
27094
+ }
27095
+ // cli/src/check.ts
27096
+ /**
27097
+ * Checks files against packages.json with the Check page's own parser and matcher, and turns
27098
+ * the results into findings: one per (CVE, package, file), with the line the package is on.
27099
+ */
27100
+ /** The Check page reads files up to this size. */
27101
+ var MAX_FILE_BYTES = 52428800;
27102
+ var RANK = {
27103
+ exploited: 4,
27104
+ likely: 3,
27105
+ watch: 2,
27106
+ quiet: 1,
27107
+ possible: 0
27108
+ };
27109
+ /**
27110
+ * 1-based line numbers by package, found once per file. The best line names the package as a whole
27111
+ * name (so "lodash" is not found in "lodash.merge") together with its version; then one naming it
27112
+ * alone; then any line holding the text. Lines with a URL are passed over for the first two, as a
27113
+ * download URL repeats the name and version (npm's "resolved").
27114
+ */
27115
+ function lineFinder(text) {
27116
+ const lines = text.split("\n");
27117
+ const cache = /* @__PURE__ */ new Map();
27118
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27119
+ return (name, version) => {
27120
+ const key = `${name}\u0000${version ?? ""}`;
27121
+ if (cache.has(key)) return cache.get(key);
27122
+ const whole = new RegExp(`(?<![\\w.-])${esc(name)}(?![\\w-]|\\.[\\w])`);
27123
+ let both = null;
27124
+ let named = null;
27125
+ let any = null;
27126
+ for (let i = 0; i < lines.length && both === null; i++) {
27127
+ const l = lines[i];
27128
+ if (!l.includes(name)) continue;
27129
+ any ??= i + 1;
27130
+ if (l.includes("://") || !whole.test(l)) continue;
27131
+ named ??= i + 1;
27132
+ if (version && l.includes(version)) both = i + 1;
27133
+ }
27134
+ const at = both ?? named ?? any;
27135
+ cache.set(key, at);
27136
+ return at;
27137
+ };
27138
+ }
27139
+ /**
27140
+ * The lowest version that fixes every matching advisory: the highest of their next fixed versions, by
27141
+ * the ecosystem's own version order. Null when an advisory names no fix (the package needs another
27142
+ * way out), or a fix cannot be compared.
27143
+ */
27144
+ function lowestFix(pkg) {
27145
+ const c = COMPARATORS[pkg.eco];
27146
+ let best = null;
27147
+ for (const a of pkg.advisories) {
27148
+ if (a.fixedIn === null) return null;
27149
+ const key = c.parse(a.fixedIn);
27150
+ if (key === null) return null;
27151
+ if (best === null || c.cmp(key, best.key) > 0) best = {
27152
+ key,
27153
+ text: a.fixedIn
27154
+ };
27155
+ }
27156
+ return best?.text ?? null;
27157
+ }
27158
+ /** Group order for findings: Exploited first, possibly affected last; within a group by score, then CVE. */
27159
+ var compareFindings = (a, b) => RANK[b.group] - RANK[a.group] || b.row.s - a.row.s || a.row.id.localeCompare(b.row.id) || a.file.localeCompare(b.file) || a.pkg.name.localeCompare(b.pkg.name);
27160
+ /** Read and parse `files` (relative to `cwd`). No network: the distro releases they name decide what to load next. */
27161
+ function readFiles(files, cwd) {
27162
+ return files.map((path) => {
27163
+ const abs = resolve(cwd, path);
27164
+ let text;
27165
+ try {
27166
+ if (statSync(abs).size > 52428800) return {
27167
+ path,
27168
+ text: "",
27169
+ parsed: null,
27170
+ error: `larger than ${MAX_FILE_BYTES / 1024 / 1024} MB`
27171
+ };
27172
+ text = readFileSync(abs, "utf8");
27173
+ } catch (e) {
27174
+ return {
27175
+ path,
27176
+ text: "",
27177
+ parsed: null,
27178
+ error: `could not be read: ${e.message}`
27179
+ };
27180
+ }
27181
+ try {
27182
+ return {
27183
+ path,
27184
+ text,
27185
+ parsed: parse(text, path),
27186
+ error: null
27187
+ };
27188
+ } catch (e) {
27189
+ return {
27190
+ path,
27191
+ text,
27192
+ parsed: null,
27193
+ error: e instanceof ParseError ? e.message : `could not be read: ${e.message}`
27194
+ };
27195
+ }
27196
+ });
27197
+ }
27198
+ /**
27199
+ * Check `files` (paths relative to `cwd`, or files already read) at evidence bar `knob`. No network:
27200
+ * `os` says which distro releases `index` holds (loadOs in data.ts); without it distro packages are
27201
+ * not checked.
27202
+ */
27203
+ function checkFiles(files, cwd, index, knob = 50, older = {
27204
+ olderIds: /* @__PURE__ */ new Set(),
27205
+ olderError: null
27206
+ }, os = null) {
27207
+ const reports = [];
27208
+ const findings = [];
27209
+ const notes = [];
27210
+ let packages = 0;
27211
+ let checked = 0;
27212
+ const read = files.length > 0 && typeof files[0] === "string" ? readFiles(files, cwd) : files;
27213
+ for (const f of read) {
27214
+ const { path, text } = f;
27215
+ if (!f.parsed) {
27216
+ reports.push({
27217
+ path,
27218
+ format: null,
27219
+ error: f.error,
27220
+ result: null
27221
+ });
27222
+ continue;
27223
+ }
27224
+ const result = checkComponents(f.parsed, index, os);
27225
+ reports.push({
27226
+ path,
27227
+ format: result.format,
27228
+ error: null,
27229
+ result
27230
+ });
27231
+ packages += result.distinct;
27232
+ checked += result.checked;
27233
+ for (const n of result.notes) notes.push({
27234
+ file: path,
27235
+ text: n
27236
+ });
27237
+ const line = lineFinder(text);
27238
+ for (const [group, hits] of groupByTier(result.cves, knob)) for (const hit of hits) for (const pkg of hit.packages) {
27239
+ const g = group !== "possible" && pkg.unchecked !== null ? "possible" : group;
27240
+ const named = pkg.binary ? pkg.binary.split(", ")[0] : pkg.name;
27241
+ findings.push({
27242
+ group: g,
27243
+ row: hit.row,
27244
+ pkg,
27245
+ file: path,
27246
+ line: line(named, pkg.version),
27247
+ fixedIn: lowestFix(pkg),
27248
+ tracked: !older.olderIds.has(hit.row.id)
27249
+ });
27250
+ }
27251
+ }
27252
+ findings.sort(compareFindings);
27253
+ return {
27254
+ generatedAt: index.generated_at,
27255
+ knob,
27256
+ files: reports,
27257
+ findings,
27258
+ packages,
27259
+ checked,
27260
+ indexCves: index.cves.rows.length,
27261
+ ecosystemsDown: index.sources.filter((s) => !s.ok).map((s) => s.ecosystem),
27262
+ coverage: {
27263
+ tracked: index.cves.rows.length - older.olderIds.size,
27264
+ older: older.olderIds.size,
27265
+ advisories: index.distinct?.advisories ?? 0,
27266
+ olderError: older.olderError
27267
+ },
27268
+ notes
27269
+ };
27270
+ }
27271
+ /** Distinct CVEs per group. */
27272
+ function countByGroup(findings) {
27273
+ const out = {
27274
+ exploited: /* @__PURE__ */ new Set(),
27275
+ likely: /* @__PURE__ */ new Set(),
27276
+ watch: /* @__PURE__ */ new Set(),
27277
+ quiet: /* @__PURE__ */ new Set(),
27278
+ possible: /* @__PURE__ */ new Set()
27279
+ };
27280
+ for (const f of findings) out[f.group].add(f.row.id);
27281
+ return {
27282
+ exploited: out.exploited.size,
27283
+ likely: out.likely.size,
27284
+ watch: out.watch.size,
27285
+ quiet: out.quiet.size,
27286
+ possible: out.possible.size
27287
+ };
27288
+ }
27289
+ // site/src/check/files.ts
27290
+ /**
27291
+ * Which files a dependency check reads, shared by the browser (a public GitHub repo, Check page) and
27292
+ * the command line (cli/src/discover.ts): the lockfile names the parser knows, common SBOM names,
27293
+ * and the folders never searched. Pure: no Node or DOM APIs.
27294
+ */
27295
+ /** Directories never walked: installed dependencies, build output, virtualenvs, VCS metadata, test data. */
27296
+ var SKIP_DIRS = /* @__PURE__ */ new Set([
27297
+ ".git",
27298
+ ".hg",
27299
+ ".svn",
27300
+ "node_modules",
27301
+ "bower_components",
27302
+ "jspm_packages",
27303
+ "vendor",
27304
+ "Pods",
27305
+ ".venv",
27306
+ "venv",
27307
+ "__pycache__",
27308
+ ".tox",
27309
+ ".nox",
27310
+ ".gradle",
27311
+ ".terraform",
27312
+ "dist",
27313
+ "build",
27314
+ "out",
27315
+ "target",
27316
+ "coverage",
27317
+ ".next",
27318
+ ".nuxt",
27319
+ ".cache",
27320
+ "testdata",
27321
+ "fixtures",
27322
+ "__fixtures__"
27323
+ ]);
27324
+ /** CycloneDX and SPDX files as tools usually name them. */
27325
+ var SBOM_NAME = /^(?:bom\.(?:json|xml)|sbom(?:[\w.-]{0,64})?\.json|[\w.-]{1,128}\.(?:cdx\.(?:json|xml)|spdx(?:\.json)?))$/i;
27326
+ /** True when the walk picks a file of this name. */
27327
+ var isCheckable = (name) => formatOfFilename(name) !== null || SBOM_NAME.test(name);
27328
+ /** The files to check under `paths` (relative to `cwd`). */
27329
+ function discover(paths, cwd, limits = {
27330
+ depth: 12,
27331
+ files: 500
27332
+ }) {
27333
+ const files = [];
27334
+ const seen = /* @__PURE__ */ new Set();
27335
+ const missing = [];
27336
+ let truncated = false;
27337
+ const add = (p) => {
27338
+ if (seen.has(p)) return;
27339
+ if (files.length >= limits.files) {
27340
+ truncated = true;
27341
+ return;
27342
+ }
27343
+ seen.add(p);
27344
+ files.push(p);
27345
+ };
27346
+ const walk = (dir, depth) => {
27347
+ if (depth > limits.depth || truncated) return;
27348
+ let entries;
27349
+ try {
27350
+ entries = readdirSync(dir, { withFileTypes: true });
27351
+ } catch {
27352
+ return;
27353
+ }
27354
+ entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
27355
+ for (const e of entries) if (e.isFile() && isCheckable(e.name)) add(join(dir, e.name));
27356
+ for (const e of entries) if (e.isDirectory() && !SKIP_DIRS.has(e.name)) walk(join(dir, e.name), depth + 1);
27357
+ };
27358
+ for (const raw of paths.length ? paths : ["."]) {
27359
+ const p = resolve(cwd, raw);
27360
+ let st;
27361
+ try {
27362
+ st = lstatSync(p).isSymbolicLink() ? statSync(p) : lstatSync(p);
27363
+ } catch {
27364
+ missing.push(raw);
27365
+ continue;
27366
+ }
27367
+ if (st.isDirectory()) walk(p, 0);
27368
+ else if (st.isFile()) add(p);
27369
+ }
27370
+ const goMods = new Set(files.filter((f) => basename(f) === "go.mod").map(dirname));
27371
+ const skipped = files.filter((f) => basename(f) === "go.sum" && goMods.has(dirname(f)));
27372
+ const kept = files.filter((f) => !skipped.includes(f));
27373
+ const rel = (f) => {
27374
+ const r = relative(cwd, f);
27375
+ return r === "" ? basename(f) : r.startsWith("..") ? f : r.split(sep).join("/");
27376
+ };
27377
+ return {
27378
+ files: kept.map(rel),
27379
+ skipped: skipped.map(rel),
27380
+ missing,
27381
+ truncated
27382
+ };
27383
+ }
27384
+ var cveUrl = (id) => `${BRAND.siteUrl}/cve/${encodeURIComponent(id)}`;
27385
+ /** Where a finding's CVE is explained: its CVE page when tracked, else its record on cve.org (older CVEs have no page). */
27386
+ var findingUrl = (f) => f.tracked ? cveUrl(f.row.id) : `https://www.cve.org/CVERecord?id=${encodeURIComponent(f.row.id)}`;
27387
+ // mcp/src/tools.ts
27388
+ /**
27389
+ * The MCP tools as plain functions over the published files: (call, args, now) -> result.
27390
+ * No SDK imports, so they are unit-tested with a fake fetch. Every result starts with `data`, which
27391
+ * names the run and every file the answer came from (McpData in shared/contract.ts).
27392
+ */
27393
+ /** A request the tool cannot answer as asked (isError: true). A filter is never silently dropped. */
27394
+ var InputError = class extends Error {};
27395
+ var LIMITS = {
27396
+ ids: 15,
27397
+ detailIds: 5,
27398
+ page: 50,
27399
+ offset: 1e5,
27400
+ queryWords: 8,
27401
+ withinDays: 60,
27402
+ overdueDays: 14,
27403
+ names: 200,
27404
+ nameChars: 80,
27405
+ perName: 25
27406
+ };
27407
+ /** Bytes of JSON check_inventory answers with at most (about 17,000 tokens); the least urgent CVEs are left out to fit. */
27408
+ var INVENTORY_BUDGET = 61440;
27409
+ var DAY_MS = 864e5;
27410
+ var TITLE_MAX = 160;
27411
+ /** Pipeline event details run to about 120 characters; a mirror may send more. */
27412
+ var DETAIL_MAX = 300;
27413
+ /** UTC date or date-time: anchored, no nested quantifiers; applied after a length cap of 30. */
27414
+ var DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?Z)?$/;
27415
+ /** Milliseconds for a DATE_RE string, or NaN when it does not match or does not exist (2026-02-30). */
27416
+ function parseUtc(s) {
27417
+ if (s.length > 30 || !DATE_RE.test(s)) return NaN;
27418
+ const ms = Date.parse(s);
27419
+ if (Number.isNaN(ms)) return NaN;
27420
+ const iso = new Date(ms).toISOString();
27421
+ if (iso.slice(0, 10) !== s.slice(0, 10) || s.length > 10 && iso.slice(11, 16) !== s.slice(11, 16)) return NaN;
27422
+ return ms;
27423
+ }
27424
+ function dateArg(field, s) {
27425
+ const ms = parseUtc(s);
27426
+ if (Number.isNaN(ms)) throw new InputError(MCP_MSG.badDate(field));
27427
+ return ms;
27428
+ }
27429
+ var oneLine = (s) => s.replace(/\s+/g, " ").trim();
27430
+ var cut = (s, max) => s.length <= max ? s : `${s.slice(0, max - 1).trimEnd()}…`;
27431
+ var cveOrg = (id) => `https://www.cve.org/CVERecord?id=${id}`;
27432
+ /** Highest score first, then newest, then id: the pipeline's order (byScoreThenNewest). */
27433
+ var byScore = (a, b) => b.s - a.s || b.pub.localeCompare(a.pub) || a.id.localeCompare(b.id);
27434
+ function mcpRow(r, knob) {
27435
+ return {
27436
+ id: r.id,
27437
+ tier: tierFor(r.s, r.x === 1, r.w === 1, knob),
27438
+ score: r.s,
27439
+ published: r.pub,
27440
+ cna: r.cna,
24815
27441
  vendor: r.v,
24816
27442
  product: r.p,
24817
27443
  title: cut(oneLine(r.t), TITLE_MAX),
@@ -24949,7 +27575,7 @@ async function listSignal(call, a, now) {
24949
27575
  const since = a.published_since === void 0 ? null : dateArg("published_since", a.published_since);
24950
27576
  const vendor = a.vendor?.trim().toLowerCase() ?? "";
24951
27577
  const file = knob >= 35 && tiers.every((t) => t === "exploited" || t === "likely") ? "signal.json" : "index.json";
24952
- const { rows } = await call.file(file, parse.rows);
27578
+ const { rows } = await call.file(file, parse$1.rows);
24953
27579
  const want = new Set(tiers);
24954
27580
  const p = page(rows.filter((r) => want.has(tierFor(r.s, r.x === 1, r.w === 1, knob)) && (!vendor || `${r.v} ${r.p}`.toLowerCase().includes(vendor)) && (since === null || Date.parse(r.pub) >= since) && (!a.kev_only || r.k === 1)).sort(byScore), a.offset, a.limit ?? 25);
24955
27581
  return {
@@ -24962,7 +27588,7 @@ async function listSignal(call, a, now) {
24962
27588
  };
24963
27589
  }
24964
27590
  async function kevDue(call, a, now) {
24965
- const kev = await call.file("kev.json", parse.kev);
27591
+ const kev = await call.file("kev.json", parse$1.kev);
24966
27592
  const day = (ms) => new Date(ms).toISOString().slice(0, 10);
24967
27593
  const today = day(now);
24968
27594
  const from = day(Date.parse(today) - (a.overdue_days ?? 7) * DAY_MS);
@@ -24992,7 +27618,7 @@ async function kevDue(call, a, now) {
24992
27618
  };
24993
27619
  }
24994
27620
  async function wokeUp(call, a, now) {
24995
- const woke = await call.file("woke.json", parse.woke);
27621
+ const woke = await call.file("woke.json", parse$1.woke);
24996
27622
  const knob = (await call.meta()).knob_default;
24997
27623
  const sinceMs = a.since === void 0 ? Date.parse(woke.generated_at) - 7 * DAY_MS : dateArg("since", a.since);
24998
27624
  const since = new Date(sinceMs).toISOString();
@@ -25019,7 +27645,7 @@ async function wokeUp(call, a, now) {
25019
27645
  async function receipts(call, a, now) {
25020
27646
  const id = a.id?.trim().toUpperCase();
25021
27647
  if (id !== void 0 && !CVE_ID_RE.test(id)) throw new InputError(MCP_MSG.notCveId);
25022
- const r = await call.file("receipts.json", parse.receipts);
27648
+ const r = await call.file("receipts.json", parse$1.receipts);
25023
27649
  const { items, uncounted, gaps: _gaps, ...forward } = r.forward;
25024
27650
  const b = r.backtest;
25025
27651
  const withRow = (x) => x ? {
@@ -25063,7 +27689,7 @@ async function searchCves(call, a, now) {
25063
27689
  if (terms.length === 0) throw new InputError("query needs at least one word.");
25064
27690
  if (terms.length > LIMITS.queryWords) throw new InputError(MCP_MSG.tooManyWords(LIMITS.queryWords));
25065
27691
  const tiers = a.tiers?.length ? new Set(a.tiers) : null;
25066
- const { rows, hay } = await call.file("index.json", parse.rows);
27692
+ const { rows, hay } = await call.file("index.json", parse$1.rows);
25067
27693
  const meta = await call.meta();
25068
27694
  const hits = [];
25069
27695
  for (let i = 0; i < rows.length; i++) {
@@ -25111,8 +27737,8 @@ async function checkInventory(call, a, now) {
25111
27737
  const names = watchNames(a.names);
25112
27738
  const tiers = a.tiers?.length ? [...new Set(a.tiers)] : [...TIERS];
25113
27739
  const want = new Set(tiers);
25114
- const { rows } = await call.file("index.json", parse.rows);
25115
- const woke = await call.file("woke.json", parse.woke);
27740
+ const { rows } = await call.file("index.json", parse$1.rows);
27741
+ const woke = await call.file("woke.json", parse$1.woke);
25116
27742
  const seen = new Set(rows.map((r) => r.id));
25117
27743
  const tracked = [...rows, ...woke.items.map((i) => i.row).filter((r) => !seen.has(r.id))];
25118
27744
  const matched = new Map(names.map((n) => [n, []]));
@@ -25221,7 +27847,7 @@ async function changesSince(call, a, now) {
25221
27847
  const untilMs = a.until === void 0 ? null : dateArg("until", a.until);
25222
27848
  const names = a.names?.length ? watchNames(a.names) : null;
25223
27849
  const types = a.types?.length ? [...new Set(a.types)] : null;
25224
- const ev = await call.file("events.json", parse.events);
27850
+ const ev = await call.file("events.json", parse$1.events);
25225
27851
  const genMs = Date.parse(ev.generated_at);
25226
27852
  const to = new Date(genMs).toISOString();
25227
27853
  const from = (/* @__PURE__ */ new Date(genMs - ev.days * DAY_MS)).toISOString();
@@ -25250,6 +27876,161 @@ async function changesSince(call, a, now) {
25250
27876
  items: p.items.map(eventOut)
25251
27877
  };
25252
27878
  }
27879
+ /** Bytes of JSON check_dependencies answers with at most (about 17,000 tokens); the least urgent findings are left out to fit. */
27880
+ var DEPENDENCIES_BUDGET = 61440;
27881
+ var DEPENDENCY_LIMITS = {
27882
+ paths: 20,
27883
+ pathChars: 1024
27884
+ };
27885
+ /** check_dependencies reads up to two larger files (packages-older.json is about 2 MB gzip): a longer deadline than other tools. */
27886
+ var DEPENDENCIES_TIMEOUT_MS = 3e4;
27887
+ /**
27888
+ * Paths inside `root` to hand to discover(): each must resolve, through any symbolic link, to a place
27889
+ * inside root, and a file must have a lockfile or SBOM name. That keeps an agent that was talked into
27890
+ * it from reading other files: nothing else is opened, and file errors never quote file content.
27891
+ */
27892
+ function dependencyPaths(raw, root) {
27893
+ const realRoot = realpathSync(root);
27894
+ const inside = (p) => {
27895
+ const r = relative(realRoot, p);
27896
+ return r === "" || !r.startsWith("..") && !isAbsolute(r);
27897
+ };
27898
+ return raw.map((p) => {
27899
+ const abs = resolve(root, p);
27900
+ let real;
27901
+ try {
27902
+ real = realpathSync(abs);
27903
+ } catch {
27904
+ return p;
27905
+ }
27906
+ if (!inside(real)) throw new InputError(MCP_MSG.outsideRoot(p));
27907
+ if (statSync(real).isFile() && !isCheckable(basename(real))) throw new InputError(MCP_MSG.notCheckable(p));
27908
+ return relative(root, abs) || ".";
27909
+ });
27910
+ }
27911
+ /** A file error as the agent sees it: the parser's fixed messages, and never a quote from the file. */
27912
+ function fileError(e) {
27913
+ if (e === null) return null;
27914
+ if (e.startsWith("This looks like JSON")) return "This looks like JSON, but it could not be read.";
27915
+ return e.startsWith("could not be read") ? "could not be read" : e;
27916
+ }
27917
+ var groupRank = {
27918
+ exploited: 0,
27919
+ likely: 1,
27920
+ watch: 2,
27921
+ quiet: 3,
27922
+ possible: 4
27923
+ };
27924
+ async function checkDependencies(call, a, now, root = process.cwd()) {
27925
+ const knob = a.knob ?? 50;
27926
+ const found = discover(dependencyPaths(a.paths?.length ? a.paths : ["."], root), root);
27927
+ if (!found.files.length) throw new InputError(MCP_MSG.noDependencyFiles((a.paths?.length ? a.paths : ["."]).join(", ")));
27928
+ const tracked = await call.file("packages.json", parse$1.packages);
27929
+ let older = null;
27930
+ let olderMissing = null;
27931
+ try {
27932
+ older = await call.file("packages-older.json", parse$1.packages);
27933
+ } catch (e) {
27934
+ if (!(e instanceof DataError)) throw e;
27935
+ olderMissing = e instanceof DataUnavailable ? "packages-older.json is not published in this data" : e.message;
27936
+ }
27937
+ const trackedIds = new Set(rowsFromTable(tracked.cves).map((r) => r.id));
27938
+ const olderIds = new Set(older ? rowsFromTable(older.cves).map((r) => r.id).filter((id) => !trackedIds.has(id)) : []);
27939
+ const read = readFiles(found.files, root);
27940
+ const needs = osNeeds(read.flatMap((f) => f.parsed?.components ?? []));
27941
+ let index = mergePackageFiles(tracked, older);
27942
+ let os = null;
27943
+ if (needs.length > 0) {
27944
+ const osIndex = await call.file("os/index.json", parse$1.osIndex).catch((e) => {
27945
+ if (e instanceof DataError) return null;
27946
+ throw e;
27947
+ });
27948
+ const plan = osPlan(osIndex, needs);
27949
+ const cover = {
27950
+ loaded: /* @__PURE__ */ new Set(),
27951
+ notFollowed: plan.notFollowed,
27952
+ failed: new Set(plan.failed)
27953
+ };
27954
+ os = cover;
27955
+ const files = [];
27956
+ for (const [tag, rel] of plan.files) try {
27957
+ files.push(await call.file(rel, parse$1.packages));
27958
+ cover.loaded.add(tag);
27959
+ } catch (e) {
27960
+ if (!(e instanceof DataError)) throw e;
27961
+ cover.failed.add(tag);
27962
+ }
27963
+ for (const n of needs) if (!osIndex) cover.failed.add(osTag(n.eco, n.release));
27964
+ const merged = mergeOsFiles(index, files);
27965
+ index = merged.file;
27966
+ for (const id of merged.noPage) olderIds.add(id);
27967
+ }
27968
+ const report = checkFiles(read, root, index, knob, {
27969
+ olderIds,
27970
+ olderError: olderMissing
27971
+ }, os);
27972
+ const counts = countByGroup(report.findings);
27973
+ const items = report.findings.filter((f) => a.include_quiet || f.group !== "quiet").sort((x, y) => groupRank[x.group] - groupRank[y.group]).map((f) => ({
27974
+ cve: f.row.id,
27975
+ group: f.group,
27976
+ verdict: f.group === "possible" ? "Possibly affected: the version in the file could not be compared with the advisory." : VERDICT[f.group],
27977
+ score: f.row.s,
27978
+ in_kev: f.row.k === 1,
27979
+ kev_due: f.row.kd,
27980
+ exploited: f.row.x === 1,
27981
+ weaponized: f.row.w === 1,
27982
+ ecosystem: f.pkg.eco,
27983
+ package: cut(oneLine(f.pkg.name), TITLE_MAX),
27984
+ named: f.pkg.named ? cut(oneLine(f.pkg.named), TITLE_MAX) : null,
27985
+ version: f.pkg.version === null ? null : cut(oneLine(f.pkg.version), 64),
27986
+ fixed_in: f.fixedIn,
27987
+ advisories: f.pkg.advisories.map((x) => x.id),
27988
+ file: f.file,
27989
+ line: f.line,
27990
+ tracked: f.tracked,
27991
+ url: findingUrl(f),
27992
+ title: cut(oneLine(f.row.t), TITLE_MAX)
27993
+ }));
27994
+ const data = await dataBlock(call, now);
27995
+ const scope = `${olderMissing === null ? `Every CVE that one of ${report.coverage.advisories.toLocaleString("en-US")} OSV.dev advisories ties to a package version, in npm, PyPI, Maven, Go, crates.io, RubyGems, Packagist and NuGet, and Debian, Ubuntu and Alpine packages against their distro's security tracker` : "Tracked CVEs only"}. Not checked: advisories without a CVE ID (malware reports among them), other ecosystems (rpm and other distros), a distro release its tracker no longer follows, and bugs no advisory names yet. Tracked CVEs (tracked: true) have a page and get_verdict knows them; older ones link to cve.org.`;
27996
+ const build = (n) => ({
27997
+ data,
27998
+ knob,
27999
+ scope,
28000
+ note: [n < items.length ? MCP_MSG.dependenciesCut(n, items.length) : null, olderMissing === null ? null : MCP_MSG.olderMissing(olderMissing)].filter(Boolean).join(" ") || null,
28001
+ files: report.files.map((f) => ({
28002
+ path: f.path,
28003
+ format: f.format,
28004
+ packages: f.result?.distinct ?? 0,
28005
+ error: fileError(f.error)
28006
+ })),
28007
+ counts,
28008
+ packages_checked: report.checked,
28009
+ coverage: {
28010
+ tracked_cves: report.coverage.tracked,
28011
+ older_cves: report.coverage.older,
28012
+ advisories: report.coverage.advisories,
28013
+ older_missing: olderMissing
28014
+ },
28015
+ total: items.length,
28016
+ omitted: items.length - n,
28017
+ items: items.slice(0, n)
28018
+ });
28019
+ const fits = (r) => Buffer.byteLength(JSON.stringify(r)) <= DEPENDENCIES_BUDGET;
28020
+ let out = build(items.length);
28021
+ if (!fits(out)) {
28022
+ let lo = 0;
28023
+ let hi = items.length - 1;
28024
+ out = build(0);
28025
+ while (lo < hi) {
28026
+ const mid = Math.ceil((lo + hi) / 2);
28027
+ const r = build(mid);
28028
+ if (fits(r)) [lo, out] = [mid, r];
28029
+ else hi = mid - 1;
28030
+ }
28031
+ }
28032
+ return out;
28033
+ }
25253
28034
  // mcp/src/server.ts
25254
28035
  /**
25255
28036
  * The MCP server factory: one McpServer with the read-only tools over a DataClient. It knows
@@ -25257,7 +28038,7 @@ async function changesSince(call, a, now) {
25257
28038
  * web-standard handler (createMcpHandler) unchanged. Inputs are bounded by zod schemas; every
25258
28039
  * failure comes back as a tool result with isError: true, never as a thrown protocol error.
25259
28040
  */
25260
- /** Every tool reads one published dataset and changes nothing. */
28041
+ /** Every tool reads published data (check_dependencies also the project's lockfiles) and changes nothing. */
25261
28042
  var ANNOTATIONS = {
25262
28043
  readOnlyHint: true,
25263
28044
  destructiveHint: false,
@@ -25313,6 +28094,11 @@ var SCHEMAS = {
25313
28094
  knob: knob.describe(`The evidence bar, 30 to 80 (default 50), as in get_verdict.`),
25314
28095
  per_name: number$1().int().min(1).max(LIMITS.perName).optional().describe(`CVEs per name, 1 to ${LIMITS.perName} (default 10). If the answer would be too large, the least urgent across all names are left out, with a note.`)
25315
28096
  }),
28097
+ check_dependencies: object({
28098
+ paths: array(string().min(1).max(DEPENDENCY_LIMITS.pathChars)).min(1).max(DEPENDENCY_LIMITS.paths).optional().describe(`Files or folders inside the working directory, 1 to ${DEPENDENCY_LIMITS.paths}. Default ["."].`),
28099
+ knob: knob.describe(`The evidence bar, 30 to 80 (default 50), as in get_verdict.`),
28100
+ include_quiet: boolean().optional().describe("Also list Quiet findings (always counted). Default false.")
28101
+ }),
25316
28102
  changes_since: object({
25317
28103
  since: utc.describe("Events after this UTC date-time (next_since of an earlier answer), or from 00:00Z of this date, within the log's 7 days."),
25318
28104
  until: date("Only events at or before this time. On later pages, pass next_since of the first page."),
@@ -25330,6 +28116,7 @@ var HANDLERS = {
25330
28116
  receipts,
25331
28117
  search_cves: searchCves,
25332
28118
  check_inventory: checkInventory,
28119
+ check_dependencies: checkDependencies,
25333
28120
  changes_since: changesSince
25334
28121
  };
25335
28122
  /** structuredContent plus the same JSON as one text block (spec: SHOULD), or an isError text. */
@@ -25379,7 +28166,7 @@ function createServer(dc) {
25379
28166
  annotations: ANNOTATIONS
25380
28167
  }, async (args) => {
25381
28168
  try {
25382
- return answer(await dc.run((call) => handler(call, args, dc.now())));
28169
+ return answer(await dc.run((call) => handler(call, args, dc.now()), name === "check_dependencies" ? DEPENDENCIES_TIMEOUT_MS : void 0));
25383
28170
  } catch (e) {
25384
28171
  if (e instanceof DataError || e instanceof InputError) return failure(e.message);
25385
28172
  return failure(`${MCP_SERVER.title} could not answer: ${e instanceof Error ? e.message : String(e)}`);