@clear-capabilities/agentic-security-scanner 0.172.1 → 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 (194) hide show
  1. package/CHANGELOG.md +15 -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/1351.index.js +133 -0
  7. package/dist/1387.index.js +271 -0
  8. package/dist/1437.index.js +23 -0
  9. package/dist/1445.index.js +110 -0
  10. package/dist/1505.index.js +151 -0
  11. package/dist/1557.index.js +293 -0
  12. package/dist/1621.index.js +311 -0
  13. package/dist/1751.index.js +160 -0
  14. package/dist/1765.index.js +727 -0
  15. package/dist/1861.index.js +690 -0
  16. package/dist/1898.index.js +116 -0
  17. package/dist/1906.index.js +433 -0
  18. package/dist/1920.index.js +1 -291
  19. package/dist/208.index.js +1631 -0
  20. package/dist/2199.index.js +0 -239
  21. package/dist/2223.index.js +159 -0
  22. package/dist/2530.index.js +152 -0
  23. package/dist/2565.index.js +116 -0
  24. package/dist/2574.index.js +127 -0
  25. package/dist/2620.index.js +345 -0
  26. package/dist/2773.index.js +98 -0
  27. package/dist/2775.index.js +32 -0
  28. package/dist/2966.index.js +171 -0
  29. package/dist/2972.index.js +87 -0
  30. package/dist/2991.index.js +131 -0
  31. package/dist/3063.index.js +833 -0
  32. package/dist/3075.index.js +227 -0
  33. package/dist/3121.index.js +297 -0
  34. package/dist/3314.index.js +263 -0
  35. package/dist/3480.index.js +1822 -0
  36. package/dist/3481.index.js +24 -0
  37. package/dist/3506.index.js +268 -0
  38. package/dist/3533.index.js +591 -0
  39. package/dist/3653.index.js +450 -0
  40. package/dist/3822.index.js +131 -0
  41. package/dist/3868.index.js +292 -0
  42. package/dist/3917.index.js +152 -0
  43. package/dist/3918.index.js +192 -0
  44. package/dist/4090.index.js +288 -0
  45. package/dist/4121.index.js +1190 -0
  46. package/dist/4142.index.js +0 -239
  47. package/dist/4336.index.js +436 -0
  48. package/dist/4387.index.js +532 -0
  49. package/dist/4413.index.js +302 -0
  50. package/dist/4476.index.js +4510 -0
  51. package/dist/4491.index.js +133 -0
  52. package/dist/4538.index.js +185 -0
  53. package/dist/4684.index.js +319 -0
  54. package/dist/4740.index.js +165 -0
  55. package/dist/4780.index.js +209 -0
  56. package/dist/4802.index.js +225 -0
  57. package/dist/4812.index.js +379 -0
  58. package/dist/4835.index.js +126 -0
  59. package/dist/494.index.js +226 -0
  60. package/dist/4991.index.js +549 -0
  61. package/dist/5199.index.js +305 -0
  62. package/dist/5216.index.js +109 -0
  63. package/dist/5439.index.js +301 -0
  64. package/dist/5443.index.js +97 -0
  65. package/dist/5496.index.js +377 -0
  66. package/dist/550.index.js +2 -1
  67. package/dist/5801.index.js +588 -0
  68. package/dist/5858.index.js +223 -0
  69. package/dist/5933.index.js +143 -0
  70. package/dist/601.index.js +23 -0
  71. package/dist/6173.index.js +273 -0
  72. package/dist/6291.index.js +1871 -0
  73. package/dist/6312.index.js +666 -0
  74. package/dist/634.index.js +16182 -0
  75. package/dist/644.index.js +87 -0
  76. package/dist/6508.index.js +283 -0
  77. package/dist/6560.index.js +645 -0
  78. package/dist/6576.index.js +422 -0
  79. package/dist/6579.index.js +271 -0
  80. package/dist/6745.index.js +305 -0
  81. package/dist/6818.index.js +21642 -0
  82. package/dist/6972.index.js +167 -0
  83. package/dist/6995.index.js +163 -0
  84. package/dist/7249.index.js +191 -0
  85. package/dist/7372.index.js +1197 -0
  86. package/dist/7546.index.js +541 -0
  87. package/dist/76.index.js +448 -0
  88. package/dist/7879.index.js +163 -0
  89. package/dist/8025.index.js +130 -0
  90. package/dist/8054.index.js +248 -0
  91. package/dist/8097.index.js +201 -0
  92. package/dist/8126.index.js +191 -0
  93. package/dist/8178.index.js +78 -0
  94. package/dist/818.index.js +212 -0
  95. package/dist/8382.index.js +93 -0
  96. package/dist/8408.index.js +261 -0
  97. package/dist/8540.index.js +174 -0
  98. package/dist/8635.index.js +802 -0
  99. package/dist/8688.index.js +410 -0
  100. package/dist/8699.index.js +779 -0
  101. package/dist/8891.index.js +457 -0
  102. package/dist/8916.index.js +885 -0
  103. package/dist/9146.index.js +170 -0
  104. package/dist/9168.index.js +841 -0
  105. package/dist/9292.index.js +369 -0
  106. package/dist/9382.index.js +135 -11
  107. package/dist/9422.index.js +866 -0
  108. package/dist/9440.index.js +453 -0
  109. package/dist/9479.index.js +152 -0
  110. package/dist/9481.index.js +220 -0
  111. package/dist/9539.index.js +100 -0
  112. package/dist/9547.index.js +103 -0
  113. package/dist/9560.index.js +41 -61
  114. package/dist/9692.index.js +90 -0
  115. package/dist/9800.index.js +213 -1
  116. package/dist/9899.index.js +138 -0
  117. package/dist/9981.index.js +206 -0
  118. package/dist/999.index.js +117 -0
  119. package/dist/agentic-security.mjs +27 -27
  120. package/dist/agentic-security.mjs.sha256 +1 -1
  121. package/package.json +28 -3
  122. package/src/context-intelligence/candidates.js +2 -1
  123. package/src/context-intelligence/capabilities.js +2 -1
  124. package/src/context-intelligence/cli.js +2 -0
  125. package/src/context-intelligence/config.js +3 -1
  126. package/src/context-intelligence/controls.js +49 -1
  127. package/src/context-intelligence/counterexample.js +200 -0
  128. package/src/context-intelligence/cross-route.js +111 -0
  129. package/src/context-intelligence/findings.js +166 -0
  130. package/src/context-intelligence/invariants.js +197 -0
  131. package/src/context-intelligence/queue.js +6 -1
  132. package/src/context-intelligence/reachability.js +2 -2
  133. package/src/context-intelligence/review.js +68 -4
  134. package/src/dataflow/access-paths.js +11 -0
  135. package/src/dataflow/analysis-limits.js +66 -0
  136. package/src/dataflow/engine.js +272 -20
  137. package/src/dataflow/service-edges.js +174 -0
  138. package/src/dataflow/summaries.js +7 -1
  139. package/src/discovery/judge.js +2 -1
  140. package/src/engine.js +82 -14
  141. package/src/fix/apply-fix-service.js +55 -8
  142. package/src/fix/batch-journal.js +84 -0
  143. package/src/fix/exploit-replay.js +51 -0
  144. package/src/fix/footprint.js +65 -0
  145. package/src/fix/patch-policy.js +49 -0
  146. package/src/fix/secret-persistence.js +39 -0
  147. package/src/fix/test-commands.js +84 -0
  148. package/src/fix/verification-adapters.js +97 -0
  149. package/src/fix/verification-record.js +243 -0
  150. package/src/fix/verify-patch.js +89 -0
  151. package/src/ir/CLAUDE.md +5 -0
  152. package/src/ir/callgraph.js +23 -1
  153. package/src/ir/module-resolver.js +315 -0
  154. package/src/ir/parser-js.js +21 -2
  155. package/src/ir/semantic-graph.js +245 -0
  156. package/src/lineage/build-attested-correlation.js +63 -0
  157. package/src/lineage/deployment-identity.js +76 -0
  158. package/src/mcp/tools.js +13 -34
  159. package/src/pipeline/canonical-output.js +64 -0
  160. package/src/pipeline/detector-runner.js +7 -0
  161. package/src/pipeline/scan-health.js +14 -0
  162. package/src/pipeline/supervised-analyzers.js +125 -0
  163. package/src/pipeline/supervised-child.js +17 -0
  164. package/src/pipeline/telemetry.js +79 -0
  165. package/src/posture/accuracy-scorecard.js +98 -9
  166. package/src/posture/artifact-registry.js +5 -0
  167. package/src/posture/assurance/evidence-registry.js +215 -0
  168. package/src/posture/assurance/release-package-verify.js +135 -0
  169. package/src/posture/assurance/release-package.js +118 -0
  170. package/src/posture/assurance/release-verdict.js +94 -0
  171. package/src/posture/assurance/waiver.js +200 -0
  172. package/src/posture/compliance-truth.js +100 -0
  173. package/src/posture/evaluation/scan-child.js +3 -1
  174. package/src/posture/evaluation/why-missed.js +3 -1
  175. package/src/posture/exploitability-evidence.js +141 -0
  176. package/src/posture/fix-verify.js +4 -2
  177. package/src/posture/fleet/exposure-ranking.js +115 -0
  178. package/src/posture/fleet/service-chain-graph.js +150 -0
  179. package/src/posture/graph-reconciliation.js +154 -0
  180. package/src/posture/provenance/coverage.js +103 -0
  181. package/src/posture/provenance/git-evidence.js +84 -0
  182. package/src/posture/provenance/origin-resolver.js +7 -1
  183. package/src/posture/provenance/predicate-replay.js +14 -4
  184. package/src/posture/runtime-correlation.js +61 -15
  185. package/src/posture/runtime-explanation.js +116 -0
  186. package/src/posture/runtime-trace-ingest.js +194 -0
  187. package/src/posture/scan-checkpoint.js +38 -10
  188. package/src/posture/waf-ingest.js +7 -2
  189. package/src/report/index.js +4 -0
  190. package/src/report/oscal.js +38 -0
  191. package/src/report/perspectives.js +150 -0
  192. package/src/sast/_comment-strip.js +8 -1
  193. package/src/sast/ruby.js +26 -0
  194. package/src/util/string-memo.js +38 -0
