"""Write charts/INDEX.md from the specs, the render log and the per-chart source and caveat notes below.

Titles, n, split and direction are read from the specs (plus the renderer's filled fields for ws10), so
INDEX.md cannot drift from what the charts show. Source fields and caveats were collected from each
workstream's results file and REPORT.md during F.1 (verifier notes in charts/_work/<ws>-verify.md).

Run after render_all.py: python gen_index.py
"""
import json
import os

HERE = os.path.dirname(os.path.abspath(__file__))
EXP = os.path.dirname(HERE)

from render_all import OVERRIDES, REDACT, SOURCES, apply_file_overrides, file_overrides, load  # noqa: E402

A = "ws1/analysis.json"
NOTES = {
    "ws1-1": {
        "src": [f"{A} -> q12.threshold_sweep_conservative[\"0.5\"..\"0.95\"].A and .B (x100): both series",
                f"{A} -> q12.primary.accept_A.p / accept_B.p: the 0.8 points (2/110, 16/110)",
                f"{A} -> n_in_scope: n claims (110)"],
        "cav": ["Not adjudicated when the spec was written: an accept is not a correct accept. F.2 has since found 9 fails "
                "in these 110 claims, none accepted (see adj-1).",
                "Arm A is mostly a fixed 'no receipt' note: 103 of 110 claims had no receipt.",
                "5 dossiers, one draft per vendor, so 5 vendor clusters.",
                "48 of the 110 are score rows; Jev gets no rubric and accepted 0 of them.",
                "Descriptive sweep; no threshold was chosen from it."]},
    "ws1-2": {
        "src": [f"{A} -> q11.per_dossier.<slug>: (in_scope - no_receipt_in_scope) / in_scope, vendors in {A} -> vendors order",
                f"{A} -> q11.per_dossier.<slug>.in_scope: the n under each bar",
                "ws1/REPORT.md Table 1 ('With receipt' column) agrees"],
        "cav": ["Each bar is 19 to 26 claims from one step-02 draft; step-02 output varies run to run.",
                "Only 7 of 110 claims carry a receipt.",
                "ground.py counts 'URL in bundle, no receipt' as grounded.",
                "Evidence bundles frozen in June 2026. Vendors stay anonymized; do not quote their claims.",
                "The spec title said four of five dossiers had no receipt; the chart title is rewritten to the bars' "
                "three of five (override)."]},
    "ws1-3": {
        "src": ["Values are not stored: they are z*sqrt(p(1-p)/(n*22*0.3909)) with z = " + A + " -> q14.z",
                f"{A} -> q14.projections.jev_armB_checker_any_repeat.h5_p50_deff1.0.f_point.dossiers / h3_p50_deff1.0: "
                "the 45 and 125 in the title",
                f"{A} -> q12.primary.checker_fail_B_any_repeat.p (0.3909) and q14.in_scope_per_dossier_mean (22.0)",
                "Added diamond curve (override, computed at render time by render_all.projection_values): the same "
                f"formula with share = adj/results.json -> fail_share.k / fail_share.n (9/110), z = {A} -> q14.z, "
                f"22.0 = {A} -> q14.in_scope_per_dossier_mean, miss rate 0.5",
                "adj/results.json -> fail_share.k (9): n recorded fails; the 214 and 593 in the title and assumptions "
                "are ceil((z*0.5/h)^2 / (22 * 9/110)) for h = 0.05 and 0.03"],
        "cav": ["The fail share is a proxy (Jev's arm-B checker view), not an adjudicated rate. F.2 later measured 8.2% "
                "(9/110) on these claims, far below the 39% assumed.",
                "45 and 125 hold only for the worst case (true miss rate 50%); at 20% they are 29 and 80.",
                "Assumes no clustering (design effect 1); a design effect of 2 doubles every count.",
                "Over the fail share's own 95% range the counts are 37 to 58 (+-5) and 101 to 160 (+-3)."]},
    "ws2-1": {
        "src": ["ws3/rekey120/ws2run/ws2_results.json -> q2_3.curves.C0[i] and .K3[i] {x, y, y_lo, y_hi, cut}: the two curves",
                "ws3/rekey120/ws2run/ws2_results.json -> existing_rule_0p8.dev.two_repeat: the star",
                "ws3/rekey120/ws2run/ws2_results.json -> q2_2.zero_miss.C0.summary and .nested_candidate.summary: the two diamonds",
                "ws3/rekey120/ws2run/ws2_results.json -> counts.dev: n claims 258, n fails 85"],
        "cav": ["Curves and the star are in-sample; only the diamonds are out-of-fold.",
                "0 of 85 is not a zero miss rate: upper bound 4.3% on dev, 9.9% on held-out.",
                "Labels are mostly Opus judgments (307 of 372).",
                "All 3 out-of-fold misses come from one vendor, so the Wilson intervals are too narrow.",
                "The spec's accept-everything point (cut -1.0, drawn at (100, 100)) is dropped from both curves: it is "
                "stored as q2_3.curves.<score>[0] but is not an operating point of either rule (override).",
                "On the 125-fail key the spec rounded twice (4 dp, then 1 dp) and some values read 0.1 point high; on "
                "the 120-fail key they do not (3 of 85 plots at 3.5, 5 of 85 at 5.9)."]},
    "ws2-2": {
        "src": ["ws3/rekey120/ws2run/ws2_results.json -> q2_1.dev.none_conf_pooled.table[i] and q2_1.test.none_conf_pooled.table[i] "
                "{x, y, y_lo, y_hi, n, too_small}",
                "ws3/rekey120/ws2run/ws2_results.json -> q2_1.dev.none_conf_pooled.ece: the 0.25 in the title",
                "ws3/rekey120/ws2run/ws2_results.json -> counts: n claims 258 + 114, n fails 85 + 35"],
        "cav": ["The unit is the answer (2 repeats per claim), and the repeats are nearly identical, so the effective n "
                "is about half.",
                "Only 'none' answers are shown; the fail-flag ECE (0.168) is not.",
                "Held-out is descriptive only (ECE 0.156, 0.086 to 0.259); dev ECE interval 0.190 to 0.305.",
                "Three of the five claims the founder ruled not fails are in the held-out split and drew "
                "'none' answers, so the held-out curve moved on the re-key; the dev curve did not.",
                "Labels are Opus judgments."]},
    "ws2-3": {
        "src": ["ws3/rekey120/ws2run/ws2_results.json -> q2_2.zero_miss.C0.summary: the current-rule bar",
                "ws3/rekey120/ws2run/ws2_results.json -> q2_2.zero_miss.per_score_exploratory.K1..K7.summary: the candidate bars and "
                "their out-of-fold misses"],
        "cav": ["The K bars are exploratory; the pre-registered comparison (nested candidate 65/173, +1.2 points, "
                "0.0 to +3.0, McNemar p = 0.50) is not on the chart.",
                "Picking the tallest bar ignores the selection step.",
                "The 3 misses are the same 3 claims from one vendor.",
                "K5 to K7 let through fewer fails (1 of 85 against 3), so they sit at a different operating point; on "
                "the 120-fail key they accept 23% to 32% of passes, against 6% to 12% on the 125-fail "
                "key.",
                "Labels are Opus judgments."]},
    "ws2-4": {
        "src": ["ws3/rekey120/ws2run/ws2_results.json -> q2_3.operating_points[score=C0].sample_sizes[assumed=oof_point].n_fails_wilson "
                "and .p",
                "ws3/rekey120/ws2run/ws2_results.json -> q2_3.dev_base_rate (0.330, in the note)"],
        "cav": ["The deployed-0.8 bar assumes the in-sample miss rate of 0; the conservative +-3-point figure is 290.",
                "Assumes independent claims; fails that cluster by vendor need more.",
                "The 0.330 fail base rate is a property of how the dataset was built; at 0.10 the +-3 range means "
                "1,250 to 3,460 claims.",
                "The assumed miss rates rest on 3 and 5 fails."]},
    "ws3-1": {
        "src": ["ws3/rekey120/run/tables.json -> q31.pooled.type.<type>.fails.jev_checker_miss / .mistral_vocab_miss {rate, k, n, lo, hi}",
                "ws3/rekey120/run/tables.json -> q31.pooled.overall.fails.<model>: 'all claims'",
                "'six smaller types combined' is in no file: k and n summed over capability_feature, "
                "certification_compliance, date_event, numeric_fact, other, pricing (Jev 5/21, Mistral 4/21); its "
                "interval was computed by the renderer",
                "Error bars: added by the renderer from the same fields (lo, hi)"],
        "cav": ["Labels are mostly Opus judgments (102 of 120 fails).",
                "Intervals overlap; REPORT section 4 says 'one claim type is harder' is not supported.",
                "Checker view, not router: as a router Jev let 0 of 120 fails through.",
                "Paraphrased evidence pulls the pooled rates down (see ws3-4).",
                "Held-out is pooled in, descriptive only."]},
    "ws3-2": {
        "src": ["ws3/rekey120/run/tables.json -> q32.pooled.fails_jevchecker_x_vocab.P_col_given_row / .P_col_given_not_row "
                "{rate, lo, hi, n}: the bars",
                "ws3/rekey120/run/tables.json -> q32.pooled.fails_jevchecker_x_vocab.rate_col: the independence line (0.200)",
                "ws3/rekey120/run/tables.json -> .odds_ratio, .or_boot95, .both, .expected_both_if_independent: the note"],
        "cav": ["Mistral here is the vocab prompt run per claim, not production step 03 (prod prompt: 13/32, OR 5.34).",
                "Odds-ratio interval is a vendor-resampled bootstrap. Dev alone 3.14 (0.94 to 9.45), an interval that "
                "now spans 1; held-out alone 50 (4 to 360), unstable.",
                "The robustness arm still reads 5.30, but on this key it drops only the 4 not-in-evidence fails: the "
                "questionable-label claims it used to drop are the five now ruled out of the key.",
                "Labels are Opus judgments. Held-out pooled in, descriptive only."]},
    "ws3-3": {
        "src": ["ws3/rekey120/run/cause_codes.json -> rows[], grouped by (code, who_missed): every segment",
                "ws3/rekey120/run/cause_codes.json -> tally.by_code.<CODE>.k: the totals; tally.n_missed_by_either: 42",
                "ws3/rekey120/run/cause_codes.json -> tally.explor_PROV_NOTVIS_QLABEL: 17/42 (40%, 27 to 56) behind "
                "'two in five'"],
        "cav": ["One reader coded causes after seeing labels and model outputs: not blind.",
                "The pre-registered hypothesis (at least 30% not-in-evidence plus questionable label) failed at 10% "
                "(4 to 22); 'two in five' needs provenance-only misses added.",
                "Recorded deviations moved 7 claims between codes.",
                "Three Jev-only provenance misses come from one dossier. The 5 questionable-label fails left the key "
                "on 2026-09-22, so that bar is empty and the code is kept only because it was "
                "pre-registered."]},
    "ws3-4": {
        "src": ["ws3/rekey120/run/tables.json -> q31.pooled.verbatim.True|False.fails.jev_checker_miss / .mistral_vocab_miss "
                "{rate, k, n, lo, hi}: bars and (renderer-added) error bars",
                "ws3/explor_evidence_form.json -> True|False.fails_neg_cue and .fails: the 50 of 67 paraphrased. The "
                "verbatim cue count (14 of 58) was measured on the 125-fail key and no re-keyed copy of "
                "this file exists, so the chart note reads 'no more than 14 of the 53'."],
        "cav": ["Exploratory and confounded (-34.8 points, -50.1 to -18.4).",
                "REPORT section 4 lists 'paraphrased evidence is harder or easier' as not supported; the spec title's "
                "'because' stated a cause, and the chart title is reworded (override).",
                "The negation-cue count was added after seeing the data; the 67 mix paraphrase and transcription.",
                "All five claims ruled not fails on 2026-09-22 carried verbatim evidence, so the verbatim "
                "bars moved (58 fails to 53) and the paraphrase bars did not.",
                "Verbatim rates are the better guide to live use. Labels are Opus judgments."]},
    "ws4-1": {
        "src": ["ws4/results.json -> dvp.arms.{a,b,c} {k, n, share, Wilson}: planted defects caught",
                "ws4/results.json -> q43_clean_incumbent.arms.{a,b,c}: clean claims flagged",
                "ws4/results.json -> dvp.n_confirmed (31), q43_clean_incumbent.arms.a.n (599)"],
        "cav": ["Planted, synthetic defects, kept only if ground.py flags them (DV-P); labels are ground.py, not Opus.",
                "The arms use different catch rules: (c) counts any non-pass verdict; (a), (b) need the flag to point "
                "at the claim.",
                "4 of the 7 (c) catches already failed before planting; only 3 flipped (ws4-4).",
                "31 defects in 22 vendors, dev side only; one model, one prompt."]},
    "ws4-2": {
        "src": ["ws4/results.json -> dvp.arms.{a,b} and dvp.arms_sensitivity.c: planted defects caught",
                "ws4/results.json -> q43_clean_incumbent.arms.{a,b} and .arms_sensitivity.c: clean claims flagged"],
        "cav": ["Exploratory sensitivity rule, not the registered one.",
                "Text-overlap match: a model that describes a defect without quoting it gets no credit.",
                "(c) by flag match against (a): p = 0.25.",
                "Planted synthetic defects, 31 in 22 vendors, dev side only; conservative 2-repeat rule."]},
    "ws4-3": {
        "src": ["ws4/results.json -> cost[\"incumbent/{a,b,c}\"].cost_per_dossier_usd (x100 = US cents)",
                "ws4/results.json -> unit_counts.incumbent (sum 609), registered_primary.arms.a.n (1)"],
        "cav": ["Costs cover only the 23 unmodified incumbent drafts, both repeats.",
                "Each call re-sends about 16,000 prompt tokens, so per-claim cost grows with claim count.",
                "Arm (c) made 562 calls per repeat for 609 claims (table rows share a call).",
                "One model, served mostly by one inference provider."]},
    "ws4-4": {
        "src": ["ws4/results.json -> dvp_before_after.counts (3 / 4 / 23 / 1, n 31)"],
        "cav": ["Exploratory; McNemar on the flips (3 vs 1) p = 0.625 (dvp_before_after.mcnemar_p).",
                "Per-claim verdict rule, 2 repeats. The one-call check flagged none of the 31, before or after.",
                "Planted synthetic defects, 31 in 22 vendors, dev side only."]},
    "ws5-1": {
        "src": ["ws5/rekey120/results.json -> 5.1.jev.L.<arm> and 5.1.mistral.L.<arm> {p, lo, hi, n}: the bars",
                "ws5/rekey120/results.json -> 5.1.mistral.L_pooled / 5.1.jev.L_pooled {k, n, p}: the 57 of 120 and "
                "0 of 156",
                "n claims 80 and n fails 40 are hard-coded in ws5/make_charts.py; 80 still equals "
                "5.1.*.n_fail_claims + n_pass_claims, and the fail count is re-keyed to 39 in the override"],
        "cav": ["Recorded fails are answer-key labels, mostly Opus judgments. Dev only.",
                "The two 'stopped' rules and denominators differ (Jev 39, Mistral 30): descriptive, not a test.",
                "Jev's rule accepts few claims (9 of 41 passes), so it had little room to be fooled.",
                "Four fixed strings appended at the end: a floor for Mistral's weakness, not proof Jev is strong.",
                "Mistral ran per claim with the vocab prompt, not as production step 03.",
                "Re-keyed 2026-09-22: S5-006 left the fail arm. Mistral had not stopped it on clean evidence, so "
                "Mistral's 57 of 120 is the figure the run produced on either key."]},
    "jev-1": {
        "src": ["ws5/rekey120/results.json -> 5.1.jev.L.<arm> {k, n}: recorded fails accepted per style (0 of 39 each); "
                "the clean arm is 0 of 39 by definition (5.1.jev.clean_stop_fails, all 39 stopped on clean)",
                "ws5/rekey120/results.json -> 5.1.jev.passes_stop_share.<arm> {k, n}: passes accepted = n - k "
                "(9, 10, 7, 3, 4, 0 of 41)",
                "ws5/rekey120/results.json -> 5.1.jev.L_pooled {k 0, n 156, hi 0.024}: the title and note",
                "Authored 2026-09-26 by charts/build_jev_spec.py into specs/jev.json; Wilson 95% computed there"],
        "cav": ["Jev only: the comparison with the per-claim validator (ws5-1) is held with the internal note.",
                "Jev's rule accepts few claims (9 of 41 passes on clean), so it had little room to be fooled.",
                "Four fixed strings, one placement each; not proof Jev cannot be steered.",
                "Pass-side counts are exploratory (41 claims per style). Recorded labels are mostly Opus judgments. Dev only."]},
    "ws5-2": {
        "src": ["ws5/rekey120/results.json -> 5.2.B_share and 5.2.W_share: pass/fail bars",
                "ws5/rekey120/results.json -> 5.2.finding_between_disagreement and "
                "5.2.finding_within_flip_any_provider: 7-option bars",
                "ws5/rekey120/results.json -> 5.2.n_evaluable_B (60); 5.2.B_by_key.fail.n (29)"],
        "cav": ["0 of 60 only rules out disagreement above about 6%. Dev only, one day, one session.",
                "The 7-option measure is exploratory; every change was a fail that stayed a fail.",
                "The pinned providers serve at different precision (fp8, bf16, fp8).",
                "Labels are mostly Opus judgments; REPORT section 4: does not support 'hosting never matters'.",
                "Re-keyed 2026-09-22: S4c-032 left the fail arm. Both plotted shares are counted over all 60 "
                "claims whatever the key says about them, so neither bar moves."]},
    "ws5-3": {
        "src": ["ws5/rekey120/results.json -> "
                "5.2.per_provider.<DeepInfra|Parasail|Venice|unpinned>.catch_rate_on_fails_majority {p, lo, hi, n}"],
        "cav": ["Answer-key labels, mostly Opus judgments. n = 29 fails, dev only, one day.",
                "Majority verdicts are identical on every route, so the four bars are not four independent confirmations.",
                "Default routing mix shifts between runs.",
                "Mistral per claim with the vocab prompt, not production step 03.",
                "Re-keyed 2026-09-22: S4c-032 left the fail arm. Every route had passed it on all 3 repeats, so it "
                "was one of the 6 not caught; the count holds at 24 and the denominator moves, 30 to 29."]},
    "ws10-1": {
        "src": ["ws10/results.json -> flip_share.any.<arm> {share, flipped, n, wilson95} (x100)",
                "ws10/results.json -> n_primary (22); screening.detail.stage_A (22 planted, both baseline calls fail)",
                "split: ws10/REPORT.md Status line and PREREG.md section 3 (not in results.json)"],
        "cav": ["Planted, synthetic, blatant defects (2 scores moved 3-4 steps, a headline figure x50, 2 made-up rows).",
                "22 dossiers, one per vendor, 2 repeats, dev split; one validator (Mistral Small 3.2 24B, temperature 0), "
                "one prompt.",
                "Instruction at end vs clean: p = 0.016 (Holm 0.031). Inside the quote: p = 0.25, not shown, which is not "
                "the same as no effect.",
                "The in-quote placement is the realistic one."]},
    "ws10-2": {
        "src": ["ws10/results.json -> flip_share.both.<arm> {share, flipped, n, wilson95} (x100)"],
        "cav": ["Under the both-repeats rule, instruction at end vs clean is +18.2 points, p = 0.125 (Holm 0.25): not "
                "significant.",
                "Same planted-defect and single-validator caveats as ws10-1."]},
    "ws10-3": {
        "src": ["ws10/results.json -> flip_share.any.{N_end, N_quote, I_end, I_quote, F_I_end, F_I_quote}.share (x100)",
                "ws10/results.json -> flip_share.any.C0 and .F_clean: the two reference lines (0)",
                "Error bars: added by the renderer from flip_share.any.<arm>.wilson95"],
        "cav": ["'Works best at the end' is exploratory: I_quote vs I_end p = 0.125.",
                "'Fencing cut' was not shown: F_I_end vs I_end p = 0.125; REPORT reads it as 'may help; not shown'.",
                "The fence is one label wording. Same planted-defect caveats as ws10-1."]},
    "ws10-4": {
        "src": ["ws10/results.json -> call_level.<arm>.pass / .calls (44 per arm)"],
        "cav": ["Calls come in pairs per dossier, so they are not independent; one vendor gives 8 of the 25 "
                "instruction-arm passes.",
                "Temperature 0 is not deterministic, but the clean rerun passed 0 of 44 calls.",
                "No intervals: the spec has none and calls are clustered, so a call-level Wilson interval would be too narrow."]},
    "ws10-5": {
        "src": ["ws10/results.json -> screening.counts.stage_A {screened, kept} (23, 23); .stage_B (0, 0) is not "
                "plotted because stage B was not run",
                "ws10/results.json -> natural_vendors (['Vendor 9']): the unmodified 23rd dossier",
                "ws10/REPORT.md section 2.1: 22/22 planted plus 1/1 natural (unmodified) dossier"],
        "cav": ["Stage B was not run (REPORT section 4); results.json stores 0 / 0, and the chart labels it 'not run' "
                "instead of drawing zero bars (override).",
                "The 23 includes one unmodified 'natural' dossier outside the primary n of 22.",
                "In 42 of 44 screening calls on planted dossiers both planted scores were marked major (REPORT 2.1).",
                "Synthetic defects, dev split. The spec title said 22; the chart title now says 23 to match the bars "
                "and names the unmodified 23rd dossier (override)."]},
}
LIVE_CAV = ["Labels are Opus judgments, not a person's; F.3 (the founder's 60 labels) measures the gap.",
            "Claims cluster by vendor; the Wilson intervals treat them as independent."]
