@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,138 @@
1
+ export const id = 9899;
2
+ export const ids = [9899];
3
+ export const modules = {
4
+
5
+ /***/ 99899:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ validateOsvFunctionsExist: () => (/* binding */ validateOsvFunctionsExist)
10
+ /* harmony export */ });
11
+ /* unused harmony export extractPythonPackageFunctions */
12
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
13
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(76760);
14
+ /* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(31421);
15
+ /* harmony import */ var _ir_parser_py_cst_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(71349);
16
+ // Python package function extraction via the CST parser.
17
+ //
18
+ // Locates an installed Python package in site-packages or .venv,
19
+ // parses its source files via the Python CST parser, and returns
20
+ // a map of exported function names. Used by markUsedVulnFunctions
21
+ // to validate that OSV-named vulnerable functions actually exist
22
+ // in the installed version.
23
+
24
+
25
+
26
+
27
+
28
+
29
+ const VENV_DIRS = ['.venv', 'venv', '.env', 'env'];
30
+
31
+ function _findSitePackages(scanRoot) {
32
+ for (const vdir of VENV_DIRS) {
33
+ const base = node_path__WEBPACK_IMPORTED_MODULE_1__.join(scanRoot || '.', vdir);
34
+ if (!node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(base)) continue;
35
+ const lib = node_path__WEBPACK_IMPORTED_MODULE_1__.join(base, 'lib');
36
+ if (!node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(lib)) continue;
37
+ const pydirs = node_fs__WEBPACK_IMPORTED_MODULE_0__.readdirSync(lib).filter(d => d.startsWith('python'));
38
+ for (const pydir of pydirs) {
39
+ const sp = node_path__WEBPACK_IMPORTED_MODULE_1__.join(lib, pydir, 'site-packages');
40
+ if (node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(sp)) return sp;
41
+ }
42
+ }
43
+ // Fallback: ask python3 directly
44
+ try {
45
+ const out = (0,node_child_process__WEBPACK_IMPORTED_MODULE_2__.execFileSync)('python3', ['-c', 'import site; print(site.getsitepackages()[0])'], {
46
+ encoding: 'utf8', timeout: 5000,
47
+ }).trim();
48
+ if (out && node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(out)) return out;
49
+ } catch { /* no python3 or no site-packages */ }
50
+ return null;
51
+ }
52
+
53
+ function _findPackageDir(sitePackages, packageName) {
54
+ if (!sitePackages) return null;
55
+ const normalized = packageName.replace(/-/g, '_').toLowerCase();
56
+ const candidates = [
57
+ normalized,
58
+ packageName.toLowerCase(),
59
+ packageName,
60
+ ];
61
+ for (const name of candidates) {
62
+ const dir = node_path__WEBPACK_IMPORTED_MODULE_1__.join(sitePackages, name);
63
+ if (node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(dir) && node_fs__WEBPACK_IMPORTED_MODULE_0__.statSync(dir).isDirectory()) return dir;
64
+ }
65
+ return null;
66
+ }
67
+
68
+ function _readPyFilesFromDir(dir, maxFiles = 50) {
69
+ const entries = [];
70
+ try {
71
+ const files = node_fs__WEBPACK_IMPORTED_MODULE_0__.readdirSync(dir, { recursive: true })
72
+ .filter(f => f.endsWith('.py'))
73
+ .slice(0, maxFiles);
74
+ for (const f of files) {
75
+ const fp = node_path__WEBPACK_IMPORTED_MODULE_1__.join(dir, f);
76
+ try {
77
+ const content = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(fp, 'utf8');
78
+ if (content.length < 1_000_000) {
79
+ entries.push({ file: f, content });
80
+ }
81
+ } catch { /* skip unreadable files */ }
82
+ }
83
+ } catch { /* dir not readable */ }
84
+ return entries;
85
+ }
86
+
87
+ function extractPythonPackageFunctions(packageName, scanRoot) {
88
+ const cap = (0,_ir_parser_py_cst_js__WEBPACK_IMPORTED_MODULE_3__/* .probePythonAvailable */ .w4)();
89
+ if (!cap.ok) return null;
90
+
91
+ const sitePackages = _findSitePackages(scanRoot);
92
+ const pkgDir = _findPackageDir(sitePackages, packageName);
93
+ if (!pkgDir) return null;
94
+
95
+ const pyFiles = _readPyFilesFromDir(pkgDir);
96
+ if (!pyFiles.length) return null;
97
+
98
+ const batch = (0,_ir_parser_py_cst_js__WEBPACK_IMPORTED_MODULE_3__/* .parsePythonFilesBatch */ .H2)(pyFiles);
99
+ if (!batch || !Array.isArray(batch)) return null;
100
+
101
+ const functionMap = new Map();
102
+ for (const fileIR of batch) {
103
+ if (!fileIR || !fileIR.functions) continue;
104
+ for (const fn of fileIR.functions) {
105
+ if (fn.name && !fn.name.startsWith('_')) {
106
+ functionMap.set(fn.name, {
107
+ file: fileIR.file,
108
+ line: fn.line,
109
+ qid: fn.qid,
110
+ params: fn.params,
111
+ });
112
+ }
113
+ }
114
+ }
115
+ return functionMap;
116
+ }
117
+
118
+ function validateOsvFunctionsExist(packageName, osvFunctions, scanRoot) {
119
+ if (!osvFunctions || !osvFunctions.length) return { validated: [], missing: [] };
120
+ const fnMap = extractPythonPackageFunctions(packageName, scanRoot);
121
+ if (!fnMap) return { validated: osvFunctions, missing: [] };
122
+ const validated = [];
123
+ const missing = [];
124
+ for (const fn of osvFunctions) {
125
+ const shortFn = fn.includes('.') ? fn.split('.').pop() : fn;
126
+ if (fnMap.has(shortFn) || fnMap.has(fn)) {
127
+ validated.push(shortFn);
128
+ } else {
129
+ missing.push(fn);
130
+ }
131
+ }
132
+ return { validated, missing };
133
+ }
134
+
135
+
136
+ /***/ })
137
+
138
+ };
@@ -0,0 +1,206 @@
1
+ export const id = 9981;
2
+ export const ids = [9981];
3
+ export const modules = {
4
+
5
+ /***/ 89981:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ buildBaselineMap: () => (/* binding */ buildBaselineMap),
10
+ /* harmony export */ computeMTTR: () => (/* binding */ computeMTTR),
11
+ /* harmony export */ fingerprintFinding: () => (/* binding */ fingerprintFinding),
12
+ /* harmony export */ renderSlaSummary: () => (/* binding */ renderSlaSummary),
13
+ /* harmony export */ stampFindingTimestamps: () => (/* binding */ stampFindingTimestamps)
14
+ /* harmony export */ });
15
+ /* unused harmony export findingsExceedingSLA */
16
+ /* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(77598);
17
+ /* harmony import */ var _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(49171);
18
+ // 0.8.0 Feat-11: MTTR / finding-age tracking — per-finding firstSeenAt/lastSeenAt with SLA breach detection.
19
+ //
20
+ // Stamps every finding with `firstSeenAt` (preserved from the baseline if the
21
+ // finding existed previously) and `lastSeenAt` (the current scan time). Surfaces
22
+ // findings exceeding an SLA threshold per severity.
23
+ //
24
+ // Pure function — does not write to disk. The caller (CLI / fix workflow) decides
25
+ // when to persist firstSeenAt back into the baseline.
26
+
27
+
28
+
29
+
30
+ // FR-PROV-019: "reports never show an age without its basis and confidence."
31
+ // FINDING_ORIGIN is the only basis backed by a resolved git commit for the
32
+ // finding's actual introduction; EARLIEST_OBSERVABLE is also git-derived but
33
+ // partial (weaker claim, no exact introduction commit). UNCOMMITTED and
34
+ // FIRST_OBSERVED are both wall-clock fallbacks — the age is a first-seen
35
+ // timestamp, never resolved against git history — and must say so honestly
36
+ // rather than read like a proven date.
37
+ function _ageBasisLabel(ageBasis, confidence) {
38
+ const level = confidence?.level && confidence.level !== 'unknown' ? confidence.level.toUpperCase() : null;
39
+ switch (ageBasis) {
40
+ case _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.FINDING_ORIGIN:
41
+ return `proven origin${level ? `, ${level} confidence` : ''}`;
42
+ case _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.EARLIEST_OBSERVABLE:
43
+ return `earliest observable commit, partial history${level ? `, ${level} confidence` : ''}`;
44
+ case _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.UNCOMMITTED:
45
+ return 'uncommitted — first-seen fallback, origin not proven';
46
+ case _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.FIRST_OBSERVED:
47
+ default:
48
+ return 'first-seen fallback — origin not proven';
49
+ }
50
+ }
51
+
52
+ // Stable fingerprint for cross-scan finding identity. Mirrors the dedupe key.
53
+ // Exported so a caller can compute the "removed since baseline" (i.e. fixed)
54
+ // set that computeMTTR needs, using the exact same identity function
55
+ // buildBaselineMap uses internally — a caller-side reimplementation would
56
+ // risk drifting from this one and silently under/over-counting fixes.
57
+ function fingerprintFinding(f) { return _fingerprint(f); }
58
+ function _fingerprint(f) {
59
+ const file = (f.file || '').split(' -> ').pop();
60
+ const line = f.line || f.source?.line || f.sink?.line || 0;
61
+ const vuln = (f.vuln || f.type || '').replace(/\W+/g, '_').toLowerCase();
62
+ const cwe = (f.cwe || '').toUpperCase();
63
+ return node_crypto__WEBPACK_IMPORTED_MODULE_0__.createHash('sha256').update(`${file}:${line}:${vuln}:${cwe}`).digest('hex').slice(0, 16);
64
+ }
65
+
66
+ // Stamp findings in-place with firstSeenAt / lastSeenAt / ageDays.
67
+ // `findings` — current scan findings (will be mutated).
68
+ // `baselineMap` — optional Map of fingerprint → { firstSeenAt }. Pass an empty Map for first run.
69
+ // `now` — Date.now() at scan time (allow injection for tests).
70
+ function stampFindingTimestamps(findings, baselineMap = new Map(), now = Date.now()) {
71
+ const nowIso = new Date(now).toISOString();
72
+ for (const f of findings) {
73
+ const fp = _fingerprint(f);
74
+ f._fp = fp;
75
+ const prev = baselineMap.get(fp);
76
+ f.firstSeenAt = prev?.firstSeenAt || nowIso;
77
+ f.lastSeenAt = nowIso;
78
+ const firstMs = Date.parse(f.firstSeenAt);
79
+ f.ageDays = Math.max(0, Math.floor((now - firstMs) / 86400000));
80
+ // FR-PROV-019: age/SLA basis. ageDays above stays pure wall-clock —
81
+ // every existing SLA/computeMTTR consumer keeps its current meaning.
82
+ // ageBasis + provenAgeDays are ADDITIVE: a report can show both and
83
+ // explain the discrepancy, never silently swap which number "age" means.
84
+ const status = f.findingProvenance?.status;
85
+ const origin = f.findingProvenance?.findingOrigin;
86
+ if (status === 'complete' && origin?.authorDate) {
87
+ f.ageBasis = _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.FINDING_ORIGIN;
88
+ f.provenAgeDays = Math.max(0, Math.floor((now - Date.parse(origin.authorDate)) / 86400000));
89
+ } else if (status === 'partial' && origin?.authorDate) {
90
+ f.ageBasis = _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.EARLIEST_OBSERVABLE;
91
+ f.provenAgeDays = Math.max(0, Math.floor((now - Date.parse(origin.authorDate)) / 86400000));
92
+ } else if (status === 'uncommitted') {
93
+ f.ageBasis = _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.UNCOMMITTED;
94
+ f.provenAgeDays = f.ageDays;
95
+ } else {
96
+ f.ageBasis = _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.FIRST_OBSERVED;
97
+ f.provenAgeDays = f.ageDays;
98
+ }
99
+ }
100
+ return findings;
101
+ }
102
+
103
+ // Build a baseline map from an existing baseline JSON (or scan JSON shape).
104
+ // Recognised top-level: { findings, secrets, supplyChain }. Each entry retains
105
+ // firstSeenAt if it had one previously.
106
+ function buildBaselineMap(baselineJson) {
107
+ const map = new Map();
108
+ const all = [
109
+ ...(baselineJson?.findings || []),
110
+ ...(baselineJson?.secrets || []),
111
+ ...(baselineJson?.supplyChain || []).filter(s => s.type === 'vulnerable_dep'),
112
+ ];
113
+ for (const f of all) {
114
+ const fp = _fingerprint(f);
115
+ if (f.firstSeenAt) map.set(fp, { firstSeenAt: f.firstSeenAt });
116
+ }
117
+ return map;
118
+ }
119
+
120
+ // Identify findings exceeding an SLA threshold.
121
+ // slaDays: { critical: 7, high: 30, medium: 60, low: 90, info: 180 } (default).
122
+ function findingsExceedingSLA(findings, slaDays = null) {
123
+ const SLA = slaDays || { critical: 7, high: 30, medium: 60, low: 90, info: 180 };
124
+ return findings.filter(f => {
125
+ const limit = SLA[f.severity] ?? 90;
126
+ return (f.ageDays || 0) > limit;
127
+ });
128
+ }
129
+
130
+ // Median age (days) of the currently-open findings, PLUS the ageBasis/
131
+ // confidence of whichever finding landed on that median — a single-scan proxy
132
+ // for "how long has this debt been sitting". True MTTR (computeMTTR) needs the
133
+ // set of findings that were FIXED; this reports the open backlog's median age
134
+ // so a scan can show whether debt is getting older. Returns null on empty
135
+ // input. Local — surfaced only through renderSlaSummary (its sole consumer).
136
+ //
137
+ // FR-PROV-019: the days figure prefers `provenAgeDays` (git-derived when
138
+ // available) over the pure-wall-clock `ageDays`, and the ageBasis/confidence
139
+ // travel WITH the day count they describe — never a bare number with the
140
+ // basis looked up separately, which is how the original miss happened
141
+ // (ageBasis was stamped onto the finding but never reached the string that
142
+ // printed its age). Findings stamped by an older/test caller that never ran
143
+ // through stampFindingTimestamps (no ageBasis at all) degrade to the same
144
+ // honest "not proven" label FIRST_OBSERVED gets, never a false claim.
145
+ function medianOpenAge(findings) {
146
+ const entries = (findings || [])
147
+ .map(f => ({
148
+ days: f.provenAgeDays != null ? f.provenAgeDays : (f.ageDays || 0),
149
+ ageBasis: f.ageBasis || _provenance_schema_js__WEBPACK_IMPORTED_MODULE_1__/* .AGE_BASIS */ .pI.FIRST_OBSERVED,
150
+ confidence: f.findingProvenance?.confidence || null,
151
+ }))
152
+ .sort((a, b) => a.days - b.days);
153
+ if (!entries.length) return null;
154
+ return entries[Math.floor(entries.length / 2)];
155
+ }
156
+
157
+ // One-line SLA-breach summary for surfacing after a scan (#10). Returns null
158
+ // when nothing is past its per-severity SLA. Pairs with medianOpenAge for a
159
+ // "is my security debt aging" readout that the vibecoder can act on.
160
+ //
161
+ // FR-PROV-019: never prints the median age number without its basis and
162
+ // confidence alongside it — see medianOpenAge/_ageBasisLabel above.
163
+ function renderSlaSummary(findings, slaDays = null) {
164
+ const breached = findingsExceedingSLA(findings || [], slaDays);
165
+ if (!breached.length) return null;
166
+ const bySev = {};
167
+ for (const f of breached) bySev[f.severity] = (bySev[f.severity] || 0) + 1;
168
+ const parts = ['critical', 'high', 'medium', 'low', 'info'].filter(s => bySev[s]).map(s => `${bySev[s]} ${s}`);
169
+ const median = medianOpenAge(findings);
170
+ const ageNote = median != null
171
+ ? ` (median open age ${median.days}d, ${_ageBasisLabel(median.ageBasis, median.confidence)})`
172
+ : '';
173
+ return `${breached.length} finding(s) past remediation SLA: ${parts.join(', ')}${ageNote}`;
174
+ }
175
+
176
+ // Compute MTTR statistics from a series of saved scans (each with firstSeen/lastSeen).
177
+ // Useful for trend reporting.
178
+ function computeMTTR(removedFindings) {
179
+ // removedFindings: findings that existed in baseline but no longer in current
180
+ // (i.e., were fixed). Each carries firstSeenAt and lastSeenAt from the baseline.
181
+ if (!removedFindings.length) return { count: 0, meanDays: null, medianDays: null, perSeverity: {} };
182
+ const ages = removedFindings.map(f => {
183
+ const first = Date.parse(f.firstSeenAt || 0);
184
+ const last = Date.parse(f.lastSeenAt || 0);
185
+ return Math.max(0, (last - first) / 86400000);
186
+ }).sort((a, b) => a - b);
187
+ const meanDays = ages.reduce((s, x) => s + x, 0) / ages.length;
188
+ const medianDays = ages[Math.floor(ages.length / 2)];
189
+ const perSeverity = {};
190
+ for (const f of removedFindings) {
191
+ const sev = f.severity || 'medium';
192
+ (perSeverity[sev] = perSeverity[sev] || []).push(
193
+ Math.max(0, (Date.parse(f.lastSeenAt || 0) - Date.parse(f.firstSeenAt || 0)) / 86400000)
194
+ );
195
+ }
196
+ for (const k of Object.keys(perSeverity)) {
197
+ const a = perSeverity[k];
198
+ perSeverity[k] = { count: a.length, meanDays: a.reduce((s,x)=>s+x,0)/a.length };
199
+ }
200
+ return { count: removedFindings.length, meanDays, medianDays, perSeverity };
201
+ }
202
+
203
+
204
+ /***/ })
205
+
206
+ };
@@ -0,0 +1,117 @@
1
+ export const id = 999;
2
+ export const ids = [999];
3
+ export const modules = {
4
+
5
+ /***/ 60999:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ validateScenario: () => (/* binding */ validateScenario)
10
+ /* harmony export */ });
11
+ /* unused harmony exports SCENARIO_VERSION, SCENARIO_OPERATION_KINDS, SCENARIO_OPERATION_REQUIRED_FIELDS */
12
+ // scenario.js — M5 deliverable #3a (FR-502 §10.10, DFG-0xx): the
13
+ // Scenario extension contract — a hypothetical set of graph overrides,
14
+ // NOT a DataFlowGraph v1 entity, mirrors recipient-profile.js's own
15
+ // contract shape exactly (structural-only {valid, errors} validator,
16
+ // zero graph access, per-field evidence typing for the fields a
17
+ // Scenario actually overrides).
18
+ //
19
+ // See docs/superpowers/plans/2026-09-02-data-flow-explorer-m5-whatif-simulator-scoping.md
20
+ // for the full design reasoning, including why EVIDENCE_GRADES gained
21
+ // 'assumed' instead of reusing 'declared', and why this module's own
22
+ // operations catalog excludes synthetic node/edge insertion (deferred).
23
+
24
+ const SCENARIO_VERSION = '1.0.0';
25
+
26
+ // The 6 in-scope hypothetical-change kinds (FR-502's own 7, minus the
27
+ // deferred synthetic-insertion category). Each operation names its
28
+ // target canonical id(s) plus the override value(s); scenario-engine.js
29
+ // is the only consumer that interprets `kind`.
30
+ const SCENARIO_OPERATION_KINDS = Object.freeze([
31
+ 'require_transit_protection',
32
+ 'apply_handling',
33
+ 'remove_entity',
34
+ 'replace_recipient_fact',
35
+ 'change_storage_fact',
36
+ 'change_governance_fact',
37
+ ]);
38
+
39
+ // Per-operation-kind required fields, beyond the universal `kind`. Kept
40
+ // as data (not inline in validateScenario) for the same reason
41
+ // SCENARIO_OPERATION_KINDS above is — a single source of truth a table
42
+ // can be checked against — though scenario-engine.js does not currently
43
+ // import this table itself; it only mentions it in a prose comment on
44
+ // its own _applyReplaceRecipientFact.
45
+ const SCENARIO_OPERATION_REQUIRED_FIELDS = Object.freeze({
46
+ require_transit_protection: ['targetEdgeId'],
47
+ apply_handling: ['targetEdgeId', 'handling'],
48
+ remove_entity: ['targetNodeId'],
49
+ replace_recipient_fact: ['targetNodeId', 'field', 'value'],
50
+ change_storage_fact: ['targetNodeId', 'field', 'value'],
51
+ change_governance_fact: ['targetFlowId', 'field', 'value'],
52
+ });
53
+
54
+ function _isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }
55
+ function _isPlainObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }
56
+ function _isStringArray(v) { return Array.isArray(v) && v.every((x) => typeof x === 'string'); }
57
+
58
+ /**
59
+ * Structural validation only — mirrors validateRecipientProfile's own
60
+ * {valid, errors} shape and "never throws" contract. Does not check
61
+ * that targetEdgeId/targetNodeId/targetFlowId actually exist in any
62
+ * real graph — that is scenario-engine.js's job at apply time, since
63
+ * this module has zero graph access by design.
64
+ */
65
+ function validateScenario(record) {
66
+ const errors = [];
67
+ const err = (p, message) => errors.push({ path: p, message });
68
+ if (!record || typeof record !== 'object' || Array.isArray(record)) {
69
+ err('$', 'Scenario record must be an object');
70
+ return { valid: false, errors };
71
+ }
72
+ if (!_isNonEmptyString(record.id) || !record.id.startsWith('scenario:')) {
73
+ err('$.id', 'id is required and must start with "scenario:"');
74
+ }
75
+ if (!_isNonEmptyString(record.version)) err('$.version', 'version is required');
76
+ if (!_isNonEmptyString(record.baseGraphId)) err('$.baseGraphId', 'baseGraphId is required');
77
+ if (!_isNonEmptyString(record.baseGraphDigest)) err('$.baseGraphDigest', 'baseGraphDigest is required');
78
+ if (!_isNonEmptyString(record.author)) err('$.author', 'author is required');
79
+ if (!_isNonEmptyString(record.createdAt)) err('$.createdAt', 'createdAt is required');
80
+ if (record.expiration !== null && record.expiration !== undefined && !_isNonEmptyString(record.expiration)) {
81
+ err('$.expiration', 'expiration must be a string or null');
82
+ }
83
+ if (!_isStringArray(record.assumptions ?? [])) err('$.assumptions', 'assumptions must be an array of strings');
84
+ if (!_isStringArray(record.verificationRequirements ?? [])) {
85
+ err('$.verificationRequirements', 'verificationRequirements must be an array of strings');
86
+ }
87
+ if (!Array.isArray(record.operations) || record.operations.length === 0) {
88
+ err('$.operations', 'operations is required and must be a non-empty array');
89
+ } else {
90
+ record.operations.forEach((op, i) => {
91
+ const p = `$.operations[${i}]`;
92
+ if (!_isPlainObject(op)) { err(p, 'each operation must be an object'); return; }
93
+ if (!SCENARIO_OPERATION_KINDS.includes(op.kind)) {
94
+ err(`${p}.kind`, `unrecognized operation kind "${op.kind}" — must be one of ${SCENARIO_OPERATION_KINDS.join('|')}`);
95
+ return;
96
+ }
97
+ for (const field of SCENARIO_OPERATION_REQUIRED_FIELDS[op.kind]) {
98
+ if (op[field] === undefined || op[field] === null || op[field] === '') {
99
+ err(`${p}.${field}`, `operation of kind "${op.kind}" requires "${field}"`);
100
+ }
101
+ }
102
+ });
103
+ }
104
+ // simulatedDelta is populated by scenario-engine.js after apply, never
105
+ // by a caller constructing the pre-apply record — null is the only
106
+ // valid pre-apply value, an object (scenario-diff.js's own shape) the
107
+ // only valid post-apply value.
108
+ if (record.simulatedDelta !== null && record.simulatedDelta !== undefined && !_isPlainObject(record.simulatedDelta)) {
109
+ err('$.simulatedDelta', 'simulatedDelta must be null (before apply) or an object (after apply)');
110
+ }
111
+ return { valid: errors.length === 0, errors };
112
+ }
113
+
114
+
115
+ /***/ })
116
+
117
+ };