#!/usr/bin/env python3
"""Bank batch-274: Rule 232 second landform/geography reference lexical expansion."""

from __future__ import annotations

import datetime as dt
import json
import re
import sqlite3

from process_ledger import ensure_schema, record_event

DB = "/mnt/donto-data/donto-resources/research/translation-training/kuku-yalanji-runpod-2026-06-30/synthetic/claude-synthetic-v1-2026-07-02/synthetic.db"
LABEL = "batch-274"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-274-second-landform-geography-reference-lexical-expansion-after-rule231-process.md"

TARGET_HEADS = {
    "mabil": "swamp",
    "karrirrangkal": "coral",
    "jalngarr": "flat rock",
    "jinali": "smooth rock",
    "kangku": "valley",
    "yalmba": "seashore",
    "kambal-kambal": "mud",
    "jalkar": "high bank",
    "janku": "hole",
    "jamba": "hillside",
}
SUPPORT = {"yinya", "yaluy", "yinyay", "ngayu", "nyajil"}
DENY_KUKU = {
    # Rule 185-186 landform targets and rejected/high-risk candidates.
    "binda-dijarr", "duli", "jamar", "kabay", "karrangkal", "kuri", "ngamar", "nganyay",
    "ngidin", "warrmba", "damu naka", "kurrkal", "ngunnga", "nurru", "nyamun", "walba-murru",
    "yikin", "jalkaraburr", "manjal",
    # High-frequency geography/object heads deliberately not part of Rule 232.
    "bubu", "baral", "kulji", "jukar", "madja", "wabarr",
}
DENY_ENGLISH = (
    "route", "travel", "cross", "crossing", "river", "water", "waterhole", "burn", "burning",
    "clear", "clearing", "cleared", "ant", "insect", "reef", "sea", "lime", "collect",
    "gather", "habitat", "ecology", "climb", "fall", "danger", "scarcity", "ownership",
    "dispute", "legal", "social", "find", "peep", "cause", "rubbish", "debris", "leaf",
    "mould", "grow", "growing", "road", "path", "track", "shortcut", "place name", "story",
    "country",
)


def js(values: list[str]) -> str:
    return json.dumps(values, ensure_ascii=False)


def row(
    seq: int,
    english: str,
    kuku: str,
    analysis: str,
    frame: str,
    words: list[str],
    evidence: str,
) -> tuple:
    return (seq, english, kuku, analysis, frame, 2, js(words), js([]), evidence, "0.86")


EVIDENCE = {
    "mabil": "Dictionary mabil noun gloss 'swamp'. Patz 3.1 supports nouns as nominal semantic content; Patz 3.7 supports yinya/yaluy/yinyay deictic support.",
    "karrirrangkal": "Dictionary karrirrangkal noun gloss 'coral' with definition 'coral crushed for lime'. Rule 232 uses coral reference only; lime/use prose stays closed. Patz 3.1 and 3.7.",
    "jalngarr": "Dictionary jalngarr noun gloss 'flat rock'. Patz 3.1 nominal source and 3.7 deictic support license bare reference only.",
    "jinali": "Dictionary jinali noun gloss 'smooth rock'. Rule 232 keeps the whole noun sense and does not open smooth-property predication. Patz 3.1 and 3.7.",
    "kangku": "Dictionary kangku noun gloss 'valley' with definition 'low gap in mountain, mountain pass'. Rule 232 uses valley reference only. Patz 3.1 and 3.7.",
    "yalmba": "Dictionary yalmba noun gloss 'seashore' with definition 'seashore, beach'. Rule 232 uses seashore reference only. Patz 3.1 and 3.7.",
    "kambal-kambal": "Dictionary kambal-kambal noun gloss 'mud', lexicalized reduplicated form. Rule 232 uses the whole headword as a noun. Patz 3.1 and 3.7.",
    "jalkar": "Dictionary jalkar noun gloss 'high bank'. Commentary contrasts jalkar-jalkar 'steep', which remains closed. Patz 3.1 and 3.7.",
    "janku": "Dictionary janku noun gloss 'hole' with definition 'hole in the ground'. Rule 232 uses hole reference only. Patz 3.1 and 3.7.",
    "jamba": "Dictionary jamba noun gloss 'hillside'. Rule 232 uses hillside reference only. Patz 3.1 and 3.7.",
}


