instinct-cli 0.3.7

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
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
// generated by hxc 1.0.0-acgt-compiler from src/check/observe.hlx -- do not edit by hand

#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
    let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
    if !ok {
        eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
    }
    ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
        std::process::exit(13);
    }
    c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    use std::os::windows::process::CommandExt;
    c.creation_flags(0x08000000);
    c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
    if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
        std::process::exit(13);
    }
    c
}

// hlx:2
// `instinct check observe`: first M2 adapter, artifact-inventory/v1. Spec: docs/check-observation-wire.md.
// hlx:3
// Reads directory NAMES and KINDS only: no file contents, no writes, no network, no process, no bank, no logging.
// hlx:4
// Granted root = the explicit --root argument for this one invocation. Nothing in the policy JSON grants access.
// hlx:5
// Assumption, not proof: the caller asserts `trusted_quiescent_staging`. Portable std paths are not a hostile-race
// hlx:6
// security boundary; the two-pass compare only catches VISIBLE mutation between passes. A hostile concurrent writer
// hlx:7
// is outside what this adapter can contain. Symlinks in the root path (every ancestor and the root itself) are rejected, under the same assumption.
// hlx:8
// Subset and required checks are delegated to the pure kernel (`kernel::evaluate`); there is no second evaluator here.
// hlx:9
// Not implemented in this increment: grant/root fingerprints, metadata or content digests, receipts, MCP.
// hlx:10
use super::json::{self, J};
// hlx:11
use super::kernel::{self, Mode};
// hlx:12
use std::collections::BTreeSet;
// hlx:13
use std::path::{Component, Path, PathBuf};
// hlx:14
const OBSERVE_USAGE: &str = "usage: instinct check observe --root /absolute/staging/root --input FILE|-\n\
// hlx:15
Read-only inventory of names and kinds under the granted root, checked against the caller policy\n\
// hlx:16
(schema instinct.artifact-policy/v1). No bank is opened; exit 0 for observed/incomplete, exit 2 for an error result.\n\
// hlx:17
Spec: docs/check-observation-wire.md.";
// hlx:18
const POLICY_SCHEMA: &str = "instinct.artifact-policy/v1";
// hlx:19
const CEIL_ENTRIES: u64 = 10000;
// hlx:20
const CEIL_DEPTH: u64 = 64;
// hlx:21
const CEIL_BYTES: u64 = 1 << 20;
// hlx:22
const META_ALLOWANCE: u64 = 64;
// hlx:23
#[derive(Clone, Copy)]
// hlx:24
struct Limits {
    // hlx:25
    entries: u64,
    // hlx:26
    depth: u64,
    // hlx:27
    bytes: u64,
    // hlx:28
}
// hlx:29
struct Policy {
    // hlx:30
    trusted: bool,
    // hlx:31
    allowed: Vec<String>,
    // hlx:32
    required: Vec<String>,
    // hlx:33
    scope: Vec<(String, String)>,
    // hlx:34
    limits: Limits,
    // hlx:35
}
// hlx:36
#[derive(Clone, PartialEq, Eq, Debug)]
// hlx:37
struct Meta {
    // hlx:38
    len: u64,
    // hlx:39
    stamp: [i64; 6],
    // hlx:40
    mode: u32,
    // hlx:41
}
// hlx:42
#[derive(Clone, PartialEq, Eq, Debug)]
// hlx:43
struct Ent {
    // hlx:44
    path: String,
    // hlx:45
    dir: bool,
    // hlx:46
    meta: Meta,
    // hlx:47
}
// hlx:48
#[derive(PartialEq, Eq, Debug)]
// hlx:49
struct Snap {
    // hlx:50
    root_before: Meta,
    // hlx:51
    root_after: Meta,
    // hlx:52
    ents: Vec<Ent>,
    // hlx:53
}
// hlx:54
struct Stop {
    // hlx:55
    reason: String,
    // hlx:56
    witness: Option<String>,
    // hlx:57
}
// hlx:58
fn stop(reason: &str, witness: Option<&str>) -> Stop {
    // hlx:59
    Stop {
        reason: reason.to_string(),
        witness: witness.map(|w| w.to_string()),
    }
    // hlx:60
}
// hlx:61
fn jstr(s: &str) -> String {
    // hlx:62
    let mut o = String::with_capacity(s.len() + 2);
    // hlx:63
    o.push('"');
    // hlx:64
    for c in s.chars() {
        // hlx:65
        match c {
            // hlx:66
            '"' => o.push_str("\\\""),
            // hlx:67
            '\\' => o.push_str("\\\\"),
            // hlx:68
            '\n' => o.push_str("\\n"),
            // hlx:69
            '\r' => o.push_str("\\r"),
            // hlx:70
            '\t' => o.push_str("\\t"),
            // hlx:71
            c if (c as u32) < 0x20 || c as u32 == 0x7f => {
                o.push_str(&format!("\\u{:04x}", c as u32))
            }
            // hlx:72
            c => o.push(c),
            // hlx:73
        }
        // hlx:74
    }
    // hlx:75
    o.push('"');
    // hlx:76
    o
    // hlx:77
}
// hlx:78
fn jlist(items: &[String]) -> String {
    // hlx:79
    let parts: Vec<String> = items.iter().map(|s| jstr(s)).collect();
    // hlx:80
    format!("[{}]", parts.join(","))
    // hlx:81
}
// hlx:82
fn jscope(scope: &[(String, String)]) -> String {
    // hlx:83
    let parts: Vec<String> = scope
        .iter()
        .map(|(k, v)| format!("{}:{}", jstr(k), jstr(v)))
        .collect();
    // hlx:84
    format!("{{{}}}", parts.join(","))
    // hlx:85
}
// hlx:86
fn valid_rel(p: &str) -> Result<(), &'static str> {
    // hlx:87
    if p.is_empty() {
        // hlx:88
        return Err("empty path");
        // hlx:89
    }
    // hlx:90
    if p.contains('\0') {
        // hlx:91
        return Err("NUL in path");
        // hlx:92
    }
    // hlx:93
    if p.starts_with('/') {
        // hlx:94
        return Err("absolute path");
        // hlx:95
    }
    // hlx:96
    if p.starts_with("\\\\") {
        // hlx:97
        return Err("UNC path");
        // hlx:98
    }
    // hlx:99
    let b = p.as_bytes();
    // hlx:100
    if b.len() >= 2 && b[0].is_ascii_alphabetic() && b[1] == b':' {
        // hlx:101
        return Err("drive path");
        // hlx:102
    }
    // hlx:103
    if p.ends_with('/') {
        // hlx:104
        return Err("trailing slash");
        // hlx:105
    }
    // hlx:106
    for c in p.split('/') {
        // hlx:107
        if c.is_empty() {
            // hlx:108
            return Err("empty component");
            // hlx:109
        }
        // hlx:110
        if c == "." || c == ".." {
            // hlx:111
            return Err("dot component");
            // hlx:112
        }
        // hlx:113
    }
    // hlx:114
    Ok(())
    // hlx:115
}
// hlx:116
fn obj<'a>(v: &'a J, what: &str) -> Result<&'a [(String, J)], String> {
    // hlx:117
    match v {
        // hlx:118
        J::Obj(o) => Ok(o),
        // hlx:119
        _ => Err(format!("malformed_policy: {what} must be an object")),
        // hlx:120
    }
    // hlx:121
}
// hlx:122
fn only_keys(o: &[(String, J)], allowed: &[&str], what: &str) -> Result<(), String> {
    // hlx:123
    for (k, _) in o {
        // hlx:124
        if !allowed.contains(&k.as_str()) {
            // hlx:125
            return Err(format!("malformed_policy: unknown field in {what}"));
            // hlx:126
        }
        // hlx:127
    }
    // hlx:128
    Ok(())
    // hlx:129
}
// hlx:130
fn get<'a>(o: &'a [(String, J)], k: &str) -> Option<&'a J> {
    // hlx:131
    o.iter().find(|(n, _)| n == k).map(|(_, v)| v)
    // hlx:132
}
// hlx:133
fn path_list(v: &J, name: &str) -> Result<Vec<String>, String> {
    // hlx:134
    let items = match v {
        // hlx:135
        J::Arr(a) => a,
        // hlx:136
        _ => {
            return Err(format!(
                "malformed_policy: {name} must be an array of strings"
            ))
        } // hlx:137
    };
    // hlx:138
    if items.len() as u64 > CEIL_ENTRIES {
        // hlx:139
        return Err(format!(
            "limit_exceeded: {name} has more than 10000 entries"
        ));
        // hlx:140
    }
    // hlx:141
    let mut seen: BTreeSet<&str> = BTreeSet::new();
    // hlx:142
    let mut out = Vec::new();
    // hlx:143
    for (i, it) in items.iter().enumerate() {
        // hlx:144
        let s = match it {
            // hlx:145
            J::Str(s) => s,
            // hlx:146
            _ => return Err(format!("malformed_policy: {name}[{i}] must be a string")),
            // hlx:147
        };
        // hlx:148
        if let Err(why) = valid_rel(s) {
            // hlx:149
            return Err(format!("invalid_path: {name}[{i}]: {why}"));
            // hlx:150
        }
        // hlx:151
        if !seen.insert(s.as_str()) {
            // hlx:152
            return Err(format!("malformed_policy: {name}[{i}] is a duplicate"));
            // hlx:153
        }
        // hlx:154
        out.push(s.clone());
        // hlx:155
    }
    // hlx:156
    Ok(out)
    // hlx:157
}
// hlx:158
fn limit(o: &[(String, J)], key: &str, default: u64, ceil: u64) -> Result<u64, String> {
    // hlx:159
    let v = match get(o, key) {
        // hlx:160
        None => return Ok(default),
        // hlx:161
        Some(J::Num(n)) => n,
        // hlx:162
        Some(_) => return Err(format!("invalid_limit: {key} must be an integer")),
        // hlx:163
    };
    // hlx:164
    let canon = !v.is_empty()
        && v.len() <= 10
        && v.bytes().all(|c| c.is_ascii_digit())
        && (v == "0" || !v.starts_with('0'));
    // hlx:165
    if !canon {
        // hlx:166
        return Err(format!(
            "invalid_limit: {key} must be a canonical non-negative integer"
        ));
        // hlx:167
    }
    // hlx:168
    let n: u64 = v
        .parse()
        .map_err(|_| format!("invalid_limit: {key} is not a number"))?;
    // hlx:169
    if n > ceil {
        // hlx:170
        return Err(format!("invalid_limit: {key} exceeds the ceiling {ceil}"));
        // hlx:171
    }
    // hlx:172
    Ok(n)
    // hlx:173
}
// hlx:174
fn parse_policy(bytes: &[u8]) -> Result<Policy, String> {
    // hlx:175
    let tree = json::parse(bytes)?;
    // hlx:176
    let top = obj(&tree, "the policy")?;
    // hlx:177
    only_keys(
        top,
        &[
            "schema",
            "assumptions",
            "allowed",
            "required",
            "scope",
            "limits",
        ],
        "policy",
    )?;
    // hlx:178
    match get(top, "schema") {
        // hlx:179
        Some(J::Str(s)) if s == POLICY_SCHEMA => {}
        // hlx:180
        _ => return Err(format!("malformed_policy: schema must be {POLICY_SCHEMA}")),
        // hlx:181
    }
    // hlx:182
    let trusted = match get(top, "assumptions") {
        // hlx:183
        None => false,
        // hlx:184
        Some(a) => {
            // hlx:185
            let ao = obj(a, "assumptions")?;
            // hlx:186
            only_keys(ao, &["trusted_quiescent_staging"], "assumptions")?;
            // hlx:187
            match get(ao, "trusted_quiescent_staging") {
                // hlx:188
                None => false,
                // hlx:189
                Some(J::Bool(b)) => *b,
                // hlx:190
                Some(_) => {
                    return Err(
                        "malformed_policy: trusted_quiescent_staging must be a boolean".to_string(),
                    )
                } // hlx:191
            }
            // hlx:192
        } // hlx:193
    };
    // hlx:194
    let allowed = match get(top, "allowed") {
        // hlx:195
        Some(v) => path_list(v, "allowed")?,
        // hlx:196
        None => return Err("malformed_policy: allowed is required".to_string()),
        // hlx:197
    };
    // hlx:198
    let required = match get(top, "required") {
        // hlx:199
        Some(v) => path_list(v, "required")?,
        // hlx:200
        None => Vec::new(),
        // hlx:201
    };
    // hlx:202
    let allow_set: BTreeSet<&str> = allowed.iter().map(String::as_str).collect();
    // hlx:203
    if required.iter().any(|r| !allow_set.contains(r.as_str())) {
        // hlx:204
        return Err("contradictory_policy: every required path must also be allowed".to_string());
        // hlx:205
    }
    // hlx:206
    let mut scope: Vec<(String, String)> = Vec::new();
    // hlx:207
    if let Some(s) = get(top, "scope") {
        // hlx:208
        for (k, v) in obj(s, "scope")? {
            // hlx:209
            match v {
                // hlx:210
                J::Str(v) => scope.push((k.clone(), v.clone())),
                // hlx:211
                _ => return Err("malformed_policy: scope values must be strings".to_string()),
                // hlx:212
            }
            // hlx:213
        }
        // hlx:214
    }
    // hlx:215
    let mut limits = Limits {
        entries: CEIL_ENTRIES,
        depth: CEIL_DEPTH,
        bytes: CEIL_BYTES,
    };
    // hlx:216
    if let Some(l) = get(top, "limits") {
        // hlx:217
        let lo = obj(l, "limits")?;
        // hlx:218
        only_keys(
            lo,
            &["max_entries", "max_depth", "max_inventory_bytes"],
            "limits",
        )?;
        // hlx:219
        limits.entries = limit(lo, "max_entries", CEIL_ENTRIES, CEIL_ENTRIES)?;
        // hlx:220
        limits.depth = limit(lo, "max_depth", CEIL_DEPTH, CEIL_DEPTH)?;
        // hlx:221
        limits.bytes = limit(lo, "max_inventory_bytes", CEIL_BYTES, CEIL_BYTES)?;
        // hlx:222
    }
    // hlx:223
    Ok(Policy {
        trusted,
        allowed,
        required,
        scope,
        limits,
    })
    // hlx:224
}
// hlx:225
fn check_text(id: &str, left: &str, right: &str, facts: &str, conds: bool, scope: &str) -> String {
    // hlx:226
    let conditions = if conds {
        "{\"complete-inventory\":true,\"explicit-policy\":true}"
    } else {
        "{}"
    };
    // hlx:227
    format!(
// hlx:228
"{{\"check\":{{\"schema\":\"instinct.check/v1\",\"id\":{},\"revision\":1,\"inputs\":{{{}:\"set<string>\",{}:\"set<string>\"}},\"claim\":{{\"op\":\"subset\",\"left\":{{\"fact\":{}}},\"right\":{{\"fact\":{}}}}},\"required_conditions\":[\"complete-inventory\",\"explicit-policy\"],\"scope\":{}}},\"facts\":{},\"conditions\":{},\"scope\":{}}}",
// hlx:229
jstr(id),
// hlx:230
jstr(left),
// hlx:231
jstr(right),
// hlx:232
jstr(left),
// hlx:233
jstr(right),
// hlx:234
scope,
// hlx:235
facts,
// hlx:236
conditions,
// hlx:237
scope
// hlx:238
)
    // hlx:239
}
// hlx:240
const ID_ALLOWED: &str = "artifact-actual-subset-allowed";
// hlx:241
const ID_REQUIRED: &str = "artifact-required-subset-actual";
// hlx:242
fn policy_facts(p: &Policy, which: u8) -> String {
    // hlx:243
    if which == 0 {
        // hlx:244
        format!("{{\"allowed\":{}}}", jlist(&p.allowed))
    // hlx:245
    } else {
        // hlx:246
        format!("{{\"required\":{}}}", jlist(&p.required))
        // hlx:247
    }
    // hlx:248
}
// hlx:249
fn preflight(p: &Policy) -> Result<(), String> {
    // hlx:250
    let scope = jscope(&p.scope);
    // hlx:251
    let a = check_text(
        ID_ALLOWED,
        "actual",
        "allowed",
        &policy_facts(p, 0),
        false,
        &scope,
    );
    // hlx:252
    let (out, err) = kernel::evaluate(Mode::Validate, a.as_bytes());
    // hlx:253
    if err {
        // hlx:254
        return Err(out);
        // hlx:255
    }
    // hlx:256
    if !p.required.is_empty() {
        // hlx:257
        let r = check_text(
            ID_REQUIRED,
            "required",
            "actual",
            &policy_facts(p, 1),
            false,
            &scope,
        );
        // hlx:258
        let (out, err) = kernel::evaluate(Mode::Validate, r.as_bytes());
        // hlx:259
        if err {
            // hlx:260
            return Err(out);
            // hlx:261
        }
        // hlx:262
    }
    // hlx:263
    Ok(())
    // hlx:264
}
// hlx:265
fn validate_root(root: &str) -> Result<PathBuf, String> {
    // hlx:266
    if root.is_empty() || root.contains('\0') {
        // hlx:267
        return Err("usage: --root must be a nonempty path".to_string());
        // hlx:268
    }
    // hlx:269
    let p = Path::new(root);
    // hlx:270
    if !p.is_absolute() {
        // hlx:271
        return Err("usage: --root must be an absolute path".to_string());
        // hlx:272
    }
    // hlx:273
    // Lexical check on the RAW string: Path::components() silently drops `.`, repeated and trailing separators, and the
    // hlx:274
    // OS resolves a trailing slash through a final symlink, so none of that may reach symlink_metadata.
    // hlx:275
    let sep = |c: char| c == '/' || (cfg!(windows) && c == '\\');
    // hlx:276
    // A filesystem root has no parent (including Windows drive/verbatim/UNC roots).
    // hlx:277
    // Still reject doubled trailing separators that components() would normalize away.
    // hlx:278
    let filesystem_root = p.parent().is_none()
// hlx:279
&& !root.strip_suffix(sep).is_some_and(|prefix| prefix.ends_with(sep));
    // hlx:280
    if root.len() > 1 && root.ends_with(sep) && !filesystem_root {
        // hlx:281
        return Err("usage: --root must not end with a separator".to_string());
        // hlx:282
    }
    // hlx:283
    if root
        .split(sep)
        .skip(1)
        .any(|c| c.is_empty() && root.len() > 1)
        && !cfg!(windows)
    {
        // hlx:284
        return Err("usage: --root must not contain empty components".to_string());
        // hlx:285
    }
    // hlx:286
    if root.split(sep).any(|c| c == "." || c == "..") {
        // hlx:287
        return Err("usage: --root must not contain . or .. components".to_string());
        // hlx:288
    }
    // hlx:289
    if p.components()
        .any(|c| matches!(c, Component::CurDir | Component::ParentDir))
    {
        // hlx:290
        return Err("usage: --root must not contain . or .. components".to_string());
        // hlx:291
    }
    // hlx:292
    Ok(p.to_path_buf())
    // hlx:293
}
// hlx:294
// Only macOS's fixed OS aliases are resolved, and only above the named root.
// hlx:295
// Arbitrary user-created ancestor symlinks remain rejected by root_meta.
// hlx:296
#[cfg(any(target_os = "macos", all(test, unix)))]
// hlx:297
fn system_alias_candidate(root: &Path) -> Option<(&'static str, &'static str, PathBuf)> {
    // hlx:298
    for (alias, target) in [
        ("/var", "/private/var"),
        ("/tmp", "/private/tmp"),
        ("/etc", "/private/etc"),
    ] {
        // hlx:299
        if let Ok(rest) = root.strip_prefix(alias) {
            // hlx:300
            if !rest.as_os_str().is_empty() {
                return Some((alias, target, Path::new(target).join(rest)));
            }
            // hlx:301
        }
        // hlx:302
    }
    // hlx:303
    None
    // hlx:304
}
// hlx:305
fn platform_root(root: PathBuf) -> Result<PathBuf, String> {
    // hlx:306
    #[cfg(target_os = "macos")]
    // hlx:307
    if let Some((alias, target, resolved)) = system_alias_candidate(&root) {
        // hlx:308
        let meta = std::fs::symlink_metadata(alias)
            .map_err(|_| "root_invalid: cannot inspect system ancestor")?;
        // hlx:309
        if meta.file_type().is_symlink() {
            // hlx:310
            let link = std::fs::read_link(alias)
                .map_err(|_| "root_invalid: cannot inspect system alias")?;
            // hlx:311
            let actual = if link.is_absolute() {
                link
            } else {
                Path::new("/").join(link)
            };
            // hlx:312
            if actual != Path::new(target) {
                return Err("root_invalid: unexpected system alias target".into());
            }
            // hlx:313
            return Ok(resolved);
            // hlx:314
        }
        // hlx:315
    }
    // hlx:316
    Ok(root)
    // hlx:317
}
// hlx:318
#[cfg(unix)]
// hlx:319
fn meta_of(m: &std::fs::Metadata) -> Meta {
    // hlx:320
    use std::os::unix::fs::MetadataExt;
    // hlx:321
    Meta {
        // hlx:322
        len: m.len(),
        // hlx:323
        stamp: [
            m.mtime(),
            m.mtime_nsec(),
            m.ctime(),
            m.ctime_nsec(),
            m.dev() as i64,
            m.ino() as i64,
        ],
        // hlx:324
        mode: m.mode(),
        // hlx:325
    }
    // hlx:326
}
// hlx:327
#[cfg(not(unix))]
// hlx:328
fn meta_of(m: &std::fs::Metadata) -> Meta {
    // hlx:329
    Meta {
        len: m.len(),
        stamp: [0; 6],
        mode: 0,
    }
    // hlx:330
}
// hlx:331
fn io_reason(what: &str, e: &std::io::Error) -> String {
    // hlx:332
    format!("{what}: {:?}", e.kind())
    // hlx:333
}
// hlx:334
fn root_meta(root: &Path) -> Result<Meta, Stop> {
    // hlx:335
    let comps: Vec<Component> = root.components().collect();
    // hlx:336
    let mut cur = PathBuf::new();
    // hlx:337
    for (i, c) in comps.iter().enumerate() {
        // hlx:338
        cur.push(c.as_os_str());
        // hlx:339
        if i + 1 == comps.len() || matches!(c, Component::RootDir | Component::Prefix(_)) {
            // hlx:340
            continue;
            // hlx:341
        }
        // hlx:342
        let am = std::fs::symlink_metadata(&cur)
            .map_err(|e| stop(&io_reason("root_unreadable", &e), None))?;
        // hlx:343
        if am.file_type().is_symlink() {
            // hlx:344
            return Err(stop("symlink_rejected: root_ancestor", None));
            // hlx:345
        }
        // hlx:346
    }
    // hlx:347
    let m = std::fs::symlink_metadata(root)
        .map_err(|e| stop(&io_reason("root_unreadable", &e), None))?;
    // hlx:348
    if m.file_type().is_symlink() {
        // hlx:349
        return Err(stop("symlink_rejected: root", None));
        // hlx:350
    }
    // hlx:351
    if !m.is_dir() {
        // hlx:352
        return Err(stop("root_not_directory", None));
        // hlx:353
    }
    // hlx:354
    Ok(meta_of(&m))
    // hlx:355
}
// hlx:356
/// One bounded traversal. Charges entry, depth and byte budgets before storing each entry.
// hlx:357
fn walk(root: &Path, lim: Limits, seen: &mut usize) -> Result<Snap, Stop> {
    // hlx:358
    let root_before = root_meta(root)?;
    // hlx:359
    let mut ents: Vec<Ent> = Vec::new();
    // hlx:360
    let mut bytes: u64 = 0;
    // hlx:361
    let mut pending: Vec<(String, u64)> = vec![(String::new(), 0)];
    // hlx:362
    while let Some((rel, depth)) = pending.pop() {
        // hlx:363
        let abs = if rel.is_empty() {
            root.to_path_buf()
        } else {
            root.join(&rel)
        };
        // hlx:364
        let shown = if rel.is_empty() { "." } else { rel.as_str() };
        // hlx:365
        let rd = std::fs::read_dir(&abs)
            .map_err(|e| stop(&io_reason("read_dir_failed", &e), Some(shown)))?;
        // hlx:366
        let mut names: Vec<String> = Vec::new();
        // hlx:367
        for item in rd {
            // hlx:368
            let item = item.map_err(|e| stop(&io_reason("read_dir_failed", &e), Some(shown)))?;
            // hlx:369
            let name = match item.file_name().into_string() {
                // hlx:370
                Ok(n) => n,
                // hlx:371
                Err(_) => return Err(stop("non_utf8_name", Some(shown))),
                // hlx:372
            };
            // hlx:373
            let child = if rel.is_empty() {
                name.clone()
            } else {
                format!("{rel}/{name}")
            };
            // hlx:374
            if ents.len() as u64 + names.len() as u64 + 1 > lim.entries {
                // hlx:375
                return Err(stop("budget_exceeded: max_entries", Some(&child)));
                // hlx:376
            }
            // hlx:377
            if depth + 1 > lim.depth {
                // hlx:378
                return Err(stop("budget_exceeded: max_depth", Some(&child)));
                // hlx:379
            }
            // hlx:380
            bytes += child.len() as u64 + META_ALLOWANCE;
            // hlx:381
            if bytes > lim.bytes {
                // hlx:382
                return Err(stop("budget_exceeded: max_inventory_bytes", Some(&child)));
                // hlx:383
            }
            // hlx:384
            names.push(name);
            // hlx:385
            *seen += 1;
            // hlx:386
        }
        // hlx:387
        names.sort();
        // hlx:388
        for name in names {
            // hlx:389
            let child = if rel.is_empty() {
                name.clone()
            } else {
                format!("{rel}/{name}")
            };
            // hlx:390
            let m = std::fs::symlink_metadata(abs.join(&name))
                .map_err(|e| stop(&io_reason("entry_unreadable", &e), Some(&child)))?;
            // hlx:391
            let ft = m.file_type();
            // hlx:392
            if ft.is_symlink() {
                // hlx:393
                return Err(stop("symlink_rejected", Some(&child)));
                // hlx:394
            }
            // hlx:395
            let dir = ft.is_dir();
            // hlx:396
            if !dir && !ft.is_file() {
                // hlx:397
                return Err(stop("unsupported_entry_kind", Some(&child)));
                // hlx:398
            }
            // hlx:399
            if dir {
                // hlx:400
                pending.push((child.clone(), depth + 1));
                // hlx:401
            }
            // hlx:402
            ents.push(Ent {
                path: child,
                dir,
                meta: meta_of(&m),
            });
            // hlx:403
        }
        // hlx:404
    }
    // hlx:405
    ents.sort_by(|a, b| a.path.cmp(&b.path));
    // hlx:406
    let root_after = root_meta(root)?;
    // hlx:407
    Ok(Snap {
        root_before,
        root_after,
        ents,
    })
    // hlx:408
}
// hlx:409
fn first_difference(a: &Snap, b: &Snap) -> String {
    // hlx:410
    for (x, y) in a.ents.iter().zip(b.ents.iter()) {
        // hlx:411
        if x != y {
            // hlx:412
            return x.path.clone();
            // hlx:413
        }
        // hlx:414
    }
    // hlx:415
    if a.ents.len() > b.ents.len() {
        // hlx:416
        return a.ents[b.ents.len()].path.clone();
        // hlx:417
    }
    // hlx:418
    if b.ents.len() > a.ents.len() {
        // hlx:419
        return b.ents[a.ents.len()].path.clone();
        // hlx:420
    }
    // hlx:421
    ".".to_string()
    // hlx:422
}
// hlx:423
fn limits_json(l: Limits) -> String {
    // hlx:424
    format!(
// hlx:425
"{{\"max_entries\":{},\"max_depth\":{},\"max_inventory_bytes\":{},\"metadata_allowance_bytes\":{}}}",
// hlx:426
l.entries, l.depth, l.bytes, META_ALLOWANCE
// hlx:427
)
    // hlx:428
}
// hlx:429
fn incomplete(p: &Policy, reason: &str, witness: Option<&str>, visited: usize) -> String {
    // hlx:430
    let w = match witness {
        // hlx:431
        Some(w) => format!(",\"witness\":{}", jstr(w)),
        // hlx:432
        None => String::new(),
        // hlx:433
    };
    // hlx:434
    format!(
// hlx:435
"{{\"schema\":\"instinct.artifact-observation/v1\",\"adapter\":\"artifact-inventory/v1\",\"validity\":\"incomplete\",\"evidence_origin\":\"adapter_observed\",\"authorization\":\"not_evaluated\",\"reason\":{}{},\"assumptions\":{{\"trusted_quiescent_staging\":{}}},\"scope\":{},\"inventory\":[],\"checks\":[],\"limits\":{},\"visited_entries\":{}}}",
// hlx:436
jstr(reason),
// hlx:437
w,
// hlx:438
p.trusted,
// hlx:439
jscope(&p.scope),
// hlx:440
limits_json(p.limits),
// hlx:441
visited
// hlx:442
)
    // hlx:443
}
// hlx:444
fn observed(p: &Policy, snap: &Snap) -> Result<String, String> {
    // hlx:445
    let actual: Vec<String> = snap.ents.iter().map(|e| e.path.clone()).collect();
    // hlx:446
    let scope = jscope(&p.scope);
    // hlx:447
    let mut checks: Vec<String> = Vec::new();
    // hlx:448
    let a = check_text(
        ID_ALLOWED,
        "actual",
        "allowed",
        &format!(
            "{{\"actual\":{},\"allowed\":{}}}",
            jlist(&actual),
            jlist(&p.allowed)
        ),
        true,
        &scope,
    );
    // hlx:449
    let (out, err) = kernel::evaluate(Mode::Run, a.as_bytes());
    // hlx:450
    if err {
        // hlx:451
        return Err(out);
        // hlx:452
    }
    // hlx:453
    checks.push(format!("{{\"name\":\"actual_subset_allowed\",\"provenance\":{{\"actual\":\"adapter_observed\",\"allowed\":\"caller_policy\"}},\"result\":{out}}}"));
    // hlx:454
    if !p.required.is_empty() {
        // hlx:455
        let r = check_text(
            ID_REQUIRED,
            "required",
            "actual",
            &format!(
                "{{\"required\":{},\"actual\":{}}}",
                jlist(&p.required),
                jlist(&actual)
            ),
            true,
            &scope,
        );
        // hlx:456
        let (out, err) = kernel::evaluate(Mode::Run, r.as_bytes());
        // hlx:457
        if err {
            // hlx:458
            return Err(out);
            // hlx:459
        }
        // hlx:460
        checks.push(format!("{{\"name\":\"required_subset_actual\",\"provenance\":{{\"required\":\"caller_policy\",\"actual\":\"adapter_observed\"}},\"result\":{out}}}"));
        // hlx:461
    }
    // hlx:462
    let inv: Vec<String> = snap
        // hlx:463
        .ents
        // hlx:464
        .iter()
        // hlx:465
        .map(|e| {
            format!(
                "{{\"path\":{},\"kind\":\"{}\"}}",
                jstr(&e.path),
                if e.dir { "directory" } else { "file" }
            )
        })
        // hlx:466
        .collect();
    // hlx:467
    Ok(format!(
// hlx:468
"{{\"schema\":\"instinct.artifact-observation/v1\",\"adapter\":\"artifact-inventory/v1\",\"validity\":\"observed_snapshot\",\"evidence_origin\":\"adapter_observed\",\"authorization\":\"not_evaluated\",\"reason\":\"inventory_observed_under_caller_assumption\",\"assumptions\":{{\"trusted_quiescent_staging\":true}},\"scope\":{},\"inventory\":[{}],\"checks\":[{}],\"limits\":{},\"visited_entries\":{}}}",
// hlx:469
scope,
// hlx:470
inv.join(","),
// hlx:471
checks.join(","),
// hlx:472
limits_json(p.limits),
// hlx:473
snap.ents.len()
// hlx:474
))
    // hlx:475
}
// hlx:476
/// Core entry. `between` runs after pass one and before pass two: an internal test seam only, never wired to the CLI.
// hlx:477
fn observe_inner(root: &str, policy: &[u8], between: &mut dyn FnMut()) -> (String, bool) {
    // hlx:478
    let root = match validate_root(root) {
        // hlx:479
        Ok(r) => r,
        // hlx:480
        Err(e) => return (kernel::error_json(&e), true),
        // hlx:481
    };
    // hlx:482
    let p = match parse_policy(policy) {
        // hlx:483
        Ok(p) => p,
        // hlx:484
        Err(e) => return (kernel::error_json(&e), true),
        // hlx:485
    };
    // hlx:486
    if let Err(e) = preflight(&p) {
        // hlx:487
        return (e, true);
        // hlx:488
    }
    // hlx:489
    if !p.trusted {
        // hlx:490
        return (
            incomplete(
                &p,
                "assumption_not_asserted: trusted_quiescent_staging",
                None,
                0,
            ),
            false,
        );
        // hlx:491
    }
    // hlx:492
    if cfg!(not(unix)) {
        // hlx:493
        return (
            incomplete(
                &p,
                "unsupported_platform: inventory observation is implemented for Unix only",
                None,
                0,
            ),
            false,
        );
        // hlx:494
    }
    // hlx:495
    let root = match platform_root(root) {
        Ok(root) => root,
        Err(e) => return (kernel::error_json(&e), true),
    };
    // hlx:496
    let mut seen1 = 0usize;
    // hlx:497
    let first = match walk(&root, p.limits, &mut seen1) {
        // hlx:498
        Ok(s) => s,
        // hlx:499
        Err(s) => {
            // hlx:500
            if s.reason.starts_with("root_unreadable")
                || s.reason == "root_not_directory"
                || s.reason.starts_with("symlink_rejected: root")
            {
                // hlx:501
                return (
                    kernel::error_json(&format!("root_invalid: {}", s.reason)),
                    true,
                );
                // hlx:502
            }
            // hlx:503
            return (
                incomplete(&p, &s.reason, s.witness.as_deref(), seen1),
                false,
            );
            // hlx:504
        } // hlx:505
    };
    // hlx:506
    between();
    // hlx:507
    let second = match walk(&root, p.limits, &mut 0usize) {
        // hlx:508
        Ok(s) => s,
        // hlx:509
        Err(s) => {
            return (
                incomplete(
                    &p,
                    &format!("changed_during_observation: {}", s.reason),
                    s.witness.as_deref(),
                    first.ents.len(),
                ),
                false,
            )
        } // hlx:510
    };
    // hlx:511
    if first != second {
        // hlx:512
        let w = first_difference(&first, &second);
        // hlx:513
        return (
            incomplete(
                &p,
                "changed_during_observation: inventory or metadata differs between passes",
                Some(&w),
                first.ents.len(),
            ),
            false,
        );
        // hlx:514
    }
    // hlx:515
    let out = match observed(&p, &first) {
        // hlx:516
        Ok(o) => o,
        // hlx:517
        Err(e) => return (e, true),
        // hlx:518
    };
    // hlx:519
    (out, false)
    // hlx:520
}
// hlx:521
/// Every result path (errors, incomplete, abstain, observed) goes through this one output bound. No silent truncation.
// hlx:522
fn observe_with(root: &str, policy: &[u8], between: &mut dyn FnMut()) -> (String, bool) {
    // hlx:523
    let (out, is_error) = observe_inner(root, policy, between);
    // hlx:524
    if out.len() > kernel::MAX_OUTPUT_BYTES {
        // hlx:525
        return (
            kernel::error_json("limit_exceeded: observation result exceeds 65536 bytes"),
            true,
        );
        // hlx:526
    }
    // hlx:527
    (out, is_error)
    // hlx:528
}
// hlx:529
pub fn observe(root: &str, policy: &[u8]) -> (String, bool) {
    // hlx:530
    observe_with(root, policy, &mut || {})
    // hlx:531
}
// hlx:532
fn usage_error(why: &str) -> i32 {
    // hlx:533
    println!("{}", kernel::error_json(&format!("usage: {why}")));
    // hlx:534
    2
    // hlx:535
}
// hlx:536
/// `instinct check observe ...` (args after `observe`). Returns the process exit code.
// hlx:537
pub fn cli(args: &[String]) -> i32 {
    // hlx:538
    if args.len() == 1 && (args[0] == "--help" || args[0] == "-h") {
        // hlx:539
        println!("{OBSERVE_USAGE}");
        // hlx:540
        return 0;
        // hlx:541
    }
    // hlx:542
    let mut root: Option<String> = None;
    // hlx:543
    let mut input: Option<String> = None;
    // hlx:544
    let mut i = 0;
    // hlx:545
    while i < args.len() {
        // hlx:546
        let a = &args[i];
        // hlx:547
        let (slot, name, value) = if a == "--root" || a == "--input" {
            // hlx:548
            i += 1;
            // hlx:549
            match args.get(i) {
                // hlx:550
                Some(v) if v == "-" || !v.starts_with("--") => (
                    if a == "--root" { &mut root } else { &mut input },
                    a.as_str(),
                    v.clone(),
                ),
                // hlx:551
                _ => return usage_error(&format!("{a} needs a value")),
                // hlx:552
            }
        // hlx:553
        } else if let Some(v) = a.strip_prefix("--root=") {
            // hlx:554
            (&mut root, "--root", v.to_string())
        // hlx:555
        } else if let Some(v) = a.strip_prefix("--input=") {
            // hlx:556
            (&mut input, "--input", v.to_string())
        // hlx:557
        } else if a.starts_with('-') && a != "-" {
            // hlx:558
            return usage_error("unknown option (observe accepts only --root and --input)");
        // hlx:559
        } else {
            // hlx:560
            return usage_error("unexpected positional argument");
            // hlx:561
        };
        // hlx:562
        if slot.is_some() {
            // hlx:563
            return usage_error(&format!("{name} given more than once"));
            // hlx:564
        }
        // hlx:565
        *slot = Some(value);
        // hlx:566
        i += 1;
        // hlx:567
    }
    // hlx:568
    let root = match root {
        // hlx:569
        Some(r) if !r.is_empty() => r,
        // hlx:570
        _ => return usage_error("--root ABSOLUTE_DIR is required"),
        // hlx:571
    };
    // hlx:572
    let input = match input {
        // hlx:573
        Some(p) if !p.is_empty() => p,
        // hlx:574
        _ => return usage_error("--input FILE|- is required"),
        // hlx:575
    };
    // hlx:576
    let bytes = match super::read_input(&input) {
        // hlx:577
        Ok(b) => b,
        // hlx:578
        Err(e) => {
            // hlx:579
            println!("{}", kernel::error_json(&e));
            // hlx:580
            return 2;
            // hlx:581
        } // hlx:582
    };
    // hlx:583
    let (out, is_error) = observe(&root, &bytes);
    // hlx:584
    println!("{out}");
    // hlx:585
    if is_error {
        // hlx:586
        2
    // hlx:587
    } else {
        // hlx:588
        0
        // hlx:589
    }
    // hlx:590
}
// hlx:591
#[cfg(all(test, unix))]
// hlx:592
mod tests {
    // hlx:593
    use super::*;
    // hlx:594
    use std::sync::atomic::{AtomicUsize, Ordering};
    // hlx:595
    static N: AtomicUsize = AtomicUsize::new(0);
    // hlx:596
    fn tmp() -> PathBuf {
        // hlx:597
        let d = std::env::temp_dir().join(format!(
            "instinct-observe-{}-{}",
            std::process::id(),
            N.fetch_add(1, Ordering::SeqCst)
        ));
        // hlx:598
        std::fs::create_dir_all(&d).unwrap();
        // hlx:599
        d
        // hlx:600
    }
    // hlx:601
    fn put(root: &Path, rel: &str) {
        // hlx:602
        let p = root.join(rel);
        // hlx:603
        std::fs::create_dir_all(p.parent().unwrap()).unwrap();
        // hlx:604
        std::fs::write(p, b"x").unwrap();
        // hlx:605
    }
    // hlx:606
    fn run(root: &Path, policy: &str) -> (String, bool) {
        // hlx:607
        observe(root.to_str().unwrap(), policy.as_bytes())
        // hlx:608
    }
    // hlx:609
    fn pol(allowed: &str, required: &str, extra: &str) -> String {
        // hlx:610
        format!("{{\"schema\":\"instinct.artifact-policy/v1\",\"assumptions\":{{\"trusted_quiescent_staging\":true}},\"allowed\":{allowed},\"required\":{required}{extra}}}")
        // hlx:611
    }
    // hlx:612
    #[test]
    // hlx:613
    fn fixed_system_alias_mapping_is_component_bounded() {
        // hlx:614
        assert_eq!(
            system_alias_candidate(Path::new("/var/folders/x"))
                .unwrap()
                .2,
            PathBuf::from("/private/var/folders/x")
        );
        // hlx:615
        assert!(system_alias_candidate(Path::new("/var")).is_none());
        // hlx:616
        assert!(system_alias_candidate(Path::new("/var-other/x")).is_none());
        // hlx:617
        assert!(system_alias_candidate(Path::new("/home/user/link/x")).is_none());
        // hlx:618
    }
    // hlx:619
    #[cfg(target_os = "macos")]
    // hlx:620
    #[test]
    // hlx:621
    fn macos_system_temp_alias_works_but_user_links_do_not() {
        // hlx:622
        let r = tmp();
        put(&r, "a");
        // hlx:623
        let canonical = std::fs::canonicalize(&r).unwrap();
        // hlx:624
        let alias = canonical
            .to_string_lossy()
            .replacen("/private/var/", "/var/", 1)
            .replacen("/private/tmp/", "/tmp/", 1);
        // hlx:625
        let (out, error) = observe(&alias, pol("[\"a\"]", "[]", "").as_bytes());
        // hlx:626
        assert!(!error && out.contains("observed_snapshot"), "{out}");
        // hlx:627
        std::os::unix::fs::symlink(&r, r.join("link")).unwrap();
        // hlx:628
        let (out, error) = observe(
            r.join("link").to_str().unwrap(),
            pol("[\"a\"]", "[]", "").as_bytes(),
        );
        // hlx:629
        assert!(error && out.contains("symlink_rejected"), "{out}");
        // hlx:630
    }
    // hlx:631
    #[test]
    // hlx:632
    fn clean_tree_passes_with_names_and_kinds() {
        // hlx:633
        let r = tmp();
        // hlx:634
        put(&r, "docs/README");
        // hlx:635
        put(&r, "release.bin");
        // hlx:636
        put(&r, "my file \u{e9}.txt");
        // hlx:637
        let (o, e) = run(
            &r,
            &pol(
                "[\"docs\",\"docs/README\",\"release.bin\",\"my file \u{e9}.txt\"]",
                "[\"release.bin\"]",
                "",
            ),
        );
        // hlx:638
        assert!(!e, "{o}");
        // hlx:639
        assert!(o.contains("\"validity\":\"observed_snapshot\""), "{o}");
        // hlx:640
        assert!(
            o.contains("{\"path\":\"docs\",\"kind\":\"directory\"}"),
            "{o}"
        );
        // hlx:641
        assert!(
            o.contains("{\"path\":\"my file \u{e9}.txt\",\"kind\":\"file\"}"),
            "{o}"
        );
        // hlx:642
        assert_eq!(o.matches("\"verdict\":\"pass\"").count(), 2, "{o}");
        // hlx:643
        assert!(o.contains("\"assumptions\":{\"trusted_quiescent_staging\":true}"));
        // hlx:644
        assert!(
            !o.contains(r.to_str().unwrap()),
            "absolute root must not be echoed"
        );
        // hlx:645
    }
    // hlx:646
    #[test]
    // hlx:647
    fn empty_root_is_complete_empty_inventory() {
        // hlx:648
        let r = tmp();
        // hlx:649
        let (o, e) = run(&r, &pol("[]", "[]", ""));
        // hlx:650
        assert!(
            !e && o.contains("\"inventory\":[]")
                && o.contains("observed_snapshot")
                && o.contains("\"verdict\":\"pass\""),
            "{o}"
        );
        // hlx:651
    }
    // hlx:652
    #[test]
    // hlx:653
    fn hidden_extra_file_fails_membership_with_witness() {
        // hlx:654
        let r = tmp();
        // hlx:655
        put(&r, "release.bin");
        // hlx:656
        put(&r, ".env");
        // hlx:657
        let (o, e) = run(&r, &pol("[\"release.bin\"]", "[]", ""));
        // hlx:658
        assert!(
            !e && o.contains("\"verdict\":\"fail\"") && o.contains("\"witness\":\".env\""),
            "{o}"
        );
        // hlx:659
    }
    // hlx:660
    #[test]
    // hlx:661
    fn missing_required_fails_separate_check() {
        // hlx:662
        let r = tmp();
        // hlx:663
        put(&r, "a");
        // hlx:664
        let (o, e) = run(&r, &pol("[\"a\",\"b\"]", "[\"b\"]", ""));
        // hlx:665
        assert!(!e, "{o}");
        // hlx:666
        assert!(
            o.contains("\"name\":\"required_subset_actual\"") && o.contains("\"witness\":\"b\""),
            "{o}"
        );
        // hlx:667
    }
    // hlx:668
    #[test]
    // hlx:669
    fn missing_or_false_assumption_abstains_before_traversal() {
        // hlx:670
        let bad = "/nonexistent-instinct-observe-root";
        // hlx:671
        for p in [
// hlx:672
"{\"schema\":\"instinct.artifact-policy/v1\",\"allowed\":[]}",
// hlx:673
"{\"schema\":\"instinct.artifact-policy/v1\",\"assumptions\":{\"trusted_quiescent_staging\":false},\"allowed\":[]}",
// hlx:674
] {
// hlx:675
let (o, e) = observe(bad, p.as_bytes());
// hlx:676
assert!(!e && o.contains("\"validity\":\"incomplete\"") && o.contains("assumption_not_asserted"), "{o}");
// hlx:677
assert!(o.contains("\"inventory\":[]") && o.contains("\"checks\":[]"), "{o}");
// hlx:678
}
        // hlx:679
    }
    // hlx:680
    #[test]
    // hlx:681
    fn policy_errors_are_rejected_before_observation() {
        // hlx:682
        let r = tmp();
        // hlx:683
        let cases = [
            // hlx:684
            pol("[\"../x\"]", "[]", ""),
            // hlx:685
            pol("[\"/abs\"]", "[]", ""),
            // hlx:686
            pol("[\"a//b\"]", "[]", ""),
            // hlx:687
            pol("[\"a/\"]", "[]", ""),
            // hlx:688
            pol("[\"a/./b\"]", "[]", ""),
            // hlx:689
            pol("[\"C:\\\\x\"]", "[]", ""),
            // hlx:690
            pol("[\"\\\\\\\\srv\\\\share\"]", "[]", ""),
            // hlx:691
            pol("[\"a\",\"a\"]", "[]", ""),
            // hlx:692
            pol("[\"a\"]", "[\"b\"]", ""),
            // hlx:693
            pol("[\"a\"]", "[]", ",\"scope\":{\"bogus\":\"x\"}"),
            // hlx:694
            pol("[\"a\"]", "[]", ",\"scope\":{\"project\":\"\"}"),
            // hlx:695
            pol("[\"a\"]", "[]", ",\"limits\":{\"max_entries\":10001}"),
            // hlx:696
            pol("[\"a\"]", "[]", ",\"limits\":{\"max_depth\":1.5}"),
            // hlx:697
            pol("[\"a\"]", "[]", ",\"limits\":{\"max_depth\":-1}"),
            // hlx:698
            pol("[\"a\"]", "[]", ",\"extra\":1"),
            // hlx:699
            "{\"schema\":\"instinct.artifact-policy/v1\",\"allowed\":[],\"allowed\":[]}"
                .to_string(),
            // hlx:700
            "{\"schema\":\"wrong\",\"allowed\":[]}".to_string(),
            // hlx:701
        ];
        // hlx:702
        for c in cases {
            // hlx:703
            let (o, e) = run(&r, &c);
            // hlx:704
            assert!(
                e && o.contains("instinct.check-error/v1"),
                "accepted {c}: {o}"
            );
            // hlx:705
        }
        // hlx:706
        assert!(
            std::fs::read_dir(&r).unwrap().next().is_none(),
            "root untouched"
        );
        // hlx:707
    }
    // hlx:708
    #[test]
    // hlx:709
    fn relative_or_missing_root_is_an_error() {
        // hlx:710
        let p = pol("[]", "[]", "");
        // hlx:711
        assert!(observe("relative/dir", p.as_bytes()).1);
        // hlx:712
        assert!(observe("/nonexistent-instinct-observe-root", p.as_bytes()).1);
        // hlx:713
        let r = tmp();
        // hlx:714
        put(&r, "f");
        // hlx:715
        assert!(observe(r.join("f").to_str().unwrap(), p.as_bytes()).1);
        // hlx:716
    }
    // hlx:717
    #[cfg(unix)]
    // hlx:718
    #[test]
    // hlx:719
    fn symlink_abstains_without_target_disclosure() {
        // hlx:720
        let r = tmp();
        // hlx:721
        let outside = tmp();
        // hlx:722
        put(&outside, "secret-target-name");
        // hlx:723
        std::os::unix::fs::symlink(&outside, r.join("link")).unwrap();
        // hlx:724
        let (o, e) = run(&r, &pol("[\"link\"]", "[]", ""));
        // hlx:725
        assert!(
            !e && o.contains("\"validity\":\"incomplete\"")
                && o.contains("symlink_rejected")
                && o.contains("\"witness\":\"link\""),
            "{o}"
        );
        // hlx:726
        assert!(
            !o.contains("secret-target-name") && !o.contains(outside.to_str().unwrap()),
            "{o}"
        );
        // hlx:727
        assert!(o.contains("\"inventory\":[]") && o.contains("\"checks\":[]"));
        // hlx:728
        let rl = tmp();
        // hlx:729
        std::os::unix::fs::symlink(&r, rl.join("rootlink")).unwrap();
        // hlx:730
        let (o, e) = run(&rl.join("rootlink"), &pol("[]", "[]", ""));
        // hlx:731
        assert!(e && o.contains("root_invalid"), "{o}");
        // hlx:732
    }
    // hlx:733
    #[cfg(unix)]
    // hlx:734
    #[test]
    // hlx:735
    fn symlinked_root_ancestor_is_rejected_before_enumeration() {
        // hlx:736
        let real = tmp();
        // hlx:737
        put(&real, "stage/release.bin");
        // hlx:738
        let base = tmp();
        // hlx:739
        std::os::unix::fs::symlink(&real, base.join("alias")).unwrap();
        // hlx:740
        let p = pol("[\"release.bin\"]", "[]", "");
        // hlx:741
        let (o, e) = run(&base.join("alias").join("stage"), &p);
        // hlx:742
        assert!(
            e && o.contains("root_invalid") && o.contains("root_ancestor"),
            "{o}"
        );
        // hlx:743
        assert!(
            !o.contains("release.bin") && !o.contains(real.to_str().unwrap()),
            "{o}"
        );
        // hlx:744
        let (o, e) = run(&real.join("stage"), &p);
        // hlx:745
        assert!(!e && o.contains("observed_snapshot"), "{o}");
        // hlx:746
        let np = "{\"schema\":\"instinct.artifact-policy/v1\",\"allowed\":[]}";
        // hlx:747
        let (o, e) = observe(
            base.join("alias").join("stage").to_str().unwrap(),
            np.as_bytes(),
        );
        // hlx:748
        assert!(
            !e && o.contains("assumption_not_asserted") && o.contains("\"inventory\":[]"),
            "{o}"
        );
        // hlx:749
    }
    // hlx:750
    #[test]
    // hlx:751
    fn oversized_result_on_every_path_is_a_bounded_error() {
        // hlx:752
        let big = "p".repeat(90000);
        // hlx:753
        let np = format!("{{\"schema\":\"instinct.artifact-policy/v1\",\"allowed\":[],\"scope\":{{\"project\":\"{big}\"}}}}");
        // hlx:754
        let (o, e) = observe("/nonexistent-instinct-observe-root", np.as_bytes());
        // hlx:755
        assert!(
            e && o.len() < 1000 && o.contains("limit_exceeded") && !o.contains("pppp"),
            "{}",
            o.len()
        );
        // hlx:756
        let r = tmp();
        // hlx:757
        let tp = format!("{{\"schema\":\"instinct.artifact-policy/v1\",\"assumptions\":{{\"trusted_quiescent_staging\":true}},\"allowed\":[],\"scope\":{{\"project\":\"{big}\"}}}}");
        // hlx:758
        let (o, e) = run(&r, &tp);
        // hlx:759
        assert!(
            e && o.contains("limit_exceeded") && o.len() < 1000,
            "{}",
            o.len()
        );
        // hlx:760
    }
    // hlx:761
    #[cfg(unix)]
    // hlx:762
    #[test]
    // hlx:763
    fn root_spelling_variants_cannot_bypass_the_symlink_rule() {
        // hlx:764
        let real = tmp();
        // hlx:765
        put(&real, "f");
        // hlx:766
        let base = tmp();
        // hlx:767
        std::os::unix::fs::symlink(&real, base.join("rl")).unwrap();
        // hlx:768
        let p = pol("[\"f\"]", "[]", "");
        // hlx:769
        let rl = base.join("rl").to_str().unwrap().to_string();
        // hlx:770
        let rs = real.to_str().unwrap().to_string();
        // hlx:771
        for bad in [
            rl.clone(),
            format!("{rl}/"),
            format!("{rl}//"),
            format!("{rl}/."),
            format!("{rl}/./"),
            format!("{}/./{}", base.to_str().unwrap(), "rl"),
            format!("{rs}/"),
            format!("{rs}//"),
            format!("{rs}/."),
            format!("{rs}/../{}", real.file_name().unwrap().to_str().unwrap()),
            format!("/./{}", &rs[1..]),
            rs.replacen('/', "//", 1),
        ] {
            // hlx:772
            let (o, e) = observe(&bad, p.as_bytes());
            // hlx:773
            assert!(
                e && o.contains("instinct.check-error/v1") && !o.contains("observed_snapshot"),
                "accepted {bad}: {o}"
            );
            // hlx:774
        }
        // hlx:775
        let (o, e) = observe(&rs, p.as_bytes());
        // hlx:776
        assert!(!e && o.contains("observed_snapshot"), "{o}");
        // hlx:777
    }
    // hlx:778
    #[cfg(unix)]
    // hlx:779
    #[test]
    // hlx:780
    fn non_utf8_name_abstains() {
        // hlx:781
        use std::os::unix::ffi::OsStrExt;
        // hlx:782
        let r = tmp();
        // hlx:783
        if let Err(e) = std::fs::write(r.join(std::ffi::OsStr::from_bytes(b"bad\xff")), b"x") {
            // hlx:784
            if cfg!(target_os = "macos") && e.raw_os_error() == Some(92) {
                // hlx:785
                eprintln!("SKIP non-UTF-8 fixture: this macOS filesystem rejects the name (EILSEQ); observation not exercised");
                // hlx:786
                std::fs::remove_dir(&r).unwrap();
                // hlx:787
                return;
                // hlx:788
            }
            // hlx:789
            panic!("cannot create raw-name fixture: {e}");
            // hlx:790
        }
        // hlx:791
        let (o, e) = run(&r, &pol("[]", "[]", ""));
        // hlx:792
        assert!(
            !e && o.contains("non_utf8_name") && o.contains("\"validity\":\"incomplete\""),
            "{o}"
        );
        // hlx:793
    }
    // hlx:794
    #[cfg(unix)]
    // hlx:795
    #[test]
    // hlx:796
    fn socket_is_unsupported_entry() {
        // hlx:797
        let r = tmp();
        // hlx:798
        let _l = std::os::unix::net::UnixListener::bind(r.join("sock")).unwrap();
        // hlx:799
        let (o, e) = run(&r, &pol("[\"sock\"]", "[]", ""));
        // hlx:800
        assert!(!e && o.contains("unsupported_entry_kind"), "{o}");
        // hlx:801
    }
    // hlx:802
    #[cfg(unix)]
    // hlx:803
    #[test]
    // hlx:804
    fn unreadable_directory_abstains() {
        // hlx:805
        use std::os::unix::fs::PermissionsExt;
        // hlx:806
        let r = tmp();
        // hlx:807
        put(&r, "d/inner");
        // hlx:808
        let d = r.join("d");
        // hlx:809
        std::fs::set_permissions(&d, std::fs::Permissions::from_mode(0o000)).unwrap();
        // hlx:810
        if std::fs::read_dir(&d).is_ok() {
            // hlx:811
            std::fs::set_permissions(&d, std::fs::Permissions::from_mode(0o755)).unwrap();
            // hlx:812
            return; // running with privileges that bypass permissions; cannot exercise
                    // hlx:813
        }
        // hlx:814
        let (o, e) = run(&r, &pol("[\"d\",\"d/inner\"]", "[]", ""));
        // hlx:815
        std::fs::set_permissions(&d, std::fs::Permissions::from_mode(0o755)).unwrap();
        // hlx:816
        assert!(
            !e && o.contains("read_dir_failed")
                && o.contains("\"validity\":\"incomplete\"")
                && o.contains("\"checks\":[]"),
            "{o}"
        );
        // hlx:817
    }
    // hlx:818
    #[test]
    // hlx:819
    fn mutation_between_passes_abstains() {
        // hlx:820
        let r = tmp();
        // hlx:821
        put(&r, "a");
        // hlx:822
        let p = pol("[\"a\",\"late\"]", "[]", "");
        // hlx:823
        let rc = r.clone();
        // hlx:824
        let (o, e) = observe_with(r.to_str().unwrap(), p.as_bytes(), &mut || put(&rc, "late"));
        // hlx:825
        assert!(
            !e && o.contains("changed_during_observation")
                && o.contains("\"witness\":\"late\"")
                && o.contains("\"inventory\":[]"),
            "{o}"
        );
        // hlx:826
        let rc = r.clone();
        // hlx:827
        let (o, _) = observe_with(r.to_str().unwrap(), p.as_bytes(), &mut || {
            // hlx:828
            std::fs::write(rc.join("a"), b"longer content").unwrap();
            // hlx:829
        });
        // hlx:830
        assert!(
            o.contains("changed_during_observation") && o.contains("\"witness\":\"a\""),
            "{o}"
        );
        // hlx:831
    }
    // hlx:832
    #[test]
    // hlx:833
    fn budgets_terminate_without_partial_pass() {
        // hlx:834
        let r = tmp();
        // hlx:835
        for n in 0..5 {
            // hlx:836
            put(&r, &format!("f{n}"));
            // hlx:837
        }
        // hlx:838
        let all = "[\"f0\",\"f1\",\"f2\",\"f3\",\"f4\"]";
        // hlx:839
        let (o, e) = run(&r, &pol(all, "[]", ",\"limits\":{\"max_entries\":3}"));
        // hlx:840
        assert!(
            !e && o.contains("budget_exceeded: max_entries")
                && !o.contains("\"verdict\"")
                && o.contains("\"inventory\":[]"),
            "{o}"
        );
        // hlx:841
        let (o, _) = run(
            &r,
            &pol(all, "[]", ",\"limits\":{\"max_inventory_bytes\":100}"),
        );
        // hlx:842
        assert!(o.contains("budget_exceeded: max_inventory_bytes"), "{o}");
        // hlx:843
        let d = tmp();
        // hlx:844
        put(&d, "a/b/c");
        // hlx:845
        let (o, _) = run(
            &d,
            &pol(
                "[\"a\",\"a/b\",\"a/b/c\"]",
                "[]",
                ",\"limits\":{\"max_depth\":2}",
            ),
        );
        // hlx:846
        assert!(
            o.contains("budget_exceeded: max_depth") && o.contains("\"witness\":\"a/b/c\""),
            "{o}"
        );
        // hlx:847
        let (o, _) = run(
            &d,
            &pol(
                "[\"a\",\"a/b\",\"a/b/c\"]",
                "[]",
                ",\"limits\":{\"max_depth\":3}",
            ),
        );
        // hlx:848
        assert!(o.contains("observed_snapshot"), "{o}");
        // hlx:849
    }
    // hlx:850
    #[test]
    // hlx:851
    fn scope_mismatch_is_delegated_to_kernel_abstain() {
        // hlx:852
        let r = tmp();
        // hlx:853
        put(&r, "a");
        // hlx:854
        let (o, e) = run(
            &r,
            &pol("[\"a\"]", "[]", ",\"scope\":{\"project\":\"release-lab\"}"),
        );
        // hlx:855
        assert!(
            !e && o.contains("\"scope\":{\"project\":\"release-lab\"}")
                && o.contains("\"verdict\":\"pass\""),
            "{o}"
        );
        // hlx:856
    }
    // hlx:857
    #[test]
    // hlx:858
    fn cli_arg_errors() {
        // hlx:859
        let s = |v: &[&str]| v.iter().map(|x| x.to_string()).collect::<Vec<_>>();
        // hlx:860
        assert_eq!(cli(&s(&["--help"])), 0);
        // hlx:861
        assert_eq!(cli(&s(&[])), 2);
        // hlx:862
        assert_eq!(cli(&s(&["--root", "/x"])), 2);
        // hlx:863
        assert_eq!(cli(&s(&["--input", "-"])), 2);
        // hlx:864
        assert_eq!(
            cli(&s(&["--root", "/x", "--root", "/y", "--input", "-"])),
            2
        );
        // hlx:865
        assert_eq!(cli(&s(&["--root", "/x", "--input", "-", "extra"])), 2);
        // hlx:866
        assert_eq!(cli(&s(&["--root", "/x", "--input", "-", "--bogus"])), 2);
        // hlx:867
    }
    // hlx:868
}