@@ -0,0 +1,377 @@
1
+ export const id = 5496;
2
+ export const ids = [5496,4780];
3
+ export const modules = {
4
+
5
+ /***/ 44780:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ iI: () => (/* binding */ summarizeForBadge),
10
+ /* harmony export */ renderBadge: () => (/* binding */ renderBadge)
11
+ /* harmony export */ });
12
+ /* unused harmony exports badgeFromScanRoot, renderSvg, _internal */
13
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
14
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(76760);
15
+ /* harmony import */ var _posture_state_dir_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(69259);
16
+ // Live SVG badge generator (v0.72).
17
+ //
18
+ // Every repo can drop a badge in its README pulling from the latest scan:
19
+ //
20
+ // ![agentic-security](https://agentic-security.dev/badge?repo=<slug>)
21
+ //
22
+ // or self-hosted via the CLI subcommand emitting an inline <img> URL or
23
+ // a static SVG. The badge format borrows from shields.io for visual
24
+ // consistency. Reads from .agentic-security/last-scan.json or accepts a
25
+ // scan object directly.
26
+ //
27
+ // Output formats:
28
+ // - 'svg' — inline SVG string (default; the bytes you'd serve)
29
+ // - 'json' — { label, count, color, severity } for a frontend renderer
30
+ //
31
+ // Style variants:
32
+ // - 'flat' — shields.io flat
33
+ // - 'for-the-badge' — caps + thicker
34
+ //
35
+ // Color is driven by the highest non-zero severity:
36
+ // critical → red
37
+ // high → orange
38
+ // medium → yellow
39
+ // low → blue
40
+ // info → lightgrey
41
+ // none → brightgreen
42
+
43
+
44
+
45
+
46
+
47
+ const COLORS = {
48
+ critical: '#e05d44', // red
49
+ high: '#fe7d37', // orange
50
+ medium: '#dfb317', // yellow
51
+ low: '#007ec6', // blue
52
+ info: '#9f9f9f', // grey
53
+ none: '#4c1', // brightgreen
54
+ label: '#555',
55
+ };
56
+
57
+ const SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'];
58
+
59
+ function _readLastScan(scanRoot) {
60
+ if (!scanRoot) return null;
61
+ const fp = (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_2__.statePath)(scanRoot, 'last-scan.json');
62
+ if (!node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(fp)) return null;
63
+ try { return JSON.parse(node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(fp, 'utf8')); }
64
+ catch { return null; }
65
+ }
66
+
67
+ function _ageString(ts) {
68
+ if (!ts) return null;
69
+ const ageMs = Date.now() - new Date(ts).getTime();
70
+ if (isNaN(ageMs) || ageMs < 0) return null;
71
+ const min = Math.floor(ageMs / 60_000);
72
+ if (min < 60) return `${min}m ago`;
73
+ const hr = Math.floor(min / 60);
74
+ if (hr < 24) return `${hr}h ago`;
75
+ const day = Math.floor(hr / 24);
76
+ return `${day}d ago`;
77
+ }
78
+
79
+ /**
80
+ * Compute the badge value from a scan object.
81
+ *
82
+ * Returns:
83
+ * {
84
+ * label: 'agentic-security',
85
+ * summary: 'critical 0 · high 2 · medium 5' | 'passing' | 'no scan',
86
+ * color: '#fe7d37',
87
+ * highest: 'high' | 'none' | 'unknown',
88
+ * ageStr: '4h ago' | null,
89
+ * counts: { critical, high, medium, low, info },
90
+ * total: 7,
91
+ * }
92
+ */
93
+ function summarizeForBadge(scan) {
94
+ if (!scan || !Array.isArray(scan.findings)) {
95
+ return {
96
+ label: 'agentic-security',
97
+ summary: 'no scan',
98
+ color: COLORS.info,
99
+ highest: 'unknown',
100
+ ageStr: null,
101
+ counts: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
102
+ total: 0,
103
+ };
104
+ }
105
+ const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
106
+ for (const f of scan.findings) {
107
+ const s = f.severity || 'info';
108
+ if (counts[s] !== undefined) counts[s]++;
109
+ }
110
+ let highest = 'none';
111
+ for (const s of SEVERITIES) { if (counts[s] > 0) { highest = s; break; } }
112
+ const color = COLORS[highest] || COLORS.info;
113
+ const summary = highest === 'none'
114
+ ? 'passing'
115
+ : `crit ${counts.critical} · high ${counts.high} · med ${counts.medium}`;
116
+ const total = SEVERITIES.reduce((a, s) => a + counts[s], 0);
117
+ return {
118
+ label: 'agentic-security',
119
+ summary,
120
+ color,
121
+ highest,
122
+ ageStr: _ageString(scan.timestamp || scan.when || scan.lastScan),
123
+ counts,
124
+ total,
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Compute the badge from .agentic-security/last-scan.json under `scanRoot`.
130
+ */
131
+ function badgeFromScanRoot(scanRoot) {
132
+ return summarizeForBadge(_readLastScan(scanRoot));
133
+ }
134
+
135
+ function _xmlEscape(s) {
136
+ return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
137
+ }
138
+
139
+ function _textWidth(s) {
140
+ // Rough character width — works fine for the small badge label range.
141
+ return s.length * 7 + 10;
142
+ }
143
+
144
+ /**
145
+ * Render an inline SVG matching shields.io's flat style. Self-contained
146
+ * (no external font references) so the badge works in any README.
147
+ */
148
+ function renderSvg(b, opts = {}) {
149
+ if (!b) b = summarizeForBadge(null);
150
+ const style = opts.style || 'flat';
151
+ const labelText = b.label;
152
+ const valueText = b.ageStr ? `${b.summary} · ${b.ageStr}` : b.summary;
153
+ const lblW = _textWidth(labelText);
154
+ const valW = _textWidth(valueText);
155
+ const totalW = lblW + valW;
156
+ const h = style === 'for-the-badge' ? 28 : 20;
157
+ const fontSize = style === 'for-the-badge' ? 12 : 11;
158
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${totalW}" height="${h}" role="img" aria-label="${_xmlEscape(labelText)}: ${_xmlEscape(valueText)}">
159
+ <title>${_xmlEscape(labelText)}: ${_xmlEscape(valueText)}</title>
160
+ <linearGradient id="s" x2="0" y2="100%">
161
+ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
162
+ <stop offset="1" stop-opacity=".1"/>
163
+ </linearGradient>
164
+ <clipPath id="r"><rect width="${totalW}" height="${h}" rx="3" fill="#fff"/></clipPath>
165
+ <g clip-path="url(#r)">
166
+ <rect width="${lblW}" height="${h}" fill="${COLORS.label}"/>
167
+ <rect x="${lblW}" width="${valW}" height="${h}" fill="${b.color}"/>
168
+ <rect width="${totalW}" height="${h}" fill="url(#s)"/>
169
+ </g>
170
+ <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="${fontSize}">
171
+ <text aria-hidden="true" x="${lblW / 2}" y="${h - 6}" fill="#010101" fill-opacity=".3">${_xmlEscape(labelText)}</text>
172
+ <text x="${lblW / 2}" y="${h - 7}">${_xmlEscape(labelText)}</text>
173
+ <text aria-hidden="true" x="${lblW + valW / 2}" y="${h - 6}" fill="#010101" fill-opacity=".3">${_xmlEscape(valueText)}</text>
174
+ <text x="${lblW + valW / 2}" y="${h - 7}">${_xmlEscape(valueText)}</text>
175
+ </g>
176
+ </svg>`;
177
+ }
178
+
179
+ /**
180
+ * Public entry: produce the badge in the requested format.
181
+ *
182
+ * format: 'svg' (default) | 'json'
183
+ * style: 'flat' (default) | 'for-the-badge'
184
+ * scanRoot: directory containing .agentic-security/last-scan.json
185
+ * scan: pre-loaded scan object (skips disk read)
186
+ */
187
+ function renderBadge({ format = 'svg', style = 'flat', scanRoot, scan } = {}) {
188
+ const summary = summarizeForBadge(scan || _readLastScan(scanRoot));
189
+ if (format === 'json') {
190
+ return JSON.stringify({
191
+ schemaVersion: 1,
192
+ label: summary.label,
193
+ message: summary.summary,
194
+ color: summary.color,
195
+ highest: summary.highest,
196
+ ageStr: summary.ageStr,
197
+ counts: summary.counts,
198
+ total: summary.total,
199
+ });
200
+ }
201
+ return renderSvg(summary, { style });
202
+ }
203
+
204
+ const _internal = { COLORS, _ageString, _readLastScan };
205
+
206
+
207
+ /***/ }),
208
+
209
+ /***/ 55496:
210
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
211
+
212
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
213
+ /* harmony export */ leaderboardRowFor: () => (/* binding */ leaderboardRowFor)
214
+ /* harmony export */ });
215
+ /* unused harmony exports rankRows, _internal */
216
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
217
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(76760);
218
+ /* harmony import */ var _badge_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(44780);
219
+ /* harmony import */ var _posture_state_dir_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(69259);
220
+ // Leaderboard backend (v0.72).
221
+ //
222
+ // Generates the data shape that powers the future public leaderboard at
223
+ // agentic-security.dev/leaderboard. The leaderboard ranks repos by their
224
+ // security posture under our scanner — F1-on-CVE-history when we can
225
+ // compute it, otherwise just last-scan severity counts.
226
+ //
227
+ // Public hosting of the site is deferred — we ship the data side now so
228
+ // the future site is a thin frontend over this JSON.
229
+ //
230
+ // One leaderboard row per repo:
231
+ //
232
+ // {
233
+ // repo: 'owner/name',
234
+ // score: { critical, high, medium, low, info, total },
235
+ // postureGrade: 'A' | 'B' | 'C' | 'D' | 'F',
236
+ // lastScanAge: '4h',
237
+ // topCwe: 'CWE-89',
238
+ // deltaTrend: 'improving' | 'flat' | 'regressing',
239
+ // badgeUrl: 'https://agentic-security.dev/badge?repo=…',
240
+ // }
241
+ //
242
+ // The grader is intentionally coarse — single letter — so the leaderboard
243
+ // stays scannable. Tie-break by lowest critical-count, then by recency.
244
+
245
+
246
+
247
+
248
+
249
+
250
+ // Grade thresholds. Critical findings dominate; high/medium contribute
251
+ // secondarily. These numbers are heuristic — calibrate against the
252
+ // public leaderboard corpus once data lands.
253
+ function _postureGrade(counts) {
254
+ if (!counts) return 'F';
255
+ const c = counts.critical || 0;
256
+ const h = counts.high || 0;
257
+ const m = counts.medium || 0;
258
+ if (c === 0 && h === 0 && m === 0) return 'A';
259
+ if (c === 0 && h === 0 && m <= 5) return 'B';
260
+ if (c === 0 && h <= 2) return 'C';
261
+ if (c <= 1 && h <= 5) return 'D';
262
+ return 'F';
263
+ }
264
+
265
+ function _ageString(ts) {
266
+ if (!ts) return null;
267
+ const ageMs = Date.now() - new Date(ts).getTime();
268
+ if (isNaN(ageMs) || ageMs < 0) return null;
269
+ const min = Math.floor(ageMs / 60_000);
270
+ if (min < 60) return `${min}m`;
271
+ const hr = Math.floor(min / 60);
272
+ if (hr < 24) return `${hr}h`;
273
+ const day = Math.floor(hr / 24);
274
+ return `${day}d`;
275
+ }
276
+
277
+ function _topCwe(scan) {
278
+ if (!scan || !Array.isArray(scan.findings)) return null;
279
+ const counts = new Map();
280
+ for (const f of scan.findings) {
281
+ if (!f.cwe) continue;
282
+ counts.set(f.cwe, (counts.get(f.cwe) || 0) + 1);
283
+ }
284
+ let topCwe = null, topN = 0;
285
+ for (const [cwe, n] of counts) {
286
+ if (n > topN) { topCwe = cwe; topN = n; }
287
+ }
288
+ return topCwe;
289
+ }
290
+
291
+ function _deltaTrend(history) {
292
+ // history: array of past scan summaries with `.timestamp` + `.severityCounts.critical`
293
+ if (!Array.isArray(history) || history.length < 2) return 'flat';
294
+ const recent = history.slice(-3);
295
+ const first = recent[0].severityCounts || {};
296
+ const last = recent[recent.length - 1].severityCounts || {};
297
+ const fScore = (first.critical || 0) * 4 + (first.high || 0);
298
+ const lScore = (last.critical || 0) * 4 + (last.high || 0);
299
+ if (lScore < fScore - 1) return 'improving';
300
+ if (lScore > fScore + 1) return 'regressing';
301
+ return 'flat';
302
+ }
303
+
304
+ /**
305
+ * Build a single leaderboard row for a repo. Reads the latest scan from
306
+ * `<scanRoot>/.agentic-security/last-scan.json` and (optionally) history
307
+ * from `<scanRoot>/.agentic-security/scan-history.jsonl`.
308
+ *
309
+ * `repo` is the GitHub slug ('owner/name'); used to drive the badge URL.
310
+ */
311
+ function leaderboardRowFor({ scanRoot, repo, badgeBase = 'https://agentic-security.dev/badge' } = {}) {
312
+ if (!repo) throw new Error('leaderboardRowFor: repo slug is required');
313
+ const lastScanPath = (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_3__.statePath)(scanRoot || '.', 'last-scan.json');
314
+ let scan = null;
315
+ try { scan = JSON.parse(node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(lastScanPath, 'utf8')); } catch {}
316
+ const summary = (0,_badge_js__WEBPACK_IMPORTED_MODULE_2__/* .summarizeForBadge */ .iI)(scan);
317
+ const grade = _postureGrade(summary.counts);
318
+ const topCwe = _topCwe(scan);
319
+
320
+ // Optional scan history for the trend signal.
321
+ const historyPath = (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_3__.statePath)(scanRoot || '.', 'scan-history.jsonl');
322
+ let history = [];
323
+ if (node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(historyPath)) {
324
+ try {
325
+ history = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(historyPath, 'utf8').split('\n')
326
+ .map(l => l.trim()).filter(Boolean)
327
+ .map(l => { try { return JSON.parse(l); } catch { return null; } })
328
+ .filter(Boolean);
329
+ } catch {}
330
+ }
331
+ const deltaTrend = _deltaTrend(history);
332
+
333
+ return {
334
+ repo,
335
+ score: { ...summary.counts, total: summary.total },
336
+ postureGrade: grade,
337
+ lastScanAge: _ageString(scan?.timestamp || scan?.when),
338
+ topCwe,
339
+ deltaTrend,
340
+ badgeUrl: `${badgeBase}?repo=${encodeURIComponent(repo)}`,
341
+ badgeMarkdown: `![agentic-security](${badgeBase}?repo=${encodeURIComponent(repo)})`,
342
+ };
343
+ }
344
+
345
+ /**
346
+ * Rank a list of rows for the leaderboard. Sort by:
347
+ * 1. lower critical count
348
+ * 2. lower high count
349
+ * 3. higher postureGrade (A > F)
350
+ * 4. fresher lastScanAge
351
+ *
352
+ * Returns the input rows annotated with `rank` (1-indexed).
353
+ */
354
+ function rankRows(rows) {
355
+ if (!Array.isArray(rows)) return [];
356
+ const gradeOrder = { A: 0, B: 1, C: 2, D: 3, F: 4 };
357
+ const sorted = [...rows].sort((a, b) => {
358
+ const ac = a.score?.critical || 0;
359
+ const bc = b.score?.critical || 0;
360
+ if (ac !== bc) return ac - bc;
361
+ const ah = a.score?.high || 0;
362
+ const bh = b.score?.high || 0;
363
+ if (ah !== bh) return ah - bh;
364
+ const ag = gradeOrder[a.postureGrade] ?? 5;
365
+ const bg = gradeOrder[b.postureGrade] ?? 5;
366
+ if (ag !== bg) return ag - bg;
367
+ return 0;
368
+ });
369
+ return sorted.map((r, i) => ({ ...r, rank: i + 1 }));
370
+ }
371
+
372
+ const _internal = { _postureGrade, _ageString, _topCwe, _deltaTrend };
373
+
374
+
375
+ /***/ })
376
+
377
+ };
package/dist/550.index.js CHANGED
@@ -230,7 +230,8 @@ function toFindingShape(candidate) {
230
230
  description: candidate.rationale
231
231
  ? `${candidate.rationale} (entry point: ${candidate.entryPoint || 'unstated'}; sink: ${candidate.sink || 'unstated'})`
232
232
  : `Proposed by the ${candidate.lens} lens; no rationale supplied.`,
233
- remediation: `Review ${candidate.file}:${candidate.line}. Confirm whether ${candidate.entryPoint || 'attacker-controlled input'} can reach ${candidate.sink || 'this operation'}, and constrain it at the boundary if so.`,
233
+ // a candidate that carries its own concrete remediation (a deterministic finding with a known fix shape) keeps it; every other candidate gets the generic review text
234
+ remediation: (typeof candidate.remediation === 'string' && candidate.remediation) ? candidate.remediation : `Review ${candidate.file}:${candidate.line}. Confirm whether ${candidate.entryPoint || 'attacker-controlled input'} can reach ${candidate.sink || 'this operation'}, and constrain it at the boundary if so.`,
234
235
  parser: 'DISCOVERY',
235
236
  family: candidate.family || 'other',
236
237
  ruleId: `discovery:${candidate.lens}`,