betterwithage commited on
Commit
7bdf29d
·
verified ·
1 Parent(s): bf930e8

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): Dockerfile, serve.py, szl_mosaic_governance.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 (3) hide show
  1. Dockerfile +1 -1
  2. serve.py +18 -0
  3. szl_mosaic_governance.py +252 -0
Dockerfile CHANGED
@@ -590,7 +590,7 @@ ENV A11OY_ALLOY_GGUF=/app/models/qwen2.5-coder-0.5b-instruct-q4_k_m.gguf
590
  # untouched; A11OY_REQUIRE_LOCAL_LLM gate + demo-tier RUN logic untouched.
591
  # Signed-off-by: Yachay <yachay@szlholdings.ai>
592
  # ---------------------------------------------------------------------------
593
- 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 ./
594
  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 ./
595
  COPY live_snapshots/ ./live_snapshots/
596
 
 
590
  # untouched; A11OY_REQUIRE_LOCAL_LLM gate + demo-tier RUN logic untouched.
591
  # Signed-off-by: Yachay <yachay@szlholdings.ai>
592
  # ---------------------------------------------------------------------------
593
+ 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 szl_mosaic_governance.py ./
594
  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 ./
595
  COPY live_snapshots/ ./live_snapshots/
596
 
serve.py CHANGED
@@ -112,6 +112,24 @@ try:
112
  except Exception as _szl_ev_e: # pragma: no cover
113
  print(f"[a11oy] Evidence & Research NOT registered: {_szl_ev_e!r}", file=__import__("sys").stderr)
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  # ── Unified engine status (f3-status-api) — the ONE read-only feed the 3D hologram
116
  # (F1) and every dashboard read from: GET /api/a11oy/v1/engine/status aggregates the
117
  # WHOLE agentic-GPU organism (mind / 6 organs / energy / swarm / doctrine) into one
 
112
  except Exception as _szl_ev_e: # pragma: no cover
113
  print(f"[a11oy] Evidence & Research NOT registered: {_szl_ev_e!r}", file=__import__("sys").stderr)
114
 
115
+ # ── Mosaic governance-over-anomalies (feat/mosaic-governance-oversight) — a11oy is
116
+ # the orchestrating governance brain over the SZL-Mosaic field detector
117
+ # (szl_mosaic_core, sibling package). Adds GET /api/a11oy/v1/mosaic/governed:
118
+ # the GOVERNED view of each anomaly receipt (13-axis Lambda advisory verdict
119
+ # allow/advisory/deny, signed-or-honestly-UNSIGNED provenance receipt, the
120
+ # human-approval gate for high-impact ROE deny advisories, a fused COP roll-up,
121
+ # and Khipu BFT 3-of-4 multi-witness confirmation). Honest SNAPSHOT when no live
122
+ # engine feed is wired into this Space (verified=false; no live count or signature
123
+ # fabricated). Receipt SHAPE is byte-compatible with szl_mosaic_core's
124
+ # ProvenanceReceipt (schema szl.mosaic.receipt/v1). Additive, try/except-guarded,
125
+ # registered EARLY (before the SPA catch-all). Pure stdlib, no new deps, no network.
126
+ try:
127
+ import szl_mosaic_governance as _szl_mosaic_governance
128
+ _szl_mosaic_governance.register(app, ns="a11oy")
129
+ print("[a11oy] Mosaic governance registered: /api/a11oy/v1/mosaic/governed", file=__import__("sys").stderr)
130
+ except Exception as _szl_mz_e: # pragma: no cover
131
+ print(f"[a11oy] Mosaic governance NOT registered: {_szl_mz_e!r}", file=__import__("sys").stderr)
132
+
133
  # ── Unified engine status (f3-status-api) — the ONE read-only feed the 3D hologram
134
  # (F1) and every dashboard read from: GET /api/a11oy/v1/engine/status aggregates the
135
  # WHOLE agentic-GPU organism (mind / 6 organs / energy / swarm / doctrine) into one
