#!/usr/bin/env python3
"""Bank batch-302: Rule 260 complementary non-singular shellfish perception sweep."""

from __future__ import annotations

import datetime as dt
import json
import sqlite3

from bank_301 import (
    DENY_ENGLISH,
    DENY_KUKU,
    PRONOUN_SUPPORT,
    TARGET_HEADS,
    english_has_denied,
    has_target_morphology,
    has_token,
    js,
    row,
)
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-302"
NOW = dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
PROCESS_LOG = "process_logs/batch-302-shellfish-complementary-nonsingular-pronoun-perception-after-rule259-process.md"
SUPPORT = {"ngali", "ngaliny", "yubal", "nganjin", "ngana", "yaluy", "yinyay", "nyajil"}

EVIDENCE = {
    "baymbay": "Dictionary lines 2122-2130 give baymbay as noun 'large mud clam', semantic domain fauna-shellfish-crustacean. Patz grammar lines 2577-2603 source bare nominative ngali, ngaliny, yubal, nganjin, and ngana; lines 2682-2684 discuss inclusive/exclusive and second-person non-singular forms; lines 2838-2845 source yaluy/yinyay; lines 3043-3049 source nyaji-l 'see'.",
    "darkay": "Dictionary lines 5280-5289 give darkay as noun 'clam', definition small mud clam, semantic domain fauna-shellfish-crustacean; Rule 260 selects clam only. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "kaduy": "Dictionary lines 11964-11974 give kaduy as noun 'snail', with night/nocturnal source prose closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "karraway": "Dictionary lines 13592-13601 give karraway as noun 'edible snail' with translation snail; Rule 260 selects karraway snail only and leaves edible/food prose closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "karruku": "Dictionary lines 13701-13709 give karruku as noun 'ghost crab, fiddler crab'; Rule 260 selects ghost crab only and leaves fiddler-crab expansion closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "kulil": "Dictionary lines 15209-15220 give kulil as noun 'jellyfish', synonyms mili and wuybur; Rule 260 selects kulil only and leaves synonyms/sting/burn/danger rows closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "kuyalin": "Dictionary lines 16857-16866 give kuyalin as noun 'small conical shellfish', definition includes bait; Rule 260 selects small conical shellfish only and leaves bait/use rows closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "marrkabina": "Dictionary lines 18639-18647 give marrkabina as noun 'oyster', definition edible oyster; Rule 260 selects oyster only and leaves edible/food prose closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "ngarrakaja": "Dictionary lines 22791-22801 give ngarrakaja as noun 'shell fish', with edible/species prose closed; Rule 260 selects shellfish only. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
    "nuwi": "Dictionary lines 24261-24271 give nuwi as noun 'squid' with an ink-throwing source usage; Rule 260 selects squid only and leaves action/event rows closed. Patz grammar lines 2577-2603, 2682-2684, 2838-2845, and 3043-3049 source support.",
}

