ironmonitor 7.1.0

IronMonitor: hardware monitoring for CPUs, GPUs, NPUs, memory, I/O and network silicon on Linux, Windows and macOS, which reports what it cannot read as well as what it can
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
//! Machine-readable ontology over everything IronMonitor can report.
//!
//! The three interfaces — CLI, TUI, GUI — all render the same underlying readings,
//! but until now each described them in its own words. `cli board` printed
//! `Kernel:`, the GUI printed `Kernel Version`, and the JSON output used
//! `kernel_version`; an agent reading one could not reliably talk about the others.
//! This module is the single naming authority the three surfaces agree on.
//!
//! ## What an entity is
//!
//! Every value IronMonitor can report has a stable dotted id — `gpu.0.thermal.temperature`,
//! `cpu.total.utilization`, `disk.0.capacity` — plus a unit and, most importantly,
//! a [`Provenance`].
//!
//! ## Why provenance is the point
//!
//! An agent reading `gpu.0.thermal.critical_temperature = null` learns nothing about
//! *why* it is null, and an agent reading `= 110` cannot tell whether the hardware
//! said so or whether a table of plausible constants did. That distinction is not
//! cosmetic: this repository has repeatedly shipped invented numbers through the same
//! field as measured ones — a boot time of exactly 45s assigned whenever it could not
//! be read, a GPU power percentage whose denominator came from a core-count lookup,
//! Secure Boot reported from the existence of a registry key rather than its value.
//! Each was indistinguishable from a real reading at the point of consumption.
//!
//! [`Provenance`] makes the distinction explicit and machine-checkable, so an agent
//! can refuse to reason about a specification constant as though it were a sample.

mod extended;
pub mod resolve;

pub mod capability;
pub mod jsonld;
pub mod vocabulary;

use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

/// Ontology format version. Bump the major on any breaking id or field change.
pub const ONTOLOGY_VERSION: &str = "1.1";

/// Where a value came from.
///
/// This is the field that distinguishes a reading from a guess. It is deliberately
/// not defaultable: every entity must state its provenance explicitly.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Provenance {
    /// Sampled from hardware or the OS during this collection cycle.
    Measured,
    /// A published constant — a spec sheet, a vendor table, a documented default.
    /// True of the hardware, but not observed on *this* machine right now.
    Specification,
    /// Computed from other entities. `derived_from` names the inputs.
    Derived,
    /// Not obtainable here: unsupported platform, absent device, missing permission.
    /// A consumer must render this as "unknown", never as zero.
    Unavailable,
}

impl Provenance {
    /// Whether a value with this provenance may be treated as a live observation.
    ///
    /// The guard an agent should apply before reasoning about a number as fact.
    /// `Specification` values are true but stale; `Derived` values inherit the
    /// weakest provenance of their inputs and so must be checked through those.
    pub fn is_observation(self) -> bool {
        matches!(self, Self::Measured)
    }

    pub fn as_str(self) -> &'static str {
        match self {
            Self::Measured => "measured",
            Self::Specification => "specification",
            Self::Derived => "derived",
            Self::Unavailable => "unavailable",
        }
    }
}

/// Physical unit of a value. `None` on the entity means dimensionless or textual.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Unit {
    Celsius,
    Percent,
    Bytes,
    BytesPerSecond,
    Hertz,
    Megahertz,
    MegatransfersPerSecond,
    Watts,
    Milliwatts,
    Volts,
    Rpm,
    Seconds,
    Hours,
    Milliseconds,
    Count,
    Identifier,
    Text,
    /// Radio signal power, decibels relative to one milliwatt. Negative.
    Dbm,
    /// Data rate in megabits per second, as radios and links quote it.
    MegabitsPerSecond,
    /// Tokens per second, as an inference engine reports them.
    TokensPerSecond,
    /// A money amount in the currency the provider names beside it, as the
    /// provider reports it. The scale (currency units or cents) is in the id.
    Amount,
}

impl Unit {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Celsius => "celsius",
            Self::Percent => "percent",
            Self::Bytes => "bytes",
            Self::BytesPerSecond => "bytes_per_second",
            Self::Hertz => "hertz",
            Self::Megahertz => "megahertz",
            Self::MegatransfersPerSecond => "megatransfers_per_second",
            Self::Watts => "watts",
            Self::Milliwatts => "milliwatts",
            Self::Volts => "volts",
            Self::Rpm => "rpm",
            Self::Seconds => "seconds",
            Self::Hours => "hours",
            Self::Milliseconds => "milliseconds",
            Self::Count => "count",
            Self::Identifier => "identifier",
            Self::Text => "text",
            Self::Dbm => "dbm",
            Self::MegabitsPerSecond => "megabits_per_second",
            Self::TokensPerSecond => "tokens_per_second",
            Self::Amount => "amount",
        }
    }

    /// Whether a negative value is physically meaningful for this unit.
    ///
    /// Used by [`Entity::validate_range`] so a consumer can reject impossible
    /// readings without hardcoding per-field knowledge.
    pub fn allows_negative(self) -> bool {
        matches!(self, Self::Celsius | Self::Volts | Self::Dbm)
    }
}

/// What kind of thing an entity is, which determines how an agent may use it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EntityKind {
    /// A sampled quantity that changes over time.
    Measurement,
    /// A fixed property of the device — model name, capacity, core count.
    Identity,
    /// A value that can be written back, subject to the apply layer's confirmation.
    Setting,
    /// A limit or threshold the hardware declares.
    Limit,
    /// Not a property of the hardware but a statement about the reading process
    /// itself — that a domain enumerated nothing, or that a list was truncated.
    /// These exist because silence is the one answer a resolver must never give: an
    /// agent that receives no `disk.*` rows cannot tell an absent device from an
    /// unimplemented reader, and a capped list presented as complete invites the
    /// conclusion that a process is absent when it was merely ranked eleventh.
    Diagnostic,
}

impl EntityKind {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Measurement => "measurement",
            Self::Identity => "identity",
            Self::Setting => "setting",
            Self::Limit => "limit",
            Self::Diagnostic => "diagnostic",
        }
    }
}

/// The subsystem an entity belongs to. Mirrors the CLI's top-level nouns so that
/// `ironmon cli gpu` and the `gpu.*` id space are obviously the same thing.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Domain {
    Cpu,
    Gpu,
    Memory,
    Disk,
    Network,
    Power,
    Thermal,
    Process,
    System,
    Board,
    Pci,
    Usb,
    Npu,
    Inference,
    Agents,
}

impl Domain {
    pub const ALL: &'static [Domain] = &[
        Domain::Cpu,
        Domain::Gpu,
        Domain::Memory,
        Domain::Disk,
        Domain::Network,
        Domain::Power,
        Domain::Thermal,
        Domain::Process,
        Domain::System,
        Domain::Board,
        Domain::Pci,
        Domain::Usb,
        Domain::Npu,
        Domain::Inference,
        Domain::Agents,
    ];

    pub fn as_str(self) -> &'static str {
        match self {
            Self::Cpu => "cpu",
            Self::Gpu => "gpu",
            Self::Memory => "memory",
            Self::Disk => "disk",
            Self::Network => "network",
            Self::Power => "power",
            Self::Thermal => "thermal",
            Self::Process => "process",
            Self::System => "system",
            Self::Board => "board",
            Self::Pci => "pci",
            Self::Usb => "usb",
            Self::Npu => "npu",
            Self::Inference => "inference",
            Self::Agents => "agents",
        }
    }

    pub fn parse(s: &str) -> Option<Self> {
        Self::ALL
            .iter()
            .copied()
            .find(|d| d.as_str().eq_ignore_ascii_case(s))
    }
}

/// One named thing IronMonitor can report.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Entity {
    /// Stable dotted id. `{domain}.{instance}.{path}`, where `instance` is omitted
    /// for singletons (`memory.total`) and is an index otherwise (`gpu.0.name`).
    /// Ids are the contract: they may be added, but never repurposed.
    pub id: String,
    pub domain: Domain,
    pub kind: EntityKind,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unit: Option<Unit>,
    pub provenance: Provenance,
    /// Whether the reader may legitimately have no value for this. A `false` here
    /// with a null value is a bug in the reader, not an absent device.
    pub nullable: bool,
    /// One line, written for a reader that cannot see the hardware.
    pub description: String,
    /// Ids this value is computed from. Non-empty only for [`EntityKind`] entries
    /// whose provenance is [`Provenance::Derived`].
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub derived_from: Vec<String>,
    /// The `ironmon profile set` id that writes this, when one exists.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub writable_via: Option<String>,
}

impl Entity {
    fn new(
        id: &str,
        domain: Domain,
        kind: EntityKind,
        unit: Option<Unit>,
        provenance: Provenance,
        nullable: bool,
        description: &str,
    ) -> Self {
        Self {
            id: id.to_string(),
            domain,
            kind,
            unit,
            provenance,
            nullable,
            description: description.to_string(),
            derived_from: Vec::new(),
            writable_via: None,
        }
    }

    fn derived(mut self, from: &[&str]) -> Self {
        self.provenance = Provenance::Derived;
        self.derived_from = from.iter().map(|s| s.to_string()).collect();
        self
    }

    /// Check a concrete value against what this entity's unit permits.
    ///
    /// Returns the reason it is impossible, or `None` if it is admissible. This is
    /// the same class of assertion as the `plausibility` test tier, exposed so that
    /// an agent consuming the JSON can apply it without reimplementing the rules.
    pub fn validate_range(&self, value: f64) -> Option<String> {
        let unit = self.unit?;
        if value.is_nan() {
            return Some(format!("{} is NaN", self.id));
        }
        if value < 0.0 && !unit.allows_negative() {
            return Some(format!(
                "{} = {value} is negative, which {} cannot be",
                self.id,
                unit.as_str()
            ));
        }
        if unit == Unit::Percent && value > 100.0 {
            return Some(format!("{} = {value} exceeds 100 percent", self.id));
        }
        if unit == Unit::Celsius && !(-273.15..=200.0).contains(&value) {
            return Some(format!(
                "{} = {value}C is outside any temperature real hardware reports",
                self.id
            ));
        }
        None
    }
}

/// The full set of entities IronMonitor knows how to name.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ontology {
    pub version: String,
    /// Keyed by id so lookups are O(log n) and the JSON is stable across runs.
    pub entities: BTreeMap<String, Entity>,
}

impl Default for Ontology {
    fn default() -> Self {
        Self::build()
    }
}

/// The ontology domain a writable setting belongs to.
///
/// Shared with the resolver, which publishes each setting's current value under
/// the id this mapping builds. Two copies would let the entity and the reading
/// drift into different ids, and the drift would show up as an entity that is
/// declared, never produced, and reported "no resolver bound" -- which is
/// exactly the state this function was written to get out of.
pub(crate) fn setting_domain(subsystem: crate::profile::Subsystem) -> Domain {
    match subsystem {
        crate::profile::Subsystem::Gpu => Domain::Gpu,
        crate::profile::Subsystem::Cpu => Domain::Cpu,
        crate::profile::Subsystem::Memory => Domain::Memory,
        // NVMe parameters are disk-level; display has no ontology domain of its
        // own and its settings are board-level firmware state.
        crate::profile::Subsystem::Nvme => Domain::Disk,
        crate::profile::Subsystem::Display => Domain::Board,
    }
}

