#!/usr/bin/env python3
"""neurath_gate.py — run the Solonic Neurath gate on your own claims.

No Solonic in the loop. This is the discipline, not a service: tag every claim,
attach evidence, name a falsifier, refuse to emit anything untagged. Vendored so
an agent can drop it into a pipeline and gate its own output before shipping.
"""
from dataclasses import dataclass, asdict
from typing import Optional
import json

TAGS = {"PROVED","VERIFIED","OPEN","CORRECTED","REFUTED"}

@dataclass
class Claim:
    text: str
    tag: str
    evidence: str                     # what was checked, against what, what it returned
    falsifier: Optional[str] = None   # what observation would overturn this

    def validate(self):
        problems = []
        if self.tag not in TAGS:
            problems.append(f"tag '{self.tag}' not in {sorted(TAGS)} — untagged output is a bug, not a result")
        if not self.evidence.strip():
            problems.append("no evidence — a tag without evidence is a mark of truth, which we don't sell")
        if self.tag in {"PROVED","VERIFIED","REFUTED"} and not self.falsifier:
            problems.append(f"{self.tag} needs a falsifier — a claim with no falsifier is not checkable")
        return problems

def gate(claims):
    """Returns (passed, report). Fails closed: any invalid claim blocks the batch."""
    report, ok = [], True
    for i, c in enumerate(claims):
        probs = c.validate()
        if probs: ok = False
        report.append({"i": i, "claim": c.text, "tag": c.tag,
                       "status": "pass" if not probs else "BLOCKED",
                       "problems": probs})
    return ok, report

if __name__ == "__main__":
    demo = [
        Claim("The corpus has 912 nodes.", "VERIFIED",
              "Counted nodes in atlas-merged-corpus.json: len == 912.",
              "A recount returning != 912."),
        Claim("This method is the best.", "PROVED", ""),   # deliberately fails
    ]
    passed, report = gate(demo)
    print(json.dumps({"passed": passed, "report": report}, indent=1))
    # -> the second claim BLOCKS the batch: no evidence, no falsifier. Fail closed.
