@shieldaai/security-watch 0.1.0-alpha.0 → 1.0.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/CONTRIBUTING.md +4 -2
  3. package/README.md +173 -48
  4. package/SECURITY.md +24 -9
  5. package/dist/assessment.d.ts +12 -1
  6. package/dist/assessment.js +223 -52
  7. package/dist/cli.js +340 -27
  8. package/dist/config.d.ts +62 -2
  9. package/dist/config.js +88 -5
  10. package/dist/coverage.d.ts +4 -0
  11. package/dist/coverage.js +11 -0
  12. package/dist/cve-now.d.ts +32 -2
  13. package/dist/cve-now.js +715 -126
  14. package/dist/cvss4.d.ts +3 -0
  15. package/dist/cvss4.js +39 -0
  16. package/dist/delivery.d.ts +34 -2
  17. package/dist/delivery.js +391 -98
  18. package/dist/ecosystems.d.ts +23 -0
  19. package/dist/ecosystems.js +88 -10
  20. package/dist/engine.d.ts +55 -1
  21. package/dist/engine.js +101 -20
  22. package/dist/everyday-words.d.ts +11 -0
  23. package/dist/everyday-words.js +256 -0
  24. package/dist/health.d.ts +7 -0
  25. package/dist/health.js +55 -3
  26. package/dist/http.d.ts +7 -0
  27. package/dist/http.js +31 -2
  28. package/dist/index.d.ts +22 -4
  29. package/dist/index.js +12 -4
  30. package/dist/inventory-evidence.d.ts +10 -0
  31. package/dist/inventory-evidence.js +206 -0
  32. package/dist/inventory.d.ts +273 -0
  33. package/dist/inventory.js +210 -17
  34. package/dist/maintenance.d.ts +5 -0
  35. package/dist/maintenance.js +73 -5
  36. package/dist/matching.d.ts +29 -0
  37. package/dist/matching.js +537 -0
  38. package/dist/models.d.ts +17 -4
  39. package/dist/models.js +359 -29
  40. package/dist/pilot-cases.d.ts +171 -0
  41. package/dist/pilot-cases.js +330 -0
  42. package/dist/pilot-input.d.ts +16 -0
  43. package/dist/pilot-input.js +125 -0
  44. package/dist/pilot-recall.d.ts +166 -0
  45. package/dist/pilot-recall.js +231 -0
  46. package/dist/pilot-report.d.ts +113 -0
  47. package/dist/pilot-report.js +279 -0
  48. package/dist/pilot-responses.d.ts +111 -0
  49. package/dist/pilot-responses.js +159 -0
  50. package/dist/python-version.d.ts +3 -0
  51. package/dist/python-version.js +30 -0
  52. package/dist/rehearsal.d.ts +440 -0
  53. package/dist/rehearsal.js +372 -0
  54. package/dist/sbom.d.ts +13 -0
  55. package/dist/sbom.js +193 -0
  56. package/dist/source-error.d.ts +17 -1
  57. package/dist/source-error.js +18 -3
  58. package/dist/sources.d.ts +2 -2
  59. package/dist/sources.js +699 -45
  60. package/dist/store.d.ts +38 -13
  61. package/dist/store.js +325 -23
  62. package/dist/types.d.ts +159 -2
  63. package/dist/util.d.ts +23 -0
  64. package/dist/util.js +81 -1
  65. package/dist/vendor/cvss4-reference.d.ts +2 -0
  66. package/dist/vendor/cvss4-reference.js +789 -0
  67. package/dist/word-filter.d.ts +3 -0
  68. package/dist/word-filter.js +3291 -0
  69. package/docs/alert-outcome-evaluation.md +150 -0
  70. package/docs/compatibility.md +35 -0
  71. package/docs/configuration.md +289 -29
  72. package/docs/cvss-v4-support.md +41 -0
  73. package/docs/offline-advisory-preview.md +114 -0
  74. package/docs/offline-rehearsal.md +44 -0
  75. package/docs/pilot-cases.md +58 -0
  76. package/docs/pilot-recall.md +124 -0
  77. package/docs/pilot-report.md +52 -0
  78. package/docs/validation/alert-outcome-evaluation-2026-11-05.json +2935 -0
  79. package/docs/validation/cvss-v4-reference-parity-2026-11-05.json +93 -0
  80. package/docs/validation/rehearsal-accepted-2026-11-05.json +175 -0
  81. package/docs/validation/rehearsal-unknown-2026-11-05.json +175 -0
  82. package/docs/vendor/cvss-v4-LICENSE.txt +22 -0
  83. package/docs/vendor/cvss-v4-provenance.json +38 -0
  84. package/examples/agent-advisories-2026.json +145 -0
  85. package/examples/agent-advisory-cases-2026.json +397 -0
  86. package/examples/libraries.example.txt +4 -2
  87. package/examples/libraries.example.yaml +2 -0
  88. package/examples/offline-advisory-preview.mjs +42 -0
  89. package/examples/rehearsal.json +75 -0
  90. package/examples/systems.example.yaml +4 -0
  91. package/package.json +24 -7
  92. package/docs/quality-review.md +0 -104