impl Ontology {
    /// Construct the ontology. Pure — no hardware is touched, so this is safe to call
    /// on any machine and produces identical output everywhere, which is what makes
    /// it usable as a schema an agent can fetch ahead of time.
    pub fn build() -> Self {
        let mut entities = BTreeMap::new();
        let mut add = |e: Entity| {
            debug_assert!(
                !entities.contains_key(&e.id),
                "duplicate ontology id: {}",
                e.id
            );
            entities.insert(e.id.clone(), e);
        };

        use Domain as D;
        use EntityKind as K;
        use Provenance as P;
        use Unit as U;

        // ── CPU ──────────────────────────────────────────────────────────────
        add(Entity::new(
            "cpu.model",
            D::Cpu,
            K::Identity,
            Some(U::Text),
            P::Measured,
            // Nullable: an empty model string is a failed read, not a CPU
            // without a name, and the resolver reports it as absent.
            true,
            "Processor model string as the CPU reports it.",
        ));
        add(Entity::new(
            "cpu.cores.physical",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Measured,
            // Nullable: the resolver reports it absent both when the
            // reader errors and when the platform gives no physical count
            // distinct from the logical one.
            true,
            "Physical core count, excluding SMT siblings.",
        ));
        add(Entity::new(
            "cpu.cores.logical",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Measured,
            false,
            "Logical processor count, including SMT siblings.",
        ));
        add(Entity::new(
            "cpu.total.utilization",
            D::Cpu,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            // Nullable: the resolver reports it absent when the CPU stats
            // reader errors.
            true,
            concat!(
                "System-wide CPU busy percentage over the last sampling ",
                "interval. That interval is the time since the previous call, ",
                "not a fixed window: two snapshots taken back to back make the ",
                "second one span milliseconds, and it will report whatever ",
                "happened in those milliseconds. Measured here at 17.9% then ",
                "6.7% from consecutive calls on an idle machine, and steady at ",
                "55.7-56.2% across five spaced calls with half the cores ",
                "loaded, against an independent per-core mean of 55.7%. Space ",
                "the calls out to get a figure that means anything."
            ),
        )
        .derived(&["cpu.total.idle"]));
        add(Entity::new(
            "cpu.total.idle",
            D::Cpu,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            false,
            "System-wide idle percentage over the last sampling interval.",
        ));
        add(Entity::new(
            "cpu.core.{n}.utilization",
            D::Cpu,
            K::Measurement,
            Some(U::Percent),
            P::Derived,
            true,
            "Per-core busy percentage. Null where the platform exposes no \
             per-processor times — deliberately not the system average. Derived \
             rather than measured because no platform reports it: the resolver \
             computes `100 - idle` from per-core times, which is what the \
             reading has always been.",
        )
        .derived(&["cpu.core.{n}.idle"]));
        add(Entity::new(
            "cpu.core.{n}.idle",
            D::Cpu,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Per-core idle percentage over the last sampling interval. The \
             measured half of the pair: `utilization` beside it is `100 - idle`, \
             and naming the input is what lets a consumer see that the two are \
             one reading rather than two.",
        ));
        add(Entity::new(
            "cpu.core.{n}.frequency.max",
            D::Cpu,
            K::Limit,
            Some(U::Megahertz),
            P::Specification,
            true,
            concat!(
                "Rated maximum core clock, as the firmware reports it. A ",
                "boosting core can and does exceed it."
            ),
        ));
        add(Entity::new(
            "cpu.core.{n}.frequency",
            D::Cpu,
            K::Measurement,
            Some(U::Megahertz),
            // Declared as the weakest provenance any platform's rows can
            // carry, which is what `a_reading_never_resolves_weaker_than_                // its_entity_declares` asks for. Linux reads
            // `scaling_cur_freq` and over-delivers `Measured`; Windows has
            // no unprivileged API for a current clock and multiplies the
            // rated maximum by the kernel's delivered-performance counter,
            // which is a derivation and says so.
            P::Derived,
            true,
            concat!(
                "Current core clock. Null when the platform reports no ",
                "per-core clock. Each reading carries its own provenance: ",
                "Linux measures it from `scaling_cur_freq`, Windows derives ",
                "it from the rated maximum and `% Processor Performance`."
            ),
        )
        .derived(&["cpu.core.{n}.frequency.max"]));
        add(Entity::new(
            "cpu.core.{n}.frequency.min",
            D::Cpu,
            K::Limit,
            Some(U::Megahertz),
            P::Unavailable,
            true,
            "Minimum core clock. Unavailable on Windows, which exposes no such \
             figure; it is not inferable from the maximum.",
        ));

        // ── GPU ──────────────────────────────────────────────────────────────
        add(Entity::new(
            "gpu.{n}.name",
            D::Gpu,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Adapter name as the driver reports it.",
        ));
        add(Entity::new(
            "gpu.{n}.vendor",
            D::Gpu,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            false,
            "One of nvidia, amd, intel, apple.",
        ));
        add(Entity::new(
            "gpu.{n}.utilization",
            D::Gpu,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Graphics engine busy percentage.",
        ));
        add(Entity::new(
            "gpu.{n}.memory.used",
            D::Gpu,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            concat!(
                "Video memory in use, including what the driver reserves for itself ",
                "-- about 250 MB on an RTX 3090 Ti -- so an idle discrete card does ",
                "not read zero. Recent `nvidia-smi` excludes the reservation, and ",
                "reads lower by that much. Null on unified-memory parts that report none."
            ),
        ));
        add(Entity::new(
            "gpu.{n}.memory.total",
            D::Gpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total video memory.",
        ));
        add(Entity::new(
            "gpu.{n}.thermal.temperature",
            D::Gpu,
            K::Measurement,
            Some(U::Celsius),
            P::Measured,
            true,
            "GPU core temperature. Null where no sensor is exposed — notably Apple \
             Silicon via powermetrics. Null is not zero degrees.",
        ));
        add(Entity::new(
            "gpu.{n}.thermal.max_temperature",
            D::Gpu,
            K::Limit,
            Some(U::Celsius),
            P::Measured,
            true,
            "Vendor-declared thermal limit, read from the driver. Null when the \
             vendor publishes none — it must not be filled with a plausible constant.",
        ));
        add(Entity::new(
            "gpu.{n}.thermal.critical_temperature",
            D::Gpu,
            K::Limit,
            Some(U::Celsius),
            P::Measured,
            true,
            "Vendor-declared shutdown threshold, read from the driver. Null when \
             unpublished.",
        ));
        add(Entity::new(
            "gpu.{n}.power.draw",
            D::Gpu,
            K::Measurement,
            Some(U::Milliwatts),
            P::Measured,
            true,
            "Instantaneous board power draw.",
        ));
        add(Entity::new(
            "gpu.{n}.power.limit",
            D::Gpu,
            K::Limit,
            Some(U::Milliwatts),
            P::Measured,
            true,
            "Enforced power cap. Null when the driver exposes none; a percentage of \
             an unknown cap is not a measurement and is reported null in turn.",
        ));
        add(Entity::new(
            "gpu.{n}.clocks.graphics",
            D::Gpu,
            K::Measurement,
            Some(U::Megahertz),
            P::Measured,
            true,
            "Current graphics clock.",
        ));
        add(Entity::new(
            "gpu.{n}.clocks.graphics.max",
            D::Gpu,
            K::Limit,
            Some(U::Megahertz),
            P::Measured,
            true,
            "Maximum graphics clock as the driver declares it. Null where the vendor \
             publishes no ceiling.",
        ));

        // ── Memory ───────────────────────────────────────────────────────────
        add(Entity::new(
            "memory.total",
            D::Memory,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            false,
            "Total installed RAM visible to the OS.",
        ));
        add(Entity::new(
            "memory.used",
            D::Memory,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            false,
            "RAM currently in use.",
        ));
        add(Entity::new(
            "memory.utilization",
            D::Memory,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            // Nullable: with total memory reported as zero the percentage
            // has no denominator, and the resolver says so.
            true,
            "Used RAM as a percentage of total.",
        )
        .derived(&["memory.used", "memory.total"]));
        add(Entity::new(
            "memory.swap.total",
            D::Memory,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total swap or pagefile capacity.",
        ));
        add(Entity::new(
            "memory.swap.used",
            D::Memory,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Swap or pagefile currently in use.",
        ));

        add(Entity::new(
            "cpu.cache.l1d",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total L1 data cache across all cores. Reported in bytes, though the \
             platform sources state it in KiB, so that every capacity in this \
             ontology carries the same unit.",
        ));
        add(Entity::new(
            "cpu.cache.l1i",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total L1 instruction cache across all cores.",
        ));
        add(Entity::new(
            "cpu.cache.l2",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total L2 cache.",
        ));
        add(Entity::new(
            "cpu.cache.l3",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Total L3 cache. Null on parts with no last-level cache to report.",
        ));
        add(Entity::new(
            "cpu.cache.{n}.level",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Cache level of one cache instance — l1, l2, l3, l4.",
        ));
        add(Entity::new(
            "cpu.cache.{n}.size",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Size of one cache instance.",
        ));
        add(Entity::new(
            "cpu.cache.{n}.line_size",
            D::Cpu,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Cache line size. The unit of false sharing, and the reason this is \
             exposed per instance rather than assumed to be 64 bytes.",
        ));
        add(Entity::new(
            "cpu.cache.{n}.shared_cpus",
            D::Cpu,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Which logical processors share this cache, as a range list. Null where \
             the platform does not publish the sharing map.",
        ));

        // ── Microarchitecture and instruction set ────────────────────────────
        //
        // CPUID and its equivalents, which is the processor describing itself.
        // `Specification` rather than `Measured` for that reason: these values
        // do not change while the machine runs, and ironmon read a declaration
        // rather than sampling anything.
        //
        // The reader also computes a `single_thread_score` and a matching
        // multi-thread figure, both 0-100, and neither is published here. They
        // come from a lookup table over microarchitecture names, not from any
        // measurement of this processor, and an agent choosing between machines
        // on a number called a performance score would be relying on a guess
        // with a benchmark's authority. The extension list below is the part of
        // that reader an agent can actually act on: whether AVX-512 is present
        // is a fact, and it is the fact that decides a kernel.
        add(Entity::new(
            "cpu.microarch.<none>",
            D::Cpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the processor could not be identified, carrying why.",
        ));
        add(Entity::new(
            "cpu.microarch.name",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            true,
            "Microarchitecture as ironmon recognises it - Zen 5, Golden Cove, \
             Firestorm. Distinct from `cpu.model`, which is the marketing \
             string: processors with different model names share a \
             microarchitecture, and it is the microarchitecture that decides \
             which instructions are fast. Nullable: unavailable for a processor \
             ironmon does not identify, where it used to say \"Unknown AMD\".",
        ));
        add(Entity::new(
            "cpu.microarch.codename",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            true,
            "Vendor code name for this silicon - Granite Ridge, Raptor Lake-S. \
             Nullable: IronMonitor does not hold one for every part it can name.",
        ));
        add(Entity::new(
            "cpu.microarch.vendor",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Who made the processor.",
        ));
        add(Entity::new(
            "cpu.microarch.isa",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Instruction set architecture - x86_64, aarch64, riscv64. The coarsest \
             compatibility question there is, and the first one a consumer \
             selecting a binary has to answer.",
        ));
        add(Entity::new(
            "cpu.microarch.process",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Manufacturing process node in nanometres. A marketing figure as much \
             as a physical one across vendors, so it is comparable within a \
             vendor and not between them. Nullable where IronMonitor holds none.",
        ));
        add(Entity::new(
            "cpu.microarch.year",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Year this microarchitecture was introduced. From ironmon's own table \
             rather than from the silicon - it is the age of the design, not of \
             this chip. Nullable where IronMonitor holds no date.",
        ));
        add(Entity::new(
            "cpu.microarch.hybrid",
            D::Cpu,
            K::Identity,
            None,
            P::Specification,
            true,
            "Whether the design mixes performance and efficiency cores. True means \
             the per-core figures elsewhere are not comparable to each other, \
             which is worth knowing before averaging any of them. Nullable: \
             unavailable when the processor was not identified.",
        ));
        add(Entity::new(
            "cpu.microarch.family",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "CPUID family. Reported alongside model and stepping because the three \
             together identify the silicon exactly, which the name does not. \
             Nullable because Windows never decodes the triple, and all three go \
             together or not at all: publishing a stepping beside an absent family \
             would present a default as a measurement.",
        ));
        add(Entity::new(
            "cpu.microarch.model",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "CPUID model number within the family. Nullable with family and \
             stepping, which it is only meaningful beside.",
        ));
        add(Entity::new(
            "cpu.microarch.stepping",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "CPUID stepping - the revision of this particular silicon. Errata are \
             published against steppings, so a consumer checking for one needs \
             this and not the model name. Nullable with family and model; a \
             stepping of 0 is a legitimate value, which is why it is withheld \
             rather than defaulted when the triple was not read.",
        ));
        add(Entity::new(
            "cpu.microarch.physical_cores",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Physical core count. Below `logical_cores` when SMT is on, and the \
             right denominator for anything that scales with execution \
             resources rather than with schedulable threads.",
        ));
        add(Entity::new(
            "cpu.microarch.logical_cores",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Logical processor count, SMT threads included. The right denominator \
             for a thread pool.",
        ));
        add(Entity::new(
            "cpu.microarch.smt_enabled",
            D::Cpu,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether simultaneous multithreading is on right now. Measured rather \
             than declared: the silicon supports it or does not, but firmware \
             and the kernel both get a say, and this is the state as found.",
        ));
        add(Entity::new(
            "cpu.microarch.extension.<none>",
            D::Cpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no instruction set extension was enumerated, carrying \
             why. An empty list is never the answer: every processor ironmon runs \
             on supports something, so nothing enumerated means the reader \
             failed rather than that the CPU is bare.",
        ));
        add(Entity::new(
            "cpu.microarch.extension.<unread>",
            D::Cpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when some instruction set extensions were not checked on this \
             platform, carrying how many. Their absence is unknown, so they are never \
             listed as unsupported.",
        ));
        add(Entity::new(
            "cpu.microarch.extension.{n}.name",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Extension the processor reports as present - AVX-512, AES-NI, SVE. \
             The list holds only supported extensions, so membership is the \
             claim and there is no `supported` flag to check.",
        ));
        add(Entity::new(
            "cpu.microarch.extension.{n}.category",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "What the extension is for - vector arithmetic, cryptography, atomics.",
        ));
        add(Entity::new(
            "cpu.microarch.extension.{n}.description",
            D::Cpu,
            K::Identity,
            Some(U::Text),
            P::Specification,
            false,
            "A sentence on what the extension does. ironmon's own text rather than \
             the vendor's, and it is there so an agent that has not met an \
             extension can still tell whether it matters to the task at hand.",
        ));

        // ── Cryptographic acceleration ───────────────────────────────────────
        //
        // Which crypto primitives this processor implements in hardware. The
        // reader's `acceleration_score` and its free-text recommendations are
        // left out for the same reason the performance scores above are: a
        // score compresses a set of facts into a number whose scale nothing
        // documents, and an agent is better served by the facts.
        //
        // Throughput is declared but never filled. The per-primitive constants
        // it used to carry were not measured on this processor, so the row is
        // unavailable with the reason, rather than a figure labelled `Derived`.
        add(Entity::new(
            "cpu.crypto.<none>",
            D::Cpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no hardware crypto feature was enumerated, carrying why.",
        ));
        add(Entity::new(
            "cpu.crypto.feature.{n}.name",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Hardware-accelerated primitive - AES-NI, SHA extensions, carry-less \
             multiply. Only accelerated primitives appear; a primitive absent \
             from this list runs in software.",
        ));
        add(Entity::new(
            "cpu.crypto.feature.{n}.flag",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "The CPU flag that reports it, as the platform spells it. Included so a consumer can match against the flag names it already has rather than against the naming ironmon chose.",
        ));
        add(Entity::new(
            "cpu.crypto.feature.{n}.category",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Primitive class - symmetric cipher, hash, public key, random.",
        ));
        add(Entity::new(
            "cpu.crypto.feature.{n}.throughput",
            D::Cpu,
            K::Limit,
            Some(U::BytesPerSecond),
            P::Unavailable,
            true,
            "Per-core throughput for this primitive. Not measured by IronMonitor, \
             so it is always unavailable; the reason on each row says so. Kept \
             declared so the id is stable and a future benchmark can fill it.",
        ));
        add(Entity::new(
            "cpu.crypto.rng.<none>",
            D::Cpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no hardware random source was found, carrying why. Worth \
             its own diagnostic: a machine with no hardware RNG is a real and \
             consequential state, and it must not look like a failed read.",
        ));
        add(Entity::new(
            "cpu.crypto.rng.{n}.name",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Hardware random source the platform reports as available - RDRAND, \
             RDSEED, a TPM. Unavailable sources are omitted rather than listed \
             as present-but-off.",
        ));
        add(Entity::new(
            "cpu.crypto.rng.{n}.source",
            D::Cpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Where the entropy comes from - a CPU instruction, a discrete chip, \
             the kernel pool. The distinction matters: a CPU instruction and a \
             TPM fail in different ways and are trusted differently.",
        ));
        add(Entity::new(
            "cpu.crypto.rng.{n}.quality",
            D::Cpu,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Entropy bits per sample, where the source declares a figure. Nullable \
             and usually null - most sources state nothing, and an assumed \
             number here would be worse than silence.",
        ));

        // ── Memory modules ───────────────────────────────────────────────────
        //
        // Everything here comes from the SMBIOS type-17 tables, which the board
        // fills in at POST. Until 6.0.0 the whole cluster was declared
        // `Measured`, which claimed IronMonitor had sampled a part number off the
        // module -- it had not; it read a table the firmware wrote. A board that
        // lies about its own DIMMs makes ironmon repeat the lie, and a consumer
        // deciding whether to trust one of these figures needs to know that
        // before it decides. `ecc` stays `Derived`: it is a comparison of two of
        // the fields below rather than a field of its own.
        //
        // Serial numbers, bank labels and ranks are in `extended::memory`.
        // Until ontology 1.1 serials were left out as identifying; the
        // inventory now publishes identifying values like any other.
        add(Entity::new(
            "memory.dimm.{n}.locator",
            D::Memory,
            K::Identity,
            Some(U::Text),
            P::Specification,
            true,
            "Slot label as silkscreened on the board — DIMM_A1, ChannelA-DIMM0. \
             The id index is enumeration order; this is what a human replacing the \
             module needs.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.populated",
            D::Memory,
            K::Identity,
            None,
            P::Specification,
            true,
            "Whether this slot holds a module. False is a reading, and the reason \
             the fields below may be absent for a slot that genuinely exists. Null \
             where nothing the platform reported establishes presence either way: \
             an unreadable size is not an empty slot.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.capacity",
            D::Memory,
            K::Identity,
            Some(U::Bytes),
            P::Specification,
            true,
            "Module capacity. Null for an empty slot rather than zero, since zero \
             would read as a module of no size.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.speed",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Rated speed in MT/s. Counted rather than given a frequency unit \
             because megatransfers are not megahertz — DDR transfers twice per \
             clock, and conflating them halves or doubles every figure.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.configured_speed",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Speed the module is actually running at, in MT/s. Differs from the \
             rated speed whenever the board declined to train at the module's \
             profile, which is the useful thing to notice.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.type",
            D::Memory,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            true,
            "Memory technology — ddr4, ddr5, lpddr5.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.manufacturer",
            D::Memory,
            K::Identity,
            Some(U::Text),
            P::Specification,
            true,
            "Module manufacturer from SPD.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.part_number",
            D::Memory,
            K::Identity,
            Some(U::Text),
            P::Specification,
            true,
            "Module part number from SPD.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.ecc",
            D::Memory,
            K::Identity,
            None,
            P::Derived,
            true,
            "Whether the module carries ECC, from the total data width exceeding \
             the usable width — 72 bits against 64. Derived rather than measured \
             because no SMBIOS field states it directly.",
        )
        .derived(&["memory.dimm.{n}.data_width", "memory.dimm.{n}.total_width"]));
        add(Entity::new(
            "memory.dimm.{n}.data_width",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Usable data width in bits.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.total_width",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Total width in bits, including any ECC bits.",
        ));
        add(Entity::new(
            "memory.dimm.{n}.voltage",
            D::Memory,
            K::Identity,
            Some(U::Volts),
            P::Specification,
            true,
            "Operating voltage.",
        ));

        // ── Attached peripherals ─────────────────────────────────────────────
        //
        // Input devices, audio endpoints, cameras and printers, each with its
        // own `<none>` row. They share a shape and a reason for existing: an
        // agent asked to check whether a machine can join a call needs to know
        // whether a camera and a microphone are attached, and the answer "no
        // rows" cannot distinguish a headless server from a reader that is not
        // implemented on this platform.
        //
        // Everything here is `Measured`. These are enumerations of what is
        // plugged in right now, not declarations the firmware made at boot, and
        // a device unplugged between two snapshots really does disappear.
        add(Entity::new(
            "board.input.<none>",
            D::Board,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no input device was enumerated, carrying why. A machine \
             with no keyboard is an ordinary server; a machine whose input \
             enumeration failed is not, and the two must not look alike.",
        ));
        add(Entity::new(
            "board.input.{n}.name",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Device name as the platform reports it.",
        ));
        add(Entity::new(
            "board.input.{n}.type",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "What kind of device this is - keyboard, mouse, touchpad, game \
             controller, tablet. Null where the platform did not report a type, \
             which macOS and Bluetooth input devices do not.",
        ));
        add(Entity::new(
            "board.input.{n}.interface",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "How it is attached - USB, Bluetooth, PS/2, internal. Nullable \
             because a virtualised input device commonly reports no interface \
             the classification recognises - both CI runners resolve it absent \
             while bare metal resolves it - and a guess here would name a bus \
             the device is not on.",
        ));
        add(Entity::new(
            "board.input.{n}.vendor",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Vendor name or numeric id, whichever the platform gave. Nullable: \
             many devices report neither.",
        ));
        add(Entity::new(
            "board.input.{n}.product",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Product name or numeric id. Nullable for the same reason as vendor.",
        ));
        add(Entity::new(
            "board.input.{n}.active",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            // Nullable since 6.0.0: macOS does not read it. The id is
            // built with `format!`, so the static check in
            // `entities_with_an_absence_path_are_declared_nullable`
            // cannot see this one -- it had to be flipped by hand.
            true,
            "Whether the platform reports the device as connected and usable. A \
             present but inactive device is a different fact from an absent one \
             - a Bluetooth keyboard out of range is still enumerated.",
        ));
        add(Entity::new(
            "board.audio.<none>",
            D::Board,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no audio endpoint was enumerated, carrying why.",
        ));
        add(Entity::new(
            "board.audio.{n}.name",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Endpoint name as the platform presents it to a user.",
        ));
        add(Entity::new(
            "board.audio.{n}.direction",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            // Nullable: an endpoint whose platform data names no direction has
            // none published, rather than a guessed one.
            true,
            "Whether this endpoint plays, captures, or does both. The only \
             classification the platform provides - there is no separate \
             headset-or-speaker field, and declaring one would put a question \
             in the schema that no reader can answer. Null where the platform \
             did not establish it.",
        ));
        add(Entity::new(
            "board.audio.{n}.state",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            // Nullable since 6.0.0: Linux and macOS do not read it at all,
            // and Windows reads a status whose unhandled values now resolve
            // absent rather than falling through to "active".
            true,
            concat!(
                "Endpoint state as the platform reports it: active, ",
                "disabled, unplugged, not present."
            ),
        ));
        add(Entity::new(
            "board.audio.{n}.default",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            // Nullable since 6.0.0: no platform reads it. The id is built
            // with `format!`, so the static nullability check cannot see
            // it and this had to be flipped by hand.
            true,
            "Whether this is the endpoint the system routes to by default.",
        ));
        add(Entity::new(
            "board.audio.{n}.volume",
            D::Board,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Endpoint volume. Nullable: not every endpoint exposes a level, and a \
             silent zero would read as muted rather than as unknown.",
        ));
        add(Entity::new(
            "board.audio.{n}.muted",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether the endpoint is muted. Independent of volume - a muted \
             endpoint at 80% is not the same as an unmuted one at zero, and \
             only one of the two is fixed by turning it up. Null wherever the \
             mixer is not read, which is every platform today.",
        ));
        add(Entity::new(
            "board.camera.<none>",
            D::Board,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no camera was enumerated, carrying why.",
        ));
        add(Entity::new(
            "board.camera.{n}.name",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Camera name as the platform reports it.",
        ));
        add(Entity::new(
            "board.camera.{n}.connection",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            // Nullable: a camera whose bus was not named is unknown, not integrated.
            true,
            "How the camera is attached - USB, MIPI CSI, integrated, network. Null where the platform did not establish it.",
        ));
        add(Entity::new(
            "board.camera.{n}.driver",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Driver bound to the device. Nullable where the platform does not say.",
        ));
        add(Entity::new(
            "board.camera.{n}.max_width",
            D::Board,
            K::Limit,
            Some(U::Count),
            P::Measured,
            true,
            "Widest frame the device reports supporting, in pixels. Nullable \
             rather than zero: a camera that reports no mode list is not a \
             camera with a zero-pixel frame.",
        ));
        add(Entity::new(
            "board.camera.{n}.max_height",
            D::Board,
            K::Limit,
            Some(U::Count),
            P::Measured,
            true,
            "Tallest frame the device reports supporting, in pixels. Nullable for \
             the same reason as the width.",
        ));
        add(Entity::new(
            "board.camera.{n}.active",
            D::Board,
            K::Measurement,
            None,
            P::Measured,
            // Nullable since 6.0.0. It is live on Linux only; Windows can rule
            // streaming out but not attribute it, and macOS does not look.
            true,
            "Whether the camera is streaming right now. The one genuinely live \
             field in this cluster, and the reason it is a measurement rather \
             than an identity.",
        ));
        // Kernel parameters are split, not subsetted. `name`, `value` and
        // `category` are what the platform reported and are published here.
        // `is_recommended`, `recommended`, `security_score`, `network_score` and
        // `recommendations` are this crate's judgement about what the values
        // ought to be, and they are deliberately absent: `ironmon tune`'s standing
        // rule is that a proposed value comes from what the system declared,
        // never from this crate. An agent reading `security_score` off a
        // hardware report would be taking an opinion for a measurement, and the
        // ontology is the wrong surface for it.
        add(Entity::new(
            "system.kernel_param.<none>",
            D::System,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no kernel parameter could be read, carrying why. \
             Windows reads exactly one — the TCP auto-tuning level — so its \
             absence here is common and says nothing about Linux.",
        ));
        add(Entity::new(
            "system.kernel_param.{n}.name",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            false,
            "Parameter name in the platform's own namespace: a sysctl key on \
             Linux and macOS, a synthesised dotted name on Windows where the \
             setting comes from a cmdlet rather than a key.",
        ));
        add(Entity::new(
            "system.kernel_param.{n}.value",
            D::System,
            K::Measurement,
            Some(U::Identifier),
            P::Measured,
            false,
            "The value as the platform reported it, unparsed. A measurement \
             rather than an identity because it changes while the machine runs, \
             and text rather than a number because sysctl values are not all \
             numeric — a list of ports and a boolean live in the same namespace.",
        ));
        add(Entity::new(
            "system.kernel_param.{n}.category",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Which subsystem the parameter governs — network, memory, security. \
             The reader's classification of a real key, not a judgement about \
             its value.",
        ));

        // Services are counted, not enumerated. This machine runs 311 of them,
        // and one entity per service would more than double every snapshot to
        // carry a list nothing reads in full. What a consumer actually asks is
        // how many there are, how many are up, and which ones are broken — so
        // the failed units are named and the working ones are a number.
        add(Entity::new(
            "system.service.count.total",
            D::System,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            false,
            "How many services the platform's service manager knows about.",
        ));
        add(Entity::new(
            "system.service.count.running",
            D::System,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            false,
            "How many are active right now.",
        ));
        add(Entity::new(
            "system.service.count.failed",
            D::System,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            false,
            "How many are in a failed state. Zero is a real and common reading \
             here, and distinct from the absence carried by \
             `system.service.<none>` — a machine with no failures and a machine \
             whose services could not be enumerated must not look alike.",
        ));
        add(Entity::new(
            "system.service.failed.{n}",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Name of a failed service. The counts above say how much is wrong; \
             this says what, which is the part a consumer can act on. Absent \
             when nothing has failed.",
        ));
        add(Entity::new(
            "system.service.<none>",
            D::System,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the service manager could not be reached, carrying \
             why. Distinguishes that from a genuine count of zero.",
        ));
        add(Entity::new(
            "system.printer.<none>",
            D::System,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no printer was enumerated, carrying why.",
        ));
        add(Entity::new(
            "system.printer.{n}.name",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Queue name, which is what a print job is addressed to.",
        ));
        add(Entity::new(
            "system.printer.{n}.description",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Human description or model. Nullable: many queues carry none.",
        ));
        add(Entity::new(
            "system.printer.{n}.connection",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "How the printer is reached - USB, network, virtual. Nullable because \
             the classification is drawn from the port alone, and a local printer on a port shape neither recognises is a real \
             configuration rather than a failed read.",
        ));
        add(Entity::new(
            "system.printer.{n}.status",
            D::System,
            K::Measurement,
            Some(U::Identifier),
            P::Measured,
            true,
            "Queue state as the spooler reports it - idle, printing, stopped, \
             error. A measurement, because it changes while the machine runs. \
             Nullable because the spooler itself has \"Other\" and \"Unknown\" \
             states, and reporting either as a queue state would invent one.",
        ));
        add(Entity::new(
            "system.printer.{n}.default",
            D::System,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether this is the queue a job goes to when none is named. Unavailable where the default could not be read.",
        ));
        add(Entity::new(
            "system.printer.{n}.accepting_jobs",
            D::System,
            K::Measurement,
            None,
            P::Measured,
            // Nullable since 6.0.0: only CUPS reports it. The id is built
            // with `format!`, so the static nullability check cannot see
            // this one either.
            true,
            "Whether the queue is taking new work. Distinct from `status`: a \
             stopped queue may still accept jobs and hold them, which is the \
             difference between a delayed print and a rejected one.",
        ));
        add(Entity::new(
            "system.printer.{n}.color",
            D::System,
            K::Identity,
            None,
            P::Measured,
            true,
            concat!(
                "Whether the device prints in colour, as the driver declares. ",
                "Nullable: a spooler that lists no capabilities has not said the ",
                "printer is monochrome, and this read `false` for every printer ",
                "on Windows until it was taken from `Capabilities` rather than ",
                "from a property `Win32_Printer` does not have.",
            ),
        ));

        // ── Bluetooth radios ─────────────────────────────────────────────────
        //
        // Adapters here. Paired devices, and each adapter's address, are in
        // `extended::peripherals` under `network.bluetooth.device.{n}.*`:
        // since ontology 1.1 identifying values are published, not withheld.
        add(Entity::new(
            "network.bluetooth.<none>",
            D::Network,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no Bluetooth adapter was enumerated, carrying why.",
        ));
        add(Entity::new(
            "network.bluetooth.{n}.name",
            D::Network,
            K::Identity,
            Some(U::Text),
            P::Measured,
            // Nullable: a macOS controller with no chipset name has none to give.
            true,
            "Adapter name as the platform reports it.",
        ));
        add(Entity::new(
            "network.bluetooth.{n}.powered",
            D::Network,
            K::Measurement,
            None,
            P::Measured,
            true,
            "Whether the radio is on. A measurement: it is a runtime state, and it \
             is the field that answers whether the adapter is usable now.",
        ));

        // ── Storage controllers ──────────────────────────────────────────────
        //
        // The controllers the disks hang off, which is a different question
        // from the disks themselves. An agent diagnosing throughput needs both:
        // four NVMe drives behind one x4 controller do not add up the way four
        // drives behind four controllers do, and nothing in `disk.*` says which
        // arrangement this machine has.
        add(Entity::new(
            "disk.controller.<none>",
            D::Disk,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no storage controller was enumerated, carrying why.",
        ));
        add(Entity::new(
            "disk.controller.{n}.name",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Controller name as the platform reports it.",
        ));
        add(Entity::new(
            "disk.controller.{n}.vendor",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Controller vendor. Nullable where the platform names none.",
        ));
        add(Entity::new(
            "disk.controller.{n}.model",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Controller model. Nullable for the same reason as the vendor.",
        ));
        add(Entity::new(
            "disk.controller.{n}.driver",
            D::Disk,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Driver bound to the controller. The field that most often explains a \
             performance difference between two otherwise identical machines.",
        ));
        add(Entity::new(
            "disk.controller.{n}.interface",
            D::Disk,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Interface the controller speaks - NVMe, AHCI/SATA, SAS, USB, RAID. Absent where no evidence identifies it.",
        ));
        add(Entity::new(
            "disk.controller.{n}.pci_address",
            D::Disk,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "PCI address, where the controller sits on a PCI bus. Nullable for \
             controllers that do not - a USB bridge has none. Present so a \
             consumer can join this against `pci.*` and find the link width.",
        ));
        add(Entity::new(
            "disk.controller.{n}.ports",
            D::Disk,
            K::Limit,
            Some(U::Count),
            P::Measured,
            true,
            "Port count the controller reports. Nullable rather than zero: a \
             controller that reports no count still has ports.",
        ));

        // ── Power profiles ───────────────────────────────────────────────────
        //
        // Which power plans the operating system offers and which one is in
        // force. A setting in every sense -- it is writable, and it changes
        // every frequency and power figure elsewhere in this snapshot -- but it
        // is declared as an identity here because the ontology's `Setting` kind
        // is bound to the apply layer, and IronMonitor does not yet write these.
        // Declaring it writable when nothing can write it would be the same
        // overclaim in a different field.
        add(Entity::new(
            "power.profile.<none>",
            D::Power,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no power plan was enumerated, carrying why.",
        ));
        add(Entity::new(
            "power.profile.{n}.name",
            D::Power,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Plan name as the operating system presents it - Balanced, High \
             performance, Power saver.",
        ));
        add(Entity::new(
            "power.profile.{n}.active",
            D::Power,
            K::Measurement,
            None,
            P::Measured,
            false,
            "Whether this plan is the one in force. Exactly one plan should carry \
             true; a snapshot where none does means the active plan was not \
             identified rather than that the machine is running unmanaged.",
        ));

        // ── Video codec engines ──────────────────────────────────────────────
        //
        // What the GPU can encode and decode in hardware. This cluster is the
        // clearest case in the whole ontology for per-reading provenance: the
        // underlying reader records how it learned each capability, and the two
        // answers are not equally good. A capability the driver was asked about
        // directly is `Measured`; one concluded from the GPU model is `Derived`,
        // and it is wrong exactly as often as the lookup table is out of date.
        // Both are published, and which is which is never hidden.
        add(Entity::new(
            "gpu.codec.<none>",
            D::Gpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no hardware codec capability was found, or when a GPU's \
             model name is not placed by the codec rules, carrying why. A GPU with \
             no media engine is a real configuration - many datacentre \
             parts ship without one - and it must not look like a failed probe.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.device",
            D::Gpu,
            K::Identity,
            Some(U::Text),
            P::Specification,
            false,
            "The GPU this capability belongs to. Present on every row because a \
             machine with two GPUs has two independent sets of engines. Declared \
             at the weakest provenance a row can carry: a queried row resolves \
             Measured, an inferred one Specification, and a schema that promised \
             Measured for both would overstate half of them.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.codec",
            D::Gpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Codec - H.264, HEVC, AV1, VP9. Measured on a queried row; declared \
             here at the weaker provenance an inferred row carries.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.direction",
            D::Gpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            false,
            "Whether the engine encodes, decodes, or both. Asymmetry is normal: \
             AV1 decode is common on hardware that cannot encode it. Measured on \
             a queried row; declared at the weaker provenance an inferred row \
             carries.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.engine",
            D::Gpu,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            true,
            "Vendor name for the engine - NVENC, NVDEC, QuickSync, VCN. Nullable \
             where the capability was inferred rather than queried, since an \
             inference names no engine. Measured on a queried row; declared at \
             the weaker provenance an inferred row carries.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.max_resolution",
            D::Gpu,
            K::Limit,
            Some(U::Identifier),
            P::Specification,
            true,
            "Largest frame class this engine handles, as the reader classifies it - hd, full_hd, qhd, uhd_4k, uhd_8k. A class rather than a pixel count because that is what the underlying source provides. Unavailable on a VA-API row, whose vainfo query names the profile and entrypoint but not a frame size. Measured on a queried row; declared at the weaker provenance an inferred row carries.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.max_width",
            D::Gpu,
            K::Limit,
            Some(U::Count),
            P::Derived,
            true,
            "Width in pixels of the frame class above. Derived, and the derivation is a table: uhd_4k means 3840 here. An engine whose real limit sits between two classes will be described by the lower one, so this is a floor rather than a measured ceiling.",
        )
        .derived(&["gpu.codec.{n}.max_resolution"]));
        add(Entity::new(
            "gpu.codec.{n}.max_height",
            D::Gpu,
            K::Limit,
            Some(U::Count),
            P::Derived,
            true,
            "Height in pixels of the frame class above, from the same table and with the same caveat.",
        )
        .derived(&["gpu.codec.{n}.max_resolution"]));
        add(Entity::new(
            "gpu.codec.{n}.max_bit_depth",
            D::Gpu,
            K::Limit,
            Some(U::Count),
            P::Specification,
            true,
            "Bit depth per channel the engine supports. Eight against ten is the \
             difference between HDR working and not. Measured on a queried row; \
             declared at the weaker provenance an inferred row carries, like the \
             rest of this cluster.",
        ));
        add(Entity::new(
            "gpu.codec.{n}.max_fps",
            D::Gpu,
            K::Limit,
            Some(U::Count),
            // Declared `Unavailable`, not `Derived`: a `Derived` entity has
            // to name the inputs it is computed from, and this one named two
            // it never read.
            P::Unavailable,
            true,
            concat!(
                "Frames per second at the maximum resolution. No driver ",
                "reports a frame rate and this crate does not compute one, ",
                "so this always resolves absent. The description here used ",
                "to say the figure was arithmetic over the engine ",
                "generation, and the entity declared inputs to match; the ",
                "reader held a literal 60 at every construction site."
            ),
        ));
        add(Entity::new(
            "gpu.codec.{n}.confidence",
            D::Gpu,
            K::Identity,
            Some(U::Percent),
            P::Derived,
            false,
            "How sure the reader is of this row, as a percentage. Full confidence \
             means the driver was asked; anything less means the capability was \
             concluded from the GPU model. Each value is a fixed constant of the rule that \
             produced the row, not a measured probability. Published alongside the reading's \
             own provenance rather than instead of it: the provenance says what \
             kind of claim this is and the confidence says how strong.",
        )
        .derived(&["gpu.codec.{n}.codec", "gpu.codec.{n}.device"]));

        // ── Virtualization ───────────────────────────────────────────────────
        add(Entity::new(
            "system.virtualization.platform",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Whether this is bare metal, a virtual machine, or a container. The \
             first thing an agent needs before trusting any other reading: a \
             guest's view of its own hardware is the hypervisor's choice, not the \
             silicon's.",
        ));
        add(Entity::new(
            "system.virtualization.hypervisor",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            concat!(
                "Which hypervisor is present, when one was detected. ",
                "A value here does not mean this machine is a guest. ",
                "Windows 11 enables virtualization-based security by default, ",
                "which puts the host itself under a thin hypervisor, so an ",
                "ordinary desktop reports `hyperv` while ",
                "`system.virtualization.platform` correctly reports ",
                "`bare_metal` -- both rows are true at once, and the machine ",
                "this was found on is one of them. Read `platform` for the ",
                "question \"am I in a VM\": `detect.rs` answers it from the ",
                "Hyper-V privilege leaf rather than the CPUID vendor string, ",
                "which is identical either side of the partition boundary. ",
                "Null means no hypervisor was detected at all."
            ),
        ));
        add(Entity::new(
            "system.virtualization.detection_method",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "How the platform was determined — CPUID leaf, DMI string, kernel \
             file. Recorded because virtualization detection is inference, and an \
             agent weighing it should see what it rests on.",
        ));
        add(Entity::new(
            "system.virtualization.hardware_support",
            D::System,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether the CPU exposes hardware virtualization (VT-x or AMD-V). \
             Independent of whether this machine is itself virtualized.",
        ));

        // ── NUMA ─────────────────────────────────────────────────────────────
        add(Entity::new(
            "memory.numa.nodes",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Measured,
            true,
            "Number of NUMA nodes. One means uniform memory access, which is a \
             reading and not an absence.",
        ));
        add(Entity::new(
            "memory.numa.is_numa",
            D::Memory,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether memory access is genuinely non-uniform. A single-node machine \
             reports false; a machine the reader could not inspect reports nothing.",
        ));
        add(Entity::new(
            "memory.numa.{n}.cpus",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Measured,
            true,
            "Logical processors belonging to this NUMA node.",
        ));
        add(Entity::new(
            "memory.numa.{n}.memory",
            D::Memory,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Memory attached to this NUMA node.",
        ));

        // ── ECC ──────────────────────────────────────────────────────────────
        add(Entity::new(
            "memory.ecc.active",
            D::Memory,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether ECC is enabled and reporting. Distinct from whether the \
             modules carry ECC bits — see the per-slot `ecc` entity — because \
             hardware capable of correction that is not reporting corrections is \
             indistinguishable from hardware doing nothing.",
        ));
        add(Entity::new(
            "memory.ecc.correctable_errors",
            D::Memory,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Corrected memory errors since boot. Zero is a reading and a good one; \
             a rising count is the earliest warning a DIMM gives.",
        ));
        add(Entity::new(
            "memory.ecc.uncorrectable_errors",
            D::Memory,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Uncorrectable memory errors since boot. Any non-zero value means data \
             was lost.",
        ));

        // ── PCI ──────────────────────────────────────────────────────────────
        add(Entity::new(
            "pci.{addr}.vendor",
            D::Pci,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Vendor name. The id segment is the BDF address — domain, bus, device \
             and function — with separators replaced, so it is the same identifier \
             `lspci` prints and is stable across reboots.",
        ));
        add(Entity::new(
            "pci.{addr}.device",
            D::Pci,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Device name as the vendor and device id pair decodes to.",
        ));
        add(Entity::new(
            "pci.{addr}.class",
            D::Pci,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Decoded PCI class — what kind of device this is. Absent, with its reason, \
             where the platform gave no class register.",
        ));
        add(Entity::new(
            "pci.<unlocated>",
            D::Pci,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when some PCI devices have no bus address, so they cannot be keyed \
             as pci.<address>. Carries the count and why.",
        ));
        add(Entity::new(
            "pci.{addr}.driver",
            D::Pci,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Driver bound to the device. Null when none is, which is the \
             interesting case: an unclaimed device is a device that does not work.",
        ));
        add(Entity::new(
            "pci.{addr}.link.width",
            D::Pci,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Negotiated PCIe link width — x1, x4, x16. Unavailable on Windows, \
             which exposes no link state through the interfaces IronMonitor uses.",
        ));
        add(Entity::new(
            "pci.{addr}.link.max_width",
            D::Pci,
            K::Limit,
            Some(U::Identifier),
            P::Measured,
            true,
            "Maximum width the device supports. Compare against the negotiated \
             width: a x16 card trained at x4 is the classic silent performance \
             fault this pair exists to expose.",
        ));
        add(Entity::new(
            "pci.{addr}.link.speed",
            D::Pci,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Negotiated link speed, as the transfer rate the device reports — \
             8.0 GT/s, 16.0 GT/s.",
        ));
        add(Entity::new(
            "pci.{addr}.link.max_speed",
            D::Pci,
            K::Limit,
            Some(U::Identifier),
            P::Measured,
            true,
            "Maximum link speed the device supports.",
        ));
        add(Entity::new(
            "pci.{addr}.numa_node",
            D::Pci,
            K::Identity,
            Some(U::Count),
            P::Measured,
            true,
            "NUMA node this device is attached to. Null on machines with no NUMA \
             affinity to report — the reader's -1 sentinel is not a node number.",
        ));

        // ── USB ──────────────────────────────────────────────────────────────
        add(Entity::new(
            "usb.{addr}.product",
            D::Usb,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            concat!(
                "Product string as the device reports it. The id segment is ",
                "the platform's own device path -- the sysfs name on Linux, ",
                "the PnP instance path on Windows, the Location ID on ",
                "macOS -- normalised into one segment. It is unique per ",
                "device and changes only when that device moves or is ",
                "replaced, so unplugging one device does not repoint the ",
                "ids of the others."
            ),
        ));
        add(Entity::new(
            "usb.{addr}.manufacturer",
            D::Usb,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Manufacturer string. Null on devices that publish none.",
        ));
        add(Entity::new(
            "usb.{addr}.vendor_id",
            D::Usb,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "USB vendor id, four hex digits.",
        ));
        add(Entity::new(
            "usb.{addr}.product_id",
            D::Usb,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "USB product id, four hex digits.",
        ));
        add(Entity::new(
            "usb.{addr}.class",
            D::Usb,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Device class — hid, mass_storage, hub, and so on.",
        ));
        add(Entity::new(
            "usb.{addr}.speed",
            D::Usb,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Negotiated bus speed — low, full, high, super. A super-speed device \
             on a high-speed port reports high, which is how a wrong cable shows.",
        ));

        // ── Disk ─────────────────────────────────────────────────────────────
        add(Entity::new(
            "disk.{n}.model",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Drive model string from the device.",
        ));
        add(Entity::new(
            "disk.{n}.capacity",
            D::Disk,
            K::Identity,
            Some(U::Bytes),
            P::Measured,
            true,
            "Raw device capacity, before any partitioning. Nullable because a \
             device can genuinely decline to report one — a USB mass-storage \
             gadget with no medium presents as a drive of unstated size, and zero \
             would claim it holds nothing.",
        ));
        add(Entity::new(
            "disk.{n}.read_rate",
            D::Disk,
            K::Measurement,
            Some(U::BytesPerSecond),
            P::Measured,
            true,
            concat!(
                "Read throughput. Null in a single-shot snapshot, because a ",
                "rate needs two samples to difference and this resolver takes ",
                "one. Not a platform limitation: Windows exposes ",
                "`DiskReadBytesPerSec` and Linux `/sys/block/*/stat` gives ",
                "read and write sectors separately, so a caller that samples ",
                "twice can compute it per direction."
            ),
        ));
        add(Entity::new(
            "disk.{n}.write_rate",
            D::Disk,
            K::Measurement,
            Some(U::BytesPerSecond),
            P::Measured,
            true,
            concat!(
                "Write throughput. Null in a single-shot snapshot, because a ",
                "rate needs two samples to difference and this resolver takes ",
                "one. Not a platform limitation: Windows exposes ",
                "`DiskWriteBytesPerSec` and Linux `/sys/block/*/stat` gives ",
                "read and write sectors separately, so a caller that samples ",
                "twice can compute it per direction."
            ),
        ));
        add(Entity::new(
            "disk.{n}.partition.{m}.mount_point",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Mount point of a partition that genuinely resides on this device. A \
             device holding no mounted volume reports none rather than every volume \
             on the system.",
        ));
        add(Entity::new(
            "disk.{n}.serial",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Drive serial number. Null where the platform will not disclose it \
             without elevation.",
        ));
        add(Entity::new(
            "disk.{n}.kind",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Transport and medium — nvme_ssd, sata_ssd, sata_hdd, and so on. \
             Distinct from the SMART media type, which describes the medium alone.",
        ));
        add(Entity::new(
            "disk.{n}.health",
            D::Disk,
            K::Measurement,
            Some(U::Text),
            P::Measured,
            true,
            "Health verdict — healthy, warning, critical, failed, unknown. Derived \
             from the drive's own report, never from the device merely existing. \
             `unknown` is a real answer and means no counter could be read.",
        ));
        add(Entity::new(
            "disk.{n}.temperature",
            D::Disk,
            K::Measurement,
            Some(U::Celsius),
            P::Measured,
            true,
            "Drive temperature, from the NVMe health log or ATA attribute 194. \
             Null on devices that expose no thermal sensor.",
        ));
        add(Entity::new(
            "disk.{n}.smart.passed",
            D::Disk,
            K::Measurement,
            None,
            P::Measured,
            true,
            "The drive's own pass/fail verdict on itself — NVMe critical warning \
             bits, or the ATA failure prediction. Not a judgement computed from the \
             counters below.",
        ));
        add(Entity::new(
            "disk.{n}.smart.power_on_hours",
            D::Disk,
            K::Measurement,
            Some(U::Hours),
            P::Measured,
            true,
            "Lifetime powered-on hours. On NVMe, from the health log page. On ATA, the \
             raw count of SMART attribute 9 (Power_On_Hours), unconverted: most drives \
             count hours, but a minority count minutes or half-minutes and nothing in \
             the structure distinguishes them.",
        ));
        add(Entity::new(
            "disk.{n}.smart.power_cycles",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Lifetime power cycle count.",
        ));
        add(Entity::new(
            "disk.{n}.smart.reallocated_sectors",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Sectors the drive has remapped. Null on NVMe, which has no sector \
             reallocation concept — that is an ATA notion, and zero would assert a \
             clean count that was never measured.",
        ));
        add(Entity::new(
            "disk.{n}.smart.pending_sectors",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Sectors awaiting remap — data at risk now. Null on NVMe, for the same \
             reason as the reallocated count.",
        ));
        add(Entity::new(
            "disk.{n}.smart.uncorrectable_sectors",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Uncorrectable sectors on ATA; media errors on NVMe.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.version",
            D::Disk,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "NVMe specification version the controller reports. Null on non-NVMe.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.percentage_used",
            D::Disk,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Share of rated write endurance consumed. May legitimately exceed 100 \
             on a drive past its rating, which is a reading and not an error.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.data_units_written",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Lifetime data units written, in 1000x512-byte units as NVMe defines \
             them. Reported in the drive's own unit rather than converted, so that \
             the number matches what other NVMe tools show.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.data_units_read",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Lifetime data units read, in the same units as the written count.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.power_state",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Current NVMe power state index. State 0 is both the active state and \
             what an unread field would look like, so this is null unless the \
             controller answered Get Features.",
        ));
        add(Entity::new(
            "disk.{n}.nvme.critical_warnings",
            D::Disk,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "NVMe critical warning bitfield. Zero is a reading — a drive with \
             nothing wrong — and is reported as such rather than omitted.",
        ));

        // ── Network ──────────────────────────────────────────────────────────
        add(Entity::new(
            "network.{iface}.rx_rate",
            D::Network,
            K::Measurement,
            Some(U::BytesPerSecond),
            P::Measured,
            true,
            "Receive throughput on this interface.",
        ));
        add(Entity::new(
            "network.{iface}.tx_rate",
            D::Network,
            K::Measurement,
            Some(U::BytesPerSecond),
            P::Measured,
            true,
            "Transmit throughput on this interface.",
        ));
        // Cumulative counters exist because a rate does not: a single-shot query has
        // one sample, and a rate needs two. Declaring only `rx_rate` forced a
        // resolver to either return nothing useful or to pass a counter off as a
        // rate. These are what a one-shot read can honestly produce.
        add(Entity::new(
            "network.{iface}.rx_bytes",
            D::Network,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Bytes received since the interface came up. A counter, not a rate — \
             differentiate two samples to obtain throughput.",
        ));
        add(Entity::new(
            "network.{iface}.tx_bytes",
            D::Network,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Bytes transmitted since the interface came up. A counter, not a rate.",
        ));
        add(Entity::new(
            "network.{iface}.link_speed",
            D::Network,
            K::Limit,
            Some(U::MegabitsPerSecond),
            P::Measured,
            true,
            "Negotiated link rate in megabits per second, read from the driver. \
             Platforms that can only guess from the interface name report this as \
             specification-provenance instead.",
        ));

        // ── Power and thermal ────────────────────────────────────────────────
        add(Entity::new(
            "power.battery.percentage",
            D::Power,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Battery charge. Null on machines with no battery.",
        ));
        add(Entity::new(
            "thermal.{sensor}.temperature",
            D::Thermal,
            K::Measurement,
            Some(U::Celsius),
            P::Measured,
            true,
            "A named board or package temperature sensor.",
        ));
        add(Entity::new(
            "thermal.{sensor}.fan_rpm",
            D::Thermal,
            K::Measurement,
            Some(U::Rpm),
            P::Measured,
            true,
            "Fan speed. Null where no tachometer is wired.",
        ));

        // ── Process ──────────────────────────────────────────────────────────
        add(Entity::new(
            "process.{pid}.name",
            D::Process,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Executable name.",
        ));
        add(Entity::new(
            "process.{pid}.cpu",
            D::Process,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Process CPU share over an interval of about 250 ms between two \
             samples taken for this snapshot, as a share of all logical \
             processors. A process that started within the interval reports \
             its average since it started.",
        ));
        add(Entity::new(
            "process.{pid}.memory",
            D::Process,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Process resident memory.",
        ));

        // ── Displays ─────────────────────────────────────────────────────────
        //
        // Not in the plan's named list, which was the plan's own list rather
        // than an audit: `display` has a reader that answers on every desktop
        // and had no schema at all. Around 28 modules are still in that state;
        // see the plan section.
        add(Entity::new(
            "board.display.<none>",
            D::Board,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no display was enumerated, carrying why. A headless server reporting none is a reading; a failed query is not.",
        ));
        add(Entity::new(
            "board.display.{n}.name",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Display name as the platform reports it. Nullable: a monitor that publishes no EDID name genuinely has none to report.",
        ));
        add(Entity::new(
            "board.display.{n}.connector",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Port the display is attached to, as the platform names it (for example eDP-1 or HDMI-A-1). Nullable: where the platform gives no connector name it is unknown, not a guessed port.",
        ));
        add(Entity::new(
            "board.display.{n}.connection",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "How the display is attached - hdmi, displayport, edp, internal. Nullable, and measured to be so: two of the three displays on the development machine report a connection the reader cannot classify, and it says `unknown`, which the resolver turns into an absence rather than an identifier reading `unknown`.",
        ));
        add(Entity::new(
            "board.display.{n}.width",
            D::Board,
            K::Identity,
            Some(U::Count),
            P::Measured,
            true,
            concat!(
                "Horizontal resolution in pixels, at the mode currently set. Nullable: ",
                "an attached display whose mode is unreadable has no resolution to ",
                "report, and zero is not one.",
            ),
        ));
        add(Entity::new(
            "board.display.{n}.height",
            D::Board,
            K::Identity,
            Some(U::Count),
            P::Measured,
            true,
            "Vertical resolution in pixels, at the mode currently set.",
        ));
        add(Entity::new(
            "board.display.{n}.refresh_rate",
            D::Board,
            K::Measurement,
            Some(U::Hertz),
            P::Measured,
            true,
            "Refresh rate of the mode currently set.",
        ));
        add(Entity::new(
            "board.display.{n}.primary",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            // Nullable: the DRM path reports no primary flag.
            true,
            "Whether the platform treats this as the primary display.",
        ));

        // ── Platform sensors ─────────────────────────────────────────────────
        //
        // The last cluster named in plan item F. These are the OS-level sensor
        // devices — ambient light, accelerometer, orientation — not the board
        // temperature sensors, which resolve under `thermal`.
        add(Entity::new(
            "board.sensor.<none>",
            D::Board,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no platform sensor was enumerated, carrying why. A desktop reporting none is the common case and a true reading; this row distinguishes it from a query that could not be made.",
        ));
        add(Entity::new(
            "board.sensor.{n}.name",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Sensor name as the platform reports it. A sensor the platform did not name is skipped rather than called \"Unknown\".",
        ));
        add(Entity::new(
            "board.sensor.{n}.type",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            false,
            "Sensor kind - ambient light, accelerometer, gyroscope, orientation.",
        ));
        add(Entity::new(
            "board.sensor.{n}.active",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether the platform reports this sensor as ready. A present but inactive sensor is a different fact from an absent one.",
        ));

        // ── Package energy (RAPL) ────────────────────────────────────────────
        //
        // Named in the plan's item F as a remaining cluster. Templated per
        // package because a two-socket machine has two, and the diagnostic for
        // "this platform has no RAPL" is the domain's `<none>` row, which
        // already exists for every domain.
        add(Entity::new(
            "power.rapl.<none>",
            D::Power,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no RAPL energy domain was enumerated, carrying why. A sub-cluster diagnostic rather than the domain-wide `power.<none>`: a machine can have a readable battery and no RAPL interface, and claiming the whole power domain enumerated nothing would be false.",
        ));
        add(Entity::new(
            "power.rapl.{n}.name",
            D::Power,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "RAPL domain name as the platform reports it - package-0, core, dram, uncore.",
        ));
        add(Entity::new(
            "power.rapl.{n}.energy",
            D::Power,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            false,
            "Cumulative energy counter in microjoules. A counter, not a rate: it wraps at `max_energy_range`, and power in watts is the difference between two readings divided by the interval. Reported raw because a single sample cannot be converted to watts and pretending otherwise would invent a rate.",
        ));
        add(Entity::new(
            "power.rapl.{n}.max_energy_range",
            D::Power,
            K::Limit,
            Some(U::Count),
            P::Specification,
            false,
            "The value the energy counter wraps at, in microjoules. Needed to compute power across a wrap; a consumer without it will read a wrap as a negative delta.",
        ));
        add(Entity::new(
            "power.rapl.{n}.power_limit",
            D::Power,
            K::Limit,
            Some(U::Watts),
            P::Specification,
            true,
            "The configured power limit for this domain. Nullable: not every RAPL domain publishes a constraint.",
        ));
        add(Entity::new(
            "power.rapl.{n}.enabled",
            D::Power,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether the platform reports this domain as enabled. Nullable: unavailable when the domain's enabled attribute was not read, and never assumed true. A disabled domain still has a counter and it does not advance.",
        ));

        // ── Memory bandwidth ─────────────────────────────────────
        //
        // Every figure here except the configuration itself is `Derived`, and
        // that matters more than usual: nothing in this cluster was measured.
        // The peak is arithmetic over the channel count and the transfer rate,
        // The achievable and STREAM figures used to be that peak scaled by a
        // constant and are now always unavailable, since those constants are not
        // facts about this machine. An agent choosing a batch size from the peak
        // should know it is reading a calculation and not a benchmark - which is
        // what the provenance field is for.
        add(Entity::new(
            "memory.bandwidth.<none>",
            D::Memory,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the memory configuration needed to estimate bandwidth \
             could not be read, carrying why.",
        ));
        add(Entity::new(
            "memory.bandwidth.generation",
            D::Memory,
            K::Identity,
            Some(U::Identifier),
            P::Specification,
            true,
            "Memory generation the estimate rests on - DDR5, LPDDR5X, HBM3. \
             Nullable because a virtual machine's SMBIOS routinely names no \
             generation at all, which is what both CI runners see; naming one \
             anyway would put a spec-sheet figure behind a bandwidth estimate \
             that has no memory type to rest on.",
        ));
        add(Entity::new(
            "memory.bandwidth.speed",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            true,
            "Transfer rate in megatransfers per second, as used in the estimate. Nullable because it is the generation's figure: with no generation identified the estimator substitutes 3200 MT/s, which is a default and not a reading.",
        ));
        add(Entity::new(
            "memory.bandwidth.channels",
            D::Memory,
            K::Identity,
            Some(U::Count),
            P::Specification,
            // Nullable: where the memory configuration cannot be read at all --
            // every Mac, and a machine without readable SMBIOS -- there is no
            // channel count, and a null here is that fact rather than a reader
            // bug.
            true,
            "Active channel count. The largest single term in the estimate: a \
             dual-channel machine misread as single-channel halves every figure \
             below it.",
        ));
        add(Entity::new(
            "memory.bandwidth.max_channels",
            D::Memory,
            K::Limit,
            Some(U::Count),
            P::Specification,
            // Nullable for the same reason as `channels`.
            true,
            "Channels the controller supports. Above `channels` means the machine \
             is running below the bandwidth its board allows, which is usually a \
             populated-slot problem and worth being able to see.",
        ));
        add(Entity::new(
            "memory.bandwidth.peak",
            D::Memory,
            K::Limit,
            Some(U::BytesPerSecond),
            P::Derived,
            true,
            "Theoretical peak bandwidth, computed from the transfer rate, the bus \
             width and the channel count. No workload reaches it. Nullable: withheld entirely when the generation was not identified, since the transfer rate and bus width it needs would both be built-in defaults.",
        )
        .derived(&[
            "memory.bandwidth.generation",
            "memory.bandwidth.speed",
            "memory.bandwidth.channels",
        ]));
        add(Entity::new(
            "memory.bandwidth.achievable",
            D::Memory,
            K::Limit,
            Some(U::BytesPerSecond),
            P::Derived,
            true,
            "Achievable bandwidth. Always unavailable: no efficiency figure is read \
             from this machine, and the peak scaled by a fixed per-generation factor \
             was a rule of thumb rendered as a number. Nullable, and the reason is \
             published with it.",
        )
        .derived(&[
            "memory.bandwidth.generation",
            "memory.bandwidth.speed",
            "memory.bandwidth.channels",
        ]));
        add(Entity::new(
            "memory.bandwidth.stream_triad",
            D::Memory,
            K::Limit,
            Some(U::BytesPerSecond),
            P::Derived,
            true,
            "STREAM Triad bandwidth. Always unavailable: ironmon runs no benchmarks, \
             and the figure used to be the peak times a fixed ratio, so a consumer \
             comparing it against a real STREAM result would be comparing an \
             estimate to a measurement. Nullable, and the reason is published with it.",
        )
        .derived(&[
            "memory.bandwidth.generation",
            "memory.bandwidth.speed",
            "memory.bandwidth.channels",
        ]));

        // ── System and board ─────────────────────────────────────────────────
        //
        // The four below were readable by `os_info` long before they were named
        // here. A reader holding data the schema does not expose is invisible to
        // every agent, which is the same silence this module exists to prevent —
        // it just happens one level up.
        add(Entity::new(
            "system.hostname",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The machine's hostname. Nullable: a container or a freshly imaged host may genuinely have none set.",
        ));
        add(Entity::new(
            "system.os.version",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Operating system version string, as distinct from the build number and from the product name.",
        ));
        add(Entity::new(
            "system.kernel.version",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Kernel version. On Windows this is the NT build rather than a separate kernel line, which is why it can equal the OS build.",
        ));
        add(Entity::new(
            "system.architecture",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "CPU architecture the OS reports — x86_64, aarch64. The architecture of the running kernel, which on some hosts differs from the hardware's.",
        ));
        add(Entity::new(
            "system.os.name",
            D::System,
            K::Identity,
            Some(U::Text),
            P::Measured,
            false,
            "Operating system product name, corrected where the vendor's own \
             registry is stale.",
        ));
        add(Entity::new(
            "system.os.build",
            D::System,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "OS build identifier.",
        ));
        add(Entity::new(
            "system.uptime",
            D::System,
            K::Measurement,
            Some(U::Seconds),
            P::Measured,
            // Nullable: the resolver reports it absent when the uptime
            // reader errors.
            true,
            "Seconds since boot.",
        ));
        add(Entity::new(
            "system.boot.duration",
            D::System,
            K::Measurement,
            Some(U::Seconds),
            P::Measured,
            true,
            "Measured boot duration. Null when it could not be read — never a \
             representative constant.",
        ));
        add(Entity::new(
            "system.boot.secure_boot",
            D::System,
            K::Identity,
            None,
            P::Measured,
            true,
            "Whether Secure Boot is enforcing, read from the firmware flag itself \
             rather than inferred from the presence of the key holding it.",
        ));
        add(Entity::new(
            "board.model",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Baseboard product name from SMBIOS.",
        ));
        add(Entity::new(
            "board.firmware.vendor",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "System firmware vendor, from SMBIOS.",
        ));
        add(Entity::new(
            "board.firmware.product",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "System product name, from SMBIOS.",
        ));
        add(Entity::new(
            "board.firmware.boot_mode",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Whether the machine booted UEFI or legacy BIOS. Determines whether \
             Secure Boot is even applicable.",
        ));
        add(Entity::new(
            "board.firmware.{n}.component",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "Name of one component in the firmware inventory — BIOS, ME, a device \
             option ROM.",
        ));
        add(Entity::new(
            "board.firmware.{n}.version",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Installed version of that component.",
        ));
        add(Entity::new(
            "board.tpm.present",
            D::Board,
            K::Identity,
            None,
            P::Measured,
            // Nullable since 6.0.0. `TpmMonitor::refresh` can report a
            // failure now, and the resolver already said what to do with
            // one: "not knowing whether a TPM exists is different from
            // knowing there is none".
            true,
            "Whether a TPM was enumerated at all. False is a reading: the absence \
             of a TPM is a fact about the machine, distinct from being unable to \
             look.",
        ));
        add(Entity::new(
            "board.tpm.version",
            D::Board,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "TPM specification version. Null when no TPM is present.",
        ));
        add(Entity::new(
            "board.tpm.manufacturer",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "TPM manufacturer string.",
        ));
        add(Entity::new(
            "board.tpm.status",
            D::Board,
            K::Measurement,
            Some(U::Identifier),
            P::Measured,
            true,
            "Whether the TPM is enabled, activated and owned. A present but \
             disabled TPM cannot attest anything, so presence alone is not the \
             question an agent should ask.",
        ));
        add(Entity::new(
            "board.tpm.measured_boot",
            D::Board,
            K::Measurement,
            None,
            P::Measured,
            true,
            "Whether platform integrity measurements are active.",
        ));
        add(Entity::new(
            "board.manufacturer",
            D::Board,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Baseboard manufacturer from SMBIOS.",
        ));

        // ── Writable settings ────────────────────────────────────────────────
        //
        // Generated from the apply-handler registry rather than listed here, for the
        // same reason the command catalogue is walked out of clap: a hand-maintained
        // list would claim a write the binary cannot perform the first time a
        // handler was removed and nobody remembered this function. An agent reading
        // `writable_via` is being told it can change something, which is a promise
        // that has to be backed by a registered handler.
        //
        // Until this existed, `EntityKind::Setting` and `Entity::writable_via` were
        // declared and populated by nothing: the ontology described a machine an
        // agent could only read, while `ironmon profile set` could write.
        for handler in crate::profile::apply::builtin_handlers() {
            let setting_id = handler.setting_id();
            let domain = setting_domain(handler.subsystem());
            let mut entity = Entity::new(
                &format!("{}.setting.{}", domain.as_str(), setting_id),
                domain,
                K::Setting,
                Some(U::Identifier),
                P::Measured,
                true,
                "A driver or firmware setting with a registered write handler. \
                 Writing requires explicit confirmation and is recorded in the \
                 apply audit log.",
            );
            entity.writable_via = Some(setting_id.to_string());
            add(entity);
        }

        // ── Inference (local providers) ──────────────────────────────────────
        //
        // Ollama, llama.cpp, vLLM, LM Studio and MLX-LM, each read from the
        // endpoints its own documentation names (see inference/local.rs). A value
        // a server did not report is absent. Each `<provider>.<none>` row carries
        // the reason when that provider gave no sample. Counters are cumulative;
        // rates are derived from two samples; gauges are current figures.
        add(Entity::new(
            "inference.ollama.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no Ollama data was read, carrying the reason: nothing answered at the endpoint, or the endpoint answered with something other than Ollama's /api/ps.",
        ));
        add(Entity::new(
            "inference.ollama.version",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The Ollama server version, from GET /api/version.",
        ));
        add(Entity::new(
            "inference.ollama.model",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The first model Ollama reports as loaded into memory, from GET /api/ps. Absent when none is loaded.",
        ));
        add(Entity::new(
            "inference.ollama.models_loaded",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many models Ollama reports as loaded into memory right now, from GET /api/ps. Zero is a reading: the list was empty.",
        ));
        add(Entity::new(
            "inference.lmstudio.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no LM Studio data was read, carrying the reason: nothing answered, or the endpoint did not return LM Studio's v1 model listing.",
        ));
        add(Entity::new(
            "inference.lmstudio.model",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The first model LM Studio reports with a non-empty loaded_instances list, from GET /api/v1/models.",
        ));
        add(Entity::new(
            "inference.lmstudio.models_loaded",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many models LM Studio reports with a non-empty loaded_instances list, from GET /api/v1/models. LM Studio's listing carries no runtime counters.",
        ));
        add(Entity::new(
            "inference.mlx.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when MLX-LM did not answer its /health check, carrying the reason. MLX-LM exposes no metrics, so only its health is read.",
        ));
        add(Entity::new(
            "inference.mlx.health",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The status MLX-LM reports from GET /health: \"ok\" while its generation thread is alive.",
        ));
        add(Entity::new(
            "inference.llamacpp.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no llama.cpp metrics were read, carrying the reason. llama-server serves /metrics only when started with --metrics.",
        ));
        add(Entity::new(
            "inference.llamacpp.prompt_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prompt tokens llama-server has processed since it started. A counter from llamacpp:prompt_tokens_total; a rate is derived from two samples.",
        ));
        add(Entity::new(
            "inference.llamacpp.predicted_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative tokens llama-server has generated since it started. A counter from llamacpp:tokens_predicted_total.",
        ));
        add(Entity::new(
            "inference.llamacpp.decodes_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative decode calls llama-server has made since it started. A counter from llamacpp:n_decode_total.",
        ));
        add(Entity::new(
            "inference.llamacpp.requests_processing",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests llama-server is processing right now. A current figure, not a counter.",
        ));
        add(Entity::new(
            "inference.llamacpp.requests_deferred",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests llama-server has deferred right now. A current figure, not a counter.",
        ));
        add(Entity::new(
            "inference.llamacpp.prompt_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Prompt tokens per second over the window between two samples: the change in prompt_tokens_total over the observation window. Absent in a single-shot read.",
        ).derived(&["inference.llamacpp.prompt_tokens_total"]));
        add(Entity::new(
            "inference.llamacpp.predicted_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Generated tokens per second over the window between two samples: the change in predicted_tokens_total over the observation window. Absent in a single-shot read.",
        ).derived(&["inference.llamacpp.predicted_tokens_total"]));
        add(Entity::new(
            "inference.vllm.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no vLLM metrics were read, carrying the reason: nothing answered, or the endpoint answered with something without vllm: series on /metrics.",
        ));
        add(Entity::new(
            "inference.vllm.model",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The model_name label vLLM attaches to its series, as the server names the model it serves.",
        ));
        add(Entity::new(
            "inference.vllm.generation_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative generated tokens since vLLM started, summed over its label sets. A counter from vllm:generation_tokens; a rate is derived from two samples.",
        ));
        add(Entity::new(
            "inference.vllm.prompt_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prompt tokens since vLLM started, summed over its label sets. A counter from vllm:prompt_tokens.",
        ));
        add(Entity::new(
            "inference.vllm.request_success_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative requests vLLM has finished, summed over every finished_reason. A counter from vllm:request_success.",
        ));
        add(Entity::new(
            "inference.vllm.num_preemptions_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative request preemptions since vLLM started. A counter from vllm:num_preemptions.",
        ));
        add(Entity::new(
            "inference.vllm.prefix_cache_hits_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefix-cache hits since vLLM started. A counter from vllm:prefix_cache_hits. The numerator of prefix_cache_hit_ratio.",
        ));
        add(Entity::new(
            "inference.vllm.prefix_cache_queries_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefix-cache queries since vLLM started. A counter from vllm:prefix_cache_queries. The denominator of prefix_cache_hit_ratio.",
        ));
        add(Entity::new(
            "inference.vllm.requests_running",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests vLLM is running right now. A current figure, from vllm:num_requests_running.",
        ));
        add(Entity::new(
            "inference.vllm.requests_waiting",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests waiting in vLLM's queue right now. A current figure, from vllm:num_requests_waiting.",
        ));
        add(Entity::new(
            "inference.vllm.kv_cache_usage",
            D::Inference,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Share of vLLM's KV cache in use right now, as a percentage. vLLM reports it as a fraction (vllm:kv_cache_usage_perc); the resolver multiplies by 100.",
        ));
        add(Entity::new(
            "inference.vllm.prefix_cache_hit_ratio",
            D::Inference,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            "Share of vLLM prefix-cache queries that hit, as a percentage over the window between two samples: prefix_cache_hits_total / prefix_cache_queries_total. Absent when no query happened in the window.",
        ).derived(&[
            "inference.vllm.prefix_cache_hits_total",
            "inference.vllm.prefix_cache_queries_total",
        ]));
        add(Entity::new(
            "inference.vllm.generation_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Generated tokens per second over the window between two samples. Absent in a single-shot read.",
        ).derived(&["inference.vllm.generation_tokens_total"]));
        add(Entity::new(
            "inference.vllm.prompt_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Prompt tokens per second over the window between two samples. Absent in a single-shot read.",
        ).derived(&["inference.vllm.prompt_tokens_total"]));

        // ── Agents (IronObserver recordings) ─────────────────────────────────
        //
        // Read from the recordings directory, which IronObserver's `ironobs` writes
        // when IronMonitor runs it (see agents/mod.rs). Metadata only: no prompts,
        // tool arguments or file contents, and no session or project identifiers.
        // Counts are of recordings, not of work done. A recording's `in_progress`
        // is what its producer said; "not evidenced" is kept apart from "closed".
        add(Entity::new(
            "agents.recordings.<none>",
            D::Agents,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when no recordings were read, carrying the reason: the directory does not exist, it holds no recording files, or none of its files could be used.",
        ));
        add(Entity::new(
            "agents.recordings.dir",
            D::Agents,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The directory recordings are read from. Set by IRONMON_RECORDINGS_DIR; by default it is under the user's cache directory.",
        ));
        add(Entity::new(
            "agents.recordings.files",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many recording files (.json) are in the read: those whose summaries are cached or were read within the query deadline. Absent when the directory does not exist.",
        ));
        add(Entity::new(
            "agents.recordings.rejected",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Recordings refused, plus files that are not recording JSON. A refused recording names a format this IronMonitor does not read, so it is counted rather than guessed at.",
        ));
        add(Entity::new(
            "agents.recordings.<truncated>",
            D::Agents,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when a snapshot read stopped at its deadline before every recording file was read, carrying how many were read of how many. Counts that depend on the unread files are reported unavailable. The background reader reads them all.",
        ));
        add(Entity::new(
            "agents.ironobs.<none>",
            D::Agents,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when IronObserver's `ironobs` is not on PATH, with how to install it. Recordings already on disk are still read.",
        ));
        add(Entity::new(
            "agents.ironobs.version",
            D::Agents,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The version `ironobs --version` printed, when the background reader probed the installed binary. A one-shot read does not run ironobs, so it reports this unavailable.",
        ));
        add(Entity::new(
            "agents.import.state",
            D::Agents,
            K::Measurement,
            Some(U::Text),
            P::Measured,
            true,
            "What the import cycle is doing now: running since a time (and whether another IronMonitor window started it), idle with when the last cycle ended and when the next is due, pending before the first import, or not run because ironobs is missing or too old for --out. Each producer is stopped at 30 minutes.",
        ));
        add(Entity::new(
            "agents.import.claude_code.state",
            D::Agents,
            K::Measurement,
            Some(U::Text),
            P::Measured,
            true,
            "The Claude Code import: when its last run finished and what it reported, in counts, and which sessions the next run selects. Unavailable, with the reason, when no Claude Code projects folder exists.",
        ));
        add(Entity::new(
            "agents.import.codex.state",
            D::Agents,
            K::Measurement,
            Some(U::Text),
            P::Measured,
            true,
            "The Codex CLI import: when its last run finished and what it reported, in counts, and which sessions the next run selects. Unavailable, with the reason, when no Codex sessions folder exists.",
        ));
        add(Entity::new(
            "agents.import.last_written",
            D::Agents,
            K::Measurement,
            Some(U::Text),
            P::Measured,
            true,
            "When the newest recording file was written, RFC 3339. Absent when no recording file exists.",
        ));
        add(Entity::new(
            "agents.sessions.count",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Top-level agent sessions among the recordings read: recordings that are not a subagent of another. Absent, with the reason, when no recording was read. Session identifiers are not reported.",
        ));
        add(Entity::new(
            "agents.sessions.active",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many recordings show in_progress true: their producer's source was still being written when it was read. This counts recordings that show that, not sessions known to be running.",
        ));
        add(Entity::new(
            "agents.sessions.in_progress_unevidenced",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many recordings do not say whether they are still being written. They are neither counted as active nor as closed: the producer evidenced neither.",
        ));
        add(Entity::new(
            "agents.sessions.subagents",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many recordings are subagent runs of another recording in the same read.",
        ));
        add(Entity::new(
            "agents.workflows.count",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many top-level sessions delegated work to subagents: multi-agent runs whose structure the recordings carry.",
        ));
        add(Entity::new(
            "agents.sessions.input_tokens",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Uncached input tokens summed over recordings whose events report usage. Cache reads and writes are not included, so this is usually far below what the models were sent. Absent when no recording reports usage. What a provider charged is on the Inference tab, not here.",
        ));
        add(Entity::new(
            "agents.sessions.output_tokens",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Output tokens summed over recordings whose events report usage. Absent when no recording reports usage.",
        ));
        add(Entity::new(
            "agents.producer.claude_code.sessions",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Recordings read from Claude Code, imported by `ironobs import claude-code`. Absent, with the reason, when none were read.",
        ));
        add(Entity::new(
            "agents.producer.codex.sessions",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Recordings read from the Codex CLI, imported by `ironobs import codex` from the Codex sessions folder (IRONMON_CODEX_DIR, by default under the home directory). Absent, with the reason, when none were read.",
        ));
        add(Entity::new(
            "agents.producer.gemini_cli.sessions",
            D::Agents,
            K::Diagnostic,
            Some(U::Count),
            P::Unavailable,
            true,
            "Always absent. Gemini CLI stores no chats on disk, so there is nothing to read; this says so rather than reporting zero.",
        ));
        add(Entity::new(
            "agents.producer.{name}.sessions",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Recordings read from any other producer that wrote a recording, named by its sanitised producer name. Expanded against a snapshot.",
        ));
        add(Entity::new(
            "agents.remote.<none>",
            D::Agents,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Always present. Cloud and hosted agent sessions have no source readable from this machine, so they are not counted on this tab. Provider cost and usage are on the Inference tab.",
        ));
        add(Entity::new(
            "agents.engine.requests.active",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests the IronWorks engine reports in flight, read from the Inference tab's poller and not polled again here. Absent in a one-shot snapshot, which does not run that poller.",
        ));
        add(Entity::new(
            "agents.engine.requests.recent",
            D::Agents,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Entries in the IronWorks engine's recent-request buffer, read from the Inference tab's poller. Absent in a one-shot snapshot.",
        ));

        // ── Inference (remote providers) ─────────────────────────────────────
        //
        // OpenAI and Anthropic, read only by the background poller and only once
        // the user has configured them (see inference/remote.rs). Snapshot and get
        // never request them. Cost is the current UTC month to date, summed from the
        // rows the provider's admin usage API reports; it is never estimated, and it
        // keeps the provider's currency and scale.
        add(Entity::new(
            "inference.openai.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when OpenAI was not read, carrying the reason: not configured, nothing reachable, the key was rejected, or the endpoint answered with something unexpected.",
        ));
        add(Entity::new(
            "inference.openai.models_listed",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many models the key can list, from GET /v1/models. A reachability fact: it shows the key works.",
        ));
        add(Entity::new(
            "inference.openai.cost.month_to_date",
            D::Inference,
            K::Measurement,
            Some(U::Amount),
            P::Measured,
            true,
            "OpenAI organization cost since the start of the current UTC month, in currency units, summed over the rows GET /v1/organization/costs reports (admin key). The currency is inference.openai.cost.currency. Absent when the admin key is missing or refused, or the rows name more than one currency.",
        ));
        add(Entity::new(
            "inference.openai.cost.currency",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The lowercase ISO-4217 currency the OpenAI cost rows name, such as usd.",
        ));
        add(Entity::new(
            "inference.openai.cost.period_start",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Start of the period the OpenAI cost covers, 00:00 UTC on the first day of the month, RFC 3339.",
        ));
        add(Entity::new(
            "inference.openai.cost.period_end",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "When the OpenAI cost was read, RFC 3339. The cost is refreshed at most every five minutes.",
        ));
        add(Entity::new(
            "inference.anthropic.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when Anthropic was not read, carrying the reason: not configured, nothing reachable, the key was rejected, or the endpoint answered with something unexpected.",
        ));
        add(Entity::new(
            "inference.anthropic.models_listed",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "How many models the key can list, from GET /v1/models. A reachability fact: it shows the key works.",
        ));
        add(Entity::new(
            "inference.anthropic.cost.month_to_date_cents",
            D::Inference,
            K::Measurement,
            Some(U::Amount),
            P::Measured,
            true,
            "Anthropic cost since the start of the current UTC month, in cents (lowest currency units) as the cost report gives them, summed over its daily rows (admin key). Priority Tier costs are not included in this report. The currency is inference.anthropic.cost.currency. An individual account has no Admin API, so the figure is absent there.",
        ));
        add(Entity::new(
            "inference.anthropic.cost.currency",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The currency the Anthropic cost rows name, such as USD.",
        ));
        add(Entity::new(
            "inference.anthropic.cost.period_start",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "Start of the period the Anthropic cost covers, 00:00 UTC on the first day of the month, RFC 3339.",
        ));
        add(Entity::new(
            "inference.anthropic.cost.period_end",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "When the Anthropic cost was read, RFC 3339. The cost is refreshed at most every five minutes.",
        ));

        // ── Inference (IronWorks) ────────────────────────────────────────────
        //
        // Provider-segmented: `inference.ironworks.*` is the first provider and
        // others slot in beside it. Ids follow the engine's schema v1 (final,
        // 2026-11-03): `tiers.vram.hits_total` is `tier.vram.hits_total`. Everything
        // is nullable, because the engine may not be running, and every counter is a
        // measurement the engine reports, so none is `K::Setting`. Peaks and current
        // figures are named as such, because a peak is not a depth.
        add(Entity::new(
            "inference.ironworks.engine.model",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The model the IronWorks engine is serving, as the engine names it.",
        ));
        add(Entity::new(
            "inference.ironworks.engine.backend",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The compute backend the IronWorks engine runs on, such as cuda or metal.",
        ));
        add(Entity::new(
            "inference.ironworks.requests.total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative requests the IronWorks engine has served since it started. A counter; a rate is derived from two samples.",
        ));
        add(Entity::new(
            "inference.ironworks.requests.active",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Requests the IronWorks engine is serving right now. A current count, not a peak.",
        ));
        add(Entity::new(
            "inference.ironworks.decode.prompt_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prompt tokens across every request since the engine started. A counter. Prompt throughput is derived from this counter across two samples, never taken from the engine.",
        ));
        add(Entity::new(
            "inference.ironworks.decode.completion_tokens_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative completion tokens across every request since the engine started, from the engine's token accounting. A counter. Output throughput is derived from this counter across two samples.",
        ));
        add(Entity::new(
            "inference.ironworks.decode.completion_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Output tokens per second: the change in decode.completion_tokens_total over the engine's uptime between two samples. Null in a single-shot read, and across an engine restart.",
        ).derived(&["inference.ironworks.decode.completion_tokens_total"]));
        add(Entity::new(
            "inference.ironworks.decode.prompt_tok_s",
            D::Inference,
            K::Measurement,
            Some(U::TokensPerSecond),
            P::Measured,
            true,
            "Prompt tokens per second: the change in decode.prompt_tokens_total over the engine's uptime between two samples. Null in a single-shot read, and across an engine restart.",
        ).derived(&["inference.ironworks.decode.prompt_tokens_total"]));
        add(Entity::new(
            "inference.ironworks.tier.vram.policy",
            D::Inference,
            K::Identity,
            Some(U::Text),
            P::Measured,
            true,
            "The eviction policy the IronWorks engine applies to its VRAM expert cache.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.experts_resident",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Expert weights resident in the VRAM expert cache right now.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.capacity_experts",
            D::Inference,
            K::Limit,
            Some(U::Count),
            P::Measured,
            true,
            "How many expert weights the VRAM expert cache can hold, as the engine configured it.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.bytes_resident",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Bytes of expert weights resident in the VRAM expert cache right now.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.hits_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM expert-cache hits since the engine started. A counter. The numerator of tier.vram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.fills_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM expert-cache fills since the engine started. A counter. A term in the denominator of tier.vram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.bypass_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM expert-cache bypasses, as the engine counts them since it started. A counter. A term in the denominator of tier.vram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.not_admitted_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM picks not admitted to the cache, as the engine counts them since it started. A counter. A term in the denominator of tier.vram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.evictions_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative expert evictions from the VRAM cache since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.fill_bytes_total",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Cumulative bytes written into the VRAM expert cache since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.warm_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM expert-cache warm-ups, as the engine counts them since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.fills_aborted_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative VRAM expert-cache fills the engine aborted, since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.hit_ratio",
            D::Inference,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            concat!(
                "Share of VRAM expert-cache picks served from the cache, as a percentage over the window between two samples: ",
                "tier.vram.hits_total / (tier.vram.hits_total + tier.vram.fills_total + tier.vram.bypass_total + tier.vram.not_admitted_total), ",
                "over every deduplicated pick the VRAM tier saw. Unavailable when any of those counters is missing, when the window had no picks, ",
                "and in a single-shot read. Never zero for a window that had no picks.",
            ),
        ).derived(&["inference.ironworks.tier.vram.hits_total","inference.ironworks.tier.vram.fills_total","inference.ironworks.tier.vram.bypass_total","inference.ironworks.tier.vram.not_admitted_total"]));
        add(Entity::new(
            "inference.ironworks.tier.ram.experts_resident",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Expert weights resident in the host RAM expert cache right now.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.pinned_bytes",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Bytes of host memory the engine has pinned for the RAM expert cache.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.hits_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative host RAM expert-cache hits since the engine started. A counter. The numerator of tier.ram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.misses_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative host RAM expert-cache misses since the engine started. A counter. A term in the denominator of tier.ram.hit_ratio.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.waits_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative waits on a host RAM expert load, as the engine counts them since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.evictions_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative expert evictions from the host RAM cache since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.bytes_loaded_total",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Cumulative bytes loaded into the host RAM cache since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.puts_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative host RAM expert-cache puts, as the engine counts them since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.discards_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative host RAM expert-cache discards, as the engine counts them since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.loads_abandoned_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative host RAM expert loads the engine abandoned, since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.hit_ratio",
            D::Inference,
            K::Measurement,
            Some(U::Percent),
            P::Measured,
            true,
            concat!(
                "Share of host RAM expert-cache lookups that hit, as a percentage over the window between two samples: ",
                "tier.ram.hits_total / (tier.ram.hits_total + tier.ram.misses_total). ",
                "Unavailable when either counter is missing, when the window had no lookups, and in a single-shot read.",
            ),
        ).derived(&["inference.ironworks.tier.ram.hits_total","inference.ironworks.tier.ram.misses_total"]));
        add(Entity::new(
            "inference.ironworks.tier.nvme.reads_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative reads issued to the NVMe expert store since the engine started. A counter; a rate is derived from two samples.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.bytes_total",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Cumulative bytes read from the NVMe expert store since the engine started. A counter; the read rate is derived from two samples.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.batches_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative read batches issued to the NVMe expert store since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.inflight_peak",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "The most NVMe reads in flight at once since the engine started. A peak (high-water mark), not the number in flight now.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.latency_p50_ms",
            D::Inference,
            K::Measurement,
            Some(U::Milliseconds),
            P::Measured,
            true,
            "Median NVMe read latency as the engine computes it. The engine reports nanoseconds; this is shown in milliseconds.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.latency_p99_ms",
            D::Inference,
            K::Measurement,
            Some(U::Milliseconds),
            P::Measured,
            true,
            "99th-percentile NVMe read latency as the engine computes it. The engine reports nanoseconds; this is shown in milliseconds.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.latency_max_ms",
            D::Inference,
            K::Measurement,
            Some(U::Milliseconds),
            P::Measured,
            true,
            "The slowest single NVMe read since the engine started. A peak (high-water mark). The engine reports nanoseconds; this is shown in milliseconds.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.queue_depth",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Reads queued against the NVMe expert store right now. Reported only by engine builds that instrument it.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.requested_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative expert prefetches requested since the engine started. A counter. Present only with an expert store.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.scheduled_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetches scheduled since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.dropped_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetch requests dropped, as the engine counts them since it started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.loaded_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetched experts loaded since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.useful_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetched experts the engine counts as useful, since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.wasted_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetched experts the engine counts as wasted, since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.errors_total",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "Cumulative prefetch loads that failed, since the engine started. A counter.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.queue_peak",
            D::Inference,
            K::Measurement,
            Some(U::Count),
            P::Measured,
            true,
            "The longest the prefetch queue has been since the engine started. A peak (high-water mark), not the queue length now.",
        ));
        add(Entity::new(
            "inference.ironworks.memory.host.engine_pinned_bytes",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            "Host memory the IronWorks engine has pinned, as the engine reports it.",
        ));
        add(Entity::new(
            "inference.ironworks.gpu.{n}.vram_used_bytes",
            D::Inference,
            K::Measurement,
            Some(U::Bytes),
            P::Measured,
            true,
            concat!(
                "VRAM the IronWorks engine is using on this GPU, as the engine reports it, not the device's total use. ",
                "The engine's GPU is joined to this gpu.{n} by PCI bus address, with UUID as fallback, never by the engine's own device index, ",
                "which CUDA_VISIBLE_DEVICES can renumber.",
            ),
        ));
        add(Entity::new(
            "inference.ironworks.gpu.{n}.pci_bus_id",
            D::Inference,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "The PCI bus address of the GPU the IronWorks engine runs on, as the engine reports it.",
        ));
        add(Entity::new(
            "inference.ironworks.gpu.{n}.uuid",
            D::Inference,
            K::Identity,
            Some(U::Identifier),
            P::Measured,
            true,
            "The UUID of the GPU the IronWorks engine runs on, as the engine reports it.",
        ));
        add(Entity::new(
            "inference.ironworks.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            concat!(
                "Present when no IronWorks metrics were read, carrying the reason. Two different states are named apart: ",
                "\"engine running, metrics not enabled — start it with --metrics\" (the engine answered 404 with its metrics-off body), ",
                "and \"no engine answered\" (nothing answered at the endpoint). Also present when the endpoint answered with something other than IronWorks metrics.",
            ),
        ));
        add(Entity::new(
            "inference.ironworks.tier.vram.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the VRAM expert-cache tier is not configured, or is absent from the engine's metrics, carrying the reason.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.ram.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the host RAM expert-cache tier is not configured, or is absent from the engine's metrics, carrying the reason.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.nvme.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the NVMe expert-store tier is not configured, or is absent from the engine's metrics, carrying the engine's reason.",
        ));
        add(Entity::new(
            "inference.ironworks.tier.prefetch.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the engine's metrics carry no prefetch object. The engine includes one only when an expert store is configured, so its absence means no store, not zero prefetches.",
        ));
        add(Entity::new(
            "inference.ironworks.gpu.<unmatched>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present for each GPU the IronWorks engine uses that could not be matched to one of IronMonitor's own GPUs by PCI bus address or UUID. Its figures are withheld rather than attached to a guessed gpu.{n}, and the reason is given.",
        ));
        add(Entity::new(
            "inference.ironworks.gpu.<none>",
            D::Inference,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when the IronWorks engine reports no per-GPU memory, carrying the reason.",
        ));