NOTES_OWN = {
    "adj-1": LIVE_CAV + ["Small sample: 5 vendors, 110 claims, 9 fails; the 0 of 9 upper bound is 30%.",
                         "Thresholds were not tuned on these labels and must not be tuned on 9 fails.",
                         "Live claims from re-drafted dossiers, not a random sample of published claims."],
    "adj-2": LIVE_CAV + ["9 fails only: 0 of 9 caught has an upper bound of 30%.",
                         "Neither production gate compares a claim with the wording of its cited page.",
                         "Three claims pass on their cited page but are false per a web check (stale pages); no "
                         "source-support check can catch those."],
    "adj-3": LIVE_CAV + ["Descriptive only (adj/REPORT.md caveats): 1 to 4 fails per section.",
                         "One score row states [UNKNOWN] and was recorded as 0."],
    "f4-1": LIVE_CAV + ["One Jev version (typesafe/jev-1.13-20260917), one route, one moment.",
                        "Three vendors give 33 of the 111 accepts; a vendor-clustered bootstrap is uninformative at 0 bad.",
                        "The sample of non-accepts is 37 claims: the weighted 'about 30 bad' among 369 is loose (10 to 79)."],
    "f4-2": LIVE_CAV + ["Where the 0 of 127 comes from: 127 = 16 pilot accepts (F.2, the 5 WS1 dossiers, "
                        "ws1/shadow_claims.jsonl) plus 111 scale-up accepts (F4, 22 other dossiers, "
                        "f4/shadow_claims.jsonl), counting accept_B_conservative on in-scope primary rows. Blind "
                        "Claude Opus reviewers labelled all 127 (F.2: adj/REPORT.md; F4: f4/adj/REPORT.md) and none "
                        "got a fail verdict (adj/results.json jev_router_curve.primary_armB t=0.8 miss.k = 0; "
                        "f4/adj/results.json primary_bad_share_armB_accepts k = 0 of 111).",
                        "89 of the 127 had no page read recorded at first review. All 89 were re-read against the "
                        "whole saved page on 2026-09-22 (82 in adj/recheck-window-only, 7 in adj/recheck-spliced): 0 "
                        "fails, and every re-read flag on them is 'none'. The one minor flag in those two re-read sets "
                        "(over-specification, still a pass) is on a spliced-set claim Jev did not accept.",
                        "The pooled count and its Wilson 95% upper bound (2.9%, z = 1.959964) are computed for this "
                        "chart by build_specs.py; neither results.json stores them. The same 0 of 127 and 2.9% are "
                        "stated in f4/adj/REPORT.md line 38 and adj/recheck-window-only/REPORT.md.",
                        "F.2 and F4 cover different vendors (no WS1 vendor in F4); same rule, same Jev version.",
                        "Coverage: one vendor failed before drafting; the last 12 in the hash order were never run."],
    "f4-3": LIVE_CAV + ["Section counts come from the raw shadow-claims files, checked against the results files (asserts "
                        "in build_specs.py).",
                        "Jev gets no rubric, so dimension-score rows are never accepted by design.",
                        "The 'Pricing or right-of-reply' bars are one claim each."],
}


