Spaces:
Running
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): Dockerfile, serve.py, szl_conjecture_factory.py
Deleted (gone from the repo + Dockerfile COPY set): (none)
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- Dockerfile +1 -1
- serve.py +11 -0
- szl_conjecture_factory.py +361 -0
Dockerfile
CHANGED
|
@@ -532,7 +532,7 @@ ENV A11OY_ALLOY_GGUF=/app/models/qwen2.5-coder-0.5b-instruct-q4_k_m.gguf
|
|
| 532 |
# Signed-off-by: Yachay <yachay@szlholdings.ai>
|
| 533 |
# ---------------------------------------------------------------------------
|
| 534 |
COPY a11oy_live_feeds.py a11oy_signing_key.py a11oy_dev1_endpoints.py a11oy_vertical_feeds.py a11oy_deva_feeds.py a11oy_devb_endpoints.py a11oy_amaru_feeds.py szl_governance_gateway.py szl_abacus_verify.py szl_decision_uncertainty.py szl_gor_audit.py szl_sovereign_search.py szl_consensus_clusters.py szl_mission_ledger.py szl_budget_router.py szl_wave910_proofs.py szl_evidence_research.py szl_uds_fleet.py szl_readiness.py szl_quantum_bio.py ./
|
| 535 |
-
COPY szl_unified_formulas.py szl_cuas_formulas.py szl_contracting.py szl_bounties.py szl_putnam.py szl_connectors_serve.py szl_connector_mcp.py ./
|
| 536 |
COPY live_snapshots/ ./live_snapshots/
|
| 537 |
|
| 538 |
# ADDITIVE (Investor-WOW Layer, 2026-06-08, Dev1): a11oy_dev1_endpoints.py exposes
|
|
|
|
| 532 |
# Signed-off-by: Yachay <yachay@szlholdings.ai>
|
| 533 |
# ---------------------------------------------------------------------------
|
| 534 |
COPY a11oy_live_feeds.py a11oy_signing_key.py a11oy_dev1_endpoints.py a11oy_vertical_feeds.py a11oy_deva_feeds.py a11oy_devb_endpoints.py a11oy_amaru_feeds.py szl_governance_gateway.py szl_abacus_verify.py szl_decision_uncertainty.py szl_gor_audit.py szl_sovereign_search.py szl_consensus_clusters.py szl_mission_ledger.py szl_budget_router.py szl_wave910_proofs.py szl_evidence_research.py szl_uds_fleet.py szl_readiness.py szl_quantum_bio.py ./
|
| 535 |
+
COPY szl_unified_formulas.py szl_cuas_formulas.py szl_contracting.py szl_bounties.py szl_putnam.py szl_connectors_serve.py szl_connector_mcp.py szl_conjecture_factory.py ./
|
| 536 |
COPY live_snapshots/ ./live_snapshots/
|
| 537 |
|
| 538 |
# ADDITIVE (Investor-WOW Layer, 2026-06-08, Dev1): a11oy_dev1_endpoints.py exposes
|
serve.py
CHANGED
|
@@ -206,6 +206,17 @@ try:
|
|
| 206 |
print("[a11oy] Open-Problem Bounty Board registered: /api/a11oy/v1/bounties", file=__import__("sys").stderr)
|
| 207 |
except Exception as _szl_bn_e: # pragma: no cover
|
| 208 |
print(f"[a11oy] Open-Problem Bounty Board NOT registered: {_szl_bn_e!r}", file=__import__("sys").stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
# ── Putnam 2025 canonical-set honest verdict (putnam-2025-tab-patch). Serves the
|
| 211 |
# per-problem REAL/DEMO/OPEN verdict for the canonical Putnam 2025 set (A1-A6,
|
|
|
|
| 206 |
print("[a11oy] Open-Problem Bounty Board registered: /api/a11oy/v1/bounties", file=__import__("sys").stderr)
|
| 207 |
except Exception as _szl_bn_e: # pragma: no cover
|
| 208 |
print(f"[a11oy] Open-Problem Bounty Board NOT registered: {_szl_bn_e!r}", file=__import__("sys").stderr)
|
| 209 |
+
# ── Conjecture Factory (conjecture-factory-tab-patch). Honest live board of
|
| 210 |
+
# factory-generated OPEN conjectures read from the real disclosure ledger
|
| 211 |
+
# (szl-lake khipu, kind=conjecture-disclosure-anchor). A conjecture is NEVER a
|
| 212 |
+
# theorem; every item stays OPEN until independently verified; Conjecture 1
|
| 213 |
+
# (Λ uniqueness) is and remains OPEN. Additive, try/except-guarded. Pure stdlib.
|
| 214 |
+
try:
|
| 215 |
+
import szl_conjecture_factory as _szl_conjecture_factory
|
| 216 |
+
_szl_conjecture_factory.register(app, ns="a11oy")
|
| 217 |
+
print("[a11oy] Conjecture Factory registered: /api/a11oy/v1/conjecture-factory", file=__import__("sys").stderr)
|
| 218 |
+
except Exception as _szl_cf_e: # pragma: no cover
|
| 219 |
+
print(f"[a11oy] Conjecture Factory NOT registered: {_szl_cf_e!r}", file=__import__("sys").stderr)
|
| 220 |
|
| 221 |
# ── Putnam 2025 canonical-set honest verdict (putnam-2025-tab-patch). Serves the
|
| 222 |
# per-problem REAL/DEMO/OPEN verdict for the canonical Putnam 2025 set (A1-A6,
|
szl_conjecture_factory.py
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""szl_conjecture_factory.py
|
| 2 |
+
|
| 3 |
+
Read-only loader that surfaces the SZL Conjecture Factory's output for the
|
| 4 |
+
a11oy /console and killinchu /elite consoles.
|
| 5 |
+
|
| 6 |
+
It reads the conjecture-disclosure records the factory appends to the szl-lake
|
| 7 |
+
DSSE Khipu ledger (NDJSON), and exposes them with an HONEST status convention
|
| 8 |
+
("live" / "cached" / "unreachable") identical to the other shared console
|
| 9 |
+
modules.
|
| 10 |
+
|
| 11 |
+
Honesty doctrine (do NOT weaken):
|
| 12 |
+
* A factory-generated problem is a CONJECTURE, never a theorem. It stays OPEN
|
| 13 |
+
until a solution is independently verified.
|
| 14 |
+
* "novelty" is an advisory screen, not a proof of originality.
|
| 15 |
+
* "difficulty"/"grade" come from a bounded solver run: OPEN means
|
| 16 |
+
searched-to-budget (NOT proven true); VERIFIED-FINITE certifies only the
|
| 17 |
+
finite enumerated domain; REFUTED carries a concrete witness.
|
| 18 |
+
* The cosign/Rekor signature attests the timestamp + content, NOT the truth
|
| 19 |
+
of the conjecture.
|
| 20 |
+
* An unreachable source is reported as unreachable; it never confirms novelty
|
| 21 |
+
and we never fabricate a value.
|
| 22 |
+
|
| 23 |
+
Stdlib only (urllib/json) so it drops into the console containers with no extra
|
| 24 |
+
dependency, mirroring szl_bounties.py / szl_evidence_research.py.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
from __future__ import annotations
|
| 28 |
+
|
| 29 |
+
import json
|
| 30 |
+
import os
|
| 31 |
+
import re
|
| 32 |
+
import time
|
| 33 |
+
import urllib.error
|
| 34 |
+
import urllib.request
|
| 35 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 36 |
+
|
| 37 |
+
# --- status labels (shared honest convention) -------------------------------
|
| 38 |
+
STATUS_LIVE = "live"
|
| 39 |
+
STATUS_CACHED = "cached"
|
| 40 |
+
STATUS_UNREACHABLE = "unreachable"
|
| 41 |
+
|
| 42 |
+
# The factory anchors each disclosure under this receipt kind.
|
| 43 |
+
CONJECTURE_KIND = "conjecture-disclosure-anchor"
|
| 44 |
+
CONJECTURE_MILESTONE_KIND = "conjecture-disclosure"
|
| 45 |
+
|
| 46 |
+
# Sources, in priority order. Overridable by env for the box/HF containers.
|
| 47 |
+
# The factory anchors its disclosures into the szl-lake DSSE Khipu ledger.
|
| 48 |
+
# NOTE: the two surfaces use DIFFERENT path prefixes for the same file --
|
| 49 |
+
# HF dataset has no `data/` prefix, GitHub raw does. Probed live.
|
| 50 |
+
_DEFAULT_SOURCES = [
|
| 51 |
+
os.environ.get(
|
| 52 |
+
"SZL_LAKE_NDJSON_HF",
|
| 53 |
+
"https://huggingface.co/datasets/szlholdings/szl-lake/resolve/main/khipu/lutar_lean_receipts.ndjson",
|
| 54 |
+
),
|
| 55 |
+
os.environ.get(
|
| 56 |
+
"SZL_LAKE_NDJSON_GH",
|
| 57 |
+
"https://raw.githubusercontent.com/szl-holdings/szl-lake/main/data/khipu/lutar_lean_receipts.ndjson",
|
| 58 |
+
),
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
_CACHE_PATH = os.environ.get(
|
| 62 |
+
"SZL_CONJECTURE_CACHE",
|
| 63 |
+
os.path.join(os.path.dirname(os.path.abspath(__file__)), ".conjecture_factory_cache.ndjson"),
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
_HTTP_TIMEOUT = float(os.environ.get("SZL_CONJECTURE_HTTP_TIMEOUT", "6"))
|
| 67 |
+
|
| 68 |
+
# Verdict tokens we recognise from the factory's own honesty prose when the
|
| 69 |
+
# record does not carry discrete fields. We only read what the factory wrote;
|
| 70 |
+
# we never invent a verdict.
|
| 71 |
+
_NOVELTY_TOKENS = {"novel-candidate", "known-restatement", "duplicate", "inconclusive"}
|
| 72 |
+
_DIFFICULTY_TOKENS = {"open-resistant", "hard", "moderate", "easy", "verified-finite", "refuted"}
|
| 73 |
+
_GRADE_TOKENS = {"OPEN", "VERIFIED-FINITE", "REFUTED", "RETRACTED"}
|
| 74 |
+
_RELEASE_STAGES = {"teaser", "statement", "solution"}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _first_match(text: Optional[str], allowed: set, lower: bool = True) -> Optional[str]:
|
| 78 |
+
"""Return the first single-quoted token in *text* that is in *allowed*."""
|
| 79 |
+
if not text:
|
| 80 |
+
return None
|
| 81 |
+
for tok in re.findall(r"'([^']+)'", text):
|
| 82 |
+
probe = tok.lower() if lower else tok
|
| 83 |
+
bucket = {a.lower() for a in allowed} if lower else allowed
|
| 84 |
+
if probe in bucket:
|
| 85 |
+
return tok
|
| 86 |
+
return None
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _fetch(url: str) -> Optional[str]:
|
| 90 |
+
if not url:
|
| 91 |
+
return None
|
| 92 |
+
try:
|
| 93 |
+
req = urllib.request.Request(url, headers={"User-Agent": "szl-conjecture-factory/1.0"})
|
| 94 |
+
with urllib.request.urlopen(req, timeout=_HTTP_TIMEOUT) as resp: # nosec - read-only public ledger
|
| 95 |
+
if getattr(resp, "status", 200) != 200:
|
| 96 |
+
return None
|
| 97 |
+
return resp.read().decode("utf-8", "replace")
|
| 98 |
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError, ValueError):
|
| 99 |
+
return None
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _read_cache() -> Optional[str]:
|
| 103 |
+
try:
|
| 104 |
+
with open(_CACHE_PATH, "r", encoding="utf-8") as fh:
|
| 105 |
+
data = fh.read()
|
| 106 |
+
return data if data.strip() else None
|
| 107 |
+
except OSError:
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def _write_cache(raw: str) -> None:
|
| 112 |
+
try:
|
| 113 |
+
tmp = _CACHE_PATH + ".tmp"
|
| 114 |
+
with open(tmp, "w", encoding="utf-8") as fh:
|
| 115 |
+
fh.write(raw)
|
| 116 |
+
os.replace(tmp, _CACHE_PATH)
|
| 117 |
+
except OSError:
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _parse_ndjson(raw: str) -> List[Dict[str, Any]]:
|
| 122 |
+
out: List[Dict[str, Any]] = []
|
| 123 |
+
for line in raw.splitlines():
|
| 124 |
+
line = line.strip()
|
| 125 |
+
if not line:
|
| 126 |
+
continue
|
| 127 |
+
try:
|
| 128 |
+
obj = json.loads(line)
|
| 129 |
+
except json.JSONDecodeError:
|
| 130 |
+
continue
|
| 131 |
+
if isinstance(obj, dict):
|
| 132 |
+
out.append(obj)
|
| 133 |
+
return out
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def _is_conjecture(rec: Dict[str, Any]) -> bool:
|
| 137 |
+
return (
|
| 138 |
+
rec.get("kind") == CONJECTURE_KIND
|
| 139 |
+
or rec.get("milestone_kind") == CONJECTURE_MILESTONE_KIND
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def _normalize(rec: Dict[str, Any]) -> Dict[str, Any]:
|
| 144 |
+
"""Map one ledger record to a console-friendly, honesty-preserving item.
|
| 145 |
+
|
| 146 |
+
Prefers discrete fields if the factory writes them; otherwise reads the
|
| 147 |
+
factory's own honesty prose. Never fabricates a verdict.
|
| 148 |
+
"""
|
| 149 |
+
honesty = rec.get("honesty") or {}
|
| 150 |
+
signing = rec.get("signing") or {}
|
| 151 |
+
source_run = rec.get("source_run") or {}
|
| 152 |
+
|
| 153 |
+
novelty = (
|
| 154 |
+
rec.get("novelty_verdict")
|
| 155 |
+
or rec.get("novelty")
|
| 156 |
+
or _first_match(honesty.get("novelty"), _NOVELTY_TOKENS)
|
| 157 |
+
)
|
| 158 |
+
difficulty = (
|
| 159 |
+
rec.get("difficulty_grade")
|
| 160 |
+
or rec.get("difficulty")
|
| 161 |
+
or _first_match(honesty.get("difficulty"), _DIFFICULTY_TOKENS)
|
| 162 |
+
)
|
| 163 |
+
grade = (
|
| 164 |
+
rec.get("grade")
|
| 165 |
+
or rec.get("milestone_status")
|
| 166 |
+
or _first_match(honesty.get("difficulty"), _GRADE_TOKENS, lower=False)
|
| 167 |
+
)
|
| 168 |
+
release_stage = (
|
| 169 |
+
rec.get("release_stage")
|
| 170 |
+
or rec.get("stage")
|
| 171 |
+
or _first_match(honesty.get("status"), _RELEASE_STAGES)
|
| 172 |
+
or "statement"
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
# Honesty guard: a conjecture is NEVER a theorem and is shown OPEN until
|
| 176 |
+
# independently verified. Only the factory's own VERIFIED-FINITE / REFUTED
|
| 177 |
+
# grades may change that; an absent grade defaults to OPEN, not "proved".
|
| 178 |
+
if not grade:
|
| 179 |
+
grade = "OPEN"
|
| 180 |
+
|
| 181 |
+
return {
|
| 182 |
+
"id": rec.get("receipt_id") or rec.get("milestone_id") or rec.get("chain_index"),
|
| 183 |
+
"title": rec.get("milestone_title") or rec.get("title") or "(untitled conjecture)",
|
| 184 |
+
"statement": rec.get("statement") or honesty.get("conjecture") or "",
|
| 185 |
+
"novelty": novelty,
|
| 186 |
+
"difficulty": difficulty,
|
| 187 |
+
"grade": grade,
|
| 188 |
+
"release_stage": release_stage,
|
| 189 |
+
"is_open": grade not in ("VERIFIED-FINITE", "REFUTED"),
|
| 190 |
+
"organ": rec.get("organ"),
|
| 191 |
+
"kernel_commit_short": rec.get("kernel_commit_short") or (rec.get("kernel_commit") or "")[:12] or None,
|
| 192 |
+
"timestamp": rec.get("timestamp"),
|
| 193 |
+
"chain_index": rec.get("chain_index"),
|
| 194 |
+
"prev_hash": rec.get("prev_hash"),
|
| 195 |
+
"honesty": {
|
| 196 |
+
"status": honesty.get("status"),
|
| 197 |
+
"conjecture": honesty.get("conjecture"),
|
| 198 |
+
"novelty": honesty.get("novelty"),
|
| 199 |
+
"difficulty": honesty.get("difficulty"),
|
| 200 |
+
"signing": honesty.get("signing"),
|
| 201 |
+
"doctrine": honesty.get("doctrine") or rec.get("doctrine"),
|
| 202 |
+
},
|
| 203 |
+
"receipt": {
|
| 204 |
+
"receipt_id": rec.get("receipt_id"),
|
| 205 |
+
"chain_index": rec.get("chain_index"),
|
| 206 |
+
"predicate_type": signing.get("predicate_type"),
|
| 207 |
+
"signing_mode": signing.get("mode"),
|
| 208 |
+
"rekor_log_index": signing.get("rekor_log_index"),
|
| 209 |
+
"rekor_integrated_time": signing.get("rekor_integrated_time"),
|
| 210 |
+
"verify_cmd": signing.get("verify_cmd"),
|
| 211 |
+
"fulcio_identity": signing.get("fulcio_identity"),
|
| 212 |
+
"source_run_url": source_run.get("url"),
|
| 213 |
+
"source_run_workflow": source_run.get("workflow"),
|
| 214 |
+
},
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def load_conjectures(force_refresh: bool = True) -> Dict[str, Any]:
|
| 219 |
+
"""Load factory conjectures with an honest live/cached/unreachable status.
|
| 220 |
+
|
| 221 |
+
Returns a dict::
|
| 222 |
+
|
| 223 |
+
{
|
| 224 |
+
"status": "live" | "cached" | "unreachable",
|
| 225 |
+
"source": <url-or-cache-or-None>,
|
| 226 |
+
"fetched_at": <iso8601 utc>,
|
| 227 |
+
"count": <int>,
|
| 228 |
+
"items": [ ...normalized conjecture items... ],
|
| 229 |
+
"doctrine_banner": <str>, # honesty banner, always present
|
| 230 |
+
}
|
| 231 |
+
"""
|
| 232 |
+
fetched_at = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
| 233 |
+
raw: Optional[str] = None
|
| 234 |
+
source: Optional[str] = None
|
| 235 |
+
status = STATUS_UNREACHABLE
|
| 236 |
+
|
| 237 |
+
if force_refresh:
|
| 238 |
+
for url in _DEFAULT_SOURCES:
|
| 239 |
+
data = _fetch(url)
|
| 240 |
+
if data is not None:
|
| 241 |
+
raw, source, status = data, url, STATUS_LIVE
|
| 242 |
+
_write_cache(data)
|
| 243 |
+
break
|
| 244 |
+
|
| 245 |
+
if raw is None:
|
| 246 |
+
cached = _read_cache()
|
| 247 |
+
if cached is not None:
|
| 248 |
+
raw, source, status = cached, _CACHE_PATH, STATUS_CACHED
|
| 249 |
+
|
| 250 |
+
items: List[Dict[str, Any]] = []
|
| 251 |
+
if raw is not None:
|
| 252 |
+
for rec in _parse_ndjson(raw):
|
| 253 |
+
if _is_conjecture(rec):
|
| 254 |
+
items.append(_normalize(rec))
|
| 255 |
+
|
| 256 |
+
# Stable, newest-first ordering by chain_index when available.
|
| 257 |
+
items.sort(key=lambda it: (it.get("chain_index") or 0), reverse=True)
|
| 258 |
+
|
| 259 |
+
return {
|
| 260 |
+
"status": status,
|
| 261 |
+
"source": source,
|
| 262 |
+
"fetched_at": fetched_at,
|
| 263 |
+
"count": len(items),
|
| 264 |
+
"items": items,
|
| 265 |
+
"doctrine_banner": (
|
| 266 |
+
"Factory output is a set of OPEN conjectures \u2014 generated, not proven. "
|
| 267 |
+
"Each stays OPEN until a solution is independently verified; novelty is an "
|
| 268 |
+
"advisory screen; signatures attest timestamp + content, not truth. "
|
| 269 |
+
"Conjecture 1 (unconditional \u039b uniqueness) is and remains OPEN."
|
| 270 |
+
),
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def load_conjecture(receipt_id: str, force_refresh: bool = True) -> Optional[Dict[str, Any]]:
|
| 275 |
+
"""Return a single normalized conjecture by receipt_id (or None)."""
|
| 276 |
+
bundle = load_conjectures(force_refresh=force_refresh)
|
| 277 |
+
for it in bundle["items"]:
|
| 278 |
+
if it.get("id") == receipt_id or it.get("receipt", {}).get("receipt_id") == receipt_id:
|
| 279 |
+
return {**it, "_envelope_status": bundle["status"], "_fetched_at": bundle["fetched_at"]}
|
| 280 |
+
return None
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# --- registration (FastAPI, mirrors szl_bounties.register) -------------------
|
| 284 |
+
def register(app, ns: str = "a11oy") -> None:
|
| 285 |
+
"""Attach the Conjecture Factory endpoints for namespace *ns*.
|
| 286 |
+
|
| 287 |
+
Mounts (read-only)::
|
| 288 |
+
|
| 289 |
+
GET /api/{ns}/v1/conjecture-factory -> honest bundle
|
| 290 |
+
GET /api/{ns}/v1/conjecture-factory/{rid} -> single conjecture (404 if absent)
|
| 291 |
+
|
| 292 |
+
Mirrors the szl_bounties.register() convention so the deploy is a one-line
|
| 293 |
+
import + register() and the module ships byte-identical to both consoles.
|
| 294 |
+
"""
|
| 295 |
+
try:
|
| 296 |
+
from fastapi.responses import JSONResponse
|
| 297 |
+
except Exception: # pragma: no cover - non-FastAPI host
|
| 298 |
+
return
|
| 299 |
+
|
| 300 |
+
base = "/api/%s/v1/conjecture-factory" % ns
|
| 301 |
+
|
| 302 |
+
@app.get(base)
|
| 303 |
+
async def _conjectures_index(): # noqa: ANN202
|
| 304 |
+
bundle = load_conjectures(force_refresh=True)
|
| 305 |
+
return JSONResponse({
|
| 306 |
+
"layer": "%s conjecture factory" % ns,
|
| 307 |
+
"honest": bundle["doctrine_banner"],
|
| 308 |
+
"doctrine": "v11",
|
| 309 |
+
"status": bundle["status"],
|
| 310 |
+
"source": bundle["source"],
|
| 311 |
+
"count": bundle["count"],
|
| 312 |
+
"conjectures": bundle["items"],
|
| 313 |
+
"checked_at": bundle["fetched_at"],
|
| 314 |
+
})
|
| 315 |
+
|
| 316 |
+
@app.get(base + "/{rid}")
|
| 317 |
+
async def _conjecture_one(rid: str): # noqa: ANN202
|
| 318 |
+
item = load_conjecture(rid, force_refresh=True)
|
| 319 |
+
if item is None:
|
| 320 |
+
return JSONResponse(
|
| 321 |
+
{"error": "unknown conjecture", "receipt_id": rid},
|
| 322 |
+
status_code=404,
|
| 323 |
+
)
|
| 324 |
+
return JSONResponse({
|
| 325 |
+
"layer": "%s conjecture" % ns,
|
| 326 |
+
"doctrine": "v11",
|
| 327 |
+
"conjecture": item,
|
| 328 |
+
})
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
# --- offline self-test against a local ledger --------------------------------
|
| 332 |
+
def _selftest(path: str) -> int:
|
| 333 |
+
"""Parse a local NDJSON ledger (no network) and print a summary."""
|
| 334 |
+
with open(path, "r", encoding="utf-8") as fh:
|
| 335 |
+
raw = fh.read()
|
| 336 |
+
recs = _parse_ndjson(raw)
|
| 337 |
+
conj = [_normalize(r) for r in recs if _is_conjecture(r)]
|
| 338 |
+
print(f"records={len(recs)} conjectures={len(conj)}")
|
| 339 |
+
for it in conj:
|
| 340 |
+
print(
|
| 341 |
+
f" - id={it['id'][:16] if it['id'] else None}... "
|
| 342 |
+
f"title={it['title']!r} novelty={it['novelty']} "
|
| 343 |
+
f"difficulty={it['difficulty']} grade={it['grade']} "
|
| 344 |
+
f"stage={it['release_stage']} open={it['is_open']} "
|
| 345 |
+
f"rekor={it['receipt']['rekor_log_index']}"
|
| 346 |
+
)
|
| 347 |
+
# honesty assertions
|
| 348 |
+
assert it["grade"] != "PROVED", "conjecture must never be graded PROVED"
|
| 349 |
+
assert "theorem" not in it["title"].lower() or it["is_open"], "conjecture mislabeled as theorem"
|
| 350 |
+
return 0
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
if __name__ == "__main__":
|
| 354 |
+
import sys
|
| 355 |
+
|
| 356 |
+
target = sys.argv[1] if len(sys.argv) > 1 else None
|
| 357 |
+
if target:
|
| 358 |
+
raise SystemExit(_selftest(target))
|
| 359 |
+
out = load_conjectures()
|
| 360 |
+
print(json.dumps({k: v for k, v in out.items() if k != "items"}, indent=2))
|
| 361 |
+
print(f"items={out['count']}")
|