szl_mosaic_governance.py ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # (c) 2026 Lutar, Stephen P. - SZL Holdings
3
+ """
4
+ szl_mosaic_governance.py - a11oy GOVERNANCE-OVER-ANOMALIES surface.
5
+
6
+ a11oy is the orchestrating governance brain. killinchu / the SZL Mosaic engine
7
+ (szl_mosaic_core.py, in the sibling mosaic_szl package) is the FIELD detector:
8
+ it detects/scores anomalies and emits structured provenance receipts
9
+ (schema "szl.mosaic.receipt/v1"). THIS module is the GOVERNED VIEW over those
10
+ detections: it takes each anomaly receipt and presents
11
+
12
+ - its 13-axis Lambda advisory verdict (allow | advisory | deny)
13
+ - its signed provenance receipt (DSSE/Khipu, honestly UNSIGNED here)
14
+ - the human-approval gate for high-impact ROE actions (operator approvals)
15
+ - a fused Common-Operating-Picture (COP) roll-up: counts of tracks / anomalies
16
+ / verdicts across the air + maritime + (roadmap) orbital domains
17
+ - multi-witness threat confirmation via Khipu BFT 3-of-4 (Conjecture 2)
18
+
19
+ clean-room note
20
+ ---------------
21
+ This is a CLEAN-ROOM SZL surface inspired ONLY by the *publicly described*
22
+ capability of True Anomaly Inc.'s "Mosaic" (SDA / C2 / Threat-Warning &
23
+ Assessment -> Common Operating Picture). NO proprietary Mosaic source, assets,
24
+ or internals were seen or copied. See estate_audit/mosaic_identification.md.
25
+
26
+ HONEST POSTURE (Doctrine v11) - binding:
27
+ - Lambda (L) = Conjecture 1 (conditional, ADVISORY). NEVER "proven trust".
28
+ Verdicts are advisories under human-on-the-loop, never autonomous authority.
29
+ - Khipu BFT safety = Conjecture 2 (Wave23 conditional, OPEN). Multi-witness
30
+ confirmation REDUCES single-sensor risk; it is not a proof of correctness.
31
+ - Confidence is a BOUNDED / conformal interval (finite-sample), not a certainty.
32
+ - locked-proven formulas = 8 {F1,F4,F7,F11,F12,F18,F19,F22}; organs EXPERIMENTAL.
33
+ - Receipts are real-DSSE-or-honestly-UNSIGNED, never silently fabricated.
34
+ - When no live engine feed is wired into THIS Space, the surface returns a
35
+ clearly-labeled deterministic SNAPSHOT (source="snapshot", verified=false).
36
+ It NEVER fabricates a live count or a signature.
37
+ - Sovereign own-metal, 0 CDN; pure stdlib here (no network, no new deps).
38
+
39
+ The receipt SHAPE returned here is byte-compatible with szl_mosaic_core.py's
40
+ ProvenanceReceipt ("szl.mosaic.receipt/v1") so that, once the engine feed is
41
+ wired in, the GOVERNED view ingests REAL receipts with zero schema change.
42
+ """
43
+
44
+ from __future__ import annotations
45
+
46
+ import hashlib
47
+ import json
48
+ import time
49
+
50
+ # 13-axis Lambda trust vocabulary (advisory; Conjecture 1). Same family the
51
+ # console's Trust Score (lambda) tab already names. Listed for the governed view
52
+ # so an operator can see WHICH axes a given anomaly's advisory verdict leaned on.
53
+ LAMBDA_AXES = [
54
+ "provenance", "consistency", "calibration", "robustness", "freshness",
55
+ "corroboration", "specificity", "authority", "reversibility", "containment",
56
+ "sensor_integrity", "graph_deviation", "human_review",
57
+ ]
58
+
59
+ # Advisory thresholds mirror szl_mosaic_core.SZLMosaicCore defaults so the
60
+ # governed view's verdict math matches the field engine's exactly.
61
+ _ALLOW_THR = 0.35
62
+ _DENY_THR = 0.65
63
+
64
+ _DOCTRINE = {
65
+ "doctrine": "v11",
66
+ "lambda": "Conjecture 1 (conditional, ADVISORY) - NOT proven trust",
67
+ "khipu_bft": "Conjecture 2 (Wave23 conditional, OPEN) - multi-witness, not a proof",
68
+ "locked_proven": 8,
69
+ "locked_facts": ["F1", "F4", "F7", "F11", "F12", "F18", "F19", "F22"],
70
+ "organs": "EXPERIMENTAL",
71
+ "slsa": "L1 honest / L2 build-attested / L3 roadmap",
72
+ "joules": "MEASURED only (none claimed here)",
73
+ "sovereign": "own-metal only; 0 CDN",
74
+ "free_energy": False,
75
+ "receipts": "real-DSSE-or-honestly-UNSIGNED; never silently fabricated",
76
+ "human_on_the_loop": True,
77
+ }
78
+
79
+
80
+ def _verdict(score: float) -> str:
81
+ """Honest ADVISORY Lambda verdict (Conjecture 1). Never 'proven trust'."""
82
+ if score < _ALLOW_THR:
83
+ return "allow"
84
+ if score < _DENY_THR:
85
+ return "advisory"
86
+ return "deny"
87
+
88
+
89
+ def _h(*parts) -> str:
90
+ h = hashlib.sha256()
91
+ for p in parts:
92
+ h.update(str(p).encode())
93
+ return h.hexdigest()
94
+
95
+
96
+ def _receipt(track_id, domain, score, components, witnesses, ci, ts):
97
+ """One governed anomaly record, receipt SHAPE-compatible with
98
+ szl_mosaic_core.ProvenanceReceipt (schema szl.mosaic.receipt/v1).
99
+
100
+ verified=False and signing=UNSIGNED: this Space does not hold the cosign key,
101
+ so we mark the receipt honestly unsigned and name exactly where a real DSSE/
102
+ Khipu signature attaches. We never fabricate a signature.
103
+ """
104
+ verdict = _verdict(score)
105
+ quorum_ok = witnesses >= 3 # Khipu BFT 3-of-4 (Conjecture 2)
106
+ return {
107
+ "schema": "szl.mosaic.receipt/v1",
108
+ "inputs_sha256": _h("mosaic-gov-snapshot", track_id, domain, round(score, 6), ts),
109
+ "track_id": track_id,
110
+ "domain": domain,
111
+ "timestep": ts,
112
+ "detector_ensemble": [
113
+ "IsolationForest(PyOD-lineage,BSD-2)",
114
+ "Autoencoder(Merlion/TODS-lineage,BSD-3/Apache-2)",
115
+ "RobustZScore(tsod-lineage,MIT)",
116
+ "GraphDeviation(GDN/PyGOD-lineage,MIT/BSD-2)",
117
+ ],
118
+ "component_scores": components,
119
+ "anomaly_score": round(float(score), 4),
120
+ "confidence_interval": [round(ci[0], 4), round(ci[1], 4)],
121
+ "confidence_method": (
122
+ "split-conformal-style, alpha=0.1 (bounded finite-sample interval, "
123
+ "NOT a certainty claim)"
124
+ ),
125
+ "lambda_verdict": verdict,
126
+ "lambda_note": (
127
+ "Lambda is Conjecture 1 (conditional, ADVISORY) - NOT proven trust. "
128
+ "Human-on-the-loop required."
129
+ ),
130
+ # Khipu BFT 3-of-4 multi-witness confirmation (Conjecture 2, OPEN).
131
+ "khipu_witnesses": witnesses,
132
+ "khipu_quorum": "3-of-4",
133
+ "khipu_quorum_reached": quorum_ok,
134
+ "khipu_note": (
135
+ "BFT 3-of-4 multi-witness confirmation (Conjecture 2, OPEN) reduces "
136
+ "single-sensor/spoof risk; it is not a proof of correctness."
137
+ ),
138
+ # High-impact deny advisories require an explicit operator approval gate.
139
+ "requires_human_approval": verdict == "deny",
140
+ "approval_state": "PENDING_OPERATOR" if verdict == "deny" else "n/a",
141
+ "verified": False,
142
+ "signing": (
143
+ "UNSIGNED - sign downstream via DSSE/Khipu in a11oy / khipu-consensus "
144
+ "(BFT 3-of-4) on a SHA-256 Merkle DAG. real-DSSE-or-honestly-UNSIGNED; "
145
+ "never silently fabricated."
146
+ ),
147
+ "doctrine": "v11",
148
+ }
149
+
150
+
151
+ def _snapshot():
152
+ """Deterministic, clearly-labeled SNAPSHOT of the governed-anomaly picture.
153
+
154
+ Used when no live SZL-Mosaic engine feed is wired into THIS Space. Every
155
+ field is labeled source="snapshot" / verified=false. NO live count and NO
156
+ signature is fabricated. The shape is identical to what a live feed returns,
157
+ so the frontend code path is the same live-or-snapshot.
158
+ """
159
+ ts = 0
160
+ # A small, honest illustrative population spanning the fused COP domains.
161
+ # Scores are fixed (deterministic), not random, so the snapshot is stable.
162
+ rows = [
163
+ # track_id, domain, score, witnesses, components
164
+ (101, "air", 0.12, 4, {"iforest": 0.10, "autoencoder": 0.14, "robust_zscore": 0.11}),
165
+ (102, "air", 0.41, 4, {"iforest": 0.39, "autoencoder": 0.45, "robust_zscore": 0.38}),
166
+ (103, "maritime", 0.22, 3, {"iforest": 0.20, "autoencoder": 0.26, "robust_zscore": 0.21}),
167
+ (104, "maritime", 0.71, 4, {"iforest": 0.68, "autoencoder": 0.77, "robust_zscore": 0.69}),
168
+ (105, "air", 0.83, 4, {"iforest": 0.81, "autoencoder": 0.88, "robust_zscore": 0.80}),
169
+ (106, "orbital", 0.34, 2, {"iforest": 0.31, "autoencoder": 0.39, "robust_zscore": 0.33}),
170
+ ]
171
+ receipts = []
172
+ for tid, dom, sc, wit, comp in rows:
173
+ ci = (max(0.0, sc - 0.07), min(1.0, sc + 0.07))
174
+ receipts.append(_receipt(tid, dom, sc, comp, wit, ci, ts))
175
+
176
+ # Fused Common-Operating-Picture roll-up across domains.
177
+ by_verdict = {"allow": 0, "advisory": 0, "deny": 0}
178
+ by_domain = {}
179
+ for r in receipts:
180
+ by_verdict[r["lambda_verdict"]] += 1
181
+ by_domain[r["domain"]] = by_domain.get(r["domain"], 0) + 1
182
+ quorum_ok = sum(1 for r in receipts if r["khipu_quorum_reached"])
183
+ pending = [r["track_id"] for r in receipts if r["approval_state"] == "PENDING_OPERATOR"]
184
+
185
+ return {
186
+ "status": "ok",
187
+ "ns": "a11oy",
188
+ "source": "snapshot",
189
+ "source_note": (
190
+ "SNAPSHOT - no live SZL-Mosaic engine feed is wired into this Space. "
191
+ "Deterministic illustrative population; verified=false; no live count "
192
+ "or signature is fabricated. Wire szl_mosaic_core receipts here to go live."
193
+ ),
194
+ "generated_at_unix": int(time.time()),
195
+ "cop": {
196
+ "tracks_total": len(receipts),
197
+ "anomalies_scored": len(receipts),
198
+ "by_verdict": by_verdict,
199
+ "by_domain": by_domain,
200
+ "domains": ["air", "maritime", "orbital (roadmap)"],
201
+ "khipu_quorum_reached": quorum_ok,
202
+ "khipu_quorum_total": len(receipts),
203
+ "pending_operator_approvals": pending,
204
+ },
205
+ "lambda_axes": LAMBDA_AXES,
206
+ "thresholds": {"allow_below": _ALLOW_THR, "deny_at_or_above": _DENY_THR},
207
+ "receipts": receipts,
208
+ "doctrine": _DOCTRINE,
209
+ }
210
+
211
+
212
+ def governed_view():
213
+ """Public entrypoint. Returns the governed-anomaly picture.
214
+
215
+ This Space carries no live engine feed, so it returns the honest SNAPSHOT.
216
+ When a live SZL-Mosaic receipt stream is mounted, replace the snapshot source
217
+ with the ingested receipts (same schema) and set source="live".
218
+ """
219
+ return _snapshot()
220
+
221
+
222
+ def register(app, ns: str = "a11oy"):
223
+ """Additive registration of the governed-anomalies surface.
224
+
225
+ Adds GET /api/{ns}/v1/mosaic/governed. Pure stdlib, no new deps, no network.
226
+ Idempotent and side-effect-free beyond adding one read-only route.
227
+ """
228
+ from fastapi.responses import JSONResponse
229
+
230
+ path = f"/api/{ns}/v1/mosaic/governed"
231
+
232
+ async def _handler(): # pragma: no cover - thin wrapper over governed_view()
233
+ try:
234
+ return JSONResponse(governed_view())
235
+ except Exception as e: # never 500 the console; degrade honestly
236
+ return JSONResponse(
237
+ {
238
+ "status": "error",
239
+ "source": "snapshot",
240
+ "error": f"{e!r}",
241
+ "note": "governed-anomaly view unavailable; nothing fabricated.",
242
+ "doctrine": _DOCTRINE,
243
+ },
244
+ status_code=200,
245
+ )
246
+
247
+ app.add_api_route(path, _handler, methods=["GET"], name="mosaic_governed")
248
+ return path
249
+
250
+
251
+ if __name__ == "__main__":
252
+ print(json.dumps(governed_view(), indent=2))