#!/usr/bin/env python3
"""Bank batch-334: Rule 292 low-count weapon/tool pronoun past perception."""

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-334"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-334-low-count-traditional-weapon-tool-pronoun-past-perception-after-rule291-process.md"

TARGET_EVIDENCE = {
    "kurrajan": "Dictionary lines 16196-16207 give kurrajan as noun 'spear point', with source prose about wattle, fire-hardening, and turtle spearing. Rule 292 selects visible spear-point reference only.",
    "nambarr": "Dictionary lines 21516-21526 give nambarr as noun 'bamboo stick', a flexible bamboo stick used in nose piercing. Rule 292 selects visible bamboo-stick reference only.",
    "manbir": "Dictionary lines 17699-17707 give manbir as noun 'barb of a spear'. Rule 292 selects visible spear-barb reference only.",
    "wakay": "Dictionary lines 25192-25202 give wakay as noun 'wooden sword'. Rule 292 selects visible wooden-sword reference only.",
    "wulburr": "Dictionary lines 27767-27776 give wulburr as noun 'bamboo spear stick' and 'spear'. Rule 292 selects visible bamboo-spear-stick reference only.",
}

SUPPORT_EVIDENCE = (
    "Patz lines 2577-2603 source the bare nominative pronouns used here: ngayu, yundu, nyulu, ngali, "
    "ngaliny, yubal, bula, nganjin, ngana, and yurra; lines 2674-2686 source the non-singular person/number "
    "contrasts; lines 2838-2845 source yaluy/yinyay; lines 2568-2571 and 2023 source nyaji-ny 'see-PAST'; "
    "and lines 3160-3162 source the past -ny function. Rule 292 uses corpus-conventional nyajin as the past "
    "visual-perception surface."
)

TARGET_ORDER = ["kurrajan", "nambarr", "manbir", "wakay", "wulburr"]
FRAME_SPECS = [
    ("ngayu", "yinyay"),
    ("yundu", "yaluy"),
    ("nyulu", "yinyay"),
    ("ngali", "yaluy"),
    ("ngaliny", "yinyay"),
    ("yubal", "yaluy"),
    ("bula", "yaluy"),
    ("nganjin", "yinyay"),
    ("ngana", "yaluy"),
    ("yurra", "yinyay"),
]