ROWS = [
    row(1, "The swamp is here.", "Mabil yaluy.", "mabil yaluy | swamp here", "r232_landform_ref_here_mabil", ["mabil", "yaluy"], EVIDENCE["mabil"]),
    row(2, "The coral is here.", "Karrirrangkal yaluy.", "karrirrangkal yaluy | coral here", "r232_landform_ref_here_karrirrangkal", ["karrirrangkal", "yaluy"], EVIDENCE["karrirrangkal"]),
    row(3, "The flat rock is here.", "Jalngarr yaluy.", "jalngarr yaluy | flat.rock here", "r232_landform_ref_here_jalngarr", ["jalngarr", "yaluy"], EVIDENCE["jalngarr"]),
    row(4, "The smooth rock is here.", "Jinali yaluy.", "jinali yaluy | smooth.rock here", "r232_landform_ref_here_jinali", ["jinali", "yaluy"], EVIDENCE["jinali"]),
    row(5, "The valley is here.", "Kangku yaluy.", "kangku yaluy | valley here", "r232_landform_ref_here_kangku", ["kangku", "yaluy"], EVIDENCE["kangku"]),
    row(6, "The seashore is here.", "Yalmba yaluy.", "yalmba yaluy | seashore here", "r232_landform_ref_here_yalmba", ["yalmba", "yaluy"], EVIDENCE["yalmba"]),
    row(7, "The mud is here.", "Kambal-kambal yaluy.", "kambal-kambal yaluy | mud here", "r232_landform_ref_here_kambal_kambal", ["kambal-kambal", "yaluy"], EVIDENCE["kambal-kambal"]),
    row(8, "The high bank is here.", "Jalkar yaluy.", "jalkar yaluy | high.bank here", "r232_landform_ref_here_jalkar", ["jalkar", "yaluy"], EVIDENCE["jalkar"]),
    row(9, "The hole is here.", "Janku yaluy.", "janku yaluy | hole here", "r232_landform_ref_here_janku", ["janku", "yaluy"], EVIDENCE["janku"]),
    row(10, "The hillside is here.", "Jamba yaluy.", "jamba yaluy | hillside here", "r232_landform_ref_here_jamba", ["jamba", "yaluy"], EVIDENCE["jamba"]),
    row(11, "That swamp is here.", "Yinya mabil yaluy.", "yinya mabil yaluy | that swamp here", "r232_that_landform_here_mabil", ["yinya", "mabil", "yaluy"], EVIDENCE["mabil"]),
    row(12, "That coral is here.", "Yinya karrirrangkal yaluy.", "yinya karrirrangkal yaluy | that coral here", "r232_that_landform_here_karrirrangkal", ["yinya", "karrirrangkal", "yaluy"], EVIDENCE["karrirrangkal"]),
    row(13, "That flat rock is here.", "Yinya jalngarr yaluy.", "yinya jalngarr yaluy | that flat.rock here", "r232_that_landform_here_jalngarr", ["yinya", "jalngarr", "yaluy"], EVIDENCE["jalngarr"]),
    row(14, "That smooth rock is here.", "Yinya jinali yaluy.", "yinya jinali yaluy | that smooth.rock here", "r232_that_landform_here_jinali", ["yinya", "jinali", "yaluy"], EVIDENCE["jinali"]),
    row(15, "That valley is here.", "Yinya kangku yaluy.", "yinya kangku yaluy | that valley here", "r232_that_landform_here_kangku", ["yinya", "kangku", "yaluy"], EVIDENCE["kangku"]),
    row(16, "That seashore is here.", "Yinya yalmba yaluy.", "yinya yalmba yaluy | that seashore here", "r232_that_landform_here_yalmba", ["yinya", "yalmba", "yaluy"], EVIDENCE["yalmba"]),
    row(17, "That mud is here.", "Yinya kambal-kambal yaluy.", "yinya kambal-kambal yaluy | that mud here", "r232_that_landform_here_kambal_kambal", ["yinya", "kambal-kambal", "yaluy"], EVIDENCE["kambal-kambal"]),
    row(18, "That high bank is here.", "Yinya jalkar yaluy.", "yinya jalkar yaluy | that high.bank here", "r232_that_landform_here_jalkar", ["yinya", "jalkar", "yaluy"], EVIDENCE["jalkar"]),
    row(19, "That hole is here.", "Yinya janku yaluy.", "yinya janku yaluy | that hole here", "r232_that_landform_here_janku", ["yinya", "janku", "yaluy"], EVIDENCE["janku"]),
    row(20, "That hillside is here.", "Yinya jamba yaluy.", "yinya jamba yaluy | that hillside here", "r232_that_landform_here_jamba", ["yinya", "jamba", "yaluy"], EVIDENCE["jamba"]),
    row(21, "That swamp is there.", "Mabil yinya yinyay.", "mabil yinya yinyay | swamp that there", "r232_landform_that_there_mabil", ["mabil", "yinya", "yinyay"], EVIDENCE["mabil"]),
    row(22, "That coral is there.", "Karrirrangkal yinya yinyay.", "karrirrangkal yinya yinyay | coral that there", "r232_landform_that_there_karrirrangkal", ["karrirrangkal", "yinya", "yinyay"], EVIDENCE["karrirrangkal"]),
    row(23, "That flat rock is there.", "Jalngarr yinya yinyay.", "jalngarr yinya yinyay | flat.rock that there", "r232_landform_that_there_jalngarr", ["jalngarr", "yinya", "yinyay"], EVIDENCE["jalngarr"]),
    row(24, "That smooth rock is there.", "Jinali yinya yinyay.", "jinali yinya yinyay | smooth.rock that there", "r232_landform_that_there_jinali", ["jinali", "yinya", "yinyay"], EVIDENCE["jinali"]),
    row(25, "That valley is there.", "Kangku yinya yinyay.", "kangku yinya yinyay | valley that there", "r232_landform_that_there_kangku", ["kangku", "yinya", "yinyay"], EVIDENCE["kangku"]),
    row(26, "That seashore is there.", "Yalmba yinya yinyay.", "yalmba yinya yinyay | seashore that there", "r232_landform_that_there_yalmba", ["yalmba", "yinya", "yinyay"], EVIDENCE["yalmba"]),
    row(27, "That mud is there.", "Kambal-kambal yinya yinyay.", "kambal-kambal yinya yinyay | mud that there", "r232_landform_that_there_kambal_kambal", ["kambal-kambal", "yinya", "yinyay"], EVIDENCE["kambal-kambal"]),
    row(28, "That high bank is there.", "Jalkar yinya yinyay.", "jalkar yinya yinyay | high.bank that there", "r232_landform_that_there_jalkar", ["jalkar", "yinya", "yinyay"], EVIDENCE["jalkar"]),
    row(29, "That hole is there.", "Janku yinya yinyay.", "janku yinya yinyay | hole that there", "r232_landform_that_there_janku", ["janku", "yinya", "yinyay"], EVIDENCE["janku"]),
    row(30, "That hillside is there.", "Jamba yinya yinyay.", "jamba yinya yinyay | hillside that there", "r232_landform_that_there_jamba", ["jamba", "yinya", "yinyay"], EVIDENCE["jamba"]),
    row(31, "That swamp is there.", "Yinya mabil yinyay.", "yinya mabil yinyay | that swamp there", "r232_that_landform_there_mabil", ["yinya", "mabil", "yinyay"], EVIDENCE["mabil"]),
    row(32, "That coral is there.", "Yinya karrirrangkal yinyay.", "yinya karrirrangkal yinyay | that coral there", "r232_that_landform_there_karrirrangkal", ["yinya", "karrirrangkal", "yinyay"], EVIDENCE["karrirrangkal"]),
    row(33, "That flat rock is there.", "Yinya jalngarr yinyay.", "yinya jalngarr yinyay | that flat.rock there", "r232_that_landform_there_jalngarr", ["yinya", "jalngarr", "yinyay"], EVIDENCE["jalngarr"]),
    row(34, "That smooth rock is there.", "Yinya jinali yinyay.", "yinya jinali yinyay | that smooth.rock there", "r232_that_landform_there_jinali", ["yinya", "jinali", "yinyay"], EVIDENCE["jinali"]),
    row(35, "That valley is there.", "Yinya kangku yinyay.", "yinya kangku yinyay | that valley there", "r232_that_landform_there_kangku", ["yinya", "kangku", "yinyay"], EVIDENCE["kangku"]),
    row(36, "That seashore is there.", "Yinya yalmba yinyay.", "yinya yalmba yinyay | that seashore there", "r232_that_landform_there_yalmba", ["yinya", "yalmba", "yinyay"], EVIDENCE["yalmba"]),
    row(37, "That mud is there.", "Yinya kambal-kambal yinyay.", "yinya kambal-kambal yinyay | that mud there", "r232_that_landform_there_kambal_kambal", ["yinya", "kambal-kambal", "yinyay"], EVIDENCE["kambal-kambal"]),
    row(38, "That high bank is there.", "Yinya jalkar yinyay.", "yinya jalkar yinyay | that high.bank there", "r232_that_landform_there_jalkar", ["yinya", "jalkar", "yinyay"], EVIDENCE["jalkar"]),
    row(39, "That hole is there.", "Yinya janku yinyay.", "yinya janku yinyay | that hole there", "r232_that_landform_there_janku", ["yinya", "janku", "yinyay"], EVIDENCE["janku"]),
    row(40, "That hillside is there.", "Yinya jamba yinyay.", "yinya jamba yinyay | that hillside there", "r232_that_landform_there_jamba", ["yinya", "jamba", "yinyay"], EVIDENCE["jamba"]),
    row(41, "I see the swamp here.", "Ngayu mabil yaluy nyajil.", "ngayu mabil yaluy nyajil | I swamp here perceive.NONPAST", "r232_1sg_landform_here_mabil", ["ngayu", "mabil", "yaluy", "nyajil"], EVIDENCE["mabil"]),
    row(42, "I see the coral here.", "Ngayu karrirrangkal yaluy nyajil.", "ngayu karrirrangkal yaluy nyajil | I coral here perceive.NONPAST", "r232_1sg_landform_here_karrirrangkal", ["ngayu", "karrirrangkal", "yaluy", "nyajil"], EVIDENCE["karrirrangkal"]),
    row(43, "I see the flat rock here.", "Ngayu jalngarr yaluy nyajil.", "ngayu jalngarr yaluy nyajil | I flat.rock here perceive.NONPAST", "r232_1sg_landform_here_jalngarr", ["ngayu", "jalngarr", "yaluy", "nyajil"], EVIDENCE["jalngarr"]),
    row(44, "I see the smooth rock here.", "Ngayu jinali yaluy nyajil.", "ngayu jinali yaluy nyajil | I smooth.rock here perceive.NONPAST", "r232_1sg_landform_here_jinali", ["ngayu", "jinali", "yaluy", "nyajil"], EVIDENCE["jinali"]),
    row(45, "I see the valley here.", "Ngayu kangku yaluy nyajil.", "ngayu kangku yaluy nyajil | I valley here perceive.NONPAST", "r232_1sg_landform_here_kangku", ["ngayu", "kangku", "yaluy", "nyajil"], EVIDENCE["kangku"]),
    row(46, "I see the seashore here.", "Ngayu yalmba yaluy nyajil.", "ngayu yalmba yaluy nyajil | I seashore here perceive.NONPAST", "r232_1sg_landform_here_yalmba", ["ngayu", "yalmba", "yaluy", "nyajil"], EVIDENCE["yalmba"]),
    row(47, "I see the mud here.", "Ngayu kambal-kambal yaluy nyajil.", "ngayu kambal-kambal yaluy nyajil | I mud here perceive.NONPAST", "r232_1sg_landform_here_kambal_kambal", ["ngayu", "kambal-kambal", "yaluy", "nyajil"], EVIDENCE["kambal-kambal"]),
    row(48, "I see the high bank here.", "Ngayu jalkar yaluy nyajil.", "ngayu jalkar yaluy nyajil | I high.bank here perceive.NONPAST", "r232_1sg_landform_here_jalkar", ["ngayu", "jalkar", "yaluy", "nyajil"], EVIDENCE["jalkar"]),
    row(49, "I see the hole here.", "Ngayu janku yaluy nyajil.", "ngayu janku yaluy nyajil | I hole here perceive.NONPAST", "r232_1sg_landform_here_janku", ["ngayu", "janku", "yaluy", "nyajil"], EVIDENCE["janku"]),
    row(50, "I see the hillside here.", "Ngayu jamba yaluy nyajil.", "ngayu jamba yaluy nyajil | I hillside here perceive.NONPAST", "r232_1sg_landform_here_jamba", ["ngayu", "jamba", "yaluy", "nyajil"], EVIDENCE["jamba"]),
]