        // ── Diagnostics ──────────────────────────────────────────────────────
        //
        // Declared, not synthesised at read time, because everything the resolver
        // emits has to be findable in the schema an agent fetched beforehand. These
        // were the one class of row that violated that: emitting an undeclared
        // `disk.<none>` told an agent something true in a vocabulary it had no way
        // to look up.
        for domain in Domain::ALL {
            add(Entity::new(
                &format!("{}.<none>", domain.as_str()),
                *domain,
                K::Diagnostic,
                None,
                P::Unavailable,
                true,
                "Present only when this domain enumerated nothing. Carries the \
                 reason, so an absent device stays distinguishable from a reader \
                 that is not implemented here.",
            ));
        }
        add(Entity::new(
            "gpu.<unreadable>",
            D::Gpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present when GPU enumeration itself failed, carrying the error. \
             Whether any GPU exists is unknown, which is not the same as the \
             `gpu.<none>` finding that the domain enumerated nothing.",
        ));
        add(Entity::new(
            "gpu.{n}.<unreadable>",
            D::Gpu,
            K::Diagnostic,
            None,
            P::Unavailable,
            true,
            "Present in place of an adapter's readings when that adapter was \
             enumerated but its query failed. Carries the error. The other \
             adapters are reported as usual, and the index stays the adapter's own.",
        ));
        // One row per backend whose detection failed, declared per vendor the way
        // `board.fan.<unreadable>` is declared per domain. These are not templates:
        // the resolver emits each by its literal id, and a backend that found GPUs
        // still gets its row, so its missing cards are not read as absent.
        for vendor in ["nvidia", "amd", "intel", "apple"] {
            add(Entity::new(
                &format!("gpu.backend.{vendor}.<unreadable>"),
                D::Gpu,
                K::Diagnostic,
                None,
                P::Unavailable,
                true,
                &format!(
                    "Present when the {vendor} GPU backend failed to build or enumerate its \
                     adapters. Carries every error it reported. Its GPUs are not in the \
                     list, and their absence is not a fact about the machine."
                ),
            ));
        }
        add(Entity::new(
            "process.<truncated>",
            D::Process,
            K::Diagnostic,
            Some(U::Count),
            P::Unavailable,
            true,
            "Present when the process list was capped. Absence from a truncated \
             list is not absence from the machine.",
        ));

