Spaces:
Runtime error

File size: 55,316 Bytes
56c0d82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Validate Aureon's repo navigation and SaaS-access contract."""

from __future__ import annotations

import json
import re
import subprocess
import sys
from pathlib import Path
from urllib.parse import unquote


REPO_ROOT = Path(__file__).resolve().parents[2]

DOCS_REPO_SITEMAP = REPO_ROOT / "docs" / "repo_sitemap.json"
DOCS_ACCESS_MAP = REPO_ROOT / "docs" / "end_user_access_map.json"
DOCS_CAPABILITY_ACCESS_MATRIX = REPO_ROOT / "docs" / "capability_access_matrix.json"
DOCS_CAPABILITY_REGISTRY = REPO_ROOT / "docs" / "capability_registry.json"
DOCS_NAVIGATION_INDEX = REPO_ROOT / "docs" / "repo_navigation_index.json"
DOCS_ORGANIZATION_TREE = REPO_ROOT / "docs" / "repo_organization_tree.json"
DOCS_NAVIGATION_READINESS = REPO_ROOT / "docs" / "repo_navigation_readiness.json"
DOCS_NAVIGATION_COMPLETION_AUDIT = REPO_ROOT / "docs" / "repo_navigation_completion_audit.json"
DOCS_SYSTEM_INTEGRATION = REPO_ROOT / "docs" / "system_integration_map.json"
DOCS_SAAS_HANDOFF = REPO_ROOT / "docs" / "saas_integration_handoff.json"
DOCS_SAAS_MANIFEST = REPO_ROOT / "docs" / "saas_integration_manifest.json"
DOCS_SUPABASE_HARDENING = REPO_ROOT / "docs" / "supabase_hardening_manifest.json"
PUBLIC_REPO_SITEMAP = REPO_ROOT / "frontend" / "public" / "aureon_repo_sitemap.json"
PUBLIC_ACCESS_MAP = REPO_ROOT / "frontend" / "public" / "aureon_end_user_access_map.json"
PUBLIC_CAPABILITY_ACCESS_MATRIX = REPO_ROOT / "frontend" / "public" / "aureon_capability_access_matrix.json"
PUBLIC_CAPABILITY_REGISTRY = REPO_ROOT / "frontend" / "public" / "aureon_capability_registry.json"
PUBLIC_NAVIGATION_INDEX = REPO_ROOT / "frontend" / "public" / "aureon_repo_navigation_index.json"
PUBLIC_ORGANIZATION_TREE = REPO_ROOT / "frontend" / "public" / "aureon_repo_organization_tree.json"
PUBLIC_NAVIGATION_READINESS = REPO_ROOT / "frontend" / "public" / "aureon_repo_navigation_readiness.json"
PUBLIC_NAVIGATION_COMPLETION_AUDIT = REPO_ROOT / "frontend" / "public" / "aureon_repo_navigation_completion_audit.json"
PUBLIC_SYSTEM_INTEGRATION = REPO_ROOT / "frontend" / "public" / "aureon_system_integration_map.json"
PUBLIC_SAAS_HANDOFF = REPO_ROOT / "frontend" / "public" / "aureon_saas_integration_handoff.json"
PUBLIC_SAAS_MANIFEST = REPO_ROOT / "frontend" / "public" / "aureon_saas_integration_manifest.json"
PUBLIC_SUPABASE_HARDENING = REPO_ROOT / "frontend" / "public" / "aureon_supabase_hardening_manifest.json"
SUPABASE_CONFIG = REPO_ROOT / "supabase" / "config.toml"
ENV_SOURCES = [".env.example", "deploy/env.example", "app.yaml"]

CANONICAL_LAUNCHER_PATHS = (
    "scripts/launchers/AUREON_PRODUCTION_LIVE.cmd",
    "scripts/launchers/AUREON_WAKE_UP_FULL_AUTONOMOUS.ps1",
    "scripts/launchers/AUREON_DATA_OCEAN.cmd",
    "scripts/launchers/AUREON_DATA_OCEAN.ps1",
)

LAUNCHER_NAVIGATION_SOURCES = (
    "CAPABILITIES.md",
    "QUICK_START.md",
    "RUNNING.md",
    "docs/REPO_SITEMAP.md",
    "docs/SAAS_INTEGRATION_READINESS.md",
    "scripts/validation/generate_saas_integration_manifest.py",
    "docs/end_user_access_map.json",
    "frontend/public/aureon_end_user_access_map.json",
    "docs/repo_sitemap.json",
    "frontend/public/aureon_repo_sitemap.json",
)

AUTONOMOUS_FRONTEND_MANIFESTS = [
    "aureon_saas_system_inventory.json",
    "aureon_frontend_unification_plan.json",
    "aureon_frontend_evolution_queue.json",
    "aureon_organism_runtime_status.json",
    "aureon_autonomous_capability_switchboard.json",
]