package/dist/models.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { buildModelRequest, parseModelResponse } from './providers.js';
3
3
  import { hash, highest, severityRank } from './util.js';
4
- export const PROMPT_VERSION = 'security-watch-9';
4
+ export const PROMPT_VERSION = 'security-watch-10';
5
5
  const quoteSchema = z.object({ evidence_id: z.string(), quote: z.string().min(20).max(600) }).strict();
6
6
  const newsSchema = z
7
7
  .object({
@@ -34,9 +34,23 @@ function sourcePrefix(text, length) {
34
34
  return text.slice(0, length);
35
35
  }
36
36
  // IDs select source text; the model never has to reproduce punctuation or table spacing.
37
- function excerptsFor(evidence, index) {
37
+ // Exported for tests only; not part of the package API.
38
+ /** Whether an excerpt may be offered for citation: the quote contract counts 20 characters (code points). */
39
+ export function citable(text) {
40
+ return [...text].length >= 20;
41
+ }
42
+ // Exported for tests only; not part of the package API.
43
+ export function excerptsFor(evidence, index) {
38
44
  const text = `${evidence.title}\n${evidence.description}`;
39
45
  const excerpts = [];
46
+ // Lengths are counted in characters (code points), as the quote contract counts them.
47
+ const low = (at) => /^[\uDC00-\uDFFF]$/.test(text[at] ?? '');
48
+ const forward = (from, count) => {
49
+ let at = from;
50
+ for (let n = 0; n < count && at < text.length; n++)
51
+ at += (text.codePointAt(at) ?? 0) > 0xffff ? 2 : 1;
52
+ return at;
53
+ };
40
54
  let start = 0;
41
55
  while (start < text.length) {
42
56
  let end = Math.min(start + 480, text.length);
@@ -50,10 +64,20 @@ function excerptsFor(evidence, index) {
50
64
  if (space >= 240)
51
65
  end = start + space + 1;
52
66
  }
53
- // Do not leave a final fragment too short to satisfy the stored quote contract.
54
- if (text.length - end < 20)
55
- end = Math.max(start + 20, text.length - 20);
56
- if (/^[\uDC00-\uDFFF]$/.test(text[end] ?? ''))
67
+ // Neither this excerpt nor the final fragment is shorter than the stored quote contract allows.
68
+ const floor = forward(start, 20);
69
+ if (forward(end, 20) === text.length && [...text.slice(end)].length < 20) {
70
+ let tail = text.length;
71
+ for (let n = 0; n < 20 && tail > floor; n++)
72
+ tail -= low(tail - 1) ? 2 : 1;
73
+ end = Math.max(floor, tail);
74
+ }
75
+ // Whole characters: not before a combining mark (also one outside the basic plane) or a Hangul
76
+ // vowel or final consonant written apart (decomposed text), nor between the halves of a
77
+ // surrogate pair.
78
+ const inside = (at) => /^[\uDC00-\uDFFF]$/.test(text[at] ?? '') ||
79
+ /^[\p{M}\u1160-\u11ff\ud7b0-\ud7ff]$/u.test(String.fromCodePoint(text.codePointAt(at) ?? 32));
80
+ while (end > floor && inside(end))
57
81
  end--;
58
82
  }
59
83
  excerpts.push({ id: `e${index}s${excerpts.length}`, text: text.slice(start, end) });
@@ -193,19 +217,284 @@ export function validateAnalysis(value, evidence) {
193
217
  !known.get(q.evidence_id)?.includes(q.quote) ||
194
218
  evidence.find((e) => e.id === q.evidence_id)?.kind !== 'news'))
195
219
  throw new Error('MODEL_UNSUPPORTED_NEWS_QUOTE');
196
- const quoted = news.quotes.map((q) => q.quote.toLowerCase());
197
- if ([...news.affected_products, ...news.affected_versions, ...news.prerequisites].some((value) => !quoted.some((quote) => quote.includes(value.toLowerCase()))))
220
+ // A claim is checked in the evidence itself, and must lie inside one of the quotes. A quote the
221
+ // model writes may begin or end inside a word ("2.4.1" out of "12.4.1", "45" out of "45%"): the
222
+ // characters around the claim are the evidence's, not the quote's edges.
223
+ const quoted = [...new Set(news.quotes.map((q) => q.evidence_id))].map((id) => inQuote(known.get(id) ?? '', news.quotes.filter((q) => q.evidence_id === id).map((q) => q.quote)));
224
+ if ([...news.affected_products, ...news.prerequisites].some((value) => !quoted.some(({ text, within }) => quotesPhrase(text, value, within))) ||
225
+ news.affected_versions.some((value) => !quoted.some(({ text, within }) => citesVersion(text, value.toLowerCase(), within))))
198
226
  throw new Error('MODEL_UNSUPPORTED_NEWS_CLAIM');
199
227
  if ((news.classification === 'general_news' && news.impact !== 'not_applicable') ||
200
228
  (news.classification !== 'general_news' && news.impact === 'not_applicable') ||
201
229
  (news.classification === 'unknown' && news.impact !== 'unknown'))
202
230
  throw new Error('MODEL_INCONSISTENT_NEWS_ANALYSIS');
203
231
  if ((news.impact === 'affected' || news.impact === 'not_affected') &&
204
- (!news.affected_products.length || !news.affected_versions.length))
232
+ (!news.affected_products.length ||
233
+ !news.affected_versions.length ||
234
+ // A version citation has to name a version: a blank or a stray character quotes nothing.
235
+ news.affected_versions.some((value) => !/\d/.test(value)) ||
236
+ news.affected_products.some((value) => value.trim().length < 2)))
205
237
  throw new Error('MODEL_UNSUPPORTED_NEWS_IMPACT');
206
238
  }
207
239
  return parsed;
208
240
  }