        // The full hardware inventory, one file per area. See `extended`.
        extended::declare(&mut add);

        Self {
            version: ONTOLOGY_VERSION.to_string(),
            entities,
        }
    }

    pub fn get(&self, id: &str) -> Option<&Entity> {
        self.entities.get(id)
    }

    /// The envelope `ironmon describe --format json` prints, over `selected`.
    ///
    /// Shared with the HTTP surface. The version is carried even for a filtered
    /// fragment, so a consumer holding one still knows which schema it speaks.
    pub fn describe_document<'a>(
        &self,
        selected: impl IntoIterator<Item = &'a Entity>,
    ) -> serde_json::Value {
        let filtered: BTreeMap<&str, &Entity> =
            selected.into_iter().map(|e| (e.id.as_str(), e)).collect();
        serde_json::json!({
            "version": self.version,
            "entity_count": filtered.len(),
            "entities": filtered,
        })
    }

    /// Entities in one domain, in id order.
    pub fn in_domain(&self, domain: Domain) -> Vec<&Entity> {
        self.entities
            .values()
            .filter(|e| e.domain == domain)
            .collect()
    }

    /// Substring search over ids and descriptions, for agents that do not yet know
    /// the id space.
    pub fn search(&self, needle: &str) -> Vec<&Entity> {
        let needle = needle.to_ascii_lowercase();
        self.entities
            .values()
            .filter(|e| {
                e.id.to_ascii_lowercase().contains(&needle)
                    || e.description.to_ascii_lowercase().contains(&needle)
            })
            .collect()
    }

    /// Ids whose value is a template — `gpu.{n}.name` rather than a concrete
    /// `gpu.0.name`. A consumer expands these against the live instance count.
    pub fn is_template(id: &str) -> bool {
        id.contains('{')
    }

    /// The entity a concrete id belongs to, resolving templates.
    ///
    /// `gpu.0.name` finds `gpu.{n}.name`; an exact id finds itself. This is the
    /// inverse of expansion, and the lookup an agent needs when it holds a reading
    /// and wants the schema behind it — the unit it is in, whether it may be null,
    /// and the range it must fall inside.
    ///
    /// Segment count must match, so `disk.0.smart.passed` cannot match
    /// `disk.{n}.model`. A `{placeholder}` segment matches any single segment.
    pub fn template_for(&self, concrete: &str) -> Option<&Entity> {
        if let Some(e) = self.get(concrete) {
            return Some(e);
        }
        let parts: Vec<&str> = concrete.split('.').collect();
        self.entities.values().find(|e| {
            let tparts: Vec<&str> = e.id.split('.').collect();
            tparts.len() == parts.len()
                && tparts
                    .iter()
                    .zip(&parts)
                    .all(|(t, c)| t.starts_with('{') || t == c)
        })
    }

    /// Expand a template id for a concrete instance.
    ///
    /// `gpu.{n}.name` with `"0"` becomes `gpu.0.name`. Returns the id unchanged when
    /// it holds no placeholder, so callers need not special-case singletons.
    pub fn instantiate(id: &str, instance: &str) -> String {
        if let Some(open) = id.find('{') {
            if let Some(close) = id[open..].find('}') {
                let mut out = String::with_capacity(id.len() + instance.len());
                out.push_str(&id[..open]);
                out.push_str(instance);
                out.push_str(&id[open + close + 1..]);
                return out;
            }
        }
        id.to_string()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn every_id_is_unique_and_well_formed() {
        let ont = Ontology::build();
        assert!(!ont.entities.is_empty(), "ontology is empty");
        for (key, e) in &ont.entities {
            assert_eq!(key, &e.id, "map key and entity id disagree");
            assert!(
                e.id.starts_with(e.domain.as_str()),
                "{} is not namespaced under its domain {}",
                e.id,
                e.domain.as_str()
            );
            assert!(
                !e.description.is_empty(),
                "{} has no description; the ontology exists to be read by something \
                 that cannot see the hardware",
                e.id
            );
            assert!(
                !e.id.ends_with('.') && !e.id.contains(".."),
                "malformed id: {}",
                e.id
            );
        }
    }

    /// `writable_via` tells an agent it may change something. That is a promise, and
    /// it must be backed by a handler that actually exists — a schema claiming a
    /// write the binary cannot perform is worse than one claiming nothing, because
    /// the agent will try.
    #[test]
    fn every_writable_entity_has_a_registered_handler() {
        let ont = Ontology::build();
        let registered: Vec<String> = crate::profile::apply::builtin_handlers()
            .iter()
            .map(|h| h.setting_id().to_string())
            .collect();

        for e in ont.entities.values() {
            let Some(setting_id) = &e.writable_via else {
                continue;
            };
            assert_eq!(
                e.kind,
                EntityKind::Setting,
                "{} declares writable_via but is not a Setting",
                e.id
            );
            assert!(
                registered.contains(setting_id),
                "{} claims it can be written via {setting_id:?}, but no such apply \
                 handler is registered on this build; an agent told this would \
                 attempt a write that cannot succeed. Registered: {registered:?}",
                e.id
            );
        }
    }

    /// The converse: a handler the binary exposes but the schema hides is a
    /// capability an agent cannot discover. Reading `ironmon profile writable` should
    /// not reveal anything `ironmon describe` omits.
    #[test]
    fn every_registered_handler_is_discoverable_in_the_schema() {
        let ont = Ontology::build();
        let declared: Vec<&String> = ont
            .entities
            .values()
            .filter_map(|e| e.writable_via.as_ref())
            .collect();

        for handler in crate::profile::apply::builtin_handlers() {
            let id = handler.setting_id().to_string();
            assert!(
                declared.contains(&&id),
                "the apply registry exposes {id:?} but no ontology entity declares \
                 it, so an agent reading the schema cannot discover it"
            );
        }
    }

    /// Settings are only meaningful if the kind is used at all — an assertion over
    /// an empty set would pass while the write surface was entirely undeclared,
    /// which is precisely the state this replaced.
    #[test]
    fn the_schema_declares_at_least_one_writable_setting() {
        // Platform-dependent: a build with no handlers for this OS legitimately has
        // none, so this only asserts the two views agree about how many there are.
        let ont = Ontology::build();
        let declared = ont
            .entities
            .values()
            .filter(|e| e.kind == EntityKind::Setting)
            .count();
        let registered = crate::profile::apply::builtin_handlers().len();
        assert_eq!(
            declared, registered,
            "the schema declares {declared} writable settings but the apply registry \
             has {registered}"
        );
    }

    /// A derived value is only as trustworthy as its inputs, so it has to name them.
    #[test]
    fn derived_entities_declare_their_inputs() {
        let ont = Ontology::build();
        for e in ont.entities.values() {
            if e.provenance == Provenance::Derived {
                assert!(
                    !e.derived_from.is_empty(),
                    "{} is derived but names no inputs",
                    e.id
                );
                for input in &e.derived_from {
                    assert!(
                        ont.get(input).is_some(),
                        "{} derives from {input}, which is not in the ontology",
                        e.id
                    );
                }
            } else {
                assert!(
                    e.derived_from.is_empty(),
                    "{} names inputs but is not marked derived",
                    e.id
                );
            }
        }
    }

    /// Only `Measured` counts as an observation. This is the guard that stops an
    /// agent treating a spec-sheet constant as a live reading.
    #[test]
    fn only_measured_values_are_observations() {
        assert!(Provenance::Measured.is_observation());
        assert!(!Provenance::Specification.is_observation());
        assert!(!Provenance::Derived.is_observation());
        assert!(!Provenance::Unavailable.is_observation());
    }

    #[test]
    fn range_validation_rejects_impossible_readings() {
        let ont = Ontology::build();
        let util = ont.get("cpu.total.utilization").unwrap();
        assert!(util.validate_range(50.0).is_none());
        assert!(util.validate_range(-1.0).is_some(), "negative percent");
        assert!(util.validate_range(101.0).is_some(), "over 100 percent");

        let temp = ont.get("gpu.{n}.thermal.temperature").unwrap();
        assert!(temp.validate_range(45.0).is_none());
        // Celsius may be negative; absolute zero may not be undercut.
        assert!(temp.validate_range(-10.0).is_none());
        assert!(temp.validate_range(-300.0).is_some(), "below absolute zero");
        assert!(temp.validate_range(500.0).is_some(), "implausibly hot");
    }

    #[test]
    fn templates_expand_to_concrete_ids() {
        assert!(Ontology::is_template("gpu.{n}.name"));
        assert!(!Ontology::is_template("memory.total"));
        assert_eq!(Ontology::instantiate("gpu.{n}.name", "0"), "gpu.0.name");
        assert_eq!(
            Ontology::instantiate("network.{iface}.rx_rate", "eth0"),
            "network.eth0.rx_rate"
        );
        // Non-templates pass through untouched.
        assert_eq!(Ontology::instantiate("memory.total", "0"), "memory.total");
    }

    #[test]
    fn lookup_and_search_find_entities() {
        let ont = Ontology::build();
        assert!(ont.get("memory.total").is_some());
        assert!(ont.get("no.such.entity").is_none());
        assert!(!ont.in_domain(Domain::Gpu).is_empty());
        assert!(
            !ont.search("temperature").is_empty(),
            "search should find thermal entities"
        );
        assert_eq!(Domain::parse("gpu"), Some(Domain::Gpu));
        assert_eq!(Domain::parse("GPU"), Some(Domain::Gpu));
        assert_eq!(Domain::parse("nonsense"), None);
    }

    /// The ontology must not depend on the machine it is built on: an agent fetches
    /// it as a schema, so two builds have to agree.
    #[test]
    fn build_is_deterministic_and_hardware_independent() {
        let a = serde_json::to_string(&Ontology::build()).unwrap();
        let b = serde_json::to_string(&Ontology::build()).unwrap();
        assert_eq!(a, b);
    }
}

