OpenIslet

scripts/verify_iip0044_foundry_v1_3_biologics.py

IIP-0044 / DEC-123 (CAND-035 / EXP-032): OpenIslet Foundry v1.3 Clean-Room

script Release v0.8.0 gen-eb955f8266035aba 619 KB · 44 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0044_foundry_v1_3_biologics.py · SHA-256: 1d6c53a0817f6254…

    )
    require_cond(
        md["matched_neg_CLIP1"]["pass_md_gate"] is md_clip_derived,
        "Comp2 CLIP1 NEG MD pass_md_gate contradicts structured RMSD/pep_retention",
    )
    md_gate_derived = "PASS" if (md_wt_derived and not md_clip_derived) else "FAIL"
    require_cond(
        c2_by_gate["Explicit-Solvent 10 ns OpenMM 8.6.1 MD (n=1)"]["result"] == md_gate_derived,
        f"Comp2 10 ns MD gate verdict contradiction: derived {md_gate_derived}",
    )
    require_cond(md["on_target_WT15"]["pass_md_gate"] is False, "Comp2 WT15 10 ns MD must be FAIL (pass_md_gate=false)")
    require_cond(abs(md["on_target_WT15"]["binder_rmsd_A"] - 2.748) <= 1e-6 and abs(md["on_target_WT15"]["pep_retention"] - 0.672) <= 1e-6, "Comp2 WT15 MD numbers mismatch")
    require_cond(md["matched_neg_CLIP1"]["pass_md_gate"] is True, "Comp2 CLIP1 NEG MD pass_md_gate=true disclosure missing")
    require_cond(abs(md["matched_neg_CLIP1"]["binder_rmsd_A"] - 2.527) <= 1e-6 and abs(md["matched_neg_CLIP1"]["pep_retention"] - 0.726) <= 1e-6, "Comp2 CLIP1 NEG MD numbers mismatch")

    # Derive Comp2 gate 10 (Cocktail Compatibility) from explicit OpenFold3 <= 0.25 & Boltz-2 MIT <= 0.20 per-seed arrays (B5 + M2!)
    ck = c2["cocktail_compatibility_and_homodimer_flag"]
    het = ck["heterodimer_T006_plus_QF09_pI2"]
    of3_het_thr = Decimal(str(het.get("openfold3_heterodimer_threshold_iptm")))
    b2_het_thr = Decimal(str(het.get("boltz2_mit_heterodimer_threshold_iptm")))
    require_cond(of3_het_thr == Decimal("0.25"), f"OpenFold3 heterodimer threshold must be 0.25, got {of3_het_thr}")
    require_cond(b2_het_thr == Decimal("0.20"), f"Boltz-2 MIT heterodimer threshold must be 0.20, got {b2_het_thr}")
    of3_het_vals = [Decimal(str(x)) for x in het["openfold3_0_5_1_iptms"]]
    b2_het_vals = [Decimal(str(x)) for x in het["boltz2_mit_iptms"]]
    require_cond(len(of3_het_vals) == 3 and len(b2_het_vals) == 3, "Heterodimer per-seed arrays must contain 3 values each")
    derived_of3_pass_3_of_3 = all(x <= of3_het_thr for x in of3_het_vals)
    derived_b2_n_le_020 = sum(1 for x in b2_het_vals if x <= b2_het_thr)
    require_cond(
        het["openfold3_pass_3_of_3"] is derived_of3_pass_3_of_3,
        f"OpenFold3 heterodimer openfold3_pass_3_of_3={het['openfold3_pass_3_of_3']} contradicts derived {derived_of3_pass_3_of_3} from {het['openfold3_0_5_1_iptms']} <= {of3_het_thr}",
    )
    require_cond(
        het["boltz2_mit_n_le_020_of_3"] == derived_b2_n_le_020,
        f"Boltz-2 MIT heterodimer boltz2_mit_n_le_020_of_3={het['boltz2_mit_n_le_020_of_3']} contradicts derived {derived_b2_n_le_020} from {het['boltz2_mit_iptms']} <= {b2_het_thr}",
    )
    ck_sub_passes = [
        Decimal(str(ck["homodimer_T006_protenix_flag"]["max_iptm"])) <= Decimal("0.25"),
        Decimal(str(het["protenix_max_iptm"])) <= Decimal("0.25"),
        derived_of3_pass_3_of_3,
        derived_b2_n_le_020 == len(b2_het_vals),
    ]
    ck_gate_derived = "PASS" if all(ck_sub_passes) else ("FAIL" if not any(ck_sub_passes) else "PARTIAL")
    require_cond(
        c2_by_gate["Cocktail Compatibility (T006 + QF09_pI2 & Monomer)"]["result"] == ck_gate_derived,
        f"Comp2 Cocktail Compatibility verdict contradiction: derived {ck_gate_derived}",
    )
    require_cond(abs(ck["homodimer_T006_protenix_flag"]["max_iptm"] - 0.6691) <= 1e-6, "Comp2 Protenix homodimer 0.6691 flag mismatch")
    require_cond(het["openfold3_pass_3_of_3"] is True, "OpenFold3 heterodimer 3/3 PASS mismatch")
    require_cond(het["boltz2_mit_n_le_020_of_3"] == 2, "Boltz-2 MIT heterodimer 2/3 <= 0.20 mismatch")

    comps = c2["shipped_comparators"]
    require_cond(
        set(comps.keys()) == {"SHIELD2_QQ", "R3_shv2_stk1", "SH2_MP01", "SH2_MP06", "SH2_MP08"},
        f"Comp2 comparator set mismatch: {sorted(comps.keys())}",
    )

    # 6. Program 2: Islet-SORT (including open ITGA2 inversion & non-convergence disclosure!)
    sort_p = summary["programs"]["Islet_SORT"]
    sort_sc = side_contract["programs_registered"]["Islet_SORT"]
    require_cond(sort_p["live_odds_credit_pp"] == 0.0 and sort_sc["live_odds_credit_pp"] == 0.0, "Islet-SORT live_odds_credit_pp must be 0.0")
    require_cond(sort_p["lead_id"] == "IsletSORT_CD49a_t003_s10", "Islet-SORT lead mismatch")
    require_cond(sort_p["archived_sibling_id"] == "IsletSORT_CD49a_t003_s3", "Islet-SORT sibling mismatch")
    require_cond(sort_p["developability"]["len"] == 72 and sort_p["developability"]["deamidation_NG_NS"] == [], "Islet-SORT developability mismatch")
    require_cond(
        sort_p["itga2_paralog_inversion_status"] == "EXPLICITLY_OPEN_PENDING_5_TO_10_SIBLING_WETLAB_SCREEN"
        and sort_sc.get("itga2_paralog_inversion_open") is True,
        "Islet-SORT ITGA2 paralog inversion must be explicitly OPEN in both summary and side contract",
    )
    require_cond(
        sort_p["tier1_protenix_audit"]["wt_itga1_3xMan3_Mg_n6"]["convergence_le_2p5A_demonstrated"] is False,
        "Islet-SORT non-convergence disclosure missing",
    )

    # 7. Program 3: Islet-GUARD (including explicit MD 5.487 A FAIL, bimodal docking, and dynamic side-contract route policy!)
    guard_p = summary["programs"]["Islet_GUARD"]
    guard_sc = side_contract["programs_registered"]["Islet_GUARD"]
    require_cond(guard_p["live_odds_credit_pp"] == 0.0 and guard_sc["live_odds_credit_pp"] == 0.0, "Islet-GUARD live_odds_credit_pp must be 0.0")
    require_cond(guard_p["lead_id"] == ISLET_GUARD_CONSTRUCT_ID and guard_sc["lead_id"] == ISLET_GUARD_CONSTRUCT_ID, "Islet-GUARD lead mismatch")
    require_cond(guard_p["structural_expression_constraints"]["cys_count"] == 18, "Islet-GUARD Cys count must be 18")
    require_cond(guard_p["structural_expression_constraints"]["disulfide_bonds"] == 9, "Islet-GUARD disulfide count must be 9")
    require_cond(guard_p["structural_expression_constraints"]["n_glyc_sites_1based"] == [20, 47], "Islet-GUARD N-glyc positions must be [20, 47]")
    require_cond(
        "uniprot p07204" in str(guard_p["structural_expression_constraints"].get("reference_expectation_scope", "")).lower()
        and "unmeasured" in str(guard_p["structural_expression_constraints"].get("reference_expectation_scope", "")).lower(),
        "Islet-GUARD summary must label disulfides/glycans as UniProt P07204 reference expectations (unmeasured)",
    )
    require_cond(
        "gate 3" in str(guard_p.get("blueprint_gate_alignment", "")).lower()
        and "gate 3" in str(guard_sc.get("blueprint_gate_alignment", "")).lower(),
        "Islet-GUARD blueprint_gate_alignment must identify Blueprint Gate 3 (thrombo-inflammation / peri-graft bleeding in Route 1 context)",
    )
    require_cond(guard_p["route_restriction"]["allowed_arms"] == ["A", "X"], "Summary Islet-GUARD allowed_arms must be ['A', 'X']")
    require_cond(guard_p["route_restriction"]["disallowed_arms"] == ["B", "Y", "D"], "Summary Islet-GUARD disallowed_arms must be ['B', 'Y', 'D']")
    require_cond(guard_p["route_restriction"]["allowed_route_ids"] == ["ROUTE_1_CAO2_HYDROGEL"], "Summary Islet-GUARD allowed_route_ids must be ['ROUTE_1_CAO2_HYDROGEL']")
    require_cond(guard_sc["allowed_route_arms"] == ["A", "X"], "Side-contract Islet-GUARD allowed_route_arms must be ['A', 'X']")
    require_cond(guard_sc["disallowed_route_arms"] == ["B", "Y", "D"], "Side-contract Islet-GUARD disallowed_route_arms must be ['B', 'Y', 'D']")
    require_cond(guard_sc["allowed_route_ids"] == ["ROUTE_1_CAO2_HYDROGEL"], "Side-contract Islet-GUARD allowed_route_ids must be ['ROUTE_1_CAO2_HYDROGEL']")

    # Explicit GUARD MD 5.487 A FAIL (derived from <= 3.0 A threshold) & upstream-reported bimodal docking checks (B5!)
    guard_md = guard_p["openmm_10ns_md_n1"]
    require_cond(
        guard_md.get("verdict_verification_basis") == "LOCALLY_RECOMPUTED_FROM_STRUCTURED_METRICS",
        "Islet-GUARD MD must declare verdict_verification_basis=LOCALLY_RECOMPUTED_FROM_STRUCTURED_METRICS",
    )
    guard_md_thr = Decimal(str(guard_md.get("md_binder_rmsd_fail_gt_A")))
    require_cond(guard_md_thr == Decimal("3.0"), f"Islet-GUARD MD threshold must be 3.0 A, got {guard_md_thr}")
    guard_md_derived = Decimal(str(guard_md["binder_rmsd_A"])) <= guard_md_thr
    require_cond(
        guard_md["pass_md_gate"] is guard_md_derived,
        f"Islet-GUARD 10 ns MD pass_md_gate={guard_md['pass_md_gate']} contradicts derived {guard_md_derived} from RMSD={guard_md['binder_rmsd_A']} <= {guard_md_thr}",
    )
    require_cond(guard_md["pass_md_gate"] is False, "Islet-GUARD 10 ns MD must be FAIL (pass_md_gate=false)")
    require_cond(abs(float(guard_md["binder_rmsd_A"]) - 5.487) <= 1e-6, f"Islet-GUARD 10 ns MD binder_rmsd_A must be 5.487 A, got {guard_md['binder_rmsd_A']}")
    require_cond(abs(float(guard_md["trace_max_binder_rmsd_A"]) - 6.649) <= 1e-6, "Islet-GUARD 10 ns MD trace_max_binder_rmsd_A must be 6.649 A")
    require_cond(guard_md["stripped_heterogens"] == ["NAG"], "Islet-GUARD 10 ns MD stripped_heterogens must be ['NAG']")
    guard_bi = guard_p["tier1_matched_msa_4seed_bimodal_audit"]
    require_cond(
        guard_bi.get("verdict_verification_basis") == "UPSTREAM_REPORTED_PROVENANCE_ONLY",
        "Islet-GUARD bimodal docking audit must declare verdict_verification_basis=UPSTREAM_REPORTED_PROVENANCE_ONLY",
    )
    require_cond(
        guard_bi["WT_native_seeds_of_4"] == 2 and guard_bi["M406L_native_seeds_of_4"] == 1 and guard_bi["M406I_native_seeds_of_4"] == 0,
        f"Islet-GUARD bimodal docking seed counts mismatch: {guard_bi}",
    )

    return {
        "live_odds_credit_pp": 0.0,
        "active_pmids_verified_count": len(EXPECTED_ACTIVE_PMIDS_18),
        "core_hla_dq_pmids_verified": sorted(EXPECTED_CORE_HLA_DQ_PMIDS),
        "typed_citation_roles_verified_count": len(EXPECTED_TYPED_CITATION_ROLES),
        "typed_citation_roles_verified": dict(EXPECTED_TYPED_CITATION_ROLES),
        "recursive_citation_contradiction_surfaces_scanned": 4,
        "recursive_citation_contradiction_strings_scanned": len(all_surface_strings),
        "typed_pdb_references_verified_count": len(EXPECTED_PDB_IDS_6),
        "typed_pdb_references_verified": sorted(EXPECTED_PDB_IDS_6),
        "typed_pdb_to_primary_pmid_bound": True,
        "typed_uniprot_references_verified_count": len(EXPECTED_UNIPROT_ACCESSIONS_3),
        "typed_uniprot_references_verified": sorted(EXPECTED_UNIPROT_ACCESSIONS_3),
        "typed_uniprot_gene_and_slice_bound": True,
        "typed_insb_peptide_roles_verified": sorted(EXPECTED_INSB_REFERENCE_PEPTIDES.keys()),
        "reconstructed_76_file_sha256sums_verified": True,
        "tier1_manifest_positive_bytes_and_spdx_verified": True,
        "tier1_manifest_spdx_counts": spdx_counts,
        "excluded_tier2_carveout_count": len(t2_by_rel),
        "comp1_gates_recomputed": c1_recomp,
        "comp1_verdict_verification_basis_counts": c1_basis_counts,
        "comp2_gates_recomputed": c2_recomp,
        "comp2_verdict_verification_basis_counts": c2["verdict_verification_summary"],
        "comp2_protenix_4seed_pass": "12/12 (9/12 clash-free)",
        "comp2_dq8_offtarget_sweep": "13/14 unique peptides PASS (DQ8_glia_gamma1a FAIL modeled Protenix-v1 b_pep score 0.5289)",
        "comp2_openfold3_wt15_shift_range_derived_A": [derived_min_shift, derived_max_shift],
        "comp2_cross_engine_consensus": "FAIL (Boltz-2 MIT 23.4 A flip; OpenFold3 WT15 ejection 10.87-20.43 A; CLIP1 higher chain-pair (C,D) 0.4112-0.4227 vs WT15 0.0395-0.1486; glia-g1a sample 3 pose match 2.32 A)",
        "comp2_heterodimer_thresholds_verified": {"openfold3_iptm_le": 0.25, "boltz2_mit_iptm_le": 0.20},
        "comp2_openmm_10ns_md": "FAIL (WT15 2.748 A / 67.2% vs 70%; CLIP1 NEG 2.527 A / 72.6% pass_md_gate=true)",
        "comp2_protenix_homodimer_flag_iptm": 0.6691,
        "comp2_comparators_verified": sorted(comps.keys()),
        "islet_sort_itga2_inversion_open": True,
        "islet_guard_blueprint_gate_alignment": "Blueprint Gate 3 (thrombo-inflammation / peri-graft bleeding in Route 1 CaO2 context)",
        "islet_guard_10ns_md_fail_verified": "FAIL (5.487 A binder RMSD > 3.0 A threshold, max 6.649 A, NAG stripped, pass_md_gate=false)",
        "islet_guard_route1_arms_only": ["A", "X"],
        "islet_guard_allowed_route_ids": ["ROUTE_1_CAO2_HYDROGEL"],
        "passed": True,
    }