DENY_KUKU = {
    "biyul", "durray", "jinil", "mirru", "kurajan", "ngurmu", "birungubay", "biruwybay", "birubay",
    "kurrajanji", "nambarriji", "manbirji", "wakayji", "wulburrji",
    "nganya", "yununy", "nyunguny", "ngalingan", "ngalinyan", "yubalan", "bulangan",
    "nganjinan", "nganangan", "yurrangan", "janangan", "ngalinka", "ngalinyanka", "yubalanka",
    "bulanka", "nganjinanka", "ngananka", "yurranka", "ngalinda", "ngalinyanda", "yubalanda",
    "bulanda", "nganjinanda", "ngananda", "yurranda", "ngalinji", "ngalinyanji", "yubalanji",
    "bulanji", "nganjinanji", "ngananji", "yurranji", "ngalinga", "ngalinyanga", "yubalanga",
    "bulanga", "nganjinanga", "ngananga", "yurranga",
    "nyajil", "nyaji-l", "nyaji-nka", "nyaji-l-nyaji", "yinyangka", "yinyayngka",
    "yinyamba", "yinyamuny", "yalungku", "yaluyngku", "yaluymbu", "yaluyundu", "yalamuny",
}
DENY_ENGLISH = (
    "cook", "cooking", "earth oven", "voya", "vine", "gather", "turtle spearing", "turtle", "wattle",
    "fire", "fire-hardening", "hardened", "pierce", "piercing", "throw", "throwing", "threw", "hunting",
    "hunt", "fighting with", "fight with", "defend", "defence", "cutting", "cut with", "stab", "stabbing",
    "injury", "nose piercing", "made", "make", "used", "use", "owned", "belongs", "route", "travel",
    "place", "story",
)


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 spear point there.", "Ngayu kurrajan yinyay nyajin.", "ngayu kurrajan yinyay nyajin | 1sg.NOM spear.point there see.PAST", "r292_1sg_there_low_weapon_tool_saw_kurrajan", ["ngayu", "kurrajan", "yinyay", "nyajin"]),
    row(2, "I saw the bamboo stick there.", "Ngayu nambarr yinyay nyajin.", "ngayu nambarr yinyay nyajin | 1sg.NOM bamboo.stick there see.PAST", "r292_1sg_there_low_weapon_tool_saw_nambarr", ["ngayu", "nambarr", "yinyay", "nyajin"]),
    row(3, "I saw the spear barb there.", "Ngayu manbir yinyay nyajin.", "ngayu manbir yinyay nyajin | 1sg.NOM spear.barb there see.PAST", "r292_1sg_there_low_weapon_tool_saw_manbir", ["ngayu", "manbir", "yinyay", "nyajin"]),
    row(4, "I saw the wooden sword there.", "Ngayu wakay yinyay nyajin.", "ngayu wakay yinyay nyajin | 1sg.NOM wooden.sword there see.PAST", "r292_1sg_there_low_weapon_tool_saw_wakay", ["ngayu", "wakay", "yinyay", "nyajin"]),
    row(5, "I saw the bamboo spear stick there.", "Ngayu wulburr yinyay nyajin.", "ngayu wulburr yinyay nyajin | 1sg.NOM bamboo.spear.stick there see.PAST", "r292_1sg_there_low_weapon_tool_saw_wulburr", ["ngayu", "wulburr", "yinyay", "nyajin"]),
    row(6, "You saw the spear point here.", "Yundu kurrajan yaluy nyajin.", "yundu kurrajan yaluy nyajin | 2sg.NOM spear.point here see.PAST", "r292_2sg_here_low_weapon_tool_saw_kurrajan", ["yundu", "kurrajan", "yaluy", "nyajin"]),
    row(7, "You saw the bamboo stick here.", "Yundu nambarr yaluy nyajin.", "yundu nambarr yaluy nyajin | 2sg.NOM bamboo.stick here see.PAST", "r292_2sg_here_low_weapon_tool_saw_nambarr", ["yundu", "nambarr", "yaluy", "nyajin"]),
    row(8, "You saw the spear barb here.", "Yundu manbir yaluy nyajin.", "yundu manbir yaluy nyajin | 2sg.NOM spear.barb here see.PAST", "r292_2sg_here_low_weapon_tool_saw_manbir", ["yundu", "manbir", "yaluy", "nyajin"]),
    row(9, "You saw the wooden sword here.", "Yundu wakay yaluy nyajin.", "yundu wakay yaluy nyajin | 2sg.NOM wooden.sword here see.PAST", "r292_2sg_here_low_weapon_tool_saw_wakay", ["yundu", "wakay", "yaluy", "nyajin"]),
    row(10, "You saw the bamboo spear stick here.", "Yundu wulburr yaluy nyajin.", "yundu wulburr yaluy nyajin | 2sg.NOM bamboo.spear.stick here see.PAST", "r292_2sg_here_low_weapon_tool_saw_wulburr", ["yundu", "wulburr", "yaluy", "nyajin"]),
    row(11, "He saw the spear point there.", "Nyulu kurrajan yinyay nyajin.", "nyulu kurrajan yinyay nyajin | 3sg.NOM spear.point there see.PAST", "r292_3sg_there_low_weapon_tool_saw_kurrajan", ["nyulu", "kurrajan", "yinyay", "nyajin"]),
    row(12, "He saw the bamboo stick there.", "Nyulu nambarr yinyay nyajin.", "nyulu nambarr yinyay nyajin | 3sg.NOM bamboo.stick there see.PAST", "r292_3sg_there_low_weapon_tool_saw_nambarr", ["nyulu", "nambarr", "yinyay", "nyajin"]),
    row(13, "He saw the spear barb there.", "Nyulu manbir yinyay nyajin.", "nyulu manbir yinyay nyajin | 3sg.NOM spear.barb there see.PAST", "r292_3sg_there_low_weapon_tool_saw_manbir", ["nyulu", "manbir", "yinyay", "nyajin"]),
    row(14, "He saw the wooden sword there.", "Nyulu wakay yinyay nyajin.", "nyulu wakay yinyay nyajin | 3sg.NOM wooden.sword there see.PAST", "r292_3sg_there_low_weapon_tool_saw_wakay", ["nyulu", "wakay", "yinyay", "nyajin"]),
    row(15, "He saw the bamboo spear stick there.", "Nyulu wulburr yinyay nyajin.", "nyulu wulburr yinyay nyajin | 3sg.NOM bamboo.spear.stick there see.PAST", "r292_3sg_there_low_weapon_tool_saw_wulburr", ["nyulu", "wulburr", "yinyay", "nyajin"]),
    row(16, "We two (not you) saw the spear point here.", "Ngali kurrajan yaluy nyajin.", "ngali kurrajan yaluy nyajin | 1du.excl.NOM spear.point here see.PAST", "r292_1du_excl_here_low_weapon_tool_saw_kurrajan", ["ngali", "kurrajan", "yaluy", "nyajin"]),
    row(17, "We two (not you) saw the bamboo stick here.", "Ngali nambarr yaluy nyajin.", "ngali nambarr yaluy nyajin | 1du.excl.NOM bamboo.stick here see.PAST", "r292_1du_excl_here_low_weapon_tool_saw_nambarr", ["ngali", "nambarr", "yaluy", "nyajin"]),
    row(18, "We two (not you) saw the spear barb here.", "Ngali manbir yaluy nyajin.", "ngali manbir yaluy nyajin | 1du.excl.NOM spear.barb here see.PAST", "r292_1du_excl_here_low_weapon_tool_saw_manbir", ["ngali", "manbir", "yaluy", "nyajin"]),
    row(19, "We two (not you) saw the wooden sword here.", "Ngali wakay yaluy nyajin.", "ngali wakay yaluy nyajin | 1du.excl.NOM wooden.sword here see.PAST", "r292_1du_excl_here_low_weapon_tool_saw_wakay", ["ngali", "wakay", "yaluy", "nyajin"]),
    row(20, "We two (not you) saw the bamboo spear stick here.", "Ngali wulburr yaluy nyajin.", "ngali wulburr yaluy nyajin | 1du.excl.NOM bamboo.spear.stick here see.PAST", "r292_1du_excl_here_low_weapon_tool_saw_wulburr", ["ngali", "wulburr", "yaluy", "nyajin"]),
    row(21, "You and I saw the spear point there.", "Ngaliny kurrajan yinyay nyajin.", "ngaliny kurrajan yinyay nyajin | 1du.incl.NOM spear.point there see.PAST", "r292_1du_incl_there_low_weapon_tool_saw_kurrajan", ["ngaliny", "kurrajan", "yinyay", "nyajin"]),
    row(22, "You and I saw the bamboo stick there.", "Ngaliny nambarr yinyay nyajin.", "ngaliny nambarr yinyay nyajin | 1du.incl.NOM bamboo.stick there see.PAST", "r292_1du_incl_there_low_weapon_tool_saw_nambarr", ["ngaliny", "nambarr", "yinyay", "nyajin"]),
    row(23, "You and I saw the spear barb there.", "Ngaliny manbir yinyay nyajin.", "ngaliny manbir yinyay nyajin | 1du.incl.NOM spear.barb there see.PAST", "r292_1du_incl_there_low_weapon_tool_saw_manbir", ["ngaliny", "manbir", "yinyay", "nyajin"]),
    row(24, "You and I saw the wooden sword there.", "Ngaliny wakay yinyay nyajin.", "ngaliny wakay yinyay nyajin | 1du.incl.NOM wooden.sword there see.PAST", "r292_1du_incl_there_low_weapon_tool_saw_wakay", ["ngaliny", "wakay", "yinyay", "nyajin"]),
    row(25, "You and I saw the bamboo spear stick there.", "Ngaliny wulburr yinyay nyajin.", "ngaliny wulburr yinyay nyajin | 1du.incl.NOM bamboo.spear.stick there see.PAST", "r292_1du_incl_there_low_weapon_tool_saw_wulburr", ["ngaliny", "wulburr", "yinyay", "nyajin"]),
    row(26, "You two saw the spear point here.", "Yubal kurrajan yaluy nyajin.", "yubal kurrajan yaluy nyajin | 2du.NOM spear.point here see.PAST", "r292_2du_here_low_weapon_tool_saw_kurrajan", ["yubal", "kurrajan", "yaluy", "nyajin"]),
    row(27, "You two saw the bamboo stick here.", "Yubal nambarr yaluy nyajin.", "yubal nambarr yaluy nyajin | 2du.NOM bamboo.stick here see.PAST", "r292_2du_here_low_weapon_tool_saw_nambarr", ["yubal", "nambarr", "yaluy", "nyajin"]),
    row(28, "You two saw the spear barb here.", "Yubal manbir yaluy nyajin.", "yubal manbir yaluy nyajin | 2du.NOM spear.barb here see.PAST", "r292_2du_here_low_weapon_tool_saw_manbir", ["yubal", "manbir", "yaluy", "nyajin"]),
    row(29, "You two saw the wooden sword here.", "Yubal wakay yaluy nyajin.", "yubal wakay yaluy nyajin | 2du.NOM wooden.sword here see.PAST", "r292_2du_here_low_weapon_tool_saw_wakay", ["yubal", "wakay", "yaluy", "nyajin"]),
    row(30, "You two saw the bamboo spear stick here.", "Yubal wulburr yaluy nyajin.", "yubal wulburr yaluy nyajin | 2du.NOM bamboo.spear.stick here see.PAST", "r292_2du_here_low_weapon_tool_saw_wulburr", ["yubal", "wulburr", "yaluy", "nyajin"]),
    row(31, "They two saw the spear point here.", "Bula kurrajan yaluy nyajin.", "bula kurrajan yaluy nyajin | 3du.NOM spear.point here see.PAST", "r292_3du_here_low_weapon_tool_saw_kurrajan", ["bula", "kurrajan", "yaluy", "nyajin"]),
    row(32, "They two saw the bamboo stick here.", "Bula nambarr yaluy nyajin.", "bula nambarr yaluy nyajin | 3du.NOM bamboo.stick here see.PAST", "r292_3du_here_low_weapon_tool_saw_nambarr", ["bula", "nambarr", "yaluy", "nyajin"]),
    row(33, "They two saw the spear barb here.", "Bula manbir yaluy nyajin.", "bula manbir yaluy nyajin | 3du.NOM spear.barb here see.PAST", "r292_3du_here_low_weapon_tool_saw_manbir", ["bula", "manbir", "yaluy", "nyajin"]),
    row(34, "They two saw the wooden sword here.", "Bula wakay yaluy nyajin.", "bula wakay yaluy nyajin | 3du.NOM wooden.sword here see.PAST", "r292_3du_here_low_weapon_tool_saw_wakay", ["bula", "wakay", "yaluy", "nyajin"]),
    row(35, "They two saw the bamboo spear stick here.", "Bula wulburr yaluy nyajin.", "bula wulburr yaluy nyajin | 3du.NOM bamboo.spear.stick here see.PAST", "r292_3du_here_low_weapon_tool_saw_wulburr", ["bula", "wulburr", "yaluy", "nyajin"]),
    row(36, "We all, not you, saw the spear point there.", "Nganjin kurrajan yinyay nyajin.", "nganjin kurrajan yinyay nyajin | 1pl.excl.NOM spear.point there see.PAST", "r292_1pl_excl_there_low_weapon_tool_saw_kurrajan", ["nganjin", "kurrajan", "yinyay", "nyajin"]),
    row(37, "We all, not you, saw the bamboo stick there.", "Nganjin nambarr yinyay nyajin.", "nganjin nambarr yinyay nyajin | 1pl.excl.NOM bamboo.stick there see.PAST", "r292_1pl_excl_there_low_weapon_tool_saw_nambarr", ["nganjin", "nambarr", "yinyay", "nyajin"]),
    row(38, "We all, not you, saw the spear barb there.", "Nganjin manbir yinyay nyajin.", "nganjin manbir yinyay nyajin | 1pl.excl.NOM spear.barb there see.PAST", "r292_1pl_excl_there_low_weapon_tool_saw_manbir", ["nganjin", "manbir", "yinyay", "nyajin"]),
    row(39, "We all, not you, saw the wooden sword there.", "Nganjin wakay yinyay nyajin.", "nganjin wakay yinyay nyajin | 1pl.excl.NOM wooden.sword there see.PAST", "r292_1pl_excl_there_low_weapon_tool_saw_wakay", ["nganjin", "wakay", "yinyay", "nyajin"]),
    row(40, "We all, not you, saw the bamboo spear stick there.", "Nganjin wulburr yinyay nyajin.", "nganjin wulburr yinyay nyajin | 1pl.excl.NOM bamboo.spear.stick there see.PAST", "r292_1pl_excl_there_low_weapon_tool_saw_wulburr", ["nganjin", "wulburr", "yinyay", "nyajin"]),
    row(41, "We saw the spear point here.", "Ngana kurrajan yaluy nyajin.", "ngana kurrajan yaluy nyajin | 1pl.incl.NOM spear.point here see.PAST", "r292_1pl_incl_here_low_weapon_tool_saw_kurrajan", ["ngana", "kurrajan", "yaluy", "nyajin"]),
    row(42, "We saw the bamboo stick here.", "Ngana nambarr yaluy nyajin.", "ngana nambarr yaluy nyajin | 1pl.incl.NOM bamboo.stick here see.PAST", "r292_1pl_incl_here_low_weapon_tool_saw_nambarr", ["ngana", "nambarr", "yaluy", "nyajin"]),
    row(43, "We saw the spear barb here.", "Ngana manbir yaluy nyajin.", "ngana manbir yaluy nyajin | 1pl.incl.NOM spear.barb here see.PAST", "r292_1pl_incl_here_low_weapon_tool_saw_manbir", ["ngana", "manbir", "yaluy", "nyajin"]),
    row(44, "We saw the wooden sword here.", "Ngana wakay yaluy nyajin.", "ngana wakay yaluy nyajin | 1pl.incl.NOM wooden.sword here see.PAST", "r292_1pl_incl_here_low_weapon_tool_saw_wakay", ["ngana", "wakay", "yaluy", "nyajin"]),
    row(45, "We saw the bamboo spear stick here.", "Ngana wulburr yaluy nyajin.", "ngana wulburr yaluy nyajin | 1pl.incl.NOM bamboo.spear.stick here see.PAST", "r292_1pl_incl_here_low_weapon_tool_saw_wulburr", ["ngana", "wulburr", "yaluy", "nyajin"]),
    row(46, "You all saw the spear point there.", "Yurra kurrajan yinyay nyajin.", "yurra kurrajan yinyay nyajin | 2pl.NOM spear.point there see.PAST", "r292_2pl_there_low_weapon_tool_saw_kurrajan", ["yurra", "kurrajan", "yinyay", "nyajin"]),
    row(47, "You all saw the bamboo stick there.", "Yurra nambarr yinyay nyajin.", "yurra nambarr yinyay nyajin | 2pl.NOM bamboo.stick there see.PAST", "r292_2pl_there_low_weapon_tool_saw_nambarr", ["yurra", "nambarr", "yinyay", "nyajin"]),
    row(48, "You all saw the spear barb there.", "Yurra manbir yinyay nyajin.", "yurra manbir yinyay nyajin | 2pl.NOM spear.barb there see.PAST", "r292_2pl_there_low_weapon_tool_saw_manbir", ["yurra", "manbir", "yinyay", "nyajin"]),
    row(49, "You all saw the wooden sword there.", "Yurra wakay yinyay nyajin.", "yurra wakay yinyay nyajin | 2pl.NOM wooden.sword there see.PAST", "r292_2pl_there_low_weapon_tool_saw_wakay", ["yurra", "wakay", "yinyay", "nyajin"]),
    row(50, "You all saw the bamboo spear stick there.", "Yurra wulburr yinyay nyajin.", "yurra wulburr yinyay nyajin | 2pl.NOM bamboo.spear.stick there see.PAST", "r292_2pl_there_low_weapon_tool_saw_wulburr", ["yurra", "wulburr", "yinyay", "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 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) // 5]
        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) % 5]:
            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("r292_"):
            issues.append(f"{seq}: frame not r292 {frame}")
    return issues