REQUIRED_PATHS = [
    "README.md",
    "docs/REPO_SITEMAP.md",
    "docs/END_USER_ACCESS_MAP.md",
    "docs/CAPABILITY_REGISTRY.md",
    "docs/SAAS_INTEGRATION_READINESS.md",
    "docs/SYSTEM_INTEGRATION_MAP.md",
    "docs/INDEX.md",
    "docs/investor/README.md",
    "docs/investor/TERMINOLOGY.md",
    "docs/repo_sitemap.json",
    "docs/end_user_access_map.json",
    "docs/capability_access_matrix.json",
    "docs/capability_registry.json",
    "docs/repo_navigation_index.json",
    "docs/repo_organization_tree.json",
    "docs/repo_navigation_readiness.json",
    "docs/repo_navigation_completion_audit.json",
    "docs/system_integration_map.json",
    "docs/saas_integration_handoff.json",
    "docs/saas_integration_manifest.json",
    "docs/SUPABASE_HARDENING_REVIEW.md",
    "docs/supabase_hardening_manifest.json",
    "docs/audits/aureon_saas_system_inventory.json",
    "docs/audits/aureon_frontend_unification_plan.json",
    "docs/audits/aureon_frontend_evolution_queue.json",
    "docs/audits/aureon_organism_runtime_status.json",
    "docs/audits/aureon_autonomous_capability_switchboard.json",
    "frontend/src/components/RepoNavigationPanel.tsx",
    "frontend/public/aureon_repo_sitemap.json",
    "frontend/public/aureon_end_user_access_map.json",
    "frontend/public/aureon_capability_access_matrix.json",
    "frontend/public/aureon_capability_registry.json",
    "frontend/public/aureon_repo_navigation_index.json",
    "frontend/public/aureon_repo_organization_tree.json",
    "frontend/public/aureon_repo_navigation_readiness.json",
    "frontend/public/aureon_repo_navigation_completion_audit.json",
    "frontend/public/aureon_system_integration_map.json",
    "frontend/public/aureon_saas_integration_handoff.json",
    "frontend/public/aureon_saas_integration_manifest.json",
    "frontend/public/aureon_supabase_hardening_manifest.json",
    "frontend/public/aureon_saas_system_inventory.json",
    "frontend/public/aureon_frontend_unification_plan.json",
    "frontend/public/aureon_frontend_evolution_queue.json",
    "frontend/public/aureon_organism_runtime_status.json",
    "frontend/public/aureon_autonomous_capability_switchboard.json",
    "scripts/validation/generate_capability_access_matrix.py",
    "scripts/validation/generate_repo_navigation_index.py",
    "scripts/validation/generate_repo_organization_tree.py",
    "scripts/validation/generate_repo_navigation_readiness.py",
    "scripts/validation/generate_repo_navigation_completion_audit.py",
    "scripts/validation/generate_capability_registry.py",
    "scripts/validation/generate_system_integration_map.py",
    "scripts/validation/generate_saas_integration_handoff.py",
    "scripts/validation/generate_saas_integration_manifest.py",
    "scripts/validation/generate_supabase_hardening_manifest.py",
]

MARKDOWN_FILES = [
    "README.md",
    "docs/INDEX.md",
    "docs/REPO_SITEMAP.md",
    "docs/END_USER_ACCESS_MAP.md",
    "docs/CAPABILITY_REGISTRY.md",
    "docs/SYSTEM_INTEGRATION_MAP.md",
    "docs/SAAS_INTEGRATION_READINESS.md",
    "docs/SUPABASE_HARDENING_REVIEW.md",
    "docs/investor/README.md",
    "docs/investor/TERMINOLOGY.md",
]

SECRET_VALUE_PATTERNS = [
    re.compile(r"sk-[A-Za-z0-9_-]{16,}"),
    re.compile(r"pk_[A-Za-z0-9_-]{16,}"),
    re.compile(r"ghp_[A-Za-z0-9_]{20,}"),
    re.compile(r"AKIA[0-9A-Z]{16}"),
    re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----"),
]

SAFE_CREDENTIAL_METADATA_VALUES = {
    "",
    "false",
    "none",
    "null",
    "redacted",
    "[redacted]",
    "hidden",
    "metadata_only_hide_values",
    "metadata_status_only_never_reveal_values",
}


def run_git(*args: str) -> list[str]:
    result = subprocess.run(
        ["git", *args],
        cwd=REPO_ROOT,
        check=True,
        capture_output=True,
        text=True,
    )
    return result.stdout.splitlines()


def load_json(path: Path) -> object:
    with path.open("r", encoding="utf-8") as handle:
        return json.load(handle)


def git_file_count(path_prefix: str | None = None) -> int:
    args = ["ls-files", "-z"]
    if path_prefix:
        args.extend(["--", path_prefix])
    result = subprocess.run(
        ["git", *args],
        cwd=REPO_ROOT,
        check=True,
        capture_output=True,
    )
    return len([path for path in result.stdout.split(b"\0") if path])


def git_directory_count() -> int:
    result = subprocess.run(
        ["git", "ls-files", "-z"],
        cwd=REPO_ROOT,
        check=True,
        capture_output=True,
    )
    directories: set[str] = set()
    for raw_path in result.stdout.split(b"\0"):
        if not raw_path:
            continue
        path = raw_path.decode("utf-8", errors="replace")
        parts = path.split("/")[:-1]
        for index in range(1, len(parts) + 1):
            directories.add("/".join(parts[:index]) + "/")
    return len(directories)


def parse_supabase_auth_counts() -> dict[str, int]:
    counts = {"verify_jwt_true": 0, "verify_jwt_false": 0}
    current_function = None
    section_re = re.compile(r"^\s*\[functions\.([^\]]+)\]\s*$")
    verify_re = re.compile(r"^\s*verify_jwt\s*=\s*(true|false)\s*(?:#.*)?$")

    for raw_line in SUPABASE_CONFIG.read_text(encoding="utf-8").splitlines():
        section_match = section_re.match(raw_line)
        if section_match:
            current_function = section_match.group(1)
            continue

        verify_match = verify_re.match(raw_line)
        if current_function and verify_match:
            key = f"verify_jwt_{verify_match.group(1)}"
            counts[key] += 1

    return counts


def parse_env_variable_names() -> set[str]:
    names: set[str] = set()
    assignment_re = re.compile(r"^\s*([A-Z][A-Z0-9_]+)\s*=")
    app_key_re = re.compile(r"^\s*-\s*key:\s*([A-Z][A-Z0-9_]+)\s*$")

    for rel_path in ENV_SOURCES:
        path = REPO_ROOT / rel_path
        if not path.exists():
            continue
        for raw_line in path.read_text(encoding="utf-8", errors="replace").splitlines():
            assignment_match = assignment_re.match(raw_line)
            if assignment_match:
                names.add(assignment_match.group(1))
                continue
            app_key_match = app_key_re.match(raw_line)
            if app_key_match:
                names.add(app_key_match.group(1))

    return names


def parse_capabilities_table_count() -> int:
    source = REPO_ROOT / "CAPABILITIES.md"
    markdown = source.read_text(encoding="utf-8")
    start = markdown.find("## Capability Table")
    if start == -1:
        return 0
    end = markdown.find("\n## ", start + len("## Capability Table"))
    section = markdown[start:] if end == -1 else markdown[start:end]
    count = 0
    for raw_line in section.splitlines():
        line = raw_line.strip()
        if line.startswith("|") and not line.startswith("|---") and not line.startswith("| Capability "):
            count += 1
    return count


