#!/usr/bin/env python3
"""Bank batch-344: Rule 302 complementary insect singular/third-person past perception."""

from __future__ import annotations

import datetime as dt
import json
import re
import sqlite3

from bank_343 import DENY_ENGLISH, DENY_KUKU, TARGET_ORDER, count_words
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-344"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-344-complementary-insect-singular-third-past-perception-after-rule301-process.md"

TARGET_EVIDENCE = {
    "balarr": "Dictionary yaml line 833 gives balarr as noun 'flea'. Rule 302 selects visible flea reference only and leaves body, bite, sickness, pest-control, and event rows closed.",
    "dijaraban": "Dictionary yaml line 5542 gives dijaraban as noun 'mayfly' with a mayfly/dragonfly definition. Rule 302 retains the established mayfly label only and leaves dragonfly expansion and ecology rows closed.",
    "kalburiji": "Dictionary yaml line 12474 gives kalburiji as a species of bee. Rule 302 selects visible bee-label reference only and leaves honey, nest, egg, larvae, collecting, edible, and source-prose rows closed.",
    "mawal": "Dictionary yaml line 18743 gives mawal as a species of bee. Rule 302 selects visible bee-label reference only and leaves honey, nest, egg, larvae, collecting, edible, and source-prose rows closed.",
    "munudumbun": "Dictionary yaml line 20816 gives munudumbun as 'scorpion' with synonym munukurru. Rule 302 selects visible scorpion reference only and leaves synonym, sting, poison, danger, sickness, and event rows closed.",
    "munyurri": "Dictionary yaml line 20868 gives munyurri as 'sandfly' with synonym diri-diri. Rule 302 selects visible sandfly reference only and leaves synonym, biting, sickness, pest-control, and event rows closed.",
    "nakawarra": "Dictionary yaml line 21461 gives nakawarra as a species of bee. Rule 302 selects visible bee-label reference only and leaves honey, nest, collecting, edible, and source-prose rows closed.",
    "ngalmnbu": "Dictionary yaml line 21972 gives ngalmnbu as 'jumper ant'. Rule 302 selects visible ant-label reference only and leaves jumping, bite, sting, antbed, and event rows closed.",
    "yarrka": "Dictionary yaml line 29551 gives yarrka as 'bee, the smallest bee in the bush'. Rule 302 selects visible bee-label reference only and leaves smallest, bush, honey, nest, collecting, and source-prose rows closed.",
    "yiljun": "Dictionary yaml line 30019 gives yiljun as 'grasshopper' and a singing/yam-readiness usage. Rule 302 selects visible grasshopper reference only and leaves singing, yam-readiness, seasonal-signal, movement, and event rows closed.",
}

SUPPORT_EVIDENCE = (
    "Living grammar pronoun tables source bare nominative ngayu, yundu, nyulu, bula, and jana; demonstrative notes "
    "source yaluy 'here' and yinyay 'there'; Patz examples and living grammar source nyaji-ny / nyajin as past visual "
    "perception. Rule 302 uses only bare support forms."
)

FRAME_SPECS = [
    ("ngayu", "yaluy"),
    ("yundu", "yinyay"),
    ("nyulu", "yaluy"),
    ("bula", "yinyay"),
    ("jana", "yaluy"),
]


def row(seq: int, english: str, kuku: str, analysis: str, frame: str, words: list[str]) -> tuple:
    target = words[1]
    evidence = f"{TARGET_EVIDENCE[target]} {SUPPORT_EVIDENCE}"
    return (seq, english, kuku, analysis, frame, 3, json.dumps(words, ensure_ascii=False), json.dumps([], ensure_ascii=False), evidence, "0.86")