/// Human-facing labels, derived from the ontology rather than retyped per surface.
///
/// The CLI printed `Kernel:`, the GUI printed `Kernel Version`, and the JSON emitted
/// `kernel_version` — three names for one reading, which is exactly what stops an
/// agent correlating what a user reports seeing with what it can query. These
/// helpers give the TUI and GUI the same source the CLI and `ironmon describe` use, so
/// a label shown on screen can be turned back into an id.
pub mod labels {
    use super::{Domain, Ontology};

    /// Title-cased label for an entity id, e.g. `gpu.0.thermal.temperature` ->
    /// "Temperature". Falls back to the last path segment for ids the ontology does
    /// not declare, so a surface never renders a raw dotted id at a user.
    pub fn short_label(id: &str) -> String {
        let leaf = id.rsplit('.').next().unwrap_or(id);
        title_case(leaf)
    }

    /// Fully qualified label including the domain and instance, e.g.
    /// "GPU 0 — Temperature". Used where a surface shows readings from several
    /// devices in one list.
    pub fn qualified_label(id: &str) -> String {
        let parts: Vec<&str> = id.split('.').collect();
        let short = short_label(id);
        match parts.as_slice() {
            [domain, instance, ..] if instance.chars().all(|c| c.is_ascii_digit()) => {
                format!("{} {} — {}", domain_label(domain), instance, short)
            }
            [domain, ..] => format!("{} — {}", domain_label(domain), short),
            [] => short,
        }
    }