241
+ /**
242
+ * Whether a quote contains this product name or prerequisite as whole words: "express" is not in
243
+ * "expressive-forms", "authenticated" is not in "unauthenticated", and "forms 4" is not in
244
+ * "forms 4.17.1". A word joined to the phrase by a hyphen, dot, slash, "@" or "#", or a "+" after it
245
+ * ("expressive-forms", "Node.js", "@angular/core", "Notepad++") makes one longer name.
246
+ */
247
+ function quotesPhrase(original, value, within = () => true) {
248
+ const wanted = readText(value).trim();
249
+ if (!wanted)
250
+ return false;
251
+ const quote = readText(original);
252
+ const first = [...wanted][0];
253
+ const last = [...wanted].at(-1);
254
+ const attached = (character) => /[\p{P}\p{S}]/u.test(character) &&
255
+ // Brackets and quotation marks of any script ("Struts【CVE-…】", "Intel「R」").
256
+ !/[\p{Ps}\p{Pe}\p{Pi}\p{Pf}]/u.test(character) &&
257
+ // Handled above, with their own exceptions, or the punctuation of a sentence.
258
+ !/[-@/:~+#._.,;!?'"’‘“”«»()[\]{}<>。、,;!?…—–]/u.test(character);
259
+ for (let at = quote.indexOf(wanted); at !== -1; at = quote.indexOf(wanted, at + 1)) {
260
+ if (!within(at, at + wanted.length))
261
+ continue;
262
+ // Whole characters (code points) on either side, not halves of a surrogate pair.
263
+ const before = [...quote.slice(Math.max(0, at - 4), at)];
264
+ const b1 = before.at(-1) ?? '';
265
+ const b2 = before.at(-2) ?? '';
266
+ const rest = quote.slice(at + wanted.length);
267
+ const [a1 = '', a2 = '', a3 = ''] = [...rest.slice(0, 6)];
268
+ const mark = (character) => !/[\p{L}\p{N}\p{M}_]/u.test(character);
269
+ // A version straight after a hyphen, "@" or "/" is the name's own version ("node-18",
270
+ // "lodash@4.17.20", "Apache/2.4.58"); "vue-3d-model" and "express@4evil" are other names.
271
+ // A package revision or a release qualifier may follow ("openssl-3.0.7-r0", "glibc-2.35-0ubuntu3",
272
+ // "Tomcat-9.0.80-beta", "spring-core-5.3.20.RELEASE"), and so may a file extension
273
+ // ("log4j-core-2.14.1.jar"); anything else joined to the number makes another name
274
+ // ("vue-3d-model", "vue-3.model", "vue-3:d"). After "+" or "~", a dot is followed only by digits or a
275
+ // commit hash, so a qualifier can be read one way only (no exponential backtracking).
276
+ const ownVersion = /^[-@/:](?:v?(?:\d+(?:\.\d+)+(?:[a-z]|p\d+)?|\d+)(?:\.x)?)(?:-r\d+|-\d+(?:\.\d+)*(?:(?:ubuntu|deb|build)\d[0-9.]*)?(?:\.(?:el|fc)\d+(?:_\d+)*)?(?:[~+][a-z]*\d[a-z0-9]*(?:\.\d+|\.(?=\d*[a-f])[0-9a-f]{7,40})*|~(?:jammy|focal|noble|bionic|xenial|bookworm|bullseye|buster|trixie))?|[-.](?:rc|beta|alpha|release|final|ga|preview|snapshot)\d*|\.(?:jar|war|tar|gz|tgz|zip|whl|gem|deb|rpm)|-alpine|-slim)*(?![\p{L}\p{N}\p{M}_@/#:+~-]|\.[\p{L}\p{N}])/iu.test(rest);
277
+ // A phrase that starts or ends with a mark (".NET", "C++") must still not continue a word
278
+ // (".NET" in "ASP.NET").
279
+ const joinedBefore = mark(first)
280
+ ? joins(b1, b1)
281
+ : joins(first, b1) ||
282
+ b1 === '+' ||
283
+ b1 === '@' ||
284
+ b1 === '/' ||
285
+ (/[-.#:~]/u.test(b1) && joins(first, b2));
286
+ // "Notepad" in "Notepad++", "C" in "C#", "express" in "express-forms", "Apache" in
287
+ // "apache/struts".
288
+ const joinedAfter = mark(last)
289
+ ? joins(a1, a1)
290
+ : joins(last, a1) ||
291
+ a1 === '+' ||
292
+ a1 === '#' ||
293
+ (a1 === '.' && joins(last, a2)) ||
294
+ (/[-@/]/u.test(a1) && !ownVersion && (joins(last, a2) || a1 === '/')) ||
295
+ (/[:~]/u.test(a1) && !(a1 === ':' && ownVersion) && joins(last, a2)) ||
296
+ // Any other mark or symbol written straight between the name and more of a word ("Notepad➕x",
297
+ // "struts∖x"), except the punctuation of a sentence.
298
+ (attached(a1) && joins(last, a2)) ||
299
+ // An apostrophe joins too, except in a possessive ("Notepad's").
300
+ (/['’]/u.test(a1) && joins(last, a2) && !(a2 === 's' && !joins('s', a3)));
301
+ if (joinedBefore || joinedAfter || (!mark(first) && attached(b1) && joins(first, b2)))
302
+ continue;
303
+ return true;
304
+ }
305
+ return false;
306
+ }
307
+ /**
308
+ * The evidence as quotes and claims are read, and a test of whether a stretch of it lies inside an
309
+ * occurrence of the quote. readText is applied once more inside the checks; it changes nothing it
310
+ * has already read, so the positions stay valid.
311
+ */
312
+ function inQuote(evidence, quotes) {
313
+ const text = readText(evidence);
314
+ const spans = [];
315
+ for (const quote of quotes) {
316
+ const wanted = readText(quote).trim();
317
+ if (wanted)
318
+ for (let at = text.indexOf(wanted); at !== -1; at = text.indexOf(wanted, at + 1))
319
+ spans.push([at, at + wanted.length]);
320
+ }
321
+ // Quotes that overlap, meet or are apart only by spaces in the evidence are one stretch of it: a
322
+ // name split across two cited excerpts is still inside the quotes (a quote is read without the
323
+ // space an excerpt ends with).
324
+ spans.sort((a, b) => a[0] - b[0]);
325
+ const merged = [];
326
+ for (const [from, to] of spans) {
327
+ const last = merged.at(-1);
328
+ if (last && (from <= last[1] || /^\s+$/u.test(text.slice(last[1], from))))
329
+ last[1] = Math.max(last[1], to);
330
+ else
331
+ merged.push([from, to]);
332
+ }
333
+ return { text, within: (start, end) => merged.some(([from, to]) => start >= from && end <= to) };
334
+ }
335
+ /**
336
+ * Text as every claim check reads it: quoteText, lower case, and composed again, since lowering
337
+ * the case can produce a pair that composes ("T" and a diaeresis become "ẗ"). Reading it again
338
+ * changes nothing, so positions found in one reading hold in the next.
339
+ */
340
+ function readText(text) {
341
+ // A final sigma is a sigma: where an excerpt ends decides which form lowering the case gives.
342
+ return quoteText(text).toLowerCase().normalize('NFC').replace(/ς/g, 'σ');
343
+ }
344
+ /**
345
+ * A quote and a claim read the same way: full-width forms ("+", "2") as their plain forms, every
346
+ * kind of hyphen and minus sign as a hyphen, the look-alike slashes as a slash, characters that show
347
+ * as nothing removed, and every kind and run of space as one space. Other compatibility forms are
348
+ * kept: a superscript, a circled digit or a fraction is not the digit it resembles ("2.4¹").
349
+ */
350
+ function quoteText(text) {
351
+ return (text
352
+ .normalize('NFC')
353
+ .replace(/[\uff01-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 0xfee0))
354
+ // The small forms ("﹒", "﹢", "﹕", "﹨") are the characters they are small forms of.
355
+ .replace(/[\ufe50-\ufe6b]/g, (character) => character.normalize('NFKC'))
356
+ .replace(/[\u2795]/g, '+')
357
+ .replace(/[\u2216]/g, '\\')
358
+ .replace(/[\u2236]/g, ':')
359
+ .replace(/[\u2e31\u30fb]/g, '.')
360
+ .replace(/[\p{Default_Ignorable_Code_Point}\p{Cf}]/gu, '')
361
+ .replace(/[\u2010-\u2013\u2212\ufe58\ufe63\u2e17\u058a\u30a0\u1400]/g, '-')
362
+ .replace(/[\u2215\u2044\u29f8\\]/g, '/')
363
+ // Look-alike dots and the small commercial at.
364
+ .replace(/[\u00b7\u2024\u2027\u2043]/g, '.')
365
+ .replace(/\ufe6b/g, '@')
366
+ .replace(/\s+/g, ' ')
367
+ // Removing an invisible mark can bring a base letter and a combining mark together: compose
368
+ // them, so that reading the text again changes nothing and positions in it stay valid.
369
+ .normalize('NFC'));
370
+ }
371
+ /** Scripts written without spaces between words. Korean is written with spaces. */
372
+ const UNSPACED = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u;
373
+ const HANGUL = /\p{Script=Hangul}/u;
374
+ /**
375
+ * Whether a character next to a name or version continues it. Digits of any script join. A letter of
376
+ * a script written without spaces gives no boundary to check, so it does not join ("Strutsの",
377
+ * "2.4.1以前"); a change between Korean and another script is a boundary too ("Struts의"), while
378
+ * Korean letters join each other.
379
+ */
380
+ function joins(edge, neighbour) {
381
+ const wordy = (character) => /[\p{L}\p{N}\p{M}_]/u.test(character);
382
+ if (!wordy(edge) || !wordy(neighbour))
383
+ return false;
384
+ // A superscript or subscript digit is a footnote or a formula, not more of the version ("2.4¹").
385
+ if (/[\u00b2\u00b3\u00b9\u2070-\u209f]/u.test(neighbour))
386
+ return false;
387
+ if (/\p{N}/u.test(neighbour))
388
+ return true;
389
+ if (UNSPACED.test(neighbour))
390
+ return false;
391
+ if (HANGUL.test(neighbour) || HANGUL.test(edge))
392
+ return HANGUL.test(neighbour) && HANGUL.test(edge);
393
+ return !UNSPACED.test(edge);
394
+ }
395
+ /**
396
+ * Whether a quote states this version as written. The check is about how the text is written, not
397
+ * what it means: a number that stands alone ("30 days", "port 8080", a year) cannot be told from a
398
+ * version and is accepted. What is refused is a number that is visibly part of something else:
399
+ * - another number or identifier: "4" in "4.2", "4,200", "3/4", "10:30", "CVE-2026-40001";
400
+ * - a longer version: "2.4.1" in "2.4.1-rc.1", "2.4.1+build.5", "2.4.1.RELEASE", "1.2" in "1.2.x";
401
+ * - an amount or a unit: "$5", "5€", "45%", "45 %", "#45", "-5", "20°";
402
+ * - a port with its protocol: "443/tcp".
403
+ * Hyphens, en dashes and minus signs count as hyphens ("CVE‑2026‑40001", "2.0–2.4"); an em dash is
404
+ * punctuation.
405
+ * A "v" before the version belongs to it ("v2.4.1"). Either end of a range written with a hyphen is
406
+ * a citation ("2.0-2.4", "versions 12-16"), and so is a version in a list ("2.4.1, 2.4.2",
407
+ * "2.4.1/2.4.2") or after a name joined by a hyphen ("exampledb2-2.4.52", "node-18").
408
+ */
409
+ function citesVersion(original, version, within = () => true) {
410
+ // The quote and the version the model copied from it are read the same way: hyphens, en dashes
411
+ // and minus signs are hyphens ("CVE‑2026‑40001", "2.0–2.4"), every kind and run of space is one
412
+ // space ("45 %"), and characters that show as nothing are dropped ("2.4.1<zero-width>.1").
413
+ const normal = readText;
414
+ const wanted = normal(version).trim();
415
+ // A version begins and ends with a letter or digit: "2.4." is not cited by "2.4.1".
416
+ if (!/^[\p{L}\p{N}](?:.*[\p{L}\p{N}])?$/u.test(wanted))
417
+ return false;
418
+ const quote = normal(original);
419
+ // A dotted version, possibly with a letter release ("1.1.1w").
420
+ const dotted = (token) => /^v?\d+(?:\.\d+)+[a-z]?$/u.test(token);
421
+ // A short whole number, without a leading zero ("0100" is half of a telephone number).
422
+ const integer = (token) => /^(?:0|[1-9]\d{0,3})$/u.test(token);
423
+ for (let at = quote.indexOf(wanted); at !== -1; at = quote.indexOf(wanted, at + 1)) {
424
+ if (!within(at, at + wanted.length))
425
+ continue;
426
+ let before = quote.slice(Math.max(0, at - 64), at);
427
+ const after = quote.slice(at + wanted.length, at + wanted.length + 64);
428
+ // "v2.4.1", "v.2.4.1", "ver.2.4.1": the abbreviation belongs to the version, not to a word.
429
+ const abbreviation = /(?:^|[^\p{L}\p{N}])(?:v|ver)\.?$/iu.exec(before);
430
+ if (abbreviation && /^\d/u.test(wanted))
431
+ before = before.slice(0, before.length - abbreviation[0].replace(/^[^vV]/u, '').length);
432
+ // A letter or digit joined to it makes another token; text without spaces between words does not.
433
+ if (joins([...wanted][0], [...before].at(-1) ?? '') || /\d\.$/u.test(before))
434
+ continue;
435
+ if (joins([...wanted].at(-1), [...after][0] ?? '') || /^\.[\dx*]/iu.test(after))
436
+ continue;
437
+ // A label ("Version:2.5.32", "Affected versions: 2.5.32") or the end of a range written with a
438
+ // tilde ("2.0.0~2.5.32") is a citation.
439
+ const labelled = /(?:(?:^|[^\p{L}\p{N}\-])(?:versions?|releases?|affected|fixed(?: in)?|patched|vulnerable|ver|versión|versiones|versionen|versão|versões|версия|версии)|版本|バージョン|버전) ?:$/iu.test(before);
440
+ const rangeEnd = /\d~$/u.test(before) && dotted(wanted) && dotted(/([\d.]+)~$/u.exec(before)[1]);
441
+ // An amount, a time, a port, a protocol version, or the tail or head of a longer version.
442
+ if ((!rangeEnd && /[\p{Sc}#_~∶±×№·]$/u.test(before)) ||
443
+ /[\p{L}\p{N}]\+$/u.test(before) ||
444
+ // A time ("10:30") or a thousands separator ("4'200"); a quotation mark or a label is not one.
445
+ /\d['’]$/u.test(before) ||
446
+ // After a colon joined to a word or number: a port ("example.com:443"), a vector
447
+ // ("CVSS:3.1"), an address ("::1"), a time.
448
+ (!labelled && /[\p{L}\p{N}:]:$/u.test(before)) ||
449
+ // A protocol version ("HTTP/2", "TLS/1.3"); a product and its version ("Apache/2.4.58") is a
450
+ // citation.
451
+ /(?:^|[^\p{L}])(?:https?|http2|tls|ssl|ssh|smb|smtp|imap|pop3|spdy|quic|rtsp|sip|snmp|ftp|ldap)\/$/iu.test(before) ||
452
+ // A minus sign ("-5", "(-5)", "x=-5") or a decimal point (".5 seconds").
453
+ /(?:^|[^\p{L}\p{N}.])-$/u.test(before) ||
454
+ /(?:^|[^\p{N}])\.$/u.test(before))
455
+ continue;
456
+ // After it: a percent sign or a currency (also after a space), a unit of degrees, a protocol
457
+ // ("443/tcp"), a qualifier that makes it another version ("2.4.1.RELEASE", "2.4.1-beta").
458
+ if (
459
+ // A plus sign joined to more is build metadata ("2.4.1+build.5"); alone it means "and later"
460
+ // ("3.0+ are affected").
461
+ // Units written as one symbol ("8.0.3㎳", "2㎝") are amounts too.
462
+ /^(?: ?[%‰٪\p{Sc}°×\u3380-\u33ff]|[_·∶]|~(?!\d+\.\d)|\+[\p{L}\p{N}]|[:'’]\d|-\p{L}|-$|\/(?:tcp|udp|sctp)\b)/iu.test(after) ||
463
+ // A qualifier that makes it another release ("2.4.1.RELEASE", "5.3.20.Final", "1.0.M2").
464
+ // A file extension does not ("log4j-2.17.1.jar", "foo-1.2.3.tar.gz").
465
+ /^\.(?:release|final|ga|snapshot|build|sp\d*|cr\d*|rc\d*|m\d+|beta\d*|alpha\d*|post\d*|dev\d*|pre(?:view)?\d*|v\d{6,})(?![\p{L}\p{N}])/iu.test(after))
466
+ continue;
467
+ // In a list, both neighbours are versions of the same kind.
468
+ const listed = /([\p{L}\p{N}.]*\d)[,/]$/u.exec(before)?.[1];
469
+ if (listed !== undefined && !(dotted(wanted) && dotted(listed)))
470
+ continue;
471
+ const listing = /^[,/](\d[\p{L}\p{N}.]*)/u.exec(after)?.[1];
472
+ if (listing !== undefined && !(dotted(wanted) && dotted(listing.replace(/\.$/u, ''))))
473
+ continue;
474
+ // Joined to something by a hyphen. Two dotted versions, or two short whole numbers on their
475
+ // own, are a range. A name before a version is a name and its version. Anything else is one
476
+ // identifier ("CVE-2026-40001", "1.0.0-1", "2026-11-14").
477
+ const left = /([\p{L}\p{N}.]*[\p{L}\p{N}])-$/u.exec(before);
478
+ const right = /^-(\d[\p{L}\p{N}.]*)/u.exec(after);
479
+ if (left) {
480
+ const token = left[1];
481
+ const chained = /-$/u.test(before.slice(0, left.index)) || right !== null;
482
+ const range = !chained && ((dotted(wanted) && dotted(token)) || (integer(wanted) && integer(token)));
483
+ const named = (dotted(wanted) && /\p{L}/u.test(token) && !dotted(token)) ||
484
+ (integer(wanted) && /^\p{L}+$/u.test(token) && !chained);
485
+ if (!range && !named)
486
+ continue;
487
+ }
488
+ if (right) {
489
+ const token = right[1].replace(/\.$/u, '');
490
+ const chained = /^-/u.test(after.slice(right[0].length)) || left !== null;
491
+ if (chained || !((dotted(wanted) && dotted(token)) || (integer(wanted) && integer(token))))
492
+ continue;
493
+ }
494
+ return true;
495
+ }
496
+ return false;
497
+ }
209
498
  function verifiedTargetAliases(eventId, evidence) {
210
499
  const target = eventId.toUpperCase();
211
500
  const identifier = /^(?:CVE-\d{4}-\d{4,}|GHSA-[A-Z0-9-]+)$/;
@@ -222,19 +511,19 @@ function verifiedTargetAliases(eventId, evidence) {
222
511
  }
223
512
  export class ModelAnalyzer {
224
513
  config;
225
- store;
226
514
  http;
227
515
  now;
228
516
  signal;
229
517
  env;
230
518
  constructor(config, store, http, now = Date.now, signal, env = process.env) {
231
519
  this.config = config;
232
- this.store = store;
233
520
  this.http = http;
234
521
  this.now = now;
235
522
  this.signal = signal;
236
523
  this.env = env;
524
+ this.store = store;
237
525
  }
526
+ store;
238
527
  async call(spec, system, evidence, assessment) {
239
528
  this.signal?.throwIfAborted();
240
529
  if (!evidence.length)
@@ -255,7 +544,9 @@ export class ModelAnalyzer {
255
544
  .filter((e, index) => e.description !== visible[index].description || e.title !== visible[index].title)
256
545
  .map((e) => e.id);
257
546
  const incompleteArticles = evidence
258
- .filter((e) => e.kind === 'news' && (e.content_status === 'excerpt' || e.content_status === 'unavailable'))
547
+ .filter(
548
+ // Only an article read in full can support a decisive claim; a missing status is not "full".
549
+ (e) => e.kind === 'news' && e.content_status !== 'full')
259
550
  .map((e) => e.id);
260
551
  let partialContext = evidence.length > visible.length || truncatedIds.length > 0 || incompleteArticles.length > 0;
261
552
  const staleEvidenceIds = evidence
@@ -283,27 +574,51 @@ export class ModelAnalyzer {
283
574
  [p.name, ...p.keywords].some(mentions));
284
575
  const targetHasInstalledVersion = Boolean(components.some((item) => item.id === assessment.component_id && item.version) ||
285
576
  products.some((item) => `product:${item.name.toLowerCase()}` === assessment.component_id && item.version));
286
- const keywords = system.keywords.filter(mentions);
287
- partialContext ||= keywords.length > 30;
577
+ const disclosureProfile = spec.disclosure_profile ?? 'minimal';
578
+ const includeDeployment = disclosureProfile === 'deployment-context';
579
+ const keywords = includeDeployment ? system.keywords.filter(mentions) : [];
580
+ const productKeywords = products.map((p) => (includeDeployment ? p.keywords.filter(mentions) : []));
581
+ const omittedKeywords = Math.max(0, keywords.length - 30) +
582
+ productKeywords.reduce((count, items) => count + Math.max(0, items.length - 30), 0);
583
+ partialContext ||= omittedKeywords > 0;
288
584
  if (components.length > 20 || products.length > 20)
289
585
  throw new Error('MODEL_CONTEXT_LIMIT');
586
+ // Request-local IDs correlate the target without disclosing host inventory identities.
587
+ // Construct each wire object explicitly. Inventory schema additions must never silently
588
+ // expand disclosure, including when the verification model uses a different profile.
589
+ const componentIndex = components.findIndex((c) => c.id === assessment.component_id);
590
+ const productIndex = products.findIndex((p) => `product:${p.name.toLowerCase()}` === assessment.component_id);
290
591
  const context = {
592
+ disclosure_profile: disclosureProfile,
291
593
  target: {
292
594
  event_id: assessment.event_id,
293
595
  verified_aliases: verifiedTargetAliases(assessment.event_id, evidence),
294
596
  installed_version_known: targetHasInstalledVersion,
295
- component_id: assessment.component_id ?? null,
597
+ component_id: componentIndex >= 0 ? `c${componentIndex}` : productIndex >= 0 ? `p${productIndex}` : null,
296
598
  category: assessment.category,
297
599
  },
298
600
  system: {
299
- environment: system.environment,
300
- exposure: system.exposure,
301
- criticality: system.criticality,
302
- inventory_updated_at: system.updated_at,
601
+ ...(includeDeployment
602
+ ? {
603
+ environment: system.environment,
604
+ exposure: system.exposure,
605
+ criticality: system.criticality,
606
+ keywords: keywords.slice(0, 30),
607
+ }
608
+ : {}),
303
609
  inventory_status: staleInventory ? 'stale' : 'current',
304
- components,
305
- products,
306
- keywords: keywords.slice(0, 30),
610
+ components: components.map((c, index) => ({
611
+ id: `c${index}`,
612
+ ecosystem: c.ecosystem,
613
+ name: c.name,
614
+ ...(c.version ? { version: c.version } : {}),
615
+ })),
616
+ products: products.map((p, index) => ({
617
+ id: `p${index}`,
618
+ name: p.name,
619
+ ...(p.version ? { version: p.version } : {}),
620
+ ...(includeDeployment ? { keywords: productKeywords[index].slice(0, 30) } : {}),
621
+ })),
307
622
  },
308
623
  coverage: {
309
624
  total_evidence: evidence.length,
@@ -311,7 +626,7 @@ export class ModelAnalyzer {
311
626
  truncated_evidence_ids: truncatedIds,
312
627
  incomplete_article_ids: incompleteArticles,
313
628
  stale_evidence_ids: staleEvidenceIds,
314
- omitted_keywords: Math.max(0, keywords.length - 30),
629
+ omitted_keywords: omittedKeywords,
315
630
  },
316
631
  evidence: visible.map((e, index) => ({
317
632
  id: e.id,
@@ -320,7 +635,14 @@ export class ModelAnalyzer {
320
635
  title: e.title,
321
636
  excerpts: excerptsFor(e, index),
322
637
  severity: e.severity,
323
- packages: e.packages,
638
+ packages: e.packages.map((p) => ({
639
+ ecosystem: p.ecosystem,
640
+ name: p.name,
641
+ range: p.range,
642
+ versions: p.versions,
643
+ matched_versions: p.matched_versions,
644
+ fixed: p.fixed,
645
+ })),
324
646
  exploited: e.exploited,
325
647
  withdrawn: e.withdrawn,
326
648
  aliases: e.aliases,
@@ -370,14 +692,19 @@ export class ModelAnalyzer {
370
692
  context.evidence[item.index].excerpts = excerptsFor(original, item.index);
371
693
  }
372
694
  const excerpts = new Map(context.evidence.flatMap((e) => e.excerpts
373
- .filter((excerpt) => excerpt.text.length >= 20)
695
+ .filter((excerpt) => citable(excerpt.text))
374
696
  .map((excerpt) => [excerpt.id, { evidence_id: e.id, quote: excerpt.text }])));
375
697
  if (!excerpts.size)
376
698
  throw new Error('MODEL_EVIDENCE_MISSING');
377
699
  const input = JSON.stringify(context);
378
700
  if (input.length > this.config.models.max_input_chars)
379
701
  throw new Error('MODEL_CONTEXT_LIMIT');
380
- const key = 'analysis:' + hash({ version: PROMPT_VERSION, spec, context });
702
+ const key = 'analysis:' +
703
+ hash({
704
+ version: PROMPT_VERSION,
705
+ spec: { ...spec, disclosure_profile: disclosureProfile },
706
+ context,
707
+ });
381
708
  const cached = this.store.getMeta(key);
382
709
  if (cached)
383
710
  return {
@@ -387,10 +714,13 @@ export class ModelAnalyzer {
387
714
  staleEvidence,
388
715
  };
389
716
  const maxOutput = this.config.models.max_output_tokens;
390
- const { url, headers, body } = buildModelRequest(spec, this.env[spec.api_key_env], instruction, input, modelOutputSchema(excerpts, new Set(visible.filter((item) => item.kind === 'news').map((item) => item.id)), targetHasInstalledVersion), maxOutput);
717
+ const { url, headers, body } = buildModelRequest(spec, this.env[spec.api_key_env], instruction +
718
+ ' The disclosure_profile describes the inventory fields the operator permits this model to receive. Request-local component/product IDs have no meaning outside this input. Undisclosed deployment context and keywords are unknown, never proof that prerequisites are absent or a target is not affected. Minimal inventory includes package/product identity and known version, not deployment configuration.', input, modelOutputSchema(excerpts, new Set(visible.filter((item) => item.kind === 'news').map((item) => item.id)), targetHasInstalledVersion), maxOutput);
391
719
  const serialized = JSON.stringify(body);
392
- // Reserve conservatively; never refund timeouts, invalid output or possibly billed requests.
393
- const inputAllowance = Buffer.byteLength(serialized) + 512;
720
+ // Reserve before sending; never refund timeouts, invalid output or possibly billed requests.
721
+ // One token per three bytes over-counts ordinary text (about four bytes per token) without
722
+ // charging the budget a whole token for every byte.
723
+ const inputAllowance = Math.ceil(Buffer.byteLength(serialized) / 3) + 512;
394
724
  const usd = spec.input_usd_per_million === undefined || spec.output_usd_per_million === undefined
395
725
  ? undefined
396
726
  : Math.ceil(((inputAllowance * spec.input_usd_per_million + maxOutput * spec.output_usd_per_million) /