ROWS = [
    row(1, "I saw the flea here.", "Ngayu balarr yaluy nyajin.", "ngayu balarr yaluy nyajin | 1sg.NOM flea here see.PAST", "r302_1sg_here_insect_saw_balarr", ["ngayu", "balarr", "yaluy", "nyajin"]),
    row(2, "I saw the mayfly here.", "Ngayu dijaraban yaluy nyajin.", "ngayu dijaraban yaluy nyajin | 1sg.NOM mayfly here see.PAST", "r302_1sg_here_insect_saw_dijaraban", ["ngayu", "dijaraban", "yaluy", "nyajin"]),
    row(3, "I saw the kalburiji bee here.", "Ngayu kalburiji yaluy nyajin.", "ngayu kalburiji yaluy nyajin | 1sg.NOM kalburiji.bee here see.PAST", "r302_1sg_here_insect_saw_kalburiji", ["ngayu", "kalburiji", "yaluy", "nyajin"]),
    row(4, "I saw the mawal bee here.", "Ngayu mawal yaluy nyajin.", "ngayu mawal yaluy nyajin | 1sg.NOM mawal.bee here see.PAST", "r302_1sg_here_insect_saw_mawal", ["ngayu", "mawal", "yaluy", "nyajin"]),
    row(5, "I saw the scorpion here.", "Ngayu munudumbun yaluy nyajin.", "ngayu munudumbun yaluy nyajin | 1sg.NOM scorpion here see.PAST", "r302_1sg_here_insect_saw_munudumbun", ["ngayu", "munudumbun", "yaluy", "nyajin"]),
    row(6, "I saw the sandfly here.", "Ngayu munyurri yaluy nyajin.", "ngayu munyurri yaluy nyajin | 1sg.NOM sandfly here see.PAST", "r302_1sg_here_insect_saw_munyurri", ["ngayu", "munyurri", "yaluy", "nyajin"]),
    row(7, "I saw the nakawarra bee here.", "Ngayu nakawarra yaluy nyajin.", "ngayu nakawarra yaluy nyajin | 1sg.NOM nakawarra.bee here see.PAST", "r302_1sg_here_insect_saw_nakawarra", ["ngayu", "nakawarra", "yaluy", "nyajin"]),
    row(8, "I saw the jumper ant here.", "Ngayu ngalmnbu yaluy nyajin.", "ngayu ngalmnbu yaluy nyajin | 1sg.NOM jumper.ant here see.PAST", "r302_1sg_here_insect_saw_ngalmnbu", ["ngayu", "ngalmnbu", "yaluy", "nyajin"]),
    row(9, "I saw the yarrka bee here.", "Ngayu yarrka yaluy nyajin.", "ngayu yarrka yaluy nyajin | 1sg.NOM yarrka.bee here see.PAST", "r302_1sg_here_insect_saw_yarrka", ["ngayu", "yarrka", "yaluy", "nyajin"]),
    row(10, "I saw the grasshopper here.", "Ngayu yiljun yaluy nyajin.", "ngayu yiljun yaluy nyajin | 1sg.NOM grasshopper here see.PAST", "r302_1sg_here_insect_saw_yiljun", ["ngayu", "yiljun", "yaluy", "nyajin"]),
    row(11, "You saw the flea there.", "Yundu balarr yinyay nyajin.", "yundu balarr yinyay nyajin | 2sg.NOM flea there see.PAST", "r302_2sg_there_insect_saw_balarr", ["yundu", "balarr", "yinyay", "nyajin"]),
    row(12, "You saw the mayfly there.", "Yundu dijaraban yinyay nyajin.", "yundu dijaraban yinyay nyajin | 2sg.NOM mayfly there see.PAST", "r302_2sg_there_insect_saw_dijaraban", ["yundu", "dijaraban", "yinyay", "nyajin"]),
    row(13, "You saw the kalburiji bee there.", "Yundu kalburiji yinyay nyajin.", "yundu kalburiji yinyay nyajin | 2sg.NOM kalburiji.bee there see.PAST", "r302_2sg_there_insect_saw_kalburiji", ["yundu", "kalburiji", "yinyay", "nyajin"]),
    row(14, "You saw the mawal bee there.", "Yundu mawal yinyay nyajin.", "yundu mawal yinyay nyajin | 2sg.NOM mawal.bee there see.PAST", "r302_2sg_there_insect_saw_mawal", ["yundu", "mawal", "yinyay", "nyajin"]),
    row(15, "You saw the scorpion there.", "Yundu munudumbun yinyay nyajin.", "yundu munudumbun yinyay nyajin | 2sg.NOM scorpion there see.PAST", "r302_2sg_there_insect_saw_munudumbun", ["yundu", "munudumbun", "yinyay", "nyajin"]),
    row(16, "You saw the sandfly there.", "Yundu munyurri yinyay nyajin.", "yundu munyurri yinyay nyajin | 2sg.NOM sandfly there see.PAST", "r302_2sg_there_insect_saw_munyurri", ["yundu", "munyurri", "yinyay", "nyajin"]),
    row(17, "You saw the nakawarra bee there.", "Yundu nakawarra yinyay nyajin.", "yundu nakawarra yinyay nyajin | 2sg.NOM nakawarra.bee there see.PAST", "r302_2sg_there_insect_saw_nakawarra", ["yundu", "nakawarra", "yinyay", "nyajin"]),
    row(18, "You saw the jumper ant there.", "Yundu ngalmnbu yinyay nyajin.", "yundu ngalmnbu yinyay nyajin | 2sg.NOM jumper.ant there see.PAST", "r302_2sg_there_insect_saw_ngalmnbu", ["yundu", "ngalmnbu", "yinyay", "nyajin"]),
    row(19, "You saw the yarrka bee there.", "Yundu yarrka yinyay nyajin.", "yundu yarrka yinyay nyajin | 2sg.NOM yarrka.bee there see.PAST", "r302_2sg_there_insect_saw_yarrka", ["yundu", "yarrka", "yinyay", "nyajin"]),
    row(20, "You saw the grasshopper there.", "Yundu yiljun yinyay nyajin.", "yundu yiljun yinyay nyajin | 2sg.NOM grasshopper there see.PAST", "r302_2sg_there_insect_saw_yiljun", ["yundu", "yiljun", "yinyay", "nyajin"]),
    row(21, "He saw the flea here.", "Nyulu balarr yaluy nyajin.", "nyulu balarr yaluy nyajin | 3sg.NOM flea here see.PAST", "r302_3sg_here_insect_saw_balarr", ["nyulu", "balarr", "yaluy", "nyajin"]),
    row(22, "He saw the mayfly here.", "Nyulu dijaraban yaluy nyajin.", "nyulu dijaraban yaluy nyajin | 3sg.NOM mayfly here see.PAST", "r302_3sg_here_insect_saw_dijaraban", ["nyulu", "dijaraban", "yaluy", "nyajin"]),
    row(23, "He saw the kalburiji bee here.", "Nyulu kalburiji yaluy nyajin.", "nyulu kalburiji yaluy nyajin | 3sg.NOM kalburiji.bee here see.PAST", "r302_3sg_here_insect_saw_kalburiji", ["nyulu", "kalburiji", "yaluy", "nyajin"]),
    row(24, "He saw the mawal bee here.", "Nyulu mawal yaluy nyajin.", "nyulu mawal yaluy nyajin | 3sg.NOM mawal.bee here see.PAST", "r302_3sg_here_insect_saw_mawal", ["nyulu", "mawal", "yaluy", "nyajin"]),
    row(25, "He saw the scorpion here.", "Nyulu munudumbun yaluy nyajin.", "nyulu munudumbun yaluy nyajin | 3sg.NOM scorpion here see.PAST", "r302_3sg_here_insect_saw_munudumbun", ["nyulu", "munudumbun", "yaluy", "nyajin"]),
    row(26, "He saw the sandfly here.", "Nyulu munyurri yaluy nyajin.", "nyulu munyurri yaluy nyajin | 3sg.NOM sandfly here see.PAST", "r302_3sg_here_insect_saw_munyurri", ["nyulu", "munyurri", "yaluy", "nyajin"]),
    row(27, "He saw the nakawarra bee here.", "Nyulu nakawarra yaluy nyajin.", "nyulu nakawarra yaluy nyajin | 3sg.NOM nakawarra.bee here see.PAST", "r302_3sg_here_insect_saw_nakawarra", ["nyulu", "nakawarra", "yaluy", "nyajin"]),
    row(28, "He saw the jumper ant here.", "Nyulu ngalmnbu yaluy nyajin.", "nyulu ngalmnbu yaluy nyajin | 3sg.NOM jumper.ant here see.PAST", "r302_3sg_here_insect_saw_ngalmnbu", ["nyulu", "ngalmnbu", "yaluy", "nyajin"]),
    row(29, "He saw the yarrka bee here.", "Nyulu yarrka yaluy nyajin.", "nyulu yarrka yaluy nyajin | 3sg.NOM yarrka.bee here see.PAST", "r302_3sg_here_insect_saw_yarrka", ["nyulu", "yarrka", "yaluy", "nyajin"]),
    row(30, "He saw the grasshopper here.", "Nyulu yiljun yaluy nyajin.", "nyulu yiljun yaluy nyajin | 3sg.NOM grasshopper here see.PAST", "r302_3sg_here_insect_saw_yiljun", ["nyulu", "yiljun", "yaluy", "nyajin"]),
    row(31, "The two of them saw the flea there.", "Bula balarr yinyay nyajin.", "bula balarr yinyay nyajin | 3du.NOM flea there see.PAST", "r302_3du_there_insect_saw_balarr", ["bula", "balarr", "yinyay", "nyajin"]),
    row(32, "The two of them saw the mayfly there.", "Bula dijaraban yinyay nyajin.", "bula dijaraban yinyay nyajin | 3du.NOM mayfly there see.PAST", "r302_3du_there_insect_saw_dijaraban", ["bula", "dijaraban", "yinyay", "nyajin"]),
    row(33, "The two of them saw the kalburiji bee there.", "Bula kalburiji yinyay nyajin.", "bula kalburiji yinyay nyajin | 3du.NOM kalburiji.bee there see.PAST", "r302_3du_there_insect_saw_kalburiji", ["bula", "kalburiji", "yinyay", "nyajin"]),
    row(34, "The two of them saw the mawal bee there.", "Bula mawal yinyay nyajin.", "bula mawal yinyay nyajin | 3du.NOM mawal.bee there see.PAST", "r302_3du_there_insect_saw_mawal", ["bula", "mawal", "yinyay", "nyajin"]),
    row(35, "The two of them saw the scorpion there.", "Bula munudumbun yinyay nyajin.", "bula munudumbun yinyay nyajin | 3du.NOM scorpion there see.PAST", "r302_3du_there_insect_saw_munudumbun", ["bula", "munudumbun", "yinyay", "nyajin"]),
    row(36, "The two of them saw the sandfly there.", "Bula munyurri yinyay nyajin.", "bula munyurri yinyay nyajin | 3du.NOM sandfly there see.PAST", "r302_3du_there_insect_saw_munyurri", ["bula", "munyurri", "yinyay", "nyajin"]),
    row(37, "The two of them saw the nakawarra bee there.", "Bula nakawarra yinyay nyajin.", "bula nakawarra yinyay nyajin | 3du.NOM nakawarra.bee there see.PAST", "r302_3du_there_insect_saw_nakawarra", ["bula", "nakawarra", "yinyay", "nyajin"]),
    row(38, "The two of them saw the jumper ant there.", "Bula ngalmnbu yinyay nyajin.", "bula ngalmnbu yinyay nyajin | 3du.NOM jumper.ant there see.PAST", "r302_3du_there_insect_saw_ngalmnbu", ["bula", "ngalmnbu", "yinyay", "nyajin"]),
    row(39, "The two of them saw the yarrka bee there.", "Bula yarrka yinyay nyajin.", "bula yarrka yinyay nyajin | 3du.NOM yarrka.bee there see.PAST", "r302_3du_there_insect_saw_yarrka", ["bula", "yarrka", "yinyay", "nyajin"]),
    row(40, "The two of them saw the grasshopper there.", "Bula yiljun yinyay nyajin.", "bula yiljun yinyay nyajin | 3du.NOM grasshopper there see.PAST", "r302_3du_there_insect_saw_yiljun", ["bula", "yiljun", "yinyay", "nyajin"]),
    row(41, "They saw the flea here.", "Jana balarr yaluy nyajin.", "jana balarr yaluy nyajin | 3pl.NOM flea here see.PAST", "r302_3pl_here_insect_saw_balarr", ["jana", "balarr", "yaluy", "nyajin"]),
    row(42, "They saw the mayfly here.", "Jana dijaraban yaluy nyajin.", "jana dijaraban yaluy nyajin | 3pl.NOM mayfly here see.PAST", "r302_3pl_here_insect_saw_dijaraban", ["jana", "dijaraban", "yaluy", "nyajin"]),
    row(43, "They saw the kalburiji bee here.", "Jana kalburiji yaluy nyajin.", "jana kalburiji yaluy nyajin | 3pl.NOM kalburiji.bee here see.PAST", "r302_3pl_here_insect_saw_kalburiji", ["jana", "kalburiji", "yaluy", "nyajin"]),
    row(44, "They saw the mawal bee here.", "Jana mawal yaluy nyajin.", "jana mawal yaluy nyajin | 3pl.NOM mawal.bee here see.PAST", "r302_3pl_here_insect_saw_mawal", ["jana", "mawal", "yaluy", "nyajin"]),
    row(45, "They saw the scorpion here.", "Jana munudumbun yaluy nyajin.", "jana munudumbun yaluy nyajin | 3pl.NOM scorpion here see.PAST", "r302_3pl_here_insect_saw_munudumbun", ["jana", "munudumbun", "yaluy", "nyajin"]),
    row(46, "They saw the sandfly here.", "Jana munyurri yaluy nyajin.", "jana munyurri yaluy nyajin | 3pl.NOM sandfly here see.PAST", "r302_3pl_here_insect_saw_munyurri", ["jana", "munyurri", "yaluy", "nyajin"]),
    row(47, "They saw the nakawarra bee here.", "Jana nakawarra yaluy nyajin.", "jana nakawarra yaluy nyajin | 3pl.NOM nakawarra.bee here see.PAST", "r302_3pl_here_insect_saw_nakawarra", ["jana", "nakawarra", "yaluy", "nyajin"]),
    row(48, "They saw the jumper ant here.", "Jana ngalmnbu yaluy nyajin.", "jana ngalmnbu yaluy nyajin | 3pl.NOM jumper.ant here see.PAST", "r302_3pl_here_insect_saw_ngalmnbu", ["jana", "ngalmnbu", "yaluy", "nyajin"]),
    row(49, "They saw the yarrka bee here.", "Jana yarrka yaluy nyajin.", "jana yarrka yaluy nyajin | 3pl.NOM yarrka.bee here see.PAST", "r302_3pl_here_insect_saw_yarrka", ["jana", "yarrka", "yaluy", "nyajin"]),
    row(50, "They saw the grasshopper here.", "Jana yiljun yaluy nyajin.", "jana yiljun yaluy nyajin | 3pl.NOM grasshopper here see.PAST", "r302_3pl_here_insect_saw_yiljun", ["jana", "yiljun", "yaluy", "nyajin"]),
]


