#!/usr/bin/env python3 """gcy_verify_intake.py — GoCheckYourself (GCY-2) Automated Card & Intake Validator. Standalone zero-dependency Python 3 verifier for GCY-2 JSON paper cards (`schema_version = "gcy-v1"`) and submission payloads. Enforces: 1. Required schema structure (`gcy-v1`), canonical IDs, and author attribution. 2. Evidence label discipline (`PROVED`, `COMPUTED`, `CITED`, `CONJECTURED`, `CONDITIONAL`, `OPEN`). 3. Objective 5-tier verification consistency (Tier 1..5). 4. Strict conditional venue URL rules (`unsubmitted`, `staged`, and `superseded` venues MUST have `url == ""`; `submitted`, `published`, and `accepted` venues MUST carry valid `https://` URLs). 5. Strict zero-local-path hygiene (`C:\\`, `D:\\`, `file:///`, `/Users/`). 6. Disallowed-axiom rejection (`sorryAx`, `Lean.ofReduceBool`, `Lean.trustCompiler`). Usage: python -I gcy_verify_intake.py --self-test python -I gcy_verify_intake.py path/to/paper-card.json [path/to/card2.json ...] """ from __future__ import annotations import argparse import json import re import sys from pathlib import Path from typing import Any VALID_EVIDENCE_TAGS = {"PROVED", "COMPUTED", "CITED", "CONJECTURED", "CONDITIONAL", "OPEN"} VALID_STANDING_TIERS = {"frontier_1", "active_frontier", "exact_structural", "foundation"} VALID_VENUE_STATUSES = {"unsubmitted", "staged", "superseded", "submitted", "published", "accepted"} VALID_BOUND_TYPES = { "upper_bound", "lower_bound", "two_sided_bracket", "threshold_radius", "exact_identity", "no_go_barrier", } VALID_BETTER_DIRECTIONS = {"lower_is_better", "higher_is_better", "narrower_bracket", "exact"} DISALLOWED_AXIOMS = {"sorryAx", "Lean.ofReduceBool", "Lean.trustCompiler"} LOCAL_PATH_RE = re.compile(r"(?:(?]+$", re.I) PAPER_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{2,64}$") def _walk_strings(obj: Any, path: str = "$"): if isinstance(obj, str): yield path, obj elif isinstance(obj, list): for idx, item in enumerate(obj): yield from _walk_strings(item, f"{path}[{idx}]") elif isinstance(obj, dict): for k, v in obj.items(): yield from _walk_strings(v, f"{path}.{k}") def validate_gcy_card(card: dict[str, Any]) -> list[str]: """Return a list of validation errors for a GCY-1 card (empty list = PASS).""" errors: list[str] = [] if not isinstance(card, dict): return ["Root JSON value must be an object"] if card.get("schema_version") != "gcy-v1": errors.append(f"schema_version must be 'gcy-v1', got {card.get('schema_version')!r}") paper_id = card.get("paper_id") if not isinstance(paper_id, str) or not PAPER_ID_RE.match(paper_id): errors.append(f"Invalid paper_id: {paper_id!r}") for field in ("title", "short_title", "author", "slug", "abstract", "verify_command"): val = card.get(field) if not isinstance(val, str) or not val.strip(): errors.append(f"Missing or empty required string field: {field}") # Evidence tags etags = card.get("evidence_tags") if not isinstance(etags, list) or not etags: errors.append("evidence_tags must be a non-empty list") else: bad = [t for t in etags if t not in VALID_EVIDENCE_TAGS] if bad: errors.append(f"Invalid evidence_tags: {bad}") # Standing metadata standing = card.get("standing") if not isinstance(standing, dict): errors.append("Missing required object: standing") else: stier = standing.get("standing_tier") if stier not in VALID_STANDING_TIERS: errors.append(f"Invalid standing.standing_tier: {stier!r}") if not isinstance(standing.get("projected_rank_label"), str) or not standing["projected_rank_label"].strip(): errors.append("standing.projected_rank_label must be a non-empty string") if not isinstance(standing.get("baseline_compared"), str) or not standing["baseline_compared"].strip(): errors.append("standing.baseline_compared must be a non-empty string") if "bound_type" in standing and standing["bound_type"] not in VALID_BOUND_TYPES: errors.append(f"Invalid standing.bound_type: {standing['bound_type']!r}") if "better_direction" in standing and standing["better_direction"] not in VALID_BETTER_DIRECTIONS: errors.append(f"Invalid standing.better_direction: {standing['better_direction']!r}") # Verification metadata (Objective 5-Tier GCY-1 Ladder) ver = card.get("verification") if not isinstance(ver, dict): errors.append("Missing required object: verification") else: tier = ver.get("tier") if not isinstance(tier, int) or not (1 <= tier <= 5): errors.append(f"verification.tier must be integer 1..5, got {tier!r}") else: t0 = bool(ver.get("trust_level_zero")) pc_rej = int(ver.get("planted_controls_rejected", 0) or 0) pc_tot = int(ver.get("planted_controls_total", 0) or 0) zax = int(ver.get("zero_axiom_declarations", 0) or 0) sha_cnt = int(ver.get("sha256_manifest_files", 0) or 0) if sha_cnt <= 0: errors.append("verification.sha256_manifest_files must be >= 1") if pc_rej != pc_tot: errors.append(f"Planted controls mismatch: rejected={pc_rej} != total={pc_tot}") if tier >= 2 and pc_tot < 1: errors.append(f"Tier {tier} requires >= 1 planted negative control") if tier >= 3 and not t0: errors.append(f"Tier {tier} requires trust_level_zero=true kernel replay") if tier >= 4 and zax < 1: errors.append(f"Tier {tier} requires >= 1 zero-axiom (axioms=[]) declaration") # Axiom hygiene on declarations if embedded for d in card.get("declarations", []): axs = d.get("axioms", []) bad_ax = [a for a in axs if a in DISALLOWED_AXIOMS] if bad_ax: errors.append(f"Disallowed axioms {bad_ax} in declaration {d.get('declaration')!r}") # Venue conditional URL rules venues = card.get("venues") if not isinstance(venues, list): errors.append("venues must be a list") else: for idx, v in enumerate(venues): if not isinstance(v, dict): errors.append(f"venues[{idx}] must be an object") continue vstatus = v.get("status") vurl = v.get("url", "") if vstatus not in VALID_VENUE_STATUSES: errors.append(f"venues[{idx}].status invalid: {vstatus!r}") if vstatus in ("unsubmitted", "staged", "superseded"): if isinstance(vurl, str) and vurl.strip(): errors.append( f"Premature URL on {vstatus} venue {v.get('name')!r}: url must be empty string" ) elif vstatus in ("submitted", "published", "accepted"): if not isinstance(vurl, str) or not HTTPS_URL_RE.match(vurl.strip()): errors.append( f"Venue {v.get('name')!r} with status={vstatus!r} requires valid https:// url" ) # Zero local paths in public card payloads for jpath, text in _walk_strings(card): if LOCAL_PATH_RE.search(text): errors.append(f"Local machine path detected at {jpath}: {text[:80]!r}") return errors def run_self_test() -> int: """Verify valid card acceptance AND planted invalid card rejection.""" valid_card = { "schema_version": "gcy-v1", "paper_id": "paper-self-test-01", "paper_number": 999, "slug": "2026-11-26-self-test-bundle", "title": "Self-Test Valid GCY-2 Certificate Card", "short_title": "Self-Test Valid Card", "author": "Sonny", "abstract": "Synthetic self-test certificate verifying GCY-2 card acceptance including CONDITIONAL evidence tag.", "evidence_tags": ["PROVED", "COMPUTED", "CONDITIONAL", "CITED", "OPEN"], "verify_command": "python scripts/verify_bundle.py", "standing": { "standing_tier": "exact_structural", "projected_rank_label": "Self-Test Structural Certificate", "baseline_compared": "Reference GCY-2 baseline", }, "verification": { "tier": 5, "tier_label": "Tier 5: Kernel Replay + Zero-Axiom Core + Dual Replay", "trust_level_zero": True, "lean_modules": 1, "target_declarations": 2, "zero_axiom_declarations": 2, "planted_controls_total": 1, "planted_controls_rejected": 1, "sha256_manifest_files": 6, "dual_independent_checker": True, }, "declarations": [ {"declaration": "SelfTest.valid_thm", "axioms": []}, ], "venues": [ {"name": "Zenodo", "status": "staged", "url": "", "note": "Local zip staged"}, {"name": "arXiv", "status": "unsubmitted", "url": "", "note": "Target preprint"}, ], } planted_invalid_card = { "schema_version": "gcy-v1", "paper_id": "paper-planted-bad-01", "paper_number": 998, "slug": "2026-11-26-planted-bad", "title": "Planted Invalid Card (Must Be Rejected)", "short_title": "Planted Invalid", "author": "Sonny", "abstract": "Contains C:\\fake\\local\\path and premature unsubmitted URL and sorryAx.", "evidence_tags": ["PROVED"], "verify_command": "python scripts/verify_bundle.py", "standing": { "standing_tier": "frontier_1", "projected_rank_label": "Planted Fault", "baseline_compared": "Planted Fault Baseline", }, "verification": { "tier": 5, "trust_level_zero": False, "zero_axiom_declarations": 0, "planted_controls_total": 1, "planted_controls_rejected": 0, "sha256_manifest_files": 0, }, "declarations": [ {"declaration": "Planted.bad_thm", "axioms": ["sorryAx"]}, ], "venues": [ {"name": "Zenodo", "status": "unsubmitted", "url": "https://zenodo.org/records/fake", "note": "Premature link"}, ], } valid_errs = validate_gcy_card(valid_card) if valid_errs: print("SELF_TEST_FAIL: Valid card was rejected:", valid_errs, file=sys.stderr) return 1 bad_errs = validate_gcy_card(planted_invalid_card) if len(bad_errs) < 5: print("SELF_TEST_FAIL: Planted invalid card did not trigger expected faults:", bad_errs, file=sys.stderr) return 1 print("GCY_INTAKE_SELF_TEST=PASS") print(" VALID_CARD_ERRORS=0") print(f" PLANTED_INVALID_CARD_FAULTS_CAUGHT={len(bad_errs)}") for err in bad_errs: print(f" - REJECTED_AS_REQUIRED: {err}") return 0 def main() -> int: parser = argparse.ArgumentParser(description="GCY-2 Card & Bundle Intake Validator") parser.add_argument("--self-test", action="store_true", help="Run built-in valid + planted-invalid self-test") parser.add_argument("files", nargs="*", help="GCY-2 JSON card files to validate (schema_version=gcy-v1)") args = parser.parse_args() if args.self_test: return run_self_test() if not args.files: parser.print_help() return 2 failed = 0 for fpath in args.files: p = Path(fpath) try: data = json.loads(p.read_text(encoding="utf-8")) except Exception as exc: print(f"FAIL {p.name}: JSON parse error: {exc}", file=sys.stderr) failed += 1 continue errs = validate_gcy_card(data) if errs: print(f"FAIL {p.name}: {len(errs)} error(s)", file=sys.stderr) for e in errs: print(f" - {e}", file=sys.stderr) failed += 1 else: print(f"PASS {p.name} (paper_id={data.get('paper_id')}, tier={data['verification']['tier']})") return 1 if failed else 0 if __name__ == "__main__": raise SystemExit(main())