# QA finish of 2026-09-25 (charts/QA-FINISH-2026-09-25.md): the ten charts the article uses, each checked against
# its primary files. Charts not listed here were not re-checked in that pass.
HELD = "HELD with Finding 6: numbers checked, not releasable until Finding 6 is released."
CHECKED = {
    "f4-2": "Checked 2026-09-25. 16 + 111 = 127 accepts recounted from ws1/ and f4/ shadow_claims.jsonl; 0 bad in "
            "adj/results.json and f4/adj/results.json; upper bounds 19.4, 3.4 and 2.9% recomputed; provenance "
            "caveat rewritten.",
    "f4-1": "Checked 2026-09-25. All four bars, n and title against f4/adj/results.json.",
    "ws2-1": "Checked 2026-09-25. Spec equals ws2/make_charts.py re-run on ws3/rekey120/ws2run/ws2_results.json, minus "
             "the dropped cut -1.0 point; title 25% = 44 of 173 recorded passes, 0 of 85 fails.",
    "ws2-2": "Checked 2026-09-25. Series identical to ws2/make_charts.py on the re-keyed results; 235 and 100 answers, "
             "63 and 31 vendors, dev ECE 0.2545.",
    "ws3-2": "Checked 2026-09-25. Bars, independence line and odds ratio against ws3/rekey120/run/tables.json q32 "
             "(14 of 32, 10 of 88, 0.200, 6.067).",
    "ws3-3": "Checked 2026-09-25. Every segment against the 42 rows of ws3/rekey120/run/cause_codes.json; 'numeric' "
             "in a cause label is the ordinary word, not a vendor.",
    "adj-2": "Checked 2026-09-25. All six bars against adj/results.json production_gates and jev_checker_view.",
    "ws4-1": "Checked 2026-09-25. Title against ws4/REPORT.md lines 19-23 and 88-90; bars against ws4/results.json; the "
             "two held-out vendor names are redacted on the chart and in this entry.",
    "ws10-1": "Checked 2026-09-25, " + HELD + " Bars against ws10/results.json flip_share.any; the four dagger fields "
              "confirmed in ws10/REPORT.md lines 3-4 and PREREG.md sections 3 and 5.",
    "ws5-1": "Checked 2026-09-25, " + HELD + " Every bar and the pooled 57 of 120 and 0 of 156 against "
             "ws5/rekey120/results.json 5.1.",
}