def scan_static() -> list[str]:
    issues: list[str] = []
    if len(ROWS) != 50:
        issues.append(f"row count {len(ROWS)} != 50")
    if [r[0] for r in ROWS] != list(range(1, 51)):
        issues.append("sequence is not 1..50")
    kukus = [r[2] for r in ROWS]
    if len(set(kukus)) != len(kukus):
        issues.append("duplicate Kuku surface inside batch")
    for seq, english, kuku, _analysis, frame, _tier, words_json, loans_json, _evidence, _confidence in ROWS:
        words = json.loads(words_json)
        loans = json.loads(loans_json)
        lower_kuku = kuku.lower()
        lower_english = english.lower()
        if loans:
            issues.append(f"{seq}: loans used {loans}")
        denied = sorted({w for w in DENY_KUKU if re.search(rf"(^|\s){re.escape(w)}([\s\.]|$)", lower_kuku)})
        if denied:
            issues.append(f"{seq}: denied Kuku forms {denied}")
        denied_english = [term for term in DENY_ENGLISH if re.search(rf"\b{re.escape(term.strip())}\b", lower_english)]
        if denied_english:
            issues.append(f"{seq}: denied English drift {denied_english}")
        target_hits = [w for w in TARGET_ORDER if w in words]
        if len(target_hits) != 1:
            issues.append(f"{seq}: target hits {target_hits}")
        if len(words) != 4:
            issues.append(f"{seq}: expected 4 words, got {words}")
        if "nyajin" not in words or not lower_kuku.endswith(" nyajin."):
            issues.append(f"{seq}: missing final nyajin")
        if "nyajil" in lower_kuku:
            issues.append(f"{seq}: nonpast nyajil leakage")
        if len([w for w in ("yaluy", "yinyay") if w in words]) != 1:
            issues.append(f"{seq}: demonstrative problem {words}")
        expected_pronoun, expected_demo = FRAME_SPECS[(seq - 1) // 10]
        if words[0] != expected_pronoun:
            issues.append(f"{seq}: expected pronoun {expected_pronoun}, got {words[0]}")
        if words[2] != expected_demo:
            issues.append(f"{seq}: expected demonstrative {expected_demo}, got {words[2]}")
        if words[1] != TARGET_ORDER[(seq - 1) % 10]:
            issues.append(f"{seq}: target order mismatch {words[1]}")
        if words[3] != "nyajin":
            issues.append(f"{seq}: word 4 is not nyajin {words[3]}")
        if lower_kuku.rstrip(".") != " ".join(words):
            issues.append(f"{seq}: Kuku does not match words_used {words}")
        if not frame.startswith("r302_"):
            issues.append(f"{seq}: frame not r302 {frame}")
    return issues


def main() -> int:
    issues = scan_static()
    if issues:
        for issue in issues:
            print(issue)
        raise SystemExit(1)

    db = sqlite3.connect(DB)
    db.execute("PRAGMA foreign_keys = ON")
    db.execute("BEGIN")
    ensure_schema(db)
    if db.execute("SELECT 1 FROM batches WHERE label=?", (LABEL,)).fetchone():
        raise SystemExit(f"{LABEL} already exists")
    collisions = []
    for _seq, _english, kuku, *_rest in ROWS:
        existing = 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!='rejected'
            """,
            (kuku,),
        ).fetchall()
        if existing:
            collisions.append((kuku, existing))
    if collisions:
        raise SystemExit(f"duplicate preflight failed: {collisions}")

    target_counts = count_words(db, TARGET_ORDER)
    support_counts = count_words(db, ["ngayu", "yundu", "nyulu", "bula", "jana", "yaluy", "yinyay", "nyajin"])
    verified_before, words_before = db.execute(
        """
        SELECT COUNT(*), SUM(LENGTH(kuku)-LENGTH(REPLACE(kuku,' ',''))+1)
        FROM sentences
        WHERE status IN ('accepted','revised')
        """
    ).fetchone()

    notes = (
        "COMPLEMENTARY INSECT SINGULAR/THIRD-PERSON PAST PERCEPTION SWEEP AFTER RULE 301 (Rule 302). "
        "50 under-review rows over the same ten checked insect target heads: balarr flea, dijaraban mayfly, "
        "kalburiji bee, mawal bee, munudumbun scorpion, munyurri sandfly, nakawarra bee, ngalmnbu jumper ant, "
        "yarrka bee, and yiljun grasshopper. SUPPORT: bare nominative ngayu, yundu, nyulu, bula, and jana, plus "
        "complementary yaluy/yinyay and nyajin. Only bare visible object past perception/reference rows are opened; "
        "biting, stinging, poison, sickness, vomiting, honey, nest, eggs, larvae, collecting, edible/food/medicine, "
        "seasonal-signal, singing, jumping, antbed, body/human-body, tree/wood, ecology, movement, danger, event, "
        "target case, pronoun case, demonstrative case, compounds, productive reduplication, nonpast/purposive/"
        "reduplicated perception drift, and support inflection remain closed."
    )
    cur = db.execute(
        "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
        (LABEL, "Rule 302 under review", "operator-guide-2026-07-09", notes, NOW),
    )
    batch_id = cur.lastrowid
    db.executemany(
        """
        INSERT INTO sentences(
          batch_id, seq, english, kuku, analysis, frame, tier, words_used, loans_used,
          evidence, status, confidence, rights_status, author, created_at, updated_at
        )
        VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (
                batch_id, seq, english, kuku, analysis, frame, tier, words_used, loans_used,
                evidence, "under_review", confidence,
                "project_approved_synthetic_pending_elder_verification", "claude", NOW, NOW,
            )
            for seq, english, kuku, analysis, frame, tier, words_used, loans_used, evidence, confidence in ROWS
        ],
    )
    record_event(db, batch_label=LABEL, phase="source", event_type="source-readback", actor="claude-main", detail="Reread direct dictionary yaml entries for ten Rule 302 insect targets and living grammar pronoun, demonstrative, and nyaji-ny/nyajin past support before authoring Rule 302.", artifact_path=PROCESS_LOG, created_at=NOW)
    record_event(db, batch_label=LABEL, phase="planning", event_type="complementary-insect-singular-third-past-scope", actor="claude-main", detail="Selected the complementary here/there half of the Rule 301 insect singular/third-person past perception field. The batch uses ngayu, yundu, nyulu, bula, and jana with nyajin, reversing the demonstrative slot and opening no insect action, danger, honey, nest, medicine, ecology, movement, event, or source-prose semantics.", artifact_path=PROCESS_LOG, created_at=NOW)
    record_event(db, batch_label=LABEL, phase="preflight", event_type="coverage-audit", actor="claude-main", detail=f"Token-aware accepted/revised coverage before banking from words_used JSON: targets={target_counts}; support={support_counts}.", artifact_path=PROCESS_LOG, created_at=NOW)
    record_event(db, batch_label=LABEL, phase="preflight", event_type="duplicate-preflight", actor="claude-main", detail="Final 50 Rule 302 complementary insect singular/third-person past surfaces returned no accepted, revised, or under-review collisions over the Rule 301 target set.", artifact_path=PROCESS_LOG, created_at=NOW)
    record_event(db, batch_label=LABEL, phase="preflight", event_type="static-guard-pass", actor="claude-main", detail="Static guard passed: 50 explicit hand-authored rows, one target each, bare singular/third-person nominative pronoun bands, complementary bare yaluy/yinyay, final nyajin, no loans, no denied Kuku forms, and no bite/sting/honey/nest/larvae/medicine/ecology/case/compound drift.", command="python3 -m py_compile batch_scripts/bank_344.py && python3 -c \"import sys; sys.path.insert(0,'batch_scripts'); import bank_344; print(bank_344.scan_static())\"", output_excerpt="issues 0", artifact_path="batch_scripts/bank_344.py", created_at=NOW)
    record_event(db, batch_label=LABEL, phase="bank", event_type="bank-success", actor="claude-main", detail=f"Banked 50 Rule 302 rows as under_review. Verified total remains {verified_before}; Kuku word count remains {words_before}.", command="python3 batch_scripts/bank_344.py", output_excerpt=f"banked batch-344: 50 rows under_review; verified_before={verified_before}; kuku_words_before={words_before}", artifact_path=PROCESS_LOG, created_at=NOW)
    db.commit()
    print("banked batch-344: 50 rows under_review")
    return 0


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