def has_token(low: str, token: str) -> bool:
    return re.search(rf"(?<![a-z-]){re.escape(token)}(?![a-z-])", low) is not None


def has_target_morphology(low: str, head: str) -> bool:
    suffixes = "ngka|ngku|angka|nga|ngu|ba|mba|mbu|muny|darr|burr|bu|ka|nka|nku|ji|jirr|ku|mundu|amu|mu|iji|nda|ndu|anda|undu|unji|nji|kari|baka|baja|bungal|bungan|mal|man|rriny|karra|manda|bulal"
    return re.search(rf"(?<![a-z-]){re.escape(head)}-(?:{suffixes})\b", low) is not None


def english_has_denied(english_low: str, denied: str) -> bool:
    return denied in english_low if " " in denied else re.search(rf"\b{re.escape(denied.strip())}\b", english_low) is not None


def scan_static() -> list[str]:
    issues: list[str] = []
    if len(ROWS) != 50:
        issues.append(f"{LABEL}: expected 50 rows, found {len(ROWS)}")
    seen_ku: set[str] = set()
    for expected, row_data in enumerate(ROWS, start=1):
        seq, english, kuku, analysis, frame, _tier, words_used, loans_used, evidence, confidence = row_data
        label = f"{LABEL}.{seq:02d}"
        low = kuku.lower()
        english_low = english.lower()
        words = json.loads(words_used)
        if seq != expected:
            issues.append(f"{label}: sequence mismatch; expected {expected}")
        if not english[:1].isupper() or english[-1:] not in ".!?":
            issues.append(f"{label}: English punctuation/capitalization failure")
        if " | " not in analysis:
            issues.append(f"{label}: analysis missing gloss separator")
        if not frame.startswith("r232_"):
            issues.append(f"{label}: Rule 232 frame must start with r232_")
        if low in seen_ku:
            issues.append(f"{label}: duplicate Kuku surface within batch")
        seen_ku.add(low)
        if json.loads(loans_used):
            issues.append(f"{label}: no loans are admitted in Rule 232")
        for denied in DENY_KUKU:
            if has_token(low, denied):
                issues.append(f"{label}: denied landform/geography token {denied!r}")
        targets = [head for head in TARGET_HEADS if has_token(low, head)]
        if len(targets) != 1:
            issues.append(f"{label}: expected exactly one Rule 232 target noun, found {targets}")
        for head in targets:
            selected = TARGET_HEADS[head]
            dotted = selected.replace("-", ".").replace(" ", ".")
            if head not in words:
                issues.append(f"{label}: target head {head} missing from words_used")
            if selected not in english_low:
                issues.append(f"{label}: English must include selected sense {selected!r}")
            if selected not in analysis and dotted not in analysis:
                issues.append(f"{label}: analysis must gloss {head} as {selected}")
            if has_target_morphology(low, head):
                issues.append(f"{label}: target head {head} has forbidden morphology")
        for support in SUPPORT:
            if has_token(low, support) and support not in words:
                issues.append(f"{label}: support {support} missing from words_used")
        if 1 <= seq <= 10 and (has_token(low, "yinya") or has_token(low, "yinyay") or not low.endswith(" yaluy.") or len(low.split()) != 2):
            issues.append(f"{label}: rows 1-10 require TARGET yaluy")
        if 11 <= seq <= 20 and (not low.startswith("yinya ") or has_token(low, "yinyay") or not low.endswith(" yaluy.") or len(low.split()) != 3):
            issues.append(f"{label}: rows 11-20 require Yinya TARGET yaluy")
        if 21 <= seq <= 30 and (not has_token(low, "yinya") or has_token(low, "yaluy") or not low.endswith(" yinyay.") or len(low.split()) != 3 or low.startswith("yinya ")):
            issues.append(f"{label}: rows 21-30 require TARGET yinya yinyay")
        if 31 <= seq <= 40 and (not low.startswith("yinya ") or has_token(low, "yaluy") or not low.endswith(" yinyay.") or len(low.split()) != 3):
            issues.append(f"{label}: rows 31-40 require Yinya TARGET yinyay")
        if 41 <= seq <= 50 and (not low.startswith("ngayu ") or not low.endswith(" yaluy nyajil.") or has_token(low, "yinyay") or len(low.split()) != 4):
            issues.append(f"{label}: rows 41-50 require Ngayu TARGET yaluy nyajil")
        if any(english_has_denied(english_low, bad) for bad in DENY_ENGLISH):
            issues.append(f"{label}: denied landform source-prose field in English")
        if not evidence or not confidence:
            issues.append(f"{label}: missing evidence/confidence")
    return issues