def main():
    log = load("charts/_work/render_log.json")["charts"]
    fo = file_overrides()
    out = ["# Jev claim-triage charts (plan step F.1) - INDEX", "",
           "29 charts. Each is `<id>.png` (200 dpi) and `<id>.svg` in this folder. `render_all.py` draws them from "
           "`ws*/charts.json` (workstream specs) and `specs/adj.json`, `specs/f4.json` (authored here by "
           "`build_specs.py` from `adj/results.json` and `f4/adj/results.json`). `gen_index.py` writes this file. "
           "Problems found along the way are in `QA.md`; read it before using any chart.", "",
           "QA finish, 2026-09-25 (`QA-FINISH-2026-09-25.md`): the ten charts the article uses (f4-2, f4-1, ws2-1, "
           "ws2-2, ws3-2, adj-2, ws4-1, ws3-3, ws10-1, ws5-1) carry a 'QA status' line. ws10-1 and ws5-1 are held "
           "with Finding 6. The other 19 charts were not re-checked in that pass. Vendor-name sweep of all 29: no "
           "vendor name on any chart.", "",
           f"QA overrides: {len(fo)} charts ({', '.join(fo)}) carry fixes from the F.1 QA pass, kept in "
           "`specs/overrides.json` and applied on top of the workstream spec at render time (no `ws*/charts.json` "
           "file was edited). The takeaway, n, split and direction below are "
           "the rendered (overridden) text; each such entry has an 'F.1 QA override' line, and the chart's footnote "
           "says what changed.", "",
           "Re-key of 2026-09-22: the founder ruled five disputed WS3 labels not fails, so the answer key holds 120 "
           "recorded fails rather than 125 (`ws3/REKEY-120-REPORT.md`). Eight charts draw that key and are re-keyed "
           "through the same override file: ws2-1, ws2-2, ws2-3, ws2-4, ws3-1, ws3-2, ws3-3 and ws3-4. Their values "
           "come from the re-key working copies under `ws3/rekey120/`, and the four WS2 specs were regenerated by "
           "the workstream's own `ws2/make_charts.py` run against the re-keyed results. The `ws*/charts.json` files "
           "still hold the 2026-09-21 figures, as every other workstream record does. `charts/REKEY-120-CHARTS.md` "
           "lists each chart's old and new numbers.", "",
           "Conventions on every chart: plain-English takeaway as the title; n, split and direction in the subtitle; "
           "Wilson 95% error bars wherever an interval exists; Okabe-Ito colours plus a marker, dash or hatch per series. "
           "A dagger (+) on the chart marks a field the workstream spec left out and the renderer filled from its "
           "REPORT.md. Paths below are relative to `spike/out/exp/`.", ""]
    for key, rel in SOURCES:
        specs = load(rel)
        out += [f"## {key}", ""]
        for i, spec in enumerate(specs, 1):
            cid = f"{key}-{i}"
            spec = json.loads(json.dumps(spec))  # private copy; overrides apply exactly as in render_all.py
            ov = dict(OVERRIDES.get(cid, {}))
            qa_ops = apply_file_overrides(cid, spec, ov, fo)
            fill = ov.get("fill", {})
            lg = log.get(cid, {})
            def val(k):
                v = spec.get(k)
                if v in (None, "") and k in fill:
                    return f"{fill[k]} (+ filled from REPORT.md)"
                return v
            nc, nf = val("n_claims"), val("n_recorded_fails")
            if spec.get("n_claims_note"):
                nc = f"{nc} ({spec['n_claims_note']})"
            if spec.get("n_recorded_fails_note"):
                nf = f"{nf} ({spec['n_recorded_fails_note']})"
            out += [f"### {cid}", "",
                    f"- Files: `{cid}.png`, `{cid}.svg` (spec: `{rel}`, entry {i})"]
            if cid in CHECKED:
                out.append(f"- QA status: {CHECKED[cid]}")
            out += [f"- Takeaway: {spec['title']}",
                    f"- n claims: {nc}; n recorded fails: {nf}",
                    f"- Split: {val('split')}",
                    f"- Direction: {val('direction')}"]
            if lg.get("renderer_notes"):
                out.append("- Renderer departures: " + "; ".join(lg["renderer_notes"]))
            if qa_ops:
                out.append(f"- F.1 QA override (`specs/overrides.json` \"{cid}\"): {fo[cid]['reason']} "
                           f"Operations: {'; '.join(qa_ops)}.")
            srcs = spec.get("sources") or NOTES.get(cid, {}).get("src", ["NOT DOCUMENTED"])
            out.append("- Source of every plotted number:")
            out += [f"  - {s}" for s in srcs]
            cav = NOTES_OWN.get(cid) or NOTES.get(cid, {}).get("cav", [])
            out.append("- Caveats that travel with it:")
            out += [f"  - {c}" for c in cav]
            out.append("")
    text = "\n".join(out)
    for rx, rep in REDACT:  # the same vendor-name redaction render_all.py applies on the charts
        text = rx.sub(rep, text)
    with open(os.path.join(HERE, "INDEX.md"), "w", encoding="utf-8") as f:
        f.write(text)
    print("INDEX.md entries:", sum(len(load(rel)) for _, rel in SOURCES))


if __name__ == "__main__":
    main()