ROWS = [
    row(1, "We two, not you, see the large mud clam here.", "Ngali baymbay yaluy nyajil.", "ngali baymbay yaluy nyajil | 1du.EXCL.NOM large.mud.clam here see.NPST", "r260_1du_excl_target_here_see_baymbay", ["ngali", "baymbay", "yaluy", "nyajil"], EVIDENCE["baymbay"]),
    row(2, "We two, not you, see the clam here.", "Ngali darkay yaluy nyajil.", "ngali darkay yaluy nyajil | 1du.EXCL.NOM clam here see.NPST", "r260_1du_excl_target_here_see_darkay", ["ngali", "darkay", "yaluy", "nyajil"], EVIDENCE["darkay"]),
    row(3, "We two, not you, see the snail here.", "Ngali kaduy yaluy nyajil.", "ngali kaduy yaluy nyajil | 1du.EXCL.NOM snail here see.NPST", "r260_1du_excl_target_here_see_kaduy", ["ngali", "kaduy", "yaluy", "nyajil"], EVIDENCE["kaduy"]),
    row(4, "We two, not you, see the karraway snail here.", "Ngali karraway yaluy nyajil.", "ngali karraway yaluy nyajil | 1du.EXCL.NOM karraway.snail here see.NPST", "r260_1du_excl_target_here_see_karraway", ["ngali", "karraway", "yaluy", "nyajil"], EVIDENCE["karraway"]),
    row(5, "We two, not you, see the ghost crab here.", "Ngali karruku yaluy nyajil.", "ngali karruku yaluy nyajil | 1du.EXCL.NOM ghost.crab here see.NPST", "r260_1du_excl_target_here_see_karruku", ["ngali", "karruku", "yaluy", "nyajil"], EVIDENCE["karruku"]),
    row(6, "We two, not you, see the jellyfish here.", "Ngali kulil yaluy nyajil.", "ngali kulil yaluy nyajil | 1du.EXCL.NOM jellyfish here see.NPST", "r260_1du_excl_target_here_see_kulil", ["ngali", "kulil", "yaluy", "nyajil"], EVIDENCE["kulil"]),
    row(7, "We two, not you, see the small conical shellfish here.", "Ngali kuyalin yaluy nyajil.", "ngali kuyalin yaluy nyajil | 1du.EXCL.NOM small.conical.shellfish here see.NPST", "r260_1du_excl_target_here_see_kuyalin", ["ngali", "kuyalin", "yaluy", "nyajil"], EVIDENCE["kuyalin"]),
    row(8, "We two, not you, see the oyster here.", "Ngali marrkabina yaluy nyajil.", "ngali marrkabina yaluy nyajil | 1du.EXCL.NOM oyster here see.NPST", "r260_1du_excl_target_here_see_marrkabina", ["ngali", "marrkabina", "yaluy", "nyajil"], EVIDENCE["marrkabina"]),
    row(9, "We two, not you, see the shellfish here.", "Ngali ngarrakaja yaluy nyajil.", "ngali ngarrakaja yaluy nyajil | 1du.EXCL.NOM shellfish here see.NPST", "r260_1du_excl_target_here_see_ngarrakaja", ["ngali", "ngarrakaja", "yaluy", "nyajil"], EVIDENCE["ngarrakaja"]),
    row(10, "We two, not you, see the squid here.", "Ngali nuwi yaluy nyajil.", "ngali nuwi yaluy nyajil | 1du.EXCL.NOM squid here see.NPST", "r260_1du_excl_target_here_see_nuwi", ["ngali", "nuwi", "yaluy", "nyajil"], EVIDENCE["nuwi"]),
    row(11, "You and I see the large mud clam there.", "Ngaliny baymbay yinyay nyajil.", "ngaliny baymbay yinyay nyajil | 1du.INCL.NOM large.mud.clam there see.NPST", "r260_1du_incl_target_there_see_baymbay", ["ngaliny", "baymbay", "yinyay", "nyajil"], EVIDENCE["baymbay"]),
    row(12, "You and I see the clam there.", "Ngaliny darkay yinyay nyajil.", "ngaliny darkay yinyay nyajil | 1du.INCL.NOM clam there see.NPST", "r260_1du_incl_target_there_see_darkay", ["ngaliny", "darkay", "yinyay", "nyajil"], EVIDENCE["darkay"]),
    row(13, "You and I see the snail there.", "Ngaliny kaduy yinyay nyajil.", "ngaliny kaduy yinyay nyajil | 1du.INCL.NOM snail there see.NPST", "r260_1du_incl_target_there_see_kaduy", ["ngaliny", "kaduy", "yinyay", "nyajil"], EVIDENCE["kaduy"]),
    row(14, "You and I see the karraway snail there.", "Ngaliny karraway yinyay nyajil.", "ngaliny karraway yinyay nyajil | 1du.INCL.NOM karraway.snail there see.NPST", "r260_1du_incl_target_there_see_karraway", ["ngaliny", "karraway", "yinyay", "nyajil"], EVIDENCE["karraway"]),
    row(15, "You and I see the ghost crab there.", "Ngaliny karruku yinyay nyajil.", "ngaliny karruku yinyay nyajil | 1du.INCL.NOM ghost.crab there see.NPST", "r260_1du_incl_target_there_see_karruku", ["ngaliny", "karruku", "yinyay", "nyajil"], EVIDENCE["karruku"]),
    row(16, "You and I see the jellyfish there.", "Ngaliny kulil yinyay nyajil.", "ngaliny kulil yinyay nyajil | 1du.INCL.NOM jellyfish there see.NPST", "r260_1du_incl_target_there_see_kulil", ["ngaliny", "kulil", "yinyay", "nyajil"], EVIDENCE["kulil"]),
    row(17, "You and I see the small conical shellfish there.", "Ngaliny kuyalin yinyay nyajil.", "ngaliny kuyalin yinyay nyajil | 1du.INCL.NOM small.conical.shellfish there see.NPST", "r260_1du_incl_target_there_see_kuyalin", ["ngaliny", "kuyalin", "yinyay", "nyajil"], EVIDENCE["kuyalin"]),
    row(18, "You and I see the oyster there.", "Ngaliny marrkabina yinyay nyajil.", "ngaliny marrkabina yinyay nyajil | 1du.INCL.NOM oyster there see.NPST", "r260_1du_incl_target_there_see_marrkabina", ["ngaliny", "marrkabina", "yinyay", "nyajil"], EVIDENCE["marrkabina"]),
    row(19, "You and I see the shellfish there.", "Ngaliny ngarrakaja yinyay nyajil.", "ngaliny ngarrakaja yinyay nyajil | 1du.INCL.NOM shellfish there see.NPST", "r260_1du_incl_target_there_see_ngarrakaja", ["ngaliny", "ngarrakaja", "yinyay", "nyajil"], EVIDENCE["ngarrakaja"]),
    row(20, "You and I see the squid there.", "Ngaliny nuwi yinyay nyajil.", "ngaliny nuwi yinyay nyajil | 1du.INCL.NOM squid there see.NPST", "r260_1du_incl_target_there_see_nuwi", ["ngaliny", "nuwi", "yinyay", "nyajil"], EVIDENCE["nuwi"]),
    row(21, "You two see the large mud clam here.", "Yubal baymbay yaluy nyajil.", "yubal baymbay yaluy nyajil | 2du.NOM large.mud.clam here see.NPST", "r260_2du_target_here_see_baymbay", ["yubal", "baymbay", "yaluy", "nyajil"], EVIDENCE["baymbay"]),
    row(22, "You two see the clam here.", "Yubal darkay yaluy nyajil.", "yubal darkay yaluy nyajil | 2du.NOM clam here see.NPST", "r260_2du_target_here_see_darkay", ["yubal", "darkay", "yaluy", "nyajil"], EVIDENCE["darkay"]),
    row(23, "You two see the snail here.", "Yubal kaduy yaluy nyajil.", "yubal kaduy yaluy nyajil | 2du.NOM snail here see.NPST", "r260_2du_target_here_see_kaduy", ["yubal", "kaduy", "yaluy", "nyajil"], EVIDENCE["kaduy"]),
    row(24, "You two see the karraway snail here.", "Yubal karraway yaluy nyajil.", "yubal karraway yaluy nyajil | 2du.NOM karraway.snail here see.NPST", "r260_2du_target_here_see_karraway", ["yubal", "karraway", "yaluy", "nyajil"], EVIDENCE["karraway"]),
    row(25, "You two see the ghost crab here.", "Yubal karruku yaluy nyajil.", "yubal karruku yaluy nyajil | 2du.NOM ghost.crab here see.NPST", "r260_2du_target_here_see_karruku", ["yubal", "karruku", "yaluy", "nyajil"], EVIDENCE["karruku"]),
    row(26, "You two see the jellyfish here.", "Yubal kulil yaluy nyajil.", "yubal kulil yaluy nyajil | 2du.NOM jellyfish here see.NPST", "r260_2du_target_here_see_kulil", ["yubal", "kulil", "yaluy", "nyajil"], EVIDENCE["kulil"]),
    row(27, "You two see the small conical shellfish here.", "Yubal kuyalin yaluy nyajil.", "yubal kuyalin yaluy nyajil | 2du.NOM small.conical.shellfish here see.NPST", "r260_2du_target_here_see_kuyalin", ["yubal", "kuyalin", "yaluy", "nyajil"], EVIDENCE["kuyalin"]),
    row(28, "You two see the oyster here.", "Yubal marrkabina yaluy nyajil.", "yubal marrkabina yaluy nyajil | 2du.NOM oyster here see.NPST", "r260_2du_target_here_see_marrkabina", ["yubal", "marrkabina", "yaluy", "nyajil"], EVIDENCE["marrkabina"]),
    row(29, "You two see the shellfish here.", "Yubal ngarrakaja yaluy nyajil.", "yubal ngarrakaja yaluy nyajil | 2du.NOM shellfish here see.NPST", "r260_2du_target_here_see_ngarrakaja", ["yubal", "ngarrakaja", "yaluy", "nyajil"], EVIDENCE["ngarrakaja"]),
    row(30, "You two see the squid here.", "Yubal nuwi yaluy nyajil.", "yubal nuwi yaluy nyajil | 2du.NOM squid here see.NPST", "r260_2du_target_here_see_nuwi", ["yubal", "nuwi", "yaluy", "nyajil"], EVIDENCE["nuwi"]),
    row(31, "We all, not you, see the large mud clam there.", "Nganjin baymbay yinyay nyajil.", "nganjin baymbay yinyay nyajil | 1pl.EXCL.NOM large.mud.clam there see.NPST", "r260_1pl_excl_target_there_see_baymbay", ["nganjin", "baymbay", "yinyay", "nyajil"], EVIDENCE["baymbay"]),
    row(32, "We all, not you, see the clam there.", "Nganjin darkay yinyay nyajil.", "nganjin darkay yinyay nyajil | 1pl.EXCL.NOM clam there see.NPST", "r260_1pl_excl_target_there_see_darkay", ["nganjin", "darkay", "yinyay", "nyajil"], EVIDENCE["darkay"]),
    row(33, "We all, not you, see the snail there.", "Nganjin kaduy yinyay nyajil.", "nganjin kaduy yinyay nyajil | 1pl.EXCL.NOM snail there see.NPST", "r260_1pl_excl_target_there_see_kaduy", ["nganjin", "kaduy", "yinyay", "nyajil"], EVIDENCE["kaduy"]),
    row(34, "We all, not you, see the karraway snail there.", "Nganjin karraway yinyay nyajil.", "nganjin karraway yinyay nyajil | 1pl.EXCL.NOM karraway.snail there see.NPST", "r260_1pl_excl_target_there_see_karraway", ["nganjin", "karraway", "yinyay", "nyajil"], EVIDENCE["karraway"]),
    row(35, "We all, not you, see the ghost crab there.", "Nganjin karruku yinyay nyajil.", "nganjin karruku yinyay nyajil | 1pl.EXCL.NOM ghost.crab there see.NPST", "r260_1pl_excl_target_there_see_karruku", ["nganjin", "karruku", "yinyay", "nyajil"], EVIDENCE["karruku"]),
    row(36, "We all, not you, see the jellyfish there.", "Nganjin kulil yinyay nyajil.", "nganjin kulil yinyay nyajil | 1pl.EXCL.NOM jellyfish there see.NPST", "r260_1pl_excl_target_there_see_kulil", ["nganjin", "kulil", "yinyay", "nyajil"], EVIDENCE["kulil"]),
    row(37, "We all, not you, see the small conical shellfish there.", "Nganjin kuyalin yinyay nyajil.", "nganjin kuyalin yinyay nyajil | 1pl.EXCL.NOM small.conical.shellfish there see.NPST", "r260_1pl_excl_target_there_see_kuyalin", ["nganjin", "kuyalin", "yinyay", "nyajil"], EVIDENCE["kuyalin"]),
    row(38, "We all, not you, see the oyster there.", "Nganjin marrkabina yinyay nyajil.", "nganjin marrkabina yinyay nyajil | 1pl.EXCL.NOM oyster there see.NPST", "r260_1pl_excl_target_there_see_marrkabina", ["nganjin", "marrkabina", "yinyay", "nyajil"], EVIDENCE["marrkabina"]),
    row(39, "We all, not you, see the shellfish there.", "Nganjin ngarrakaja yinyay nyajil.", "nganjin ngarrakaja yinyay nyajil | 1pl.EXCL.NOM shellfish there see.NPST", "r260_1pl_excl_target_there_see_ngarrakaja", ["nganjin", "ngarrakaja", "yinyay", "nyajil"], EVIDENCE["ngarrakaja"]),
    row(40, "We all, not you, see the squid there.", "Nganjin nuwi yinyay nyajil.", "nganjin nuwi yinyay nyajil | 1pl.EXCL.NOM squid there see.NPST", "r260_1pl_excl_target_there_see_nuwi", ["nganjin", "nuwi", "yinyay", "nyajil"], EVIDENCE["nuwi"]),
    row(41, "We see the large mud clam here.", "Ngana baymbay yaluy nyajil.", "ngana baymbay yaluy nyajil | 1pl.INC.NOM large.mud.clam here see.NPST", "r260_1pl_incl_target_here_see_baymbay", ["ngana", "baymbay", "yaluy", "nyajil"], EVIDENCE["baymbay"]),
    row(42, "We see the clam here.", "Ngana darkay yaluy nyajil.", "ngana darkay yaluy nyajil | 1pl.INC.NOM clam here see.NPST", "r260_1pl_incl_target_here_see_darkay", ["ngana", "darkay", "yaluy", "nyajil"], EVIDENCE["darkay"]),
    row(43, "We see the snail here.", "Ngana kaduy yaluy nyajil.", "ngana kaduy yaluy nyajil | 1pl.INC.NOM snail here see.NPST", "r260_1pl_incl_target_here_see_kaduy", ["ngana", "kaduy", "yaluy", "nyajil"], EVIDENCE["kaduy"]),
    row(44, "We see the karraway snail here.", "Ngana karraway yaluy nyajil.", "ngana karraway yaluy nyajil | 1pl.INC.NOM karraway.snail here see.NPST", "r260_1pl_incl_target_here_see_karraway", ["ngana", "karraway", "yaluy", "nyajil"], EVIDENCE["karraway"]),
    row(45, "We see the ghost crab here.", "Ngana karruku yaluy nyajil.", "ngana karruku yaluy nyajil | 1pl.INC.NOM ghost.crab here see.NPST", "r260_1pl_incl_target_here_see_karruku", ["ngana", "karruku", "yaluy", "nyajil"], EVIDENCE["karruku"]),
    row(46, "We see the jellyfish here.", "Ngana kulil yaluy nyajil.", "ngana kulil yaluy nyajil | 1pl.INC.NOM jellyfish here see.NPST", "r260_1pl_incl_target_here_see_kulil", ["ngana", "kulil", "yaluy", "nyajil"], EVIDENCE["kulil"]),
    row(47, "We see the small conical shellfish here.", "Ngana kuyalin yaluy nyajil.", "ngana kuyalin yaluy nyajil | 1pl.INC.NOM small.conical.shellfish here see.NPST", "r260_1pl_incl_target_here_see_kuyalin", ["ngana", "kuyalin", "yaluy", "nyajil"], EVIDENCE["kuyalin"]),
    row(48, "We see the oyster here.", "Ngana marrkabina yaluy nyajil.", "ngana marrkabina yaluy nyajil | 1pl.INC.NOM oyster here see.NPST", "r260_1pl_incl_target_here_see_marrkabina", ["ngana", "marrkabina", "yaluy", "nyajil"], EVIDENCE["marrkabina"]),
    row(49, "We see the shellfish here.", "Ngana ngarrakaja yaluy nyajil.", "ngana ngarrakaja yaluy nyajil | 1pl.INC.NOM shellfish here see.NPST", "r260_1pl_incl_target_here_see_ngarrakaja", ["ngana", "ngarrakaja", "yaluy", "nyajil"], EVIDENCE["ngarrakaja"]),
    row(50, "We see the squid here.", "Ngana nuwi yaluy nyajil.", "ngana nuwi yaluy nyajil | 1pl.INC.NOM squid here see.NPST", "r260_1pl_incl_target_here_see_nuwi", ["ngana", "nuwi", "yaluy", "nyajil"], EVIDENCE["nuwi"]),
]


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("r260_"):
            issues.append(f"{label}: Rule 260 frame must start with r260_")
        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 260")
        for denied in DENY_KUKU:
            if has_token(low, denied):
                issues.append(f"{label}: denied carry-forward 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 260 shellfish/crustacean 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")
        pronouns = [pronoun for pronoun in PRONOUN_SUPPORT if has_token(low, pronoun)]
        if len(pronouns) != 1:
            issues.append(f"{label}: rows require exactly one bare nominative non-singular pronoun, found {pronouns}")
        if 1 <= seq <= 10 and (not low.startswith("ngali ") or not low.endswith(" yaluy nyajil.") or len(low.split()) != 4):
            issues.append(f"{label}: rows 1-10 require Ngali TARGET yaluy nyajil")
        if 11 <= seq <= 20 and (not low.startswith("ngaliny ") or not low.endswith(" yinyay nyajil.") or len(low.split()) != 4):
            issues.append(f"{label}: rows 11-20 require Ngaliny TARGET yinyay nyajil")
        if 21 <= seq <= 30 and (not low.startswith("yubal ") or not low.endswith(" yaluy nyajil.") or len(low.split()) != 4):
            issues.append(f"{label}: rows 21-30 require Yubal TARGET yaluy nyajil")
        if 31 <= seq <= 40 and (not low.startswith("nganjin ") or not low.endswith(" yinyay nyajil.") or len(low.split()) != 4):
            issues.append(f"{label}: rows 31-40 require Nganjin TARGET yinyay nyajil")
        if 41 <= seq <= 50 and (not low.startswith("ngana ") or not low.endswith(" yaluy nyajil.") or len(low.split()) != 4):
            issues.append(f"{label}: rows 41-50 require Ngana TARGET yaluy nyajil")
        if any(english_has_denied(english_low, bad) for bad in DENY_ENGLISH):
            issues.append(f"{label}: denied shellfish use/event/habitat/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 lessons WHERE batch_id=?", (batch_id,))
        db.execute("DELETE FROM sentences WHERE batch_id=?", (batch_id,))
        db.execute("UPDATE batches SET notes=?, created_at=? WHERE id=?", ("rebanked under_review", NOW, batch_id))
    else:
        db.execute(
            "INSERT INTO batches(label, cheatsheet_version, guide_version, notes, created_at) VALUES(?,?,?,?,?)",
            (LABEL, "Rule 260 draft", "operator-guide-2026-07-09", "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}: {kuku} -> {found}")
    if collisions:
        raise SystemExit("collision scan failed:\n" + "\n".join(collisions))

    db.executemany(
        """
        INSERT INTO sentences(
          batch_id, seq, english, kuku, analysis, frame, tier, words_used,
          loans_used, evidence, status, confidence, created_at
        )
        VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)
        """,
        [
            (
                batch_id,
                seq,
                english,
                kuku,
                analysis,
                frame,
                tier,
                words_used,
                loans_used,
                evidence,
                "under_review",
                confidence,
                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="Rule 260 source pass checked exact dictionary lines for baymbay large mud clam, darkay clam, kaduy snail, karraway snail, karruku ghost crab, kulil jellyfish, kuyalin small conical shellfish, marrkabina oyster, ngarrakaja shellfish, and nuwi squid; Patz grammar lines 2577-2603 for bare nominative ngali, ngaliny, yubal, nganjin, and ngana; lines 2682-2684 for inclusive/exclusive and second-person non-singular discussion; lines 2838-2845 for yaluy/yinyay; and lines 3043-3049 for nyaji-l.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="planning",
        event_type="debt-sweep-scope",
        actor="claude-main",
        detail="Selected Rule 260 complementary shellfish/crustacean non-singular pronoun perception sweep after Rule 259: same ten checked Rule 213 shellfish labels in zero-collision nominative-pronoun perception bands using the opposite yaluy/yinyay pairing for ngali, ngaliny, yubal, nganjin, and ngana. All shellfish use/source-prose, target-case, pronoun-case, demonstrative-case, and perception-compound semantics remain closed.",
        artifact_path=PROCESS_LOG,
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="preflight",
        event_type="coverage-audit",
        actor="claude-main",
        detail="Pre-batch token-aware target coverage among accepted/revised rows after Rule 259: baymbay 21, darkay 26, kaduy 21, karraway 20, karruku 21, kulil 22, kuyalin 20, marrkabina 20, ngarrakaja 20, and nuwi 21. Support coverage: ngali 169, ngaliny 104, yubal 115, nganjin 121, ngana 869, yaluy 2343, yinyay 2606, nyajil 2817.",
        command="sqlite3 synthetic.db token-aware coverage audit",
        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 260 Kuku surfaces returned zero accepted, revised, or under-review collisions.",
        command="python3 batch_scripts/bank_302.py internal collision scan",
        output_excerpt="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="Static guards passed: 50 rows, exactly one Rule 260 target shellfish/crustacean noun per row, exactly one bare nominative non-singular pronoun per row, no loans, no target suffixes, no excluded shellfish candidate, no food/use/event/habitat/body/source-prose drift, no pronoun case, no demonstrative case, no perception compound, and five planned frame bands only.",
        command="python3 batch_scripts/bank_302.py",
        artifact_path="batch_scripts/bank_302.py",
        created_at=NOW,
    )
    record_event(
        db,
        batch_label=LABEL,
        phase="bank",
        event_type="bank-success",
        actor="claude-main",
        detail="Banked 50 explicit hand-authored Rule 260 complementary shellfish/crustacean non-singular pronoun perception rows as under_review.",
        command="python3 batch_scripts/bank_302.py",
        artifact_path="batch_scripts/bank_302.py",
        created_at=NOW,
    )
    db.commit()
    print(f"banked {LABEL}: 50 under_review rows")
    return 0


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