def verify_zero_lims_touch_invariance(repo_root: Path) -> dict[str, Any]:
    lims_checked: dict[str, dict[str, Any]] = {}
    for rel, expected_sha in FROZEN_LIMS_SHA256.items():
        p = repo_root / rel
        if not p.is_file():
            raise FileNotFoundError(f"Frozen LIMS file missing in repo: {rel}")
        actual_sha = sha256_file(p)
        require_cond(actual_sha == expected_sha, f"Frozen LIMS file mutated ({rel}): {actual_sha} != {expected_sha}")
        lims_checked[rel] = {"sha256": actual_sha, "zero_byte_untouched": True}

    pb_path = repo_root / "docs" / "STAGE-0-EXECUTION-PLAYBOOK.md"
    if not pb_path.is_file():
        raise FileNotFoundError("Missing docs/STAGE-0-EXECUTION-PLAYBOOK.md")
    pb_norm = pb_path.read_text(encoding="utf-8").replace("\r\n", "\n")
    start_tok = "#### 4.1.20 Preregistered Autologous `D1b-Auto-C v2`"
    end_tok = "<!-- END_IIP0035_PLAYBOOK_SECTION_4_1_20 -->"
    s_idx = pb_norm.find(start_tok)
    e_idx = pb_norm.find(end_tok, s_idx) if s_idx != -1 else -1
    require_cond(s_idx != -1 and e_idx != -1, "Could not locate canonical Playbook §4.1.20 boundaries")
    sec4120_sha = sha256_bytes(pb_norm[s_idx:e_idx].strip().encode("utf-8"))
    require_cond(
        sec4120_sha == EXPECTED_PLAYBOOK_SEC4120_SHA256,
        f"Playbook §4.1.20 mutated: {sec4120_sha} != {EXPECTED_PLAYBOOK_SEC4120_SHA256}",
    )
    return {
        "frozen_lims_files": lims_checked,
        "playbook_sec4120_sha256": sec4120_sha,
        "playbook_sec4120_untouched": True,
        "all_zero_lims_touch_invariants_passed": True,
    }