def count_words(db: sqlite3.Connection, words: list[str]) -> dict[str, int]:
    return {
        word: db.execute(
            """
            SELECT COUNT(*)
            FROM sentences s
            WHERE s.status IN ('accepted','revised')
              AND EXISTS (SELECT 1 FROM json_each(s.words_used) WHERE value=?)
            """,
            (word,),
        ).fetchone()[0]
        for word in words
    }


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", "ngali", "ngaliny", "yubal", "bula", "nganjin", "ngana", "yurra", "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 = (
        "LOW-COUNT VISIBLE TRADITIONAL WEAPON/TOOL TEN-PRONOUN PAST PERCEPTION SWEEP AFTER RULE 291 "
        "(Rule 292). 50 under-review rows over five lower-count checked targets: kurrajan spear point, nambarr "
        "bamboo stick, manbir spear barb, wakay wooden sword, and wulburr bamboo spear stick. SUPPORT: bare "
        "nominative ngayu, yundu, nyulu, ngali, ngaliny, yubal, bula, nganjin, ngana, and yurra, plus yaluy/yinyay "
        "and nyajin. Only bare visible object past perception/reference rows are opened; weapon use, cooking, "
        "earth-oven/vine source, turtle spearing, fire-hardening, nose-piercing, throwing, hunting, fighting, "
        "piercing, cutting, material-source, 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 292 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 dictionary source lines for five lower-count visible traditional weapon/tool targets and Patz pronoun, demonstrative, nyaji-ny past, and past -ny support before authoring Rule 292.", artifact_path=PROCESS_LOG, created_at=NOW)
    record_event(db, batch_label=LABEL, phase="planning", event_type="pronoun-coverage-scope", actor="claude-main", detail="Selected the past-tense counterpart to Rule 291's ten-pronoun nonpast perception coverage over the five lowest-count weapon/tool targets. The batch reuses the zero-collision local-demonstrative pattern and does not open weapon-use 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 292 low-count weapon/tool ten-pronoun past surfaces returned no accepted, revised, or under-review collisions.", 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 nominative pronoun bands, bare yaluy/yinyay, final nyajin, no loans, no denied Kuku forms, and no weapon-use/source-prose/case/compound drift.", command="python3 -m py_compile batch_scripts/bank_334.py && python3 -c \"import sys; sys.path.insert(0,'batch_scripts'); import bank_334; print(bank_334.scan_static())\"", output_excerpt="issues 0", artifact_path="batch_scripts/bank_334.py", created_at=NOW)
    record_event(db, batch_label=LABEL, phase="bank", event_type="bank-success", actor="claude-main", detail=f"Banked 50 Rule 292 rows as under_review. Verified total remains {verified_before}; Kuku word count remains {words_before}.", command="python3 batch_scripts/bank_334.py", output_excerpt=f"banked batch-334: 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-334: 50 rows under_review")
    return 0


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