@clear-capabilities/agentic-security-scanner 0.172.0 → 0.173.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bin/agentic-security.js +37 -0
  3. package/dist/119.index.js +197 -0
  4. package/dist/128.index.js +129 -0
  5. package/dist/1293.index.js +5689 -0
  6. package/dist/1336.index.js +101 -101
  7. package/dist/1351.index.js +133 -0
  8. package/dist/1387.index.js +271 -0
  9. package/dist/1437.index.js +23 -0
  10. package/dist/1445.index.js +110 -0
  11. package/dist/1505.index.js +151 -0
  12. package/dist/1557.index.js +293 -0
  13. package/dist/1621.index.js +311 -0
  14. package/dist/1751.index.js +160 -0
  15. package/dist/1765.index.js +727 -0
  16. package/dist/1861.index.js +690 -0
  17. package/dist/1898.index.js +116 -0
  18. package/dist/1906.index.js +433 -0
  19. package/dist/1920.index.js +1 -291
  20. package/dist/208.index.js +1631 -0
  21. package/dist/2199.index.js +0 -239
  22. package/dist/2223.index.js +159 -0
  23. package/dist/2530.index.js +152 -0
  24. package/dist/2565.index.js +116 -0
  25. package/dist/2574.index.js +127 -0
  26. package/dist/2620.index.js +345 -0
  27. package/dist/2773.index.js +98 -0
  28. package/dist/2775.index.js +32 -0
  29. package/dist/2966.index.js +171 -0
  30. package/dist/2972.index.js +87 -0
  31. package/dist/2991.index.js +131 -0
  32. package/dist/3063.index.js +833 -0
  33. package/dist/3075.index.js +227 -0
  34. package/dist/3121.index.js +297 -0
  35. package/dist/3314.index.js +263 -0
  36. package/dist/3480.index.js +1822 -0
  37. package/dist/3481.index.js +24 -0
  38. package/dist/3506.index.js +268 -0
  39. package/dist/3533.index.js +591 -0
  40. package/dist/3653.index.js +450 -0
  41. package/dist/3822.index.js +131 -0
  42. package/dist/3868.index.js +292 -0
  43. package/dist/3917.index.js +152 -0
  44. package/dist/3918.index.js +192 -0
  45. package/dist/4090.index.js +288 -0
  46. package/dist/4121.index.js +1190 -0
  47. package/dist/4142.index.js +0 -239
  48. package/dist/4336.index.js +436 -0
  49. package/dist/4387.index.js +532 -0
  50. package/dist/4413.index.js +302 -0
  51. package/dist/4476.index.js +4510 -0
  52. package/dist/4491.index.js +133 -0
  53. package/dist/4538.index.js +185 -0
  54. package/dist/4684.index.js +319 -0
  55. package/dist/4740.index.js +165 -0
  56. package/dist/4780.index.js +209 -0
  57. package/dist/4802.index.js +225 -0
  58. package/dist/4812.index.js +379 -0
  59. package/dist/4835.index.js +126 -0
  60. package/dist/494.index.js +226 -0
  61. package/dist/4991.index.js +549 -0
  62. package/dist/5199.index.js +305 -0
  63. package/dist/5216.index.js +109 -0
  64. package/dist/5439.index.js +301 -0
  65. package/dist/5443.index.js +97 -0
  66. package/dist/5496.index.js +377 -0
  67. package/dist/550.index.js +2 -1
  68. package/dist/5801.index.js +588 -0
  69. package/dist/5858.index.js +223 -0
  70. package/dist/5933.index.js +143 -0
  71. package/dist/601.index.js +23 -0
  72. package/dist/6173.index.js +273 -0
  73. package/dist/6291.index.js +1871 -0
  74. package/dist/6312.index.js +666 -0
  75. package/dist/634.index.js +16182 -0
  76. package/dist/644.index.js +87 -0
  77. package/dist/6508.index.js +283 -0
  78. package/dist/6560.index.js +645 -0
  79. package/dist/6576.index.js +422 -0
  80. package/dist/6579.index.js +271 -0
  81. package/dist/6745.index.js +305 -0
  82. package/dist/6818.index.js +21642 -0
  83. package/dist/6972.index.js +167 -0
  84. package/dist/6995.index.js +163 -0
  85. package/dist/7249.index.js +191 -0
  86. package/dist/7372.index.js +1197 -0
  87. package/dist/7405.index.js +23 -6
  88. package/dist/7546.index.js +541 -0
  89. package/dist/76.index.js +448 -0
  90. package/dist/7879.index.js +163 -0
  91. package/dist/8025.index.js +130 -0
  92. package/dist/8054.index.js +248 -0
  93. package/dist/8097.index.js +201 -0
  94. package/dist/8126.index.js +191 -0
  95. package/dist/8178.index.js +78 -0
  96. package/dist/818.index.js +212 -0
  97. package/dist/8382.index.js +93 -0
  98. package/dist/8408.index.js +261 -0
  99. package/dist/8540.index.js +174 -0
  100. package/dist/8635.index.js +802 -0
  101. package/dist/8688.index.js +410 -0
  102. package/dist/8699.index.js +779 -0
  103. package/dist/8891.index.js +457 -0
  104. package/dist/8916.index.js +885 -0
  105. package/dist/9146.index.js +170 -0
  106. package/dist/9168.index.js +841 -0
  107. package/dist/9292.index.js +369 -0
  108. package/dist/9382.index.js +338 -48
  109. package/dist/9422.index.js +866 -0
  110. package/dist/9440.index.js +453 -0
  111. package/dist/9479.index.js +152 -0
  112. package/dist/9481.index.js +220 -0
  113. package/dist/9539.index.js +100 -0
  114. package/dist/9547.index.js +103 -0
  115. package/dist/9560.index.js +41 -61
  116. package/dist/9692.index.js +90 -0
  117. package/dist/9800.index.js +213 -1
  118. package/dist/9899.index.js +138 -0
  119. package/dist/9981.index.js +206 -0
  120. package/dist/999.index.js +117 -0
  121. package/dist/agentic-security.mjs +28 -28
  122. package/dist/agentic-security.mjs.sha256 +1 -1
  123. package/package.json +31 -6
  124. package/src/context-intelligence/CLAUDE.md +4 -0
  125. package/src/context-intelligence/adapters/haskell-hie.js +28 -1
  126. package/src/context-intelligence/candidates.js +2 -1
  127. package/src/context-intelligence/canonical.js +25 -0
  128. package/src/context-intelligence/capabilities.js +2 -1
  129. package/src/context-intelligence/cli.js +16 -10
  130. package/src/context-intelligence/config.js +4 -1
  131. package/src/context-intelligence/controls.js +108 -10
  132. package/src/context-intelligence/counterexample.js +200 -0
  133. package/src/context-intelligence/cross-route.js +111 -0
  134. package/src/context-intelligence/entrypoints.js +2 -2
  135. package/src/context-intelligence/evaluation/index.js +11 -4
  136. package/src/context-intelligence/evaluation/scripted-reader.js +12 -2
  137. package/src/context-intelligence/findings.js +166 -0
  138. package/src/context-intelligence/invariants.js +197 -0
  139. package/src/context-intelligence/queue.js +6 -1
  140. package/src/context-intelligence/reachability.js +10 -4
  141. package/src/context-intelligence/review.js +129 -16
  142. package/src/dataflow/access-paths.js +11 -0
  143. package/src/dataflow/analysis-limits.js +66 -0
  144. package/src/dataflow/engine.js +272 -20
  145. package/src/dataflow/service-edges.js +174 -0
  146. package/src/dataflow/summaries.js +7 -1
  147. package/src/discovery/judge.js +2 -1
  148. package/src/engine.js +82 -14
  149. package/src/fix/apply-fix-service.js +55 -8
  150. package/src/fix/batch-journal.js +84 -0
  151. package/src/fix/exploit-replay.js +51 -0
  152. package/src/fix/footprint.js +65 -0
  153. package/src/fix/patch-policy.js +49 -0
  154. package/src/fix/secret-persistence.js +39 -0
  155. package/src/fix/test-commands.js +84 -0
  156. package/src/fix/verification-adapters.js +97 -0
  157. package/src/fix/verification-record.js +243 -0
  158. package/src/fix/verify-patch.js +89 -0
  159. package/src/ir/CLAUDE.md +5 -0
  160. package/src/ir/callgraph.js +23 -1
  161. package/src/ir/module-resolver.js +315 -0
  162. package/src/ir/parser-js.js +21 -2
  163. package/src/ir/semantic-graph.js +245 -0
  164. package/src/lineage/build-attested-correlation.js +63 -0
  165. package/src/lineage/deployment-identity.js +76 -0
  166. package/src/mcp/tools.js +13 -34
  167. package/src/pipeline/canonical-output.js +64 -0
  168. package/src/pipeline/detector-runner.js +7 -0
  169. package/src/pipeline/scan-health.js +14 -0
  170. package/src/pipeline/supervised-analyzers.js +125 -0
  171. package/src/pipeline/supervised-child.js +17 -0
  172. package/src/pipeline/telemetry.js +79 -0
  173. package/src/posture/accuracy-scorecard.js +98 -9
  174. package/src/posture/artifact-registry.js +5 -0
  175. package/src/posture/assurance/evidence-registry.js +215 -0
  176. package/src/posture/assurance/release-package-verify.js +135 -0
  177. package/src/posture/assurance/release-package.js +118 -0
  178. package/src/posture/assurance/release-verdict.js +94 -0
  179. package/src/posture/assurance/waiver.js +200 -0
  180. package/src/posture/compliance-truth.js +100 -0
  181. package/src/posture/evaluation/scan-child.js +3 -1
  182. package/src/posture/evaluation/why-missed.js +3 -1
  183. package/src/posture/exploitability-evidence.js +141 -0
  184. package/src/posture/fix-verify.js +4 -2
  185. package/src/posture/fleet/exposure-ranking.js +115 -0
  186. package/src/posture/fleet/service-chain-graph.js +150 -0
  187. package/src/posture/graph-reconciliation.js +154 -0
  188. package/src/posture/provenance/coverage.js +103 -0
  189. package/src/posture/provenance/git-evidence.js +84 -0
  190. package/src/posture/provenance/origin-resolver.js +7 -1
  191. package/src/posture/provenance/predicate-replay.js +14 -4
  192. package/src/posture/runtime-correlation.js +61 -15
  193. package/src/posture/runtime-explanation.js +116 -0
  194. package/src/posture/runtime-trace-ingest.js +194 -0
  195. package/src/posture/scan-checkpoint.js +38 -10
  196. package/src/posture/waf-ingest.js +7 -2
  197. package/src/report/index.js +4 -0
  198. package/src/report/oscal.js +38 -0
  199. package/src/report/perspectives.js +150 -0
  200. package/src/sast/_comment-strip.js +8 -1
  201. package/src/sast/ruby.js +26 -0
  202. package/src/util/string-memo.js +38 -0