    /// Display name for a domain, preserving the acronyms users expect to see.
    pub fn domain_label(domain: &str) -> String {
        match domain {
            "cpu" => "CPU".to_string(),
            "gpu" => "GPU".to_string(),
            // Added with the `usb` domain in 3.4.0. Without it the GUI's existing
            // "USB Devices" heading and the ontology's `Usb` disagreed, which is
            // precisely what `hardcoded_headings_do_not_contradict_the_ontology`
            // exists to catch — and did, on the commit that introduced the domain.
            "usb" => "USB".to_string(),
            "npu" => "NPU".to_string(),
            _ => title_case(domain),
        }
    }

    /// The id a label came from, if the ontology declares exactly one match.
    ///
    /// The inverse direction, and the reason the labels live here: an agent handed
    /// "Temperature" by a user looking at the GUI can ask which ids that could mean
    /// instead of guessing.
    pub fn ids_for_label(label: &str) -> Vec<String> {
        let ontology = Ontology::build();
        let needle = label.trim().to_ascii_lowercase();
        ontology
            .entities
            .keys()
            .filter(|id| short_label(id).to_ascii_lowercase() == needle)
            .cloned()
            .collect()
    }

    /// Whether a domain name is one the ontology knows, so a surface can assert its
    /// section headings correspond to real domains.
    pub fn is_known_domain(domain: &str) -> bool {
        Domain::parse(domain).is_some()
    }

