betterwithage commited on
Commit
2a5fe4a
·
verified ·
1 Parent(s): 34a46c6

chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)

Browse files

Automated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): serve.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.

Files changed (1) hide show
  1. serve.py +192 -0
serve.py CHANGED
@@ -681,6 +681,198 @@ try:
681
  except Exception as _szl_ipinn_e: # pragma: no cover
682
  print(f"[a11oy] Governed Inverse-PINN NOT registered (a11oy continues): {_szl_ipinn_e!r}", file=__import__("sys").stderr)
683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  # ── Compliance crosswalk MESH (compliance-mesh) — closes the audited gap where the
685
  # doctrine-v11 → NIST AI RMF / ISO 42001 / EU AI Act crosswalk module existed
686
  # (szl_compliance_mesh.py + compliance_crosswalk.py, REAL honest data with
 
681
  except Exception as _szl_ipinn_e: # pragma: no cover
682
  print(f"[a11oy] Governed Inverse-PINN NOT registered (a11oy continues): {_szl_ipinn_e!r}", file=__import__("sys").stderr)
683
 
684
+ # ── Auditor Evidence Pack (assurance-evidence-pack) — closes GAP 3 where
685
+ # GET /api/a11oy/v1/assurance/evidence-pack 404'd. Assembles ONE signed, offline-
686
+ # verifiable auditor pack at REQUEST time from material that is ALREADY LIVE:
687
+ # • assurance matrix (szl_assurance.ASSURANCE_MATRIX — CDAO/DoD req→artifact,
688
+ # honest IMPLEMENTED/PARTIAL/ROADMAP labels)
689
+ # • khipu chain heads + re-walked links_intact per organ (szl_khipu_verify.list_organs)
690
+ # • lake health snapshot (szl_lake_store … sha3_256, total_receipts, per-organ chain_head)
691
+ # • doctrine snapshot (8 locked-proven, kernel c7c0ba17, Λ=Conjecture 1, Khipu BFT=
692
+ # Conjecture 2, liveness=Conjecture 3 — REAL values, never inflated)
693
+ # • generated_at + the cosign public-key fingerprint.
694
+ # The pack body is canonicalised + sha3_256-hashed and that digest is INCLUDED so an
695
+ # auditor re-verifies OFFLINE (no server round-trip). If demo signing is available
696
+ # (szl_demo_sign / SZL_DEMO_SIGN_KEY) the digest is signed with the clearly-labelled
697
+ # DEMO key (keyid=demo-signing-key — NOT production cosign); otherwise an honest
698
+ # DSSE_PLACEHOLDER unsigned note. NEVER a fabricated signature.
699
+ # PURE STDLIB (json, hashlib sha3_256, time) — the numpy-less HF web image has no
700
+ # numpy/pandas; every optional dep is imported INSIDE the handler under try/except and
701
+ # degrades HONESTLY (never 404, never raises into startup). Routes are FRONT-MOVED to
702
+ # the HEAD of app.router.routes (same proven pattern as the inverse-PINN +
703
+ # compliance-mesh blocks) so they win over the /api/a11oy/{path:path} Node proxy + SPA
704
+ # catch-all defined at the file tail. Additive, try/except-guarded.
705
+ try:
706
+ from starlette.routing import Route as _EPRoute
707
+ from starlette.responses import JSONResponse as _EPJSON
708
+
709
+ # Doctrine snapshot — REAL values read from the codebase (szl_willay_gateway.DOCTRINE,
710
+ # szl_yupay.LOCKED_THEOREMS, AGENTS.md). NEVER inflate the locked count past 8.
711
+ _EP_DOCTRINE = {
712
+ "version": "v11 LOCKED",
713
+ "locked_proven": 8,
714
+ "locked_theorems": ["F1", "F4", "F7", "F11", "F12", "F18", "F19", "F22"],
715
+ "locked_count_ci_gate": "locked_count_eight (no-axiom theorem)",
716
+ "kernel_commit": "c7c0ba17",
717
+ "lambda": "Conjecture 1 (advisory; Λ-uniqueness is NOT a theorem)",
718
+ "khipu_bft": ("Conjecture 2 (chain INTEGRITY is real and recomputed via sha3_256 "
719
+ "re-walk; BFT/consensus safety across replicas is the OPEN conjecture, "
720
+ "NOT proven)"),
721
+ "liveness": "Conjecture 3 (advisory; agentic-loop liveness is NOT a closed theorem)",
722
+ "slsa": "L1 honest · L2 roadmap · L3 roadmap",
723
+ "accreditation": {
724
+ "ato": "NOT obtained — ROADMAP",
725
+ "il5": "NOT obtained — ROADMAP",
726
+ "fedramp_high": "NOT obtained — ROADMAP",
727
+ },
728
+ "honest_note": ("a11oy is the governance OVERLAY — NOT accredited. Chain integrity is "
729
+ "COMPUTED (sha3_256 re-walk), never asserted. 8 locked-proven only; "
730
+ "Λ/Khipu/liveness are conjectures, never theorems. No datum is fabricated."),
731
+ }
732
+
733
+ def _ep_canon(obj):
734
+ import json as _j
735
+ return _j.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
736
+
737
+ def _ep_sha3(b):
738
+ import hashlib as _h
739
+ return _h.sha3_256(b).hexdigest()
740
+
741
+ def _ep_assurance():
742
+ try:
743
+ import szl_assurance as _a # REAL CDAO/DoD requirement → artifact matrix
744
+ return {
745
+ "source": "/api/a11oy/v1/assurance/matrix",
746
+ "status": "LIVE",
747
+ "requirement_count": len(_a.ASSURANCE_MATRIX),
748
+ "requirements": _a.ASSURANCE_MATRIX,
749
+ "honest_note": ("Status: LIVE=operational; MEASURED=real data; SAMPLE=demo; "
750
+ "MODELED=model-derived; ROADMAP=planned. ATO/IL5/FedRAMP=ROADMAP."),
751
+ }
752
+ except Exception as _e: # honest degrade — NEVER 404
753
+ return {"source": "/api/a11oy/v1/assurance/matrix", "status": "NO-LIVE-DATA",
754
+ "label": "ROADMAP — assurance matrix unavailable in this build",
755
+ "detail": str(_e)[:160], "fabricated": False}
756
+
757
+ def _ep_khipu():
758
+ try:
759
+ import szl_khipu_verify as _k # re-walks prev-links; links_intact is COMPUTED
760
+ return _k.list_organs()
761
+ except Exception as _e:
762
+ return {"source": "/api/a11oy/v1/khipu/organs", "ok": False, "status": "NO-LIVE-DATA",
763
+ "label": "ROADMAP — khipu organs unavailable in this build",
764
+ "detail": str(_e)[:160], "fabricated": False}
765
+
766
+ def _ep_lake():
767
+ try:
768
+ import szl_lake_store as _l # sha3_256 chain alg, total_receipts, per-organ heads
769
+ return _l.get_default_ledger().health()
770
+ except Exception as _e:
771
+ return {"source": "/api/lake/v1/health", "ok": False, "status": "NO-LIVE-DATA",
772
+ "label": "ROADMAP — lake health unavailable in this build",
773
+ "detail": str(_e)[:160], "fabricated": False}
774
+
775
+ def _ep_cosign():
776
+ # Fingerprint of the DEMO public key (PUBLIC data). The PRODUCTION founder-gated
777
+ # cosign key is NEVER placed in this runtime — stated plainly, never faked.
778
+ try:
779
+ import szl_demo_sign as _d, hashlib as _h
780
+ pem = _d.DEMO_COSIGN_PUBLIC_PEM.strip()
781
+ fp = _h.sha256(pem.encode("utf-8")).hexdigest()
782
+ try:
783
+ available = bool(_d.demo_signing_available())
784
+ except Exception:
785
+ available = False
786
+ return {
787
+ "key_id": _d.DEMO_KEY_ID,
788
+ "key_kind": "demo",
789
+ "verify_key_url": "/demo-cosign.pub",
790
+ "sha256_fingerprint": fp,
791
+ "demo_signing_available": available,
792
+ "note": (_d.DEMO_NOTE + ". The production founder-gated cosign key is NEVER "
793
+ "placed in this runtime; this fingerprint is the DEMO public key."),
794
+ }
795
+ except Exception as _e:
796
+ return {"key_id": None, "status": "NO-KEY",
797
+ "note": "no signing key available in runtime — pack is honest-unsigned (DSSE_PLACEHOLDER)",
798
+ "detail": str(_e)[:160]}
799
+
800
+ def _ep_sign(digest):
801
+ try:
802
+ import szl_demo_sign as _d
803
+ env = _d.sign_payload_demo({"a11oy_evidence_pack_sha3_256": digest})
804
+ if env is not None:
805
+ return {
806
+ "signed": True,
807
+ "alg": "ECDSA-P256-SHA256 over DSSE PAE",
808
+ "keyid": env.get("key_id"),
809
+ "key_kind": "demo",
810
+ "verify_key_url": "/demo-cosign.pub",
811
+ "dsse": env,
812
+ "note": (_d.DEMO_NOTE + " — NOT production cosign. Verify in-browser against "
813
+ "/demo-cosign.pub. The sha3_256 self-digest is independently "
814
+ "recomputable offline regardless of signature."),
815
+ }
816
+ except Exception as _e:
817
+ return {"signed": False, "status": "DSSE_PLACEHOLDER",
818
+ "note": ("signing path unavailable — honest-unsigned. The sha3_256 self-digest "
819
+ "is still independently recomputable offline; NEVER a fabricated signature."),
820
+ "detail": str(_e)[:160]}
821
+ return {"signed": False, "status": "DSSE_PLACEHOLDER",
822
+ "note": ("no demo signing key in runtime (SZL_DEMO_SIGN_KEY absent) — honest-unsigned. "
823
+ "The sha3_256 self-digest is independently recomputable offline; "
824
+ "NEVER a fabricated signature.")}
825
+
826
+ def _ep_handler(request=None):
827
+ import time as _t
828
+ try:
829
+ generated_at = _t.strftime("%Y-%m-%dT%H:%M:%SZ", _t.gmtime())
830
+ pack = {
831
+ "schema": "szl.a11oy.assurance.evidence-pack.v1",
832
+ "generated_at": generated_at,
833
+ "what": ("Single, offline-verifiable auditor evidence pack assembled at REQUEST "
834
+ "time from already-live a11oy surfaces. stdlib-only; no fabrication."),
835
+ "assurance_matrix": _ep_assurance(),
836
+ "khipu_organs": _ep_khipu(),
837
+ "lake_health": _ep_lake(),
838
+ "doctrine": _EP_DOCTRINE,
839
+ "cosign_public_key": _ep_cosign(),
840
+ "honest_disclosure": ("a11oy is the governance overlay, NOT accredited "
841
+ "(ATO/IL5/FedRAMP are ROADMAP). Chain integrity is COMPUTED "
842
+ "(sha3_256 re-walk), never asserted. Khipu BFT is Conjecture 2 "
843
+ "(NOT proven). 8 locked-proven only. No datum here is fabricated."),
844
+ }
845
+ body = _ep_canon(pack)
846
+ digest = _ep_sha3(body)
847
+ signature = _ep_sign(digest)
848
+ return _EPJSON({
849
+ "schema": "szl.a11oy.assurance.evidence-pack.envelope.v1",
850
+ "pack": pack,
851
+ "pack_sha3_256": digest,
852
+ "digest_alg": "sha3_256",
853
+ "digest_canonicalization": ("json.dumps(pack, sort_keys=True, "
854
+ "separators=(',',':'), ensure_ascii=False)"
855
+ ".encode('utf-8') then hashlib.sha3_256(...).hexdigest()"),
856
+ "offline_verify": ("Recompute: take the 'pack' object verbatim, canonicalise per "
857
+ "digest_canonicalization, sha3_256 it, and confirm it equals "
858
+ "pack_sha3_256. Zero server round-trip required."),
859
+ "signature": signature,
860
+ "generated_at": generated_at,
861
+ })
862
+ except Exception as _e: # last-resort honest degrade — NEVER 404, NEVER raises
863
+ return _EPJSON({
864
+ "schema": "szl.a11oy.assurance.evidence-pack.envelope.v1",
865
+ "status": "DEGRADED",
866
+ "label": "ROADMAP — evidence pack temporarily unavailable in this build",
867
+ "detail": str(_e)[:200], "fabricated": False})
868
+
869
+ # Front-move so these beat the /api/a11oy/{path:path} Node proxy + SPA catch-all.
870
+ for _ep_path in ("/v1/assurance/evidence-pack", "/api/a11oy/v1/assurance/evidence-pack"):
871
+ app.router.routes.insert(0, _EPRoute(_ep_path, _ep_handler, methods=["GET"]))
872
+ print("[a11oy] Assurance evidence-pack registered (front-moved): /api/a11oy/v1/assurance/evidence-pack", file=__import__("sys").stderr)
873
+ except Exception as _szl_ep_e: # pragma: no cover
874
+ print(f"[a11oy] Assurance evidence-pack NOT registered: {_szl_ep_e!r}", file=__import__("sys").stderr)
875
+
876
  # ── Compliance crosswalk MESH (compliance-mesh) — closes the audited gap where the
877
  # doctrine-v11 → NIST AI RMF / ISO 42001 / EU AI Act crosswalk module existed
878
  # (szl_compliance_mesh.py + compliance_crosswalk.py, REAL honest data with