def collect_json_secret_findings(value: object, path: str = "$") -> list[str]:
    findings: list[str] = []

    if isinstance(value, dict):
        for key, child in value.items():
            child_path = f"{path}.{key}"
            lower_key = key.lower()
            if any(marker in lower_key for marker in ("password", "secret", "token", "api_key", "apikey", "private_key")):
                normalized_child = child.strip().lower() if isinstance(child, str) else ""
                is_metadata_policy = (
                    lower_key.endswith("_policy")
                    or lower_key.endswith("_values_hidden")
                    or lower_key in {"secrets", "secret_values_hidden", "contains_secrets"}
                )
                if is_metadata_policy and (isinstance(child, bool) or normalized_child in SAFE_CREDENTIAL_METADATA_VALUES):
                    pass
                elif isinstance(child, str) and normalized_child not in SAFE_CREDENTIAL_METADATA_VALUES:
                    findings.append(f"{child_path} contains a credential-like key with a string value")
                elif child not in (False, None) and not isinstance(child, (dict, list)):
                    findings.append(f"{child_path} contains a credential-like key with a non-empty value")
            findings.extend(collect_json_secret_findings(child, child_path))
    elif isinstance(value, list):
        for index, child in enumerate(value):
            findings.extend(collect_json_secret_findings(child, f"{path}[{index}]"))
    elif isinstance(value, str):
        for pattern in SECRET_VALUE_PATTERNS:
            if pattern.search(value):
                findings.append(f"{path} contains a credential-like value")

    return findings


def markdown_link_targets(markdown: str) -> list[str]:
    pattern = re.compile(r"(?<!!)\[[^\]]+\]\(([^)]+)\)")
    return [match.group(1).strip() for match in pattern.finditer(markdown)]


def is_external_or_anchor(target: str) -> bool:
    lowered = target.lower()
    return (
        not target
        or lowered.startswith(("http://", "https://", "mailto:", "javascript:"))
        or target.startswith("#")
    )


def normalize_markdown_target(target: str) -> str:
    if target.startswith("<") and target.endswith(">"):
        target = target[1:-1]
    target = target.split("#", 1)[0].strip()
    if " " in target and not target.endswith("/"):
        first, *_ = target.split()
        target = first
    return unquote(target)


def collect_broken_markdown_links() -> list[str]:
    broken: list[str] = []
    for rel_path in MARKDOWN_FILES:
        markdown_path = REPO_ROOT / rel_path
        if not markdown_path.exists():
            broken.append(f"{rel_path} is missing")
            continue

        for raw_target in markdown_link_targets(markdown_path.read_text(encoding="utf-8")):
            if is_external_or_anchor(raw_target):
                continue
            target = normalize_markdown_target(raw_target)
            if not target:
                continue
            candidate = (markdown_path.parent / target).resolve()
            if not str(candidate).startswith(str(REPO_ROOT.resolve())):
                broken.append(f"{rel_path} links outside repo: {raw_target}")
            elif not candidate.exists():
                broken.append(f"{rel_path} has broken link: {raw_target}")

    return broken


def expect(condition: bool, failures: list[str], message: str) -> None:
    if not condition:
        failures.append(message)


def collect_launcher_navigation_failures() -> list[str]:
    failures: list[str] = []
    for rel_path in CANONICAL_LAUNCHER_PATHS:
        if not (REPO_ROOT / rel_path).is_file():
            failures.append(f"canonical launcher missing: {rel_path}")

    for source_path in LAUNCHER_NAVIGATION_SOURCES:
        path = REPO_ROOT / source_path
        if not path.is_file():
            failures.append(f"launcher navigation source missing: {source_path}")
            continue
        normalized = path.read_text(encoding="utf-8").replace(chr(92), "/")
        for launcher_path in CANONICAL_LAUNCHER_PATHS:
            launcher_name = Path(launcher_path).name
            without_canonical_paths = normalized.replace(launcher_path, "")
            if launcher_name in without_canonical_paths:
                failures.append(
                    f"{source_path} contains bare-root launcher reference: "
                    f"{launcher_name}"
                )
    return failures