@@ -0,0 +1,271 @@
1
+ export const id = 1387;
2
+ export const ids = [1387];
3
+ export const modules = {
4
+
5
+ /***/ 91387:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+
9
+ // EXPORTS
10
+ __webpack_require__.d(__webpack_exports__, {
11
+ buildViews: () => (/* binding */ buildViews),
12
+ renderHtml: () => (/* binding */ renderHtml),
13
+ renderText: () => (/* binding */ renderText)
14
+ });
15
+
16
+ // UNUSED EXPORTS: buildCanonicalFindings
17
+
18
+ // EXTERNAL MODULE: external "node:crypto"
19
+ var external_node_crypto_ = __webpack_require__(77598);
20
+ ;// CONCATENATED MODULE: ./src/posture/assurance/release-verdict.js
21
+ // The release verdict (E7-08): a deterministic function from a release package to one of three answers, with every reason in plain words.
22
+ //
23
+ // not_deployable a condition the policy treats as blocking is present: an unfinished scan, files that were not scanned, an analyzer that timed out or failed,
24
+ // a fix that was claimed and not verified, an open finding that is proven exploitable, an open high or critical finding
25
+ // needs_review nothing blocks, but something is unknown and a person has to decide: a signal the context analysis could not settle, runtime evidence that
26
+ // came from a different build, a finding of unproven exploitability that is high or critical
27
+ // deployable none of the above. This is NOT a statement that the release is safe; it says no blocking or unknown condition was found in the evidence the package holds
28
+ //
29
+ // The word "safe" is never produced. The verdict is a function of the package alone (no clock, no environment), so the same package gives the same verdict and the same
30
+ // reasons in the same order, and a stated verdict that differs from the one recomputed here is refused (`verifyStatedVerdict`).
31
+ //
32
+ // WHAT COUNTS AS A BLOCKER is the policy below, not a judgement made per release. Waived findings (a waiver the package lists as honoured) do not block but are listed.
33
+ const SEV_BLOCK = new Set(['critical', 'high']);
34
+
35
+ const asArray = (v) => (Array.isArray(v) ? v : []);
36
+ const by = (pkg, kind) => asArray(pkg && pkg.evidence).filter((e) => e && e.ref && e.ref.kind === kind);
37
+
38
+ /**
39
+ * @param {object} pkg a release package
40
+ * @param {{waivedIds?:string[]}} [opts] finding ids covered by an honoured waiver
41
+ * @returns {{verdict:'not_deployable'|'needs_review'|'deployable', blockers:{code:string, message:string, evidence:string[]}[], unknowns:{code:string, message:string, evidence:string[]}[], waived:string[], statement:string}}
42
+ */
43
+ function releaseVerdict(pkg, { waivedIds = [] } = {}) {
44
+ const blockers = []; const unknowns = [];
45
+ const block = (code, message, evidence = []) => blockers.push({ code, message, evidence });
46
+ const unk = (code, message, evidence = []) => unknowns.push({ code, message, evidence });
47
+ const waived = new Set(waivedIds);
48
+
49
+ // ---- the scan itself
50
+ const health = by(pkg, 'scan-health')[0];
51
+ if (!health) block('NO_SCAN_HEALTH', 'the package holds no scan health, so nothing says the scan finished');
52
+ else {
53
+ const h = health.payload || {}; const ev = [health.ref.digest];
54
+ if (h.status !== 'complete') block('SCAN_INCOMPLETE', `the scan did not finish cleanly (status ${JSON.stringify(h.status ?? 'unknown')}): ${asArray(h.conditions).join('; ') || 'no reason was recorded'}`, ev);
55
+ const f = h.files || {};
56
+ if (Number.isFinite(f.expected) && Number.isFinite(f.scanned) && f.scanned < f.expected) block('FILES_NOT_SCANNED', `${f.expected - f.scanned} of ${f.expected} files were not scanned`, ev);
57
+ else if (Number.isFinite(f.unanalysed) ? f.unanalysed > 0 : (Number.isFinite(f.skipped) && f.skipped > 0)) block('FILES_SKIPPED', `${Number.isFinite(f.unanalysed) ? f.unanalysed : f.skipped} file(s) were skipped (too large or too dense to analyse)`, ev);
58
+ if (Number.isFinite(f.timedOut) && f.timedOut > 0) block('FILES_TIMED_OUT', `${f.timedOut} file(s) exceeded the per-file analysis time`, ev);
59
+ const a = h.analyzers || {};
60
+ if (Number.isFinite(a.timedOut) && a.timedOut > 0) block('ANALYZER_TIMED_OUT', `${a.timedOut} analyzer(s) timed out, so what they would have found is not in this result`, ev);
61
+ if (Number.isFinite(a.failed) && a.failed > 0 && !(Number.isFinite(a.timedOut) && a.failed === a.timedOut)) block('ANALYZER_FAILED', `${a.failed} analyzer(s) failed, so what they would have found is not in this result`, ev);
62
+ if (h.deepAnalysis && Array.isArray(h.deepAnalysis.incomplete) && h.deepAnalysis.incomplete.length) unk('DEEP_ANALYSIS_INCOMPLETE', `deep analysis stopped short: ${h.deepAnalysis.incomplete.map((x) => `${x.reason} x${x.count}`).join(', ')}`, ev);
63
+ }
64
+
65
+ // ---- findings and fixes
66
+ const fixes = by(pkg, 'fix-verification');
67
+ const fixFor = (id) => fixes.filter((x) => x.payload && (x.payload.findingStableId === id || x.payload.findingId === id));
68
+ for (const e of by(pkg, 'finding')) {
69
+ const f = e.payload || {}; const id = e.ref.payloadId || f.stableId || f.id; const ev = [e.ref.digest];
70
+ const triage = f.triage && f.triage.state;
71
+ const falsePositive = triage === 'false_positive' || f.falsePositive === true;
72
+ const myFixes = fixFor(id); const fixed = myFixes.find((x) => x.payload.verifiedFull === true);
73
+ if (waived.has(id)) continue;
74
+ if (falsePositive) {
75
+ if (!(f.triage && f.triage.by && f.triage.reason)) unk('FALSE_POSITIVE_UNJUSTIFIED', `finding ${id} is marked a false positive without a named person and a reason`, ev);
76
+ continue;
77
+ }
78
+ for (const x of myFixes) if (x.payload.verifiedFull !== true) block('FIX_NOT_VERIFIED', `a fix for ${id} is claimed but was not fully verified (${asArray(x.payload.degradedLegs).map((d) => (typeof d === 'string' ? d : d && d.leg)).filter(Boolean).join(', ') || 'checks did not all pass'})`, [...ev, x.ref.digest]);
79
+ if (fixed) continue;
80
+ const sev = String(f.severity || 'info'); const tier = typeof f.proofTier === 'string' ? f.proofTier : 'unproven';
81
+ const ci = f.contextIntelligence && (f.contextIntelligence.counterexample && f.contextIntelligence.counterexample.state || f.contextIntelligence.state);
82
+ if (tier === 'execution-proven') block('PROVEN_OPEN_FINDING', `finding ${id} (${sev}) is proven exploitable and is open`, ev);
83
+ else if (SEV_BLOCK.has(sev)) {
84
+ if (ci === 'unresolved' || ci === 'plausible') unk('CONTEXT_SIGNAL_UNSETTLED', `finding ${id} (${sev}) rests on a context signal the analysis could not settle (${ci}); a person has to decide whether it is real`, ev);
85
+ else block('OPEN_HIGH_FINDING', `finding ${id} is open at severity ${sev}`, ev);
86
+ } else if (ci === 'unresolved' || ci === 'plausible') unk('CONTEXT_SIGNAL_UNSETTLED', `finding ${id} rests on a context signal the analysis could not settle (${ci})`, ev);
87
+ }
88
+
89
+ // ---- runtime evidence from another build
90
+ for (const e of by(pkg, 'runtime-explanation')) {
91
+ const edges = asArray(e.payload && e.payload.runtime && e.payload.runtime.edges); const bad = edges.filter((x) => Number(x.mismatchedRecords) > 0);
92
+ if (bad.length) unk('RUNTIME_BUILD_MISMATCH', `runtime records for ${bad.length} edge(s) of ${e.ref.payloadId || 'a finding'} came from a different build than the one released, so they say nothing about this release and are not counted as corroboration`, [e.ref.digest]);
93
+ const miss = asArray(e.payload && e.payload.runtime && e.payload.runtime.missingObservations);
94
+ if (!bad.length && miss.length && e.payload.compare && e.payload.compare.state !== 'corroborated') unk('RUNTIME_NOT_CORROBORATED', `runtime evidence for ${e.ref.payloadId || 'a finding'} does not corroborate the path: ${miss[0]}`, [e.ref.digest]);
95
+ }
96
+
97
+ blockers.sort((a, b) => (a.code + a.message < b.code + b.message ? -1 : 1)); unknowns.sort((a, b) => (a.code + a.message < b.code + b.message ? -1 : 1));
98
+ const verdict = blockers.length ? 'not_deployable' : unknowns.length ? 'needs_review' : 'deployable';
99
+ const statement = verdict === 'deployable'
100
+ ? 'No blocking or unknown condition was found in the evidence this package holds. That is not a statement that the release is safe.'
101
+ : verdict === 'needs_review' ? `Nothing blocks the release, but ${unknowns.length} thing(s) are unknown and a person has to decide.` : `${blockers.length} condition(s) block the release.`;
102
+ return { verdict, blockers, unknowns, waived: [...waived].sort(), statement };
103
+ }
104
+
105
+ /** Is the verdict a package states the one its own contents give? @returns {{ok:boolean, stated:string|null, computed:string, message:string|null}} */
106
+ function verifyStatedVerdict(pkg, opts) {
107
+ const computed = releaseVerdict(pkg, opts).verdict;
108
+ const decisions = asArray(pkg && pkg.policy && pkg.policy.decisions);
109
+ const d = decisions.find((x) => x && x.id === 'release-verdict');
110
+ const stated = d ? d.outcome : null;
111
+ if (stated === null) return { ok: false, stated, computed, message: 'the package states no release verdict' };
112
+ if (stated !== computed) return { ok: false, stated, computed, message: `the package states "${stated}" but its own contents give "${computed}"` };
113
+ return { ok: true, stated, computed, message: null };
114
+ }
115
+
116
+ ;// CONCATENATED MODULE: ./src/report/perspectives.js
117
+ // Three views of one release (E7-07): what a developer needs, what a CISO needs, what an auditor needs, all built from the SAME canonical list of findings so they
118
+ // cannot disagree.
119
+ //
120
+ // developer where the problem is, why it is one, how to fix it, and whether a fix was verified
121
+ // CISO what is proven and what is not, what changed since the previous release, how risky and how complete
122
+ // auditor for each assertion and each unknown, the evidence it rests on (by digest) and why anything is unknown; the issuer and what the signature does not prove
123
+ //
124
+ // One list, three projections. `canonicalFindings` is computed once from the release package; every view only selects and arranges its fields, and each entry
125
+ // carries the same finding id, status, evidence hash and confidence wherever it appears. Nothing is recomputed per view.
126
+ //
127
+ // The package is DATA from a repository we do not control: every string is escaped before it reaches HTML, the page loads nothing from anywhere and runs no script, and a
128
+ // content security policy says so.
129
+
130
+
131
+
132
+ const esc = (v) => String(v ?? '').replace(/[&<>"'`]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '`': '&#96;' }[c]));
133
+ const sevRank = { critical: 4, high: 3, medium: 2, low: 1, info: 0 };
134
+
135
+ function confidenceOf(f) {
136
+ if (typeof f.confidence === 'number') return f.confidence >= 0.8 ? 'high' : f.confidence >= 0.5 ? 'medium' : 'low';
137
+ return typeof f.confidenceTier === 'string' ? f.confidenceTier : 'unknown';
138
+ }
139
+
140
+ /**
141
+ * @param {object} pkg a release package (E7-03). It is assumed to have been verified by the caller; the views carry `verification` as the caller states it.
142
+ * @param {{previous?:object, ranking?:object, verification?:{ok:boolean, errors?:object[]}}} opts `previous` is the previous release's package; `ranking` is a result of rankFleetExposure
143
+ */
144
+ function buildCanonicalFindings(pkg) {
145
+ const entries = Array.isArray(pkg && pkg.evidence) ? pkg.evidence : [];
146
+ const byKind = (k) => entries.filter((e) => e.ref && e.ref.kind === k);
147
+ const fixes = byKind('fix-verification');
148
+ const out = [];
149
+ for (const e of byKind('finding')) {
150
+ const f = e.payload || {};
151
+ const id = e.ref.payloadId || f.stableId || f.id;
152
+ const fixesFor = fixes.filter((x) => x.payload && (x.payload.findingStableId === id || x.payload.findingId === id || x.payload.findingId === f.id) );
153
+ const fix = fixesFor.find((x) => x.payload.verifiedFull === true) || fixesFor[0] || null;
154
+ const status = !fix ? 'open' : fix.payload.verifiedFull === true ? 'fix-verified' : 'fix-unverified';
155
+ out.push({
156
+ id, evidenceHash: e.ref.digest, status, confidence: confidenceOf(f), severity: f.severity || 'info', proofTier: typeof f.proofTier === 'string' ? f.proofTier : 'unproven',
157
+ where: { file: f.file ?? null, line: Number.isInteger(f.line) ? f.line : null }, title: f.vuln || f.title || 'finding', cwe: f.cwe || null,
158
+ why: f.description || f.reason || null, how: f.remediation || null,
159
+ fix: fix ? { evidenceHash: fix.ref.digest, verifiedFull: fix.payload.verifiedFull === true, completeness: fix.payload.fixCompleteness || null, degradedLegs: Array.isArray(fix.payload.degradedLegs) ? fix.payload.degradedLegs.map((d) => (typeof d === 'string' ? d : d && d.leg) ).filter(Boolean) : [] } : null,
160
+ });
161
+ }
162
+ return out.sort((a, b) => (sevRank[b.severity] - sevRank[a.severity]) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
163
+ }
164
+
165
+ function buildViews(pkg, { previous = null, ranking = null, verification = null } = {}) {
166
+ const findings = buildCanonicalFindings(pkg);
167
+ const packageDigest = `sha256:${(0,external_node_crypto_.createHash)('sha256').update(JSON.stringify(pkg && pkg.lineageOrder || [])).digest('hex')}`;
168
+ const prev = previous ? buildCanonicalFindings(previous) : null;
169
+ const prevById = prev ? new Map(prev.map((f) => [f.id, f])) : null;
170
+ const ids = new Set(findings.map((f) => f.id));
171
+ const change = prev ? {
172
+ new: findings.filter((f) => !prevById.has(f.id)).map((f) => f.id),
173
+ resolved: prev.filter((f) => !ids.has(f.id)).map((f) => f.id),
174
+ statusChanged: findings.filter((f) => prevById.has(f.id) && prevById.get(f.id).status !== f.status).map((f) => ({ id: f.id, from: prevById.get(f.id).status, to: f.status })),
175
+ unchanged: findings.filter((f) => prevById.has(f.id) && prevById.get(f.id).status === f.status).length,
176
+ } : null;
177
+ const rankById = ranking ? new Map(ranking.ranked.map((r) => [r.id, r])) : null;
178
+ const tier = (t) => findings.filter((f) => f.proofTier === t).length;
179
+ const completeness = pkg && pkg.completeness ? { verdict: pkg.completeness.verdict, scanStatus: pkg.completeness.scanStatus, conditions: pkg.completeness.conditions || [] } : { verdict: 'unknown', scanStatus: 'unknown', conditions: [] };
180
+ const unknowns = [];
181
+ if (completeness.verdict !== 'complete') for (const c of completeness.conditions.length ? completeness.conditions : ['the scan did not report that it finished']) unknowns.push({ about: 'scan completeness', reason: c, evidence: pkg.completeness && pkg.completeness.source ? [pkg.completeness.source] : [] });
182
+ for (const a of (pkg && pkg.assertions) || []) if (a.status !== 'supported') unknowns.push({ about: a.text, reason: a.reason || `the assertion is ${a.status}`, evidence: a.evidence || [] });
183
+ for (const f of findings) if (f.proofTier !== 'execution-proven') unknowns.push({ about: `exploitability of ${f.id}`, reason: `proof tier is ${f.proofTier}: it has not been shown to be exploitable`, evidence: [f.evidenceHash] });
184
+
185
+ const developer = findings.map((f) => ({ id: f.id, evidenceHash: f.evidenceHash, status: f.status, confidence: f.confidence, severity: f.severity, where: f.where, why: f.why, how: f.how, title: f.title, cwe: f.cwe, fix: f.fix }));
186
+ const verdict = releaseVerdict(pkg);
187
+ const ciso = {
188
+ verdict: { verdict: verdict.verdict, statement: verdict.statement, blockers: verdict.blockers.map((b) => b.message), unknowns: verdict.unknowns.map((u) => u.message) },
189
+ verified: verification ? verification.ok === true : null,
190
+ scan: completeness,
191
+ proven: { executionProven: tier('execution-proven'), taintProven: tier('taint-proven'), unproven: findings.length - tier('execution-proven') - tier('taint-proven'), total: findings.length },
192
+ bySeverity: Object.fromEntries(['critical', 'high', 'medium', 'low', 'info'].map((s) => [s, findings.filter((f) => f.severity === s).length])),
193
+ fixes: { verified: findings.filter((f) => f.status === 'fix-verified').length, unverified: findings.filter((f) => f.status === 'fix-unverified').length, open: findings.filter((f) => f.status === 'open').length },
194
+ changeSinceLast: change,
195
+ risk: ranking ? { byPriority: ranking.summary.byPriority, incompleteCoverage: ranking.summary.incompleteCoverage, top: ranking.ranked.slice(0, 5).map((r) => ({ id: r.id, priority: r.priority, rule: r.rule })) } : null,
196
+ findings: findings.map((f) => ({ id: f.id, evidenceHash: f.evidenceHash, status: f.status, confidence: f.confidence, severity: f.severity, proofTier: f.proofTier, priority: rankById && rankById.get(f.id) ? rankById.get(f.id).priority : null })),
197
+ };
198
+ const auditor = {
199
+ package: { lineageDigest: packageDigest, snapshot: pkg && pkg.snapshot ? { commit: pkg.snapshot.commit, immutable: pkg.snapshot.immutable, digest: pkg.snapshot.digest } : null },
200
+ issuer: pkg && pkg.issuance ? { trustBasis: pkg.issuance.trustBasis, independentlyCertified: pkg.issuance.independentlyCertified, keyFingerprint: pkg.issuance.issuer && pkg.issuance.issuer.keyFingerprint } : null,
201
+ verification: verification ? { ok: verification.ok === true, errors: (verification.errors || []).map((e) => `${e.code}: ${e.message}`) } : { ok: null, errors: ['no verification was performed by this view'] },
202
+ proves: pkg && pkg.proves || null, doesNotProve: pkg && pkg.doesNotProve || null,
203
+ assertions: ((pkg && pkg.assertions) || []).map((a) => ({ id: a.id, text: a.text, status: a.status, evidence: a.evidence || [], reason: a.reason || null })),
204
+ unknowns,
205
+ findings: findings.map((f) => ({ id: f.id, evidenceHash: f.evidenceHash, status: f.status, confidence: f.confidence, proofTier: f.proofTier, fixEvidence: f.fix ? f.fix.evidenceHash : null })),
206
+ policyDecisions: (pkg && pkg.policy && pkg.policy.decisions) || [],
207
+ };
208
+ return { canonical: findings, developer, ciso, auditor };
209
+ }
210
+
211
+ // ---- text ------------------------------------------------------------------------------------------------------------------------
212
+
213
+ function renderText(views, view = 'all') {
214
+ const L = [];
215
+ const dev = () => { L.push('DEVELOPER VIEW'); for (const f of views.developer) { L.push(` [${f.severity}] ${f.title} ${f.where.file ?? '?'}:${f.where.line ?? '?'} id=${f.id} status=${f.status} confidence=${f.confidence} evidence=${f.evidenceHash.slice(0, 19)}`); if (f.why) L.push(` why: ${String(f.why).slice(0, 300)}`); if (f.how) L.push(` fix: ${String(f.how).slice(0, 300)}`); if (f.fix) L.push(` fix check: ${f.fix.verifiedFull ? 'verified' : 'not fully verified'}${f.fix.degradedLegs.length ? ` (not passed: ${f.fix.degradedLegs.join(', ')})` : ''}`); } if (!views.developer.length) L.push(' no findings'); };
216
+ const ciso = () => { const c = views.ciso; L.push('CISO VIEW'); L.push(` release verdict: ${c.verdict.verdict}. ${c.verdict.statement}`); for (const b of c.verdict.blockers) L.push(` blocks: ${b}`); for (const u of c.verdict.unknowns) L.push(` unknown: ${u}`); L.push(` scan: ${c.scan.verdict} (${c.scan.scanStatus})${c.scan.conditions.length ? ' - ' + c.scan.conditions.join('; ') : ''}`); L.push(` proven: ${c.proven.executionProven} executed, ${c.proven.taintProven} taint path, ${c.proven.unproven} unproven, of ${c.proven.total}`); L.push(` fixes: ${c.fixes.verified} verified, ${c.fixes.unverified} unverified, ${c.fixes.open} open`); if (c.changeSinceLast) L.push(` since last release: ${c.changeSinceLast.new.length} new, ${c.changeSinceLast.resolved.length} resolved, ${c.changeSinceLast.statusChanged.length} changed status`); else L.push(' since last release: no previous release was supplied'); if (c.risk) L.push(` risk: ${JSON.stringify(c.risk.byPriority)}; ${c.risk.incompleteCoverage} with incomplete coverage`); L.push(` verification: ${c.verified === null ? 'not performed here' : c.verified ? 'signature and contents verified' : 'FAILED'}`); };
217
+ const aud = () => { const a = views.auditor; L.push('AUDITOR VIEW'); L.push(` snapshot: ${a.package.snapshot ? `${a.package.snapshot.commit ?? 'no commit'} (${a.package.snapshot.immutable ? 'immutable' : 'NOT immutable'})` : 'none'}`); L.push(` issuer: ${a.issuer ? `${a.issuer.trustBasis}, independently certified: ${a.issuer.independentlyCertified}` : 'none'}`); L.push(` verification: ${a.verification.ok === null ? 'not performed here' : a.verification.ok ? 'ok' : 'FAILED: ' + a.verification.errors.join('; ')}`); for (const x of a.assertions) L.push(` assertion ${x.id} [${x.status}]: ${x.text} evidence=${x.evidence.map((d) => d.slice(0, 19)).join(',') || 'none'}`); for (const u of a.unknowns) L.push(` unknown: ${u.about} - ${u.reason}`); L.push(` does not prove: ${a.doesNotProve}`); };
218
+ if (view === 'developer' || view === 'all') dev();
219
+ if (view === 'ciso' || view === 'all') ciso();
220
+ if (view === 'auditor' || view === 'all') aud();
221
+ return L.join('\n') + '\n';
222
+ }
223
+
224
+ // ---- html ------------------------------------------------------------------------------------------------------------------------
225
+
226
+ /** One self-contained page, no script, nothing loaded from elsewhere. Every value is escaped. */
227
+ function renderHtml(views, { title = 'Release assurance report' } = {}) {
228
+ const c = views.ciso; const a = views.auditor;
229
+ const row = (f, cols) => `<tr data-finding="${esc(f.id)}" data-evidence="${esc(f.evidenceHash)}" data-status="${esc(f.status)}" data-confidence="${esc(f.confidence)}">${cols.map((x) => `<td>${x}</td>`).join('')}</tr>`;
230
+ return `<!doctype html>
231
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
232
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:">
233
+ <title>${esc(title)}</title>
234
+ <style>
235
+ :root{--bg:#fff;--fg:#1a1a1a;--muted:#555;--line:#d0d0d0;--bad:#a40000;--ok:#0a6b2b}
236
+ @media (prefers-color-scheme: dark){:root{--bg:#14161a;--fg:#e8e8e8;--muted:#a0a0a0;--line:#3a3d44;--bad:#ff8080;--ok:#6fd48e}}
237
+ body{background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,sans-serif;margin:0 auto;max-width:72rem;padding:1rem 16px}
238
+ h1,h2{line-height:1.2}table{border-collapse:collapse;width:100%;overflow-wrap:anywhere}th,td{border:1px solid var(--line);padding:.35rem .5rem;text-align:left;vertical-align:top}
239
+ code{font-family:ui-monospace,monospace;font-size:.9em}.muted{color:var(--muted)}.bad{color:var(--bad)}.ok{color:var(--ok)}details{margin:1rem 0}summary{cursor:pointer;font-weight:600}
240
+ </style></head><body>
241
+ <h1>${esc(title)}</h1>
242
+ <p class="muted">Snapshot ${esc(a.package.snapshot ? a.package.snapshot.commit : 'none')} (${a.package.snapshot && a.package.snapshot.immutable ? 'immutable' : 'not immutable'}). Verification: <span class="${a.verification.ok === true ? 'ok' : 'bad'}">${esc(a.verification.ok === null ? 'not performed by this page' : a.verification.ok ? 'passed' : 'FAILED')}</span>.</p>
243
+ <details open><summary>Developer: where, why, how to fix</summary>
244
+ <table><thead><tr><th>Finding</th><th>Where</th><th>Why</th><th>How to fix</th><th>Status</th><th>Confidence</th></tr></thead><tbody>
245
+ ${views.developer.map((f) => row(f, [`<code>${esc(f.id)}</code> ${esc(f.title)}<br><span class="muted">${esc(f.severity)}${f.cwe ? ' ' + esc(f.cwe) : ''}</span>`, `<code>${esc(f.where.file ?? '?')}:${esc(f.where.line ?? '?')}</code>`, esc(f.why ?? ''), esc(f.how ?? ''), esc(f.status), esc(f.confidence)])).join('\n') || '<tr><td colspan="6">No findings.</td></tr>'}
246
+ </tbody></table></details>
247
+ <details open><summary>CISO: what is proven, what changed, risk and coverage</summary>
248
+ <p><strong>Release verdict: ${esc(c.verdict.verdict)}.</strong> ${esc(c.verdict.statement)}</p>
249
+ <ul>${c.verdict.blockers.map((b) => `<li class="bad">Blocks: ${esc(b)}</li>`).join('')}${c.verdict.unknowns.map((u) => `<li>Unknown: ${esc(u)}</li>`).join('')}</ul>
250
+ <p>Scan: <strong>${esc(c.scan.verdict)}</strong> (${esc(c.scan.scanStatus)}). ${c.scan.conditions.map((x) => esc(x)).join('; ')}</p>
251
+ <p>Proven: ${esc(c.proven.executionProven)} by execution, ${esc(c.proven.taintProven)} by a taint path, ${esc(c.proven.unproven)} unproven, of ${esc(c.proven.total)}. Fixes: ${esc(c.fixes.verified)} verified, ${esc(c.fixes.unverified)} unverified, ${esc(c.fixes.open)} open.</p>
252
+ <p>${c.changeSinceLast ? `Since the previous release: ${esc(c.changeSinceLast.new.length)} new, ${esc(c.changeSinceLast.resolved.length)} resolved, ${esc(c.changeSinceLast.statusChanged.length)} changed status.` : 'No previous release was supplied, so no change is reported.'}</p>
253
+ <table><thead><tr><th>Finding</th><th>Severity</th><th>Proof</th><th>Priority</th><th>Status</th><th>Confidence</th></tr></thead><tbody>
254
+ ${c.findings.map((f) => row(f, [`<code>${esc(f.id)}</code>`, esc(f.severity), esc(f.proofTier), esc(f.priority ?? 'not ranked'), esc(f.status), esc(f.confidence)])).join('\n') || '<tr><td colspan="6">No findings.</td></tr>'}
255
+ </tbody></table></details>
256
+ <details open><summary>Auditor: evidence behind each statement, and what is unknown</summary>
257
+ <p>Issuer: ${esc(a.issuer ? a.issuer.trustBasis : 'none')}; independently certified: ${esc(a.issuer ? a.issuer.independentlyCertified : 'n/a')}.</p>
258
+ <p class="muted">Proves: ${esc(a.proves)}<br>Does not prove: ${esc(a.doesNotProve)}</p>
259
+ <table><thead><tr><th>Finding</th><th>Evidence hash</th><th>Fix evidence</th><th>Status</th><th>Confidence</th></tr></thead><tbody>
260
+ ${a.findings.map((f) => row(f, [`<code>${esc(f.id)}</code>`, `<code>${esc(f.evidenceHash)}</code>`, `<code>${esc(f.fixEvidence ?? 'none')}</code>`, esc(f.status), esc(f.confidence)])).join('\n') || '<tr><td colspan="5">No findings.</td></tr>'}
261
+ </tbody></table>
262
+ <h2>Assertions</h2><ul>${a.assertions.map((x) => `<li><strong>${esc(x.status)}</strong>: ${esc(x.text)} <span class="muted">(${x.evidence.length ? x.evidence.map((d) => `<code>${esc(d)}</code>`).join(', ') : 'no evidence cited'}${x.reason ? '; ' + esc(x.reason) : ''})</span></li>`).join('') || '<li>None.</li>'}</ul>
263
+ <h2>Unknowns</h2><ul>${a.unknowns.map((u) => `<li>${esc(u.about)}: ${esc(u.reason)}</li>`).join('') || '<li>None.</li>'}</ul>
264
+ </details></body></html>
265
+ `;
266
+ }
267
+
268
+
269
+ /***/ })
270
+
271
+ };
@@ -0,0 +1,23 @@
1
+ export const id = 1437;
2
+ export const ids = [1437];
3
+ export const modules = {
4
+
5
+ /***/ 1437:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ __webpack_require__.r(__webpack_exports__);
9
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
10
+ /* harmony export */ BaseJavaCstVisitor: () => (/* reexport safe */ _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__.ak),
11
+ /* harmony export */ BaseJavaCstVisitorWithDefaults: () => (/* reexport safe */ _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__.C5),
12
+ /* harmony export */ "default": () => (/* reexport safe */ _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__.Ay),
13
+ /* harmony export */ lexAndParse: () => (/* reexport safe */ _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__.Ch),
14
+ /* harmony export */ parse: () => (/* reexport safe */ _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__.qg)
15
+ /* harmony export */ });
16
+ /* harmony import */ var _node_modules_java_parser_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6818);
17
+
18
+
19
+
20
+
21
+ /***/ })
22
+
23
+ };
@@ -0,0 +1,110 @@
1
+ export const id = 1445;
2
+ export const ids = [1445];
3
+ export const modules = {
4
+
5
+ /***/ 41445:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ deriveVexStatus: () => (/* binding */ deriveVexStatus)
10
+ /* harmony export */ });
11
+ /* unused harmony export VEX_STATUSES */
12
+ // PRD 5 P0 §8 — VEX (Vulnerability Exploitability eXchange). Statuses are the
13
+ // PRD's own four. The PRD's one explicit rule — "`not affected` requires
14
+ // positive evidence" — is enforced structurally: `not_affected` is only ever
15
+ // returned from one of two named, checked evidence paths below; there is no
16
+ // code path that reaches it by default or by absence of information.
17
+ // Justification strings follow the CISA VEX vocabulary this repo's other VEX
18
+ // output (`toVex` in `src/posture/sbom.js`'s neighborhood) already uses,
19
+ // where applicable.
20
+ //
21
+ // `affected` likewise requires positive evidence (confirmed reachability),
22
+ // not just "OSV lists this version as vulnerable" — a scanner result alone
23
+ // only tells you the CVE/version pair matches; it doesn't tell you the
24
+ // vulnerable code path is reachable in THIS artifact. Absent that
25
+ // confirmation, the honest status is `under_investigation`, never a
26
+ // confident `affected` the evidence doesn't support.
27
+ const VEX_STATUSES = Object.freeze(['affected', 'not_affected', 'fixed', 'under_investigation']);
28
+
29
+ // Loose dotted-numeric version comparison. Returns -1/0/1, or null when
30
+ // either side isn't a clean dotted-numeric form — a "fixed" verdict is only
31
+ // ever returned when this does NOT return null; an unparseable version
32
+ // means that evidence path is skipped, never guessed through.
33
+ function compareVersions(a, b) {
34
+ const pa = String(a).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
35
+ const pb = String(b).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
36
+ if (pa.some((n) => n === null) || pb.some((n) => n === null)) return null;
37
+ const len = Math.max(pa.length, pb.length);
38
+ for (let i = 0; i < len; i++) {
39
+ const x = pa[i] ?? 0;
40
+ const y = pb[i] ?? 0;
41
+ if (x !== y) return x < y ? -1 : 1;
42
+ }
43
+ return 0;
44
+ }
45
+
46
+ function componentKeyOf(c) {
47
+ return c.purl || (c.ecosystem && c.name && c.version ? `${c.ecosystem}:${c.name}@${c.version}` : null);
48
+ }
49
+
50
+ /**
51
+ * `vulnerability` is one `vulnerable_dep`-shaped entry already confirmed
52
+ * present via `vuln-correlate.js` against THIS artifact. `artifactComponents`
53
+ * is the artifact's own inventory (`osPackages`/`appPackages` concatenated).
54
+ * `reachability`, if supplied, is `{ reachable: true|false, reason }` from
55
+ * this codebase's existing dataflow/reachability evidence (never computed
56
+ * here — this module does no new analysis, only statuses the evidence it's
57
+ * handed).
58
+ */
59
+ function deriveVexStatus({ vulnerability, artifactComponents, reachability = null }) {
60
+ if (!vulnerability || typeof vulnerability !== 'object') {
61
+ throw new TypeError('deriveVexStatus requires a vulnerability object');
62
+ }
63
+ if (!Array.isArray(artifactComponents)) {
64
+ throw new TypeError('deriveVexStatus requires an artifactComponents array');
65
+ }
66
+
67
+ const vulnKey = vulnerability.purl
68
+ || (vulnerability.ecosystem && vulnerability.name && vulnerability.version ? `${vulnerability.ecosystem}:${vulnerability.name}@${vulnerability.version}` : null);
69
+ const present = vulnKey != null && artifactComponents.some((c) => componentKeyOf(c) === vulnKey);
70
+
71
+ if (!present) {
72
+ return {
73
+ status: 'not_affected',
74
+ justification: 'component_not_present',
75
+ evidence: 'the affected component (by purl/ecosystem+name+version) is not present in this artifact\'s inventory',
76
+ };
77
+ }
78
+
79
+ if (reachability && reachability.reachable === false) {
80
+ return {
81
+ status: 'not_affected',
82
+ justification: 'vulnerable_code_not_in_execute_path',
83
+ evidence: reachability.reason || 'static reachability analysis found no path to the vulnerable function in this artifact',
84
+ };
85
+ }
86
+
87
+ if (Array.isArray(vulnerability.fixedVersions) && vulnerability.fixedVersions.length && vulnerability.version) {
88
+ for (const fv of vulnerability.fixedVersions) {
89
+ const cmp = compareVersions(vulnerability.version, fv);
90
+ if (cmp !== null && cmp >= 0) {
91
+ return { status: 'fixed', justification: null, evidence: `installed version ${vulnerability.version} is >= the fixed version ${fv}` };
92
+ }
93
+ }
94
+ }
95
+
96
+ if (reachability && reachability.reachable === true) {
97
+ return { status: 'affected', justification: null, evidence: reachability.reason || 'static reachability analysis confirmed a path to the vulnerable function in this artifact' };
98
+ }
99
+
100
+ return {
101
+ status: 'under_investigation',
102
+ justification: null,
103
+ evidence: 'the affected component is present and not confirmed fixed, but reachability has not been established — not a confident "affected" claim',
104
+ };
105
+ }
106
+
107
+
108
+ /***/ })
109
+
110
+ };
@@ -0,0 +1,151 @@
1
+ export const id = 1505;
2
+ export const ids = [1505];
3
+ export const modules = {
4
+
5
+ /***/ 61505:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ computeRuntimeAssurance: () => (/* binding */ computeRuntimeAssurance)
10
+ /* harmony export */ });
11
+ /* unused harmony export RUNTIME_STATUS_VALUES */
12
+ // runtime-assurance.js — PRD "Runtime-Corroborated Security Twin" P0-8
13
+ // (Runtime Assurance). A pure aggregation over already-loaded observation
14
+ // imports and an already-computed `correlateObservations` result — never
15
+ // re-reads a file, never re-runs the match ladder. Honest by construction:
16
+ // the one rule this module exists to enforce is that a MISSING or STALE
17
+ // telemetry source can never collapse into "no runtime risk" — the
18
+ // `runtimeStatus` field is always exactly one of `'complete'`, `'partial'`,
19
+ // or `'unavailable'`, and `'unavailable'` is the answer whenever no
20
+ // observation store was consulted at all, never a silent empty report.
21
+ //
22
+ // `parseFailures` is always reported as 0, with an explicit note why:
23
+ // `dataflow observations import` REFUSES the whole import the moment any
24
+ // record fails to parse or validate (AC-29 clause 5) — a failed import is
25
+ // never persisted, so there is no on-disk history of parse failures for
26
+ // this module to read. This is a real, disclosed limitation, not a false
27
+ // "zero failures ever happened" claim.
28
+
29
+ const RUNTIME_STATUS_VALUES = Object.freeze(['complete', 'partial', 'unavailable']);
30
+
31
+ function _isPlainObject(v) {
32
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
33
+ }
34
+
35
+ function _maxIso(list) {
36
+ let best = null;
37
+ let bestT = -Infinity;
38
+ for (const s of list) {
39
+ const t = Date.parse(s);
40
+ if (Number.isFinite(t) && t > bestT) { bestT = t; best = s; }
41
+ }
42
+ return best;
43
+ }
44
+
45
+ function _minIso(list) {
46
+ let best = null;
47
+ let bestT = Infinity;
48
+ for (const s of list) {
49
+ const t = Date.parse(s);
50
+ if (Number.isFinite(t) && t < bestT) { bestT = t; best = s; }
51
+ }
52
+ return best;
53
+ }
54
+
55
+ /**
56
+ * `computeRuntimeAssurance(opts) -> RuntimeAssurance`
57
+ *
58
+ * `opts`:
59
+ * - `importRecords`: the `ObservationImport[]` read back from the store
60
+ * (`loadObservationImports`), or `null`/`undefined` when the store was
61
+ * never consulted at all (mirrors `correlateObservations`'s own
62
+ * `observations === null` convention).
63
+ * - `correlation`: the `CorrelationResult` from `correlateObservations`
64
+ * for the SAME graph/observations/window this call is reporting on.
65
+ * - `now`: an ISO-8601 string (defaults to `new Date().toISOString()`,
66
+ * injectable for deterministic tests).
67
+ * - `staleAfterHours`: how old the most recent observed event can be
68
+ * before freshness is reported stale (default 24 * 30 = 720, i.e. 30
69
+ * days — telemetry windows in this package's own fixtures/CLI default
70
+ * to month-long exports, so a 30-day staleness bar is the honest
71
+ * "this is still describing roughly the current system" line, not an
72
+ * arbitrary short window).
73
+ *
74
+ * Never throws.
75
+ */
76
+ function computeRuntimeAssurance(opts) {
77
+ const o = opts && typeof opts === 'object' ? opts : {};
78
+ const now = typeof o.now === 'string' && Number.isFinite(Date.parse(o.now)) ? o.now : new Date().toISOString();
79
+ const staleAfterHours = Number.isFinite(o.staleAfterHours) ? o.staleAfterHours : 720;
80
+
81
+ const importRecords = Array.isArray(o.importRecords) ? o.importRecords : null;
82
+ const correlation = _isPlainObject(o.correlation) ? o.correlation : null;
83
+
84
+ const base = {
85
+ runtimeStatus: 'unavailable',
86
+ telemetryWindow: { start: null, end: null },
87
+ freshness: { lastObservedAt: null, lastImportedAt: null, staleHours: null, stale: true },
88
+ parseFailures: 0,
89
+ parseFailuresNote: 'A failed import is refused in full and never persisted (AC-29 clause 5) — '
90
+ + 'this count reflects the import store, not the history of every attempt. Check `runtime ingest`\'s '
91
+ + 'own exit code/stderr at import time for parse failures.',
92
+ mappingPercentage: null,
93
+ unmatchedObservationCount: 0,
94
+ totalObservationCount: 0,
95
+ missingTelemetry: true,
96
+ limitations: [],
97
+ };
98
+
99
+ // No store was ever consulted — the honest 'unavailable' case, never a
100
+ // fabricated empty-but-fine report.
101
+ if (importRecords === null || importRecords.length === 0 || !correlation || correlation.evaluated !== true) {
102
+ base.limitations.push(
103
+ 'No runtime observation import exists for this scan — runtimeStatus is \'unavailable\', never \'complete\' '
104
+ + 'or a silent absence of risk. Import telemetry with `runtime ingest` before relying on this report.',
105
+ );
106
+ return base;
107
+ }
108
+
109
+ const windowStart = _minIso(importRecords.map((r) => r?.windowStart));
110
+ const windowEnd = _maxIso(importRecords.map((r) => r?.windowEnd));
111
+ base.telemetryWindow = { start: windowStart, end: windowEnd };
112
+ base.missingTelemetry = false;
113
+
114
+ const allObservations = importRecords.flatMap((r) => (Array.isArray(r?.observations) ? r.observations : []));
115
+ const total = allObservations.length;
116
+ const unmatched = allObservations.filter((obs) => obs && obs.matchMethod === 'unmatched').length;
117
+ base.totalObservationCount = total;
118
+ base.unmatchedObservationCount = unmatched;
119
+ base.mappingPercentage = total > 0 ? Math.round(((total - unmatched) / total) * 10000) / 100 : null;
120
+
121
+ const lastObservedAt = _maxIso(allObservations.map((obs) => obs?.lastObservedAt));
122
+ const lastImportedAt = _maxIso(importRecords.map((r) => r?.importedAt));
123
+ base.freshness.lastObservedAt = lastObservedAt;
124
+ base.freshness.lastImportedAt = lastImportedAt;
125
+ if (lastObservedAt !== null) {
126
+ const ageMs = Date.parse(now) - Date.parse(lastObservedAt);
127
+ const ageHours = Math.round((ageMs / 3600000) * 100) / 100;
128
+ base.freshness.staleHours = ageHours;
129
+ base.freshness.stale = ageHours > staleAfterHours;
130
+ }
131
+
132
+ if (total === 0) {
133
+ base.limitations.push('The import store exists but carries zero observation records.');
134
+ }
135
+ if (unmatched > 0) {
136
+ base.limitations.push(`${unmatched} of ${total} imported observation(s) never matched any graph node (matchMethod 'unmatched') — these contribute no corroboration to any flow.`);
137
+ }
138
+ if (base.freshness.stale) {
139
+ base.limitations.push(`The most recent observed event is ${base.freshness.staleHours} hour(s) old (beyond the ${staleAfterHours}-hour staleness bar) — this twin may no longer describe current production behavior.`);
140
+ }
141
+
142
+ const complete = total > 0 && unmatched === 0 && !base.freshness.stale;
143
+ base.runtimeStatus = complete ? 'complete' : 'partial';
144
+
145
+ return base;
146
+ }
147
+
148
+
149
+ /***/ })
150
+
151
+ };