codewhale-tui 0.9.10

Terminal UI for open-source and open-weight coding models
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
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
//! Progressive setup and repair guide.
//!
//! Bare `/setup` starts at the first missing decision and otherwise shows a
//! compact readiness summary. Optional power tools only join that journey when
//! they are already configured or need repair. Named `/setup <target>` routes
//! and the versioned Constitution checkpoint remain compatibility entrypoints,
//! but ordinary preferences belong to `/settings` and advanced keys belong to
//! `/config <key>`.

use std::borrow::Cow;
use std::path::Path;

use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{
    buffer::Buffer,
    layout::Rect,
    style::{Modifier, Style},
    text::{Line, Span},
    widgets::{Paragraph, Widget, Wrap},
};

use crate::config::{Config, has_api_key};
use crate::localization::{Locale, MessageId, tr};
use crate::palette;
use crate::prompts::{
    BASE_PROMPT_OVERRIDE_OPT_IN_ENV, CONSTITUTION_OVERRIDE_FILE, base_prompt_override_opt_in,
};
use crate::tui::app::App;
use crate::tui::onboarding;
use crate::tui::views::{
    ActionHint, ModalKind, ModalView, ViewAction, ViewEvent, render_modal_footer,
    render_panel_scroll_rail, render_underwater_surface,
};

use codewhale_config::{
    AutonomyPreference, ConstitutionAuthoring, ConstitutionChoice, ConstitutionSource,
    ConstitutionValidity, InheritedConfigFacts, RuntimePostureSource, SetupState, SetupStep,
    StepEntry, StepStatus, UserConstitution, UserConstitutionLoad,
    user_constitution::MAX_NOTES_LEN,
};

mod fleet_draft;
mod model_draft;
mod operate;
mod persistence;
mod provider;
mod remote;
mod tools_mcp;

pub(crate) use fleet_draft::{draft_fleet_profile_with_model, workspace_fingerprint};
pub(crate) use model_draft::draft_constitution_with_model;
use persistence::SetupPersistenceFacts;
use remote::SetupRemoteFacts;

/// Target lane for the once-per-version constitution checkpoint. Bumped per
/// release when the bundled constitution materially changes, so existing users
/// re-acknowledge it once. 0.9.4 re-ships the Fleet/operate constitution.
pub const CONSTITUTION_CHECKPOINT_VERSION: &str = "0.9.4";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SetupCommitKind {
    BundledConstitution,
    DeferredConstitution,
}

pub trait SetupWizardStep {
    fn id(&self) -> SetupStep;
    fn title_id(&self) -> MessageId;
    fn why_id(&self) -> MessageId;
    fn required(&self) -> bool;
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct StaticSetupStep {
    id: SetupStep,
    title_id: MessageId,
    why_id: MessageId,
    required: bool,
}

impl SetupWizardStep for StaticSetupStep {
    fn id(&self) -> SetupStep {
        self.id
    }

    fn title_id(&self) -> MessageId {
        self.title_id
    }

    fn why_id(&self) -> MessageId {
        self.why_id
    }

    fn required(&self) -> bool {
        self.required
    }
}

const STEP_SPECS: [StaticSetupStep; 10] = [
    StaticSetupStep {
        id: SetupStep::Language,
        title_id: MessageId::SetupStepLanguageTitle,
        why_id: MessageId::SetupStepLanguageWhy,
        required: true,
    },
    StaticSetupStep {
        id: SetupStep::ProviderModel,
        title_id: MessageId::SetupStepProviderModelTitle,
        why_id: MessageId::SetupStepProviderModelWhy,
        required: true,
    },
    StaticSetupStep {
        id: SetupStep::TrustSandbox,
        title_id: MessageId::SetupStepTrustSandboxTitle,
        why_id: MessageId::SetupStepTrustSandboxWhy,
        required: true,
    },
    StaticSetupStep {
        id: SetupStep::Constitution,
        title_id: MessageId::SetupStepConstitutionTitle,
        why_id: MessageId::SetupStepConstitutionWhy,
        required: true,
    },
    StaticSetupStep {
        id: SetupStep::OperateFleet,
        title_id: MessageId::SetupStepOperateFleetTitle,
        why_id: MessageId::SetupStepOperateFleetWhy,
        required: false,
    },
    StaticSetupStep {
        id: SetupStep::Hotbar,
        title_id: MessageId::SetupStepHotbarTitle,
        why_id: MessageId::SetupStepHotbarWhy,
        required: false,
    },
    StaticSetupStep {
        id: SetupStep::ToolsMcp,
        title_id: MessageId::SetupStepToolsMcpTitle,
        why_id: MessageId::SetupStepToolsMcpWhy,
        required: false,
    },
    StaticSetupStep {
        id: SetupStep::RemoteRuntime,
        title_id: MessageId::SetupStepRemoteRuntimeTitle,
        why_id: MessageId::SetupStepRemoteRuntimeWhy,
        required: false,
    },
    StaticSetupStep {
        id: SetupStep::Persistence,
        title_id: MessageId::SetupStepPersistenceTitle,
        why_id: MessageId::SetupStepPersistenceWhy,
        required: false,
    },
    StaticSetupStep {
        id: SetupStep::Verification,
        title_id: MessageId::SetupStepVerificationTitle,
        why_id: MessageId::SetupStepVerificationWhy,
        required: false,
    },
];

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetupWizardView {
    state: SetupState,
    selected: usize,
    locale: Locale,
    /// Bare `/setup` is a short runtime-derived repair journey. Explicit
    /// targets remain focused compatibility cards outside that journey.
    progressive_guide: bool,
    /// Technical inventory and preset details stay off the first paint.
    details_expanded: bool,
    facts: SetupRuntimeFacts,
    guided_draft: GuidedConstitutionDraft,
    /// First-run shows one plain-language initiative choice. The six-axis
    /// editor remains available explicitly, but never competes with the
    /// recommended path on first paint.
    constitution_advanced: bool,
    freeform_note: String,
    editing_freeform_note: bool,
    guided_preview_seen: bool,
    /// The keep-existing path mirrors the guided two-step: the first `K`
    /// opens the rendered preview of the existing file, the second completes
    /// the checkpoint without touching it.
    existing_preview_seen: bool,
    /// A model-drafted constitution awaiting ratification, installed by the
    /// host after a successful one-shot draft (already sanitized + bounded).
    /// Cleared whenever a guided answer changes so a stale draft can never be
    /// ratified against fresh answers.
    model_draft: Option<Box<UserConstitution>>,
    /// Display label of the model that authored `model_draft` (safe metadata,
    /// e.g. "GLM-5.2"), for provenance copy only.
    model_draft_label: Option<String>,
    runtime_preset: SetupRuntimePreset,
    runtime_preset_preview_seen: bool,
    body_scroll: usize,
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct SetupRuntimeFacts {
    provider: String,
    model: String,
    auth: String,
    health: String,
    provider_ready: bool,
    provider_result: String,
    work_intent: String,
    approval: String,
    shell: String,
    allow_shell_enabled: bool,
    trust: String,
    sandbox: String,
    sandbox_mode_value: String,
    network: String,
    network_default_value: String,
    runtime_result: String,
    operate_runtime_ready: bool,
    operate_runtime_result: String,
    fleet_roster_ready: bool,
    fleet_roster_result: String,
    operate_concurrency_result: String,
    operate_result: String,
    hotbar_bindings_result: String,
    hotbar_actions_result: String,
    hotbar_result: String,
    tools_mcp_servers_result: String,
    tools_mcp_skills_result: String,
    tools_mcp_tools_result: String,
    tools_mcp_plugins_result: String,
    tools_mcp_dsh_result: String,
    tools_mcp_hotbar_result: String,
    tools_mcp_result: String,
    tools_mcp_needs_action: bool,
    tools_mcp_path_display: String,
    tools_mcp_skills_path_display: String,
    tools_mcp_plugins_path_display: String,
    remote_clouds_result: String,
    remote_bridges_result: String,
    remote_providers_result: String,
    remote_mode_result: String,
    remote_command_provider: String,
    remote_result: String,
    remote_control_result: String,
    /// The four observed remote modes (#3409). Empty only before facts load.
    remote_modes: Vec<remote::RemoteModeFact>,
    /// True when a mode is missing a token or config. Recorded as
    /// `NeedsAction`, which by contract never blocks the ready screen.
    remote_needs_action: bool,
    persistence: SetupPersistenceFacts,
    default_mode: String,
    approval_policy_value: String,
    project_override_warning: Option<String>,
    constitution_autonomy: String,
    constitution_file: SetupConstitutionFileState,
    expert_override: SetupExpertOverrideState,
}

impl Default for SetupRuntimeFacts {
    fn default() -> Self {
        Self {
            provider: "not loaded".to_string(),
            model: "not loaded".to_string(),
            auth: "not checked".to_string(),
            health: "not checked".to_string(),
            provider_ready: false,
            provider_result: "provider/model not loaded".to_string(),
            work_intent: "not loaded".to_string(),
            approval: "not loaded".to_string(),
            shell: "not loaded".to_string(),
            allow_shell_enabled: false,
            trust: "not loaded".to_string(),
            sandbox: "not configured".to_string(),
            sandbox_mode_value: "default".to_string(),
            network: "not configured".to_string(),
            network_default_value: "prompt".to_string(),
            runtime_result: "runtime posture not loaded".to_string(),
            operate_runtime_ready: false,
            operate_runtime_result: "worker runtime not loaded".to_string(),
            fleet_roster_ready: false,
            fleet_roster_result: "Fleet roster not loaded".to_string(),
            operate_concurrency_result: "concurrency not loaded".to_string(),
            operate_result: "operate readiness not loaded".to_string(),
            hotbar_bindings_result: "Hotbar config not loaded".to_string(),
            hotbar_actions_result: "Hotbar actions not loaded".to_string(),
            hotbar_result: "hotbar not loaded".to_string(),
            tools_mcp_servers_result: "MCP config not loaded".to_string(),
            tools_mcp_skills_result: "skills dir not loaded".to_string(),
            tools_mcp_tools_result: "tools dir not loaded".to_string(),
            tools_mcp_plugins_result: "plugins dir not loaded".to_string(),
            tools_mcp_dsh_result: "DeepSeek Harness not probed".to_string(),
            tools_mcp_hotbar_result: "hotbar source metadata not loaded".to_string(),
            tools_mcp_result: "tools/MCP not loaded".to_string(),
            tools_mcp_needs_action: false,
            tools_mcp_path_display: String::new(),
            tools_mcp_skills_path_display: String::new(),
            tools_mcp_plugins_path_display: String::new(),
            remote_clouds_result: "remote cloud registry not loaded".to_string(),
            remote_bridges_result: "remote bridge registry not loaded".to_string(),
            remote_providers_result: "provider registry not loaded".to_string(),
            remote_mode_result: "remote setup mode not loaded".to_string(),
            remote_command_provider: "deepseek".to_string(),
            remote_result: "remote runtime not loaded".to_string(),
            remote_control_result: "off".to_string(),
            remote_modes: Vec::new(),
            remote_needs_action: false,
            persistence: SetupPersistenceFacts::default(),
            default_mode: "agent".to_string(),
            approval_policy_value: "on-request".to_string(),
            project_override_warning: None,
            constitution_autonomy: "not loaded".to_string(),
            constitution_file: SetupConstitutionFileState::NotChecked,
            expert_override: SetupExpertOverrideState::NotChecked,
        }
    }
}

impl SetupRuntimeFacts {
    fn from_app_config(app: &App, config: &Config) -> Self {
        let expert_override = SetupExpertOverrideState::load();
        let readiness = crate::provider_readiness::resolve_for_model(
            config,
            app.api_provider,
            if app.auto_model { "auto" } else { &app.model },
            &app.provider_health,
        );
        // A failed observed check remains retryable in route pickers, but the
        // setup receipt must not certify it as healthy. Saved-unchecked and
        // local-unchecked are honest reviewed configuration states; an actual
        // session failure is NeedsAction until a later success replaces it.
        let provider_ready = readiness.can_attempt()
            && !matches!(
                &readiness,
                crate::provider_readiness::ResolvedProviderReadiness::SavedLastCheckFailed { .. }
            );
        let model = app.model_display_label();
        let provider_name = if app.api_provider == crate::config::ApiProvider::Custom {
            app.provider_identity_for_persistence().to_string()
        } else {
            app.api_provider.display_name().to_string()
        };
        let context_window = crate::route_budget::route_context_window_tokens(
            app.api_provider,
            &app.model,
            app.active_route_limits,
        );
        let context_window_source = app.active_context_window_source.display_label();
        let provider =
            format!("{provider_name} ยท context {context_window} ({context_window_source})");
        let auth = readiness.label().into_owned();
        let health = if provider_ready {
            format!("{}; route can be attempted", readiness.label())
        } else if matches!(
            &readiness,
            crate::provider_readiness::ResolvedProviderReadiness::SavedLastCheckFailed { .. }
        ) {
            format!("{}; retry or open /provider", readiness.label())
        } else if app.api_provider == crate::config::ApiProvider::OpenaiCodex {
            format!(
                "{}; run codex login, then grant exact read-only access with `codewhale auth external-consent --provider openai-codex --mode read-only`, or open /provider",
                readiness.label()
            )
        } else if let Some(url) = crate::config::credential_help_for_provider_route(
            app.api_provider,
            &config.deepseek_base_url(),
        )
        .credential_url
        {
            format!(
                "{}; credentials: {url}; open /provider to repair the route",
                readiness.label()
            )
        } else {
            format!(
                "{}; {}; open /provider to repair the route",
                readiness.label(),
                crate::config::credential_help_for_provider_route(
                    app.api_provider,
                    &config.deepseek_base_url(),
                )
                .guidance
            )
        };
        let provider_result = format!(
            "provider={}, model={}, context_window={} ({}) auth={}, health={}",
            app.provider_identity_for_persistence(),
            model,
            context_window,
            context_window_source,
            readiness.label(),
            if provider_ready {
                "attemptable"
            } else {
                "needs action"
            }
        );
        let shell = if app.allow_shell { "enabled" } else { "hidden" }.to_string();
        let trust = if app.trust_mode {
            "trusted workspace / writes allowed by posture"
        } else {
            "workspace trust not elevated"
        }
        .to_string();
        let sandbox = config
            .sandbox_mode
            .as_deref()
            .filter(|mode| !mode.trim().is_empty())
            .unwrap_or("default")
            .to_string();
        let sandbox_mode_value = sandbox.clone();
        let network_default_value = config
            .network
            .as_ref()
            .map_or("prompt".to_string(), |policy| policy.default.clone());
        let network = config
            .network
            .as_ref()
            .map_or("prompt by default".to_string(), |policy| {
                format!("default {}", policy.default)
            });
        let runtime_result = format!(
            "intent={}, approval={}, shell={}, trust={}, sandbox={}, network={}",
            app.mode.as_setting(),
            app.approval_mode
                .permission_chip_label()
                .to_ascii_lowercase(),
            if app.allow_shell { "enabled" } else { "hidden" },
            if app.trust_mode {
                "trusted"
            } else {
                "workspace"
            },
            sandbox,
            network
        );
        let operate = operate::SetupOperateFacts::from_app_config(app, config, provider_ready);
        let known_hotbar_action_ids = app
            .hotbar_actions
            .iter()
            .map(|action| action.id())
            .collect::<Vec<_>>();
        let hotbar_resolution = config.resolve_hotbar_bindings(&known_hotbar_action_ids);
        let configured_hotbar_slots = config.hotbar.as_ref().map_or(0, Vec::len);
        let hotbar_state = match config.hotbar.as_ref() {
            None => "hidden",
            Some(bindings) if bindings.is_empty() => "disabled",
            Some(_) => "customized",
        };
        let active_hotbar_slots = hotbar_resolution.bindings.len();
        let hotbar_warning_count = hotbar_resolution.warnings.len();
        let hotbar_bindings_result = format!(
            "{hotbar_state}; configured_slots={configured_hotbar_slots}; active_slots={active_hotbar_slots}; warnings={hotbar_warning_count}"
        );
        let hotbar_actions_result =
            format!("{} bindable actions registered", app.hotbar_actions.len());
        let hotbar_result = format!(
            "state={hotbar_state}, configured_slots={configured_hotbar_slots}, active_slots={active_hotbar_slots}, actions={}, warnings={hotbar_warning_count}",
            app.hotbar_actions.len()
        );
        let codewhale_home = setup_codewhale_home_dir();
        let persistence = SetupPersistenceFacts::from_app_config(app, config, &codewhale_home);
        let tools_mcp =
            tools_mcp::SetupToolsMcpFacts::from_app_config(app, config, &codewhale_home);
        let tools_mcp_servers_result = tools_mcp.servers_result;
        let tools_mcp_skills_result = tools_mcp.skills_result;
        let tools_mcp_tools_result = tools_mcp.tools_result;
        let tools_mcp_plugins_result = tools_mcp.plugins_result;
        let tools_mcp_hotbar_result = tools_mcp.hotbar_result;
        let tools_mcp_dsh_result = tools_mcp.dsh_result;
        let tools_mcp_result = tools_mcp.result;
        let tools_mcp_needs_action = tools_mcp.needs_action;
        let tools_mcp_path_display = tools_mcp.mcp_path_display;
        let tools_mcp_skills_path_display = tools_mcp.skills_path_display;
        let tools_mcp_plugins_path_display = tools_mcp.plugins_path_display;
        let remote = SetupRemoteFacts::from_app(app);
        let remote_needs_action = remote.needs_action();
        let constitution_autonomy = UserConstitution::load()
            .ok()
            .and_then(|load| {
                load.constitution().map(|constitution| {
                    autonomy_label(constitution.autonomy_preference, app.ui_locale).to_string()
                })
            })
            .unwrap_or_else(|| tr(app.ui_locale, MessageId::SetupAutonomyUnspecified).to_string());
        Self {
            provider,
            model,
            auth,
            health,
            provider_ready,
            provider_result,
            work_intent: app.mode.display_name().to_string(),
            approval: app
                .approval_mode
                .permission_chip_label()
                .to_ascii_lowercase(),
            shell,
            allow_shell_enabled: app.allow_shell,
            trust,
            sandbox,
            sandbox_mode_value,
            network,
            network_default_value,
            runtime_result,
            operate_runtime_ready: operate.runtime_ready,
            operate_runtime_result: operate.runtime_result,
            fleet_roster_ready: operate.roster_ready,
            fleet_roster_result: operate.roster_result,
            operate_concurrency_result: operate.concurrency_result,
            operate_result: operate.result,
            hotbar_bindings_result,
            hotbar_actions_result,
            hotbar_result,
            tools_mcp_servers_result,
            tools_mcp_skills_result,
            tools_mcp_tools_result,
            tools_mcp_plugins_result,
            tools_mcp_hotbar_result,
            tools_mcp_dsh_result,
            tools_mcp_result,
            tools_mcp_needs_action,
            tools_mcp_path_display,
            tools_mcp_skills_path_display,
            tools_mcp_plugins_path_display,
            remote_clouds_result: remote.clouds_result,
            remote_bridges_result: remote.bridges_result,
            remote_providers_result: remote.providers_result,
            remote_mode_result: remote.mode_result,
            remote_command_provider: remote.command_provider,
            remote_result: remote.result,
            remote_control_result: {
                let status = app.remote_control.status_line();
                let message = if status.starts_with("Remote control: connected") {
                    MessageId::SetupRemoteStatusReady
                } else if status.starts_with("Remote control: connecting")
                    || status.starts_with("Remote control: stopping")
                {
                    MessageId::SetupStatusInProgress
                } else if status.starts_with("Remote control: disconnected") {
                    MessageId::SetupRemoteStatusNeedsAction
                } else {
                    MessageId::SetupRemoteStatusDisabled
                };
                tr(app.ui_locale, message).into_owned()
            },
            remote_needs_action,
            remote_modes: remote.modes,
            persistence,
            default_mode: app.mode.as_setting().to_string(),
            approval_policy_value: config
                .approval_policy
                .as_deref()
                .filter(|policy| !policy.trim().is_empty())
                .unwrap_or("on-request")
                .to_string(),
            project_override_warning: project_runtime_override_warning(
                &app.workspace,
                app.ui_locale,
            ),
            constitution_autonomy,
            constitution_file: SetupConstitutionFileState::load(),
            expert_override,
        }
    }
}

fn setup_codewhale_home_dir() -> std::path::PathBuf {
    codewhale_config::codewhale_home().unwrap_or_else(|_| {
        crate::config::effective_home_dir().map_or_else(
            || std::path::PathBuf::from(".codewhale"),
            |home| home.join(".codewhale"),
        )
    })
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SetupRuntimePreset {
    AskFirst,
    #[default]
    NormalAgent,
    HighTrustLocal,
}

impl SetupRuntimePreset {
    const ALL: [Self; 3] = [Self::AskFirst, Self::NormalAgent, Self::HighTrustLocal];

    fn from_key(key: char) -> Option<Self> {
        match key {
            '1' => Some(Self::AskFirst),
            '2' => Some(Self::NormalAgent),
            '3' => Some(Self::HighTrustLocal),
            _ => None,
        }
    }

    pub fn id(self) -> &'static str {
        match self {
            Self::AskFirst => "ask-first",
            Self::NormalAgent => "normal-agent",
            Self::HighTrustLocal => "high-trust-local",
        }
    }

    fn title_id(self) -> MessageId {
        match self {
            Self::AskFirst => MessageId::SetupRuntimePresetAskFirstTitle,
            Self::NormalAgent => MessageId::SetupRuntimePresetNormalAgentTitle,
            Self::HighTrustLocal => MessageId::SetupRuntimePresetHighTrustTitle,
        }
    }

    fn description_id(self) -> MessageId {
        match self {
            Self::AskFirst => MessageId::SetupRuntimePresetAskFirstDescription,
            Self::NormalAgent => MessageId::SetupRuntimePresetNormalAgentDescription,
            Self::HighTrustLocal => MessageId::SetupRuntimePresetHighTrustDescription,
        }
    }

    pub fn default_mode(self) -> &'static str {
        match self {
            Self::AskFirst => "plan",
            Self::NormalAgent | Self::HighTrustLocal => "agent",
        }
    }

    pub fn permission_posture(self) -> &'static str {
        match self {
            Self::AskFirst | Self::NormalAgent => "ask",
            Self::HighTrustLocal => "full-access",
        }
    }

    pub fn approval_policy(self) -> Option<&'static str> {
        match self {
            Self::AskFirst | Self::NormalAgent => Some("on-request"),
            // Full Access lives in TUI settings; it is intentionally not a
            // top-level approval_policy value.
            Self::HighTrustLocal => None,
        }
    }

    pub fn allow_shell(self) -> bool {
        match self {
            Self::AskFirst => false,
            Self::NormalAgent | Self::HighTrustLocal => true,
        }
    }

    pub fn sandbox_mode(self) -> &'static str {
        match self {
            Self::AskFirst => "read-only",
            Self::NormalAgent => "workspace-write",
            Self::HighTrustLocal => "danger-full-access",
        }
    }

    pub fn result_summary(self) -> String {
        let approval = self
            .approval_policy()
            .unwrap_or("unset (Full Access saved in TUI settings)");
        format!(
            "preset={}, default_mode={}, permission_posture={}, approval_policy={}, allow_shell={}, sandbox_mode={}, network=unchanged, trust=unchanged",
            self.id(),
            self.display_mode(),
            self.permission_posture(),
            approval,
            self.allow_shell(),
            self.sandbox_mode()
        )
    }

    fn display_mode(self) -> &'static str {
        match self {
            Self::AskFirst => "plan",
            Self::NormalAgent => "act",
            Self::HighTrustLocal => "act + full-access",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum SetupConstitutionFileState {
    NotChecked,
    Missing,
    Loaded,
    Empty,
    Invalid,
    Unreadable,
    PathError,
}

impl SetupConstitutionFileState {
    fn load() -> Self {
        match UserConstitution::path() {
            Ok(path) => Self::from_load(&UserConstitution::load_from(&path)),
            Err(_) => Self::PathError,
        }
    }

    fn from_load(load: &UserConstitutionLoad) -> Self {
        match load {
            UserConstitutionLoad::Missing => Self::Missing,
            UserConstitutionLoad::Empty => Self::Empty,
            UserConstitutionLoad::Invalid(_) => Self::Invalid,
            UserConstitutionLoad::Unreadable(_) => Self::Unreadable,
            UserConstitutionLoad::Loaded(_) => Self::Loaded,
        }
    }

    fn label(self, choice: ConstitutionChoice, locale: Locale) -> Cow<'static, str> {
        let id = match self {
            Self::NotChecked => MessageId::SetupConstitutionFileNotChecked,
            Self::Missing => MessageId::SetupConstitutionFileMissing,
            Self::Loaded if choice == ConstitutionChoice::GuidedCustom => {
                MessageId::SetupConstitutionFileLoadedSelected
            }
            Self::Loaded if choice.is_explicit() => MessageId::SetupConstitutionFileLoadedInactive,
            Self::Loaded => MessageId::SetupConstitutionFileLoadedUnselected,
            Self::Empty => MessageId::SetupConstitutionFileEmpty,
            Self::Invalid => MessageId::SetupConstitutionFileInvalid,
            Self::Unreadable => MessageId::SetupConstitutionFileUnreadable,
            Self::PathError => MessageId::SetupConstitutionFilePathError,
        };
        tr(locale, id)
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum SetupExpertOverrideState {
    NotChecked,
    Missing,
    Active,
    Disabled,
    Empty,
    Unreadable,
    PathError,
}

impl SetupExpertOverrideState {
    fn load() -> Self {
        let Some(path) = expert_override_path() else {
            return Self::PathError;
        };
        match std::fs::read_to_string(&path) {
            Ok(raw) if raw.trim().is_empty() => Self::Empty,
            Ok(_) if base_prompt_override_opt_in() => Self::Active,
            Ok(_) => Self::Disabled,
            Err(err) if err.kind() == std::io::ErrorKind::NotFound => Self::Missing,
            Err(_) => Self::Unreadable,
        }
    }

    fn is_active(self) -> bool {
        matches!(self, Self::Active)
    }

    fn label(self, locale: Locale) -> Cow<'static, str> {
        match self {
            Self::NotChecked => tr(locale, MessageId::SetupExpertOverrideNotChecked),
            Self::Missing => tr(locale, MessageId::SetupExpertOverrideMissing),
            Self::Active => tr(locale, MessageId::SetupExpertOverrideActive),
            Self::Disabled => tr(locale, MessageId::SetupExpertOverrideDisabled)
                .replace("{env}", BASE_PROMPT_OVERRIDE_OPT_IN_ENV)
                .into(),
            Self::Empty => tr(locale, MessageId::SetupExpertOverrideEmpty),
            Self::Unreadable => tr(locale, MessageId::SetupExpertOverrideUnreadable),
            Self::PathError => tr(locale, MessageId::SetupExpertOverridePathError),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct GuidedConstitutionDraft {
    purpose: GuidedPurpose,
    autonomy: AutonomyPreference,
    evidence: GuidedEvidence,
    communication: GuidedCommunication,
    privacy: GuidedPrivacy,
    principles: GuidedPrinciples,
}

impl Default for GuidedConstitutionDraft {
    fn default() -> Self {
        Self {
            purpose: GuidedPurpose::Coding,
            autonomy: AutonomyPreference::Balanced,
            evidence: GuidedEvidence::TestsAndReceipts,
            communication: GuidedCommunication::Concise,
            privacy: GuidedPrivacy::StandardCare,
            principles: GuidedPrinciples::ScopedChanges,
        }
    }
}

impl GuidedConstitutionDraft {
    fn cycle(&mut self, key: char) -> bool {
        match key {
            '1' => self.purpose = self.purpose.next(),
            '2' => self.autonomy = next_guided_autonomy(self.autonomy),
            '3' => self.evidence = self.evidence.next(),
            '4' => self.communication = self.communication.next(),
            '5' => self.privacy = self.privacy.next(),
            '6' => self.principles = self.principles.next(),
            _ => return false,
        }
        true
    }

    fn to_constitution_with_freeform(
        self,
        locale: Locale,
        freeform_note: Option<&str>,
    ) -> UserConstitution {
        let mut notes = self.notes(locale);
        if let Some(note) = freeform_note.map(str::trim).filter(|note| !note.is_empty()) {
            let own_words = match locale {
                Locale::Ja => format!(
                    "\nใƒฆใƒผใ‚ถใƒผ่‡ช็”ฑๅŽŸๅ‰‡๏ผš{}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::ZhHans => format!(
                    "\n็”จๆˆท่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผš{}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::ZhHant => format!(
                    "\nไฝฟ็”จ่€…่‡ช็”ฑๅŽŸๅ‰‡๏ผš{}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::PtBr => format!(
                    "\nPrincรญpio livre do usuรกrio: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Es419 => format!(
                    "\nPrincipio libre del usuario: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Vi => format!(
                    "\nNguyรชn tแบฏc tแปฑ do cแปงa ngฦฐแปi dรนng: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Ko => format!(
                    "\n์‚ฌ์šฉ์ž ์ž์œ  ์›์น™: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Ca => format!(
                    "\nPrincipi lliure de l'usuari: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::De => format!(
                    "\nFreitext-Prinzip des Nutzers: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Fr => format!(
                    "\nPrincipe en texte libre de l'utilisateur : {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Id => format!(
                    "\nPrinsip bebas pengguna: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Hi => format!(
                    "\nเค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เคฎเฅเค•เฅเคค-เคชเคพเค  เคธเคฟเคฆเฅเคงเคพเค‚เคค: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Ru => format!(
                    "\nะกะฒะพะฑะพะดะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                Locale::Uk => format!(
                    "\nะ’ั–ะปัŒะฝะธะน ะฟั€ะธะฝั†ะธะฟ ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
                _ => format!(
                    "\nUser freeform principle: {}",
                    bounded_freeform_note(note, MAX_NOTES_LEN)
                ),
            };
            notes.push_str(&own_words);
        }
        UserConstitution {
            language: Some(locale.tag().to_string()),
            about: Some(self.purpose.about(locale).to_string()),
            working_style: vec![
                self.purpose.working_style(locale).to_string(),
                self.communication.working_style(locale).to_string(),
                self.evidence.working_style(locale).to_string(),
                self.privacy.working_style(locale).to_string(),
            ],
            priorities: vec![
                authority_priority(locale).to_string(),
                autonomy_priority(self.autonomy, locale).to_string(),
                self.privacy.escalation_rule(locale).to_string(),
            ],
            autonomy_preference: self.autonomy,
            notes: Some(notes),
            ..UserConstitution::default()
        }
    }

    fn notes(self, locale: Locale) -> String {
        let notes = tr(locale, MessageId::SetupGuidedNotes);
        notes
            .replace("{purpose}", &self.purpose.label(locale))
            .replace("{initiative}", autonomy_label(self.autonomy, locale))
            .replace("{evidence}", &self.evidence.label(locale))
            .replace("{communication}", self.communication.label(locale))
            .replace("{privacy}", self.privacy.label(locale))
            .replace("{principles}", self.principles.label(locale))
            .replace("{notes}", self.principles.note(locale))
            .to_string()
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum GuidedPurpose {
    Coding,
    Research,
    Operations,
    Mixed,
}

impl GuidedPurpose {
    fn next(self) -> Self {
        match self {
            Self::Coding => Self::Research,
            Self::Research => Self::Operations,
            Self::Operations => Self::Mixed,
            Self::Mixed => Self::Coding,
        }
    }

    fn label(self, locale: Locale) -> Cow<'static, str> {
        match self {
            Self::Coding => tr(locale, MessageId::SetupGuidedPurposeCoding),
            Self::Research => tr(locale, MessageId::SetupGuidedPurposeResearch),
            Self::Operations => tr(locale, MessageId::SetupGuidedPurposeOperations),
            Self::Mixed => tr(locale, MessageId::SetupGuidedPurposeMixed),
        }
    }

    fn about(self, locale: Locale) -> Cow<'static, str> {
        match self {
            Self::Coding => tr(locale, MessageId::SetupGuidedPurposeAboutCoding),
            Self::Research => tr(locale, MessageId::SetupGuidedPurposeAboutResearch),
            Self::Operations => tr(locale, MessageId::SetupGuidedPurposeAboutOperations),
            Self::Mixed => tr(locale, MessageId::SetupGuidedPurposeAboutMixed),
        }
    }

    fn working_style(self, locale: Locale) -> Cow<'static, str> {
        match self {
            Self::Coding => tr(locale, MessageId::SetupGuidedStyleCoding),
            Self::Research => tr(locale, MessageId::SetupGuidedStyleResearch),
            Self::Operations => tr(locale, MessageId::SetupGuidedStyleOperations),
            Self::Mixed => tr(locale, MessageId::SetupGuidedStyleMixed),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum GuidedEvidence {
    Assumptions,
    TestsAndReceipts,
    ReleaseReceipts,
}

impl GuidedEvidence {
    fn next(self) -> Self {
        match self {
            Self::Assumptions => Self::TestsAndReceipts,
            Self::TestsAndReceipts => Self::ReleaseReceipts,
            Self::ReleaseReceipts => Self::Assumptions,
        }
    }

    fn label(self, locale: Locale) -> Cow<'static, str> {
        match self {
            Self::Assumptions => tr(locale, MessageId::SetupGuidedEvidenceAssumptions),
            Self::TestsAndReceipts => tr(locale, MessageId::SetupGuidedEvidenceTestsAndReceipts),
            Self::ReleaseReceipts => tr(locale, MessageId::SetupGuidedEvidenceReleaseReceipts),
        }
    }

    fn working_style(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::Assumptions) => {
                "ๅฎŒไบ†ใ‚’ไธปๅผตใ™ใ‚‹ๅ‰ใซใ€ๅ‰ๆใ€ไธๆ˜Ž็‚นใ€ๆฎ‹ใ‚‹ใƒชใ‚นใ‚ฏใ‚’่ฆ็ด„ใ™ใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::TestsAndReceipts) => {
                "ไธ็ขบๅฎŸๆ€งใ‚’ๆธ›ใ‚‰ใ›ใ‚‹ใจใใฏใ€ใ‚ณใƒžใƒณใƒ‰ใ€ใƒ†ใ‚นใƒˆใ€ใ‚นใ‚ฏใƒชใƒผใƒณใ‚ทใƒงใƒƒใƒˆใ€ๅผ•็”จใงๅ…ทไฝ“็š„ใซๆคœ่จผใ™ใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::ReleaseReceipts) => {
                "้‡่ฆใชไธปๅผตใจใƒชใƒชใƒผใ‚น่จผๆ‹ ใซใฏใ€ใƒ•ใ‚กใ‚คใƒซใ€ใ‚ณใƒžใƒณใƒ‰ใ€ใ‚นใ‚ฏใƒชใƒผใƒณใ‚ทใƒงใƒƒใƒˆใ€CIใ€ๅ‡บๅ…ธใ‚’็คบใ™ใ€‚"
            }
            (Locale::ZhHans, Self::Assumptions) => "ๅœจๅฎฃ็งฐๅฎŒๆˆๅ‰ๆ€ป็ป“ๅ‡่ฎพใ€ๆœช็Ÿฅๅ’Œๅ‰ฉไฝ™้ฃŽ้™ฉใ€‚",
            (Locale::ZhHans, Self::TestsAndReceipts) => {
                "ๅœจ่ƒฝ้™ไฝŽไธ็กฎๅฎšๆ€งๆ—ถ๏ผŒ็”จๅ‘ฝไปคใ€ๆต‹่ฏ•ใ€ๆˆชๅ›พๆˆ–ๅผ•็”จ็ป™ๅ‡บๅ…ทไฝ“้ชŒ่ฏใ€‚"
            }
            (Locale::ZhHans, Self::ReleaseReceipts) => {
                "ๅฏน้‡่ฆ็ป“่ฎบๅ’Œๅ‘ๅธƒ่ฏๆฎๆ ‡ๆณจๆ–‡ไปถใ€ๅ‘ฝไปคใ€ๆˆชๅ›พใ€CI ๆˆ–ๆฅๆบใ€‚"
            }
            (Locale::ZhHant, Self::Assumptions) => "ๅœจๅฎฃ็จฑๅฎŒๆˆๅ‰็ธฝ็ตๅ‡่จญใ€ๆœช็Ÿฅๅ’Œๅ‰ฉ้ค˜้ขจ้šชใ€‚",
            (Locale::ZhHant, Self::TestsAndReceipts) => {
                "ๅœจ่ƒฝ้™ไฝŽไธ็ขบๅฎšๆ€งๆ™‚๏ผŒ็”จๅ‘ฝไปคใ€ๆธฌ่ฉฆใ€ๆˆชๅœ–ๆˆ–ๅผ•็”จ็ตฆๅ‡บๅ…ท้ซ”้ฉ—่ญ‰ใ€‚"
            }
            (Locale::ZhHant, Self::ReleaseReceipts) => {
                "ๅฐ้‡่ฆ็ต่ซ–ๅ’Œ็™ผๅธƒ่ญ‰ๆ“šๆจ™่จปๆช”ๆกˆใ€ๅ‘ฝไปคใ€ๆˆชๅœ–ใ€CI ๆˆ–ไพ†ๆบใ€‚"
            }
            (Locale::PtBr, Self::Assumptions) => {
                "Resuma premissas, desconhecidos e risco restante antes de dizer que concluiu."
            }
            (Locale::PtBr, Self::TestsAndReceipts) => {
                "Use comandos, testes, screenshots ou citaรงรตes quando reduzirem a incerteza."
            }
            (Locale::PtBr, Self::ReleaseReceipts) => {
                "Cite arquivos, comandos, screenshots, CI ou fontes para afirmaรงรตes materiais e evidรชncia de release."
            }
            (Locale::Es419, Self::Assumptions) => {
                "Resume supuestos, incรณgnitas y riesgo restante antes de afirmar que terminaste."
            }
            (Locale::Es419, Self::TestsAndReceipts) => {
                "Usa comandos, pruebas, capturas o citas cuando reduzcan materialmente la incertidumbre."
            }
            (Locale::Es419, Self::ReleaseReceipts) => {
                "Cita archivos, comandos, capturas, CI o fuentes para afirmaciones materiales y evidencia de release."
            }
            (Locale::Vi, Self::Assumptions) => {
                "Tรณm tแบฏt giแบฃ ฤ‘แป‹nh, ฤ‘iแปu chฦฐa biแบฟt vร  rแปงi ro cรฒn lแบกi trฦฐแป›c khi tuyรชn bแป‘ hoร n tแบฅt."
            }
            (Locale::Vi, Self::TestsAndReceipts) => {
                "Dรนng lแป‡nh, kiแปƒm thแปญ, แบฃnh chแปฅp hoแบทc trรญch dแบซn khi chรบng giแบฃm ฤ‘รกng kแปƒ bแบฅt ฤ‘แป‹nh."
            }
            (Locale::Vi, Self::ReleaseReceipts) => {
                "Trรญch dแบซn tแป‡p, lแป‡nh, แบฃnh chแปฅp, CI hoแบทc nguแป“n cho tuyรชn bแป‘ quan trแปng vร  bแบฑng chแปฉng phรกt hร nh."
            }
            (Locale::Ko, Self::Assumptions) => {
                "์™„๋ฃŒ๋ฅผ ์ฃผ์žฅํ•˜๊ธฐ ์ „์— ๊ฐ€์ •, ๋ถˆํ™•์‹คํ•œ ์ , ๋‚จ์€ ์œ„ํ—˜์„ ์š”์•ฝํ•œ๋‹ค."
            }
            (Locale::Ko, Self::TestsAndReceipts) => {
                "๋ถˆํ™•์‹ค์„ฑ์„ ์‹ค์งˆ์ ์œผ๋กœ ์ค„์ผ ์ˆ˜ ์žˆ์„ ๋•Œ๋Š” ๋ช…๋ น์–ด, ํ…Œ์ŠคํŠธ, ์Šคํฌ๋ฆฐ์ƒท, ์ธ์šฉ์œผ๋กœ ๊ตฌ์ฒด์ ์œผ๋กœ ๊ฒ€์ฆํ•œ๋‹ค."
            }
            (Locale::Ko, Self::ReleaseReceipts) => {
                "์ค‘์š”ํ•œ ์ฃผ์žฅ๊ณผ ๋ฆด๋ฆฌ์Šค ๊ทผ๊ฑฐ์—๋Š” ํŒŒ์ผ ๊ฒฝ๋กœ, ๋ช…๋ น์–ด, ์Šคํฌ๋ฆฐ์ƒท, CI, ์ถœ์ฒ˜๋ฅผ ์ œ์‹œํ•œ๋‹ค."
            }
            (Locale::Ca, Self::Assumptions) => {
                "Resumeix supรฒsits, incรฒgnites i risc pendent abans de dir que has acabat."
            }
            (Locale::Ca, Self::TestsAndReceipts) => {
                "Fes servir ordres, tests, captures de pantalla o citacions quan redueixin materialment la incertesa."
            }
            (Locale::Ca, Self::ReleaseReceipts) => {
                "Cita rutes de fitxers, ordres, captures de pantalla, CI o fonts per a afirmacions materials i evidรจncia de release."
            }
            (Locale::De, Self::Assumptions) => {
                "Fasse Annahmen, Unbekannte und Restrisiken zusammen, bevor du Fertigstellung behauptest."
            }
            (Locale::De, Self::TestsAndReceipts) => {
                "Nutze Befehle, Tests, Screenshots oder Zitate, wenn sie die Unsicherheit wesentlich verringern."
            }
            (Locale::De, Self::ReleaseReceipts) => {
                "Nenne Dateipfade, Befehle, Screenshots, CI oder Quellen fรผr wesentliche Aussagen und Release-Nachweise."
            }
            (Locale::Fr, Self::Assumptions) => {
                "Rรฉsumez les hypothรจses, les inconnues et le risque restant avant d'annoncer la fin du travail."
            }
            (Locale::Fr, Self::TestsAndReceipts) => {
                "Utilisez commandes, tests, captures d'รฉcran ou citations quand ils rรฉduisent sensiblement l'incertitude."
            }
            (Locale::Fr, Self::ReleaseReceipts) => {
                "Citez chemins de fichiers, commandes, captures d'รฉcran, CI ou sources pour les affirmations importantes et les preuves de release."
            }
            (Locale::Id, Self::Assumptions) => {
                "Ringkas asumsi, hal yang belum diketahui, dan risiko tersisa sebelum mengklaim selesai."
            }
            (Locale::Id, Self::TestsAndReceipts) => {
                "Gunakan perintah, tes, tangkapan layar, atau kutipan bila secara nyata mengurangi ketidakpastian."
            }
            (Locale::Id, Self::ReleaseReceipts) => {
                "Kutip path file, perintah, tangkapan layar, CI, atau sumber untuk klaim material dan bukti rilis."
            }
            (Locale::Hi, Self::Assumptions) => {
                "เคชเฅ‚เคฐเฅเคฃเคคเคพ เค•เคพ เคฆเคพเคตเคพ เค•เคฐเคจเฅ‡ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคงเคพเคฐเคฃเคพเคเค, เค…เคœเฅเคžเคพเคค เคฌเคพเคคเฅ‡เค‚ เค”เคฐ เคถเฅ‡เคท เคœเฅ‹เค–เคฟเคฎ เคธเคพเคฐเคพเค‚เคถเคฟเคค เค•เคฐเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::TestsAndReceipts) => {
                "เคœเคฌ เคตเฅ‡ เค…เคจเคฟเคถเฅเคšเคฟเคคเคคเคพ เคธเคพเคฐเฅเคฅเค• เคฐเฅ‚เคช เคธเฅ‡ เค˜เคŸเคพเคเค เคคเฅ‹ เค•เคฎเคพเค‚เคก, เคŸเฅ‡เคธเฅเคŸ, เคธเฅเค•เฅเคฐเฅ€เคจเคถเฅ‰เคŸ เคฏเคพ เค‰เคฆเฅเคงเคฐเคฃ เค‰เคชเคฏเฅ‹เค— เค•เคฐเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::ReleaseReceipts) => {
                "เคฎเคนเคคเฅเคตเคชเฅ‚เคฐเฅเคฃ เคฆเคพเคตเฅ‹เค‚ เค”เคฐ เคฐเคฟเคฒเฅ€เคœเคผ เคธเคพเค•เฅเคทเฅเคฏ เค•เฅ‡ เคฒเคฟเค เคซเคผเคพเค‡เคฒ เคชเคฅ, เค•เคฎเคพเค‚เคก, เคธเฅเค•เฅเคฐเฅ€เคจเคถเฅ‰เคŸ, CI เคฏเคพ เคธเฅเคฐเฅ‹เคค เค‰เคฆเฅเคงเฅƒเคค เค•เคฐเฅ‡เค‚เฅค"
            }
            (Locale::Ru, Self::Assumptions) => {
                "ะŸั€ะตะถะดะต ั‡ะตะผ ะทะฐัะฒะธั‚ัŒ ะพ ะทะฐะฒะตั€ัˆะตะฝะธะธ, ะฟะตั€ะตั‡ะธัะปะธั‚ะต ะฟั€ะตะดะฟะพะปะพะถะตะฝะธั, ะฝะตะธะทะฒะตัั‚ะฝั‹ะต ะธ ะพัั‚ะฐะฒัˆะธะตัั ั€ะธัะบะธ."
            }
            (Locale::Ru, Self::TestsAndReceipts) => {
                "ะ˜ัะฟะพะปัŒะทัƒะนั‚ะต ะบะพะผะฐะฝะดั‹, ั‚ะตัั‚ั‹, ัะบั€ะธะฝัˆะพั‚ั‹ ะธะปะธ ั†ะธั‚ะฐั‚ั‹, ะบะพะณะดะฐ ะพะฝะธ ััƒั‰ะตัั‚ะฒะตะฝะฝะพ ัะฝะธะถะฐัŽั‚ ะฝะตะพะฟั€ะตะดะตะปั‘ะฝะฝะพัั‚ัŒ."
            }
            (Locale::Ru, Self::ReleaseReceipts) => {
                "ะฃะบะฐะทั‹ะฒะฐะนั‚ะต ะฟัƒั‚ะธ ั„ะฐะนะปะพะฒ, ะบะพะผะฐะฝะดั‹, ัะบั€ะธะฝัˆะพั‚ั‹, CI ะธะปะธ ะธัั‚ะพั‡ะฝะธะบะธ ะดะปั ััƒั‰ะตัั‚ะฒะตะฝะฝั‹ั… ัƒั‚ะฒะตั€ะถะดะตะฝะธะน ะธ ะดะพะบะฐะทะฐั‚ะตะปัŒัั‚ะฒ ั€ะตะปะธะทะฐ."
            }
            (Locale::Uk, Self::Assumptions) => {
                "ะŸะตั€ัˆ ะฝั–ะถ ะทะฐัะฒะธั‚ะธ ะฟั€ะพ ะทะฐะฒะตั€ัˆะตะฝะฝั, ะฟั–ะดััƒะผัƒะนั‚ะต ะฟั€ะธะฟัƒั‰ะตะฝะฝั, ะฝะตะฒั–ะดะพะผั– ั‚ะฐ ะทะฐะปะธัˆะบะพะฒั– ั€ะธะทะธะบะธ."
            }
            (Locale::Uk, Self::TestsAndReceipts) => {
                "ะ’ะธะบะพั€ะธัั‚ะพะฒัƒะนั‚ะต ะบะพะผะฐะฝะดะธ, ั‚ะตัั‚ะธ, ัะบั€ะธะฝัˆะพั‚ะธ ะฐะฑะพ ั†ะธั‚ะฐั‚ะธ, ะบะพะปะธ ะฒะพะฝะธ ััƒั‚ั‚ั”ะฒะพ ะทะผะตะฝัˆัƒัŽั‚ัŒ ะฝะตะฒะธะทะฝะฐั‡ะตะฝั–ัั‚ัŒ."
            }
            (Locale::Uk, Self::ReleaseReceipts) => {
                "ะŸะพัะธะปะฐะนั‚ะตัั ะฝะฐ ัˆะปัั…ะธ ั„ะฐะนะปั–ะฒ, ะบะพะผะฐะฝะดะธ, ัะบั€ะธะฝัˆะพั‚ะธ, CI ะฐะฑะพ ะดะถะตั€ะตะปะฐ ะดะปั ััƒั‚ั‚ั”ะฒะธั… ั‚ะฒะตั€ะดะถะตะฝัŒ ั– ะดะพะบะฐะทั–ะฒ ั€ะตะปั–ะทัƒ."
            }
            (_, Self::Assumptions) => {
                "Summarize assumptions, unknowns, and remaining risk before claiming completion."
            }
            (_, Self::TestsAndReceipts) => {
                "Use commands, tests, screenshots, or citations when they materially reduce uncertainty."
            }
            (_, Self::ReleaseReceipts) => {
                "Cite file paths, commands, screenshots, CI, or sources for material claims and release evidence."
            }
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum GuidedCommunication {
    Concise,
    Teaching,
    Direct,
}

impl GuidedCommunication {
    fn next(self) -> Self {
        match self {
            Self::Concise => Self::Teaching,
            Self::Teaching => Self::Direct,
            Self::Direct => Self::Concise,
        }
    }

    fn label(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::Concise) => "็ฐกๆฝ”",
            (Locale::Ja, Self::Teaching) => "่ชฌๆ˜Ž้‡่ฆ–",
            (Locale::Ja, Self::Direct) => "็›ดๆŽฅ็š„",
            (Locale::ZhHans, Self::Concise) => "็ฎ€ๆด",
            (Locale::ZhHans, Self::Teaching) => "ๆ•™ๅญฆๅผ",
            (Locale::ZhHans, Self::Direct) => "็›ดๆŽฅ",
            (Locale::ZhHant, Self::Concise) => "็ฐกๆฝ”",
            (Locale::ZhHant, Self::Teaching) => "ๆ•™ๅญธๅผ",
            (Locale::ZhHant, Self::Direct) => "็›ดๆŽฅ",
            (Locale::PtBr, Self::Concise) => "conciso",
            (Locale::PtBr, Self::Teaching) => "didรกtico",
            (Locale::PtBr, Self::Direct) => "direto",
            (Locale::Es419, Self::Concise) => "conciso",
            (Locale::Es419, Self::Teaching) => "didรกctico",
            (Locale::Es419, Self::Direct) => "directo",
            (Locale::Vi, Self::Concise) => "ngแบฏn gแปn",
            (Locale::Vi, Self::Teaching) => "giแบฃng giแบฃi",
            (Locale::Vi, Self::Direct) => "trแปฑc tiแบฟp",
            (Locale::Ko, Self::Concise) => "๊ฐ„๊ฒฐํ•จ",
            (Locale::Ko, Self::Teaching) => "์„ค๋ช… ์ค‘์‹ฌ",
            (Locale::Ko, Self::Direct) => "์ง์„ค์ ",
            (Locale::Ca, Self::Concise) => "concรญs",
            (Locale::Ca, Self::Teaching) => "didร ctic",
            (Locale::Ca, Self::Direct) => "directe",
            (Locale::De, Self::Concise) => "prรคgnant",
            (Locale::De, Self::Teaching) => "lehrend",
            (Locale::De, Self::Direct) => "direkt",
            (Locale::Fr, Self::Concise) => "concis",
            (Locale::Fr, Self::Teaching) => "pรฉdagogique",
            (Locale::Fr, Self::Direct) => "direct",
            (Locale::Id, Self::Concise) => "ringkas",
            (Locale::Id, Self::Teaching) => "mengajar",
            (Locale::Id, Self::Direct) => "langsung",
            (Locale::Hi, Self::Concise) => "เคธเค‚เค•เฅเคทเคฟเคชเฅเคค",
            (Locale::Hi, Self::Teaching) => "เคถเคฟเค•เฅเคทเคฃเคชเคฐเค•",
            (Locale::Hi, Self::Direct) => "เคธเฅ€เคงเคพ",
            (Locale::Ru, Self::Concise) => "ะบั€ะฐั‚ะบะธะน",
            (Locale::Ru, Self::Teaching) => "ะพะฑัƒั‡ะฐัŽั‰ะธะน",
            (Locale::Ru, Self::Direct) => "ะฟั€ัะผะพะน",
            (Locale::Uk, Self::Concise) => "ัั‚ะธัะปะธะน",
            (Locale::Uk, Self::Teaching) => "ะฝะฐะฒั‡ะฐะปัŒะฝะธะน",
            (Locale::Uk, Self::Direct) => "ะฟั€ัะผะธะน",
            (_, Self::Concise) => "concise",
            (_, Self::Teaching) => "teaching",
            (_, Self::Direct) => "direct",
        }
    }

    fn working_style(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::Concise) => "ๆ›ดๆ–ฐใฏ็ฐกๆฝ”ใซใ—ใ€้‡่ฆใชใƒˆใƒฌใƒผใƒ‰ใ‚ชใƒ•ใ ใ‘็Ÿญใ่ชฌๆ˜Žใ™ใ‚‹ใ€‚",
            (Locale::Ja, Self::Teaching) => {
                "้‡่ฆใชๆŽจ่ซ–ใจใƒˆใƒฌใƒผใƒ‰ใ‚ชใƒ•ใ‚’ใ€ใƒฆใƒผใ‚ถใƒผใŒไป•็ต„ใฟใ‚’็†่งฃใงใใ‚‹็จ‹ๅบฆใซ่ชฌๆ˜Žใ™ใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::Direct) => {
                "้˜ปๅกžใ€ใƒชใ‚นใ‚ฏใ€ไธ็ขบๅฎŸๆ€งใ‚’็›ดๆŽฅ่ฟฐในใ€่ฃ…้ฃพ็š„ใชๆ–‡ๆกˆใ‚’้ฟใ‘ใ‚‹ใ€‚"
            }
            (Locale::ZhHans, Self::Concise) => "ไฟๆŒๆ›ดๆ–ฐ็ฎ€ๆด๏ผŒๅนถๅช่งฃ้‡Š้‡่ฆๅ–่ˆใ€‚",
            (Locale::ZhHans, Self::Teaching) => "่งฃ้‡Šๅ…ณ้”ฎๆŽจ็†ๅ’Œๅ–่ˆ๏ผŒ่ฎฉ็”จๆˆท่ƒฝ็†่งฃ็ณป็ปŸใ€‚",
            (Locale::ZhHans, Self::Direct) => "็›ดๆŽฅ่ฏดๆ˜Ž้˜ปๅกžใ€้ฃŽ้™ฉๅ’Œไธ็กฎๅฎšๆ€ง๏ผŒ้ฟๅ…่ฃ…้ฅฐๆ€งๆ–‡ๆกˆใ€‚",
            (Locale::ZhHant, Self::Concise) => "ไฟๆŒๆ›ดๆ–ฐ็ฐกๆฝ”๏ผŒไธฆๅช่งฃ้‡‹้‡่ฆๅ–ๆจใ€‚",
            (Locale::ZhHant, Self::Teaching) => "่งฃ้‡‹้—œ้ตๆŽจ็†ๅ’Œๅ–ๆจ๏ผŒ่ฎ“ไฝฟ็”จ่€…่ƒฝ็†่งฃ็ณป็ตฑใ€‚",
            (Locale::ZhHant, Self::Direct) => "็›ดๆŽฅ่ชชๆ˜Ž้˜ปๅกžใ€้ขจ้šชๅ’Œไธ็ขบๅฎšๆ€ง๏ผŒ้ฟๅ…่ฃ้ฃพๆ€งๆ–‡ๆกˆใ€‚",
            (Locale::PtBr, Self::Concise) => {
                "Mantenha atualizaรงรตes concisas e explique brevemente sรณ os tradeoffs importantes."
            }
            (Locale::PtBr, Self::Teaching) => {
                "Explique raciocรญnio e tradeoffs principais o bastante para o usuรกrio entender o sistema."
            }
            (Locale::PtBr, Self::Direct) => {
                "Seja direto sobre bloqueios, risco e incerteza; evite texto ornamental."
            }
            (Locale::Es419, Self::Concise) => {
                "Mantรฉn las actualizaciones concisas y explica brevemente solo los tradeoffs importantes."
            }
            (Locale::Es419, Self::Teaching) => {
                "Explica el razonamiento y los tradeoffs clave lo suficiente para que el usuario entienda el sistema."
            }
            (Locale::Es419, Self::Direct) => {
                "Sรฉ directo sobre bloqueos, riesgo e incertidumbre; evita texto ornamental."
            }
            (Locale::Vi, Self::Concise) => {
                "Giแปฏ cแบญp nhแบญt ngแบฏn gแปn vร  chแป‰ giแบฃi thรญch ngแบฏn cรกc ฤ‘รกnh ฤ‘แป•i quan trแปng."
            }
            (Locale::Vi, Self::Teaching) => {
                "Giแบฃi thรญch suy luแบญn vร  ฤ‘รกnh ฤ‘แป•i chรญnh ฤ‘แปง ฤ‘แปƒ ngฦฐแปi dรนng hiแปƒu hแป‡ thแป‘ng."
            }
            (Locale::Vi, Self::Direct) => {
                "Nรณi thแบณng vแป ฤ‘iแปƒm chแบทn, rแปงi ro vร  bแบฅt ฤ‘แป‹nh; trรกnh cรขu chแปฏ trang trรญ."
            }
            (Locale::Ko, Self::Concise) => {
                "์—…๋ฐ์ดํŠธ๋Š” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์œ ์ง€ํ•˜๊ณ , ์ค‘์š”ํ•œ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋งŒ ์งง๊ฒŒ ์„ค๋ช…ํ•œ๋‹ค."
            }
            (Locale::Ko, Self::Teaching) => {
                "์‚ฌ์šฉ์ž๊ฐ€ ์‹œ์Šคํ…œ์„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์„ ๋งŒํผ ํ•ต์‹ฌ ์ถ”๋ก ๊ณผ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋ฅผ ์„ค๋ช…ํ•œ๋‹ค."
            }
            (Locale::Ko, Self::Direct) => {
                "์ฐจ๋‹จ ์š”์ธ, ์œ„ํ—˜, ๋ถˆํ™•์‹ค์„ฑ์„ ์ง์„ค์ ์œผ๋กœ ๋งํ•˜๊ณ  ์žฅ์‹์ ์ธ ํ‘œํ˜„์€ ํ”ผํ•œ๋‹ค."
            }
            (Locale::Ca, Self::Concise) => {
                "Mantรฉn les actualitzacions concises i explica breument nomรฉs els compromisos importants."
            }
            (Locale::Ca, Self::Teaching) => {
                "Explica el raonament i els compromisos clau prou perquรจ l'usuari pugui entendre el sistema."
            }
            (Locale::Ca, Self::Direct) => {
                "Sigues directe sobre bloquejos, risc i incertesa; evita el text ornamental."
            }
            (Locale::De, Self::Concise) => {
                "Halte Aktualisierungen knapp und erklรคre wichtige Trade-offs nur kurz."
            }
            (Locale::De, Self::Teaching) => {
                "Erklรคre zentrale Begrรผndungen und Trade-offs so weit, dass der Nutzer das System verstehen kann."
            }
            (Locale::De, Self::Direct) => {
                "Sei direkt bei Blockern, Risiken und Unsicherheit; vermeide dekorative Formulierungen."
            }
            (Locale::Fr, Self::Concise) => {
                "Gardez les mises ร  jour concises et n'expliquez que briรจvement les arbitrages importants."
            }
            (Locale::Fr, Self::Teaching) => {
                "Expliquez le raisonnement et les arbitrages clรฉs assez pour que l'utilisateur comprenne le systรจme."
            }
            (Locale::Fr, Self::Direct) => {
                "Soyez direct sur les blocages, les risques et l'incertitude ; รฉvitez le texte ornemental."
            }
            (Locale::Id, Self::Concise) => {
                "Jaga pembaruan tetap ringkas dan jelaskan tradeoff penting secara singkat."
            }
            (Locale::Id, Self::Teaching) => {
                "Jelaskan penalaran dan tradeoff kunci secukupnya agar pengguna dapat memahami sistem."
            }
            (Locale::Id, Self::Direct) => {
                "Bicara langsung soal penghambat, risiko, dan ketidakpastian; hindari teks hiasan."
            }
            (Locale::Hi, Self::Concise) => "เค…เคชเคกเฅ‡เคŸ เคธเค‚เค•เฅเคทเคฟเคชเฅเคค เคฐเค–เฅ‡เค‚ เค”เคฐ เคฎเคนเคคเฅเคตเคชเฅ‚เคฐเฅเคฃ เคŸเฅเคฐเฅ‡เคกเค‘เคซเคผ เคธเค‚เค•เฅเคทเฅ‡เคช เคฎเฅ‡เค‚ เคธเคฎเคเคพเคเคเฅค",
            (Locale::Hi, Self::Teaching) => {
                "เคฎเฅเค–เฅเคฏ เคคเคฐเฅเค• เค”เคฐ เคŸเฅเคฐเฅ‡เคกเค‘เคซเคผ เค‡เคคเคจเคพ เคธเคฎเคเคพเคเค เค•เคฟ เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เคธเคฟเคธเฅเคŸเคฎ เคธเคฎเค เคธเค•เฅ‡เฅค"
            }
            (Locale::Hi, Self::Direct) => {
                "เคฐเฅเค•เคพเคตเคŸเฅ‹เค‚, เคœเฅ‹เค–เคฟเคฎ เค”เคฐ เค…เคจเคฟเคถเฅเคšเคฟเคคเคคเคพ เค•เฅ‡ เคฌเคพเคฐเฅ‡ เคฎเฅ‡เค‚ เคธเฅ€เคงเฅ‡ เคฌเฅ‹เคฒเฅ‡เค‚; เคธเคœเคพเคตเคŸเฅ€ เคญเคพเคทเคพ เคธเฅ‡ เคฌเคšเฅ‡เค‚เฅค"
            }
            (Locale::Ru, Self::Concise) => {
                "ะ”ะตั€ะถะธั‚ะต ะพะฑะฝะพะฒะปะตะฝะธั ะบั€ะฐั‚ะบะธะผะธ ะธ ะปะธัˆัŒ ะบะพั€ะพั‚ะบะพ ะฟะพััะฝัะนั‚ะต ะฒะฐะถะฝั‹ะต ะบะพะผะฟั€ะพะผะธััั‹."
            }
            (Locale::Ru, Self::Teaching) => {
                "ะžะฑัŠััะฝัะนั‚ะต ะบะปัŽั‡ะตะฒั‹ะต ั€ะฐัััƒะถะดะตะฝะธั ะธ ะบะพะผะฟั€ะพะผะธััั‹ ะฝะฐัั‚ะพะปัŒะบะพ, ั‡ั‚ะพะฑั‹ ะฟะพะปัŒะทะพะฒะฐั‚ะตะปัŒ ะผะพะณ ะฟะพะฝัั‚ัŒ ัะธัั‚ะตะผัƒ."
            }
            (Locale::Ru, Self::Direct) => {
                "ะ“ะพะฒะพั€ะธั‚ะต ะฟั€ัะผะพ ะพ ะฑะปะพะบะตั€ะฐั…, ั€ะธัะบะฐั… ะธ ะฝะตะพะฟั€ะตะดะตะปั‘ะฝะฝะพัั‚ะธ; ะธะทะฑะตะณะฐะนั‚ะต ะดะตะบะพั€ะฐั‚ะธะฒะฝั‹ั… ั„ะพั€ะผัƒะปะธั€ะพะฒะพะบ."
            }
            (Locale::Uk, Self::Concise) => {
                "ะขั€ะธะผะฐะนั‚ะต ะพะฝะพะฒะปะตะฝะฝั ัั‚ะธัะปะธะผะธ ะน ะปะธัˆะต ะบะพั€ะพั‚ะบะพ ะฟะพััะฝัŽะนั‚ะต ะฒะฐะถะปะธะฒั– ะบะพะผะฟั€ะพะผั–ัะธ."
            }
            (Locale::Uk, Self::Teaching) => {
                "ะŸะพััะฝัŽะนั‚ะต ะบะปัŽั‡ะพะฒั– ะผั–ั€ะบัƒะฒะฐะฝะฝั ั‚ะฐ ะบะพะผะฟั€ะพะผั–ัะธ ะฝะฐัั‚ั–ะปัŒะบะธ, ั‰ะพะฑ ะบะพั€ะธัั‚ัƒะฒะฐั‡ ะผั–ะณ ะทั€ะพะทัƒะผั–ั‚ะธ ัะธัั‚ะตะผัƒ."
            }
            (Locale::Uk, Self::Direct) => {
                "ะ“ะพะฒะพั€ั–ั‚ัŒ ะฟั€ัะผะพ ะฟั€ะพ ะฑะปะพะบะตั€ะธ, ั€ะธะทะธะบะธ ั‚ะฐ ะฝะตะฒะธะทะฝะฐั‡ะตะฝั–ัั‚ัŒ; ัƒะฝะธะบะฐะนั‚ะต ะดะตะบะพั€ะฐั‚ะธะฒะฝะธั… ั„ะพั€ะผัƒะปัŽะฒะฐะฝัŒ."
            }
            (_, Self::Concise) => "Keep updates concise and explain important tradeoffs briefly.",
            (_, Self::Teaching) => {
                "Explain key reasoning and tradeoffs enough that the user can learn the system."
            }
            (_, Self::Direct) => {
                "Be direct about blockers, risk, and uncertainty; avoid ornamental copy."
            }
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum GuidedPrivacy {
    StandardCare,
    StrictBoundaries,
    ProjectLocal,
}

impl GuidedPrivacy {
    fn next(self) -> Self {
        match self {
            Self::StandardCare => Self::StrictBoundaries,
            Self::StrictBoundaries => Self::ProjectLocal,
            Self::ProjectLocal => Self::StandardCare,
        }
    }

    fn label(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::StandardCare) => "ๆจ™ๆบ–ไฟ่ญท",
            (Locale::Ja, Self::StrictBoundaries) => "ๅŽณๆ ผใชๅขƒ็•Œ",
            (Locale::Ja, Self::ProjectLocal) => "ใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆๅ†…ใƒกใƒขใƒช",
            (Locale::ZhHans, Self::StandardCare) => "ๆ ‡ๅ‡†ไฟๆŠค",
            (Locale::ZhHans, Self::StrictBoundaries) => "ไธฅๆ ผ่พน็•Œ",
            (Locale::ZhHans, Self::ProjectLocal) => "้กน็›ฎๅ†…่ฎฐๅฟ†",
            (Locale::ZhHant, Self::StandardCare) => "ๆจ™ๆบ–ไฟ่ญท",
            (Locale::ZhHant, Self::StrictBoundaries) => "ๅšดๆ ผ้‚Š็•Œ",
            (Locale::ZhHant, Self::ProjectLocal) => "ๅฐˆๆกˆๅ…ง่จ˜ๆ†ถ",
            (Locale::PtBr, Self::StandardCare) => "cuidado padrรฃo",
            (Locale::PtBr, Self::StrictBoundaries) => "limites estritos",
            (Locale::PtBr, Self::ProjectLocal) => "memรณria local do projeto",
            (Locale::Es419, Self::StandardCare) => "cuidado estรกndar",
            (Locale::Es419, Self::StrictBoundaries) => "lรญmites estrictos",
            (Locale::Es419, Self::ProjectLocal) => "memoria local del proyecto",
            (Locale::Vi, Self::StandardCare) => "bแบฃo vแป‡ tiรชu chuแบฉn",
            (Locale::Vi, Self::StrictBoundaries) => "ranh giแป›i nghiรชm ngแบทt",
            (Locale::Vi, Self::ProjectLocal) => "bแป™ nhแป› trong dแปฑ รกn",
            (Locale::Ko, Self::StandardCare) => "ํ‘œ์ค€ ๋ณดํ˜ธ",
            (Locale::Ko, Self::StrictBoundaries) => "์—„๊ฒฉํ•œ ๊ฒฝ๊ณ„",
            (Locale::Ko, Self::ProjectLocal) => "ํ”„๋กœ์ ํŠธ ๋‚ด ๋ฉ”๋ชจ๋ฆฌ",
            (Locale::Ca, Self::StandardCare) => "cura estร ndard",
            (Locale::Ca, Self::StrictBoundaries) => "lรญmits estrictes",
            (Locale::Ca, Self::ProjectLocal) => "memรฒria local del projecte",
            (Locale::De, Self::StandardCare) => "Standardvorsorge",
            (Locale::De, Self::StrictBoundaries) => "strenge Grenzen",
            (Locale::De, Self::ProjectLocal) => "projektlokaler Speicher",
            (Locale::Fr, Self::StandardCare) => "soin standard",
            (Locale::Fr, Self::StrictBoundaries) => "limites strictes",
            (Locale::Fr, Self::ProjectLocal) => "mรฉmoire locale au projet",
            (Locale::Id, Self::StandardCare) => "perlindungan standar",
            (Locale::Id, Self::StrictBoundaries) => "batasan ketat",
            (Locale::Id, Self::ProjectLocal) => "memori lokal proyek",
            (Locale::Hi, Self::StandardCare) => "เคฎเคพเคจเค• เคธเคพเคตเคงเคพเคจเฅ€",
            (Locale::Hi, Self::StrictBoundaries) => "เคธเค–เฅเคค เคธเฅ€เคฎเคพเคเค",
            (Locale::Hi, Self::ProjectLocal) => "เคชเฅเคฐเฅ‹เคœเฅ‡เค•เฅเคŸ-เคธเฅเคฅเคพเคจเฅ€เคฏ เคฎเฅ‡เคฎเฅ‹เคฐเฅ€",
            (Locale::Ru, Self::StandardCare) => "ัั‚ะฐะฝะดะฐั€ั‚ะฝะฐั ะพัั‚ะพั€ะพะถะฝะพัั‚ัŒ",
            (Locale::Ru, Self::StrictBoundaries) => "ัั‚ั€ะพะณะธะต ะณั€ะฐะฝะธั†ั‹",
            (Locale::Ru, Self::ProjectLocal) => "ะฟะฐะผัั‚ัŒ ะฒะฝัƒั‚ั€ะธ ะฟั€ะพะตะบั‚ะฐ",
            (Locale::Uk, Self::StandardCare) => "ัั‚ะฐะฝะดะฐั€ั‚ะฝะฐ ะพะฑะตั€ะตะถะฝั–ัั‚ัŒ",
            (Locale::Uk, Self::StrictBoundaries) => "ััƒะฒะพั€ั– ะผะตะถั–",
            (Locale::Uk, Self::ProjectLocal) => "ะฟะฐะผ'ัั‚ัŒ ัƒ ะผะตะถะฐั… ะฟั€ะพั”ะบั‚ัƒ",
            (_, Self::StandardCare) => "standard care",
            (_, Self::StrictBoundaries) => "strict boundaries",
            (_, Self::ProjectLocal) => "project-local memory",
        }
    }

    fn working_style(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::StandardCare) => {
                "็ง˜ๅฏ†ๆƒ…ๅ ฑใ€ใƒฆใƒผใ‚ถใƒผใƒ•ใ‚กใ‚คใƒซใ€Git ๅฑฅๆญดใ€ๆœฌ็•ชใ‚ทใ‚นใƒ†ใƒ ใ€ใ‚ณใ‚นใƒˆใ€ใƒ—ใƒฉใ‚คใƒใ‚ทใƒผใ€ๆ™‚้–“ใ‚’ไฟ่ญทใ™ใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::StrictBoundaries) => {
                "็ง˜ๅฏ†ใ€ๅ€‹ไบบใƒ‡ใƒผใ‚ฟใ€่ช่จผๆƒ…ๅ ฑใ€ๆœฌ็•ช็Šถๆ…‹ใ€่ณ‡้‡‘ใ€ๅ…ฌ้–‹ๆ“ไฝœใฏใ€ๅ…ˆใซ็ขบ่ชใ™ใ‚‹ๅขƒ็•Œใจใ—ใฆๆ‰ฑใ†ใ€‚"
            }
            (Locale::Ja, Self::ProjectLocal) => {
                "ใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆๅ›บๆœ‰ใฎๆ–‡่„ˆใฏใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆๅ†…ใซ็•™ใ‚ใ€ๆ˜Ž็คบ่ฆๆฑ‚ใŒใชใ„้™ใ‚Šใƒกใƒขใƒชใธๆ›ธใ‹ใชใ„ใ€‚"
            }
            (Locale::ZhHans, Self::StandardCare) => {
                "ไฟๆŠคๅฏ†้’ฅใ€็”จๆˆทๆ–‡ไปถใ€Git ๅކๅฒใ€็”Ÿไบง็ณป็ปŸใ€ๆˆๆœฌใ€้š็งๅ’Œๆ—ถ้—ดใ€‚"
            }
            (Locale::ZhHans, Self::StrictBoundaries) => {
                "ๆŠŠๅฏ†้’ฅใ€ไธชไบบๆ•ฐๆฎใ€ๅ‡ญๆฎใ€็”Ÿไบง็Šถๆ€ใ€่ต„้‡‘ๅ’Œๅ‘ๅธƒๅŠจไฝœ่ง†ไธบๅ…ˆ็กฎ่ฎค่พน็•Œใ€‚"
            }
            (Locale::ZhHans, Self::ProjectLocal) => {
                "้กน็›ฎ็‰นๅฎšไธŠไธ‹ๆ–‡็•™ๅœจ้กน็›ฎๅ†…๏ผŒ้™ค้žๆ˜Ž็กฎ่ฆๆฑ‚๏ผŒๅฆๅˆ™ไธ่ฆๅ†™ๅ…ฅ่ฎฐๅฟ†ใ€‚"
            }
            (Locale::ZhHant, Self::StandardCare) => {
                "ไฟ่ญทๅฏ†้‘ฐใ€ไฝฟ็”จ่€…ๆช”ๆกˆใ€Git ๆญทๅฒใ€็”Ÿ็”ข็ณป็ตฑใ€ๆˆๆœฌใ€้šฑ็งๅ’Œๆ™‚้–“ใ€‚"
            }
            (Locale::ZhHant, Self::StrictBoundaries) => {
                "ๆŠŠๅฏ†้‘ฐใ€ๅ€‹ไบบ่ณ‡ๆ–™ใ€ๆ†‘ๆ“šใ€็”Ÿ็”ข็‹€ๆ…‹ใ€่ณ‡้‡‘ๅ’Œ็™ผๅธƒๅ‹•ไฝœ่ฆ–็‚บๅ…ˆ็ขบ่ช้‚Š็•Œใ€‚"
            }
            (Locale::ZhHant, Self::ProjectLocal) => {
                "ๅฐˆๆกˆ็‰นๅฎšไธŠไธ‹ๆ–‡็•™ๅœจๅฐˆๆกˆๅ…ง๏ผŒ้™ค้žๆ˜Ž็ขบ่ฆๆฑ‚๏ผŒๅฆๅ‰‡ไธ่ฆๅฏซๅ…ฅ่จ˜ๆ†ถใ€‚"
            }
            (Locale::PtBr, Self::StandardCare) => {
                "Proteja segredos, arquivos do usuรกrio, histรณrico git, produรงรฃo, custo, privacidade e tempo."
            }
            (Locale::PtBr, Self::StrictBoundaries) => {
                "Trate segredos, dados pessoais, credenciais, estado de produรงรฃo, dinheiro e publicaรงรตes como limites de confirmaรงรฃo."
            }
            (Locale::PtBr, Self::ProjectLocal) => {
                "Mantenha contexto especรญfico do projeto no projeto; evite gravar na memรณria sem pedido explรญcito."
            }
            (Locale::Es419, Self::StandardCare) => {
                "Protege secretos, archivos del usuario, historial git, producciรณn, costo, privacidad y tiempo."
            }
            (Locale::Es419, Self::StrictBoundaries) => {
                "Trata secretos, datos personales, credenciales, estado de producciรณn, dinero y publicaciones como lรญmites de confirmaciรณn."
            }
            (Locale::Es419, Self::ProjectLocal) => {
                "Mantรฉn el contexto especรญfico del proyecto en el proyecto; evita llevarlo a memoria sin pedido explรญcito."
            }
            (Locale::Vi, Self::StandardCare) => {
                "Bแบฃo vแป‡ bรญ mแบญt, tแป‡p ngฦฐแปi dรนng, lแป‹ch sแปญ git, hแป‡ thแป‘ng sแบฃn xuแบฅt, chi phรญ, riรชng tฦฐ vร  thแปi gian."
            }
            (Locale::Vi, Self::StrictBoundaries) => {
                "Xem bรญ mแบญt, dแปฏ liแป‡u cรก nhรขn, thรดng tin xรกc thแปฑc, trแบกng thรกi sแบฃn xuแบฅt, tiแปn vร  xuแบฅt bแบฃn lร  ranh giแป›i cแบงn xรกc nhแบญn."
            }
            (Locale::Vi, Self::ProjectLocal) => {
                "Giแปฏ ngแปฏ cแบฃnh riรชng cแปงa dแปฑ รกn trong dแปฑ รกn; trรกnh ghi vร o bแป™ nhแป› nแบฟu khรดng ฤ‘ฦฐแปฃc yรชu cแบงu rรต."
            }
            (Locale::Ko, Self::StandardCare) => {
                "๋น„๋ฐ€ ์ •๋ณด, ์‚ฌ์šฉ์ž ํŒŒ์ผ, Git ์ด๋ ฅ, ํ”„๋กœ๋•์…˜ ์‹œ์Šคํ…œ, ๋น„์šฉ, ํ”„๋ผ์ด๋ฒ„์‹œ, ์‹œ๊ฐ„์„ ๋ณดํ˜ธํ•œ๋‹ค."
            }
            (Locale::Ko, Self::StrictBoundaries) => {
                "๋น„๋ฐ€ ์ •๋ณด, ๊ฐœ์ธ ๋ฐ์ดํ„ฐ, ์ž๊ฒฉ ์ฆ๋ช…, ํ”„๋กœ๋•์…˜ ์ƒํƒœ, ์ž๊ธˆ, ๊ฒŒ์‹œ ์ž‘์—…์€ ๋จผ์ € ํ™•์ธํ•˜๋Š” ๊ฒฝ๊ณ„๋กœ ์ทจ๊ธ‰ํ•œ๋‹ค."
            }
            (Locale::Ko, Self::ProjectLocal) => {
                "ํ”„๋กœ์ ํŠธ ๊ณ ์œ  ๋งฅ๋ฝ์€ ํ”„๋กœ์ ํŠธ ์•ˆ์— ๋‘๊ณ , ๋ช…์‹œ์ ์œผ๋กœ ์š”์ฒญ๋ฐ›์ง€ ์•Š๋Š” ํ•œ ๋ฉ”๋ชจ๋ฆฌ์— ์“ฐ์ง€ ์•Š๋Š”๋‹ค."
            }
            (Locale::Ca, Self::StandardCare) => {
                "Protegeix secrets, fitxers de l'usuari, historial de git, sistemes de producciรณ, cost, privacitat i temps."
            }
            (Locale::Ca, Self::StrictBoundaries) => {
                "Tracta secrets, dades personals, credencials, estat de producciรณ, diners i accions de publicaciรณ com a lรญmits que cal confirmar primer."
            }
            (Locale::Ca, Self::ProjectLocal) => {
                "Mantรฉn el context especรญfic del projecte dins del projecte; evita portar-lo a la memรฒria si no se't demana explรญcitament."
            }
            (Locale::De, Self::StandardCare) => {
                "Schรผtze Geheimnisse, Nutzerdateien, Git-Verlauf, Produktionssysteme, Kosten, Privatsphรคre und Zeit."
            }
            (Locale::De, Self::StrictBoundaries) => {
                "Behandle Geheimnisse, persรถnliche Daten, Zugangsdaten, Produktionszustand, Geld und Verรถffentlichungen als Grenzen, die erst bestรคtigt werden."
            }
            (Locale::De, Self::ProjectLocal) => {
                "Halte projektspezifischen Kontext im Projekt; vermeide es, sensible Details ohne ausdrรผckliche Bitte in den Speicher zu รผbernehmen."
            }
            (Locale::Fr, Self::StandardCare) => {
                "Protรฉgez secrets, fichiers utilisateur, historique git, systรจmes de production, coรปt, vie privรฉe et temps."
            }
            (Locale::Fr, Self::StrictBoundaries) => {
                "Traitez secrets, donnรฉes personnelles, identifiants, รฉtat de production, argent et publications comme des limites exigeant confirmation."
            }
            (Locale::Fr, Self::ProjectLocal) => {
                "Gardez le contexte propre au projet dans le projet ; รฉvitez de l'รฉcrire en mรฉmoire sans demande explicite."
            }
            (Locale::Id, Self::StandardCare) => {
                "Lindungi rahasia, file pengguna, riwayat git, sistem produksi, biaya, privasi, dan waktu."
            }
            (Locale::Id, Self::StrictBoundaries) => {
                "Perlakukan rahasia, data pribadi, kredensial, status produksi, uang, dan tindakan publikasi sebagai batas yang harus dikonfirmasi dulu."
            }
            (Locale::Id, Self::ProjectLocal) => {
                "Simpan konteks khusus proyek di dalam proyek; hindari membawanya ke memori kecuali diminta secara eksplisit."
            }
            (Locale::Hi, Self::StandardCare) => {
                "เคฐเคนเคธเฅเคฏเฅ‹เค‚, เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เคซเคผเคพเค‡เคฒเฅ‹เค‚, git เค‡เคคเคฟเคนเคพเคธ, เคชเฅเคฐเฅ‹เคกเค•เฅเคถเคจ เคธเคฟเคธเฅเคŸเคฎ, เคฒเคพเค—เคค, เค—เฅ‹เคชเคจเฅ€เคฏเคคเคพ เค”เคฐ เคธเคฎเคฏ เค•เฅ€ เคฐเค•เฅเคทเคพ เค•เคฐเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::StrictBoundaries) => {
                "เคฐเคนเคธเฅเคฏเฅ‹เค‚, เคตเฅเคฏเค•เฅเคคเคฟเค—เคค เคกเฅ‡เคŸเคพ, เค•เฅเคฐเฅ‡เคกเฅ‡เค‚เคถเคฟเคฏเคฒ, เคชเฅเคฐเฅ‹เคกเค•เฅเคถเคจ เคธเฅเคฅเคฟเคคเคฟ, เคงเคจ เค”เคฐ เคชเฅเคฐเค•เคพเคถเคจ เค•เฅเคฐเคฟเคฏเคพเค“เค‚ เค•เฅ‹ เคชเคนเคฒเฅ‡-เคชเฅเคทเฅเคŸเคฟ เคธเฅ€เคฎเคพเค“เค‚ เค•เฅ€ เคคเคฐเคน เคฎเคพเคจเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::ProjectLocal) => {
                "เคชเฅเคฐเฅ‹เคœเฅ‡เค•เฅเคŸ-เคตเคฟเคถเคฟเคทเฅเคŸ เคธเค‚เคฆเคฐเฅเคญ เคชเฅเคฐเฅ‹เคœเฅ‡เค•เฅเคŸ เค•เฅ‡ เคญเฅ€เคคเคฐ เคฐเค–เฅ‡เค‚; เคธเฅเคชเคทเฅเคŸ เค…เคจเฅเคฐเฅ‹เคง เค•เฅ‡ เคฌเคฟเคจเคพ เคธเค‚เคตเฅ‡เคฆเคจเคถเฅ€เคฒ เคตเคฟเคตเคฐเคฃ เคฎเฅ‡เคฎเฅ‹เคฐเฅ€ เคฎเฅ‡เค‚ เคจ เคฒเฅ‡ เคœเคพเคเคเฅค"
            }
            (Locale::Ru, Self::StandardCare) => {
                "ะ—ะฐั‰ะธั‰ะฐะนั‚ะต ัะตะบั€ะตั‚ั‹, ั„ะฐะนะปั‹ ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั, ะธัั‚ะพั€ะธัŽ git, production-ัะธัั‚ะตะผั‹, ะทะฐั‚ั€ะฐั‚ั‹, ะฟั€ะธะฒะฐั‚ะฝะพัั‚ัŒ ะธ ะฒั€ะตะผั."
            }
            (Locale::Ru, Self::StrictBoundaries) => {
                "ะกั‡ะธั‚ะฐะนั‚ะต ัะตะบั€ะตั‚ั‹, ะฟะตั€ัะพะฝะฐะปัŒะฝั‹ะต ะดะฐะฝะฝั‹ะต, ัƒั‡ั‘ั‚ะฝั‹ะต ะดะฐะฝะฝั‹ะต, production-ัะพัั‚ะพัะฝะธะต, ะดะตะฝัŒะณะธ ะธ ะฟัƒะฑะปะธะบะฐั†ะธะธ ะณั€ะฐะฝะธั†ะฐะผะธ, ั‚ั€ะตะฑัƒัŽั‰ะธะผะธ ะฟะพะดั‚ะฒะตั€ะถะดะตะฝะธั."
            }
            (Locale::Ru, Self::ProjectLocal) => {
                "ะ”ะตั€ะถะธั‚ะต ะบะพะฝั‚ะตะบัั‚, ัะฟะตั†ะธั„ะธั‡ะฝั‹ะน ะดะปั ะฟั€ะพะตะบั‚ะฐ, ะฒะฝัƒั‚ั€ะธ ะฟั€ะพะตะบั‚ะฐ; ะฝะต ะฟะตั€ะตะฝะพัะธั‚ะต ั‡ัƒะฒัั‚ะฒะธั‚ะตะปัŒะฝั‹ะต ะดะตั‚ะฐะปะธ ะฒ ะฟะฐะผัั‚ัŒ ะฑะตะท ัะฒะฝะพะณะพ ะทะฐะฟั€ะพัะฐ."
            }
            (Locale::Uk, Self::StandardCare) => {
                "ะ—ะฐั…ะธั‰ะฐะนั‚ะต ัะตะบั€ะตั‚ะธ, ั„ะฐะนะปะธ ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ, ั–ัั‚ะพั€ั–ัŽ git, production-ัะธัั‚ะตะผะธ, ะฒะธั‚ั€ะฐั‚ะธ, ะฟั€ะธะฒะฐั‚ะฝั–ัั‚ัŒ ั– ั‡ะฐั."
            }
            (Locale::Uk, Self::StrictBoundaries) => {
                "ะ’ะฒะฐะถะฐะนั‚ะต ัะตะบั€ะตั‚ะธ, ะฟะตั€ัะพะฝะฐะปัŒะฝั– ะดะฐะฝั–, ะพะฑะปั–ะบะพะฒั– ะดะฐะฝั–, production-ัั‚ะฐะฝ, ะณั€ะพัˆั– ั‚ะฐ ะฟัƒะฑะปั–ะบะฐั†ั–ั— ะผะตะถะฐะผะธ, ั‰ะพ ะฟะพั‚ั€ะตะฑัƒัŽั‚ัŒ ะฟั–ะดั‚ะฒะตั€ะดะถะตะฝะฝั."
            }
            (Locale::Uk, Self::ProjectLocal) => {
                "ะขั€ะธะผะฐะนั‚ะต ะบะพะฝั‚ะตะบัั‚, ัะฟะตั†ะธั„ั–ั‡ะฝะธะน ะดะปั ะฟั€ะพั”ะบั‚ัƒ, ะฒัะตั€ะตะดะธะฝั– ะฟั€ะพั”ะบั‚ัƒ; ะฝะต ะฟะตั€ะตะฝะพััŒั‚ะต ั‡ัƒั‚ะปะธะฒั– ะดะตั‚ะฐะปั– ะฒ ะฟะฐะผ'ัั‚ัŒ ะฑะตะท ัะฒะฝะพะณะพ ะทะฐะฟะธั‚ัƒ."
            }
            (_, Self::StandardCare) => {
                "Protect secrets, user files, git history, production systems, cost, privacy, and time."
            }
            (_, Self::StrictBoundaries) => {
                "Treat secrets, personal data, credentials, production state, money, and publish actions as stop-and-confirm boundaries."
            }
            (_, Self::ProjectLocal) => {
                "Keep project-specific context local; avoid carrying sensitive details into memory unless explicitly asked."
            }
        }
    }

    fn escalation_rule(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::StandardCare) => {
                "็ ดๅฃŠ็š„ใ€้ซ˜ใ‚ณใ‚นใƒˆใ€่ช่จผๆƒ…ๅ ฑใ€ๅ…ฌ้–‹ใ€ๆณ•ๅ‹™ใ€ใ‚ปใ‚ญใƒฅใƒชใƒ†ใ‚ฃใƒชใ‚นใ‚ฏใฎใ‚ใ‚‹ๆ“ไฝœใฎๅ‰ใซๅฐ‹ใญใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::StrictBoundaries) => {
                "ๆฉŸๅพฎๆƒ…ๅ ฑใฎ่ชญใฟๅ–ใ‚Šใ‚„ๆ‹กๆ•ฃใ€ๆœฌ็•ชใ‚ทใ‚นใƒ†ใƒ ๆ“ไฝœใ€ๆ”ฏๅ‡บใ€ๅ…ฌ้–‹ใฎๅ‰ใซๅœๆญขใ—ใฆๅฐ‹ใญใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::ProjectLocal) => {
                "ใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆ่ฉณ็ดฐใ‚’ใƒกใƒขใƒชใ€ใƒฏใƒผใ‚ฏใ‚นใƒšใƒผใ‚นใ€ๅคใ„ๅผ•ใ็ถ™ใŽใธๆŒใกๅ‡บใ™ๅ‰ใซ็ขบ่ชใ™ใ‚‹ใ€‚"
            }
            (Locale::ZhHans, Self::StandardCare) => {
                "้‡ๅˆฐ็ ดๅๆ€งใ€้ซ˜ๆˆๆœฌใ€ๅ‡ญๆฎใ€ๅ‘ๅธƒใ€ๆณ•ๅพ‹ๆˆ–ๅฎ‰ๅ…จ้ฃŽ้™ฉๆ“ไฝœๆ—ถๅ…ˆ่ฏข้—ฎใ€‚"
            }
            (Locale::ZhHans, Self::StrictBoundaries) => {
                "ๅœจ่ฏปๅ–ๆˆ–ไผ ๆ’ญๆ•ๆ„Ÿไฟกๆฏใ€่งฆ็ขฐ็”Ÿไบง็ณป็ปŸใ€่Šฑ่ดน่ต„้‡‘ๆˆ–ๅ‘ๅธƒๅ†…ๅฎนๅ‰ๅœๆญขๅนถ่ฏข้—ฎใ€‚"
            }
            (Locale::ZhHans, Self::ProjectLocal) => {
                "้œ€่ฆ่ทจ้กน็›ฎ่ฎฐๅฟ†ใ€ๅคๅˆถ้กน็›ฎ็ป†่Š‚ๆˆ–ๅผ•็”จๆ—งไบคๆŽฅๆ—ถ๏ผŒๅ…ˆ็กฎ่ฎค่ฟ™ไบ›ไธŠไธ‹ๆ–‡ไป้€‚็”จใ€‚"
            }
            (Locale::ZhHant, Self::StandardCare) => {
                "้‡ๅˆฐ็ ดๅฃžๆ€งใ€้ซ˜ๆˆๆœฌใ€ๆ†‘ๆ“šใ€็™ผๅธƒใ€ๆณ•ๅพ‹ๆˆ–ๅฎ‰ๅ…จ้ขจ้šชๆ“ไฝœๆ™‚ๅ…ˆ่ฉขๅ•ใ€‚"
            }
            (Locale::ZhHant, Self::StrictBoundaries) => {
                "ๅœจ่ฎ€ๅ–ๆˆ–ๅ‚ณๆ’ญๆ•ๆ„Ÿ่ณ‡่จŠใ€่งธ็ขฐ็”Ÿ็”ข็ณป็ตฑใ€่Šฑ่ฒป่ณ‡้‡‘ๆˆ–็™ผๅธƒๅ…งๅฎนๅ‰ๅœๆญขไธฆ่ฉขๅ•ใ€‚"
            }
            (Locale::ZhHant, Self::ProjectLocal) => {
                "้œ€่ฆ่ทจๅฐˆๆกˆ่จ˜ๆ†ถใ€่ค‡่ฃฝๅฐˆๆกˆ็ดฐ็ฏ€ๆˆ–ๅผ•็”จ่ˆŠไบคๆŽฅๆ™‚๏ผŒๅ…ˆ็ขบ่ช้€™ไบ›ไธŠไธ‹ๆ–‡ไป้ฉ็”จใ€‚"
            }
            (Locale::PtBr, Self::StandardCare) => {
                "Pergunte antes de aรงรตes destrutivas, caras, com credenciais, publicaรงรฃo, risco legal ou de seguranรงa."
            }
            (Locale::PtBr, Self::StrictBoundaries) => {
                "Pare e pergunte antes de ler ou espalhar dados sensรญveis, tocar produรงรฃo, gastar dinheiro ou publicar."
            }
            (Locale::PtBr, Self::ProjectLocal) => {
                "Confirme antes de levar detalhes do projeto para memรณria, workspaces ou handoffs antigos."
            }
            (Locale::Es419, Self::StandardCare) => {
                "Pregunta antes de acciones destructivas, costosas, con credenciales, publicaciรณn o riesgo legal/de seguridad."
            }
            (Locale::Es419, Self::StrictBoundaries) => {
                "Detente y pregunta antes de leer o difundir datos sensibles, tocar producciรณn, gastar dinero o publicar."
            }
            (Locale::Es419, Self::ProjectLocal) => {
                "Confirma antes de llevar detalles del proyecto a memoria, workspaces o handoffs viejos."
            }
            (Locale::Vi, Self::StandardCare) => {
                "Hแปi trฦฐแป›c cรกc thao tรกc phรก hแปงy, tแป‘n kรฉm, liรชn quan thรดng tin xรกc thแปฑc, xuแบฅt bแบฃn, phรกp lรฝ hoแบทc bแบฃo mแบญt."
            }
            (Locale::Vi, Self::StrictBoundaries) => {
                "Dแปซng vร  hแปi trฦฐแป›c khi ฤ‘แปc/phรกt tรกn dแปฏ liแป‡u nhแบกy cแบฃm, chแบกm sแบฃn xuแบฅt, chi tiแปn hoแบทc xuแบฅt bแบฃn."
            }
            (Locale::Vi, Self::ProjectLocal) => {
                "Xรกc nhแบญn trฦฐแป›c khi mang chi tiแบฟt dแปฑ รกn sang bแป™ nhแป›, workspace khรกc hoแบทc handoff cลฉ."
            }
            (Locale::Ko, Self::StandardCare) => {
                "ํŒŒ๊ดด์ ์ด๊ฑฐ๋‚˜, ๋น„์šฉ์ด ํฌ๊ฑฐ๋‚˜, ์ž๊ฒฉ ์ฆ๋ช…, ๊ฒŒ์‹œ, ๋ฒ•์ , ๋ณด์•ˆ ์œ„ํ—˜์ด ์žˆ๋Š” ์ž‘์—… ์ „์— ๋จผ์ € ๋ฌผ์–ด๋ณธ๋‹ค."
            }
            (Locale::Ko, Self::StrictBoundaries) => {
                "๋ฏผ๊ฐ ์ •๋ณด๋ฅผ ์ฝ๊ฑฐ๋‚˜ ํผ๋œจ๋ฆฌ๊ธฐ ์ „, ํ”„๋กœ๋•์…˜ ์‹œ์Šคํ…œ์„ ๊ฑด๋“œ๋ฆฌ๊ธฐ ์ „, ์ž๊ธˆ์„ ์“ฐ๊ฑฐ๋‚˜ ๊ฒŒ์‹œํ•˜๊ธฐ ์ „์— ๋ฉˆ์ถ”๊ณ  ๋ฌผ์–ด๋ณธ๋‹ค."
            }
            (Locale::Ko, Self::ProjectLocal) => {
                "ํ”„๋กœ์ ํŠธ ์„ธ๋ถ€ ์ •๋ณด๋ฅผ ๋ฉ”๋ชจ๋ฆฌ, ๋‹ค๋ฅธ ์›Œํฌ์ŠคํŽ˜์ด์Šค, ์˜ค๋ž˜๋œ ์ธ๊ณ„ ์ž๋ฃŒ๋กœ ์˜ฎ๊ธฐ๊ธฐ ์ „์— ํ™•์ธํ•œ๋‹ค."
            }
            (Locale::Ca, Self::StandardCare) => {
                "Pregunta abans d'accions destructives, costoses, amb credencials, de publicaciรณ o amb risc legal o de seguretat."
            }
            (Locale::Ca, Self::StrictBoundaries) => {
                "Atura't i pregunta abans de llegir o difondre dades sensibles, tocar sistemes de producciรณ, gastar diners o publicar."
            }
            (Locale::Ca, Self::ProjectLocal) => {
                "Confirma abans de portar detalls del projecte a la memรฒria, a altres espais de treball o a traspasos antics."
            }
            (Locale::De, Self::StandardCare) => {
                "Frage vor destruktiven, kostspieligen, zugangsdatenbezogenen, verรถffentlichenden, rechtlichen oder sicherheitskritischen Aktionen."
            }
            (Locale::De, Self::StrictBoundaries) => {
                "Halte an und frage, bevor du sensible Daten liest oder verbreitest, Produktionssysteme anfasst, Geld ausgibst oder verรถffentlichst."
            }
            (Locale::De, Self::ProjectLocal) => {
                "Bestรคtige, bevor du Projektdetails in Speicher, Workspaces oder veraltete รœbergaben รผbertrรคgst."
            }
            (Locale::Fr, Self::StandardCare) => {
                "Demandez avant toute action destructive, coรปteuse, impliquant des identifiants, une publication, ou un risque juridique ou de sรฉcuritรฉ."
            }
            (Locale::Fr, Self::StrictBoundaries) => {
                "Arrรชtez et demandez avant de lire ou diffuser des donnรฉes sensibles, de toucher aux systรจmes de production, de dรฉpenser de l'argent ou de publier."
            }
            (Locale::Fr, Self::ProjectLocal) => {
                "Confirmez avant de transporter des dรฉtails du projet vers la mรฉmoire, d'autres espaces de travail ou d'anciens transferts."
            }
            (Locale::Id, Self::StandardCare) => {
                "Tanya sebelum tindakan destruktif, mahal, terkait kredensial, publikasi, hukum, atau berisiko keamanan."
            }
            (Locale::Id, Self::StrictBoundaries) => {
                "Berhenti dan tanya sebelum membaca atau menyebarkan data sensitif, menyentuh sistem produksi, membelanjakan uang, atau mempublikasikan."
            }
            (Locale::Id, Self::ProjectLocal) => {
                "Konfirmasi sebelum membawa detail proyek ke memori, workspace lain, atau handoff lama."
            }
            (Locale::Hi, Self::StandardCare) => {
                "เคตเคฟเคจเคพเคถเค•เคพเคฐเฅ€, เค‰เคšเฅเคš-เคฒเคพเค—เคค, เค•เฅเคฐเฅ‡เคกเฅ‡เค‚เคถเคฟเคฏเคฒ, เคชเฅเคฐเค•เคพเคถเคจ, เค•เคพเคจเฅ‚เคจเฅ€ เคฏเคพ เคธเฅเคฐเค•เฅเคทเคพ-เคœเฅ‹เค–เคฟเคฎ เค•เคพเคฐเฅเคฏเฅ‹เค‚ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคชเฅ‚เค›เฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::StrictBoundaries) => {
                "เคธเค‚เคตเฅ‡เคฆเคจเคถเฅ€เคฒ เคกเฅ‡เคŸเคพ เคชเคขเคผเคจเฅ‡ เคฏเคพ เคซเฅˆเคฒเคพเคจเฅ‡, เคชเฅเคฐเฅ‹เคกเค•เฅเคถเคจ เคธเคฟเคธเฅเคŸเคฎ เค›เฅ‚เคจเฅ‡, เคงเคจ เค–เคฐเฅเคš เค•เคฐเคจเฅ‡ เคฏเคพ เคชเฅเคฐเค•เคพเคถเคฟเคค เค•เคฐเคจเฅ‡ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคฐเฅเค•เค•เคฐ เคชเฅ‚เค›เฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::ProjectLocal) => {
                "เคชเฅเคฐเฅ‹เคœเฅ‡เค•เฅเคŸ เคตเคฟเคตเคฐเคฃ เคฎเฅ‡เคฎเฅ‹เคฐเฅ€, เค…เคจเฅเคฏ เค•เคพเคฐเฅเคฏเค•เฅเคทเฅ‡เคคเฅเคฐเฅ‹เค‚ เคฏเคพ เคชเฅเคฐเคพเคจเฅ‡ เคนเฅˆเค‚เคกเค‘เคซเคผ เคฎเฅ‡เค‚ เคฒเฅ‡ เคœเคพเคจเฅ‡ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคชเฅเคทเฅเคŸเคฟ เค•เคฐเฅ‡เค‚เฅค"
            }
            (Locale::Ru, Self::StandardCare) => {
                "ะกะฟั€ะฐัˆะธะฒะฐะนั‚ะต ะฟะตั€ะตะด ะดะตัั‚ั€ัƒะบั‚ะธะฒะฝั‹ะผะธ, ะดะพั€ะพะณะธะผะธ, ัะฒัะทะฐะฝะฝั‹ะผะธ ั ัƒั‡ั‘ั‚ะฝั‹ะผะธ ะดะฐะฝะฝั‹ะผะธ, ะฟัƒะฑะปะธะบะฐั†ะธะตะน, ัŽั€ะธะดะธั‡ะตัะบะธะผะธ ะธะปะธ ัƒะณั€ะพะถะฐัŽั‰ะธะผะธ ะฑะตะทะพะฟะฐัะฝะพัั‚ะธ ะดะตะนัั‚ะฒะธัะผะธ."
            }
            (Locale::Ru, Self::StrictBoundaries) => {
                "ะžัั‚ะฐะฝะพะฒะธั‚ะตััŒ ะธ ัะฟั€ะพัะธั‚ะต, ะฟั€ะตะถะดะต ั‡ะตะผ ั‡ะธั‚ะฐั‚ัŒ ะธะปะธ ั€ะฐัะฟั€ะพัั‚ั€ะฐะฝัั‚ัŒ ั‡ัƒะฒัั‚ะฒะธั‚ะตะปัŒะฝั‹ะต ะดะฐะฝะฝั‹ะต, ั‚ั€ะพะณะฐั‚ัŒ production-ัะธัั‚ะตะผั‹, ั‚ั€ะฐั‚ะธั‚ัŒ ะดะตะฝัŒะณะธ ะธะปะธ ะฟัƒะฑะปะธะบะพะฒะฐั‚ัŒ."
            }
            (Locale::Ru, Self::ProjectLocal) => {
                "ะŸะพะดั‚ะฒะตั€ะดะธั‚ะต, ะฟั€ะตะถะดะต ั‡ะตะผ ะฟะตั€ะตะฝะพัะธั‚ัŒ ะดะตั‚ะฐะปะธ ะฟั€ะพะตะบั‚ะฐ ะฒ ะฟะฐะผัั‚ัŒ, ะดั€ัƒะณะธะต ั€ะฐะฑะพั‡ะธะต ะพะฑะปะฐัั‚ะธ ะธะปะธ ัƒัั‚ะฐั€ะตะฒัˆะธะต ะฟะตั€ะตะดะฐั‚ะพั‡ะฝั‹ะต ะทะฐะผะตั‚ะบะธ."
            }
            (Locale::Uk, Self::StandardCare) => {
                "ะŸะธั‚ะฐะนั‚ะต ะฟะตั€ะตะด ั€ัƒะนะฝั–ะฒะฝะธะผะธ, ะดะพั€ะพะณะธะผะธ, ะฟะพะฒ'ัะทะฐะฝะธะผะธ ะท ะพะฑะปั–ะบะพะฒะธะผะธ ะดะฐะฝะธะผะธ, ะฟัƒะฑะปั–ะบะฐั†ั–ั”ัŽ, ัŽั€ะธะดะธั‡ะฝะธะผะธ ั‡ะธ ะฝะตะฑะตะทะฟะตั‡ะฝะธะผะธ ะดะปั ะฑะตะทะฟะตะบะธ ะดั–ัะผะธ."
            }
            (Locale::Uk, Self::StrictBoundaries) => {
                "ะ—ัƒะฟะธะฝั–ั‚ัŒัั ะน ะทะฐะฟะธั‚ะฐะนั‚ะต, ะฟะตั€ัˆ ะฝั–ะถ ั‡ะธั‚ะฐั‚ะธ ั‡ะธ ะฟะพัˆะธั€ัŽะฒะฐั‚ะธ ั‡ัƒั‚ะปะธะฒั– ะดะฐะฝั–, ั‡ั–ะฟะฐั‚ะธ production-ัะธัั‚ะตะผะธ, ะฒะธั‚ั€ะฐั‡ะฐั‚ะธ ะณั€ะพัˆั– ะฐะฑะพ ะฟัƒะฑะปั–ะบัƒะฒะฐั‚ะธ."
            }
            (Locale::Uk, Self::ProjectLocal) => {
                "ะŸั–ะดั‚ะฒะตั€ะดัŒั‚ะต, ะฟะตั€ัˆ ะฝั–ะถ ะฟะตั€ะตะฝะพัะธั‚ะธ ะดะตั‚ะฐะปั– ะฟั€ะพั”ะบั‚ัƒ ะฒ ะฟะฐะผ'ัั‚ัŒ, ั–ะฝัˆั– ั€ะพะฑะพั‡ั– ะฟั€ะพัั‚ะพั€ะธ ั‡ะธ ะทะฐัั‚ะฐั€ั–ะปั– ะฟะตั€ะตะดะฐั‚ะพั‡ะฝั– ะฝะพั‚ะฐั‚ะบะธ."
            }
            (_, Self::StandardCare) => {
                "Ask before destructive, high-cost, credential, publishing, legal, or security-risk actions."
            }
            (_, Self::StrictBoundaries) => {
                "Stop and ask before reading or spreading sensitive data, touching production systems, spending money, or publishing."
            }
            (_, Self::ProjectLocal) => {
                "Confirm before carrying project details across memory, workspaces, or stale handoffs."
            }
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum GuidedPrinciples {
    ScopedChanges,
    UserVoice,
    ReversibleOps,
}

impl GuidedPrinciples {
    fn next(self) -> Self {
        match self {
            Self::ScopedChanges => Self::UserVoice,
            Self::UserVoice => Self::ReversibleOps,
            Self::ReversibleOps => Self::ScopedChanges,
        }
    }

    fn label(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::ScopedChanges) => "ๅฐใ•ใ็ตžใฃใŸๅค‰ๆ›ด",
            (Locale::Ja, Self::UserVoice) => "ใƒฆใƒผใ‚ถใƒผใฎๅฃฐใ‚’ไฟใค",
            (Locale::Ja, Self::ReversibleOps) => "ๅฏ้€†ๆ‰‹้ †",
            (Locale::ZhHans, Self::ScopedChanges) => "ๅฐ่Œƒๅ›ดๆ”นๅŠจ",
            (Locale::ZhHans, Self::UserVoice) => "ไฟ็•™็”จๆˆท่ฏญๆฐ”",
            (Locale::ZhHans, Self::ReversibleOps) => "ๅฏ้€†ๆญฅ้ชค",
            (Locale::ZhHant, Self::ScopedChanges) => "ๅฐ็ฏ„ๅœๆ”นๅ‹•",
            (Locale::ZhHant, Self::UserVoice) => "ไฟ็•™ไฝฟ็”จ่€…่ชžๆฐฃ",
            (Locale::ZhHant, Self::ReversibleOps) => "ๅฏ้€†ๆญฅ้ฉŸ",
            (Locale::PtBr, Self::ScopedChanges) => "mudanรงas focadas",
            (Locale::PtBr, Self::UserVoice) => "preservar voz do usuรกrio",
            (Locale::PtBr, Self::ReversibleOps) => "passos reversรญveis",
            (Locale::Es419, Self::ScopedChanges) => "cambios acotados",
            (Locale::Es419, Self::UserVoice) => "preservar voz del usuario",
            (Locale::Es419, Self::ReversibleOps) => "pasos reversibles",
            (Locale::Vi, Self::ScopedChanges) => "thay ฤ‘แป•i cรณ phแบกm vi",
            (Locale::Vi, Self::UserVoice) => "giแปฏ giแปng ngฦฐแปi dรนng",
            (Locale::Vi, Self::ReversibleOps) => "bฦฐแป›c cรณ thแปƒ ฤ‘แบฃo ngฦฐแปฃc",
            (Locale::Ko, Self::ScopedChanges) => "๋ฒ”์œ„๊ฐ€ ๋ช…ํ™•ํ•œ ๋ณ€๊ฒฝ",
            (Locale::Ko, Self::UserVoice) => "์‚ฌ์šฉ์ž์˜ ์–ด์กฐ ์œ ์ง€",
            (Locale::Ko, Self::ReversibleOps) => "๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋Š” ๋‹จ๊ณ„",
            (Locale::Ca, Self::ScopedChanges) => "canvis acotats",
            (Locale::Ca, Self::UserVoice) => "veu de l'usuari",
            (Locale::Ca, Self::ReversibleOps) => "passos reversibles",
            (Locale::De, Self::ScopedChanges) => "begrenzte ร„nderungen",
            (Locale::De, Self::UserVoice) => "Stimme des Nutzers",
            (Locale::De, Self::ReversibleOps) => "reversible Schritte",
            (Locale::Fr, Self::ScopedChanges) => "changements ciblรฉs",
            (Locale::Fr, Self::UserVoice) => "voix de l'utilisateur",
            (Locale::Fr, Self::ReversibleOps) => "รฉtapes rรฉversibles",
            (Locale::Id, Self::ScopedChanges) => "perubahan terbatas",
            (Locale::Id, Self::UserVoice) => "suara pengguna",
            (Locale::Id, Self::ReversibleOps) => "langkah reversibel",
            (Locale::Hi, Self::ScopedChanges) => "เคธเฅ€เคฎเคฟเคค เคฌเคฆเคฒเคพเคต",
            (Locale::Hi, Self::UserVoice) => "เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เค•เฅ€ เค†เคตเคพเคœเคผ",
            (Locale::Hi, Self::ReversibleOps) => "เค‰เคคเฅเค•เฅเคฐเคฎเคฃเฅ€เคฏ เคšเคฐเคฃ",
            (Locale::Ru, Self::ScopedChanges) => "ะพะณั€ะฐะฝะธั‡ะตะฝะฝั‹ะต ะธะทะผะตะฝะตะฝะธั",
            (Locale::Ru, Self::UserVoice) => "ะณะพะปะพั ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั",
            (Locale::Ru, Self::ReversibleOps) => "ะพะฑั€ะฐั‚ะธะผั‹ะต ัˆะฐะณะธ",
            (Locale::Uk, Self::ScopedChanges) => "ะพะฑะผะตะถะตะฝั– ะทะผั–ะฝะธ",
            (Locale::Uk, Self::UserVoice) => "ะณะพะปะพั ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ",
            (Locale::Uk, Self::ReversibleOps) => "ะพะฑะพั€ะพั‚ะฝั– ะบั€ะพะบะธ",
            (_, Self::ScopedChanges) => "scoped changes",
            (_, Self::UserVoice) => "user voice",
            (_, Self::ReversibleOps) => "reversible steps",
        }
    }

    fn note(self, locale: Locale) -> &'static str {
        match (locale, self) {
            (Locale::Ja, Self::ScopedChanges) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšๅฐใ•ใใƒฌใƒ“ใƒฅใƒผใ—ใ‚„ใ™ใ„ๅค‰ๆ›ดใ‚’ๅ„ชๅ…ˆใ—ใ€ๆ˜Ž็คบ่ฆๆฑ‚ใŒใชใ„้™ใ‚Š็„ก้–ขไฟ‚ใชใƒชใƒ•ใ‚กใ‚ฏใ‚ฟใ‚’้ฟใ‘ใ‚‹ใ€‚"
            }
            (Locale::Ja, Self::UserVoice) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšใƒฆใƒผใ‚ถใƒผใฎ่ชž่ชฟใ€ใƒ–ใƒฉใƒณใƒ‰ใ€ๅˆถ็ด„ใ‚’ไฟใกใ€ๅฅฝใฟใ‚’ๆจฉ้™ๆ‹กๅคงใจใ—ใฆๆ‰ฑใ‚ใชใ„ใ€‚"
            }
            (Locale::Ja, Self::ReversibleOps) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšๅฝฑ้Ÿฟใฎๅคงใใ„ๆ“ไฝœใฎๅ‰ใซใ€ๅฏ้€†ๆ‰‹้ †ใ€ใƒใ‚งใƒƒใ‚ฏใƒใ‚คใƒณใƒˆใ€ใƒญใƒผใƒซใƒใƒƒใ‚ฏ่ชฌๆ˜Žใ‚’้ธใถใ€‚"
            }
            (Locale::ZhHans, Self::ScopedChanges) => {
                "่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšไผ˜ๅ…ˆ้‡‡็”จๅฐ่Œƒๅ›ดใ€ๅฏๅฎกๆŸฅ็š„ๆ”นๅŠจ๏ผ›้™ค้žๆ˜Ž็กฎ่ฆๆฑ‚๏ผŒไธๅšๆ— ๅ…ณ้‡ๆž„ใ€‚"
            }
            (Locale::ZhHans, Self::UserVoice) => {
                "่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšไฟ็•™็”จๆˆท็š„่ฏญๆฐ”ใ€ๅ“็‰Œๅ’Œ็บฆๆŸ๏ผ›ไธๆŠŠๅๅฅฝๆŽจๆ–ญๆˆๆƒ้™ๆ‰ฉๅคงใ€‚"
            }
            (Locale::ZhHans, Self::ReversibleOps) => {
                "่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšๅ…ˆ้€‰ๆ‹ฉๅฏ้€†ๆญฅ้ชคใ€ๆฃ€ๆŸฅ็‚นๅ’Œๅ›žๆปš่ฏดๆ˜Ž๏ผŒๅ†่ฟ›่กŒ้ซ˜ๅฝฑๅ“ๆ“ไฝœใ€‚"
            }
            (Locale::ZhHant, Self::ScopedChanges) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšๅ„ชๅ…ˆๆŽก็”จๅฐ็ฏ„ๅœใ€ๅฏๅฏฉๆŸฅ็š„ๆ”นๅ‹•๏ผ›้™ค้žๆ˜Ž็ขบ่ฆๆฑ‚๏ผŒไธๅš็„ก้—œ้‡ๆง‹ใ€‚"
            }
            (Locale::ZhHant, Self::UserVoice) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšไฟ็•™ไฝฟ็”จ่€…็š„่ชžๆฐฃใ€ๅ“็‰Œๅ’Œ็ด„ๆŸ๏ผ›ไธๆŠŠๅๅฅฝๆŽจๆ–ทๆˆๆฌŠ้™ๆ“ดๅคงใ€‚"
            }
            (Locale::ZhHant, Self::ReversibleOps) => {
                "่‡ช็”ฑๅŽŸๅ‰‡๏ผšๅ…ˆ้ธๆ“‡ๅฏ้€†ๆญฅ้ฉŸใ€ๆชขๆŸฅ้ปžๅ’Œๅ›žๅพฉ่ชชๆ˜Ž๏ผŒๅ†้€ฒ่กŒ้ซ˜ๅฝฑ้Ÿฟๆ“ไฝœใ€‚"
            }
            (Locale::PtBr, Self::ScopedChanges) => {
                "Princรญpio livre: prefira mudanรงas pequenas e revisรกveis; evite refactors nรฃo relacionados sem pedido explรญcito."
            }
            (Locale::PtBr, Self::UserVoice) => {
                "Princรญpio livre: preserve a voz, marca e restriรงรตes do usuรกrio sem tratar preferรชncias como expansรฃo de permissรฃo."
            }
            (Locale::PtBr, Self::ReversibleOps) => {
                "Princรญpio livre: favoreรงa passos reversรญveis, checkpoints e notas de rollback antes de aรงรตes de alto impacto."
            }
            (Locale::Es419, Self::ScopedChanges) => {
                "Principio libre: prefiere cambios pequeรฑos y revisables; evita refactors no relacionados sin pedido explรญcito."
            }
            (Locale::Es419, Self::UserVoice) => {
                "Principio libre: preserva la voz, marca y restricciones del usuario sin tratar preferencias como expansiรณn de permisos."
            }
            (Locale::Es419, Self::ReversibleOps) => {
                "Principio libre: favorece pasos reversibles, checkpoints y notas de rollback antes de acciones de alto impacto."
            }
            (Locale::Vi, Self::ScopedChanges) => {
                "Nguyรชn tแบฏc tแปฑ do: ฦฐu tiรชn thay ฤ‘แป•i nhแป, dแป… review; trรกnh refactor khรดng liรชn quan nแบฟu khรดng ฤ‘ฦฐแปฃc yรชu cแบงu rรต."
            }
            (Locale::Vi, Self::UserVoice) => {
                "Nguyรชn tแบฏc tแปฑ do: giแปฏ giแปng, thฦฐฦกng hiแป‡u vร  rร ng buแป™c cแปงa ngฦฐแปi dรนng, khรดng xem sแปŸ thรญch lร  mแปŸ rแป™ng quyแปn."
            }
            (Locale::Vi, Self::ReversibleOps) => {
                "Nguyรชn tแบฏc tแปฑ do: ฦฐu tiรชn bฦฐแป›c cรณ thแปƒ ฤ‘แบฃo ngฦฐแปฃc, checkpoint vร  ghi chรบ rollback trฦฐแป›c thao tรกc tรกc ฤ‘แป™ng cao."
            }
            (Locale::Ko, Self::ScopedChanges) => {
                "์ž์œ  ์›์น™: ์ž‘๊ณ  ๋ฆฌ๋ทฐํ•˜๊ธฐ ์‰ฌ์šด ๋ณ€๊ฒฝ์„ ์šฐ์„ ํ•˜๊ณ , ๋ช…์‹œ์ ์œผ๋กœ ์š”์ฒญ๋ฐ›์ง€ ์•Š๋Š” ํ•œ ๊ด€๋ จ ์—†๋Š” ๋ฆฌํŒฉํ„ฐ๋ง์€ ํ•˜์ง€ ์•Š๋Š”๋‹ค."
            }
            (Locale::Ko, Self::UserVoice) => {
                "์ž์œ  ์›์น™: ์‚ฌ์šฉ์ž์˜ ์–ด์กฐ, ๋ธŒ๋žœ๋“œ, ์ œ์•ฝ์„ ์œ ์ง€ํ•˜๊ณ  ์„ ํ˜ธ๋ฅผ ๊ถŒํ•œ ํ™•๋Œ€๋กœ ์ทจ๊ธ‰ํ•˜์ง€ ์•Š๋Š”๋‹ค."
            }
            (Locale::Ko, Self::ReversibleOps) => {
                "์ž์œ  ์›์น™: ์˜ํ–ฅ์ด ํฐ ์ž‘์—… ์ „์— ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋Š” ๋‹จ๊ณ„, ์ฒดํฌํฌ์ธํŠธ, ๋กค๋ฐฑ ๋ฉ”๋ชจ๋ฅผ ์šฐ์„ ํ•œ๋‹ค."
            }
            (Locale::Ca, Self::ScopedChanges) => {
                "Principi lliure: prefereix canvis petits i revisables i evita refactors no relacionats si no es demanen explรญcitament."
            }
            (Locale::Ca, Self::UserVoice) => {
                "Principi lliure: preserva la veu, la marca i les restriccions de l'usuari sense tractar les preferรจncies com una ampliaciรณ de permisos."
            }
            (Locale::Ca, Self::ReversibleOps) => {
                "Principi lliure: priorita passos reversibles, punts de control i notes de marxa enrere abans d'operacions d'alt impacte."
            }
            (Locale::De, Self::ScopedChanges) => {
                "Freitext-Prinzip: Bevorzuge kleine, รผberprรผfbare ร„nderungen und vermeide unzusammenhรคngende Refactorings, sofern nicht ausdrรผcklich gewรผnscht."
            }
            (Locale::De, Self::UserVoice) => {
                "Freitext-Prinzip: Bewahre Stimme, Marke und Vorgaben des Nutzers, ohne Prรคferenzen als Rechteausweitung zu behandeln."
            }
            (Locale::De, Self::ReversibleOps) => {
                "Freitext-Prinzip: Bevorzuge reversible Schritte, Checkpoints und Rollback-Notizen vor einschneidenden Operationen."
            }
            (Locale::Fr, Self::ScopedChanges) => {
                "Principe libre : prรฉfรฉrez des changements petits et rรฉvisables et รฉvitez les refactors sans rapport, sauf demande explicite."
            }
            (Locale::Fr, Self::UserVoice) => {
                "Principe libre : prรฉservez la voix, la marque et les contraintes de l'utilisateur sans traiter ses prรฉfรฉrences comme une extension de permissions."
            }
            (Locale::Fr, Self::ReversibleOps) => {
                "Principe libre : privilรฉgiez รฉtapes rรฉversibles, points de contrรดle et notes de rollback avant les opรฉrations ร  fort impact."
            }
            (Locale::Id, Self::ScopedChanges) => {
                "Prinsip bebas: utamakan perubahan kecil yang mudah ditinjau dan hindari refactor tak terkait kecuali diminta secara eksplisit."
            }
            (Locale::Id, Self::UserVoice) => {
                "Prinsip bebas: jaga suara, merek, dan batasan pengguna tanpa memperlakukan preferensi sebagai perluasan izin."
            }
            (Locale::Id, Self::ReversibleOps) => {
                "Prinsip bebas: utamakan langkah reversibel, checkpoint, dan catatan rollback sebelum operasi berdampak besar."
            }
            (Locale::Hi, Self::ScopedChanges) => {
                "เคฎเฅเค•เฅเคค-เคชเคพเค  เคธเคฟเคฆเฅเคงเคพเค‚เคค: เค›เฅ‹เคŸเฅ‡, เคธเคฎเฅ€เค•เฅเคทเคพเคฏเฅ‹เค—เฅเคฏ เคฌเคฆเคฒเคพเคตเฅ‹เค‚ เค•เฅ‹ เคชเฅเคฐเคพเคฅเคฎเคฟเค•เคคเคพ เคฆเฅ‡เค‚ เค”เคฐ เคธเฅเคชเคทเฅเคŸ เค…เคจเฅเคฐเฅ‹เคง เค•เฅ‡ เคฌเคฟเคจเคพ เค…เคธเค‚เคฌเค‚เคงเคฟเคค เคฐเคฟเคซเฅˆเค•เฅเคŸเคฐ เคธเฅ‡ เคฌเคšเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::UserVoice) => {
                "เคฎเฅเค•เฅเคค-เคชเคพเค  เคธเคฟเคฆเฅเคงเคพเค‚เคค: เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เค•เฅ€ เค†เคตเคพเคœเคผ, เคฌเฅเคฐเคพเค‚เคก เค”เคฐ เคฌเคพเคงเคพเคเค เคธเฅเคฐเค•เฅเคทเคฟเคค เคฐเค–เฅ‡เค‚; เคชเฅเคฐเคพเคฅเคฎเคฟเค•เคคเคพเค“เค‚ เค•เฅ‹ เค…เคจเฅเคฎเคคเคฟ-เคตเคฟเคธเฅเคคเคพเคฐ เคจ เคฎเคพเคจเฅ‡เค‚เฅค"
            }
            (Locale::Hi, Self::ReversibleOps) => {
                "เคฎเฅเค•เฅเคค-เคชเคพเค  เคธเคฟเคฆเฅเคงเคพเค‚เคค: เค‰เคšเฅเคš-เคชเฅเคฐเคญเคพเคต เค•เคพเคฐเฅเคฏเฅ‹เค‚ เคธเฅ‡ เคชเคนเคฒเฅ‡ เค‰เคคเฅเค•เฅเคฐเคฎเคฃเฅ€เคฏ เคšเคฐเคฃเฅ‹เค‚, เคšเฅ‡เค•เคชเฅ‰เค‡เค‚เคŸ เค”เคฐ เคฐเฅ‹เคฒเคฌเฅˆเค• เคจเฅ‹เคŸเฅเคธ เค•เฅ‹ เคชเฅเคฐเคพเคฅเคฎเคฟเค•เคคเคพ เคฆเฅ‡เค‚เฅค"
            }
            (Locale::Ru, Self::ScopedChanges) => {
                "ะกะฒะพะฑะพะดะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ: ะฟั€ะตะดะฟะพั‡ะธั‚ะฐะนั‚ะต ะฝะตะฑะพะปัŒัˆะธะต, ะฟั€ะพะฒะตั€ัะตะผั‹ะต ะธะทะผะตะฝะตะฝะธั ะธ ะธะทะฑะตะณะฐะนั‚ะต ะฝะตัะฒัะทะฐะฝะฝั‹ั… ั€ะตั„ะฐะบั‚ะพั€ะธะฝะณะพะฒ ะฑะตะท ัะฒะฝะพะณะพ ะทะฐะฟั€ะพัะฐ."
            }
            (Locale::Ru, Self::UserVoice) => {
                "ะกะฒะพะฑะพะดะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ: ัะพั…ั€ะฐะฝัะนั‚ะต ะณะพะปะพั, ะฑั€ะตะฝะด ะธ ะพะณั€ะฐะฝะธั‡ะตะฝะธั ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั, ะฝะต ั‚ั€ะฐะบั‚ัƒั ะฟั€ะตะดะฟะพั‡ั‚ะตะฝะธั ะบะฐะบ ั€ะฐััˆะธั€ะตะฝะธะต ะฟะพะปะฝะพะผะพั‡ะธะน."
            }
            (Locale::Ru, Self::ReversibleOps) => {
                "ะกะฒะพะฑะพะดะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ: ะพั‚ะดะฐะฒะฐะนั‚ะต ะฟั€ะตะดะฟะพั‡ั‚ะตะฝะธะต ะพะฑั€ะฐั‚ะธะผั‹ะผ ัˆะฐะณะฐะผ, ะบะพะฝั‚ั€ะพะปัŒะฝั‹ะผ ั‚ะพั‡ะบะฐะผ ะธ ะทะฐะผะตั‚ะบะฐะผ ะพะฑ ะพั‚ะบะฐั‚ะต ะฟะตั€ะตะด ะฒั‹ัะพะบะพั€ะธัะบะพะฒั‹ะผะธ ะพะฟะตั€ะฐั†ะธัะผะธ."
            }
            (Locale::Uk, Self::ScopedChanges) => {
                "ะ’ั–ะปัŒะฝะธะน ะฟั€ะธะฝั†ะธะฟ: ะฝะฐะดะฐะฒะฐะนั‚ะต ะฟะตั€ะตะฒะฐะณัƒ ะฝะตะฒะตะปะธะบะธะผ, ะฟะตั€ะตะฒั–ั€ัŽะฒะฐะฝะธะผ ะทะผั–ะฝะฐะผ ั– ัƒะฝะธะบะฐะนั‚ะต ะฝะตะฟะพะฒ'ัะทะฐะฝะธั… ั€ะตั„ะฐะบั‚ะพั€ะธะฝะณั–ะฒ ะฑะตะท ัะฒะฝะพะณะพ ะทะฐะฟะธั‚ัƒ."
            }
            (Locale::Uk, Self::UserVoice) => {
                "ะ’ั–ะปัŒะฝะธะน ะฟั€ะธะฝั†ะธะฟ: ะทะฑะตั€ั–ะณะฐะนั‚ะต ะณะพะปะพั, ะฑั€ะตะฝะด ั– ะพะฑะผะตะถะตะฝะฝั ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ, ะฝะต ั‚ั€ะฐะบั‚ัƒัŽั‡ะธ ะฒะฟะพะดะพะฑะฐะฝะฝั ัะบ ั€ะพะทัˆะธั€ะตะฝะฝั ะฟะพะฒะฝะพะฒะฐะถะตะฝัŒ."
            }
            (Locale::Uk, Self::ReversibleOps) => {
                "ะ’ั–ะปัŒะฝะธะน ะฟั€ะธะฝั†ะธะฟ: ะฝะฐะดะฐะฒะฐะนั‚ะต ะฟะตั€ะตะฒะฐะณัƒ ะพะฑะพั€ะพั‚ะฝะธะผ ะบั€ะพะบะฐะผ, ะบะพะฝั‚ั€ะพะปัŒะฝะธะผ ั‚ะพั‡ะบะฐะผ ั– ะฝะพั‚ะฐั‚ะบะฐะผ ะฟั€ะพ ะฒั–ะดะบะฐั‚ ะฟะตั€ะตะด ะฒะธัะพะบะพั€ะธะทะธะบะพะฒะธะผะธ ะพะฟะตั€ะฐั†ั–ัะผะธ."
            }
            (_, Self::ScopedChanges) => {
                "Freeform principle: prefer small, reviewable changes and avoid unrelated refactors unless explicitly requested."
            }
            (_, Self::UserVoice) => {
                "Freeform principle: preserve the user's voice, brand, and constraints without treating preferences as permission expansion."
            }
            (_, Self::ReversibleOps) => {
                "Freeform principle: favor reversible steps, checkpoints, and rollback notes before high-impact operations."
            }
        }
    }
}

fn next_guided_autonomy(preference: AutonomyPreference) -> AutonomyPreference {
    match preference {
        AutonomyPreference::Unspecified | AutonomyPreference::Cautious => {
            AutonomyPreference::Balanced
        }
        AutonomyPreference::Balanced => AutonomyPreference::Autonomous,
        AutonomyPreference::Autonomous => AutonomyPreference::Cautious,
    }
}

fn autonomy_label(preference: AutonomyPreference, locale: Locale) -> &'static str {
    match (locale, preference) {
        (Locale::Ja, AutonomyPreference::Cautious) => "ๆ…Ž้‡",
        (Locale::Ja, AutonomyPreference::Balanced) => "ใƒใƒฉใƒณใ‚น",
        (Locale::Ja, AutonomyPreference::Autonomous) => "็ฉๆฅต็š„",
        (Locale::ZhHans, AutonomyPreference::Cautious) => "่ฐจๆ…Ž",
        (Locale::ZhHans, AutonomyPreference::Balanced) => "ๅนณ่กก",
        (Locale::ZhHans, AutonomyPreference::Autonomous) => "็งฏๆžไธปๅŠจ",
        (Locale::ZhHant, AutonomyPreference::Cautious) => "่ฌนๆ…Ž",
        (Locale::ZhHant, AutonomyPreference::Balanced) => "ๅนณ่กก",
        (Locale::ZhHant, AutonomyPreference::Autonomous) => "็ฉๆฅตไธปๅ‹•",
        (Locale::PtBr, AutonomyPreference::Cautious) => "cauteloso",
        (Locale::PtBr, AutonomyPreference::Balanced) => "equilibrado",
        (Locale::PtBr, AutonomyPreference::Autonomous) => "ambicioso",
        (Locale::Es419, AutonomyPreference::Cautious) => "cauteloso",
        (Locale::Es419, AutonomyPreference::Balanced) => "equilibrado",
        (Locale::Es419, AutonomyPreference::Autonomous) => "ambicioso",
        (Locale::Vi, AutonomyPreference::Cautious) => "thแบญn trแปng",
        (Locale::Vi, AutonomyPreference::Balanced) => "cรขn bแบฑng",
        (Locale::Vi, AutonomyPreference::Autonomous) => "chแปง ฤ‘แป™ng",
        (Locale::Ko, AutonomyPreference::Cautious) => "์‹ ์ค‘ํ•จ",
        (Locale::Ko, AutonomyPreference::Balanced) => "๊ท ํ˜•",
        (Locale::Ko, AutonomyPreference::Autonomous) => "์ ๊ทน์ ",
        (Locale::Ca, AutonomyPreference::Cautious) => "cautelรณs",
        (Locale::Ca, AutonomyPreference::Balanced) => "equilibrat",
        (Locale::Ca, AutonomyPreference::Autonomous) => "ambiciรณs",
        (Locale::De, AutonomyPreference::Cautious) => "vorsichtig",
        (Locale::De, AutonomyPreference::Balanced) => "ausgewogen",
        (Locale::De, AutonomyPreference::Autonomous) => "ambitioniert",
        (Locale::Fr, AutonomyPreference::Cautious) => "prudent",
        (Locale::Fr, AutonomyPreference::Balanced) => "รฉquilibrรฉ",
        (Locale::Fr, AutonomyPreference::Autonomous) => "ambitieux",
        (Locale::Id, AutonomyPreference::Cautious) => "hati-hati",
        (Locale::Id, AutonomyPreference::Balanced) => "seimbang",
        (Locale::Id, AutonomyPreference::Autonomous) => "ambisius",
        (Locale::Hi, AutonomyPreference::Cautious) => "เคธเคพเคตเคงเคพเคจ",
        (Locale::Hi, AutonomyPreference::Balanced) => "เคธเค‚เคคเฅเคฒเคฟเคค",
        (Locale::Hi, AutonomyPreference::Autonomous) => "เคฎเคนเคคเฅเคตเคพเค•เคพเค‚เค•เฅเคทเฅ€",
        (Locale::Ru, AutonomyPreference::Cautious) => "ะพัั‚ะพั€ะพะถะฝั‹ะน",
        (Locale::Ru, AutonomyPreference::Balanced) => "ัะฑะฐะปะฐะฝัะธั€ะพะฒะฐะฝะฝั‹ะน",
        (Locale::Ru, AutonomyPreference::Autonomous) => "ัะฐะผะพัั‚ะพัั‚ะตะปัŒะฝั‹ะน",
        (Locale::Uk, AutonomyPreference::Cautious) => "ะพะฑะตั€ะตะถะฝะธะน",
        (Locale::Uk, AutonomyPreference::Balanced) => "ะทะฑะฐะปะฐะฝัะพะฒะฐะฝะธะน",
        (Locale::Uk, AutonomyPreference::Autonomous) => "ัะฐะผะพัั‚ั–ะนะฝะธะน",
        (_, AutonomyPreference::Cautious) => "cautious",
        (_, AutonomyPreference::Balanced) => "balanced",
        (_, AutonomyPreference::Autonomous) => "ambitious",
        (_, AutonomyPreference::Unspecified) => "unspecified",
    }
}

fn autonomy_priority(preference: AutonomyPreference, locale: Locale) -> &'static str {
    match (locale, preference) {
        (Locale::Ja, AutonomyPreference::Cautious) => {
            "ใƒ•ใ‚กใ‚คใƒซ็ทจ้›†ใ€ใ‚ณใƒžใƒณใƒ‰ๅฎŸ่กŒใ€ใ‚ใ„ใพใ„ใช่ฃฝๅ“ๅˆคๆ–ญใฎๅ‰ใซๅœๆญขใ—ใฆๅฐ‹ใญใ‚‹ใ€‚"
        }
        (Locale::Ja, AutonomyPreference::Balanced) => {
            "ๆ˜Ž็ขบใงไฝŽใƒชใ‚นใ‚ฏใชไฝœๆฅญใฏ็›ดๆŽฅ้€ฒใ‚ใ€ๅฑ้™บใ€็ ดๅฃŠ็š„ใ€ใ‚ใ„ใพใ„ใชๆ“ไฝœใงใฏๅ…ˆใซ็ขบ่ชใ™ใ‚‹ใ€‚"
        }
        (Locale::Ja, AutonomyPreference::Autonomous) => {
            "ๅฎ‰ๅ…จใชๅฎšๅž‹ไฝœๆฅญใฏใพใจใ‚ใฆ้€ฒใ‚ใ‚‹ใŒใ€็ ดๅฃŠ็š„ใ€่ช่จผๆƒ…ๅ ฑใ€ๅ…ฌ้–‹ใ€้ซ˜ใ‚ณใ‚นใƒˆใ€ๆณ•ๅ‹™ใ€ใ‚ปใ‚ญใƒฅใƒชใƒ†ใ‚ฃใƒชใ‚นใ‚ฏใงใฏๅœๆญขใ—ใฆๅฐ‹ใญใ‚‹ใ€‚"
        }
        (Locale::ZhHans, AutonomyPreference::Cautious) => {
            "ๅœจ็ผ–่พ‘ๆ–‡ไปถใ€่ฟ่กŒๅ‘ฝไปคๆˆ–ไบงๅ“้€‰ๆ‹ฉไธๆ˜Ž็กฎๅ‰๏ผŒๅ€พๅ‘ๅ…ˆๅœไธ‹่ฏข้—ฎใ€‚"
        }
        (Locale::ZhHans, AutonomyPreference::Balanced) => {
            "ๆธ…ๆ™ฐไฝŽ้ฃŽ้™ฉไปปๅŠกๅฏ็›ดๆŽฅ่กŒๅŠจ๏ผ›้‡ๅˆฐ้ฃŽ้™ฉใ€็ ดๅๆ€งๆˆ–ๆญงไน‰ๆ—ถๅ…ˆ็กฎ่ฎคใ€‚"
        }
        (Locale::ZhHans, AutonomyPreference::Autonomous) => {
            "ๅฏๆ‰น้‡ๅค„็†ๅฎ‰ๅ…จ็š„ๅธธ่ง„ๅทฅไฝœ๏ผŒไฝ†้‡ๅˆฐ็ ดๅๆ€งใ€ๅ‡ญๆฎใ€ๅ‘ๅธƒใ€้ซ˜ๆˆๆœฌใ€ๆณ•ๅพ‹ๆˆ–ๅฎ‰ๅ…จ้ฃŽ้™ฉๆ—ถๅœๆญข่ฏข้—ฎใ€‚"
        }
        (Locale::ZhHant, AutonomyPreference::Cautious) => {
            "ๅœจ็ทจ่ผฏๆช”ๆกˆใ€ๅŸท่กŒๅ‘ฝไปคๆˆ–็”ขๅ“้ธๆ“‡ไธๆ˜Ž็ขบๅ‰๏ผŒๅ‚พๅ‘ๅ…ˆๅœไธ‹่ฉขๅ•ใ€‚"
        }
        (Locale::ZhHant, AutonomyPreference::Balanced) => {
            "ๆธ…ๆ™ฐไฝŽ้ขจ้šชไปปๅ‹™ๅฏ็›ดๆŽฅ่กŒๅ‹•๏ผ›้‡ๅˆฐ้ขจ้šชใ€็ ดๅฃžๆ€งๆˆ–ๆญง็พฉๆ™‚ๅ…ˆ็ขบ่ชใ€‚"
        }
        (Locale::ZhHant, AutonomyPreference::Autonomous) => {
            "ๅฏๆ‰น้‡่™•็†ๅฎ‰ๅ…จ็š„ๅธธ่ฆๅทฅไฝœ๏ผŒไฝ†้‡ๅˆฐ็ ดๅฃžๆ€งใ€ๆ†‘ๆ“šใ€็™ผๅธƒใ€้ซ˜ๆˆๆœฌใ€ๆณ•ๅพ‹ๆˆ–ๅฎ‰ๅ…จ้ขจ้šชๆ™‚ๅœๆญข่ฉขๅ•ใ€‚"
        }
        (Locale::PtBr, AutonomyPreference::Cautious) => {
            "Pare e pergunte antes de editar arquivos, rodar comandos ou escolher entre caminhos ambรญguos de produto."
        }
        (Locale::PtBr, AutonomyPreference::Balanced) => {
            "Aja diretamente em tarefas claras e de baixo risco; confirme antes de aรงรตes arriscadas, destrutivas ou ambรญguas."
        }
        (Locale::PtBr, AutonomyPreference::Autonomous) => {
            "Agrupe trabalho seguro de rotina, mas pare para aรงรตes destrutivas, credenciais, publicaรงรฃo, alto custo, legais ou de seguranรงa."
        }
        (Locale::Es419, AutonomyPreference::Cautious) => {
            "Detente y pregunta antes de editar archivos, ejecutar comandos o elegir entre caminos ambiguos de producto."
        }
        (Locale::Es419, AutonomyPreference::Balanced) => {
            "Actรบa directamente en tareas claras y de bajo riesgo; confirma antes de acciones riesgosas, destructivas o ambiguas."
        }
        (Locale::Es419, AutonomyPreference::Autonomous) => {
            "Agrupa trabajo seguro de rutina, pero detente ante acciones destructivas, credenciales, publicaciรณn, alto costo, legales o de seguridad."
        }
        (Locale::Vi, AutonomyPreference::Cautious) => {
            "Dแปซng vร  hแปi trฦฐแป›c khi sแปญa tแป‡p, chแบกy lแป‡nh hoแบทc chแปn giแปฏa ฤ‘ฦฐแปng sแบฃn phแบฉm mฦก hแป“."
        }
        (Locale::Vi, AutonomyPreference::Balanced) => {
            "Hร nh ฤ‘แป™ng trแปฑc tiแบฟp vแป›i viแป‡c rรต, rแปงi ro thแบฅp; xรกc nhแบญn trฦฐแป›c viแป‡c rแปงi ro, phรก hแปงy hoแบทc mฦก hแป“."
        }
        (Locale::Vi, AutonomyPreference::Autonomous) => {
            "Gแป™p viแป‡c thฦฐแปng lแป‡ an toร n, nhฦฐng dแปซng vแป›i thao tรกc phรก hแปงy, thรดng tin xรกc thแปฑc, xuแบฅt bแบฃn, chi phรญ cao, phรกp lรฝ hoแบทc bแบฃo mแบญt."
        }
        (Locale::Ko, AutonomyPreference::Cautious) => {
            "ํŒŒ์ผ ์ˆ˜์ •, ๋ช…๋ น์–ด ์‹คํ–‰, ์• ๋งคํ•œ ์ œํ’ˆ ์„ ํƒ ์ „์— ๋ฉˆ์ถ”๊ณ  ๋ฌผ์–ด๋ณธ๋‹ค."
        }
        (Locale::Ko, AutonomyPreference::Balanced) => {
            "๋ช…ํ™•ํ•˜๊ณ  ์œ„ํ—˜์ด ๋‚ฎ์€ ์ž‘์—…์€ ๋ฐ”๋กœ ์ง„ํ–‰ํ•˜๊ณ , ์œ„ํ—˜ํ•˜๊ฑฐ๋‚˜ ํŒŒ๊ดด์ ์ด๊ฑฐ๋‚˜ ์• ๋งคํ•œ ์ž‘์—…์€ ๋จผ์ € ํ™•์ธํ•œ๋‹ค."
        }
        (Locale::Ko, AutonomyPreference::Autonomous) => {
            "์•ˆ์ „ํ•œ ์ •ํ˜• ์ž‘์—…์€ ๋ชจ์•„์„œ ์ง„ํ–‰ํ•˜๋˜, ํŒŒ๊ดด์ ์ด๊ฑฐ๋‚˜ ์ž๊ฒฉ ์ฆ๋ช…, ๊ฒŒ์‹œ, ๊ณ ๋น„์šฉ, ๋ฒ•์ , ๋ณด์•ˆ ์œ„ํ—˜์ด ์žˆ๋Š” ์ž‘์—…์—์„œ๋Š” ๋ฉˆ์ถ”๊ณ  ๋ฌผ์–ด๋ณธ๋‹ค."
        }
        (Locale::Ca, AutonomyPreference::Cautious) => {
            "Atura't i pregunta abans d'editar fitxers, executar ordres o triar entre camins de producte ambigus."
        }
        (Locale::Ca, AutonomyPreference::Balanced) => {
            "Actua directament en tasques clares i de baix risc; confirma abans d'accions arriscades, destructives o ambigรผes."
        }
        (Locale::Ca, AutonomyPreference::Autonomous) => {
            "Agrupa la feina rutinร ria segura, perรฒ atura't davant accions destructives, amb credencials, de publicaciรณ, d'alt cost o amb risc legal o de seguretat."
        }
        (Locale::De, AutonomyPreference::Cautious) => {
            "Halte an und frage, bevor du Dateien bearbeitest, Befehle ausfรผhrst oder zwischen mehrdeutigen Produktwegen wรคhlst."
        }
        (Locale::De, AutonomyPreference::Balanced) => {
            "Handle direkt bei klaren, risikoarmen Aufgaben; bestรคtige vor riskanten, destruktiven oder mehrdeutigen Aktionen."
        }
        (Locale::De, AutonomyPreference::Autonomous) => {
            "Bรผndle sichere Routinearbeit, aber halte an bei destruktiven, zugangsdatenbezogenen, verรถffentlichenden, kostspieligen, rechtlichen oder sicherheitskritischen Aktionen."
        }
        (Locale::Fr, AutonomyPreference::Cautious) => {
            "Arrรชtez et demandez avant de modifier des fichiers, d'exรฉcuter des commandes ou de choisir entre des voies produit ambiguรซs."
        }
        (Locale::Fr, AutonomyPreference::Balanced) => {
            "Agissez directement sur les tรขches claires et ร  faible risque ; confirmez avant les actions risquรฉes, destructives ou ambiguรซs."
        }
        (Locale::Fr, AutonomyPreference::Autonomous) => {
            "Regroupez le travail de routine sรปr, mais arrรชtez devant les actions destructives, impliquant des identifiants, des publications, coรปteuses, juridiques ou ร  risque de sรฉcuritรฉ."
        }
        (Locale::Id, AutonomyPreference::Cautious) => {
            "Berhenti dan tanya sebelum mengedit file, menjalankan perintah, atau memilih di antara jalur produk yang ambigu."
        }
        (Locale::Id, AutonomyPreference::Balanced) => {
            "Bertindak langsung pada tugas yang jelas dan berisiko rendah; konfirmasi sebelum tindakan berisiko, destruktif, atau ambigu."
        }
        (Locale::Id, AutonomyPreference::Autonomous) => {
            "Kelompokkan pekerjaan rutin yang aman, tetapi berhenti untuk tindakan destruktif, terkait kredensial, publikasi, mahal, hukum, atau berisiko keamanan."
        }
        (Locale::Hi, AutonomyPreference::Cautious) => {
            "เคซเคผเคพเค‡เคฒเฅ‡เค‚ เคธเค‚เคชเคพเคฆเคฟเคค เค•เคฐเคจเฅ‡, เค•เคฎเคพเค‚เคก เคšเคฒเคพเคจเฅ‡ เคฏเคพ เค…เคธเฅเคชเคทเฅเคŸ เค‰เคคเฅเคชเคพเคฆ เคฎเคพเคฐเฅเค—เฅ‹เค‚ เคฎเฅ‡เค‚ เคšเฅเคจเคจเฅ‡ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคฐเฅเค•เค•เคฐ เคชเฅ‚เค›เฅ‡เค‚เฅค"
        }
        (Locale::Hi, AutonomyPreference::Balanced) => {
            "เคธเฅเคชเคทเฅเคŸ, เค•เคฎ-เคœเฅ‹เค–เคฟเคฎ เคตเคพเคฒเฅ‡ เค•เคพเคฐเฅเคฏเฅ‹เค‚ เคชเคฐ เคธเฅ€เคงเฅ‡ เค•เคพเคฐเฅเคฏ เค•เคฐเฅ‡เค‚; เคœเฅ‹เค–เคฟเคฎเคชเฅ‚เคฐเฅเคฃ, เคตเคฟเคจเคพเคถเค•เคพเคฐเฅ€ เคฏเคพ เค…เคธเฅเคชเคทเฅเคŸ เค•เคพเคฐเฅเคฏเฅ‹เค‚ เคธเฅ‡ เคชเคนเคฒเฅ‡ เคชเฅเคทเฅเคŸเคฟ เค•เคฐเฅ‡เค‚เฅค"
        }
        (Locale::Hi, AutonomyPreference::Autonomous) => {
            "เคธเฅเคฐเค•เฅเคทเคฟเคค เคจเคฟเคฏเคฎเคฟเคค เค•เคพเคฎ เคเค• เคธเคพเคฅ เค•เคฐเฅ‡เค‚, เคฒเฅ‡เค•เคฟเคจ เคตเคฟเคจเคพเคถเค•เคพเคฐเฅ€, เค•เฅเคฐเฅ‡เคกเฅ‡เค‚เคถเคฟเคฏเคฒ, เคชเฅเคฐเค•เคพเคถเคจ, เค‰เคšเฅเคš-เคฒเคพเค—เคค, เค•เคพเคจเฅ‚เคจเฅ€ เคฏเคพ เคธเฅเคฐเค•เฅเคทเคพ-เคœเฅ‹เค–เคฟเคฎ เค•เคพเคฐเฅเคฏเฅ‹เค‚ เคชเคฐ เคฐเฅเค•เค•เคฐ เคชเฅ‚เค›เฅ‡เค‚เฅค"
        }
        (Locale::Ru, AutonomyPreference::Cautious) => {
            "ะžัั‚ะฐะฝะพะฒะธั‚ะตััŒ ะธ ัะฟั€ะพัะธั‚ะต ะฟะตั€ะตะด ั€ะตะดะฐะบั‚ะธั€ะพะฒะฐะฝะธะตะผ ั„ะฐะนะปะพะฒ, ะทะฐะฟัƒัะบะพะผ ะบะพะผะฐะฝะด ะธะปะธ ะฒั‹ะฑะพั€ะพะผ ะผะตะถะดัƒ ะฝะตะพะดะฝะพะทะฝะฐั‡ะฝั‹ะผะธ ะฟั€ะพะดัƒะบั‚ะพะฒั‹ะผะธ ะฟัƒั‚ัะผะธ."
        }
        (Locale::Ru, AutonomyPreference::Balanced) => {
            "ะ”ะตะนัั‚ะฒัƒะนั‚ะต ะฝะฐะฟั€ัะผัƒัŽ ะฒ ััะฝั‹ั… ะฝะธะทะบะพั€ะธัะบะพะฒั‹ั… ะทะฐะดะฐั‡ะฐั…; ะฟะพะดั‚ะฒะตั€ะถะดะฐะนั‚ะต ะฟะตั€ะตะด ั€ะธัะบะพะฒะฐะฝะฝั‹ะผะธ, ะดะตัั‚ั€ัƒะบั‚ะธะฒะฝั‹ะผะธ ะธะปะธ ะฝะตะพะดะฝะพะทะฝะฐั‡ะฝั‹ะผะธ ะดะตะนัั‚ะฒะธัะผะธ."
        }
        (Locale::Ru, AutonomyPreference::Autonomous) => {
            "ะ“ั€ัƒะฟะฟะธั€ัƒะนั‚ะต ะฑะตะทะพะฟะฐัะฝัƒัŽ ั€ัƒั‚ะธะฝะฝัƒัŽ ั€ะฐะฑะพั‚ัƒ, ะฝะพ ะพัั‚ะฐะฝะฐะฒะปะธะฒะฐะนั‚ะตััŒ ะฟะตั€ะตะด ะดะตัั‚ั€ัƒะบั‚ะธะฒะฝั‹ะผะธ ะดะตะนัั‚ะฒะธัะผะธ, ะดะตะนัั‚ะฒะธัะผะธ ั ัƒั‡ั‘ั‚ะฝั‹ะผะธ ะดะฐะฝะฝั‹ะผะธ, ะฟัƒะฑะปะธะบะฐั†ะธัะผะธ, ะดะพั€ะพะณะธะผะธ, ัŽั€ะธะดะธั‡ะตัะบะธะผะธ ะธะปะธ ัƒะณั€ะพะถะฐัŽั‰ะธะผะธ ะฑะตะทะพะฟะฐัะฝะพัั‚ะธ ะพะฟะตั€ะฐั†ะธัะผะธ."
        }
        (Locale::Uk, AutonomyPreference::Cautious) => {
            "ะ—ัƒะฟะธะฝั–ั‚ัŒัั ะน ะทะฐะฟะธั‚ะฐะนั‚ะต ะฟะตั€ะตะด ั€ะตะดะฐะณัƒะฒะฐะฝะฝัะผ ั„ะฐะนะปั–ะฒ, ะทะฐะฟัƒัะบะพะผ ะบะพะผะฐะฝะด ะฐะฑะพ ะฒะธะฑะพั€ะพะผ ะผั–ะถ ะฝะตะพะดะฝะพะทะฝะฐั‡ะฝะธะผะธ ะฟั€ะพะดัƒะบั‚ะพะฒะธะผะธ ัˆะปัั…ะฐะผะธ."
        }
        (Locale::Uk, AutonomyPreference::Balanced) => {
            "ะ”ั–ะนั‚ะต ะฑะตะทะฟะพัะตั€ะตะดะฝัŒะพ ะฒ ั‡ั–ั‚ะบะธั… ะฝะธะทัŒะบะพั€ะธะทะธะบะพะฒะธั… ะทะฐะฒะดะฐะฝะฝัั…; ะฟั–ะดั‚ะฒะตั€ะดะถัƒะนั‚ะต ะฟะตั€ะตะด ั€ะธะทะธะบะพะฒะฐะฝะธะผะธ, ั€ัƒะนะฝั–ะฒะฝะธะผะธ ั‡ะธ ะฝะตะพะดะฝะพะทะฝะฐั‡ะฝะธะผะธ ะดั–ัะผะธ."
        }
        (Locale::Uk, AutonomyPreference::Autonomous) => {
            "ะ“ั€ัƒะฟัƒะนั‚ะต ะฑะตะทะฟะตั‡ะฝัƒ ั€ัƒั‚ะธะฝะฝัƒ ั€ะพะฑะพั‚ัƒ, ะฐะปะต ะทัƒะฟะธะฝัะนั‚ะตัั ะฟะตั€ะตะด ั€ัƒะนะฝั–ะฒะฝะธะผะธ ะดั–ัะผะธ, ะดั–ัะผะธ ะท ะพะฑะปั–ะบะพะฒะธะผะธ ะดะฐะฝะธะผะธ, ะฟัƒะฑะปั–ะบะฐั†ั–ัะผะธ, ะดะพั€ะพะณะธะผะธ, ัŽั€ะธะดะธั‡ะฝะธะผะธ ั‡ะธ ะฝะตะฑะตะทะฟะตั‡ะฝะธะผะธ ะดะปั ะฑะตะทะฟะตะบะธ ะพะฟะตั€ะฐั†ั–ัะผะธ."
        }
        (_, AutonomyPreference::Cautious) => {
            "Stop and ask before editing files, running commands, or choosing between ambiguous product paths."
        }
        (_, AutonomyPreference::Balanced) => {
            "Do clear, low-risk work; ask before risky, destructive, or unclear work."
        }
        (_, AutonomyPreference::Autonomous) => {
            "Batch routine safe work, then stop for destructive, credential, publishing, high-cost, legal, or security-risk actions."
        }
        (_, AutonomyPreference::Unspecified) => "No standing initiative preference was selected.",
    }
}

fn authority_priority(locale: Locale) -> &'static str {
    match locale {
        Locale::Ja => {
            "็พๅœจใฎใƒฆใƒผใ‚ถใƒผ่ฆๆฑ‚ใจใƒฉใ‚คใƒ–ใƒ„ใƒผใƒซ่จผๆ‹ ใฏใ€ใƒกใƒขใƒชใ€ๅคใ„ๅผ•ใ็ถ™ใŽใ€ๆŽจๆธฌใ‚ˆใ‚Šๅ„ชๅ…ˆใ•ใ‚Œใ‚‹ใ€‚"
        }
        Locale::ZhHans => "ๅฝ“ๅ‰็”จๆˆท่ฏทๆฑ‚ๅ’Œๅฎžๆ—ถๅทฅๅ…ท่ฏๆฎไผ˜ๅ…ˆไบŽ่ฎฐๅฟ†ใ€้™ˆๆ—งไบคๆŽฅๅ’Œ็Œœๆต‹ใ€‚",
        Locale::ZhHant => "็›ฎๅ‰ไฝฟ็”จ่€…่ซ‹ๆฑ‚ๅ’Œๅณๆ™‚ๅทฅๅ…ท่ญ‰ๆ“šๅ„ชๅ…ˆๆ–ผ่จ˜ๆ†ถใ€้™ณ่ˆŠไบคๆŽฅๅ’Œ็Œœๆธฌใ€‚",
        Locale::PtBr => {
            "Pedidos atuais do usuรกrio e evidรชncia viva das ferramentas superam memรณria, handoffs antigos e palpites."
        }
        Locale::Es419 => {
            "Las solicitudes actuales del usuario y la evidencia viva de herramientas superan memoria, handoffs viejos y suposiciones."
        }
        Locale::Vi => {
            "Yรชu cแบงu hiแป‡n tแบกi cแปงa ngฦฐแปi dรนng vร  bแบฑng chแปฉng trแปฑc tiแบฟp tแปซ cรดng cแปฅ ฦฐu tiรชn hฦกn bแป™ nhแป›, handoff cลฉ vร  phแปng ฤ‘oรกn."
        }
        Locale::Ko => {
            "ํ˜„์žฌ ์‚ฌ์šฉ์ž ์š”์ฒญ๊ณผ ์‹ค์‹œ๊ฐ„ ๋„๊ตฌ ๊ทผ๊ฑฐ๋Š” ๋ฉ”๋ชจ๋ฆฌ, ์˜ค๋ž˜๋œ ์ธ๊ณ„ ์ž๋ฃŒ, ์ถ”์ธก๋ณด๋‹ค ์šฐ์„ ํ•œ๋‹ค."
        }
        Locale::Ca => {
            "Les peticions actuals de l'usuari i l'evidรจncia en directe de les eines prevalen sobre la memรฒria, els traspasos antics i les conjectures."
        }
        Locale::De => {
            "Aktuelle Nutzeranfragen und Live-Werkzeugnachweise haben Vorrang vor Speicher, veralteten รœbergaben und Vermutungen."
        }
        Locale::Fr => {
            "Les demandes actuelles de l'utilisateur et les preuves directes des outils priment sur la mรฉmoire, les anciens transferts et les suppositions."
        }
        Locale::Id => {
            "Permintaan pengguna saat ini dan bukti langsung dari alat mengalahkan memori, handoff lama, dan tebakan."
        }
        Locale::Hi => "เคตเคฐเฅเคคเคฎเคพเคจ เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เค…เคจเฅเคฐเฅ‹เคง เค”เคฐ เคฒเคพเค‡เคต เคŸเฅ‚เคฒ เคธเคพเค•เฅเคทเฅเคฏ เคฎเฅ‡เคฎเฅ‹เคฐเฅ€, เคชเฅเคฐเคพเคจเฅ‡ เคนเฅˆเค‚เคกเค‘เคซเคผ เค”เคฐ เค…เคจเฅเคฎเคพเคจเฅ‹เค‚ เคธเฅ‡ เคŠเคชเคฐ เคนเฅˆเค‚เฅค",
        Locale::Ru => {
            "ะขะตะบัƒั‰ะธะต ะทะฐะฟั€ะพัั‹ ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั ะธ ะถะธะฒั‹ะต ัะฒะธะดะตั‚ะตะปัŒัั‚ะฒะฐ ะธะฝัั‚ั€ัƒะผะตะฝั‚ะพะฒ ะฒะฐะถะฝะตะต ะฟะฐะผัั‚ะธ, ัƒัั‚ะฐั€ะตะฒัˆะธั… ะฟะตั€ะตะดะฐั‚ะพั‡ะฝั‹ั… ะทะฐะผะตั‚ะพะบ ะธ ะดะพะณะฐะดะพะบ."
        }
        Locale::Uk => {
            "ะŸะพั‚ะพั‡ะฝั– ะทะฐะฟะธั‚ะธ ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ ั‚ะฐ ะถะธะฒั– ัะฒั–ะดั‡ะตะฝะฝั ั–ะฝัั‚ั€ัƒะผะตะฝั‚ั–ะฒ ะฒะฐะถะปะธะฒั–ัˆั– ะทะฐ ะฟะฐะผ'ัั‚ัŒ, ะทะฐัั‚ะฐั€ั–ะปั– ะฟะตั€ะตะดะฐั‚ะพั‡ะฝั– ะฝะพั‚ะฐั‚ะบะธ ะน ะทะดะพะณะฐะดะบะธ."
        }
        _ => {
            "Current user requests and live tool evidence outrank memory, stale handoffs, and guesses."
        }
    }
}

fn bounded_freeform_note(input: &str, max_chars: usize) -> String {
    input
        .chars()
        .filter_map(|ch| {
            if ch == '\t' {
                Some(' ')
            } else if ch == '\n' || !ch.is_control() {
                Some(ch)
            } else {
                None
            }
        })
        .take(max_chars)
        .collect::<String>()
        .trim()
        .to_string()
}

fn compact_freeform_preview(note: &str) -> String {
    let compact = note.split_whitespace().collect::<Vec<_>>().join(" ");
    let mut preview = compact.chars().take(96).collect::<String>();
    if compact.chars().count() > 96 {
        preview.push_str("...");
    }
    preview
}

fn freeform_note_line(locale: Locale, note: &str, editing: bool) -> Line<'static> {
    let preview = compact_freeform_preview(note);
    let text = match (locale, editing, preview.is_empty()) {
        (Locale::Ja, true, true) => {
            "F ่‡ช็”ฑๅŽŸๅ‰‡๏ผš็ทจ้›†ไธญ - ๆœ‰็•ŒใฎๅŽŸๅ‰‡ใ‚’ๅ…ฅๅŠ›ใพใŸใฏ่ฒผใ‚Šไป˜ใ‘ใ€Enter ใงๅฎŒไบ†".to_string()
        }
        (Locale::Ja, true, false) => format!("F ่‡ช็”ฑๅŽŸๅ‰‡๏ผš็ทจ้›†ไธญ - {preview}"),
        (Locale::Ja, false, true) => "F ่‡ช็”ฑๅŽŸๅ‰‡๏ผšF ใงๆœ‰็•ŒใฎๅŽŸๅ‰‡ใ‚’ๅ…ฅๅŠ›ใพใŸใฏ่ฒผใ‚Šไป˜ใ‘".to_string(),
        (Locale::Ja, false, false) => format!("F ่‡ช็”ฑๅŽŸๅ‰‡๏ผš{preview}"),
        (Locale::ZhHans, true, true) => {
            "F ่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšๆญฃๅœจ็ผ–่พ‘ - ่พ“ๅ…ฅๆˆ–็ฒ˜่ดดๆ˜Ž็กฎ็š„ๅ‡†ๅˆ™๏ผŒEnter ๅฎŒๆˆ".to_string()
        }
        (Locale::ZhHans, true, false) => format!("F ่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšๆญฃๅœจ็ผ–่พ‘ - {preview}"),
        (Locale::ZhHans, false, true) => {
            "F ่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผšๆŒ‰ F ่พ“ๅ…ฅๆˆ–็ฒ˜่ดด่‡ชๅทฑ็š„ๆ˜Ž็กฎๅ‡†ๅˆ™".to_string()
        }
        (Locale::ZhHans, false, false) => format!("F ่‡ชๅฎšไน‰ๅ‡†ๅˆ™๏ผš{preview}"),
        (Locale::ZhHant, true, true) => {
            "F ่‡ช็”ฑๅŽŸๅ‰‡๏ผšๆญฃๅœจ็ทจ่ผฏ - ่ผธๅ…ฅๆˆ–่ฒผไธŠๆœ‰็•ŒๅŽŸๅ‰‡๏ผŒEnter ๅฎŒๆˆ".to_string()
        }
        (Locale::ZhHant, true, false) => format!("F ่‡ช็”ฑๅŽŸๅ‰‡๏ผšๆญฃๅœจ็ทจ่ผฏ - {preview}"),
        (Locale::ZhHant, false, true) => "F ่‡ช็”ฑๅŽŸๅ‰‡๏ผšๆŒ‰ F ่ผธๅ…ฅๆˆ–่ฒผไธŠ่‡ชๅทฑ็š„ๆœ‰็•ŒๅŽŸๅ‰‡".to_string(),
        (Locale::ZhHant, false, false) => format!("F ่‡ช็”ฑๅŽŸๅ‰‡๏ผš{preview}"),
        (Locale::PtBr, true, true) => {
            "F Princรญpio livre: editando - digite ou cole um princรญpio limitado, Enter para concluir".to_string()
        }
        (Locale::PtBr, true, false) => format!("F Princรญpio livre: editando - {preview}"),
        (Locale::PtBr, false, true) => {
            "F Princรญpio livre: pressione F para digitar ou colar um princรญpio limitado".to_string()
        }
        (Locale::PtBr, false, false) => format!("F Princรญpio livre: {preview}"),
        (Locale::Es419, true, true) => {
            "F Principio libre: editando - escribe o pega un principio acotado, Enter para terminar".to_string()
        }
        (Locale::Es419, true, false) => format!("F Principio libre: editando - {preview}"),
        (Locale::Es419, false, true) => {
            "F Principio libre: presiona F para escribir o pegar un principio acotado".to_string()
        }
        (Locale::Es419, false, false) => format!("F Principio libre: {preview}"),
        (Locale::Vi, true, true) => {
            "F Nguyรชn tแบฏc tแปฑ do: ฤ‘ang sแปญa - nhแบญp hoแบทc dรกn nguyรชn tแบฏc cรณ giแป›i hแบกn, Enter ฤ‘แปƒ xong".to_string()
        }
        (Locale::Vi, true, false) => format!("F Nguyรชn tแบฏc tแปฑ do: ฤ‘ang sแปญa - {preview}"),
        (Locale::Vi, false, true) => {
            "F Nguyรชn tแบฏc tแปฑ do: nhแบฅn F ฤ‘แปƒ nhแบญp hoแบทc dรกn nguyรชn tแบฏc cรณ giแป›i hแบกn".to_string()
        }
        (Locale::Vi, false, false) => format!("F Nguyรชn tแบฏc tแปฑ do: {preview}"),
        (Locale::Ko, true, true) => {
            "F ์ž์œ  ์›์น™: ํŽธ์ง‘ ์ค‘ - ์ œํ•œ๋œ ์›์น™์„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋ถ™์—ฌ๋„ฃ๊ณ  Enter๋กœ ์™„๋ฃŒ".to_string()
        }
        (Locale::Ko, true, false) => format!("F ์ž์œ  ์›์น™: ํŽธ์ง‘ ์ค‘ - {preview}"),
        (Locale::Ko, false, true) => "F ์ž์œ  ์›์น™: F๋ฅผ ๋ˆŒ๋Ÿฌ ์ œํ•œ๋œ ์›์น™์„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋ถ™์—ฌ๋„ฃ๊ธฐ".to_string(),
        (Locale::Ko, false, false) => format!("F ์ž์œ  ์›์น™: {preview}"),
        (Locale::Ca, true, true) => {
            "F Paraules prรฒpies: editant - escriu o enganxa un principi acotat, Enter per acabar".to_string()
        }
        (Locale::Ca, true, false) => format!("F Paraules prรฒpies: editant - {preview}"),
        (Locale::Ca, false, true) => {
            "F Paraules prรฒpies: prem F per escriure o enganxar un principi acotat".to_string()
        }
        (Locale::Ca, false, false) => format!("F Paraules prรฒpies: {preview}"),
        (Locale::De, true, true) => {
            "F Eigene Worte: Bearbeitung - tippe oder fรผge ein begrenztes Prinzip ein, Enter zum Abschluss".to_string()
        }
        (Locale::De, true, false) => format!("F Eigene Worte: Bearbeitung - {preview}"),
        (Locale::De, false, true) => {
            "F Eigene Worte: F drรผcken, um ein begrenztes Prinzip zu tippen oder einzufรผgen".to_string()
        }
        (Locale::De, false, false) => format!("F Eigene Worte: {preview}"),
        (Locale::Fr, true, true) => {
            "F Vos mots : รฉdition - tapez ou collez un principe bornรฉ, Entrรฉe pour terminer".to_string()
        }
        (Locale::Fr, true, false) => format!("F Vos mots : รฉdition - {preview}"),
        (Locale::Fr, false, true) => {
            "F Vos mots : appuyez sur F pour taper ou coller un principe bornรฉ".to_string()
        }
        (Locale::Fr, false, false) => format!("F Vos mots : {preview}"),
        (Locale::Id, true, true) => {
            "F Kata sendiri: mengedit - ketik atau tempel prinsip terbatas, Enter untuk selesai".to_string()
        }
        (Locale::Id, true, false) => format!("F Kata sendiri: mengedit - {preview}"),
        (Locale::Id, false, true) => {
            "F Kata sendiri: tekan F untuk mengetik atau menempel prinsip terbatas".to_string()
        }
        (Locale::Id, false, false) => format!("F Kata sendiri: {preview}"),
        (Locale::Hi, true, true) => {
            "F เค…เคชเคจเฅ‡ เคถเคฌเฅเคฆ: เคธเค‚เคชเคพเคฆเคจ เคœเคพเคฐเฅ€ - เคธเฅ€เคฎเคฟเคค เคธเคฟเคฆเฅเคงเคพเค‚เคค เคŸเคพเค‡เคช เคฏเคพ เคชเฅ‡เคธเฅเคŸ เค•เคฐเฅ‡เค‚, Enter เคธเฅ‡ เคธเคฎเคพเคชเฅเคค เค•เคฐเฅ‡เค‚".to_string()
        }
        (Locale::Hi, true, false) => format!("F เค…เคชเคจเฅ‡ เคถเคฌเฅเคฆ: เคธเค‚เคชเคพเคฆเคจ เคœเคพเคฐเฅ€ - {preview}"),
        (Locale::Hi, false, true) => {
            "F เค…เคชเคจเฅ‡ เคถเคฌเฅเคฆ: เคธเฅ€เคฎเคฟเคค เคธเคฟเคฆเฅเคงเคพเค‚เคค เคŸเคพเค‡เคช เคฏเคพ เคชเฅ‡เคธเฅเคŸ เค•เคฐเคจเฅ‡ เค•เฅ‡ เคฒเคฟเค F เคฆเคฌเคพเคเค".to_string()
        }
        (Locale::Hi, false, false) => format!("F เค…เคชเคจเฅ‡ เคถเคฌเฅเคฆ: {preview}"),
        (Locale::Ru, true, true) => {
            "F ะกะฒะพะธ ัะปะพะฒะฐ: ั€ะตะดะฐะบั‚ะธั€ะพะฒะฐะฝะธะต - ะฒะฒะตะดะธั‚ะต ะธะปะธ ะฒัั‚ะฐะฒัŒั‚ะต ะพะณั€ะฐะฝะธั‡ะตะฝะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ, Enter ะดะปั ะทะฐะฒะตั€ัˆะตะฝะธั".to_string()
        }
        (Locale::Ru, true, false) => format!("F ะกะฒะพะธ ัะปะพะฒะฐ: ั€ะตะดะฐะบั‚ะธั€ะพะฒะฐะฝะธะต - {preview}"),
        (Locale::Ru, false, true) => {
            "F ะกะฒะพะธ ัะปะพะฒะฐ: ะฝะฐะถะผะธั‚ะต F, ั‡ั‚ะพะฑั‹ ะฒะฒะตัั‚ะธ ะธะปะธ ะฒัั‚ะฐะฒะธั‚ัŒ ะพะณั€ะฐะฝะธั‡ะตะฝะฝั‹ะน ะฟั€ะธะฝั†ะธะฟ".to_string()
        }
        (Locale::Ru, false, false) => format!("F ะกะฒะพะธ ัะปะพะฒะฐ: {preview}"),
        (Locale::Uk, true, true) => {
            "F ะกะฒะพั— ัะปะพะฒะฐ: ั€ะตะดะฐะณัƒะฒะฐะฝะฝั - ะฒะฒะตะดั–ั‚ัŒ ะฐะฑะพ ะฒัั‚ะฐะฒั‚ะต ะพะฑะผะตะถะตะฝะธะน ะฟั€ะธะฝั†ะธะฟ, Enter ะดะปั ะทะฐะฒะตั€ัˆะตะฝะฝั".to_string()
        }
        (Locale::Uk, true, false) => format!("F ะกะฒะพั— ัะปะพะฒะฐ: ั€ะตะดะฐะณัƒะฒะฐะฝะฝั - {preview}"),
        (Locale::Uk, false, true) => {
            "F ะกะฒะพั— ัะปะพะฒะฐ: ะฝะฐั‚ะธัะฝั–ั‚ัŒ F, ั‰ะพะฑ ะฒะฒะตัั‚ะธ ะฐะฑะพ ะฒัั‚ะฐะฒะธั‚ะธ ะพะฑะผะตะถะตะฝะธะน ะฟั€ะธะฝั†ะธะฟ".to_string()
        }
        (Locale::Uk, false, false) => format!("F ะกะฒะพั— ัะปะพะฒะฐ: {preview}"),
        (_, true, true) => {
            "F Own words: editing - type or paste a bounded principle, Enter to finish".to_string()
        }
        (_, true, false) => format!("F Own words: editing - {preview}"),
        (_, false, true) => "F Own words: press F to type or paste a bounded principle".to_string(),
        (_, false, false) => format!("F Own words: {preview}"),
    };
    let style = if editing || !preview.is_empty() {
        Style::default().fg(palette::WHALE_HUMAN)
    } else {
        Style::default().fg(palette::TEXT_MUTED)
    };
    Line::from(Span::styled(text, style))
}

impl SetupWizardView {
    #[must_use]
    pub fn new_for_app(app: &App, config: &Config) -> Self {
        Self::new_with_facts(
            load_setup_state_for_app(app, config),
            app.ui_locale,
            SetupRuntimeFacts::from_app_config(app, config),
        )
    }

    #[must_use]
    pub fn new_checkpoint_for_app(app: &App, config: &Config) -> Self {
        Self::new_checkpoint_with_facts(
            load_setup_state_for_app(app, config),
            app.ui_locale,
            SetupRuntimeFacts::from_app_config(app, config),
        )
    }

    #[must_use]
    pub fn new_for_app_at(app: &App, config: &Config, step: SetupStep) -> Self {
        Self::new_at_with_facts(
            load_setup_state_for_app(app, config),
            app.ui_locale,
            step,
            SetupRuntimeFacts::from_app_config(app, config),
        )
    }

    #[must_use]
    pub fn selected_step(&self) -> SetupStep {
        STEP_SPECS[self.selected].id()
    }

    fn selected_spec(&self) -> &'static dyn SetupWizardStep {
        &STEP_SPECS[self.selected]
    }

    fn new_with_facts(state: SetupState, locale: Locale, facts: SetupRuntimeFacts) -> Self {
        let selected = progressive_initial_step_index(&state, &facts);
        Self {
            state,
            selected,
            locale,
            progressive_guide: true,
            details_expanded: false,
            facts,
            guided_draft: GuidedConstitutionDraft::default(),
            constitution_advanced: false,
            freeform_note: String::new(),
            editing_freeform_note: false,
            guided_preview_seen: false,
            existing_preview_seen: false,
            model_draft: None,
            model_draft_label: None,
            runtime_preset: SetupRuntimePreset::default(),
            runtime_preset_preview_seen: false,
            body_scroll: 0,
        }
    }

    fn new_at_with_facts(
        state: SetupState,
        locale: Locale,
        step: SetupStep,
        facts: SetupRuntimeFacts,
    ) -> Self {
        Self {
            state,
            selected: visible_step_index(step),
            locale,
            progressive_guide: false,
            details_expanded: false,
            facts,
            guided_draft: GuidedConstitutionDraft::default(),
            constitution_advanced: false,
            freeform_note: String::new(),
            editing_freeform_note: false,
            guided_preview_seen: false,
            existing_preview_seen: false,
            model_draft: None,
            model_draft_label: None,
            runtime_preset: SetupRuntimePreset::default(),
            runtime_preset_preview_seen: false,
            body_scroll: 0,
        }
    }

    fn new_checkpoint_with_facts(
        state: SetupState,
        locale: Locale,
        facts: SetupRuntimeFacts,
    ) -> Self {
        Self::new_at_with_facts(state, locale, SetupStep::Constitution, facts)
    }

    fn surface_title(&self) -> String {
        tr(self.locale, MessageId::SetupWizardTitle).into_owned()
    }

    fn tools_relevant(&self) -> bool {
        self.facts.tools_mcp_needs_action || !self.facts.tools_mcp_result.contains("overall=off")
    }

    fn progressive_steps(&self) -> Vec<SetupStep> {
        let mut steps = vec![
            SetupStep::ProviderModel,
            SetupStep::TrustSandbox,
            SetupStep::RemoteRuntime,
        ];
        if self.tools_relevant() {
            steps.push(SetupStep::ToolsMcp);
        }
        steps.push(SetupStep::Verification);
        steps
    }

    fn move_next(&mut self) {
        if self.progressive_guide {
            let steps = self.progressive_steps();
            let position = steps
                .iter()
                .position(|step| *step == self.selected_step())
                .unwrap_or(0);
            let next = steps[(position + 1).min(steps.len().saturating_sub(1))];
            self.selected = visible_step_index(next);
        } else {
            self.selected = (self.selected + 1).min(STEP_SPECS.len().saturating_sub(1));
        }
        self.constitution_advanced = false;
        self.details_expanded = false;
        self.body_scroll = 0;
    }

    fn move_back(&mut self) {
        if self.progressive_guide {
            let steps = self.progressive_steps();
            let position = steps
                .iter()
                .position(|step| *step == self.selected_step())
                .unwrap_or(0);
            let previous = steps[position.saturating_sub(1)];
            self.selected = visible_step_index(previous);
        } else {
            self.selected = self.selected.saturating_sub(1);
        }
        self.constitution_advanced = false;
        self.details_expanded = false;
        self.body_scroll = 0;
    }

    fn commit_selected_status(
        &mut self,
        status: StepStatus,
        message_id: MessageId,
        advance: bool,
    ) -> ViewAction {
        let spec = self.selected_spec();
        let result = match status {
            StepStatus::Skipped => Some("skipped by user"),
            StepStatus::NeedsAction => Some("retry requested; needs action"),
            _ => None,
        };
        let mut entry = StepEntry::new(status, spec.required(), CONSTITUTION_CHECKPOINT_VERSION);
        if let Some(result) = result {
            entry = entry.with_result(result);
        }
        let mut state = self.state.clone();
        state.set_step(spec.id(), entry);
        if spec.id() == SetupStep::Constitution && status == StepStatus::Skipped {
            // `S` is a durable response to the versioned checkpoint, just like
            // choosing the explicit defer action. It only skips this setup
            // checkpoint, though; it must not replace an already active
            // bundled or custom Constitution choice. A fresh state has no
            // active choice, so keep the bundled floor by recording Deferred.
            let choice = if state.constitution_choice.is_explicit() {
                state.constitution_choice
            } else {
                ConstitutionChoice::Deferred
            };
            state.complete_constitution_checkpoint(CONSTITUTION_CHECKPOINT_VERSION, choice);
        }
        self.state = state.clone();
        if advance {
            self.move_next();
        }
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, message_id).to_string(),
        })
    }

    fn commit_language_review(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        state.constitution_language = Some(self.locale.tag().to_string());
        state.set_step(
            SetupStep::Language,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(format!("setup locale {}", self.locale.tag())),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupLanguageReviewed).to_string(),
        })
    }

    fn commit_provider_model_review(&mut self) -> ViewAction {
        let status = provider::step_status(self.facts.provider_ready);
        let mut state = self.state.clone();
        state.set_step(
            SetupStep::ProviderModel,
            provider::step_entry(
                self.facts.provider_ready,
                CONSTITUTION_CHECKPOINT_VERSION,
                self.facts.provider_result.clone(),
            ),
        );
        self.state = state.clone();
        self.move_next();
        let message_id = if status == StepStatus::Verified {
            MessageId::SetupProviderModelReviewed
        } else {
            MessageId::SetupProviderModelNeedsActionSaved
        };
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, message_id).to_string(),
        })
    }

    fn commit_runtime_posture_review(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        state.runtime_posture_source = RuntimePostureSource::Confirmed;
        state.set_step(
            SetupStep::TrustSandbox,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.runtime_result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupRuntimePostureReviewed).to_string(),
        })
    }

    fn operate_fleet_facts_ready(&self) -> bool {
        // Provider, capacity, and roster facts are configuration snapshots,
        // not proof of dispatch and terminal receipts. This release must never
        // persist an Operate-ready claim from those facts alone.
        false
    }

    fn commit_operate_fleet_review(&mut self) -> ViewAction {
        let status = if self.operate_fleet_facts_ready() {
            StepStatus::Verified
        } else {
            StepStatus::NeedsAction
        };
        let mut state = self.state.clone();
        state.set_step(
            SetupStep::OperateFleet,
            StepEntry::new(status, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.operate_result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        let message_id = if status == StepStatus::Verified {
            MessageId::SetupOperateReviewed
        } else {
            MessageId::SetupOperateNeedsActionSaved
        };
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, message_id).to_string(),
        })
    }

    fn commit_hotbar_review(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        state.set_step(
            SetupStep::Hotbar,
            StepEntry::new(StepStatus::Verified, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.hotbar_result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupHotbarReviewed).to_string(),
        })
    }

    fn commit_tools_mcp_review(&mut self) -> ViewAction {
        // Optional step: empty/off inventories settle as Optional; broken
        // configured tools record NeedsAction without blocking first-run.
        let status = if self.facts.tools_mcp_needs_action {
            StepStatus::NeedsAction
        } else if self.facts.tools_mcp_result.contains("overall=off") {
            StepStatus::Optional
        } else {
            StepStatus::Verified
        };
        let mut state = self.state.clone();
        state.set_step(
            SetupStep::ToolsMcp,
            StepEntry::new(status, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.tools_mcp_result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        let message_id = if status == StepStatus::NeedsAction {
            MessageId::SetupToolsMcpNeedsActionSaved
        } else {
            MessageId::SetupToolsMcpReviewed
        };
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, message_id).to_string(),
        })
    }

    fn preview_tools_mcp_on_ramp(&self) -> ViewAction {
        ViewAction::Emit(ViewEvent::OpenTextPager {
            title: tr(self.locale, MessageId::SetupToolsMcpPreviewTitle).to_string(),
            content: tools_mcp_on_ramp_text(self.locale, &self.facts),
        })
    }

    fn preview_remote_runtime_on_ramp(&self) -> ViewAction {
        ViewAction::Emit(ViewEvent::OpenTextPager {
            title: tr(self.locale, MessageId::SetupRemotePreviewTitle).to_string(),
            content: remote_runtime_on_ramp_text(self.locale, &self.facts),
        })
    }

    /// Record the remote step honestly (#3409).
    ///
    /// Local-only always works, so Enter alone settles the step โ€” a user who
    /// never wants remote access is finished in one key. When a *reachable*
    /// mode is missing a token or config the entry is `NeedsAction`, which the
    /// setup report and doctor inherit verbatim and which never blocks ready.
    fn commit_remote_runtime_review(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        let status = if self.facts.remote_needs_action {
            StepStatus::NeedsAction
        } else {
            StepStatus::Verified
        };
        state.set_step(
            SetupStep::RemoteRuntime,
            StepEntry::new(status, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.remote_result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupRemoteReviewed).to_string(),
        })
    }

    fn commit_persistence_review(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        state.set_step(
            SetupStep::Persistence,
            StepEntry::new(StepStatus::Verified, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.facts.persistence.result.clone()),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupPersistenceReviewed).to_string(),
        })
    }

    fn select_runtime_preset(&mut self, key: char) -> ViewAction {
        if let Some(preset) = SetupRuntimePreset::from_key(key)
            && preset != self.runtime_preset
        {
            self.runtime_preset = preset;
            self.runtime_preset_preview_seen = false;
        }
        ViewAction::None
    }

    fn preview_runtime_preset(&mut self) -> ViewAction {
        self.runtime_preset_preview_seen = true;
        ViewAction::Emit(ViewEvent::OpenTextPager {
            title: tr(self.locale, MessageId::SetupRuntimePresetPreviewTitle).to_string(),
            content: runtime_preset_preview_text(self.locale, self.runtime_preset, &self.facts),
        })
    }

    fn commit_runtime_preset(&mut self) -> ViewAction {
        if !self.runtime_preset_preview_seen {
            return self.preview_runtime_preset();
        }

        let mut state = self.state.clone();
        state.runtime_posture_source = RuntimePostureSource::Confirmed;
        state.set_step(
            SetupStep::TrustSandbox,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(self.runtime_preset.result_summary()),
        );
        self.state = state.clone();
        self.move_next();
        ViewAction::Emit(ViewEvent::SetupRuntimePresetApplyRequested {
            preset: self.runtime_preset,
            state,
            message: tr(self.locale, MessageId::SetupRuntimePresetApplied).to_string(),
        })
    }

    fn commit_setup_report(&mut self) -> ViewAction {
        let mut state = self.state.clone();
        let status = if setup_report_ready(&state) {
            StepStatus::Verified
        } else {
            StepStatus::NeedsAction
        };
        state.set_step(
            SetupStep::Verification,
            StepEntry::new(status, false, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(setup_report_result(&state, &self.facts)),
        );
        self.state = state.clone();
        let event = ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupReportRecorded).to_string(),
        };
        if self.progressive_guide {
            ViewAction::EmitAndClose(event)
        } else {
            ViewAction::Emit(event)
        }
    }

    fn open_constitution_advanced(&mut self) -> ViewAction {
        self.constitution_advanced = true;
        self.body_scroll = 0;
        ViewAction::None
    }

    fn close_constitution_advanced(&mut self) -> ViewAction {
        self.constitution_advanced = false;
        self.editing_freeform_note = false;
        self.body_scroll = 0;
        ViewAction::None
    }

    /// The first-run path is intentionally one decision: how much initiative
    /// Codewhale should take. This saves guidance only. Runtime approval,
    /// sandbox, shell, network, trust, and MCP policy remain untouched.
    fn commit_simple_constitution(&mut self) -> ViewAction {
        match self.facts.constitution_file {
            // Existing law is the safest default on an update checkpoint.
            // Keep it byte-for-byte and only advance setup state.
            SetupConstitutionFileState::Loaded => {
                return self.commit_existing_constitution_unchanged();
            }
            // Do not overwrite a file the user attempted to provide when it
            // cannot be parsed or read. The bundled floor remains active and
            // Advanced exposes the explicit repair/regenerate choices.
            SetupConstitutionFileState::Empty
            | SetupConstitutionFileState::Invalid
            | SetupConstitutionFileState::Unreadable
            | SetupConstitutionFileState::PathError => {
                return self.commit_constitution(SetupCommitKind::BundledConstitution);
            }
            SetupConstitutionFileState::NotChecked | SetupConstitutionFileState::Missing => {}
        }

        // The compiled constitution already embodies the balanced posture:
        // act on clear reversible work, ask when ambiguity is costly, and
        // require express authorization for irreversible or external effects.
        // Accepting the recommendation therefore records Bundled rather than
        // pinning a generated user-global fork that would miss future bundled
        // law improvements. Only Customize writes a GuidedCustom file.
        self.commit_constitution(SetupCommitKind::BundledConstitution)
    }

    fn commit_custom_constitution(
        &mut self,
        constitution: UserConstitution,
        authoring: ConstitutionAuthoring,
        result_prefix: &str,
    ) -> ViewAction {
        let mut state = self.state.clone();
        state.complete_constitution_checkpoint(
            CONSTITUTION_CHECKPOINT_VERSION,
            ConstitutionChoice::GuidedCustom,
        );
        state.constitution_language = constitution.language.clone();
        state.constitution_source = ConstitutionSource::UserGlobal;
        state.constitution_validity = ConstitutionValidity::Valid;
        state.constitution_authoring = Some(authoring);
        state.constitution_preview_hash = Some(constitution.preview_hash());
        state.constitution_preview_version =
            state.constitution_preview_version.saturating_add(1).max(1);
        let hash = state
            .constitution_preview_hash
            .as_deref()
            .unwrap_or("unknown");
        state.set_step(
            SetupStep::Constitution,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(format!("{result_prefix} preview_hash={hash}")),
        );
        self.state = state.clone();
        ViewAction::EmitAndClose(ViewEvent::SetupConstitutionCommitRequested {
            constitution,
            state,
            message: tr(self.locale, MessageId::SetupCheckpointDoneGuided).to_string(),
        })
    }

    fn commit_guided_constitution(&mut self) -> ViewAction {
        if !self.guided_preview_seen {
            return self.preview_guided_constitution();
        }

        let (constitution, authoring) = match self.model_draft.as_deref() {
            // Model drafts arrive sanitized + bounded from the untrusted-JSON
            // gate; ratify exactly what was previewed.
            Some(draft) => (draft.clone(), ConstitutionAuthoring::ModelDrafted),
            None => (
                self.guided_draft
                    .to_constitution_with_freeform(self.locale, self.freeform_note_for_draft()),
                ConstitutionAuthoring::Guided,
            ),
        };
        let result_prefix = match authoring {
            ConstitutionAuthoring::ModelDrafted => format!(
                "model-drafted constitution ratified ({})",
                self.model_draft_label.as_deref().unwrap_or("model")
            ),
            ConstitutionAuthoring::Guided => "guided custom constitution".to_string(),
        };
        self.commit_custom_constitution(constitution, authoring, &result_prefix)
    }

    fn preview_guided_constitution(&mut self) -> ViewAction {
        self.guided_preview_seen = true;
        let (constitution, provenance) = match self.model_draft.as_deref() {
            Some(draft) => (
                draft.clone(),
                DraftProvenance::Model(
                    self.model_draft_label
                        .clone()
                        .unwrap_or_else(|| "model".to_string()),
                ),
            ),
            None => (
                self.guided_draft
                    .to_constitution_with_freeform(self.locale, self.freeform_note_for_draft()),
                DraftProvenance::Guided,
            ),
        };
        ViewAction::Emit(ViewEvent::OpenTextPager {
            title: ratification_preview_title(self.locale).to_string(),
            content: constitution_ratification_text(self.locale, &constitution, &provenance),
        })
    }

    fn cycle_guided_answer(&mut self, key: char) -> ViewAction {
        if self.guided_draft.cycle(key) {
            self.guided_preview_seen = false;
            // Answers changed under the draft: the model draft is stale law
            // and must be re-drafted or replaced by the guided rendering.
            self.model_draft = None;
            self.model_draft_label = None;
        }
        ViewAction::None
    }

    /// `A` on the constitution step: ask the first configured model to draft.
    /// Requires a ready provider route; otherwise the key is inert and the
    /// deterministic guided flow stands untouched.
    fn request_model_draft(&self) -> ViewAction {
        if !self.facts.provider_ready {
            return ViewAction::None;
        }
        ViewAction::Emit(ViewEvent::SetupConstitutionModelDraftRequested {
            draft: self.guided_draft,
            freeform_note: self.freeform_note_for_draft().map(str::to_string),
            locale: self.locale,
        })
    }

    fn toggle_freeform_edit(&mut self) -> ViewAction {
        if self.selected_step() == SetupStep::Constitution {
            self.editing_freeform_note = !self.editing_freeform_note;
        }
        ViewAction::None
    }

    fn freeform_note_for_draft(&self) -> Option<&str> {
        let note = self.freeform_note.trim();
        (!note.is_empty()).then_some(note)
    }

    fn append_freeform_note_text(&mut self, text: &str) {
        let mut next = self.freeform_note.clone();
        next.push_str(text);
        self.freeform_note = bounded_freeform_note(&next, MAX_NOTES_LEN);
        self.guided_preview_seen = false;
        self.model_draft = None;
        self.model_draft_label = None;
    }

    fn handle_freeform_note_key(&mut self, key: KeyEvent) -> Option<ViewAction> {
        if self.selected_step() != SetupStep::Constitution || !self.editing_freeform_note {
            return None;
        }
        match key.code {
            KeyCode::Esc | KeyCode::Enter => {
                self.editing_freeform_note = false;
                Some(ViewAction::None)
            }
            KeyCode::Backspace => {
                self.freeform_note.pop();
                self.guided_preview_seen = false;
                self.model_draft = None;
                self.model_draft_label = None;
                Some(ViewAction::None)
            }
            KeyCode::Char(c) if key.modifiers.is_empty() => {
                let mut buf = [0; 4];
                self.append_freeform_note_text(c.encode_utf8(&mut buf));
                Some(ViewAction::None)
            }
            _ => Some(ViewAction::None),
        }
    }

    /// Install a model-drafted constitution (already sanitized + bounded by
    /// the untrusted-JSON gate) and return the `(title, content)` of the
    /// ratification preview the host must open in the same breath โ€” that is
    /// what satisfies the preview gate. Ratifying still takes the explicit
    /// `G` keypress afterwards.
    #[must_use]
    pub(crate) fn install_model_draft(
        &mut self,
        constitution: Box<UserConstitution>,
        model_label: String,
    ) -> (String, String) {
        let content = constitution_ratification_text(
            self.locale,
            &constitution,
            &DraftProvenance::Model(model_label.clone()),
        );
        self.model_draft = Some(constitution);
        self.model_draft_label = Some(model_label);
        self.guided_preview_seen = true;
        (ratification_preview_title(self.locale).to_string(), content)
    }

    fn commit_constitution(&self, kind: SetupCommitKind) -> ViewAction {
        let choice = match kind {
            SetupCommitKind::BundledConstitution => ConstitutionChoice::Bundled,
            SetupCommitKind::DeferredConstitution => ConstitutionChoice::Deferred,
        };
        let mut state = self.state.clone();
        state.complete_constitution_checkpoint(CONSTITUTION_CHECKPOINT_VERSION, choice);
        state.constitution_source = ConstitutionSource::Bundled;
        state.constitution_validity = ConstitutionValidity::Unknown;
        state.constitution_authoring = None;
        state.constitution_preview_hash = None;
        state.set_step(
            SetupStep::Constitution,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(match kind {
                    SetupCommitKind::BundledConstitution => "bundled/default constitution",
                    SetupCommitKind::DeferredConstitution => "checkpoint deferred; bundled applies",
                }),
        );
        let message_id = match kind {
            SetupCommitKind::BundledConstitution => MessageId::SetupCheckpointDoneBundled,
            SetupCommitKind::DeferredConstitution => MessageId::SetupCheckpointDeferred,
        };
        ViewAction::EmitAndClose(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, message_id).to_string(),
        })
    }

    fn load_existing_constitution(&self) -> Option<UserConstitution> {
        if self.facts.constitution_file != SetupConstitutionFileState::Loaded {
            return None;
        }
        // Re-read the live file so a stale card cannot ratify a file that
        // has since become invalid; any non-loaded state leaves the key inert.
        UserConstitution::load().ok()?.constitution().cloned()
    }

    fn commit_existing_constitution_unchanged(&mut self) -> ViewAction {
        let Some(constitution) = self.load_existing_constitution() else {
            return ViewAction::None;
        };
        let mut state = self.state.clone();
        state.complete_constitution_checkpoint(
            CONSTITUTION_CHECKPOINT_VERSION,
            ConstitutionChoice::GuidedCustom,
        );
        state.constitution_source = ConstitutionSource::UserGlobal;
        state.constitution_validity = ConstitutionValidity::Valid;
        state.constitution_preview_hash = Some(constitution.preview_hash());
        state.set_step(
            SetupStep::Constitution,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result("existing constitution kept unchanged"),
        );
        self.state = state.clone();
        ViewAction::EmitAndClose(ViewEvent::SetupStateCommitRequested {
            state,
            message: tr(self.locale, MessageId::SetupCheckpointDoneKept).to_string(),
        })
    }

    /// Complete the checkpoint by keeping the existing valid
    /// `constitution.json` exactly as it stands (#3794). First `K` previews
    /// the rendered law; second `K` records the choice. The file is never
    /// rewritten โ€” only `setup_state.json` changes, through the same commit
    /// event as every other completion.
    fn commit_keep_existing_constitution(&mut self) -> ViewAction {
        let Some(constitution) = self.load_existing_constitution() else {
            return ViewAction::None;
        };
        if !self.existing_preview_seen {
            self.existing_preview_seen = true;
            let content = constitution_ratification_text(
                self.locale,
                &constitution,
                &DraftProvenance::Existing,
            );
            return ViewAction::Emit(ViewEvent::OpenTextPager {
                title: ratification_preview_title(self.locale).to_string(),
                content,
            });
        }
        self.commit_existing_constitution_unchanged()
    }

    fn status_label(&self, status: StepStatus) -> Cow<'static, str> {
        tr(
            self.locale,
            match status {
                StepStatus::NotStarted => MessageId::SetupStatusNotStarted,
                StepStatus::Recommended => MessageId::SetupStatusRecommended,
                StepStatus::Optional => MessageId::SetupStatusOptional,
                StepStatus::Deferred => MessageId::SetupStatusDeferred,
                StepStatus::InProgress => MessageId::SetupStatusInProgress,
                StepStatus::NeedsAction => MessageId::SetupStatusNeedsAction,
                StepStatus::Verified => MessageId::SetupStatusVerified,
                StepStatus::Skipped => MessageId::SetupStatusSkipped,
                StepStatus::Failed => MessageId::SetupStatusFailed,
            },
        )
    }
}

impl ModalView for SetupWizardView {
    fn kind(&self) -> ModalKind {
        ModalKind::SetupWizard
    }

    fn handle_key(&mut self, key: KeyEvent) -> ViewAction {
        if let Some(action) = self.handle_freeform_note_key(key) {
            return action;
        }
        if self.selected_step() == SetupStep::Constitution && !self.constitution_advanced {
            return match key.code {
                KeyCode::Esc | KeyCode::Char('q') => ViewAction::Close,
                KeyCode::Left | KeyCode::Char('b') => {
                    self.move_back();
                    ViewAction::None
                }
                KeyCode::Char('c') => self.open_constitution_advanced(),
                KeyCode::Enter => self.commit_simple_constitution(),
                _ => ViewAction::None,
            };
        }
        if self.selected_step() == SetupStep::Constitution
            && self.constitution_advanced
            && key.code == KeyCode::Esc
        {
            return self.close_constitution_advanced();
        }
        match key.code {
            KeyCode::Esc | KeyCode::Char('q') => ViewAction::Close,
            KeyCode::Char('i') | KeyCode::Char('?') if self.progressive_guide => {
                self.details_expanded = !self.details_expanded;
                self.body_scroll = 0;
                ViewAction::None
            }
            KeyCode::Left | KeyCode::Char('b') => {
                self.move_back();
                ViewAction::None
            }
            KeyCode::Right | KeyCode::Char('n') => {
                self.move_next();
                ViewAction::None
            }
            KeyCode::PageUp => {
                self.body_scroll = self.body_scroll.saturating_sub(8);
                ViewAction::None
            }
            KeyCode::PageDown => {
                self.body_scroll = self.body_scroll.saturating_add(8);
                ViewAction::None
            }
            KeyCode::Up if self.progressive_guide => {
                self.body_scroll = self.body_scroll.saturating_sub(1);
                ViewAction::None
            }
            KeyCode::Down if self.progressive_guide => {
                self.body_scroll = self.body_scroll.saturating_add(1);
                ViewAction::None
            }
            KeyCode::Up => {
                self.move_back();
                ViewAction::None
            }
            KeyCode::Down => {
                self.move_next();
                ViewAction::None
            }
            KeyCode::Char('s') if self.progressive_guide => {
                if self.selected_step() == SetupStep::Verification {
                    ViewAction::Close
                } else {
                    self.move_next();
                    ViewAction::None
                }
            }
            KeyCode::Char('s') => {
                self.commit_selected_status(StepStatus::Skipped, MessageId::SetupStepSkipped, true)
            }
            KeyCode::Char('r')
                if self.progressive_guide
                    && matches!(
                        self.selected_step(),
                        SetupStep::RemoteRuntime | SetupStep::Verification
                    ) =>
            {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenRemoteControlRequested)
            }
            KeyCode::Char('p')
                if self.progressive_guide && self.selected_step() == SetupStep::Verification =>
            {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenProviderRequested)
            }
            KeyCode::Char('c')
                if self.progressive_guide && self.selected_step() == SetupStep::Verification =>
            {
                self.selected = visible_step_index(SetupStep::TrustSandbox);
                self.details_expanded = false;
                self.body_scroll = 0;
                ViewAction::None
            }
            KeyCode::Char('r')
                if !self.progressive_guide && self.selected_step() == SetupStep::ToolsMcp =>
            {
                self.preview_tools_mcp_on_ramp()
            }
            KeyCode::Char('r') if self.selected_step() == SetupStep::RemoteRuntime => {
                self.preview_remote_runtime_on_ramp()
            }
            KeyCode::Char('r') => self.commit_selected_status(
                StepStatus::NeedsAction,
                MessageId::SetupStepRetryRecorded,
                false,
            ),
            KeyCode::Char('g') if self.selected_step() == SetupStep::Constitution => {
                self.commit_guided_constitution()
            }
            KeyCode::Char('p') if self.selected_step() == SetupStep::ProviderModel => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenProviderRequested)
            }
            KeyCode::Char('m') if self.selected_step() == SetupStep::ProviderModel => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenModelRequested)
            }
            KeyCode::Char('p') if self.selected_step() == SetupStep::OperateFleet => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenProviderRequested)
            }
            KeyCode::Char('f') if self.selected_step() == SetupStep::OperateFleet => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenFleetRequested)
            }
            KeyCode::Char('h') if self.selected_step() == SetupStep::Hotbar => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenHotbarRequested)
            }
            KeyCode::Char('m') if self.selected_step() == SetupStep::TrustSandbox => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenModeRequested)
            }
            KeyCode::Char('c') if self.selected_step() == SetupStep::TrustSandbox => {
                ViewAction::EmitAndClose(ViewEvent::SetupOpenConfigRequested)
            }
            KeyCode::Char(key @ ('1' | '2' | '3'))
                if self.selected_step() == SetupStep::TrustSandbox =>
            {
                self.select_runtime_preset(key)
            }
            KeyCode::Char('a') if self.selected_step() == SetupStep::TrustSandbox => {
                self.commit_runtime_preset()
            }
            KeyCode::Char(key @ ('1' | '2' | '3' | '4' | '5' | '6'))
                if self.selected_step() == SetupStep::Constitution =>
            {
                self.cycle_guided_answer(key)
            }
            KeyCode::Char('a') if self.selected_step() == SetupStep::Constitution => {
                self.request_model_draft()
            }
            KeyCode::Char('f') if self.selected_step() == SetupStep::Constitution => {
                self.toggle_freeform_edit()
            }
            KeyCode::Char('k') if self.selected_step() == SetupStep::Constitution => {
                self.commit_keep_existing_constitution()
            }
            KeyCode::Char('u') => self.commit_constitution(SetupCommitKind::BundledConstitution),
            KeyCode::Char('d') => self.commit_constitution(SetupCommitKind::DeferredConstitution),
            KeyCode::Enter if self.selected_step() == SetupStep::Constitution => {
                self.commit_constitution(SetupCommitKind::BundledConstitution)
            }
            KeyCode::Enter if self.selected_step() == SetupStep::Language => {
                self.commit_language_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::ProviderModel => {
                if self.progressive_guide && !self.facts.provider_ready {
                    ViewAction::EmitAndClose(ViewEvent::SetupOpenProviderRequested)
                } else {
                    self.commit_provider_model_review()
                }
            }
            KeyCode::Enter if self.selected_step() == SetupStep::TrustSandbox => {
                self.commit_runtime_posture_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::OperateFleet => {
                self.commit_operate_fleet_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::Hotbar => {
                self.commit_hotbar_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::ToolsMcp => {
                self.commit_tools_mcp_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::RemoteRuntime => {
                self.commit_remote_runtime_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::Persistence => {
                self.commit_persistence_review()
            }
            KeyCode::Enter if self.selected_step() == SetupStep::Verification => {
                self.commit_setup_report()
            }
            KeyCode::Enter => {
                self.move_next();
                ViewAction::None
            }
            _ => ViewAction::None,
        }
    }

    fn handle_paste(&mut self, text: &str) -> bool {
        if self.selected_step() != SetupStep::Constitution || !self.constitution_advanced {
            return false;
        }
        self.append_freeform_note_text(text);
        true
    }

    fn render(&self, area: Rect, buf: &mut Buffer) {
        let inner = render_underwater_surface(area, buf, self.surface_title());
        let simple_constitution =
            self.selected_step() == SetupStep::Constitution && !self.constitution_advanced;
        let hints = if self.progressive_guide {
            self.progressive_action_hints()
        } else if simple_constitution {
            vec![
                ActionHint::new(
                    "Enter",
                    tr(
                        self.locale,
                        if self.facts.constitution_file == SetupConstitutionFileState::Loaded {
                            MessageId::SetupActionKeepExisting
                        } else {
                            MessageId::SetupActionUseRecommended
                        },
                    )
                    .to_string(),
                ),
                ActionHint::new(
                    "C",
                    tr(self.locale, MessageId::SetupActionCustomize).to_string(),
                ),
                ActionHint::new("B", tr(self.locale, MessageId::SetupActionBack).to_string()),
                ActionHint::new(
                    "Esc",
                    tr(self.locale, MessageId::SetupActionCancel).to_string(),
                ),
            ]
        } else {
            let mut hints = vec![
                ActionHint::new(
                    "Enter",
                    tr(self.locale, MessageId::SetupActionContinue).to_string(),
                ),
                ActionHint::new("B", tr(self.locale, MessageId::SetupActionBack).to_string()),
                ActionHint::new("S", tr(self.locale, MessageId::SetupActionSkip).to_string()),
            ];
            self.extend_focused_action_hints(&mut hints);
            hints.push(ActionHint::new(
                "Esc",
                tr(self.locale, MessageId::SetupActionCancel).to_string(),
            ));
            hints
        };
        let content_area = render_modal_footer(inner, buf, &hints);
        let spec = self.selected_spec();
        let (title_text, question_text) = if self.progressive_guide {
            match self.selected_step() {
                SetupStep::ProviderModel => (
                    tr(self.locale, MessageId::OnboardProviderTitle).into_owned(),
                    tr(self.locale, MessageId::OnboardProviderBlurb).into_owned(),
                ),
                SetupStep::TrustSandbox => (
                    tr(self.locale, MessageId::SetupStepTrustSandboxTitle).into_owned(),
                    tr(self.locale, MessageId::SetupRuntimePostureReviewHint).into_owned(),
                ),
                SetupStep::RemoteRuntime => (
                    "/rc".to_string(),
                    tr(self.locale, MessageId::CmdRemoteControlDescription).into_owned(),
                ),
                SetupStep::Verification => (
                    tr(self.locale, MessageId::OnboardReadyTitle).into_owned(),
                    tr(self.locale, MessageId::OnboardReadyLead).into_owned(),
                ),
                _ => (
                    tr(self.locale, spec.title_id()).into_owned(),
                    tr(self.locale, spec.why_id()).into_owned(),
                ),
            }
        } else {
            (
                tr(self.locale, spec.title_id()).into_owned(),
                tr(self.locale, spec.why_id()).into_owned(),
            )
        };
        let title = Line::from(Span::styled(
            title_text,
            Style::default()
                .fg(palette::WHALE_INFO)
                .add_modifier(Modifier::BOLD),
        ));
        let why = Line::from(Span::raw(question_text));
        let mut lines = vec![title, why, Line::from("")];
        lines.extend(self.selected_step_detail_lines());
        let wrap_width = usize::from(content_area.width).max(1);
        let visual_rows: usize = lines
            .iter()
            .map(|line| line.width().div_ceil(wrap_width).max(1))
            .sum();
        let visible_rows = usize::from(content_area.height).max(1);
        let max_scroll = visual_rows.saturating_sub(visible_rows);
        let scroll = self.body_scroll.min(max_scroll);
        let content_area =
            render_panel_scroll_rail(content_area, buf, visual_rows, scroll, visible_rows, true);
        Paragraph::new(lines)
            .wrap(Wrap { trim: false })
            .scroll((scroll as u16, 0))
            .render(content_area, buf);
    }

    fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
        self
    }
}

impl SetupWizardView {
    fn progressive_action_hints(&self) -> Vec<ActionHint> {
        let back = || ActionHint::new("B", tr(self.locale, MessageId::SetupActionBack).to_string());
        let exit = || {
            ActionHint::new(
                "Esc",
                tr(self.locale, MessageId::SetupActionCancel).to_string(),
            )
        };
        let details = || {
            ActionHint::new(
                "I",
                tr(self.locale, MessageId::CtxMenuOpenDetails).to_string(),
            )
        };
        let skip = || ActionHint::new("S", tr(self.locale, MessageId::SetupActionSkip).to_string());
        let mut hints = match self.selected_step() {
            SetupStep::ProviderModel => vec![
                ActionHint::new(
                    "Enter",
                    tr(
                        self.locale,
                        if self.facts.provider_ready {
                            MessageId::SetupActionContinue
                        } else {
                            MessageId::SetupActionProvider
                        },
                    )
                    .to_string(),
                ),
                skip(),
                details(),
                exit(),
            ],
            SetupStep::TrustSandbox => vec![
                ActionHint::new(
                    "Enter",
                    tr(self.locale, MessageId::SetupActionKeepExisting).to_string(),
                ),
                skip(),
                details(),
                exit(),
            ],
            SetupStep::RemoteRuntime => vec![
                ActionHint::new(
                    "R",
                    tr(self.locale, MessageId::CmdRemoteControlDescription).to_string(),
                ),
                skip(),
                details(),
                exit(),
            ],
            SetupStep::ToolsMcp => vec![
                ActionHint::new(
                    "Enter",
                    tr(self.locale, MessageId::SetupActionContinue).to_string(),
                ),
                skip(),
                details(),
                exit(),
            ],
            SetupStep::Verification => vec![
                ActionHint::new(
                    "Enter",
                    tr(self.locale, MessageId::OnboardReadyStart).to_string(),
                ),
                details(),
                exit(),
            ],
            _ => vec![exit()],
        };
        let position = self
            .progressive_steps()
            .iter()
            .position(|step| *step == self.selected_step())
            .unwrap_or(0);
        if position > 0 {
            hints.insert(hints.len().saturating_sub(1), back());
        }
        hints
    }

    fn extend_focused_action_hints(&self, hints: &mut Vec<ActionHint>) {
        match self.selected_step() {
            SetupStep::Constitution if self.constitution_advanced => {
                hints.push(ActionHint::new(
                    "1-6",
                    tr(self.locale, MessageId::SetupActionTuneGuided).to_string(),
                ));
                hints.push(ActionHint::new(
                    "G",
                    tr(self.locale, MessageId::SetupActionGuided).to_string(),
                ));
                hints.push(ActionHint::new(
                    "F",
                    tr(self.locale, MessageId::SetupActionFreeform).to_string(),
                ));
            }
            SetupStep::ProviderModel => {
                hints.push(ActionHint::new(
                    "P",
                    tr(self.locale, MessageId::SetupActionProvider).to_string(),
                ));
                hints.push(ActionHint::new(
                    "M",
                    tr(self.locale, MessageId::SetupActionModel).to_string(),
                ));
            }
            SetupStep::OperateFleet => hints.push(ActionHint::new(
                "F",
                tr(self.locale, MessageId::SetupActionFleet).to_string(),
            )),
            SetupStep::Hotbar => hints.push(ActionHint::new(
                "H",
                tr(self.locale, MessageId::SetupActionHotbar).to_string(),
            )),
            SetupStep::ToolsMcp | SetupStep::RemoteRuntime => hints.push(ActionHint::new(
                "R",
                tr(self.locale, MessageId::SetupActionRetry).to_string(),
            )),
            SetupStep::TrustSandbox => hints.push(ActionHint::new(
                "C",
                tr(self.locale, MessageId::SetupActionConfig).to_string(),
            )),
            _ => {}
        }
    }

    fn selected_step_detail_lines(&self) -> Vec<Line<'static>> {
        if self.progressive_guide {
            return if self.details_expanded {
                self.progressive_expanded_lines()
            } else {
                self.progressive_detail_lines()
            };
        }
        match self.selected_step() {
            SetupStep::ProviderModel => self.provider_model_detail_lines(),
            SetupStep::TrustSandbox => self.runtime_posture_detail_lines(),
            SetupStep::Constitution if self.constitution_advanced => {
                self.constitution_detail_lines()
            }
            SetupStep::Constitution => self.constitution_simple_lines(),
            SetupStep::OperateFleet => self.operate_fleet_detail_lines(),
            SetupStep::Hotbar => self.hotbar_detail_lines(),
            SetupStep::ToolsMcp => self.tools_mcp_detail_lines(),
            SetupStep::RemoteRuntime => self.remote_runtime_detail_lines(),
            SetupStep::Persistence => self.persistence_detail_lines(),
            SetupStep::Verification => self.verification_detail_lines(),
            _ => Vec::new(),
        }
    }

    fn progressive_detail_lines(&self) -> Vec<Line<'static>> {
        match self.selected_step() {
            SetupStep::ProviderModel => {
                let answer = format!(
                    "{} ยท {} ยท {}",
                    self.facts.provider, self.facts.model, self.facts.auth
                );
                vec![self.detail_row(MessageId::SetupCardRouteLabel, &answer)]
            }
            SetupStep::TrustSandbox => {
                let answer = format!(
                    "{} ยท {} ยท {}",
                    self.facts.approval, self.facts.trust, self.facts.sandbox
                );
                let mut lines = vec![self.detail_row(MessageId::SetupCardApprovalLabel, &answer)];
                if let Some(warning) = &self.facts.project_override_warning {
                    lines.push(
                        self.detail_row(MessageId::SetupRuntimeProjectOverrideLabel, warning),
                    );
                }
                lines
            }
            SetupStep::RemoteRuntime => vec![self.detail_row(
                MessageId::SetupRemoteModeLabel,
                &self.facts.remote_control_result,
            )],
            SetupStep::ToolsMcp => {
                let status = tr(
                    self.locale,
                    if self.facts.tools_mcp_needs_action {
                        MessageId::SetupStatusNeedsAction
                    } else {
                        MessageId::SetupStatusVerified
                    },
                )
                .into_owned();
                vec![self.detail_row(MessageId::SetupStepToolsMcpTitle, &status)]
            }
            SetupStep::Verification => self.progressive_summary_lines(),
            _ => self.selected_step_detail_lines_expanded(),
        }
    }

    fn selected_step_detail_lines_expanded(&self) -> Vec<Line<'static>> {
        match self.selected_step() {
            SetupStep::ProviderModel => self.provider_model_detail_lines(),
            SetupStep::TrustSandbox => self.runtime_posture_detail_lines(),
            SetupStep::ToolsMcp => self.tools_mcp_detail_lines(),
            SetupStep::RemoteRuntime => self.remote_runtime_detail_lines(),
            SetupStep::Verification => self.verification_detail_lines(),
            _ => Vec::new(),
        }
    }

    fn progressive_expanded_lines(&self) -> Vec<Line<'static>> {
        if self.selected_step() != SetupStep::Verification {
            return self.selected_step_detail_lines_expanded();
        }
        let mut lines = self.progressive_summary_lines();
        lines.push(Line::from(""));
        lines.push(Line::from(vec![
            Span::styled(
                "/settings  ",
                Style::default()
                    .fg(palette::WHALE_INFO)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(tr(self.locale, MessageId::CmdSettingsDescription).to_string()),
        ]));
        lines.push(Line::from(vec![
            Span::styled(
                "/config <key>  ",
                Style::default()
                    .fg(palette::TEXT_MUTED)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(tr(self.locale, MessageId::SetupActionConfig).to_string()),
        ]));
        lines
    }

    fn progressive_summary_lines(&self) -> Vec<Line<'static>> {
        let route = format!("{} ยท {}", self.facts.provider, self.facts.model);
        let permissions = format!(
            "{} ยท {} ยท {}",
            self.facts.approval, self.facts.trust, self.facts.sandbox
        );
        let mut lines = vec![
            self.detail_row(MessageId::SetupStepProviderModelTitle, &route),
            self.detail_row(MessageId::SetupStepTrustSandboxTitle, &permissions),
            self.detail_row(
                MessageId::SetupStepRemoteRuntimeTitle,
                &self.facts.remote_control_result,
            ),
        ];
        if self.tools_relevant() {
            let tools_status = tr(
                self.locale,
                if self.facts.tools_mcp_needs_action {
                    MessageId::SetupStatusNeedsAction
                } else {
                    MessageId::SetupStatusVerified
                },
            )
            .into_owned();
            lines.push(self.detail_row(MessageId::SetupStepToolsMcpTitle, &tools_status));
        }
        lines
    }

    fn constitution_simple_lines(&self) -> Vec<Line<'static>> {
        if self.facts.constitution_file == SetupConstitutionFileState::Loaded {
            return vec![
                self.detail_row(
                    MessageId::SetupConstitutionExistingLabel,
                    &self
                        .facts
                        .constitution_file
                        .label(self.state.constitution_choice, self.locale),
                ),
                Line::from(Span::styled(
                    tr(
                        self.locale,
                        MessageId::SetupConstitutionExistingDefaultDetail,
                    )
                    .to_string(),
                    Style::default().fg(palette::TEXT_MUTED),
                )),
            ];
        }
        if !matches!(
            self.facts.constitution_file,
            SetupConstitutionFileState::NotChecked | SetupConstitutionFileState::Missing
        ) {
            return vec![
                self.detail_row(
                    MessageId::SetupConstitutionExistingLabel,
                    &self
                        .facts
                        .constitution_file
                        .label(self.state.constitution_choice, self.locale),
                ),
                Line::from(Span::styled(
                    tr(self.locale, MessageId::SetupConstitutionRepairDefaultDetail).to_string(),
                    Style::default().fg(palette::TEXT_MUTED),
                )),
            ];
        }

        let recommendation = format!(
            "{} ยท {}",
            tr(self.locale, MessageId::SetupStatusRecommended),
            autonomy_label(AutonomyPreference::Balanced, self.locale)
        );
        vec![
            Line::from(Span::styled(
                recommendation,
                Style::default()
                    .fg(palette::TEXT_PRIMARY)
                    .add_modifier(Modifier::BOLD),
            )),
            Line::from(Span::styled(
                autonomy_priority(AutonomyPreference::Balanced, self.locale).to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
        ]
    }

    fn provider_model_detail_lines(&self) -> Vec<Line<'static>> {
        vec![
            self.detail_row(MessageId::SetupCardRouteLabel, &self.facts.provider),
            self.detail_row(MessageId::SetupCardModelLabel, &self.facts.model),
            self.detail_row(MessageId::SetupCardAuthLabel, &self.facts.auth),
            self.detail_row(MessageId::SetupCardHealthLabel, &self.facts.health),
            Line::from(Span::styled(
                tr(
                    self.locale,
                    if self.facts.provider_ready {
                        MessageId::SetupProviderModelReadyHint
                    } else {
                        MessageId::SetupProviderModelNeedsActionHint
                    },
                )
                .to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
        ]
    }

    fn constitution_detail_lines(&self) -> Vec<Line<'static>> {
        let choice = constitution_choice_label(self.state.constitution_choice);
        let source = constitution_source_label(self.state.constitution_source);
        let validity = constitution_validity_label(self.state.constitution_validity);
        let source_state = format!("{source}; validity {validity}");
        let existing_file = self
            .facts
            .constitution_file
            .label(self.state.constitution_choice, self.locale);
        let expert_override = self.facts.expert_override.label(self.locale);
        let preview = self
            .state
            .constitution_preview_hash
            .as_deref()
            .unwrap_or("not accepted yet")
            .to_string();
        let mut lines = vec![
            self.detail_row(MessageId::SetupConstitutionChoiceLabel, choice),
            self.detail_row(MessageId::SetupConstitutionSourceLabel, &source_state),
            self.detail_row(MessageId::SetupConstitutionPreviewLabel, &preview),
            self.detail_row(MessageId::SetupConstitutionExistingLabel, &existing_file),
            self.detail_row(
                MessageId::SetupConstitutionExpertOverrideLabel,
                &expert_override,
            ),
            Line::from(Span::styled(
                tr(self.locale, MessageId::SetupConstitutionGuidedAnswersHint).to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
            self.guided_answer_pair(
                (
                    "1",
                    MessageId::SetupConstitutionPurposeLabel,
                    &self.guided_draft.purpose.label(self.locale),
                ),
                (
                    "2",
                    MessageId::SetupConstitutionAutonomyLabel,
                    autonomy_label(self.guided_draft.autonomy, self.locale),
                ),
            ),
            self.guided_answer_pair(
                (
                    "3",
                    MessageId::SetupConstitutionEvidenceLabel,
                    &self.guided_draft.evidence.label(self.locale),
                ),
                (
                    "4",
                    MessageId::SetupConstitutionCommunicationLabel,
                    self.guided_draft.communication.label(self.locale),
                ),
            ),
            self.guided_answer_single(
                "5",
                MessageId::SetupConstitutionPrivacyLabel,
                self.guided_draft.privacy.label(self.locale),
            ),
            self.guided_answer_single(
                "6",
                MessageId::SetupConstitutionPrinciplesLabel,
                self.guided_draft.principles.label(self.locale),
            ),
            freeform_note_line(self.locale, &self.freeform_note, self.editing_freeform_note),
        ];
        if self.facts.constitution_file == SetupConstitutionFileState::Loaded {
            lines.push(Line::from(Span::styled(
                keep_existing_invitation_line(self.locale),
                Style::default().fg(palette::WHALE_HUMAN),
            )));
        }
        if let Some(label) = self
            .model_draft_label
            .as_deref()
            .filter(|_| self.model_draft.is_some())
        {
            lines.push(Line::from(Span::styled(
                model_draft_ready_line(self.locale, label),
                Style::default().fg(palette::STATUS_SUCCESS),
            )));
        } else if self.facts.provider_ready {
            lines.push(Line::from(Span::styled(
                model_draft_invitation_line(self.locale, &self.facts.model),
                Style::default().fg(palette::WHALE_HUMAN),
            )));
        }
        lines.push(Line::from(Span::styled(
            tr(self.locale, MessageId::SetupConstitutionGuidedHint).to_string(),
            Style::default().fg(palette::TEXT_MUTED),
        )));
        lines
    }

    fn runtime_posture_detail_lines(&self) -> Vec<Line<'static>> {
        let project_override = self
            .facts
            .project_override_warning
            .clone()
            .unwrap_or_else(|| {
                tr(self.locale, MessageId::SetupRuntimeProjectOverrideNone).to_string()
            });
        let mut lines = vec![
            self.detail_row(MessageId::SetupCardIntentLabel, &self.facts.work_intent),
            self.detail_row(MessageId::SetupCardApprovalLabel, &self.facts.approval),
            self.detail_row(MessageId::SetupCardShellLabel, &self.facts.shell),
            self.detail_row(MessageId::SetupCardTrustLabel, &self.facts.trust),
            self.detail_row(MessageId::SetupCardSandboxLabel, &self.facts.sandbox),
            self.detail_row(MessageId::SetupCardNetworkLabel, &self.facts.network),
            self.detail_row(
                MessageId::SetupRuntimePresetSelectedLabel,
                &runtime_preset_summary(self.locale, self.runtime_preset),
            ),
            self.detail_row(
                MessageId::SetupRuntimePresetDiffLabel,
                &runtime_preset_inline_diff(self.runtime_preset, &self.facts),
            ),
            self.detail_row(
                MessageId::SetupRuntimeProjectOverrideLabel,
                &project_override,
            ),
            Line::from(Span::styled(
                tr(self.locale, MessageId::SetupRuntimePostureBoundary).to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
            Line::from(Span::styled(
                tr(self.locale, MessageId::SetupRuntimePresetSafetyFloor).to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
            self.setup_review_hint_line(
                MessageId::SetupRuntimePostureReviewHint,
                Some("Press M for work mode or C for config."),
            ),
            Line::from(Span::styled(
                tr(self.locale, MessageId::SetupRuntimePresetApplyHint).to_string(),
                Style::default().fg(palette::TEXT_MUTED),
            )),
        ];
        for (idx, preset) in SetupRuntimePreset::ALL.iter().enumerate() {
            let marker = if *preset == self.runtime_preset {
                ">"
            } else {
                " "
            };
            lines.push(Line::from(Span::styled(
                format!(
                    "{marker} {}. {}",
                    idx + 1,
                    runtime_preset_summary(self.locale, *preset)
                ),
                Style::default().fg(if *preset == self.runtime_preset {
                    palette::TEXT_PRIMARY
                } else {
                    palette::TEXT_MUTED
                }),
            )));
        }
        lines
    }

    fn operate_fleet_detail_lines(&self) -> Vec<Line<'static>> {
        let route = format!("{} / {}", self.facts.provider, self.facts.model);
        let readiness = self.ready_label(self.operate_fleet_facts_ready());
        vec![
            self.detail_row(MessageId::SetupCardRouteLabel, &route),
            self.detail_row(MessageId::SetupCardAuthLabel, &self.facts.auth),
            self.detail_row(
                MessageId::SetupOperateRuntimeLabel,
                &self.facts.operate_runtime_result,
            ),
            self.detail_row(
                MessageId::SetupOperateRosterLabel,
                &self.facts.fleet_roster_result,
            ),
            self.detail_row(
                MessageId::SetupOperateConcurrencyLabel,
                &self.facts.operate_concurrency_result,
            ),
            self.detail_row(MessageId::SetupOperateReadinessLabel, &readiness),
            self.setup_review_hint_line(MessageId::SetupOperateReviewHint, None),
        ]
    }

    fn hotbar_detail_lines(&self) -> Vec<Line<'static>> {
        vec![
            self.detail_row(
                MessageId::SetupHotbarBindingsLabel,
                &self.facts.hotbar_bindings_result,
            ),
            self.detail_row(
                MessageId::SetupHotbarActionsLabel,
                &self.facts.hotbar_actions_result,
            ),
            self.setup_review_hint_line(
                MessageId::SetupHotbarReviewHint,
                Some("Press H to customize slots."),
            ),
        ]
    }

    fn tools_mcp_detail_lines(&self) -> Vec<Line<'static>> {
        vec![
            self.detail_row(
                MessageId::SetupToolsMcpServersLabel,
                &self.facts.tools_mcp_servers_result,
            ),
            self.detail_row(
                MessageId::SetupToolsMcpSkillsLabel,
                &self.facts.tools_mcp_skills_result,
            ),
            self.detail_row(
                MessageId::SetupToolsMcpToolsLabel,
                &self.facts.tools_mcp_tools_result,
            ),
            self.detail_row(
                MessageId::SetupToolsMcpPluginsLabel,
                &self.facts.tools_mcp_plugins_result,
            ),
            self.detail_row(
                MessageId::SetupToolsMcpHotbarLabel,
                &self.facts.tools_mcp_hotbar_result,
            ),
            self.detail_row(
                MessageId::SetupToolsMcpDshLabel,
                &self.facts.tools_mcp_dsh_result,
            ),
            self.setup_review_hint_line(
                MessageId::SetupToolsMcpReviewHint,
                Some("Press R for safe on-ramps (no auto-run)."),
            ),
        ]
    }

    /// #3409: one row per mode, each carrying its own observed status. The
    /// registry counts stay available in the preview; the card itself answers
    /// "where can this be reached from?" in four plain lines.
    fn remote_runtime_detail_lines(&self) -> Vec<Line<'static>> {
        let mut lines = Vec::new();
        for fact in &self.facts.remote_modes {
            lines.push(self.detail_row(
                fact.mode.label_id(),
                &format!(
                    "{} ยท {}",
                    tr(self.locale, fact.status.label_id()),
                    fact.detail
                ),
            ));
        }
        if lines.is_empty() {
            lines.push(self.detail_row(
                MessageId::SetupRemoteModeLabel,
                &self.facts.remote_mode_result,
            ));
        }
        lines.push(self.detail_row(
            MessageId::SetupRemoteProvidersLabel,
            &self.facts.remote_providers_result,
        ));
        lines.push(self.setup_review_hint_line(
            MessageId::SetupRemoteReviewHint,
            Some("Press R to preview (nothing is written). Enter keeps local-only."),
        ));
        lines
    }

    fn persistence_detail_lines(&self) -> Vec<Line<'static>> {
        vec![
            self.detail_row(
                MessageId::SetupPersistenceHomeLabel,
                &self.facts.persistence.home_result,
            ),
            self.detail_row(
                MessageId::SetupPersistenceConfigLabel,
                &self.facts.persistence.config_result,
            ),
            self.detail_row(
                MessageId::SetupPersistenceStateLabel,
                &self.facts.persistence.state_result,
            ),
            self.detail_row(
                MessageId::SetupPersistenceConstitutionLabel,
                &self.facts.persistence.constitution_result,
            ),
            self.detail_row(
                MessageId::SetupPersistenceMemoryLabel,
                &self.facts.persistence.memory_result,
            ),
            self.detail_row(
                MessageId::SetupPersistenceNotesLabel,
                &self.facts.persistence.notes_result,
            ),
            self.setup_review_hint_line(MessageId::SetupPersistenceReviewHint, None),
        ]
    }

    fn verification_detail_lines(&self) -> Vec<Line<'static>> {
        let mut lines = vec![
            self.detail_row(
                MessageId::SetupReportFirstRunLabel,
                &self.ready_label(self.state.first_run_ready()),
            ),
            self.detail_row(
                MessageId::SetupReportUpdateLabel,
                &self.ready_label(self.state.update_ready(CONSTITUTION_CHECKPOINT_VERSION)),
            ),
            self.detail_row(
                MessageId::SetupReportOperateLabel,
                &self.ready_label(self.state.operate_ready()),
            ),
            self.detail_row(
                MessageId::SetupReportSourceLabel,
                &self.state_source_label(),
            ),
            self.detail_row(
                MessageId::SetupReportAutonomyLabel,
                &self.facts.constitution_autonomy,
            ),
            self.detail_row(
                MessageId::SetupReportRuntimePostureLabel,
                &self.facts.runtime_result,
            ),
            Line::from(""),
            Line::from(Span::styled(
                tr(self.locale, MessageId::SetupReportRowsLabel).to_string(),
                Style::default()
                    .fg(palette::TEXT_MUTED)
                    .add_modifier(Modifier::BOLD),
            )),
        ];

        for spec in STEP_SPECS {
            let step = spec.id();
            let entry = self.state.steps.get(&step);
            let required = entry.map_or(spec.required(), |entry| entry.required);
            let required_label = if required {
                tr(self.locale, MessageId::SetupReportRequired)
            } else {
                tr(self.locale, MessageId::SetupReportOptional)
            };
            let mut value = format!(
                "{} ({})",
                self.status_label(self.state.status(step)),
                required_label
            );
            if let Some(version) = entry.and_then(|entry| entry.version.as_deref()) {
                value.push_str(&format!(" ยท {version}"));
            }
            if let Some(result) = entry.and_then(|entry| entry.result.as_deref()) {
                value.push_str(&format!(" ยท {result}"));
            }
            lines.push(self.detail_row(spec.title_id(), &value));
        }

        lines.push(Line::from(""));
        let next_action = tr(self.locale, self.next_action_id()).to_string();
        lines.push(self.detail_row(MessageId::SetupReportNextActionLabel, &next_action));
        lines
    }

    fn setup_review_hint_line(
        &self,
        hint_id: MessageId,
        english_action: Option<&'static str>,
    ) -> Line<'static> {
        let hint = if self.locale == Locale::En {
            let mut hint = "Enter records this setup snapshot.".to_string();
            if let Some(action) = english_action {
                hint.push(' ');
                hint.push_str(action);
            }
            hint
        } else {
            tr(self.locale, hint_id).to_string()
        };
        Line::from(Span::styled(hint, Style::default().fg(palette::TEXT_MUTED)))
    }

    fn ready_label(&self, ready: bool) -> String {
        if ready {
            tr(self.locale, MessageId::SetupReportReady).to_string()
        } else {
            tr(self.locale, MessageId::SetupStatusNeedsAction).to_string()
        }
    }

    fn state_source_label(&self) -> String {
        if self.state.inherited {
            tr(self.locale, MessageId::SetupReportInherited).to_string()
        } else {
            tr(self.locale, MessageId::SetupReportPersisted).to_string()
        }
    }

    fn next_action_id(&self) -> MessageId {
        if !self.state.update_ready(CONSTITUTION_CHECKPOINT_VERSION) {
            return MessageId::SetupReportNextActionConstitution;
        }
        if !matches!(
            self.state.status(SetupStep::ProviderModel),
            StepStatus::Verified | StepStatus::NeedsAction
        ) {
            return MessageId::SetupReportNextActionProvider;
        }
        if !self.state.runtime_posture_source.is_reviewed() {
            return MessageId::SetupReportNextActionRuntime;
        }
        if !self.state.first_run_ready() {
            return MessageId::SetupReportNextActionRequired;
        }
        if !self.state.operate_ready() {
            return MessageId::SetupReportNextActionOperate;
        }
        MessageId::SetupReportNextActionNone
    }

    fn detail_row(&self, label: MessageId, value: &str) -> Line<'static> {
        Line::from(vec![
            Span::styled(
                format!("{} ", tr(self.locale, label)),
                Style::default()
                    .fg(palette::TEXT_MUTED)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(value.to_string()),
        ])
    }

    fn guided_answer_pair(
        &self,
        left: (&str, MessageId, &str),
        right: (&str, MessageId, &str),
    ) -> Line<'static> {
        let label_style = Style::default()
            .fg(palette::TEXT_MUTED)
            .add_modifier(Modifier::BOLD);
        Line::from(vec![
            Span::styled(
                format!("{} {} ", left.0, tr(self.locale, left.1)),
                label_style,
            ),
            Span::raw(left.2.to_string()),
            Span::styled("  ยท  ", Style::default().fg(palette::TEXT_MUTED)),
            Span::styled(
                format!("{} {} ", right.0, tr(self.locale, right.1)),
                label_style,
            ),
            Span::raw(right.2.to_string()),
        ])
    }

    fn guided_answer_single(&self, key: &str, label: MessageId, value: &str) -> Line<'static> {
        Line::from(vec![
            Span::styled(
                format!("{key} {} ", tr(self.locale, label)),
                Style::default()
                    .fg(palette::TEXT_MUTED)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(value.to_string()),
        ])
    }
}

fn setup_report_ready(state: &SetupState) -> bool {
    state.first_run_ready() || state.update_ready(CONSTITUTION_CHECKPOINT_VERSION)
}

fn runtime_preset_summary(locale: Locale, preset: SetupRuntimePreset) -> String {
    format!(
        "{} - {}",
        tr(locale, preset.title_id()),
        tr(locale, preset.description_id())
    )
}

fn runtime_preset_inline_diff(preset: SetupRuntimePreset, facts: &SetupRuntimeFacts) -> String {
    runtime_preset_diff_rows(preset, facts).join("; ")
}

fn runtime_preset_preview_text(
    locale: Locale,
    preset: SetupRuntimePreset,
    facts: &SetupRuntimeFacts,
) -> String {
    let mut lines = vec![
        tr(locale, MessageId::SetupRuntimePresetPreviewTitle).to_string(),
        runtime_preset_summary(locale, preset),
        String::new(),
        tr(locale, MessageId::SetupRuntimePresetDiffLabel).to_string(),
    ];
    lines.extend(
        runtime_preset_diff_rows(preset, facts)
            .into_iter()
            .map(|row| format!("- {row}")),
    );
    lines.extend([
        String::new(),
        tr(locale, MessageId::SetupRuntimePostureBoundary).to_string(),
        tr(locale, MessageId::SetupRuntimePresetSafetyFloor).to_string(),
        tr(locale, MessageId::SetupRuntimePresetApplyHint).to_string(),
    ]);
    lines.join("\n")
}

fn runtime_preset_diff_rows(preset: SetupRuntimePreset, facts: &SetupRuntimeFacts) -> Vec<String> {
    let approval_target = preset.approval_policy().map_or_else(
        || "removed; Full Access comes from settings.permission_posture".to_string(),
        ToString::to_string,
    );
    let mut rows = vec![
        format!(
            "settings.default_mode: {} -> {}",
            facts.default_mode,
            preset.display_mode()
        ),
        format!(
            "settings.permission_posture: -> {}",
            preset.permission_posture()
        ),
        format!(
            "config.approval_policy: {} -> {}",
            facts.approval_policy_value, approval_target
        ),
        format!(
            "config.allow_shell: {} -> {}",
            facts.allow_shell_enabled,
            preset.allow_shell()
        ),
        format!(
            "config.sandbox_mode: {} -> {}",
            facts.sandbox_mode_value,
            preset.sandbox_mode()
        ),
        format!(
            "config.network.default: {} -> unchanged",
            facts.network_default_value
        ),
        format!("workspace trust: {} -> unchanged", facts.trust),
    ];
    if let Some(warning) = facts.project_override_warning.as_deref() {
        rows.push(format!("project override warning: {warning}"));
    }
    rows
}

fn project_runtime_override_warning(workspace: &Path, locale: Locale) -> Option<String> {
    let outcome = codewhale_config::load_project_config_outcome(workspace);
    // A project config that exists but can't be parsed is not the same as no
    // project config: its restrictions are silently not in effect, and the
    // workspace falls back to the user's baseline. Say so here rather than
    // only in a log line the TUI never shows.
    if let Some((path, reason)) = outcome.invalid() {
        let path = path.display();
        return Some(match locale {
            Locale::ZhHans => format!(
                "ๆ— ๆณ•่งฃๆž้กน็›ฎ้…็ฝฎ {path}๏ผˆ{reason}๏ผ‰ใ€‚ๆญคๅทฅไฝœๅŒบ็š„้กน็›ฎ็บง่ฟ่กŒๅงฟๆ€้™ๅˆถๆœช็”Ÿๆ•ˆ๏ผŒๅฐ†ๅ›ž้€€ๅˆฐ็”จๆˆท้ป˜่ฎคๅ€ผใ€‚",
            ),
            _ => format!(
                "Project config {path} could not be parsed ({reason}). Its runtime posture restrictions are NOT in effect; this workspace falls back to your user defaults.",
            ),
        });
    }
    let project = outcome.into_config()?;
    let mut fields = Vec::new();
    if let Some(policy) = project.approval_policy.as_deref() {
        fields.push(format!("approval_policy={policy}"));
    }
    if let Some(mode) = project.sandbox_mode.as_deref() {
        fields.push(format!("sandbox_mode={mode}"));
    }
    if fields.is_empty() {
        return None;
    }
    Some(match locale {
        Locale::ZhHans => format!(
            "ๆญคๅทฅไฝœๅŒบ็š„้กน็›ฎ้…็ฝฎๅŒ…ๅซ {}ใ€‚้ข„่ฎพไผšไฟๅญ˜็”จๆˆท้ป˜่ฎคๅ€ผ๏ผ›้กน็›ฎ้…็ฝฎไปๅฏๅœจๆญคๅทฅไฝœๅŒบๆ”ถ็ดง่ฟ่กŒๅงฟๆ€ใ€‚",
            fields.join(", ")
        ),
        _ => format!(
            "Project config contains {}. Presets save user defaults; project config can still tighten runtime posture in this workspace.",
            fields.join(", ")
        ),
    })
}

fn setup_report_result(state: &SetupState, facts: &SetupRuntimeFacts) -> String {
    format!(
        "first_run={}, update={}, operate={}, constitution={:?}, autonomy={}, posture={:?}, runtime={}, operate_fleet={}",
        if state.first_run_ready() {
            "ready"
        } else {
            "needs_action"
        },
        if state.update_ready(CONSTITUTION_CHECKPOINT_VERSION) {
            "ready"
        } else {
            "needs_action"
        },
        if state.operate_ready() {
            "ready"
        } else {
            "needs_action"
        },
        state.constitution_choice,
        facts.constitution_autonomy,
        state.runtime_posture_source,
        facts.runtime_result,
        facts.operate_result
    )
}

fn remote_runtime_on_ramp_text(locale: Locale, facts: &SetupRuntimeFacts) -> String {
    remote::on_ramp_text(
        locale,
        &facts.remote_clouds_result,
        &facts.remote_bridges_result,
        &facts.remote_providers_result,
        &facts.remote_mode_result,
        &facts.remote_command_provider,
    )
}

fn tools_mcp_on_ramp_text(locale: Locale, facts: &SetupRuntimeFacts) -> String {
    let tools_facts = tools_mcp::SetupToolsMcpFacts {
        servers_result: facts.tools_mcp_servers_result.clone(),
        skills_result: facts.tools_mcp_skills_result.clone(),
        tools_result: facts.tools_mcp_tools_result.clone(),
        plugins_result: facts.tools_mcp_plugins_result.clone(),
        hotbar_result: facts.tools_mcp_hotbar_result.clone(),
        dsh_result: facts.tools_mcp_dsh_result.clone(),
        result: facts.tools_mcp_result.clone(),
        overall_status: if facts.tools_mcp_needs_action {
            tools_mcp::InventoryStatus::NeedsConfig
        } else if facts.tools_mcp_result.contains("overall=off") {
            tools_mcp::InventoryStatus::Off
        } else {
            tools_mcp::InventoryStatus::Healthy
        },
        needs_action: facts.tools_mcp_needs_action,
        mcp_path_display: facts.tools_mcp_path_display.clone(),
        skills_path_display: facts.tools_mcp_skills_path_display.clone(),
        plugins_path_display: facts.tools_mcp_plugins_path_display.clone(),
    };
    tools_mcp::on_ramp_text(locale, &tools_facts)
}

/// Who authored the draft being previewed for ratification.
#[derive(Debug, Clone, PartialEq, Eq)]
enum DraftProvenance {
    /// Rendered deterministically from the guided answers.
    Guided,
    /// Drafted by the named model, then sanitized and bounded by Codewhale.
    Model(String),
    /// The user's existing `constitution.json`, shown unchanged for the
    /// keep-existing checkpoint completion (#3794).
    Existing,
}

fn ratification_preview_title(locale: Locale) -> &'static str {
    match locale {
        Locale::Ja => "ใƒฆใƒผใ‚ถใƒผๆ†ฒๆณ• - ๆ‰นๅ‡†ๅ‰ใฎ่‰ๆกˆ",
        Locale::ZhHans => "็”จๆˆทๅฎช็ซ  โ€” ็กฎ่ฎคๅ‰่‰ๆกˆ",
        Locale::ZhHant => "ไฝฟ็”จ่€…ๆ†ฒๆณ• - ๆ‰นๅ‡†ๅ‰่‰ๆกˆ",
        Locale::PtBr => "Constituiรงรฃo do Usuรกrio - Rascunho para Ratificaรงรฃo",
        Locale::Es419 => "Constituciรณn del Usuario - Borrador para Ratificaciรณn",
        Locale::Vi => "Hiแบฟn phรกp Ngฦฐแปi dรนng - Bแบฃn nhรกp ฤ‘แปƒ phรช chuแบฉn",
        Locale::Ko => "์‚ฌ์šฉ์ž ํ—Œ๋ฒ• - ์Šน์ธ ์ „ ์ดˆ์•ˆ",
        Locale::Ca => "Constituciรณ de l'Usuari - Esborrany per a Ratificaciรณ",
        Locale::De => "Nutzerverfassung - Entwurf zur Ratifizierung",
        Locale::Fr => "Constitution de l'Utilisateur - Brouillon pour Ratification",
        Locale::Id => "Konstitusi Pengguna - Draf untuk Ratifikasi",
        Locale::Hi => "เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เคธเค‚เคตเคฟเคงเคพเคจ - เค…เค‚เค—เฅ€เค•เคพเคฐ เคนเฅ‡เคคเฅ เคฎเคธเฅŒเคฆเคพ",
        Locale::Ru => "ะšะพะฝัั‚ะธั‚ัƒั†ะธั ะฟะพะปัŒะทะพะฒะฐั‚ะตะปั - ะŸั€ะพะตะบั‚ ะดะปั ั€ะฐั‚ะธั„ะธะบะฐั†ะธะธ",
        Locale::Uk => "ะšะพะฝัั‚ะธั‚ัƒั†ั–ั ะบะพั€ะธัั‚ัƒะฒะฐั‡ะฐ - ะŸั€ะพั”ะบั‚ ะดะปั ั€ะฐั‚ะธั„ั–ะบะฐั†ั–ั—",
        _ => "User Constitution โ€” Draft for Ratification",
    }
}

/// The ratification artifact shown in the pager: provenance, what a
/// constitution is, the exact block that will be injected (byte-identical to
/// prompt assembly's rendering), its authority boundaries, and how to ratify
/// or amend. Only the scaffold differs between guided and model drafts โ€” the
/// law itself always comes from the same renderer.
fn constitution_ratification_text(
    locale: Locale,
    constitution: &UserConstitution,
    provenance: &DraftProvenance,
) -> String {
    const RULE: &str = "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€";
    let rendered = constitution
        .render_block(None)
        .unwrap_or_else(|| match locale {
            Locale::Ja => "ๆง‹้€ ๅŒ–ใ•ใ‚ŒใŸๆ†ฒๆณ•ใฏ็ฉบใงใ™ใ€‚".to_string(),
            Locale::ZhHans => "็ป“ๆž„ๅŒ–ๅฎช็ซ ไธบ็ฉบใ€‚".to_string(),
            Locale::ZhHant => "็ตๆง‹ๅŒ–ๆ†ฒๆณ•็‚บ็ฉบใ€‚".to_string(),
            Locale::PtBr => "A constituiรงรฃo estruturada estรก vazia.".to_string(),
            Locale::Es419 => "La constituciรณn estructurada estรก vacรญa.".to_string(),
            Locale::Vi => "Hiแบฟn phรกp cรณ cแบฅu trรบc ฤ‘ang trแป‘ng.".to_string(),
            Locale::Ko => "๊ตฌ์กฐํ™”๋œ ํ—Œ๋ฒ•์ด ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค.".to_string(),
            Locale::Ca => "La constituciรณ estructurada รฉs buida.".to_string(),
            Locale::De => "Die strukturierte Verfassung ist leer.".to_string(),
            Locale::Fr => "La constitution structurรฉe est vide.".to_string(),
            Locale::Id => "Konstitusi terstruktur kosong.".to_string(),
            Locale::Hi => "เคธเค‚เคฐเคšเคฟเคค เคธเค‚เคตเคฟเคงเคพเคจ เค–เคพเคฒเฅ€ เคนเฅˆเฅค".to_string(),
            Locale::Ru => "ะกั‚ั€ัƒะบั‚ัƒั€ะธั€ะพะฒะฐะฝะฝะฐั ะบะพะฝัั‚ะธั‚ัƒั†ะธั ะฟัƒัั‚ะฐ.".to_string(),
            Locale::Uk => "ะกั‚ั€ัƒะบั‚ัƒั€ะพะฒะฐะฝะฐ ะบะพะฝัั‚ะธั‚ัƒั†ั–ั ะฟะพั€ะพะถะฝั.".to_string(),
            _ => "The structured constitution is empty.".to_string(),
        });
    let layer_order = tr(locale, MessageId::SetupCheckpointLayerOrder);

    match locale {
        Locale::Ja => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "{label} ใŒใ‚ใชใŸใฎใ‚ฌใ‚คใƒ‰ๅ›ž็ญ”ใ‹ใ‚‰่ตท่‰ใ—ใ€Codewhale ใŒๆง‹้€ ๆคœ่จผใจๅขƒ็•Œๅˆถ้™ใ‚’้ฉ็”จใ—ใพใ—ใŸใ€‚"
                ),
                DraftProvenance::Guided => {
                    "ใ‚ใชใŸใฎใ‚ฌใ‚คใƒ‰ๅ›ž็ญ”ใ‹ใ‚‰ๆฑบๅฎš็š„ใซ็”Ÿๆˆใ•ใ‚Œใพใ—ใŸใ€‚".to_string()
                }
                DraftProvenance::Existing => {
                    "ๆ—ขๅญ˜ใฎๆ†ฒๆณ•ใ‚’ constitution.json ใ‹ใ‚‰่ชญใฟ่พผใฟใ€ๅค‰ๆ›ดใ›ใšใซ่กจ็คบใ—ใฆใ„ใพใ™ใ€‚"
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "ใ“ใ‚Œใฏใ™ใงใซๆœ‰ๅŠนใชๅŸบๆบ–ใงใ™ใ€‚ใƒ—ใƒฌใƒ“ใƒฅใƒผใ‚’้–‰ใ˜ใฆ K ใ‚’ๆŠผใ™ใจใ€ใ“ใฎใพใพไฟๆŒใ—ใฆใƒใ‚งใƒƒใ‚ฏใƒใ‚คใƒณใƒˆใ‚’ๅฎŒไบ†ใ—ใพใ™ใ€‚\
                     ใƒ•ใ‚กใ‚คใƒซใฏๅค‰ๆ›ดใ•ใ‚Œใพใ›ใ‚“ใ€‚/constitution ใพใŸใฏ /setup ใงใ„ใคใงใ‚‚ไฟฎๆญฃใงใใพใ™ใ€‚"
                }
                _ => {
                    "็ขบ่ชใ™ใ‚‹ใพใงใ€ใฉใฎๅ†…ๅฎนใ‚‚ๅŸบๆบ–ใซใฏใชใ‚Šใพใ›ใ‚“ใ€‚ใƒ—ใƒฌใƒ“ใƒฅใƒผใ‚’้–‰ใ˜ใฆ G ใ‚’ๆŠผใ™ใจๆ‰นๅ‡†ใ—ใฆไฟๅญ˜ใ—ใพใ™ใ€‚\
                     /constitution ใพใŸใฏ /setup ใงใ„ใคใงใ‚‚ไฟฎๆญฃใงใใพใ™ใ€‚"
                }
            };
            format!(
                "CODEWHALE ยท ใƒฆใƒผใ‚ถใƒผๆ†ฒๆณ•\n{RULE}\n\n{drafted_by}\n\n\
                 ใ“ใ‚Œใฏ Codewhale ใŒใ‚ใชใŸใจๅ”ๅƒใ™ใ‚‹ใŸใ‚ใฎๅธธ่จญใฎๅŸบๆบ–ใงใ™ใ€‚ๅ„ชใ‚ŒใŸๆ†ฒๆณ•ใฎใ‚ˆใ†ใซใ€ไฝฟใˆใ‚‹ใปใฉ็Ÿญใใ€\
                 ็ถฒ็พ…็š„ใช่ฆๅ‰‡ใงใฏใชใๆŒ็ถšใ™ใ‚‹ๅŽŸๅ‰‡ใงๆง‹ๆˆใ•ใ‚Œใ€ใ‚ใชใŸใฎๅค‰ๅŒ–ใซๅˆใ‚ใ›ใฆไฟฎๆญฃใงใใพใ™ใ€‚\
                 ใ™ในใฆใฎๅ€‹ๅˆฅๅˆคๆ–ญใ‚’่ฃใใฎใงใฏใชใๆจฉ้™ใจๅขƒ็•Œใ‚’ๅฎšใ‚ใ€ใ‚ปใƒƒใ‚ทใƒงใƒณใ‚’่ถŠใˆใฆๅ”ๅƒใ‚’็ถ™็ถšใ•ใ›ใพใ™ใ€‚\
                 ใŸใ ใ—ใ“ใ‚Œใฏ่จ˜ๆ†ถใงใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚ๅฑฅๆญดใงใฏใชใๅŽŸๅ‰‡ใ‚’ไฟๆŒใ—ใพใ™ใ€‚\n\n\
                 {rendered}\n\n\
                 ๆจฉ้™ใฎ้šŽๅฑค\n{layer_order}\nใ‚ใชใŸใฎ็›ดๆŽฅใฎๆŒ‡็คบใฏๅธธใซใ“ใฎๆ–‡ๆ›ธใ‚ˆใ‚Šๅ„ชๅ…ˆใ•ใ‚Œใพใ™ใ€‚\n\n\
                 ใ“ใ‚ŒใŒใงใใชใ„ใ“ใจ\n\
                 ใ“ใ‚Œใฏ่กŒๅ‹•ใ‚’ๅฐŽใใ‚‚ใฎใงใ™ใ€‚ๆ‰ฟ่ชใƒใƒชใ‚ทใƒผใ€ใ‚ตใƒณใƒ‰ใƒœใƒƒใ‚ฏใ‚นใ€Shellใ€ใƒใƒƒใƒˆใƒฏใƒผใ‚ฏใ€ไฟก้ ผใ€MCP ๆจฉ้™ใ€\
                 ๆ—ขๅฎšใƒขใƒผใƒ‰ใ€ๅ…ฌ้–‹ใ€ๆ”ฏๅ‡บใฎๆจฉ้™ใ‚’ไป˜ไธŽใพใŸใฏๅค‰ๆ›ดใ™ใ‚‹ใ“ใจใฏใงใใพใ›ใ‚“ใ€‚ใ“ใ‚Œใ‚‰ใฏๅฎŸ่กŒๆ™‚ใซใ‚ใชใŸใŒ็ฎก็†ใ—ใพใ™ใ€‚\n\n\
                 ็ธฎๅฐใ‚ณใ‚ขใจไปปๆ„ใƒขใ‚ธใƒฅใƒผใƒซ\n\
                 ็ต„ใฟ่พผใฟใฎใ‚ณใ‚ขใฏๅผ•ใ็ถšใๆœ‰ๅŠนใงใ™ใ€‚ใ“ใฎ่‰ๆกˆใฏใƒฆใƒผใ‚ถใƒผใ‚ฐใƒญใƒผใƒใƒซใฎ้•ทๆœŸ่จญๅฎšใ ใ‘ใ‚’ไฟๅญ˜ใ—ใพใ™ใ€‚\
                 ๅฎŸ่กŒใจใ‚ชใƒผใ‚ฑใ‚นใƒˆใƒฌใƒผใ‚ทใƒงใƒณใฎๆฉŸ่ƒฝใฏใ€ใƒฉใƒณใ‚ฟใ‚คใƒ ใƒใƒชใ‚ทใƒผใ€็พๅœจใฎใƒ„ใƒผใƒซใ‚ซใ‚ฟใƒญใ‚ฐใ€ใพใŸใฏๅฐ†ๆฅใฎไปปๆ„ใƒขใ‚ธใƒฅใƒผใƒซใ‹ใ‚‰ๆไพ›ใ•ใ‚Œใพใ™ใ€‚ใ“ใฎใƒ—ใƒฌใƒ“ใƒฅใƒผใฏใƒขใ‚ธใƒฅใƒผใƒซใ‚’ๆœ‰ๅŠนๅŒ–ใ›ใšใ€่จญๅฎšใ‚‚ๅค‰ๆ›ดใ—ใพใ›ใ‚“ใ€‚\n\n\
                 ๆ‰นๅ‡†\n{ratify_how}"
            )
        }
        Locale::ZhHans => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "็”ฑ {label} ๆ นๆฎไฝ ็š„ๅผ•ๅฏผๅผ็ญ”ๆกˆ่ตท่‰๏ผŒๅนถๅทฒ็”ฑ Codewhale ๅฎŒๆˆ็ป“ๆž„ๆ ก้ชŒไธŽ่พน็•Œ้™ๅˆถใ€‚"
                ),
                DraftProvenance::Guided => "็”ฑไฝ ็š„ๅผ•ๅฏผๅผ็ญ”ๆกˆ็กฎๅฎšๆ€ง็”Ÿๆˆใ€‚".to_string(),
                DraftProvenance::Existing => {
                    "ไฝ ็Žฐๆœ‰็š„ๅฎช็ซ ๏ผŒ่ฏปๅ–่‡ช constitution.jsonโ€”โ€”ๅŽŸๆ ทๅฑ•็คบ๏ผŒๆœชๅšไปปไฝ•ไฟฎๆ”นใ€‚".to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "่ฟ™ๅทฒๆ˜ฏไฝ ๅฝ“ๅ‰ไฝฟ็”จ็š„ๅฎช็ซ ใ€‚ๅ…ณ้—ญๆญค้ข„่งˆๅŽๆŒ‰ K ไฟ็•™ๅนถๅฎŒๆˆๆฃ€ๆŸฅ็‚นโ€”โ€”ๆ–‡ไปถไธไผš่ขซไฟฎๆ”นใ€‚\
                     ไน‹ๅŽๅฏ้šๆ—ถ็”จ /constitution ๆˆ– /setup ไฟฎๆ”นใ€‚"
                }
                _ => {
                    "ๆœช็ปไฝ ็กฎ่ฎค๏ผŒไปปไฝ•ๅ†…ๅฎน้ƒฝไธไผšๆˆไธบๅฎช็ซ ใ€‚ๅ…ณ้—ญๆญค้ข„่งˆๅŽๆŒ‰ G ็กฎ่ฎคๅนถไฟๅญ˜๏ผ›\
                     ไน‹ๅŽๅฏ้šๆ—ถ็”จ /constitution ๆˆ– /setup ไฟฎๆ”นใ€‚"
                }
            };
            format!(
                "CODEWHALE ยท ็”จๆˆทๅฎช็ซ \n{RULE}\n\n{drafted_by}\n\n\
                 ่ฟ™ๆ˜ฏ Codewhale ไธŽไฝ ๅไฝœๆ—ถ้•ฟๆœŸ้ตๅพช็š„ๅๅฅฝๅ’Œ่ง„ๅˆ™ใ€‚ๅ†…ๅฎนๅบ”ไฟๆŒ็ฎ€็Ÿญใ€ไพฟไบŽๆ‰ง่กŒ๏ผŒไปฅๆŒไน…ๅŽŸๅˆ™ไธบไธป๏ผŒๅนถๅฏ้šๆ—ถ่ฐƒๆ•ดใ€‚\
                 ๅฎƒ็•Œๅฎšๅไฝœๆ–นๅผไธŽ่กŒไธบ่พน็•Œ๏ผŒ่€Œไธๆ˜ฏๆ›ฟไฝ ๅ†ณๅฎšๆฏไธ€็งๆƒ…ๅ†ต๏ผ›ๅฎƒ่ฎฉๅไฝœ่ทจไผš่ฏๅปถ็ปญโ€”โ€”ไฝ†ๅฎƒไธๆ˜ฏ่ฎฐๅฟ†๏ผŒๅชไฟ็•™ๅŽŸๅˆ™๏ผŒไธไฟ็•™ๅކๅฒใ€‚\n\n\
                 {rendered}\n\n\
                 ๆƒ้™ๅฑ‚็บง\n{layer_order}\nไฝ ็š„็›ดๆŽฅๆŒ‡ไปคๅง‹็ปˆ้ซ˜ไบŽๆœฌๆ–‡ไปถใ€‚\n\n\
                 ๅฎƒไธ่ƒฝๅšไป€ไนˆ\n\
                 ๅฎƒๅชๆไพ›่กŒไธบๆŒ‡ๅฏผ๏ผŒไธ่ƒฝๆŽˆไบˆๆˆ–ๆ›ดๆ”นๅฎกๆ‰น็ญ–็•ฅใ€ๆฒ™็ฎฑใ€Shellใ€็ฝ‘็ปœใ€ไฟกไปปใ€MCP ๆƒ้™ใ€้ป˜่ฎคๆจกๅผใ€ๅ‘ๅธƒๆˆ–ๆ”ฏๅ‡บๆƒ้™โ€”โ€”่ฟ™ไบ›ๅง‹็ปˆ็”ฑไฝ ๅœจ่ฟ่กŒๆ—ถๆŽŒๆŽงใ€‚\n\n\
                 ็ฒพ็ฎ€ๆ ธๅฟƒไธŽๅฏ้€‰็ญ–็•ฅ\n\
                 ๅ†…็ฝฎๆ ธๅฟƒๅง‹็ปˆ็”Ÿๆ•ˆใ€‚ๆœฌ่‰ๆกˆๅชไฟๅญ˜ไฝ ็š„็”จๆˆทๅ…จๅฑ€้•ฟๆœŸๅๅฅฝใ€‚ๆ‰ง่กŒไธŽ็ผ–ๆŽ’่ƒฝๅŠ›ๆฅ่‡ช่ฟ่กŒๆ—ถ็ญ–็•ฅใ€ๅฝ“ๅ‰ๅทฅๅ…ท็›ฎๅฝ•ๆˆ–ๆœชๆฅ็š„ๅฏ้€‰่ง„ๅˆ™ๅŒ…๏ผ›ๆญค้ข„่งˆไธไผšๅฏ็”จไปปไฝ•็ญ–็•ฅๆˆ–ๆ›ดๆ”น้…็ฝฎใ€‚\n\n\
                 ็กฎ่ฎค\n{ratify_how}"
            )
        }
        Locale::ZhHant => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "็”ฑ {label} ๆ นๆ“šไฝ ็š„ๅผ•ๅฐŽๅผ็ญ”ๆกˆ่ตท่‰๏ผŒไธฆๅทฒ็”ฑ Codewhale ๅฎŒๆˆ็ตๆง‹้ฉ—่ญ‰่ˆ‡้‚Š็•Œ้™ๅˆถใ€‚"
                ),
                DraftProvenance::Guided => "็”ฑไฝ ็š„ๅผ•ๅฐŽๅผ็ญ”ๆกˆ็ขบๅฎšๆ€ง็”Ÿๆˆใ€‚".to_string(),
                DraftProvenance::Existing => {
                    "ไฝ ็พๆœ‰็š„ๆ†ฒๆณ•๏ผŒ่ฎ€ๅ–่‡ช constitution.json๏ผ›ๅŽŸๆจฃๅฑ•็คบ๏ผŒๆœชๅšไปปไฝ•ไฟฎๆ”นใ€‚".to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "้€™ๅทฒๆ˜ฏไฝ ็พ่กŒ็š„ๆบ–ๅ‰‡ใ€‚้—œ้–‰ๆญค้ ่ฆฝๅพŒๆŒ‰ K ไฟ็•™ไธฆๅฎŒๆˆๆชขๆŸฅ้ปž๏ผ›\
                     ๆช”ๆกˆไธๆœƒ่ขซไฟฎๆ”นใ€‚ไน‹ๅพŒๅฏ้šจๆ™‚็”จ /constitution ๆˆ– /setup ไฟฎ่จ‚ใ€‚"
                }
                _ => {
                    "ๆœช็ถ“ไฝ ็ขบ่ช๏ผŒไปปไฝ•ๅ…งๅฎน้ƒฝไธๆœƒๆˆ็‚บๆบ–ๅ‰‡ใ€‚้—œ้–‰ๆญค้ ่ฆฝๅพŒๆŒ‰ G ๆ‰นๅ‡†ไธฆไฟๅญ˜๏ผ›\
                     ไน‹ๅพŒๅฏ้šจๆ™‚็”จ /constitution ๆˆ– /setup ไฟฎ่จ‚ใ€‚"
                }
            };
            format!(
                "CODEWHALE ยท ไฝฟ็”จ่€…ๆ†ฒๆณ•\n{RULE}\n\n{drafted_by}\n\n\
                 ้€™ๆ˜ฏ Codewhale ่ˆ‡ไฝ ๅ”ไฝœ็š„้•ทๆœŸๆบ–ๅ‰‡ใ€‚ๅƒๅ„ช็ง€็š„ๆ†ฒๆณ•ไธ€ๆจฃ๏ผš่ถณๅค ็ฐก็Ÿญๅ› ่€Œๅฏ็”จ๏ผŒ็”ฑๆŒไน…ๅŽŸๅ‰‡่€Œ้ž่ฉณ็›ก่ฆๅ‰‡ๆง‹ๆˆ๏ผŒไธฆไธ”ๅฏไปฅ้šจไฝ ไฟฎ่จ‚ใ€‚\
                 ๅฎƒ็•ŒๅฎšๆฌŠๅŠ›่ˆ‡้‚Š็•Œ๏ผŒ่€Œ้ž่ฃๆฑบๆฏๅ€‹ๅ…ท้ซ”ๆฑบๅฎš๏ผ›ๅฎƒ่ฎ“ๅ”ไฝœ่ทจๆœƒ่ฉฑๅปถ็บŒ๏ผŒไฝ†ๅฎƒไธๆ˜ฏ่จ˜ๆ†ถ๏ผŒๅฎƒๆ‰ฟ่ผ‰็š„ๆ˜ฏๅŽŸๅ‰‡๏ผŒ่€Œ้žๆญทๅฒใ€‚\n\n\
                 {rendered}\n\n\
                 ๆฌŠ้™ๅฑค็ดš\n{layer_order}\nไฝ ็š„็›ดๆŽฅๆŒ‡ไปคๅง‹็ต‚้ซ˜ๆ–ผๆœฌๆ–‡ไปถใ€‚\n\n\
                 ๅฎƒไธ่ƒฝๅšไป€้บผ\n\
                 ๅฎƒๅชๆไพ›่กŒ็‚บๆŒ‡ๅฐŽ๏ผŒไธ่ƒฝๆŽˆไบˆๆˆ–ๆ›ดๆ”นๅฏฉๆ‰น็ญ–็•ฅใ€ๆฒ™็ฎฑใ€Shellใ€็ถฒ่ทฏใ€ไฟกไปปใ€MCP ๆฌŠ้™ใ€้ ่จญๆจกๅผใ€็™ผๅธƒๆˆ–ๆ”ฏๅ‡บๆฌŠ้™๏ผ›้€™ไบ›ๅง‹็ต‚็”ฑไฝ ๅœจๅŸท่กŒๆ™‚ๆŽŒๆŽงใ€‚\n\n\
                 ็ฒพ็ฐกๆ ธๅฟƒ่ˆ‡ๅฏ้ธๆจก็ต„\n\
                 ๅ…งๅปบๆ ธๅฟƒๅง‹็ต‚็”Ÿๆ•ˆใ€‚ๆœฌ่‰ๆกˆๅชไฟๅญ˜ไฝ ็š„ไฝฟ็”จ่€…ๅ…จๅŸŸ้•ทๆœŸๅๅฅฝใ€‚ๅŸท่กŒ่ˆ‡็ทจๆŽ’่ƒฝๅŠ›็”ฑๅŸท่กŒๆ™‚ๆ”ฟ็ญ–ใ€ๅณๆ™‚ๅทฅๅ…ท็›ฎ้Œ„ๆˆ–ๆœชไพ†็š„ๅฏ้ธๆจก็ต„ๆไพ›๏ผ›ๆญค้ ่ฆฝไธๆœƒๅ•Ÿ็”จๆจก็ต„ๆˆ–ๆ›ดๆ”นๅ…ถ้…็ฝฎใ€‚\n\n\
                 ๆ‰นๅ‡†\n{ratify_how}"
            )
        }
        Locale::PtBr => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Rascunhado por {label} a partir das suas respostas guiadas, depois validado por schema e limitado pelo Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Renderizado deterministicamente a partir das suas respostas guiadas.".to_string()
                }
                DraftProvenance::Existing => {
                    "Sua constituiรงรฃo existente, carregada de constitution.json, รฉ exibida sem alteraรงรตes."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "Esta jรก รฉ sua regra vigente. Feche a prรฉvia e pressione K para mantรช-la e concluir o checkpoint; \
                     o arquivo nรฃo serรก modificado. Edite quando quiser com /constitution ou /setup."
                }
                _ => {
                    "Nada vira regra atรฉ vocรช confirmar. Feche a prรฉvia e pressione G para ratificar e salvar. \
                     Edite quando quiser com /constitution ou /setup."
                }
            };
            format!(
                "CODEWHALE ยท CONSTITUIร‡รƒO DO USUรRIO\n{RULE}\n\n{drafted_by}\n\n\
                 Esta รฉ a regra permanente de como o Codewhale trabalha com vocรช. Como boas constituiรงรตes, \
                 ela รฉ curta o bastante para ser usada, formada por princรญpios durรกveis em vez de regras exaustivas, \
                 e pode ser emendada conforme vocรช muda. Ela define poderes e limites em vez de decidir cada caso, \
                 e dรก continuidade ร  colaboraรงรฃo entre sessรตes. Mas ela nรฃo รฉ memรณria: carrega princรญpios, nรฃo histรณrico.\n\n\
                 {rendered}\n\n\
                 HIERARQUIA DE AUTORIDADE\n{layer_order}\nSeus pedidos diretos sempre superam este documento.\n\n\
                 O QUE ISTO NรƒO PODE FAZER\n\
                 Isto orienta comportamento. Nรฃo pode conceder nem alterar polรญtica de aprovaรงรฃo, sandbox, shell, rede, \
                 confianรงa, permissรตes MCP, modo padrรฃo, publicaรงรฃo ou autoridade para gastos; isso continua sob seu controle em tempo de execuรงรฃo.\n\n\
                 NรšCLEO REDUZIDO E Mร“DULOS OPT-IN\n\
                 O nรบcleo embutido continua ativo. Este rascunho sรณ salva suas preferรชncias permanentes globais de usuรกrio. \
                 Capacidades de execuรงรฃo e orquestraรงรฃo vรชm da polรญtica de execuรงรฃo, do catรกlogo de ferramentas ativo ou de mรณdulos opt-in futuros; esta prรฉvia nรฃo ativa mรณdulos nem muda sua configuraรงรฃo.\n\n\
                 RATIFICAร‡รƒO\n{ratify_how}"
            )
        }
        Locale::Es419 => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Redactado por {label} desde tus respuestas guiadas, luego validado por schema y acotado por Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Renderizado de forma determinรญstica desde tus respuestas guiadas.".to_string()
                }
                DraftProvenance::Existing => {
                    "Tu constituciรณn existente, cargada desde constitution.json, se muestra sin cambios."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "Esta ya es tu regla vigente. Cierra la vista previa y presiona K para conservarla y completar el checkpoint; \
                     el archivo no se modifica. Puedes enmendarla cuando quieras con /constitution o /setup."
                }
                _ => {
                    "Nada se vuelve regla hasta que confirmes. Cierra la vista previa y presiona G para ratificar y guardar. \
                     Puedes enmendarla cuando quieras con /constitution o /setup."
                }
            };
            format!(
                "CODEWHALE ยท CONSTITUCIร“N DEL USUARIO\n{RULE}\n\n{drafted_by}\n\n\
                 Esta es la regla permanente de cรณmo Codewhale trabaja contigo. Como las buenas constituciones, \
                 es lo bastante breve para usarse, hecha de principios duraderos en vez de reglas exhaustivas, \
                 y enmendable a medida que cambias. Define poderes y lรญmites en vez de decidir cada caso, \
                 y da continuidad a la colaboraciรณn entre sesiones. Pero no es memoria: lleva principios, no historial.\n\n\
                 {rendered}\n\n\
                 JERARQUรA DE AUTORIDAD\n{layer_order}\nTus pedidos directos siempre superan este documento.\n\n\
                 LO QUE ESTO NO PUEDE HACER\n\
                 Orienta comportamiento. No puede conceder ni cambiar polรญtica de aprobaciรณn, sandbox, shell, red, \
                 confianza, permisos MCP, modo predeterminado, publicaciรณn o autoridad de gasto; eso sigue bajo tu control en tiempo de ejecuciรณn.\n\n\
                 NรšCLEO REDUCIDO Y Mร“DULOS OPT-IN\n\
                 El nรบcleo integrado sigue activo. Este borrador solo guarda tus preferencias permanentes globales de usuario. \
                 Las capacidades de ejecuciรณn y orquestaciรณn provienen de la polรญtica de ejecuciรณn, el catรกlogo activo de herramientas o mรณdulos opt-in futuros; esta vista previa no activa mรณdulos ni cambia su configuraciรณn.\n\n\
                 RATIFICACIร“N\n{ratify_how}"
            )
        }
        Locale::Vi => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "ฤฦฐแปฃc {label} soแบกn tแปซ cรขu trแบฃ lแปi hฦฐแป›ng dแบซn cแปงa bแบกn, rแป“i ฤ‘ฦฐแปฃc Codewhale kiแปƒm tra schema vร  giแป›i hแบกn biรชn."
                ),
                DraftProvenance::Guided => {
                    "ฤฦฐแปฃc kแบฟt xuแบฅt xรกc ฤ‘แป‹nh tแปซ cรขu trแบฃ lแปi hฦฐแป›ng dแบซn cแปงa bแบกn.".to_string()
                }
                DraftProvenance::Existing => {
                    "Hiแบฟn phรกp hiแป‡n cรณ cแปงa bแบกn, tแบฃi tแปซ constitution.json, ฤ‘ฦฐแปฃc hiแปƒn thแป‹ nguyรชn trแบกng."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "ฤรขy ฤ‘รฃ lร  luแบญt hiแป‡n hร nh cแปงa bแบกn. ฤรณng bแบฃn xem trฦฐแป›c rแป“i nhแบฅn K ฤ‘แปƒ giแปฏ nguyรชn vร  hoร n tแบฅt checkpoint; \
                     tแป‡p khรดng bแป‹ sแปญa. Cรณ thแปƒ chแป‰nh bแบฅt cแปฉ lรบc nร o bแบฑng /constitution hoแบทc /setup."
                }
                _ => {
                    "Khรดng cรณ gรฌ trแปŸ thร nh luแบญt cho ฤ‘แบฟn khi bแบกn xรกc nhแบญn. ฤรณng bแบฃn xem trฦฐแป›c rแป“i nhแบฅn G ฤ‘แปƒ phรช chuแบฉn vร  lฦฐu. \
                     Cรณ thแปƒ chแป‰nh bแบฅt cแปฉ lรบc nร o bแบฑng /constitution hoแบทc /setup."
                }
            };
            format!(
                "CODEWHALE ยท HIแบพN PHรP NGฦฏแปœI Dร™NG\n{RULE}\n\n{drafted_by}\n\n\
                 ฤรขy lร  luแบญt thฦฐแปng trแปฑc cho cรกch Codewhale lร m viแป‡c vแป›i bแบกn. Giแป‘ng cรกc hiแบฟn phรกp tแป‘t, \
                 nรณ ฤ‘แปง ngแบฏn ฤ‘แปƒ dรนng, gแป“m cรกc nguyรชn tแบฏc bแปn vแปฏng thay vรฌ luแบญt lแป‡ cแบกn kiแป‡t, \
                 vร  cรณ thแปƒ sแปญa khi bแบกn thay ฤ‘แป•i. Nรณ ฤ‘แป‹nh khung quyแปn hแบกn vร  giแป›i hแบกn thay vรฌ quyแบฟt ฤ‘แป‹nh tแปซng trฦฐแปng hแปฃp, \
                 ฤ‘แป“ng thแปi giแปฏ sแปฑ liรชn tแปฅc giแปฏa cรกc phiรชn. Nhฦฐng nรณ khรดng phแบฃi bแป™ nhแป›: nรณ mang nguyรชn tแบฏc, khรดng mang lแป‹ch sแปญ.\n\n\
                 {rendered}\n\n\
                 THแปจ BแบฌC THแบจM QUYแป€N\n{layer_order}\nYรชu cแบงu trแปฑc tiแบฟp cแปงa bแบกn luรดn cao hฦกn tร i liแป‡u nร y.\n\n\
                 ฤIแป€U Nร€Y KHร”NG THแป‚ Lร€M\n\
                 Nรณ hฦฐแป›ng dแบซn hร nh vi. Nรณ khรดng thแปƒ cแบฅp hoแบทc ฤ‘แป•i chรญnh sรกch phรช duyแป‡t, sandbox, shell, mแบกng, \
                 ฤ‘แป™ tin cแบญy, quyแปn MCP, chแบฟ ฤ‘แป™ mแบทc ฤ‘แป‹nh, xuแบฅt bแบฃn hoแบทc quyแปn chi tiรชu; nhแปฏng thแปฉ ฤ‘รณ vแบซn do bแบกn kiแปƒm soรกt lรบc chแบกy.\n\n\
                 Lร•I RรšT GแปŒN Vร€ Mร”-ฤUN OPT-IN\n\
                 Lรตi tรญch hแปฃp vแบซn hoแบกt ฤ‘แป™ng. Bแบฃn nhรกp nร y chแป‰ lฦฐu tรนy chแปn thฦฐแปng trแปฑc toร n cแปฅc cแปงa ngฦฐแปi dรนng. \
                 Khแบฃ nฤƒng thแปฑc thi vร  ฤ‘iแปu phแป‘i ฤ‘แบฟn tแปซ chรญnh sรกch thแปi gian chแบกy, danh mแปฅc cรดng cแปฅ ฤ‘ang hoแบกt ฤ‘แป™ng hoแบทc mรด-ฤ‘un opt-in trong tฦฐฦกng lai; bแบฃn xem trฦฐแป›c nร y khรดng bแบญt mรด-ฤ‘un hoแบทc ฤ‘แป•i cแบฅu hรฌnh cแปงa chรบng.\n\n\
                 PHรŠ CHUแบจN\n{ratify_how}"
            )
        }
        Locale::Ko => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "{label}์ด(๊ฐ€) ๋‹น์‹ ์˜ ๊ฐ€์ด๋“œ ๋‹ต๋ณ€์„ ๋ฐ”ํƒ•์œผ๋กœ ์ดˆ์•ˆ์„ ์ž‘์„ฑํ–ˆ๊ณ , Codewhale์ด ๊ตฌ์กฐ๋ฅผ ๊ฒ€์ฆํ•˜๊ณ  ๋ฒ”์œ„๋ฅผ ์ œํ•œํ–ˆ์Šต๋‹ˆ๋‹ค."
                ),
                DraftProvenance::Guided => {
                    "๋‹น์‹ ์˜ ๊ฐ€์ด๋“œ ๋‹ต๋ณ€์œผ๋กœ๋ถ€ํ„ฐ ๊ฒฐ์ •์ ์œผ๋กœ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.".to_string()
                }
                DraftProvenance::Existing => {
                    "constitution.json์—์„œ ๋ถˆ๋Ÿฌ์˜จ ๊ธฐ์กด ํ—Œ๋ฒ•์ด๋ฉฐ, ๋ณ€๊ฒฝ ์—†์ด ๊ทธ๋Œ€๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "์ด๊ฒƒ์€ ์ด๋ฏธ ๋‹น์‹ ์˜ ์ƒ์‹œ ๊ทœ์น™์ž…๋‹ˆ๋‹ค. ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ๋‹ซ๊ณ  K๋ฅผ ๋ˆŒ๋Ÿฌ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๋ฉฐ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์™„๋ฃŒํ•˜์„ธ์š”; \
                     ํŒŒ์ผ์€ ์ˆ˜์ •๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. /constitution ๋˜๋Š” /setup์œผ๋กœ ์–ธ์ œ๋“ ์ง€ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
                }
                _ => {
                    "ํ™•์ธํ•˜๊ธฐ ์ „๊นŒ์ง€๋Š” ์•„๋ฌด๊ฒƒ๋„ ๊ทœ์น™์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ๋‹ซ๊ณ  G๋ฅผ ๋ˆŒ๋Ÿฌ ์Šน์ธํ•˜๊ณ  ์ €์žฅํ•˜์„ธ์š”. \
                     /constitution ๋˜๋Š” /setup์œผ๋กœ ์–ธ์ œ๋“ ์ง€ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
                }
            };
            format!(
                "CODEWHALE ยท ์‚ฌ์šฉ์ž ํ—Œ๋ฒ•\n{RULE}\n\n{drafted_by}\n\n\
                 ์ด๊ฒƒ์€ Codewhale์ด ๋‹น์‹ ๊ณผ ํ•จ๊ป˜ ์ผํ•˜๋Š” ๋ฐฉ์‹์— ๋Œ€ํ•œ ์ƒ์‹œ ๊ทœ์น™์ž…๋‹ˆ๋‹ค. ํ›Œ๋ฅญํ•œ ํ—Œ๋ฒ•์ด ๊ทธ๋ ‡๋“ฏ, \
                 ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๋งŒํผ ์งง๊ณ , ์†Œ๋ชจ์ ์ธ ๊ทœ์น™์ด ์•„๋‹Œ ์ง€์†์ ์ธ ์›์น™์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๋‹น์‹ ์ด ๋ณ€ํ™”ํ•จ์— ๋”ฐ๋ผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. \
                 ์ด๋Š” ๋ชจ๋“  ๊ฐœ๋ณ„ ์‚ฌ๋ก€๋ฅผ ํŒ๋‹จํ•˜๋Š” ๋Œ€์‹  ๊ถŒํ•œ๊ณผ ํ•œ๊ณ„๋ฅผ ๊ทœ์ •ํ•˜๋ฉฐ, ์„ธ์…˜์„ ๋„˜์–ด ํ˜‘์—…์˜ ์—ฐ์†์„ฑ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค. \
                 ๋‹ค๋งŒ ์ด๊ฒƒ์€ ๊ธฐ์–ต์ด ์•„๋‹™๋‹ˆ๋‹ค: ์ด๋ ฅ์ด ์•„๋‹ˆ๋ผ ์›์น™์„ ๋‹ด์Šต๋‹ˆ๋‹ค.\n\n\
                 {rendered}\n\n\
                 ๊ถŒํ•œ ๊ณ„์ธต\n{layer_order}\n๋‹น์‹ ์˜ ์ง์ ‘์ ์ธ ์š”์ฒญ์€ ์–ธ์ œ๋‚˜ ์ด ๋ฌธ์„œ๋ณด๋‹ค ์šฐ์„ ํ•ฉ๋‹ˆ๋‹ค.\n\n\
                 ์ด๊ฒƒ์ด ํ•  ์ˆ˜ ์—†๋Š” ์ผ\n\
                 ์ด๊ฒƒ์€ ํ–‰๋™์„ ์•ˆ๋‚ดํ•  ๋ฟ์ž…๋‹ˆ๋‹ค. ์Šน์ธ ์ •์ฑ…, ์ƒŒ๋“œ๋ฐ•์Šค, ์…ธ, ๋„คํŠธ์›Œํฌ, ์‹ ๋ขฐ, MCP ๊ถŒํ•œ, ๊ธฐ๋ณธ ๋ชจ๋“œ, ๊ฒŒ์‹œ, ์ง€์ถœ ๊ถŒํ•œ์„ \
                 ๋ถ€์—ฌํ•˜๊ฑฐ๋‚˜ ๋ฐ”๊ฟ€ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค; ์ด๋Š” ์—ฌ์ „ํžˆ ๋Ÿฐํƒ€์ž„์—์„œ ๋‹น์‹ ์ด ์ง์ ‘ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.\n\n\
                 ์ถ•์†Œ๋œ ์ฝ”์–ด์™€ ์˜ตํŠธ์ธ ๋ชจ๋“ˆ\n\
                 ๋‚ด์žฅ๋œ ์ฝ”์–ด๋Š” ๊ณ„์† ํ™œ์„ฑ ์ƒํƒœ์ž…๋‹ˆ๋‹ค. ์ด ์ดˆ์•ˆ์€ ์‚ฌ์šฉ์ž ์ „์—ญ์˜ ์ƒ์‹œ ์„ ํ˜ธ๋งŒ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. \
                 ์‹คํ–‰ ๋ฐ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ ๊ธฐ๋Šฅ์€ ๋Ÿฐํƒ€์ž„ ์ •์ฑ…, ํ˜„์žฌ ๋„๊ตฌ ์นดํƒˆ๋กœ๊ทธ ๋˜๋Š” ํ–ฅํ›„ ์˜ตํŠธ์ธ ๋ชจ๋“ˆ์—์„œ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์ด ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋Š” ๋ชจ๋“ˆ์„ ํ™œ์„ฑํ™”ํ•˜์ง€ ์•Š์œผ๋ฉฐ ๊ทธ ์„ค์ •๋„ ๋ฐ”๊พธ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.\n\n\
                 ์Šน์ธ\n{ratify_how}"
            )
        }
        Locale::Ca => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Redactat per {label} a partir de les teves respostes guiades, desprรฉs validat per esquema i acotat per Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Generat determinรญsticament a partir de les teves respostes guiades.".to_string()
                }
                DraftProvenance::Existing => {
                    "La teva constituciรณ existent, carregada de constitution.json, es mostra sense canvis."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "Aquesta ja รฉs la teva llei vigent. Tanca la previsualitzaciรณ i prem K per conservar-la i completar el punt de control; \
                     el fitxer no es modifica. Esmena-la en qualsevol moment amb /constitution o /setup."
                }
                _ => {
                    "Res no esdevรฉ llei fins que ho confirmis. Tanca la previsualitzaciรณ i prem G per ratificar i desar. \
                     Esmena-la en qualsevol moment amb /constitution o /setup."
                }
            };
            format!(
                "CODEWHALE ยท CONSTITUCIร“ DE L'USUARI\n{RULE}\n\n{drafted_by}\n\n\
                 Aquesta รฉs la llei permanent de com Codewhale treballa amb tu. Com les bones constitucions, \
                 รฉs prou curta per usar-se, feta de principis duradors en lloc de regles exhaustives, \
                 i esmenable a mesura que canvies. Defineix poders i lรญmits en lloc de decidir cada cas, \
                 i dona continuรฏtat a la colยทlaboraciรณ entre sessions โ€” perรฒ no รฉs memรฒria: porta principis, no histรฒria.\n\n\
                 {rendered}\n\n\
                 JERARQUIA D'AUTORITAT\n{layer_order}\nLes teves peticions directes sempre prevalen sobre aquest document.\n\n\
                 EL QUE AIXร’ NO POT FER\n\
                 Orienta el comportament. No pot concedir ni canviar la polรญtica d'aprovaciรณ, sandbox, shell, xarxa, \
                 confianรงa, permisos MCP, mode per defecte, publicaciรณ o autoritat de despesa; aixรฒ queda sota el teu control en temps d'execuciรณ.\n\n\
                 NUCLI REDUรT I Mร’DULS OPT-IN\n\
                 El nucli inclรฒs continua actiu. Aquest esborrany nomรฉs desa les teves preferรจncies permanents globals d'usuari. \
                 Les capacitats d'execuciรณ i orquestraciรณ provenen de la polรญtica d'execuciรณ, el catร leg d'eines actiu o futurs mรฒduls opt-in; aquesta previsualitzaciรณ no activa mรฒduls ni canvia la seva configuraciรณ.\n\n\
                 RATIFICACIร“\n{ratify_how}"
            )
        }
        Locale::De => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Entworfen von {label} aus deinen gefรผhrten Antworten, dann schema-geprรผft und begrenzt durch Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Deterministisch aus deinen gefรผhrten Antworten erzeugt.".to_string()
                }
                DraftProvenance::Existing => {
                    "Deine bestehende Verfassung, geladen aus constitution.json โ€” unverรคndert gezeigt."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "Dies ist bereits dein geltendes Recht. SchlieรŸe die Vorschau und drรผcke K, um sie zu behalten und den Checkpoint abzuschlieรŸen โ€” \
                     die Datei wird nicht verรคndert. Jederzeit mit /constitution oder /setup รคnderbar."
                }
                _ => {
                    "Nichts wird Recht, bevor du bestรคtigst. SchlieรŸe die Vorschau und drรผcke G, um zu ratifizieren und zu speichern. \
                     Jederzeit mit /constitution oder /setup รคnderbar."
                }
            };
            format!(
                "CODEWHALE ยท NUTZERVERFASSUNG\n{RULE}\n\n{drafted_by}\n\n\
                 Dies ist das geltende Gesetz dafรผr, wie Codewhale mit dir arbeitet. Wie die besten Verfassungen \
                 ist sie kurz genug, um genutzt zu werden, besteht aus dauerhaften Prinzipien statt erschรถpfender Regeln \
                 und lรคsst sich รคndern, wenn du dich รคnderst. Sie rahmt Befugnisse und Grenzen, statt jeden Einzelfall zu entscheiden, \
                 und gibt deiner Zusammenarbeit Kontinuitรคt รผber Sitzungen hinweg โ€” aber sie ist kein Gedรคchtnis: Sie trรคgt Prinzipien, nicht Geschichte.\n\n\
                 {rendered}\n\n\
                 HIERARCHIE DER AUTORITร„T\n{layer_order}\nDeine direkten Anweisungen stehen immer รผber diesem Dokument.\n\n\
                 WAS DIES NICHT KANN\n\
                 Sie leitet Verhalten. Sie kann keine Freigaberichtlinie, Sandbox, Shell, Netzwerk, \
                 Vertrauen, MCP-Berechtigungen, Standardmodus, Verรถffentlichung oder Ausgabenbefugnis gewรคhren oder รคndern โ€” die bleiben zur Laufzeit in deiner Hand.\n\n\
                 REDUZIERTER KERN UND OPT-IN-MODULE\n\
                 Der mitgelieferte Kern bleibt aktiv. Dieser Entwurf speichert nur deine benutzer-globalen Dauerprรคferenzen. \
                 Ausfรผhrungs- und Orchestrierungsfรคhigkeiten kommen aus der Laufzeitrichtlinie, dem aktuellen Werkzeugkatalog oder kรผnftigen Opt-in-Modulen; diese Vorschau aktiviert keine Module und รคndert nicht ihre Konfiguration.\n\n\
                 RATIFIZIERUNG\n{ratify_how}"
            )
        }
        Locale::Fr => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Rรฉdigรฉ par {label} ร  partir de vos rรฉponses guidรฉes, puis validรฉ par schรฉma et bornรฉ par Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Gรฉnรฉrรฉ de faรงon dรฉterministe ร  partir de vos rรฉponses guidรฉes.".to_string()
                }
                DraftProvenance::Existing => {
                    "Votre constitution existante, chargรฉe depuis constitution.json โ€” affichรฉe sans modification."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "C'est dรฉjร  votre loi permanente. Fermez cet aperรงu, puis appuyez sur K pour la conserver et terminer le point de contrรดle โ€” \
                     le fichier n'est pas modifiรฉ. Amendez-la ร  tout moment avec /constitution ou /setup."
                }
                _ => {
                    "Rien ne devient loi avant votre confirmation. Fermez cet aperรงu, puis appuyez sur G pour ratifier et enregistrer. \
                     Amendez-la ร  tout moment avec /constitution ou /setup."
                }
            };
            format!(
                "CODEWHALE ยท CONSTITUTION DE L'UTILISATEUR\n{RULE}\n\n{drafted_by}\n\n\
                 Voici la loi permanente qui rรฉgit la faรงon dont Codewhale travaille avec vous. Comme les meilleures constitutions, \
                 elle est assez courte pour รชtre utilisรฉe, faite de principes durables plutรดt que de rรจgles exhaustives, \
                 et amendable ร  mesure que vous changez. Elle encadre les pouvoirs et les limites plutรดt que de trancher chaque cas, \
                 et donne ร  votre collaboration une continuitรฉ entre les sessions โ€” mais elle n'est pas une mรฉmoire : elle porte des principes, pas un historique.\n\n\
                 {rendered}\n\n\
                 HIร‰RARCHIE D'AUTORITร‰\n{layer_order}\nVos demandes directes priment toujours sur ce document.\n\n\
                 CE QU'ELLE NE PEUT PAS FAIRE\n\
                 Elle guide le comportement. Elle ne peut ni accorder ni modifier la politique d'approbation, le sandbox, le shell, le rรฉseau, \
                 la confiance, les permissions MCP, le mode par dรฉfaut, la publication ou le pouvoir de dรฉpense โ€” ceux-ci restent entre vos mains ร  l'exรฉcution.\n\n\
                 NOYAU Rร‰DUIT ET MODULES OPT-IN\n\
                 Le noyau intรฉgrรฉ reste actif. Ce brouillon n'enregistre que vos prรฉfรฉrences permanentes globales. \
                 Les capacitรฉs d'exรฉcution et d'orchestration proviennent de la politique d'exรฉcution, du catalogue d'outils actif ou de futurs modules opt-in ; cet aperรงu n'active pas de modules et ne change pas leur configuration.\n\n\
                 RATIFICATION\n{ratify_how}"
            )
        }
        Locale::Id => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Disusun oleh {label} dari jawaban terpandu Anda, lalu diperiksa skemanya dan dibatasi oleh Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Dihasilkan secara deterministik dari jawaban terpandu Anda.".to_string()
                }
                DraftProvenance::Existing => {
                    "Konstitusi Anda yang ada, dimuat dari constitution.json โ€” ditampilkan tanpa perubahan."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "Ini sudah menjadi hukum tetap Anda. Tutup pratinjau ini, lalu tekan K untuk mempertahankannya dan menyelesaikan checkpoint โ€” \
                     file tidak diubah. Amendemen kapan saja dengan /constitution atau /setup."
                }
                _ => {
                    "Tidak ada yang menjadi hukum sampai Anda mengonfirmasi. Tutup pratinjau ini, lalu tekan G untuk meratifikasi dan menyimpan. \
                     Amendemen kapan saja dengan /constitution atau /setup."
                }
            };
            format!(
                "CODEWHALE ยท KONSTITUSI PENGGUNA\n{RULE}\n\n{drafted_by}\n\n\
                 Ini adalah hukum tetap tentang cara Codewhale bekerja dengan Anda. Seperti konstitusi terbaik, \
                 ia cukup singkat untuk dipakai, tersusun dari prinsip yang awet alih-alih aturan yang menyeluruh, \
                 dan dapat diamendemen seiring Anda berubah. Ia membingkai wewenang dan batasan alih-alih memutuskan setiap kasus, \
                 dan memberi kolaborasi Anda kesinambungan lintas sesi โ€” tetapi ia bukan memori: ia membawa prinsip, bukan riwayat.\n\n\
                 {rendered}\n\n\
                 HIERARKI OTORITAS\n{layer_order}\nPermintaan langsung Anda selalu mengungguli dokumen ini.\n\n\
                 APA YANG TIDAK BISA DILAKUKANNYA\n\
                 Ia memandu perilaku. Ia tidak dapat memberi atau mengubah kebijakan persetujuan, sandbox, shell, jaringan, \
                 kepercayaan, izin MCP, mode default, publikasi, atau wewenang belanja โ€” semua itu tetap di tangan Anda saat runtime.\n\n\
                 INTI RINGKAS DAN MODUL OPT-IN\n\
                 Inti bawaan tetap aktif. Draf ini hanya menyimpan preferensi tetap global pengguna Anda. \
                 Kemampuan eksekusi dan orkestrasi berasal dari kebijakan runtime, katalog alat aktif, atau modul opt-in mendatang; pratinjau ini tidak mengaktifkan modul atau mengubah konfigurasinya.\n\n\
                 RATIFIKASI\n{ratify_how}"
            )
        }
        Locale::Hi => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "{label} เคฆเฅเคตเคพเคฐเคพ เค†เคชเค•เฅ‡ เค—เคพเค‡เคกเฅ‡เคก เค‰เคคเฅเคคเคฐเฅ‹เค‚ เคธเฅ‡ เคคเฅˆเคฏเคพเคฐ, เคซเคฟเคฐ Codewhale เคฆเฅเคตเคพเคฐเคพ เคธเฅเค•เฅ€เคฎเคพ-เคœเคพเคเคšเคพ เค”เคฐ เคธเฅ€เคฎเคฟเคค เค•เคฟเคฏเคพ เค—เคฏเคพเฅค"
                ),
                DraftProvenance::Guided => "เค†เคชเค•เฅ‡ เค—เคพเค‡เคกเฅ‡เคก เค‰เคคเฅเคคเคฐเฅ‹เค‚ เคธเฅ‡ เคจเคฟเคฏเคค เคฐเฅ‚เคช เคธเฅ‡ เคคเฅˆเคฏเคพเคฐ เค•เคฟเคฏเคพ เค—เคฏเคพเฅค".to_string(),
                DraftProvenance::Existing => {
                    "เค†เคชเค•เคพ เคฎเฅŒเคœเฅ‚เคฆเคพ เคธเค‚เคตเคฟเคงเคพเคจ, constitution.json เคธเฅ‡ เคฒเฅ‹เคก เค•เคฟเคฏเคพ เค—เคฏเคพ โ€” เค…เคชเคฐเคฟเคตเคฐเฅเคคเคฟเคค เคฆเคฟเค–เคพเคฏเคพ เค—เคฏเคพเฅค"
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "เคฏเคน เคชเคนเคฒเฅ‡ เคธเฅ‡ เคนเฅ€ เค†เคชเค•เคพ เคธเฅเคฅเคพเคฏเฅ€ เค•เคพเคจเฅ‚เคจ เคนเฅˆเฅค เคฏเคน เคชเฅ‚เคฐเฅเคตเคพเคตเคฒเฅ‹เค•เคจ เคฌเค‚เคฆ เค•เคฐเฅ‡เค‚, เคซเคฟเคฐ เค‡เคธเฅ‡ เคฌเคจเคพเค เคฐเค–เคจเฅ‡ เค”เคฐ เคšเฅ‡เค•เคชเฅ‰เค‡เค‚เคŸ เคชเฅ‚เคฐเคพ เค•เคฐเคจเฅ‡ เค•เฅ‡ เคฒเคฟเค K เคฆเคฌเคพเคเค โ€” \
                     เคซเคผเคพเค‡เคฒ เคธเค‚เคถเฅ‹เคงเคฟเคค เคจเคนเฅ€เค‚ เคนเฅ‹เคคเฅ€เฅค /constitution เคฏเคพ /setup เคธเฅ‡ เค•เคญเฅ€ เคญเฅ€ เคธเค‚เคถเฅ‹เคงเคฟเคค เค•เคฐเฅ‡เค‚เฅค"
                }
                _ => {
                    "เคœเคฌ เคคเค• เค†เคช เคชเฅเคทเฅเคŸเคฟ เคจเคนเฅ€เค‚ เค•เคฐเคคเฅ‡, เค•เฅเค› เคญเฅ€ เค•เคพเคจเฅ‚เคจ เคจเคนเฅ€เค‚ เคฌเคจเคคเคพเฅค เคฏเคน เคชเฅ‚เคฐเฅเคตเคพเคตเคฒเฅ‹เค•เคจ เคฌเค‚เคฆ เค•เคฐเฅ‡เค‚, เคซเคฟเคฐ เค…เค‚เค—เฅ€เค•เคพเคฐ เค”เคฐ เคธเคนเฅ‡เคœเคจเฅ‡ เค•เฅ‡ เคฒเคฟเค G เคฆเคฌเคพเคเคเฅค \
                     /constitution เคฏเคพ /setup เคธเฅ‡ เค•เคญเฅ€ เคญเฅ€ เคธเค‚เคถเฅ‹เคงเคฟเคค เค•เคฐเฅ‡เค‚เฅค"
                }
            };
            format!(
                "CODEWHALE ยท เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ เคธเค‚เคตเคฟเคงเคพเคจ\n{RULE}\n\n{drafted_by}\n\n\
                 เคฏเคน Codewhale เค†เคชเค•เฅ‡ เคธเคพเคฅ เค•เฅˆเคธเฅ‡ เค•เคพเคฎ เค•เคฐเฅ‡, เค‡เคธเค•เคพ เคธเฅเคฅเคพเคฏเฅ€ เค•เคพเคจเฅ‚เคจ เคนเฅˆเฅค เคธเคฐเฅเคตเฅ‹เคคเฅเคคเคฎ เคธเค‚เคตเคฟเคงเคพเคจเฅ‹เค‚ เค•เฅ€ เคคเคฐเคน, \
                 เคฏเคน เค‰เคชเคฏเฅ‹เค— เค•เฅ‡ เคฒเคฟเค เคชเคฐเฅเคฏเคพเคชเฅเคค เค›เฅ‹เคŸเคพ เคนเฅˆ, เคธเค‚เคชเฅ‚เคฐเฅเคฃ เคจเคฟเคฏเคฎเฅ‹เค‚ เค•เฅ‡ เคฌเคœเคพเคฏ เคŸเคฟเค•เคพเคŠ เคธเคฟเคฆเฅเคงเคพเค‚เคคเฅ‹เค‚ เคธเฅ‡ เคฌเคจเคพ เคนเฅˆ, \
                 เค”เคฐ เค†เคชเค•เฅ‡ เคฌเคฆเคฒเคจเฅ‡ เค•เฅ‡ เคธเคพเคฅ เคธเค‚เคถเฅ‹เคงเคจเฅ€เคฏ เคนเฅˆเฅค เคฏเคน เคนเคฐ เคฎเคพเคฎเคฒเฅ‡ เค•เคพ เคซเคผเฅˆเคธเคฒเคพ เค•เคฐเคจเฅ‡ เค•เฅ‡ เคฌเคœเคพเคฏ เคถเค•เฅเคคเคฟเคฏเฅ‹เค‚ เค”เคฐ เคธเฅ€เคฎเคพเค“เค‚ เค•เคพ เคขเคพเคเคšเคพ เคฆเฅ‡เคคเคพ เคนเฅˆ, \
                 เค”เคฐ เค†เคชเค•เฅ‡ เคธเคนเคฏเฅ‹เค— เค•เฅ‹ เคธเคคเฅเคฐเฅ‹เค‚ เค•เฅ‡ เคชเคพเคฐ เคจเคฟเคฐเค‚เคคเคฐเคคเคพ เคฆเฅ‡เคคเคพ เคนเฅˆ โ€” เคฒเฅ‡เค•เคฟเคจ เคฏเคน เคฎเฅ‡เคฎเฅ‹เคฐเฅ€ เคจเคนเฅ€เค‚ เคนเฅˆ: เคฏเคน เค‡เคคเคฟเคนเคพเคธ เคจเคนเฅ€เค‚, เคธเคฟเคฆเฅเคงเคพเค‚เคค เคฐเค–เคคเคพ เคนเฅˆเฅค\n\n\
                 {rendered}\n\n\
                 เค…เคงเคฟเค•เคพเคฐ เคชเคฆเคพเคจเฅเค•เฅเคฐเคฎ\n{layer_order}\nเค†เคชเค•เฅ‡ เคชเฅเคฐเคคเฅเคฏเค•เฅเคท เค…เคจเฅเคฐเฅ‹เคง เคนเคฎเฅ‡เคถเคพ เค‡เคธ เคฆเคธเฅเคคเคพเคตเฅ‡เคœเคผ เคธเฅ‡ เคŠเคชเคฐ เคนเฅˆเค‚เฅค\n\n\
                 เคฏเคน เค•เฅเคฏเคพ เคจเคนเฅ€เค‚ เค•เคฐ เคธเค•เคคเคพ\n\
                 เคฏเคน เคตเฅเคฏเคตเคนเคพเคฐ เค•เคพ เคฎเคพเคฐเฅเค—เคฆเคฐเฅเคถเคจ เค•เคฐเคคเคพ เคนเฅˆเฅค เคฏเคน เค…เคจเฅเคฎเคคเคฟ เคจเฅ€เคคเคฟ, เคธเฅˆเค‚เคกเคฌเฅ‰เค•เฅเคธ, เคถเฅ‡เคฒ, เคจเฅ‡เคŸเคตเคฐเฅเค•, \
                 เคŸเฅเคฐเคธเฅเคŸ, MCP เค…เคจเฅเคฎเคคเคฟเคฏเคพเค, เคกเคฟเคซเคผเฅ‰เคฒเฅเคŸ เคฎเฅ‹เคก, เคชเฅเคฐเค•เคพเคถเคจ เคฏเคพ เค–เคฐเฅเคš เค•เคพ เค…เคงเคฟเค•เคพเคฐ เคชเฅเคฐเคฆเคพเคจ เคฏเคพ เคชเคฐเคฟเคตเคฐเฅเคคเคฟเคค เคจเคนเฅ€เค‚ เค•เคฐ เคธเค•เคคเคพ โ€” เคตเฅ‡ เคฐเคจเคŸเคพเค‡เคฎ เคชเคฐ เค†เคชเค•เฅ‡ เคนเคพเคฅ เคฎเฅ‡เค‚ เคฐเคนเคคเฅ‡ เคนเฅˆเค‚เฅค\n\n\
                 เคธเค‚เค•เฅเคทเคฟเคชเฅเคค เค•เฅ‹เคฐ เค”เคฐ เค‘เคชเฅเคŸ-เค‡เคจ เคฎเฅ‰เคกเฅเคฏเฅ‚เคฒ\n\
                 Bundled เค•เฅ‹เคฐ เคธเค•เฅเคฐเคฟเคฏ เคฐเคนเคคเคพ เคนเฅˆเฅค เคฏเคน เคฎเคธเฅŒเคฆเคพ เค•เฅ‡เคตเคฒ เค†เคชเค•เฅ€ เค‰เคชเคฏเฅ‹เค—เค•เคฐเฅเคคเคพ-เคตเฅˆเคถเฅเคตเคฟเค• เคธเฅเคฅเคพเคฏเฅ€ เคชเฅเคฐเคพเคฅเคฎเคฟเค•เคคเคพเคเค เคธเคนเฅ‡เคœเคคเคพ เคนเฅˆเฅค \
                 เคญเคพเคฐเฅ€ เคจเคฟเคทเฅเคชเคพเคฆเคจ เคฏเคพ เค‘เคฐเฅเค•เฅ‡เคธเฅเคŸเฅเคฐเฅ‡เคถเคจ เคธเคฟเคฆเฅเคงเคพเค‚เคค เคฎเฅ‹เคก เคชเฅเคฐเฅ‰เคฎเฅเคชเฅเคŸ เคฏเคพ เคญเคตเคฟเคทเฅเคฏ เค•เฅ‡ เค‘เคชเฅเคŸ-เค‡เคจ เคฎเฅ‰เคกเฅเคฏเฅ‚เคฒ เคฎเฅ‡เค‚ เคฐเคนเคคเฅ‡ เคนเฅˆเค‚; เคฏเคน เคชเฅ‚เคฐเฅเคตเคพเคตเคฒเฅ‹เค•เคจ เคฎเฅ‰เคกเฅเคฏเฅ‚เคฒ เคธเค•เฅเคทเคฎ เคจเคนเฅ€เค‚ เค•เคฐเคคเคพ เค”เคฐ เคจ เคนเฅ€ เค‰เคจเค•เฅ€ เค•เฅ‰เคจเฅเคซเคผเคฟเค—เคฐเฅ‡เคถเคจ เคฌเคฆเคฒเคคเคพ เคนเฅˆเฅค\n\n\
                 เค…เค‚เค—เฅ€เค•เคพเคฐ\n{ratify_how}"
            )
        }
        Locale::Ru => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "ะŸะพะดะณะพั‚ะพะฒะปะตะฝะพ {label} ะฝะฐ ะพัะฝะพะฒะต ะฒะฐัˆะธั… ะพั‚ะฒะตั‚ะพะฒ ะฝะฐ ะฝะฐะฒะพะดัั‰ะธะต ะฒะพะฟั€ะพัั‹, ะทะฐั‚ะตะผ ะฟั€ะพะฒะตั€ะตะฝะพ ะฟะพ ัั…ะตะผะต ะธ ะพะณั€ะฐะฝะธั‡ะตะฝะพ Codewhale."
                ),
                DraftProvenance::Guided => {
                    "ะ”ะตั‚ะตั€ะผะธะฝะธั€ะพะฒะฐะฝะฝะพ ะฟะพัั‚ั€ะพะตะฝะพ ะธะท ะฒะฐัˆะธั… ะพั‚ะฒะตั‚ะพะฒ ะฝะฐ ะฝะฐะฒะพะดัั‰ะธะต ะฒะพะฟั€ะพัั‹.".to_string()
                }
                DraftProvenance::Existing => {
                    "ะ’ะฐัˆะฐ ััƒั‰ะตัั‚ะฒัƒัŽั‰ะฐั ะบะพะฝัั‚ะธั‚ัƒั†ะธั, ะทะฐะณั€ัƒะถะตะฝะฝะฐั ะธะท constitution.json, โ€” ะฟะพะบะฐะทะฐะฝะฐ ะฑะตะท ะธะทะผะตะฝะตะฝะธะน."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "ะญั‚ะพ ัƒะถะต ะฒะฐัˆ ะดะตะนัั‚ะฒัƒัŽั‰ะธะน ะทะฐะบะพะฝ. ะ—ะฐะบั€ะพะนั‚ะต ัั‚ะพ ะฟั€ะตะฒัŒัŽ, ะทะฐั‚ะตะผ ะฝะฐะถะผะธั‚ะต K, ั‡ั‚ะพะฑั‹ ัะพั…ั€ะฐะฝะธั‚ัŒ ะตั‘ ะธ ะทะฐะฒะตั€ัˆะธั‚ัŒ ะบะพะฝั‚ั€ะพะปัŒะฝัƒัŽ ั‚ะพั‡ะบัƒ โ€” \
                     ั„ะฐะนะป ะฝะต ะธะทะผะตะฝัะตั‚ัั. ะ˜ะทะผะตะฝะธั‚ัŒ ะผะพะถะฝะพ ะฒ ะปัŽะฑะพะต ะฒั€ะตะผั ั‡ะตั€ะตะท /constitution ะธะปะธ /setup."
                }
                _ => {
                    "ะะธั‡ั‚ะพ ะฝะต ัั‚ะฐะฝะพะฒะธั‚ัั ะทะฐะบะพะฝะพะผ, ะฟะพะบะฐ ะฒั‹ ะฝะต ะฟะพะดั‚ะฒะตั€ะดะธั‚ะต. ะ—ะฐะบั€ะพะนั‚ะต ัั‚ะพ ะฟั€ะตะฒัŒัŽ, ะทะฐั‚ะตะผ ะฝะฐะถะผะธั‚ะต G, ั‡ั‚ะพะฑั‹ ั€ะฐั‚ะธั„ะธั†ะธั€ะพะฒะฐั‚ัŒ ะธ ัะพั…ั€ะฐะฝะธั‚ัŒ. \
                     ะ˜ะทะผะตะฝะธั‚ัŒ ะผะพะถะฝะพ ะฒ ะปัŽะฑะพะต ะฒั€ะตะผั ั‡ะตั€ะตะท /constitution ะธะปะธ /setup."
                }
            };
            format!(
                "CODEWHALE ยท ะšะžะะกะขะ˜ะขะฃะฆะ˜ะฏ ะŸะžะ›ะฌะ—ะžะ’ะะขะ•ะ›ะฏ\n{RULE}\n\n{drafted_by}\n\n\
                 ะญั‚ะพ ะฟะพัั‚ะพัะฝะฝั‹ะน ะทะฐะบะพะฝ ะพ ั‚ะพะผ, ะบะฐะบ Codewhale ั€ะฐะฑะพั‚ะฐะตั‚ ั ะฒะฐะผะธ. ะšะฐะบ ะปัƒั‡ัˆะธะต ะบะพะฝัั‚ะธั‚ัƒั†ะธะธ, \
                 ะพะฝะฐ ะดะพัั‚ะฐั‚ะพั‡ะฝะพ ะบะพั€ะพั‚ะบะฐ, ั‡ั‚ะพะฑั‹ ะตะน ะฟะพะปัŒะทะพะฒะฐั‚ัŒัั, ัะพัั‚ะพะธั‚ ะธะท ะดะพะปะณะพะฒะตั‡ะฝั‹ั… ะฟั€ะธะฝั†ะธะฟะพะฒ, ะฐ ะฝะต ะธัั‡ะตั€ะฟั‹ะฒะฐัŽั‰ะธั… ะฟั€ะฐะฒะธะป, \
                 ะธ ะผะพะถะตั‚ ะธะทะผะตะฝัั‚ัŒัั ะฒะผะตัั‚ะต ั ะฒะฐะผะธ. ะžะฝะฐ ะพั‡ะตั€ั‡ะธะฒะฐะตั‚ ะฟะพะปะฝะพะผะพั‡ะธั ะธ ะณั€ะฐะฝะธั†ั‹, ะฐ ะฝะต ั€ะตัˆะฐะตั‚ ะบะฐะถะดั‹ะน ัะปัƒั‡ะฐะน, \
                 ะธ ะฟั€ะธะดะฐั‘ั‚ ะฒะฐัˆะตะผัƒ ัะพั‚ั€ัƒะดะฝะธั‡ะตัั‚ะฒัƒ ะฝะตะฟั€ะตั€ั‹ะฒะฝะพัั‚ัŒ ะผะตะถะดัƒ ัะตััะธัะผะธ โ€” ะฝะพ ะพะฝะฐ ะฝะต ะฟะฐะผัั‚ัŒ: ะพะฝะฐ ั…ั€ะฐะฝะธั‚ ะฟั€ะธะฝั†ะธะฟั‹, ะฐ ะฝะต ะธัั‚ะพั€ะธัŽ.\n\n\
                 {rendered}\n\n\
                 ะ˜ะ•ะ ะะ ะฅะ˜ะฏ ะŸะžะ›ะะžะœะžะงะ˜ะ™\n{layer_order}\nะ’ะฐัˆะธ ะฟั€ัะผั‹ะต ัƒะบะฐะทะฐะฝะธั ะฒัะตะณะดะฐ ะฒะฐะถะฝะตะต ัั‚ะพะณะพ ะดะพะบัƒะผะตะฝั‚ะฐ.\n\n\
                 ะงะ•ะ“ะž ะžะะ ะะ• ะœะžะ–ะ•ะข\n\
                 ะžะฝะฐ ะฝะฐะฟั€ะฐะฒะปัะตั‚ ะฟะพะฒะตะดะตะฝะธะต. ะžะฝะฐ ะฝะต ะผะพะถะตั‚ ะฟั€ะตะดะพัั‚ะฐะฒะธั‚ัŒ ะธะปะธ ะธะทะผะตะฝะธั‚ัŒ ะฟะพะปะธั‚ะธะบัƒ ะพะดะพะฑั€ะตะฝะธั, sandbox, shell, ัะตั‚ัŒ, \
                 ะดะพะฒะตั€ะธะต, ั€ะฐะทั€ะตัˆะตะฝะธั MCP, ั€ะตะถะธะผ ะฟะพ ัƒะผะพะปั‡ะฐะฝะธัŽ, ะฟัƒะฑะปะธะบะฐั†ะธัŽ ะธะปะธ ะฟั€ะฐะฒะพ ั‚ั€ะฐั‚ะธั‚ัŒ โ€” ะพะฝะธ ะพัั‚ะฐัŽั‚ัั ะฒ ะฒะฐัˆะธั… ั€ัƒะบะฐั… ะฒะพ ะฒั€ะตะผั ะฒั‹ะฟะพะปะฝะตะฝะธั.\n\n\
                 ะกะžะšะ ะะฉะะะะžะ• ะฏะ”ะ ะž ะ˜ ะžะŸะฆะ˜ะžะะะ›ะฌะะซะ• ะœะžะ”ะฃะ›ะ˜\n\
                 ะ’ัั‚ั€ะพะตะฝะฝะพะต ัะดั€ะพ ะพัั‚ะฐั‘ั‚ัั ะฐะบั‚ะธะฒะฝั‹ะผ. ะญั‚ะพั‚ ะฟั€ะพะตะบั‚ ัะพั…ั€ะฐะฝัะตั‚ ั‚ะพะปัŒะบะพ ะฒะฐัˆะธ ะณะปะพะฑะฐะปัŒะฝั‹ะต ะฟะพัั‚ะพัะฝะฝั‹ะต ะฟั€ะตะดะฟะพั‡ั‚ะตะฝะธั. \
                 ะขัะถั‘ะปะฐั ะดะพะบั‚ั€ะธะฝะฐ ะธัะฟะพะปะฝะตะฝะธั ะธะปะธ ะพั€ะบะตัั‚ั€ะฐั†ะธะธ ะฟั€ะธะฝะฐะดะปะตะถะธั‚ ะฟั€ะพะผะฟั‚ะฐะผ ั€ะตะถะธะผะพะฒ ะธะปะธ ะฑัƒะดัƒั‰ะธะผ ะพะฟั†ะธะพะฝะฐะปัŒะฝั‹ะผ ะผะพะดัƒะปัะผ; ัั‚ะพ ะฟั€ะตะฒัŒัŽ ะฝะต ะฒะบะปัŽั‡ะฐะตั‚ ะผะพะดัƒะปะธ ะธ ะฝะต ะผะตะฝัะตั‚ ะธั… ะบะพะฝั„ะธะณัƒั€ะฐั†ะธัŽ.\n\n\
                 ะ ะะขะ˜ะคะ˜ะšะะฆะ˜ะฏ\n{ratify_how}"
            )
        }
        Locale::Uk => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "ะŸั–ะดะณะพั‚ะพะฒะปะตะฝะพ {label} ะฝะฐ ะพัะฝะพะฒั– ะฒะฐัˆะธั… ะฒั–ะดะฟะพะฒั–ะดะตะน ะฝะฐ ะฝะฐะฒั–ะดะฝั– ะทะฐะฟะธั‚ะฐะฝะฝั, ะฟะพั‚ั–ะผ ะฟะตั€ะตะฒั–ั€ะตะฝะพ ะทะฐ ัั…ะตะผะพัŽ ั‚ะฐ ะพะฑะผะตะถะตะฝะพ Codewhale."
                ),
                DraftProvenance::Guided => {
                    "ะ”ะตั‚ะตั€ะผั–ะฝะพะฒะฐะฝะพ ะฟะพะฑัƒะดะพะฒะฐะฝะพ ะท ะฒะฐัˆะธั… ะฒั–ะดะฟะพะฒั–ะดะตะน ะฝะฐ ะฝะฐะฒั–ะดะฝั– ะทะฐะฟะธั‚ะฐะฝะฝั.".to_string()
                }
                DraftProvenance::Existing => {
                    "ะ’ะฐัˆะฐ ั‡ะธะฝะฝะฐ ะบะพะฝัั‚ะธั‚ัƒั†ั–ั, ะทะฐะฒะฐะฝั‚ะฐะถะตะฝะฐ ะท constitution.json, โ€” ะฟะพะบะฐะทะฐะฝะฐ ะฑะตะท ะทะผั–ะฝ."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "ะฆะต ะฒะถะต ะฒะฐัˆ ั‡ะธะฝะฝะธะน ะทะฐะบะพะฝ. ะ—ะฐะบั€ะธะนั‚ะต ั†ะต ะฟั€ะตะฒ'ัŽ, ะฟะพั‚ั–ะผ ะฝะฐั‚ะธัะฝั–ั‚ัŒ K, ั‰ะพะฑ ะทะฑะตั€ะตะณั‚ะธ ั—ั— ั‚ะฐ ะทะฐะฒะตั€ัˆะธั‚ะธ ะบะพะฝั‚ั€ะพะปัŒะฝัƒ ั‚ะพั‡ะบัƒ โ€” \
                     ั„ะฐะนะป ะฝะต ะทะผั–ะฝัŽั”ั‚ัŒัั. ะ—ะผั–ะฝะธั‚ะธ ะผะพะถะฝะฐ ะฑัƒะดัŒ-ะบะพะปะธ ั‡ะตั€ะตะท /constitution ะฐะฑะพ /setup."
                }
                _ => {
                    "ะั–ั‰ะพ ะฝะต ัั‚ะฐั” ะทะฐะบะพะฝะพะผ, ะดะพะบะธ ะฒะธ ะฝะต ะฟั–ะดั‚ะฒะตั€ะดะธั‚ะต. ะ—ะฐะบั€ะธะนั‚ะต ั†ะต ะฟั€ะตะฒ'ัŽ, ะฟะพั‚ั–ะผ ะฝะฐั‚ะธัะฝั–ั‚ัŒ G, ั‰ะพะฑ ั€ะฐั‚ะธั„ั–ะบัƒะฒะฐั‚ะธ ั‚ะฐ ะทะฑะตั€ะตะณั‚ะธ. \
                     ะ—ะผั–ะฝะธั‚ะธ ะผะพะถะฝะฐ ะฑัƒะดัŒ-ะบะพะปะธ ั‡ะตั€ะตะท /constitution ะฐะฑะพ /setup."
                }
            };
            format!(
                "CODEWHALE ยท ะšะžะะกะขะ˜ะขะฃะฆะ†ะฏ ะšะžะ ะ˜ะกะขะฃะ’ะะงะ\n{RULE}\n\n{drafted_by}\n\n\
                 ะฆะต ะฟะพัั‚ั–ะนะฝะธะน ะทะฐะบะพะฝ ะฟั€ะพ ั‚ะต, ัะบ Codewhale ะฟั€ะฐั†ัŽั” ะท ะฒะฐะผะธ. ะฏะบ ะฝะฐะนะบั€ะฐั‰ั– ะบะพะฝัั‚ะธั‚ัƒั†ั–ั—, \
                 ะฒะพะฝะฐ ะดะพัั‚ะฐั‚ะฝัŒะพ ะบะพั€ะพั‚ะบะฐ, ั‰ะพะฑ ะฝะตัŽ ะบะพั€ะธัั‚ัƒะฒะฐั‚ะธัั, ัะบะปะฐะดะฐั”ั‚ัŒัั ะท ะดะพะฒะณะพะฒั–ั‡ะฝะธั… ะฟั€ะธะฝั†ะธะฟั–ะฒ, ะฐ ะฝะต ะฒะธั‡ะตั€ะฟะฝะธั… ะฟั€ะฐะฒะธะป, \
                 ั– ะผะพะถะต ะทะผั–ะฝัŽะฒะฐั‚ะธัั ั€ะฐะทะพะผ ั–ะท ะฒะฐะผะธ. ะ’ะพะฝะฐ ะพะบั€ะตัะปัŽั” ะฟะพะฒะฝะพะฒะฐะถะตะฝะฝั ั‚ะฐ ะผะตะถั–, ะฐ ะฝะต ะฒะธั€ั–ัˆัƒั” ะบะพะถะตะฝ ะฒะธะฟะฐะดะพะบ, \
                 ั– ะฝะฐะดะฐั” ะฒะฐัˆั–ะน ัะฟั–ะฒะฟั€ะฐั†ั– ะฝะตะฟะตั€ะตั€ะฒะฝั–ัั‚ัŒ ะผั–ะถ ัะตัั–ัะผะธ โ€” ะฐะปะต ะฒะพะฝะฐ ะฝะต ะฟะฐะผ'ัั‚ัŒ: ะฒะพะฝะฐ ะทะฑะตั€ั–ะณะฐั” ะฟั€ะธะฝั†ะธะฟะธ, ะฐ ะฝะต ั–ัั‚ะพั€ั–ัŽ.\n\n\
                 {rendered}\n\n\
                 ะ†ะ„ะ ะะ ะฅะ†ะฏ ะŸะžะ’ะะžะ’ะะ–ะ•ะะฌ\n{layer_order}\nะ’ะฐัˆั– ะฟั€ัะผั– ะฒะบะฐะทั–ะฒะบะธ ะทะฐะฒะถะดะธ ะฒะฐะถะปะธะฒั–ัˆั– ะทะฐ ั†ะตะน ะดะพะบัƒะผะตะฝั‚.\n\n\
                 ะงะžะ“ะž ะ’ะžะะ ะะ• ะœะžะ–ะ•\n\
                 ะ’ะพะฝะฐ ัะฟั€ัะผะพะฒัƒั” ะฟะพะฒะตะดั–ะฝะบัƒ. ะ’ะพะฝะฐ ะฝะต ะผะพะถะต ะฝะฐะดะฐั‚ะธ ะฐะฑะพ ะทะผั–ะฝะธั‚ะธ ะฟะพะปั–ั‚ะธะบัƒ ัั…ะฒะฐะปะตะฝะฝั, sandbox, shell, ะผะตั€ะตะถัƒ, \
                 ะดะพะฒั–ั€ัƒ, ะดะพะทะฒะพะปะธ MCP, ั€ะตะถะธะผ ะทะฐ ะทะฐะผะพะฒั‡ัƒะฒะฐะฝะฝัะผ, ะฟัƒะฑะปั–ะบะฐั†ั–ัŽ ั‡ะธ ะฟั€ะฐะฒะพ ะฒะธั‚ั€ะฐั‡ะฐั‚ะธ โ€” ะฒะพะฝะธ ะทะฐะปะธัˆะฐัŽั‚ัŒัั ัƒ ะฒะฐัˆะธั… ั€ัƒะบะฐั… ะฟั–ะด ั‡ะฐั ะฒะธะบะพะฝะฐะฝะฝั.\n\n\
                 ะกะšะžะ ะžะงะ•ะะ• ะฏะ”ะ ะž ะ™ ะžะŸะฆะ†ะ™ะะ† ะœะžะ”ะฃะ›ะ†\n\
                 ะ’ะฑัƒะดะพะฒะฐะฝะต ัะดั€ะพ ะทะฐะปะธัˆะฐั”ั‚ัŒัั ะฐะบั‚ะธะฒะฝะธะผ. ะฆะตะน ะฟั€ะพั”ะบั‚ ะทะฑะตั€ั–ะณะฐั” ะปะธัˆะต ะฒะฐัˆั– ะณะปะพะฑะฐะปัŒะฝั– ะฟะพัั‚ั–ะนะฝั– ะฒะฟะพะดะพะฑะฐะฝะฝั. \
                 ะ’ะฐะถะบะฐ ะดะพะบั‚ั€ะธะฝะฐ ะฒะธะบะพะฝะฐะฝะฝั ั‡ะธ ะพั€ะบะตัั‚ั€ะฐั†ั–ั— ะฝะฐะปะตะถะธั‚ัŒ ะฟั€ะพะผะฟั‚ะฐะผ ั€ะตะถะธะผั–ะฒ ะฐะฑะพ ะผะฐะนะฑัƒั‚ะฝั–ะผ ะพะฟั†ั–ะนะฝะธะผ ะผะพะดัƒะปัะผ; ั†ะต ะฟั€ะตะฒ'ัŽ ะฝะต ะฒะผะธะบะฐั” ะผะพะดัƒะปั– ะน ะฝะต ะทะผั–ะฝัŽั” ั—ั…ะฝัŽ ะบะพะฝั„ั–ะณัƒั€ะฐั†ั–ัŽ.\n\n\
                 ะ ะะขะ˜ะคะ†ะšะะฆะ†ะฏ\n{ratify_how}"
            )
        }
        _ => {
            let drafted_by = match provenance {
                DraftProvenance::Model(label) => format!(
                    "Drafted by {label} from your guided answers, then schema-checked and bounded by Codewhale."
                ),
                DraftProvenance::Guided => {
                    "Rendered deterministically from your guided answers.".to_string()
                }
                DraftProvenance::Existing => {
                    "Your existing constitution, loaded from constitution.json โ€” shown unchanged."
                        .to_string()
                }
            };
            let ratify_how = match provenance {
                DraftProvenance::Existing => {
                    "This is already your standing law. Close this preview, then press K to \
                     keep it and complete the checkpoint โ€” the file is not modified. Amend \
                     anytime with /constitution or /setup."
                }
                _ => {
                    "Nothing becomes law until you confirm. Close this preview, then press G to \
                     ratify and save. Amend anytime with /constitution or /setup."
                }
            };
            format!(
                "CODEWHALE ยท USER CONSTITUTION\n{RULE}\n\n{drafted_by}\n\n\
                 This is the standing law for how Codewhale works with you. Like the best \
                 constitutions, it is short enough to use, made of durable principles rather \
                 than exhaustive rules, and amendable as you change. It frames powers and \
                 limits rather than deciding every case, and it gives your collaboration \
                 continuity across sessions โ€” but it is not memory: it carries principles, \
                 not history.\n\n\
                 {rendered}\n\n\
                 HIERARCHY OF AUTHORITY\n{layer_order}\nYour direct requests always outrank this document.\n\n\
                 WHAT THIS CANNOT DO\n\
                 It guides behavior. It cannot grant or change approval policy, sandbox, shell, \
                 network, trust, MCP permissions, default mode, publishing, or spending \
                 authority โ€” those stay under your hand at runtime.\n\n\
                 REDUCED CORE AND OPT-IN MODULES\n\
                 The bundled core stays active. This draft only saves your user-global \
                 standing preferences. Execution and orchestration capabilities come from runtime \
                 policy, the live tool catalog, or future opt-in modules; this preview does not enable modules or change \
                 their configuration.\n\n\
                 RATIFICATION\n{ratify_how}"
            )
        }
    }
}

/// Card line inviting the user to let their configured model draft the law.
fn model_draft_invitation_line(locale: Locale, model_label: &str) -> String {
    match locale {
        Locale::Ja => {
            format!("A {model_label} ใŒ่ตท่‰ใ—ใ€ใ‚ใชใŸใŒๆ‰นๅ‡†ใ—ใพใ™ใ€‚็ขบ่ชใ™ใ‚‹ใพใงไฟๅญ˜ใ—ใพใ›ใ‚“ใ€‚")
        }
        Locale::ZhHans => {
            format!("A {model_label} ็”Ÿๆˆ่‰ๆกˆ๏ผŒ็”ฑไฝ ็กฎ่ฎคใ€‚ๆœช็ป็กฎ่ฎคไธไผšไฟๅญ˜ใ€‚")
        }
        Locale::ZhHant => {
            format!("A {model_label} ่ตท่‰๏ผŒไฝ ๆ‰นๅ‡†ใ€‚ๆœช็ถ“็ขบ่ชไธๆœƒไฟๅญ˜ใ€‚")
        }
        Locale::PtBr => {
            format!("A {model_label} pode rascunhar. Vocรช ratifica. Nada salva sem vocรช.")
        }
        Locale::Es419 => {
            format!("A {model_label} puede redactarla. Tรบ ratificas. Nada se guarda sin ti.")
        }
        Locale::Vi => {
            format!("A {model_label} cรณ thแปƒ soแบกn. Bแบกn phรช chuแบฉn. Khรดng lฦฐu gรฌ nแบฟu chฦฐa cรณ bแบกn.")
        }
        Locale::Ko => {
            format!(
                "A {model_label}์ด(๊ฐ€) ์ดˆ์•ˆ์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šน์ธ์€ ๋‹น์‹ ์ด ํ•ฉ๋‹ˆ๋‹ค. ๋‹น์‹  ์—†์ด๋Š” ์•„๋ฌด๊ฒƒ๋„ ์ €์žฅ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
            )
        }
        Locale::Ca => {
            format!("A {model_label} la pot redactar. Tu la ratifiques. Res no es desa sense tu.")
        }
        Locale::De => {
            format!(
                "A {model_label} kann sie entwerfen. Du ratifizierst sie. Ohne dich wird nichts gespeichert."
            )
        }
        Locale::Fr => {
            format!(
                "A {model_label} peut la rรฉdiger. Vous la ratifiez. Rien ne s'enregistre sans vous."
            )
        }
        Locale::Id => {
            format!(
                "A {model_label} dapat menyusunnya. Anda yang meratifikasi. Tidak ada yang tersimpan tanpa Anda."
            )
        }
        Locale::Hi => {
            format!(
                "A {model_label} เค‡เคธเค•เคพ เคฎเคธเฅŒเคฆเคพ เคฌเคจเคพ เคธเค•เคคเคพ เคนเฅˆเฅค เค…เค‚เค—เฅ€เค•เคพเคฐ เค†เคช เค•เคฐเคคเฅ‡ เคนเฅˆเค‚เฅค เค†เคชเค•เฅ‡ เคฌเคฟเคจเคพ เค•เฅเค› เคญเฅ€ เคธเคนเฅ‡เคœเคพ เคจเคนเฅ€เค‚ เคœเคพเคคเคพเฅค"
            )
        }
        Locale::Ru => {
            format!(
                "A {model_label} ะผะพะถะตั‚ ะฟะพะดะณะพั‚ะพะฒะธั‚ัŒ ะฟั€ะพะตะบั‚. ะ ะฐั‚ะธั„ะธั†ะธั€ัƒะตั‚ะต ะฒั‹. ะ‘ะตะท ะฒะฐั ะฝะธั‡ะตะณะพ ะฝะต ัะพั…ั€ะฐะฝัะตั‚ัั."
            )
        }
        Locale::Uk => {
            format!(
                "A {model_label} ะผะพะถะต ะฟั–ะดะณะพั‚ัƒะฒะฐั‚ะธ ะฟั€ะพั”ะบั‚. ะ ะฐั‚ะธั„ั–ะบัƒั”ั‚ะต ะฒะธ. ะ‘ะตะท ะฒะฐั ะฝั–ั‡ะพะณะพ ะฝะต ะทะฑะตั€ั–ะณะฐั”ั‚ัŒัั."
            )
        }
        _ => format!("A {model_label} can draft it. You ratify it. Nothing saves without you."),
    }
}

/// Card line offering to keep an existing valid constitution unchanged.
fn keep_existing_invitation_line(locale: Locale) -> &'static str {
    match locale {
        Locale::Ja => "K ๆ—ขๅญ˜ใฎๆ†ฒๆณ•ใ‚’ไฟๆŒ - ็ขบ่ชใ—ใฆไฟๆŒใ€ใƒ•ใ‚กใ‚คใƒซใฏๅค‰ๆ›ดใ—ใพใ›ใ‚“ใ€‚",
        Locale::ZhHans => "K ไฟ็•™็Žฐๆœ‰ๅฎช็ซ โ€”โ€”ๅ…ˆๆŸฅ็œ‹๏ผŒๅ†ไฟ็•™๏ผŒๆ–‡ไปถไธๅ˜ใ€‚",
        Locale::ZhHant => "K ไฟ็•™็พๆœ‰ๆ†ฒๆณ• - ๅ…ˆๆŸฅ็œ‹๏ผŒๅ†ไฟ็•™๏ผŒๆช”ๆกˆไธ่ฎŠใ€‚",
        Locale::PtBr => "K Manter constituiรงรฃo existente - revise, mantenha, arquivo inalterado.",
        Locale::Es419 => {
            "K Conservar constituciรณn existente - revisa, conserva, archivo sin cambios."
        }
        Locale::Vi => "K Giแปฏ hiแบฟn phรกp hiแป‡n cรณ - xem lแบกi, giแปฏ nguyรชn, tแป‡p khรดng ฤ‘แป•i.",
        Locale::Ko => "K ๊ธฐ์กด ํ—Œ๋ฒ• ์œ ์ง€ - ๊ฒ€ํ†  ํ›„ ์œ ์ง€, ํŒŒ์ผ์€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ.",
        Locale::Ca => {
            "K Mantรฉn la constituciรณ existent - revisa-la, conserva-la, fitxer sense canvis."
        }
        Locale::De => "K Bestehende Verfassung behalten - prรผfen, behalten, Datei unverรคndert.",
        Locale::Fr => {
            "K Garder votre constitution existante - rรฉvisez-la, gardez-la, fichier inchangรฉ."
        }
        Locale::Id => {
            "K Pertahankan konstitusi Anda yang ada - tinjau, pertahankan, file tidak berubah."
        }
        Locale::Hi => "K เค…เคชเคจเคพ เคฎเฅŒเคœเฅ‚เคฆเคพ เคธเค‚เคตเคฟเคงเคพเคจ เคฐเค–เฅ‡เค‚ - เคธเคฎเฅ€เค•เฅเคทเคพ เค•เคฐเฅ‡เค‚, เคฌเคจเคพเค เคฐเค–เฅ‡เค‚, เคซเคผเคพเค‡เคฒ เค…เคชเคฐเคฟเคตเคฐเฅเคคเคฟเคคเฅค",
        Locale::Ru => {
            "K ะกะพั…ั€ะฐะฝะธั‚ัŒ ััƒั‰ะตัั‚ะฒัƒัŽั‰ัƒัŽ ะบะพะฝัั‚ะธั‚ัƒั†ะธัŽ - ะฟั€ะพัะผะพั‚ั€ะธั‚ะต, ัะพั…ั€ะฐะฝะธั‚ะต, ั„ะฐะนะป ะฝะต ะธะทะผะตะฝัะตั‚ัั."
        }
        Locale::Uk => "K ะ—ะฑะตั€ะตะณั‚ะธ ั‡ะธะฝะฝัƒ ะบะพะฝัั‚ะธั‚ัƒั†ั–ัŽ - ะฟะตั€ะตะณะปัะฝัŒั‚ะต, ะทะฑะตั€ะตะถั–ั‚ัŒ, ั„ะฐะนะป ะฑะตะท ะทะผั–ะฝ.",
        _ => "K Keep your existing constitution โ€” review it, keep it, file unchanged.",
    }
}

/// Card line shown while a model draft awaits ratification.
fn model_draft_ready_line(locale: Locale, model_label: &str) -> String {
    match locale {
        Locale::Ja => {
            format!(
                "{model_label} ใฎ่‰ๆกˆใŒๆ‰นๅ‡†ๅพ…ใกใงใ™ - G ใง็ขบ่ชใ—ใฆๆ‰นๅ‡†ใ€1-6 ใง่‰ๆกˆใ‚’็ ดๆฃ„ใ—ใพใ™ใ€‚"
            )
        }
        Locale::ZhHans => {
            format!("{model_label} ็š„่‰ๆกˆๅพ…็กฎ่ฎคโ€”โ€”ๆŒ‰ G ๆŸฅ็œ‹ๅนถ็กฎ่ฎค๏ผ›ๆŒ‰ 1-6 ไผšไธขๅผƒ่‰ๆกˆใ€‚")
        }
        Locale::ZhHant => {
            format!("{model_label} ็š„่‰ๆกˆๅพ…ๆ‰นๅ‡† - ๆŒ‰ G ๆŸฅ็œ‹ไธฆๆ‰นๅ‡†๏ผ›ๆŒ‰ 1-6 ๆœƒไธŸๆฃ„่‰ๆกˆใ€‚")
        }
        Locale::PtBr => {
            format!(
                "Rascunho de {model_label} aguarda ratificaรงรฃo - G para revisar e ratificar; 1-6 descarta."
            )
        }
        Locale::Es419 => {
            format!(
                "El borrador de {model_label} espera ratificaciรณn - G para revisar y ratificar; 1-6 lo descarta."
            )
        }
        Locale::Vi => {
            format!(
                "Bแบฃn nhรกp cแปงa {model_label} chแป phรช chuแบฉn - G ฤ‘แปƒ xem vร  phรช chuแบฉn; 1-6 sแบฝ bแป bแบฃn nhรกp."
            )
        }
        Locale::Ko => {
            format!(
                "{model_label}์˜ ์ดˆ์•ˆ์ด ์Šน์ธ์„ ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค - G๋กœ ํ™•์ธํ•˜๊ณ  ์Šน์ธ, 1-6์€ ์ดˆ์•ˆ์„ ๋ฒ„๋ฆฝ๋‹ˆ๋‹ค."
            )
        }
        Locale::Ca => {
            format!(
                "L'esborrany de {model_label} espera ratificaciรณ - G per revisar i ratificar; 1-6 el descarta."
            )
        }
        Locale::De => {
            format!(
                "Entwurf von {model_label} wartet auf Ratifizierung - G zum Prรผfen und Ratifizieren; 1-6 verwirft ihn."
            )
        }
        Locale::Fr => {
            format!(
                "Le brouillon de {model_label} attend ratification - G pour rรฉviser et ratifier ; 1-6 l'รฉcarte."
            )
        }
        Locale::Id => {
            format!(
                "Draf oleh {model_label} menunggu ratifikasi - G untuk meninjau dan meratifikasi; 1-6 membuangnya."
            )
        }
        Locale::Hi => {
            format!(
                "{model_label} เค•เคพ เคฎเคธเฅŒเคฆเคพ เค…เค‚เค—เฅ€เค•เคพเคฐ เค•เฅ€ เคชเฅเคฐเคคเฅ€เค•เฅเคทเคพ เคฎเฅ‡เค‚ เคนเฅˆ - เคธเคฎเฅ€เค•เฅเคทเคพ เค”เคฐ เค…เค‚เค—เฅ€เค•เคพเคฐ เค•เฅ‡ เคฒเคฟเค G; 1-6 เค‰เคธเฅ‡ เค–เคพเคฐเคฟเคœ เค•เคฐเคคเคพ เคนเฅˆเฅค"
            )
        }
        Locale::Ru => {
            format!(
                "ะŸั€ะพะตะบั‚ ะพั‚ {model_label} ะพะถะธะดะฐะตั‚ ั€ะฐั‚ะธั„ะธะบะฐั†ะธะธ - G ะดะปั ะฟั€ะพัะผะพั‚ั€ะฐ ะธ ั€ะฐั‚ะธั„ะธะบะฐั†ะธะธ; 1-6 ะพั‚ะบะปะพะฝัะตั‚ ะตะณะพ."
            )
        }
        Locale::Uk => {
            format!(
                "ะŸั€ะพั”ะบั‚ ะฒั–ะด {model_label} ะพั‡ั–ะบัƒั” ั€ะฐั‚ะธั„ั–ะบะฐั†ั–ั— - G ะดะปั ะฟะตั€ะตะณะปัะดัƒ ั‚ะฐ ั€ะฐั‚ะธั„ั–ะบะฐั†ั–ั—; 1-6 ะฒั–ะดั…ะธะปัั” ะนะพะณะพ."
            )
        }
        _ => format!(
            "Draft by {model_label} awaits ratification โ€” G to review and ratify; 1-6 discards it."
        ),
    }
}

/// Host-facing status line after a successful model draft.
pub(crate) fn model_draft_ready_message(locale: Locale, model_label: &str) -> String {
    match locale {
        Locale::Ja => format!(
            "{model_label} ใŒใ‚ใชใŸใฎๆ†ฒๆณ•ใ‚’่ตท่‰ใ—ใพใ—ใŸใ€‚ใƒ—ใƒฌใƒ“ใƒฅใƒผใ‚’็ขบ่ชใ—ใฆใ‹ใ‚‰ G ใงๆ‰นๅ‡†ใ—ใฆใใ ใ•ใ„ใ€‚"
        ),
        Locale::ZhHans => {
            format!("{model_label} ๅทฒ็”Ÿๆˆไฝ ็š„ๅฎช็ซ ่‰ๆกˆใ€‚่ฏทๆŸฅ็œ‹้ข„่งˆ๏ผŒ็„ถๅŽๆŒ‰ G ็กฎ่ฎคใ€‚")
        }
        Locale::ZhHant => format!("{model_label} ๅทฒ่ตท่‰ไฝ ็š„ๆ†ฒๆณ•ใ€‚่ซ‹ๆŸฅ็œ‹้ ่ฆฝ๏ผŒ็„ถๅพŒๆŒ‰ G ๆ‰นๅ‡†ใ€‚"),
        Locale::PtBr => format!(
            "{model_label} rascunhou sua constituiรงรฃo. Revise a prรฉvia e pressione G para ratificar."
        ),
        Locale::Es419 => format!(
            "{model_label} redactรณ tu constituciรณn. Revisa la vista previa y presiona G para ratificar."
        ),
        Locale::Vi => format!(
            "{model_label} ฤ‘รฃ soแบกn hiแบฟn phรกp cแปงa bแบกn. Xem bแบฃn xem trฦฐแป›c rแป“i nhแบฅn G ฤ‘แปƒ phรช chuแบฉn."
        ),
        Locale::Ko => format!(
            "{model_label}์ด(๊ฐ€) ๋‹น์‹ ์˜ ํ—Œ๋ฒ• ์ดˆ์•ˆ์„ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ํ™•์ธํ•œ ๋’ค G๋ฅผ ๋ˆŒ๋Ÿฌ ์Šน์ธํ•˜์„ธ์š”."
        ),
        Locale::Ca => format!(
            "{model_label} ha redactat la teva constituciรณ. Revisa la previsualitzaciรณ i prem G per ratificar."
        ),
        Locale::De => format!(
            "{model_label} hat deine Verfassung entworfen. Prรผfe die Vorschau und drรผcke G zum Ratifizieren."
        ),
        Locale::Fr => format!(
            "{model_label} a rรฉdigรฉ votre constitution. Rรฉvisez l'aperรงu, puis appuyez sur G pour ratifier."
        ),
        Locale::Id => format!(
            "{model_label} menyusun konstitusi Anda. Tinjau pratinjaunya, lalu tekan G untuk meratifikasi."
        ),
        Locale::Hi => format!(
            "{model_label} เคจเฅ‡ เค†เคชเค•เฅ‡ เคธเค‚เคตเคฟเคงเคพเคจ เค•เคพ เคฎเคธเฅŒเคฆเคพ เคคเฅˆเคฏเคพเคฐ เค•เคฟเคฏเคพเฅค เคชเฅ‚เคฐเฅเคตเคพเคตเคฒเฅ‹เค•เคจ เคฆเฅ‡เค–เฅ‡เค‚, เคซเคฟเคฐ เค…เค‚เค—เฅ€เค•เคพเคฐ เค•เฅ‡ เคฒเคฟเค G เคฆเคฌเคพเคเคเฅค"
        ),
        Locale::Ru => format!(
            "{model_label} ะฟะพะดะณะพั‚ะพะฒะธะป ะฟั€ะพะตะบั‚ ะฒะฐัˆะตะน ะบะพะฝัั‚ะธั‚ัƒั†ะธะธ. ะŸั€ะพัะผะพั‚ั€ะธั‚ะต ะฟั€ะตะฒัŒัŽ, ะทะฐั‚ะตะผ ะฝะฐะถะผะธั‚ะต G ะดะปั ั€ะฐั‚ะธั„ะธะบะฐั†ะธะธ."
        ),
        Locale::Uk => format!(
            "{model_label} ะฟั–ะดะณะพั‚ัƒะฒะฐะฒ ะฟั€ะพั”ะบั‚ ะฒะฐัˆะพั— ะบะพะฝัั‚ะธั‚ัƒั†ั–ั—. ะŸะตั€ะตะณะปัะฝัŒั‚ะต ะฟั€ะตะฒ'ัŽ, ะฟะพั‚ั–ะผ ะฝะฐั‚ะธัะฝั–ั‚ัŒ G ะดะปั ั€ะฐั‚ะธั„ั–ะบะฐั†ั–ั—."
        ),
        _ => format!(
            "{model_label} drafted your constitution. Review the preview, then press G to ratify."
        ),
    }
}

/// Host-facing status line when model drafting fails or is unavailable. The
/// guided deterministic draft always remains the standing fallback.
pub(crate) fn model_draft_failed_message(
    locale: Locale,
    model_label: &str,
    reason: &str,
) -> String {
    match locale {
        Locale::Ja => {
            format!(
                "{model_label} ใฏ่ตท่‰ใ‚’ๅฎŒไบ†ใงใใพใ›ใ‚“ใงใ—ใŸ๏ผˆ{reason}๏ผ‰ใ€‚ใ‚ฌใ‚คใƒ‰่‰ๆกˆใฏๆœ‰ๅŠนใงใ™ใ€‚G ใงใƒ—ใƒฌใƒ“ใƒฅใƒผใ—ใฆๆ‰นๅ‡†ใงใใพใ™ใ€‚"
            )
        }
        Locale::ZhHans => {
            format!("{model_label} ๆœช่ƒฝ็”Ÿๆˆ่‰ๆกˆ๏ผˆ{reason}๏ผ‰ใ€‚ๅผ•ๅฏผๅผ่‰ๆกˆไปๅฏไฝฟ็”จโ€”โ€”ๆŒ‰ G ้ข„่งˆๅนถ็กฎ่ฎคใ€‚")
        }
        Locale::ZhHant => {
            format!("{model_label} ๆœช่ƒฝๅฎŒๆˆ่ตท่‰๏ผˆ{reason}๏ผ‰ใ€‚ๅผ•ๅฐŽๅผ่‰ๆกˆไป็„ถๆœ‰ๆ•ˆ๏ผ›ๆŒ‰ G ้ ่ฆฝไธฆๆ‰นๅ‡†ใ€‚")
        }
        Locale::PtBr => {
            format!(
                "{model_label} nรฃo conseguiu rascunhar sua constituiรงรฃo ({reason}). O rascunho guiado continua vรกlido; pressione G para prรฉ-visualizar e ratificar."
            )
        }
        Locale::Es419 => {
            format!(
                "{model_label} no pudo redactar tu constituciรณn ({reason}). El borrador guiado sigue vรกlido; presiona G para previsualizar y ratificar."
            )
        }
        Locale::Vi => {
            format!(
                "{model_label} khรดng thแปƒ soแบกn hiแบฟn phรกp cแปงa bแบกn ({reason}). Bแบฃn nhรกp hฦฐแป›ng dแบซn vแบซn hแปฃp lแป‡; nhแบฅn G ฤ‘แปƒ xem trฦฐแป›c vร  phรช chuแบฉn."
            )
        }
        Locale::Ko => {
            format!(
                "{model_label}์ด(๊ฐ€) ๋‹น์‹ ์˜ ํ—Œ๋ฒ• ์ดˆ์•ˆ์„ ์ž‘์„ฑํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค ({reason}). ๊ฐ€์ด๋“œ ์ดˆ์•ˆ์€ ์—ฌ์ „ํžˆ ์œ ํšจํ•ฉ๋‹ˆ๋‹ค. G๋ฅผ ๋ˆŒ๋Ÿฌ ๋ฏธ๋ฆฌ๋ณด๊ณ  ์Šน์ธํ•˜์„ธ์š”."
            )
        }
        Locale::Ca => {
            format!(
                "{model_label} no ha pogut redactar la teva constituciรณ ({reason}). L'esborrany guiat continua vigent; prem G per previsualitzar i ratificar."
            )
        }
        Locale::De => {
            format!(
                "{model_label} konnte deine Verfassung nicht entwerfen ({reason}). Dein gefรผhrter Entwurf bleibt gรผltig; drรผcke G fรผr Vorschau und Ratifizierung."
            )
        }
        Locale::Fr => {
            format!(
                "{model_label} n'a pas pu rรฉdiger votre constitution ({reason}). Votre brouillon guidรฉ reste valide ; appuyez sur G pour l'aperรงu et la ratification."
            )
        }
        Locale::Id => {
            format!(
                "{model_label} tidak dapat menyusun konstitusi Anda ({reason}). Draf terpandu Anda tetap berlaku; tekan G untuk pratinjau dan ratifikasi."
            )
        }
        Locale::Hi => {
            format!(
                "{model_label} เค†เคชเค•เฅ‡ เคธเค‚เคตเคฟเคงเคพเคจ เค•เคพ เคฎเคธเฅŒเคฆเคพ เคจเคนเฅ€เค‚ เคฌเคจเคพ เคธเค•เคพ ({reason})เฅค เค†เคชเค•เคพ เค—เคพเค‡เคกเฅ‡เคก เคฎเคธเฅŒเคฆเคพ เค…เคฌ เคญเฅ€ เคฎเคพเคจเฅเคฏ เคนเฅˆ; เคชเฅ‚เคฐเฅเคตเคพเคตเคฒเฅ‹เค•เคจ เค”เคฐ เค…เค‚เค—เฅ€เค•เคพเคฐ เค•เฅ‡ เคฒเคฟเค G เคฆเคฌเคพเคเคเฅค"
            )
        }
        Locale::Ru => {
            format!(
                "{model_label} ะฝะต ัะผะพะณ ะฟะพะดะณะพั‚ะพะฒะธั‚ัŒ ะฒะฐัˆัƒ ะบะพะฝัั‚ะธั‚ัƒั†ะธัŽ ({reason}). ะ’ะฐัˆ ัƒะฟั€ะฐะฒะปัะตะผั‹ะน ะฟั€ะพะตะบั‚ ะพัั‚ะฐั‘ั‚ัั ะฒ ัะธะปะต โ€” ะฝะฐะถะผะธั‚ะต G ะดะปั ะฟั€ะพัะผะพั‚ั€ะฐ ะธ ั€ะฐั‚ะธั„ะธะบะฐั†ะธะธ."
            )
        }
        Locale::Uk => {
            format!(
                "{model_label} ะฝะต ะทะผั–ะณ ะฟั–ะดะณะพั‚ัƒะฒะฐั‚ะธ ะฒะฐัˆัƒ ะบะพะฝัั‚ะธั‚ัƒั†ั–ัŽ ({reason}). ะ’ะฐัˆ ะบะตั€ะพะฒะฐะฝะธะน ะฟั€ะพั”ะบั‚ ะทะฐะปะธัˆะฐั”ั‚ัŒัั ั‡ะธะฝะฝะธะผ โ€” ะฝะฐั‚ะธัะฝั–ั‚ัŒ G ะดะปั ะฟะตั€ะตะณะปัะดัƒ ั‚ะฐ ั€ะฐั‚ะธั„ั–ะบะฐั†ั–ั—."
            )
        }
        _ => format!(
            "{model_label} could not draft your constitution ({reason}). Your guided draft still \
             stands โ€” press G to preview and ratify."
        ),
    }
}

fn constitution_choice_label(choice: ConstitutionChoice) -> &'static str {
    match choice {
        ConstitutionChoice::Unset => "unset",
        ConstitutionChoice::Bundled => "bundled/default",
        ConstitutionChoice::GuidedCustom => "guided custom",
        ConstitutionChoice::ExpertOverride => "expert override",
        ConstitutionChoice::Deferred => "deferred",
    }
}

fn constitution_source_label(source: ConstitutionSource) -> &'static str {
    match source {
        ConstitutionSource::Bundled => "bundled",
        ConstitutionSource::UserGlobal => "user-global constitution.json",
        ConstitutionSource::ExpertOverride => "expert full Markdown override",
    }
}

fn constitution_validity_label(validity: ConstitutionValidity) -> &'static str {
    match validity {
        ConstitutionValidity::Unknown => "unknown",
        ConstitutionValidity::Valid => "valid",
        ConstitutionValidity::Invalid => "invalid",
        ConstitutionValidity::Empty => "empty",
        ConstitutionValidity::Unreadable => "unreadable",
    }
}

pub fn persist_user_constitution_choice(
    constitution: &UserConstitution,
    state: &SetupState,
) -> anyhow::Result<()> {
    let constitution_path = UserConstitution::path()?;
    let setup_state_path = SetupState::path()?;
    let mut transaction = codewhale_config::persistence::SetupTransaction::new();
    transaction.stage_json(constitution_path, &constitution.bounded())?;
    transaction.stage_json(setup_state_path, state)?;
    transaction.commit()
}

#[must_use]
pub fn should_open_update_checkpoint(app: &App, config: &Config) -> bool {
    let state = load_setup_state_for_app(app, config);
    state.needs_constitution_checkpoint(CONSTITUTION_CHECKPOINT_VERSION)
}

pub fn defer_update_checkpoint_for_app(app: &App, config: &Config) -> anyhow::Result<SetupState> {
    let mut state = load_setup_state_for_app(app, config);
    if !state.needs_constitution_checkpoint(CONSTITUTION_CHECKPOINT_VERSION) {
        return Ok(state);
    }
    state.complete_constitution_checkpoint(
        CONSTITUTION_CHECKPOINT_VERSION,
        ConstitutionChoice::Deferred,
    );
    state.constitution_source = ConstitutionSource::Bundled;
    state.constitution_validity = ConstitutionValidity::Unknown;
    state.constitution_authoring = None;
    state.constitution_preview_hash = None;
    state.set_step(
        SetupStep::Constitution,
        StepEntry::new(StepStatus::Deferred, true, CONSTITUTION_CHECKPOINT_VERSION)
            .with_result("checkpoint deferred; bundled applies"),
    );
    state.save()?;
    Ok(state)
}

#[must_use]
pub fn load_setup_state_for_app(app: &App, config: &Config) -> SetupState {
    if let Ok(Some(state)) = SetupState::load() {
        return state;
    }
    SetupState::derive_inherited(&inherited_facts_for_app(app, config))
}

pub(crate) fn record_provider_model_setup_state_for_app(
    app: &App,
    config: &Config,
) -> anyhow::Result<SetupState> {
    let facts = SetupRuntimeFacts::from_app_config(app, config);
    let mut state = load_setup_state_for_app(app, config);
    state.set_step(
        SetupStep::ProviderModel,
        provider::step_entry(
            facts.provider_ready,
            CONSTITUTION_CHECKPOINT_VERSION,
            facts.provider_result,
        ),
    );
    state.save()?;
    Ok(state)
}

#[must_use]
fn inherited_facts_for_app(app: &App, config: &Config) -> InheritedConfigFacts {
    let user_constitution = UserConstitution::load().ok();
    let user_constitution_validity = user_constitution.as_ref().map_or(
        ConstitutionValidity::Unknown,
        UserConstitutionLoad::validity,
    );
    let has_user_constitution = user_constitution
        .as_ref()
        .is_some_and(|loaded| !matches!(loaded, UserConstitutionLoad::Missing));
    let expert_override = SetupExpertOverrideState::load();
    InheritedConfigFacts {
        language: Some(app.ui_locale.tag().to_string()),
        has_provider_route: !config.default_model().trim().is_empty(),
        has_credentials_or_local_runtime: has_api_key(config),
        trust_chosen: app.trust_mode || !onboarding::needs_trust(&app.workspace),
        has_expert_override: expert_override.is_active(),
        has_user_constitution,
        user_constitution_validity,
    }
}

fn expert_override_path() -> Option<std::path::PathBuf> {
    codewhale_config::codewhale_home()
        .ok()
        .map(|home| home.join(Path::new(CONSTITUTION_OVERRIDE_FILE)))
}

#[must_use]
fn progressive_initial_step_index(state: &SetupState, facts: &SetupRuntimeFacts) -> usize {
    if !facts.provider_ready {
        return step_index(SetupStep::ProviderModel);
    }
    let runtime_current = if state.inherited {
        matches!(state.status(SetupStep::TrustSandbox), StepStatus::Verified)
            && state.runtime_posture_source.is_reviewed()
    } else {
        state
            .steps
            .get(&SetupStep::TrustSandbox)
            .is_some_and(|entry| {
                entry.status == StepStatus::Verified
                    && entry.result.as_deref() == Some(facts.runtime_result.as_str())
            })
            && state.runtime_posture_source.is_reviewed()
    };
    if !runtime_current {
        return step_index(SetupStep::TrustSandbox);
    }
    if facts.tools_mcp_needs_action {
        return step_index(SetupStep::ToolsMcp);
    }
    step_index(SetupStep::Verification)
}

#[must_use]
fn step_index(step: SetupStep) -> usize {
    STEP_SPECS
        .iter()
        .position(|spec| spec.id() == step)
        .expect("all setup-state steps should have wizard specs")
}

fn visible_step_index(step: SetupStep) -> usize {
    STEP_SPECS
        .iter()
        .position(|spec| spec.id() == step)
        .unwrap_or_else(|| step_index(SetupStep::Constitution))
}

#[cfg(test)]
mod progressive_tests {
    use super::*;
    use crossterm::event::KeyModifiers;

    fn facts(provider_ready: bool) -> SetupRuntimeFacts {
        SetupRuntimeFacts {
            provider: "local".to_string(),
            model: "stub-model".to_string(),
            auth: if provider_ready { "ready" } else { "missing" }.to_string(),
            provider_ready,
            runtime_result: "approval=ask; sandbox=workspace; network=prompt".to_string(),
            tools_mcp_result: "mcp=off, skills=off, tools=off, plugins=off, overall=off"
                .to_string(),
            remote_control_result: tr(Locale::En, MessageId::SetupRemoteStatusDisabled)
                .into_owned(),
            ..SetupRuntimeFacts::default()
        }
    }

    fn complete_state(runtime_result: &str) -> SetupState {
        let mut state = SetupState {
            runtime_posture_source: RuntimePostureSource::Confirmed,
            ..SetupState::default()
        };
        state.set_step(
            SetupStep::TrustSandbox,
            StepEntry::new(StepStatus::Verified, true, CONSTITUTION_CHECKPOINT_VERSION)
                .with_result(runtime_result),
        );
        state
    }

    fn render_text(view: &SetupWizardView, width: u16, height: u16) -> String {
        let area = Rect::new(0, 0, width, height);
        let mut buffer = Buffer::empty(area);
        ModalView::render(view, area, &mut buffer);
        (0..height)
            .map(|y| {
                (0..width)
                    .map(|x| buffer[(x, y)].symbol())
                    .collect::<String>()
            })
            .collect::<Vec<_>>()
            .join("\n")
    }

    #[test]
    fn fresh_setup_starts_at_the_missing_provider_decision() {
        let view = SetupWizardView::new_with_facts(SetupState::default(), Locale::En, facts(false));

        assert_eq!(view.selected_step(), SetupStep::ProviderModel);
        assert!(matches!(
            ModalView::handle_key(
                &mut view.clone(),
                KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)
            ),
            ViewAction::EmitAndClose(ViewEvent::SetupOpenProviderRequested)
        ));
    }

    #[test]
    fn partial_setup_skips_the_ready_provider_and_asks_for_permissions() {
        let mut view =
            SetupWizardView::new_with_facts(SetupState::default(), Locale::En, facts(true));

        assert_eq!(view.selected_step(), SetupStep::TrustSandbox);
        let action =
            ModalView::handle_key(&mut view, KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
        let ViewAction::Emit(ViewEvent::SetupStateCommitRequested { state, message, .. }) = action
        else {
            panic!("reviewing the current permissions posture should persist a receipt");
        };
        assert_eq!(
            state.runtime_posture_source,
            RuntimePostureSource::Confirmed
        );
        assert_eq!(state.status(SetupStep::TrustSandbox), StepStatus::Verified);
        assert!(!message.is_empty());
        assert_eq!(view.selected_step(), SetupStep::RemoteRuntime);
    }

    #[test]
    fn fully_configured_setup_opens_the_compact_summary() {
        let facts = facts(true);
        let state = complete_state(&facts.runtime_result);
        let mut view = SetupWizardView::new_with_facts(state, Locale::En, facts);

        assert_eq!(view.selected_step(), SetupStep::Verification);
        let action =
            ModalView::handle_key(&mut view, KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
        let ViewAction::EmitAndClose(ViewEvent::SetupStateCommitRequested { state, .. }) = action
        else {
            panic!("starting from Ready should persist the report before closing");
        };
        assert!(state.steps.contains_key(&SetupStep::Verification));
    }

    #[test]
    fn stale_complete_receipts_reopen_the_real_broken_surface() {
        let mut provider_broken = facts(false);
        provider_broken.runtime_result = "current".to_string();
        let state = complete_state("old");
        assert_eq!(
            SetupWizardView::new_with_facts(state, Locale::En, provider_broken).selected_step(),
            SetupStep::ProviderModel
        );

        let runtime_current = facts(true);
        let stale_state = complete_state("old runtime snapshot");
        assert_eq!(
            SetupWizardView::new_with_facts(stale_state, Locale::En, runtime_current)
                .selected_step(),
            SetupStep::TrustSandbox
        );
    }

    #[test]
    fn configured_broken_tools_join_the_journey_but_empty_tools_do_not() {
        let mut broken = facts(true);
        let state = complete_state(&broken.runtime_result);
        broken.tools_mcp_needs_action = true;
        broken.tools_mcp_result = "overall=needs_config".to_string();
        let mut broken_view = SetupWizardView::new_with_facts(state.clone(), Locale::En, broken);
        assert_eq!(broken_view.selected_step(), SetupStep::ToolsMcp);
        let action = ModalView::handle_key(
            &mut broken_view,
            KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE),
        );
        let ViewAction::Emit(ViewEvent::SetupStateCommitRequested { state, .. }) = action else {
            panic!("continuing past a broken optional tool should save its visible issue");
        };
        assert_eq!(state.status(SetupStep::ToolsMcp), StepStatus::NeedsAction);
        assert_eq!(broken_view.selected_step(), SetupStep::Verification);

        let empty = facts(true);
        assert_eq!(
            SetupWizardView::new_with_facts(state, Locale::En, empty).selected_step(),
            SetupStep::Verification
        );
    }

    #[test]
    fn account_action_uses_the_real_remote_control_handoff() {
        let facts = facts(true);
        let state = complete_state(&facts.runtime_result);
        let mut view = SetupWizardView::new_with_facts(state, Locale::En, facts);
        view.selected = visible_step_index(SetupStep::RemoteRuntime);

        assert!(matches!(
            ModalView::handle_key(
                &mut view,
                KeyEvent::new(KeyCode::Char('r'), KeyModifiers::NONE)
            ),
            ViewAction::EmitAndClose(ViewEvent::SetupOpenRemoteControlRequested)
        ));
    }

    #[test]
    fn progressive_arrow_keys_scroll_details_without_changing_the_decision() {
        let mut view =
            SetupWizardView::new_with_facts(SetupState::default(), Locale::En, facts(false));
        view.details_expanded = true;
        view.body_scroll = 4;
        let step = view.selected_step();

        assert!(matches!(
            ModalView::handle_key(&mut view, KeyEvent::new(KeyCode::Up, KeyModifiers::NONE)),
            ViewAction::None
        ));
        assert_eq!(view.selected_step(), step);
        assert_eq!(view.body_scroll, 3);

        assert!(matches!(
            ModalView::handle_key(&mut view, KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)),
            ViewAction::None
        ));
        assert_eq!(view.selected_step(), step);
        assert_eq!(view.body_scroll, 4);
    }

    #[test]
    fn fresh_and_complete_guides_remain_reachable_at_compact_and_normal_sizes() {
        let fresh =
            SetupWizardView::new_with_facts(SetupState::default(), Locale::En, facts(false));
        let fresh_text = render_text(&fresh, 40, 12);
        assert!(fresh_text.contains(tr(Locale::En, MessageId::OnboardProviderTitle).as_ref()));
        let normal_text = render_text(&fresh, 100, 28);
        assert!(normal_text.contains(tr(Locale::En, MessageId::OnboardProviderTitle).as_ref()));
        assert!(normal_text.contains("local ยท stub-model"));

        let facts = facts(true);
        let complete = SetupWizardView::new_with_facts(
            complete_state(&facts.runtime_result),
            Locale::En,
            facts,
        );
        let complete_text = render_text(&complete, 40, 12);
        assert!(complete_text.contains(tr(Locale::En, MessageId::OnboardReadyTitle).as_ref()));
    }
}