def main() -> int:
    failures: list[str] = []

    docs_repo = load_json(DOCS_REPO_SITEMAP)
    docs_access = load_json(DOCS_ACCESS_MAP)
    docs_capability_access_matrix = load_json(DOCS_CAPABILITY_ACCESS_MATRIX)
    docs_capability_registry = load_json(DOCS_CAPABILITY_REGISTRY)
    docs_navigation_index = load_json(DOCS_NAVIGATION_INDEX)
    docs_organization_tree = load_json(DOCS_ORGANIZATION_TREE)
    docs_navigation_readiness = load_json(DOCS_NAVIGATION_READINESS)
    docs_navigation_completion_audit = load_json(DOCS_NAVIGATION_COMPLETION_AUDIT)
    docs_system_integration = load_json(DOCS_SYSTEM_INTEGRATION)
    docs_saas_handoff = load_json(DOCS_SAAS_HANDOFF)
    docs_saas_manifest = load_json(DOCS_SAAS_MANIFEST)
    docs_supabase_hardening = load_json(DOCS_SUPABASE_HARDENING)
    public_repo = load_json(PUBLIC_REPO_SITEMAP)
    public_access = load_json(PUBLIC_ACCESS_MAP)
    public_capability_access_matrix = load_json(PUBLIC_CAPABILITY_ACCESS_MATRIX)
    public_capability_registry = load_json(PUBLIC_CAPABILITY_REGISTRY)
    public_navigation_index = load_json(PUBLIC_NAVIGATION_INDEX)
    public_organization_tree = load_json(PUBLIC_ORGANIZATION_TREE)
    public_navigation_readiness = load_json(PUBLIC_NAVIGATION_READINESS)
    public_navigation_completion_audit = load_json(PUBLIC_NAVIGATION_COMPLETION_AUDIT)
    public_system_integration = load_json(PUBLIC_SYSTEM_INTEGRATION)
    public_saas_handoff = load_json(PUBLIC_SAAS_HANDOFF)
    public_saas_manifest = load_json(PUBLIC_SAAS_MANIFEST)
    public_supabase_hardening = load_json(PUBLIC_SUPABASE_HARDENING)

    for rel_path in REQUIRED_PATHS:
        expect((REPO_ROOT / rel_path).exists(), failures, f"required path missing: {rel_path}")
    failures.extend(collect_launcher_navigation_failures())

    tracked_total = git_file_count()
    expect(docs_repo.get("tracked_file_count") == tracked_total, failures, "docs/repo_sitemap.json tracked_file_count is stale")
    expect(public_repo.get("tracked_file_count") == tracked_total, failures, "frontend public sitemap tracked_file_count is stale")
    expect(docs_navigation_index.get("tracked_file_count") == tracked_total, failures, "docs repo navigation index tracked_file_count is stale")
    expect(public_navigation_index.get("tracked_file_count") == tracked_total, failures, "frontend repo navigation index tracked_file_count is stale")

    systems = {entry["path"]: entry["files"] for entry in docs_repo.get("top_level_systems", [])}
    for path, recorded_count in systems.items():
        actual_count = git_file_count(path)
        expect(recorded_count == actual_count, failures, f"top_level_systems count is stale for {path}: {recorded_count} != {actual_count}")

    docs_capabilities = docs_access.get("capabilities", [])
    public_capabilities = public_access.get("capabilities", [])
    expect(docs_access == public_access, failures, "end-user access map docs/public mirrors differ")
    expect(len(docs_capabilities) == 13, failures, "docs access map capability count changed from 13")
    expect(len(public_capabilities) == len(docs_capabilities), failures, "public access map capability count differs from docs access map")
    for capability in docs_capabilities:
        capability_id = capability.get("id", "[missing-id]") if isinstance(capability, dict) else "[invalid-row]"
        for field in ("id", "label", "user_action", "primary_docs", "related_systems", "runtime_or_api_surface", "safety_gate"):
            expect(
                bool(capability.get(field)) if isinstance(capability, dict) else False,
                failures,
                f"end-user access map capability {capability_id} is missing {field}",
            )
    repo_navigation_route = next(
        (capability for capability in docs_capabilities if isinstance(capability, dict) and capability.get("id") == "repo_navigation"),
        {},
    )
    expect(
        "docs/repo_organization_tree.json" in repo_navigation_route.get("primary_docs", []),
        failures,
        "repo_navigation access route does not expose docs/repo_organization_tree.json",
    )
    expect(
        "frontend/public/aureon_repo_organization_tree.json" in repo_navigation_route.get("runtime_or_api_surface", []),
        failures,
        "repo_navigation access route does not expose the public organization tree",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("capability_count") == len(docs_capabilities),
        failures,
        "repo sitemap end_user_access.capability_count is stale",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_navigation_tab") == "#repo-map",
        failures,
        "repo sitemap does not expose the frontend navigation tab",
    )
    expect(
        public_repo.get("frontend_navigation_tab") == "#repo-map",
        failures,
        "frontend public sitemap does not expose #repo-map",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("capability_registry") == "docs/capability_registry.json",
        failures,
        "repo sitemap does not expose the docs capability registry",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("capability_access_matrix") == "docs/capability_access_matrix.json",
        failures,
        "repo sitemap does not expose the docs capability access matrix",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_capability_access_matrix")
        == "frontend/public/aureon_capability_access_matrix.json",
        failures,
        "repo sitemap does not expose the public capability access matrix",
    )
    expect(
        public_repo.get("capability_access_matrix") == "frontend/public/aureon_capability_access_matrix.json",
        failures,
        "frontend public sitemap does not expose the capability access matrix",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_capability_registry")
        == "frontend/public/aureon_capability_registry.json",
        failures,
        "repo sitemap does not expose the public capability registry",
    )
    expect(
        public_repo.get("capability_registry") == "frontend/public/aureon_capability_registry.json",
        failures,
        "frontend public sitemap does not expose the capability registry",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("repo_navigation_index") == "docs/repo_navigation_index.json",
        failures,
        "repo sitemap does not expose the docs repo navigation index",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_navigation_index") == "frontend/public/aureon_repo_navigation_index.json",
        failures,
        "repo sitemap does not expose the public repo navigation index",
    )
    expect(
        public_repo.get("navigation_index") == "frontend/public/aureon_repo_navigation_index.json",
        failures,
        "frontend public sitemap does not expose the repo navigation index",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("repo_organization_tree") == "docs/repo_organization_tree.json",
        failures,
        "repo sitemap does not expose the docs repo organization tree",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_organization_tree")
        == "frontend/public/aureon_repo_organization_tree.json",
        failures,
        "repo sitemap does not expose the public repo organization tree",
    )
    expect(
        public_repo.get("organization_tree") == "frontend/public/aureon_repo_organization_tree.json",
        failures,
        "frontend public sitemap does not expose the repo organization tree",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("repo_navigation_readiness") == "docs/repo_navigation_readiness.json",
        failures,
        "repo sitemap does not expose the docs repo navigation readiness audit",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_repo_navigation_readiness")
        == "frontend/public/aureon_repo_navigation_readiness.json",
        failures,
        "repo sitemap does not expose the public repo navigation readiness audit",
    )
    expect(
        public_repo.get("repo_navigation_readiness") == "frontend/public/aureon_repo_navigation_readiness.json",
        failures,
        "frontend public sitemap does not expose the repo navigation readiness audit",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("repo_navigation_completion_audit") == "docs/repo_navigation_completion_audit.json",
        failures,
        "repo sitemap does not expose the docs repo navigation completion audit",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_repo_navigation_completion_audit")
        == "frontend/public/aureon_repo_navigation_completion_audit.json",
        failures,
        "repo sitemap does not expose the public repo navigation completion audit",
    )
    expect(
        public_repo.get("repo_navigation_completion_audit") == "frontend/public/aureon_repo_navigation_completion_audit.json",
        failures,
        "frontend public sitemap does not expose the repo navigation completion audit",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("system_integration_map") == "docs/system_integration_map.json",
        failures,
        "repo sitemap does not expose the docs system integration map",
    )
    expect(
        docs_repo.get("end_user_access", {}).get("frontend_public_system_integration_map")
        == "frontend/public/aureon_system_integration_map.json",
        failures,
        "repo sitemap does not expose the public system integration map",
    )
    expect(
        public_repo.get("system_integration_map") == "frontend/public/aureon_system_integration_map.json",
        failures,
        "frontend public sitemap does not expose the system integration map",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("handoff_manifest") == "docs/saas_integration_handoff.json",
        failures,
        "repo sitemap does not expose the docs SaaS integration handoff",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("frontend_public_handoff_manifest")
        == "frontend/public/aureon_saas_integration_handoff.json",
        failures,
        "repo sitemap does not expose the public SaaS integration handoff",
    )
    expect(
        public_repo.get("saas_integration_handoff") == "frontend/public/aureon_saas_integration_handoff.json",
        failures,
        "frontend public sitemap does not expose the SaaS integration handoff",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("machine_readable") == "docs/saas_integration_manifest.json",
        failures,
        "repo sitemap does not expose the docs SaaS integration manifest",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("frontend_public_mirror") == "frontend/public/aureon_saas_integration_manifest.json",
        failures,
        "repo sitemap does not expose the public SaaS integration manifest",
    )
    expect(
        public_repo.get("saas_integration_manifest") == "frontend/public/aureon_saas_integration_manifest.json",
        failures,
        "frontend public sitemap does not expose the SaaS integration manifest",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("supabase_hardening_manifest") == "docs/supabase_hardening_manifest.json",
        failures,
        "repo sitemap does not expose the docs Supabase hardening manifest",
    )
    expect(
        docs_repo.get("saas_readiness", {}).get("frontend_public_supabase_hardening_manifest")
        == "frontend/public/aureon_supabase_hardening_manifest.json",
        failures,
        "repo sitemap does not expose the public Supabase hardening manifest",
    )
    expect(
        public_repo.get("supabase_hardening_manifest") == "frontend/public/aureon_supabase_hardening_manifest.json",
        failures,
        "frontend public sitemap does not expose the Supabase hardening manifest",
    )
    expected_autonomous_frontend_paths = [
        f"frontend/public/{manifest_name}" for manifest_name in AUTONOMOUS_FRONTEND_MANIFESTS
    ]
    docs_autonomous_frontend_paths = [
        entry.get("frontend_public")
        for entry in docs_repo.get("saas_readiness", {}).get("autonomous_frontend_manifests", [])
        if isinstance(entry, dict)
    ]
    expect(
        docs_autonomous_frontend_paths == expected_autonomous_frontend_paths,
        failures,
        "repo sitemap does not expose the autonomous frontend manifests",
    )
    expect(
        public_repo.get("autonomous_frontend_manifests") == expected_autonomous_frontend_paths,
        failures,
        "frontend public sitemap does not expose the autonomous frontend manifests",
    )
    expect(docs_capability_access_matrix == public_capability_access_matrix, failures, "capability access matrix docs/public mirrors differ")
    expect(docs_capability_registry == public_capability_registry, failures, "capability registry docs/public mirrors differ")
    expect(docs_navigation_index == public_navigation_index, failures, "repo navigation index docs/public mirrors differ")
    expect(docs_organization_tree == public_organization_tree, failures, "repo organization tree docs/public mirrors differ")
    expect(docs_navigation_readiness == public_navigation_readiness, failures, "repo navigation readiness docs/public mirrors differ")
    expect(docs_navigation_completion_audit == public_navigation_completion_audit, failures, "repo navigation completion audit docs/public mirrors differ")
    expect(docs_system_integration == public_system_integration, failures, "system integration map docs/public mirrors differ")
    expect(docs_saas_handoff == public_saas_handoff, failures, "SaaS integration handoff docs/public mirrors differ")
    capability_registry_rows = docs_capability_registry.get("capabilities", []) if isinstance(docs_capability_registry, dict) else []
    expected_capability_rows = parse_capabilities_table_count()
    registry_summary = docs_capability_registry.get("summary", {}) if isinstance(docs_capability_registry, dict) else {}
    registry_resolved_count = sum(len(row.get("resolved_paths", [])) for row in capability_registry_rows if isinstance(row, dict))
    registry_runtime_count = sum(len(row.get("runtime_refs", [])) for row in capability_registry_rows if isinstance(row, dict))
    registry_generated_count = sum(len(row.get("generated_refs", [])) for row in capability_registry_rows if isinstance(row, dict))
    registry_command_count = sum(len(row.get("command_refs", [])) for row in capability_registry_rows if isinstance(row, dict))
    registry_symbol_count = sum(len(row.get("code_symbol_refs", [])) for row in capability_registry_rows if isinstance(row, dict))
    registry_unresolved_count = sum(len(row.get("unresolved_refs", [])) for row in capability_registry_rows if isinstance(row, dict))
    expect(
        registry_summary.get("tracked_file_count") == tracked_total,
        failures,
        "capability registry tracked_file_count is stale",
    )
    expect(
        registry_summary.get("navigation_index_entries") == docs_navigation_index.get("entry_count"),
        failures,
        "capability registry navigation_index_entries is stale",
    )
    expect(
        registry_summary.get("capability_count") == expected_capability_rows,
        failures,
        "capability registry capability_count differs from CAPABILITIES.md",
    )
    expect(
        len(capability_registry_rows) == expected_capability_rows,
        failures,
        "capability registry row count differs from CAPABILITIES.md",
    )
    expect(
        registry_summary.get("runtime_surface_ref_count") == registry_runtime_count,
        failures,
        "capability registry runtime_surface_ref_count differs from rows",
    )
    expect(
        registry_summary.get("generated_artifact_ref_count") == registry_generated_count,
        failures,
        "capability registry generated_artifact_ref_count differs from rows",
    )
    expect(
        registry_summary.get("command_surface_ref_count") == registry_command_count,
        failures,
        "capability registry command_surface_ref_count differs from rows",
    )
    expect(
        registry_summary.get("code_symbol_ref_count") == registry_symbol_count,
        failures,
        "capability registry code_symbol_ref_count differs from rows",
    )
    expect(
        registry_summary.get("unresolved_surface_ref_count") == registry_unresolved_count,
        failures,
        "capability registry unresolved_surface_ref_count differs from rows",
    )
    expect(
        registry_summary.get("resolved_surface_ref_count", 0) <= registry_resolved_count,
        failures,
        "capability registry resolved_surface_ref_count exceeds row path count",
    )
    expect(
        docs_capability_registry.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "capability registry public contract must not contain file contents",
    )
    expect(
        docs_capability_registry.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "capability registry public contract must not contain secrets",
    )
    matrix_rows = docs_capability_access_matrix.get("capabilities", []) if isinstance(docs_capability_access_matrix, dict) else []
    matrix_summary = docs_capability_access_matrix.get("summary", {}) if isinstance(docs_capability_access_matrix, dict) else {}
    matrix_ids = {row.get("id") for row in matrix_rows if isinstance(row, dict)}
    registry_ids = {row.get("id") for row in capability_registry_rows if isinstance(row, dict)}
    expect(
        matrix_summary.get("capability_count") == len(capability_registry_rows),
        failures,
        "capability access matrix capability_count differs from capability registry",
    )
    expect(len(matrix_rows) == len(capability_registry_rows), failures, "capability access matrix rows differ from capability registry")
    expect(matrix_ids == registry_ids, failures, "capability access matrix does not cover every registry capability")
    expect(
        matrix_summary.get("system_bound_capability_count") == len(capability_registry_rows),
        failures,
        "capability access matrix does not bind every current capability to related systems",
    )
    for row in matrix_rows:
        capability_id = row.get("id", "[missing-id]") if isinstance(row, dict) else "[invalid-row]"
        expect(bool(row.get("access_routes")) if isinstance(row, dict) else False, failures, f"capability access matrix {capability_id} has no access routes")
        expect(bool(row.get("related_systems")) if isinstance(row, dict) else False, failures, f"capability access matrix {capability_id} has no related systems")
        expect(bool(row.get("end_user_start_points")) if isinstance(row, dict) else False, failures, f"capability access matrix {capability_id} has no end-user start points")
        expect(bool(row.get("safety_gates")) if isinstance(row, dict) else False, failures, f"capability access matrix {capability_id} has no safety gates")
    expect(
        docs_capability_access_matrix.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "capability access matrix public contract must not contain file contents",
    )
    expect(
        docs_capability_access_matrix.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "capability access matrix public contract must not contain secrets",
    )
    navigation_entries = docs_navigation_index.get("entries", [])
    expect(len(navigation_entries) == tracked_total, failures, "repo navigation index entry count differs from git ls-files")
    expect(docs_navigation_index.get("entry_count") == tracked_total, failures, "repo navigation index entry_count is stale")
    entry_paths = [entry.get("path") for entry in navigation_entries if isinstance(entry, dict)]
    expect(len(set(entry_paths)) == tracked_total, failures, "repo navigation index paths are missing or duplicated")
    expect(
        docs_navigation_index.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "repo navigation index public contract must not contain file contents",
    )
    organization_directories = docs_organization_tree.get("directories", []) if isinstance(docs_organization_tree, dict) else []
    actual_directory_count = git_directory_count()
    expect(
        docs_organization_tree.get("tracked_file_count") == tracked_total,
        failures,
        "repo organization tree tracked_file_count is stale",
    )
    expect(
        docs_organization_tree.get("directory_count") == actual_directory_count,
        failures,
        "repo organization tree directory_count differs from git ls-files",
    )
    expect(
        len(organization_directories) == actual_directory_count,
        failures,
        "repo organization tree directory rows differ from git ls-files",
    )
    expect(
        docs_organization_tree.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "repo organization tree public contract must not contain file contents",
    )
    expect(
        docs_organization_tree.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "repo organization tree public contract must not contain secrets",
    )
    system_rows = docs_system_integration.get("systems", []) if isinstance(docs_system_integration, dict) else []
    system_paths = {entry.get("path") for entry in system_rows if isinstance(entry, dict)}
    sitemap_paths = {entry.get("path") for entry in docs_repo.get("top_level_systems", []) if isinstance(entry, dict)}
    system_capability_ids = {
        capability_id
        for entry in system_rows
        if isinstance(entry, dict)
        for capability_id in entry.get("capability_ids", [])
    }
    system_access_route_ids = {
        route_id
        for entry in system_rows
        if isinstance(entry, dict)
        for route_id in entry.get("access_route_ids", [])
    }
    access_route_ids = {route.get("id") for route in docs_capabilities if isinstance(route, dict)}
    capability_system_counts = docs_system_integration.get("capability_system_counts", {})
    access_route_system_counts = docs_system_integration.get("access_route_system_counts", {})
    expect(
        docs_system_integration.get("summary", {}).get("tracked_file_count") == tracked_total,
        failures,
        "system integration map tracked_file_count is stale",
    )
    expect(
        docs_system_integration.get("summary", {}).get("system_count") == len(docs_repo.get("top_level_systems", [])),
        failures,
        "system integration map system_count differs from repo sitemap",
    )
    expect(
        docs_system_integration.get("summary", {}).get("capability_count") == len(registry_ids),
        failures,
        "system integration map capability_count differs from capability registry",
    )
    expect(
        docs_system_integration.get("summary", {}).get("mapped_capability_count") == len(system_capability_ids),
        failures,
        "system integration map mapped_capability_count differs from system rows",
    )
    expect(
        system_capability_ids == registry_ids,
        failures,
        "system integration map does not cover every current capability registry ID",
    )
    expect(
        set(capability_system_counts) == registry_ids,
        failures,
        "system integration map capability_system_counts does not cover every current capability",
    )
    expect(
        docs_system_integration.get("summary", {}).get("unmapped_capability_count") == 0,
        failures,
        "system integration map reports unmapped current capabilities",
    )
    expect(
        not docs_system_integration.get("unmapped_capability_ids"),
        failures,
        "system integration map lists unmapped current capabilities",
    )
    expect(
        docs_system_integration.get("summary", {}).get("access_route_count") == len(docs_capabilities),
        failures,
        "system integration map access_route_count differs from access map",
    )
    expect(
        docs_system_integration.get("summary", {}).get("mapped_access_route_count") == len(system_access_route_ids),
        failures,
        "system integration map mapped_access_route_count differs from system rows",
    )
    expect(
        system_access_route_ids.issubset(access_route_ids),
        failures,
        "system integration map has access route IDs not present in the access map",
    )
    expect(
        set(access_route_system_counts).issubset(access_route_ids),
        failures,
        "system integration map access_route_system_counts has IDs not present in the access map",
    )
    expect(system_paths == sitemap_paths, failures, "system integration map does not cover every top-level system")
    expect(
        docs_system_integration.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "system integration map public contract must not contain file contents",
    )
    expect(
        docs_system_integration.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "system integration map public contract must not contain secrets",
    )

    supabase_counts = parse_supabase_auth_counts()
    expect(
        docs_repo.get("saas_readiness", {}).get("supabase_auth_counts") == supabase_counts,
        failures,
        "repo sitemap Supabase auth counts differ from supabase/config.toml",
    )
    expect(docs_saas_manifest == public_saas_manifest, failures, "SaaS integration manifest docs/public mirrors differ")
    expect(docs_supabase_hardening == public_supabase_hardening, failures, "Supabase hardening manifest docs/public mirrors differ")
    env_names = parse_env_variable_names()
    expect(
        docs_saas_manifest.get("environment", {}).get("variable_count") == len(env_names),
        failures,
        "SaaS integration manifest env variable count differs from env sources",
    )
    expect(
        docs_saas_manifest.get("supabase", {}).get("verify_jwt_true") == supabase_counts["verify_jwt_true"],
        failures,
        "SaaS integration manifest verify_jwt_true differs from supabase/config.toml",
    )
    expect(
        docs_saas_manifest.get("supabase", {}).get("verify_jwt_false") == supabase_counts["verify_jwt_false"],
        failures,
        "SaaS integration manifest verify_jwt_false differs from supabase/config.toml",
    )
    expect(
        docs_saas_manifest.get("public_contract", {}).get("contains_env_values") is False,
        failures,
        "SaaS integration manifest public contract must not contain env values",
    )
    readiness_summary = docs_navigation_readiness.get("summary", {}) if isinstance(docs_navigation_readiness, dict) else {}
    handoff_summary = docs_saas_handoff.get("summary", {}) if isinstance(docs_saas_handoff, dict) else {}
    expect(
        handoff_summary.get("tracked_file_count") == tracked_total,
        failures,
        "SaaS integration handoff tracked_file_count is stale",
    )
    expect(
        handoff_summary.get("readiness_status") == readiness_summary.get("readiness_status"),
        failures,
        "SaaS integration handoff readiness_status differs from readiness audit",
    )
    expect(
        handoff_summary.get("current_capability_count") == len(capability_registry_rows),
        failures,
        "SaaS integration handoff current_capability_count differs from capability registry",
    )
    expect(
        handoff_summary.get("system_mapped_capability_count") == len(capability_registry_rows),
        failures,
        "SaaS integration handoff system_mapped_capability_count differs from capability registry",
    )
    expect(
        handoff_summary.get("unmapped_capability_count") == 0,
        failures,
        "SaaS integration handoff reports unmapped capabilities",
    )
    expect(
        handoff_summary.get("deployment_surface_count") == len(docs_saas_manifest.get("deployment_surfaces", [])),
        failures,
        "SaaS integration handoff deployment_surface_count differs from SaaS manifest",
    )
    expect(
        handoff_summary.get("environment_variable_name_count") == len(env_names),
        failures,
        "SaaS integration handoff environment_variable_name_count differs from env sources",
    )
    expect(
        handoff_summary.get("supabase_production_blocker_count") == 0,
        failures,
        "SaaS integration handoff reports Supabase production blockers",
    )
    expect(
        handoff_summary.get("handoff_status") in {"ready", "ready_with_advisory_review"},
        failures,
        "SaaS integration handoff status is not ready",
    )
    expect(
        docs_saas_handoff.get("public_contract", {}).get("contains_env_values") is False,
        failures,
        "SaaS integration handoff public contract must not contain env values",
    )
    expect(
        docs_saas_handoff.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "SaaS integration handoff public contract must not contain secrets",
    )
    hardening_summary = docs_supabase_hardening.get("summary", {}) if isinstance(docs_supabase_hardening, dict) else {}
    public_high_risk_routes = docs_supabase_hardening.get("public_high_risk_routes", []) if isinstance(docs_supabase_hardening, dict) else []
    expect(
        hardening_summary.get("function_count") == supabase_counts["verify_jwt_true"] + supabase_counts["verify_jwt_false"],
        failures,
        "Supabase hardening manifest function_count differs from supabase/config.toml",
    )
    expect(
        hardening_summary.get("verify_jwt_true") == supabase_counts["verify_jwt_true"],
        failures,
        "Supabase hardening manifest verify_jwt_true differs from supabase/config.toml",
    )
    expect(
        hardening_summary.get("verify_jwt_false") == supabase_counts["verify_jwt_false"],
        failures,
        "Supabase hardening manifest verify_jwt_false differs from supabase/config.toml",
    )
    expect(
        hardening_summary.get("public_high_risk_count") == len(public_high_risk_routes),
        failures,
        "Supabase hardening manifest public_high_risk_count is stale",
    )
    expect(
        hardening_summary.get("production_blocker_count") == len(public_high_risk_routes),
        failures,
        "Supabase hardening manifest production_blocker_count is stale",
    )
    expect(
        docs_supabase_hardening.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "Supabase hardening manifest public contract must not contain file contents",
    )
    expect(
        docs_supabase_hardening.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "Supabase hardening manifest public contract must not contain secrets",
    )

    readiness_gates = docs_navigation_readiness.get("gates", []) if isinstance(docs_navigation_readiness, dict) else []
    expect(
        readiness_summary.get("readiness_status") == "pass",
        failures,
        "repo navigation readiness audit is not passing",
    )
    expect(
        readiness_summary.get("failed_gate_count") == 0,
        failures,
        "repo navigation readiness audit reports failed gates",
    )
    expect(
        readiness_summary.get("tracked_file_count") == tracked_total,
        failures,
        "repo navigation readiness tracked_file_count is stale",
    )
    expect(
        readiness_summary.get("directory_count") == actual_directory_count,
        failures,
        "repo navigation readiness directory_count is stale",
    )
    expect(
        readiness_summary.get("current_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation readiness current_capability_count differs from capability registry",
    )
    expect(
        readiness_summary.get("routed_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation readiness routed_capability_count differs from capability registry",
    )
    expect(
        readiness_summary.get("system_mapped_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation readiness system_mapped_capability_count differs from capability registry",
    )
    expect(
        readiness_summary.get("unmapped_capability_count") == 0,
        failures,
        "repo navigation readiness reports unmapped capabilities",
    )
    expect(
        readiness_summary.get("supabase_production_blocker_count") == 0,
        failures,
        "repo navigation readiness reports Supabase production blockers",
    )
    expect(
        readiness_summary.get("gate_count") == len(readiness_gates),
        failures,
        "repo navigation readiness gate_count differs from gate rows",
    )
    expect(
        docs_navigation_readiness.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "repo navigation readiness public contract must not contain file contents",
    )
    expect(
        docs_navigation_readiness.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "repo navigation readiness public contract must not contain secrets",
    )
    completion_summary = docs_navigation_completion_audit.get("summary", {}) if isinstance(docs_navigation_completion_audit, dict) else {}
    completion_requirements = docs_navigation_completion_audit.get("requirements", []) if isinstance(docs_navigation_completion_audit, dict) else []
    expect(
        completion_summary.get("completion_status") == "complete",
        failures,
        "repo navigation completion audit is not complete",
    )
    expect(
        completion_summary.get("tracked_file_count") == tracked_total,
        failures,
        "repo navigation completion audit tracked_file_count is stale",
    )
    expect(
        completion_summary.get("current_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation completion audit current_capability_count differs from capability registry",
    )
    expect(
        completion_summary.get("routed_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation completion audit routed_capability_count differs from capability registry",
    )
    expect(
        completion_summary.get("system_mapped_capability_count") == len(capability_registry_rows),
        failures,
        "repo navigation completion audit system_mapped_capability_count differs from capability registry",
    )
    expect(
        completion_summary.get("unmapped_capability_count") == 0,
        failures,
        "repo navigation completion audit reports unmapped capabilities",
    )
    expect(
        completion_summary.get("readiness_status") == readiness_summary.get("readiness_status"),
        failures,
        "repo navigation completion audit readiness_status differs from readiness audit",
    )
    expect(
        completion_summary.get("supabase_production_blocker_count") == hardening_summary.get("production_blocker_count"),
        failures,
        "repo navigation completion audit Supabase blocker count differs from hardening manifest",
    )
    expect(
        completion_summary.get("handoff_status") == handoff_summary.get("handoff_status"),
        failures,
        "repo navigation completion audit handoff_status differs from SaaS handoff",
    )
    expect(
        completion_summary.get("requirement_count") == len(completion_requirements),
        failures,
        "repo navigation completion audit requirement_count differs from requirement rows",
    )
    expect(
        completion_summary.get("incomplete_requirement_count") == 0
        and all(isinstance(item, dict) and item.get("status") == "complete" for item in completion_requirements),
        failures,
        "repo navigation completion audit has incomplete requirements",
    )
    expect(
        docs_navigation_completion_audit.get("public_contract", {}).get("contains_file_contents") is False,
        failures,
        "repo navigation completion audit public contract must not contain file contents",
    )
    expect(
        docs_navigation_completion_audit.get("public_contract", {}).get("contains_secrets") is False,
        failures,
        "repo navigation completion audit public contract must not contain secrets",
    )

    autonomous_public_manifests: list[tuple[str, object]] = []
    for manifest_name in AUTONOMOUS_FRONTEND_MANIFESTS:
        docs_label = f"docs/audits/{manifest_name}"
        public_label = f"frontend/public/{manifest_name}"
        docs_manifest = load_json(REPO_ROOT / docs_label)
        public_manifest = load_json(REPO_ROOT / public_label)
        autonomous_public_manifests.append((public_label, public_manifest))
        expect(docs_manifest == public_manifest, failures, f"{manifest_name} docs/public mirrors differ")
        expect(
            isinstance(public_manifest, dict) and isinstance(public_manifest.get("status"), str),
            failures,
            f"{public_label} must expose a status string",
        )
        expect(
            isinstance(public_manifest, dict) and isinstance(public_manifest.get("summary"), dict),
            failures,
            f"{public_label} must expose a summary object",
        )

    for label, manifest in (
        ("frontend/public/aureon_repo_sitemap.json", public_repo),
        ("frontend/public/aureon_end_user_access_map.json", public_access),
        ("frontend/public/aureon_capability_access_matrix.json", public_capability_access_matrix),
        ("frontend/public/aureon_capability_registry.json", public_capability_registry),
        ("frontend/public/aureon_repo_navigation_index.json", public_navigation_index),
        ("frontend/public/aureon_repo_organization_tree.json", public_organization_tree),
        ("frontend/public/aureon_repo_navigation_readiness.json", public_navigation_readiness),
        ("frontend/public/aureon_repo_navigation_completion_audit.json", public_navigation_completion_audit),
        ("frontend/public/aureon_system_integration_map.json", public_system_integration),
        ("frontend/public/aureon_saas_integration_handoff.json", public_saas_handoff),
        ("frontend/public/aureon_saas_integration_manifest.json", public_saas_manifest),
        ("frontend/public/aureon_supabase_hardening_manifest.json", public_supabase_hardening),
        *autonomous_public_manifests,
    ):
        for finding in collect_json_secret_findings(manifest):
            failures.append(f"{label}: {finding}")

    failures.extend(collect_broken_markdown_links())

    if failures:
        print("Navigation contract validation failed:")
        for failure in failures:
            print(f"- {failure}")
        return 1

    print(f"OK tracked_file_count={tracked_total}")
    print(f"OK capability_count={len(docs_capabilities)}")
    print(f"OK current_capability_registry_count={len(capability_registry_rows)}")
    print(f"OK capability_access_matrix_rows={len(matrix_rows)}")
    print(f"OK repo_navigation_index_entries={len(navigation_entries)}")
    print(f"OK repo_organization_directories={len(organization_directories)}")
    print(f"OK repo_navigation_readiness={readiness_summary.get('readiness_status')}")
    print(f"OK repo_navigation_completion_audit={completion_summary.get('completion_status')}")
    print(f"OK system_integration_systems={len(system_rows)}")
    print(f"OK saas_integration_handoff={handoff_summary.get('handoff_status')}")
    print(f"OK saas_env_variable_count={len(env_names)}")
    print(f"OK supabase_auth_counts={supabase_counts}")
    print(f"OK supabase_hardening_public_blockers={len(public_high_risk_routes)}")
    print(f"OK autonomous_frontend_manifests={len(AUTONOMOUS_FRONTEND_MANIFESTS)}")
    print(f"OK canonical_launchers={len(CANONICAL_LAUNCHER_PATHS)}")
    print("OK public navigation manifests contain no credential-like values")
    print("OK key Markdown links resolve")
    return 0


if __name__ == "__main__":
    sys.exit(main())