def main() -> int:
    issues = scan_static()
    if issues:
        print("pre-bank scan failed:")
        for issue in issues:
            print(f"  - {issue}")
        return 1

    db = sqlite3.connect(DB)
    db.execute("PRAGMA foreign_keys = ON")
    db.execute("BEGIN")
    ensure_schema(db)
    existing = db.execute("SELECT id FROM batches WHERE label=?", (LABEL,)).fetchone()
    if existing:
        batch_id = existing[0]
        accepted = db.execute(
            "SELECT COUNT(*) FROM sentences WHERE batch_id=? AND status IN ('accepted','revised')",
            (batch_id,),
        ).fetchone()[0]
        if accepted:
            raise SystemExit(f"{LABEL} already has accepted/revised rows; refusing to overwrite")
        db.execute("DELETE FROM reviews WHERE sentence_id IN (SELECT id FROM sentences WHERE batch_id=?)", (batch_id,))
        db.execute("DELETE FROM sentences WHERE batch_id=?", (batch_id,))
    else:
        db.execute(
            "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
            (LABEL, "Rule 232 draft", "operator-guide-2026-07-08", "draft under review", NOW),
        )
        batch_id = db.execute("SELECT id FROM batches WHERE label=?", (LABEL,)).fetchone()[0]

    collisions: list[str] = []
    for seq, _english, kuku, *_rest in ROWS:
        found = db.execute(
            """
            SELECT b.label, s.seq, s.status
            FROM sentences s JOIN batches b ON b.id=s.batch_id
            WHERE lower(s.kuku)=lower(?) AND s.status IN ('accepted','revised','under_review')
            """,
            (kuku,),
        ).fetchall()
        if found:
            collisions.append(f"{seq:02d} {kuku}: {found}")
    if collisions:
        raise SystemExit("duplicate preflight failed:\n" + "\n".join(collisions))

    record_event(
        db,
        batch_label=LABEL,
        phase="source",
        event_type="source-pass",
        actor="claude-main",
        detail="Checked Patz section 3.1 nominal word-class support, Patz section 3.7 yinya/yaluy/yinyay demonstrative support, Patz nyaji-l perception examples, and all ten dictionary entries for the Rule 232 landform/geography heads: mabil, karrirrangkal, jalngarr, jinali, kangku, yalmba, kambal-kambal, jalkar, janku, and jamba.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="scope",
        event_type="lexical-scope",
        actor="claude-main",
        detail="Rule 232 admits a second landform/geography lexical field in bare deictic and 1sg perception frames only. It excludes Rule 185-186 selected heads, rejected landform candidates, place-name/route/travel/water-use/event/ecology/source-prose drift, target case, target compounds, productive reduplication, support inflection, and all Rule 231 named-tree perception drift.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="duplicate-preflight",
        actor="claude-main",
        detail="Exact duplicate preflight over all 50 planned Rule 232 Kuku surfaces returned no accepted, revised, or under-review collisions.",
        command="sqlite3 exact lower(kuku) collision scan for 50 planned surfaces",
        output_excerpt="collisions=0",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="static-guard-pass",
        actor="claude-main",
        detail="bank_274.py static guards passed: 50 explicit hand-authored rows, exactly one Rule 232 landform target noun per row, no loans, no target morphology, no Rule 185-186 target token, no rejected landform candidate, no landform source-prose English, four deictic frame bands, and one sourced 1sg nonpast perception band.",
        artifact_path="batch_scripts/bank_274.py",
        created_at=NOW,
    )

    db.executemany(
        """
        INSERT INTO sentences(
          batch_id, seq, english, kuku, analysis, frame, tier, words_used,
          loans_used, evidence, status, confidence, created_at, updated_at
        )
        VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (batch_id, seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, "under_review", confidence, NOW, NOW)
            for seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, confidence in ROWS
        ],
    )
    db.commit()

    n = db.execute("SELECT COUNT(*) FROM sentences WHERE batch_id=? AND status='under_review'", (batch_id,)).fetchone()[0]
    print(f"banked {LABEL}: {n} under_review rows")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
