|
| 1 | +import type { z } from "zod"; |
| 2 | +import type { PublicStatsSchema } from "@loopover/contract/public-api"; |
1 | 3 | // Pure types + helpers for the Proof of Power (#1059) homepage stats band, split from the component so the |
2 | 4 | // component file only exports components (react-refresh) — mirrors the audit-feed / audit-feed-model split. |
3 | 5 |
|
4 | | -export type PublicStats = { |
5 | | - generatedAt: string; |
6 | | - updatedAt: string; |
7 | | - totals: { |
8 | | - handled: number; |
9 | | - reviewed: number; |
10 | | - merged: number; |
11 | | - closed: number; |
12 | | - commented: number; |
13 | | - ignored: number; |
14 | | - manual: number; |
15 | | - error: number; |
16 | | - reversed: number; |
17 | | - filteredPct: number | null; |
18 | | - accuracyPct: number | null; |
19 | | - minutesSaved: number; |
20 | | - }; |
21 | | - weekly: { reviewed: number; merged: number }; |
22 | | - byProject: Array<{ |
23 | | - project: string; |
24 | | - reviewed: number; |
25 | | - merged: number; |
26 | | - closed: number; |
27 | | - accuracyPct: number | null; |
28 | | - }>; |
29 | | - /** Live, fleet-wide accuracy across registered self-hosted ORB instances -- preferred over totals.accuracyPct |
30 | | - * (a frozen own-ledger snapshot) whenever instanceCount > 0. See public-stats.ts's PublicStatsPayload. */ |
31 | | - fleetAccuracy: { |
32 | | - accuracyPct: number | null; |
33 | | - /** #8829 fields -- optional-chained at the render site: an older backend simply omits them and the tile |
34 | | - * degrades to the bare figure rather than throwing. */ |
35 | | - accuracyCiPct?: { lo: number; hi: number } | null; |
36 | | - mergePrecisionPct?: number | null; |
37 | | - mergePrecisionCiPct?: { lo: number; hi: number } | null; |
38 | | - closePrecisionPct?: number | null; |
39 | | - closePrecisionCiPct?: { lo: number; hi: number } | null; |
40 | | - coveragePct?: number | null; |
41 | | - decidedCount?: number; |
42 | | - /** #9050: `aiJudgedCoveragePct` (renamed from `coveragePct`) is the share of the arm's AI-JUDGED |
43 | | - * sub-population the guarantee covers, not a share of all decided signals (that's the sibling |
44 | | - * `coveragePct` above) -- render the population it's actually over, not a bare percentage. |
45 | | - * `backfilledPct` is null when the stored calibration predates that field. */ |
46 | | - guaranteed?: { |
47 | | - close: { |
48 | | - alpha: number; |
49 | | - lambda: number; |
50 | | - aiJudgedCoveragePct: number; |
51 | | - n: number; |
52 | | - backfilledPct: number | null; |
53 | | - } | null; |
54 | | - merge: { |
55 | | - alpha: number; |
56 | | - lambda: number; |
57 | | - aiJudgedCoveragePct: number; |
58 | | - n: number; |
59 | | - backfilledPct: number | null; |
60 | | - } | null; |
61 | | - }; |
62 | | - instanceCount: number; |
63 | | - windowDays: number; |
64 | | - /** #9068: null (not 0) when the fleet has fewer than GAMING_MIN_ELIGIBLE eligible instances -- the |
65 | | - * anti-farming detector cannot run below that floor, so a structural zero must never render as "checked, |
66 | | - * found none". */ |
67 | | - gamingFlagsCaught: number | null; |
68 | | - }; |
69 | | - /** Trailing weekly history of totals.accuracyPct's SAME formula (#4447). */ |
70 | | - accuracyTrend: Array<{ |
71 | | - weekStart: string; |
72 | | - merged: number; |
73 | | - closed: number; |
74 | | - reversed: number; |
75 | | - accuracyPct: number | null; |
76 | | - }>; |
77 | | - /** Trailing weekly "how often we avoid redoing AI work" trend (#4448). */ |
78 | | - reuseRateTrend: Array<{ |
79 | | - weekStart: string; |
80 | | - hits: number; |
81 | | - misses: number; |
82 | | - reuseRatePct: number | null; |
83 | | - }>; |
84 | | - /** Trailing weekly review-volume/filtered-rate trend (#4445 follow-up) -- each week is the cohort of PRs |
85 | | - * first published that week; `merged` reflects their CURRENT disposition, not necessarily merged that |
86 | | - * same week. */ |
87 | | - reviewVolumeTrend: Array<{ |
88 | | - weekStart: string; |
89 | | - reviewed: number; |
90 | | - merged: number; |
91 | | - filteredPct: number | null; |
92 | | - }>; |
93 | | - |
94 | | - /** Measured per-rule precision + the reproducibility freeze point (#8230/#8231). Optional-chained by |
95 | | - * consumers: until the backend carrying it is deployed, an older /v1/public/stats response simply won't |
96 | | - * have the field yet, and every surface must degrade to hiding the section rather than throw. */ |
97 | | - rulePrecision?: { |
98 | | - windowDays: number; |
99 | | - rules: Array<{ |
100 | | - ruleId: string; |
101 | | - decided: number; |
102 | | - /** confirmed / decided; null below the decided-sample floor -- rendered as "insufficient data", NEVER 0%. */ |
103 | | - precision: number | null; |
104 | | - }>; |
105 | | - reversals: { reopened: number; reverted: number; superseded: number }; |
106 | | - latestBacktestRun: { corpusChecksum: string; at: string } | null; |
107 | | - }; |
108 | | -}; |
| 6 | +// #9282/#9521: DERIVED, not hand-authored. `PublicStats` was a parallel TypeScript interface kept in sync |
| 7 | +// with the backend by whoever last touched both files, and it had drifted -- it was missing |
| 8 | +// `fleetAccuracy.basis` and `rulePrecision.rules[].confirmed` outright, called `decidedCount` optional where |
| 9 | +// the wire says nullable, called `accuracyTrend`'s counts non-null where the wire says nullable, and made |
| 10 | +// `rulePrecision` optional where the wire says required. Inferring from the schema the Worker actually |
| 11 | +// serves makes the next such change a compile error here instead of broken rendering. |
| 12 | +export type { PublicRulePrecision } from "@loopover/contract/public-api"; |
| 13 | +export type PublicStats = z.infer<typeof PublicStatsSchema>; |
109 | 14 |
|
110 | 15 | /** Relative "updated Ns ago" label from the payload's updatedAt (mirrors MetaStrip's freshness logic). */ |
111 | 16 | export function formatStatsAgo(updatedAt: string | null, nowMs: number): string { |
|
0 commit comments