    fn title_case(s: &str) -> String {
        s.split('_')
            .map(|word| {
                let mut chars = word.chars();
                match chars.next() {
                    Some(first) => {
                        first.to_uppercase().collect::<String>() + &chars.as_str().to_lowercase()
                    }
                    None => String::new(),
                }
            })
            .collect::<Vec<_>>()
            .join(" ")
    }

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn labels_are_derived_from_ids() {
            assert_eq!(short_label("gpu.0.thermal.temperature"), "Temperature");
            assert_eq!(short_label("memory.total"), "Total");
            assert_eq!(short_label("system.os.name"), "Name");
            // Underscores become spaces, not run-together words.
            assert_eq!(
                short_label("gpu.0.thermal.critical_temperature"),
                "Critical Temperature"
            );
        }

        #[test]
        fn qualified_labels_name_the_device() {
            assert_eq!(
                qualified_label("gpu.0.thermal.temperature"),
                "GPU 0 — Temperature"
            );
            assert_eq!(qualified_label("memory.total"), "Memory — Total");
            // Acronyms survive title-casing.
            assert_eq!(domain_label("cpu"), "CPU");
            assert_eq!(domain_label("memory"), "Memory");
        }

        /// The inverse direction has to actually work, or the label layer is
        /// decoration rather than a mapping.
        #[test]
        fn labels_map_back_to_ids() {
            let ids = ids_for_label("Total");
            assert!(
                ids.contains(&"memory.total".to_string()),
                "expected memory.total among {ids:?}"
            );
            assert!(ids_for_label("no such label").is_empty());
        }

        #[test]
        fn every_ontology_domain_is_a_known_domain() {
            for d in Domain::ALL {
                assert!(is_known_domain(d.as_str()));
            }
            assert!(!is_known_domain("nonsense"));
        }

        /// No entity may produce an empty label — a surface would render a blank.
        #[test]
        fn no_entity_yields_an_empty_label() {
            for id in Ontology::build().entities.keys() {
                assert!(
                    !short_label(id).trim().is_empty(),
                    "{id} produced an empty label"
                );
                assert!(
                    !qualified_label(id).trim().is_empty(),
                    "{id} produced an empty qualified label"
                );
            }
        }
    }
}