_EXPECTED_SHIELD_SPR_PRECEDENCE_LIST = list(_SHIELD_SPR_PRECEDENCE_ORDER)
_EXPECTED_MANDATORY_ANALYTE_STRINGS = [
    "HLA-DQ2.5 + HIP11",
    "HLA-DQ8-trans + HIP11",
    "HLA-DQ2.2 + HIP11",
    "HLA-DQ8 + native WT InsB:9-23 (15-aa SHLVEALYLVCGERG)",
]
_EXPECTED_MANDATORY_ANALYTE_SPEC_IDS = [
    "HLA-DQ2.5 + HIP11",
    "HLA-DQ8-trans + HIP11",
    "HLA-DQ2.2 + HIP11",
    "HLA-DQ8 + native WT InsB:9-23",
]
_RE_OMISSION_OR_OPTIONAL = re.compile(
    r"\b(?:omit|omitted|optional|waive|waived|skip|skipped|exclude|excluded|not\s+required)\b",
    re.IGNORECASE,
)
_RE_MD_WEAKENED_COVERAGE = re.compile(
    r"(?:"
    r"\bonly\s+(?:one|1|two|2|three|3)\s+(?:optional\s+)?(?:complex|analyte)\b"
    r"|\b(?:omit|skip|waive|optional)\s+(?:hla-dq2\.2|hla-dq2\.5|hla-dq8-trans|any\s+of\s+the\s+(?:four|4)|this\s+assay)\b"
    r"|hla-dq(?:2\.2|2\.5|8-trans)\s*\+\s*hip11[^.\n]{0,60}\b(?:optional|omit|skip|waive|not\s+required)\b"
    r")",
    re.IGNORECASE,
)
_RE_MD_CONTRADICTORY_CYTO_FAIL = re.compile(
    r"(?:off-target\s+apc\s+cytotoxicity|simultaneous\s+(?:worst[- ]donor\s+)?(?:bonferroni\s+)?lower(?:\s+bound)?|cohort[^.\n]{0,25}l97\.?5|bonferroni[^.\n]{0,25}lower)[^.\n]{0,65}`?(?:l95|l97\.?5|lower(?:_pct|\s+bound)?)\s*>\s*(?!5\.0%)\d+(?:\.\d+)?%`?",
    re.IGNORECASE,
)
_RE_MD_CONTRADICTORY_BATCH_RULE = re.compile(
    r"(?i)(?:"
    r"\b(?:1|one|single)\s+(?:distinct\s+)?(?:declared\s+)?(?:passing\s+)?(?:linked|referenced)\s+(?:expression\s+)?batch(?:es)?\b"
    r"|\b(?:>=|<=|==|=)\s*[12]\s+(?:distinct\s+)?(?:declared\s+)?(?:passing\s+)?(?:linked|referenced|independent)?\s*(?:comp[12]\s+|component\s*[12]\s+)?(?:expression\s+)?batch(?:es)?\b"
    r"|\b(?:<=|at\s+most|at\s+least|minimum\s+(?:of\s+)?)\s*(?:1|one|single|2|two|a\s+pair\s+of)\s+(?:distinct\s+)?(?:declared\s+)?(?:passing\s+)?(?:linked\s+|referenced\s+|independent\s+)?(?:comp[12]\s+|component\s*[12]\s+)?(?:expression\s+)?batch(?:es)?\b"
    r"|\bn\s*(?:>=|<=|==|=)\s*[12]\s+independent[^\n]{0,30}expression\s+batch"
    r"|\b(?:only\s+|just\s+|require(?:s|d)?\s+|permit(?:s|ted)?\s+|allow(?:s|ed|ing)?\s+)(?:1|one|single|2|two|a\s+pair\s+of)\s+(?:distinct\s+)?(?:declared\s+)?(?:passing\s+)?(?:linked\s+|referenced\s+|independent\s+)?(?:comp[12]\s+|component\s*[12]\s+)?(?:expression\s+)?batch(?:es)?\b"
    r"|\b(?:a\s+pair\s+of|(?:1|one)\s+or\s+(?:2|two)|(?:1|one|single|2|two))\s+(?:distinct\s+)?(?:declared\s+)?(?:linked\s+)?(?:passing\s+)?(?:linked\s+)?(?:comp[12]\s+|component\s*[12]\s+)?(?:expression\s+)?batch(?:es)?(?:\s+(?:is|are|will\s+be|shall\s+be|may\s+be))?\s+(?:sufficient|enough|adequate|acceptable|allowed|permitted|required|suffices?|satisf(?:y|ies))\b"
    r"|\b(?:a\s+pair\s+of|(?:1|one)\s+or\s+(?:2|two))\s+(?:distinct\s+)?(?:declared\s+)?(?:linked\s+)?(?:passing\s+)?(?:linked\s+)?(?:comp[12]\s+|component\s*[12]\s+)?(?:expression\s+)?batch(?:es)?\b"
    r"|\bfewer\s+than\s+(?:3|three)\s+(?:distinct\s+)?(?:declared\s+)?(?:linked\s+)?(?:passing\s+)?(?:expression\s+)?batch(?:es)?[^.\n]{0,30}\b(?:sufficient|enough|adequate|acceptable|allowed|permitted)\b"
    r"|\b(?:expression\s+)?batch(?:es)?(?:\s+count)?\s+(?:(?:may|can|could|should|must|will|shall)\s+be|need\s+only\s+be|needs\s+(?:only\s+)?to\s+be|is|are|be)\s+(?:as\s+low\s+as\s+|as\s+few\s+as\s+|down\s+to\s+|reduced\s+to\s+|capped\s+at\s+|limited\s+to\s+|at\s+least\s+|at\s+most\s+|a\s+minimum\s+of\s+|minimum\s+of\s+|only\s+|just\s+)?(?:1|one|single|2|two|a\s+pair|fewer\s+than\s+(?:3|three))(?!\s*(?::|\d|\.\d|%|nm|x|fold|[- ]component|[- ]way))\b"
    r"|\b(?:number|count)\s+of\s+(?:distinct\s+)?(?:declared\s+)?(?:linked\s+)?(?:passing\s+)?(?:independent\s+)?(?:expression\s+)?batch(?:es)?[^.\n]{0,45}\b(?:as\s+low\s+as|as\s+few\s+as|down\s+to|at\s+least|at\s+most|a\s+minimum\s+of|minimum\s+of|only|just|need\s+only\s+be|needs\s+(?:only\s+)?to\s+be|equals?|is|are|may\s+be|can\s+be)\s+(?:1|one|single|2|two|a\s+pair|fewer\s+than\s+(?:3|three))(?!\s*(?::|\d|\.\d|%|nm|x|fold|[- ]component|[- ]way))\b"
    r")"
)


def _extract_gate30_shield_spr_md_section(md_text: str) -> str:
    m = re.search(r"^###\s+(?:2\.2\s+)?`?Gate 30-SHIELD-SPR`?.*$", md_text, flags=re.IGNORECASE | re.MULTILINE)
    if not m:
        return ""
    rest = md_text[m.start():]
    m_end = re.search(r"^(?:###\s+(?!2\.2\b)|##\s+|---\s*$)", rest[len(m.group(0)):], flags=re.MULTILINE)
    if m_end:
        return rest[: len(m.group(0)) + m_end.start()]