betterwithage commited on
Commit
45f8083
·
verified ·
1 Parent(s): b529805

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_counter_uas_proxy.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 +5 -0
  2. serve.py +24 -0
  3. szl_counter_uas_proxy.py +160 -0
Dockerfile CHANGED
@@ -141,6 +141,11 @@ COPY physical_bounds_certificate.json agentic_decision_trail.json physical_bound
141
  # COPY'd or serve.py's guarded import falls back to a stub (merged-but-not-live) in the HF
142
  # image. Heavy numpy/UKF/PINN solves are the Forge/GPU path; this web path never solves.
143
  COPY szl_pnt_mesh.py quantum_sensing_limits.py pnt_resilience.py nav_coasting.py fundamental_limits.py ./
 
 
 
 
 
144
  # ADDITIVE (I4 gpu-quant): Sovereign VRAM-resident GPU-Quant engine (PCA-Risk / TDA-Fracture
145
  # / HJB-Kelly) backing /api/a11oy/v1/quant/* + the /quant tab. PURE-STDLIB (Jacobi eigen,
146
  # Gaussian solve, union-find Betti) so it runs in the numpy-less HF image; cuML/giotto-tda
 
141
  # COPY'd or serve.py's guarded import falls back to a stub (merged-but-not-live) in the HF
142
  # image. Heavy numpy/UKF/PINN solves are the Forge/GPU path; this web path never solves.
143
  COPY szl_pnt_mesh.py quantum_sensing_limits.py pnt_resilience.py nav_coasting.py fundamental_limits.py ./
144
+ # Counter-UAS / killinchu surface backend (serves /api/a11oy/v1/counter-uas/*). Server-side
145
+ # proxy to OUR OWN killinchu Space (sense+evidence, signed verdict); browser surface stays
146
+ # 0-CDN (three.js-globe escape hatch, no Cesium). MUST be COPY'd or serve.py's guarded import
147
+ # falls back to a stub (merged-but-not-live) in the HF image. Per-file COPY (no `COPY . .`).
148
+ COPY szl_counter_uas_proxy.py ./
149
  # ADDITIVE (I4 gpu-quant): Sovereign VRAM-resident GPU-Quant engine (PCA-Risk / TDA-Fracture
150
  # / HJB-Kelly) backing /api/a11oy/v1/quant/* + the /quant tab. PURE-STDLIB (Jacobi eigen,
151
  # Gaussian solve, union-find Betti) so it runs in the numpy-less HF image; cuML/giotto-tda
serve.py CHANGED
@@ -1255,6 +1255,30 @@ except Exception as _szl3d_e:
1255
  # ── end szl3d 3D TOOLKIT + HOLOGRAPHIC SHELL ──
1256
 
1257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258
  # ---------------------------------------------------------------------------
1259
  # ADDITIVE (Yachay / Doctrine v13 WAYRA — 4th edge organ): mount the WAYRA tab.
1260
  # WAYRA (Quechua *wayra* = "wind, air"; Wiktionary) is the empire's lungs: the
 
1255
  # ── end szl3d 3D TOOLKIT + HOLOGRAPHIC SHELL ──
1256
 
1257
 
1258
+ # ===========================================================================
1259
+ # ADDITIVE (Dev4 — Counter-UAS / killinchu holographic surface): same-origin
1260
+ # live bridge. The /holographic Counter-UAS surface must wire to REAL killinchu
1261
+ # data (doctrine v11), but killinchu lives on a separate Space, so a browser
1262
+ # fetch would be cross-origin. This server-side proxy lets the surface poll
1263
+ # SAME-ORIGIN /api/a11oy/v1/counter-uas/* (evaluate + DSSE sig, telemetry,
1264
+ # cued-tracks, air-picture, gates, drones-db). HONEST: killinchu SENSES &
1265
+ # EVIDENCES — it does NOT defeat; the proxy forwards detect/track/classify/
1266
+ # evidence + the signed verdict verbatim and degrades gracefully (never
1267
+ # fabricates). Registered BEFORE the SPA catch-all. Additive, try/except.
1268
+ # ===========================================================================
1269
+ try:
1270
+ import szl_counter_uas_proxy as _cuas_proxy
1271
+ _cuas_status = _cuas_proxy.register(app, ns="a11oy")
1272
+ print(f"[a11oy] Counter-UAS live bridge registered: {_cuas_status['count']} routes "
1273
+ f"-> {_cuas_status['upstream']} (senses-and-evidences, signed verdict, 0 CDN)",
1274
+ file=sys.stderr)
1275
+ except Exception as _cuas_e:
1276
+ import traceback as _cuas_tb
1277
+ print(f"[a11oy] Counter-UAS live bridge NOT registered: {_cuas_e!r}", file=sys.stderr)
1278
+ _cuas_tb.print_exc()
1279
+ # ── end Counter-UAS live bridge ──
1280
+
1281
+
1282
  # ---------------------------------------------------------------------------
1283
  # ADDITIVE (Yachay / Doctrine v13 WAYRA — 4th edge organ): mount the WAYRA tab.
1284
  # WAYRA (Quechua *wayra* = "wind, air"; Wiktionary) is the empire's lungs: the
szl_counter_uas_proxy.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # © 2026 Lutar, Stephen P. Jr. — SZL Holdings · Doctrine v11
3
+ """szl_counter_uas_proxy.py — same-origin Counter-UAS live bridge (Dev4 surface).
4
+
5
+ The /holographic Counter-UAS surface (static/3d/surfaces/counter-uas.js) must wire
6
+ to REAL killinchu live data (doctrine v11: WIRE TO LIVE DATA, never fabricate). The
7
+ killinchu decision+evidence organ lives on a separate Space
8
+ (https://szlholdings-killinchu.hf.space), so a browser fetch would be cross-origin.
9
+
10
+ This module registers a small, additive, server-side proxy under the a11oy namespace
11
+ so the surface can poll SAME-ORIGIN (0 CDN, no CORS):
12
+
13
+ GET /api/a11oy/v1/counter-uas/evaluate -> killinchu POST .../counter-uas/evaluate
14
+ (live Λ decision + REAL ECDSA-P256 DSSE signature over the receipt)
15
+ GET /api/a11oy/v1/counter-uas/telemetry -> killinchu .../drone/telemetry
16
+ (friendly fleet + threat tracks, honest data_kind)
17
+ GET /api/a11oy/v1/counter-uas/cued-tracks -> killinchu .../drone/cued-tracks
18
+ GET /api/a11oy/v1/counter-uas/air-picture -> killinchu .../drone/air-picture
19
+ (real cooperative ADS-B from airplanes.live)
20
+ GET /api/a11oy/v1/counter-uas/gates -> killinchu .../v1/gates (13-axis Λ gate spec)
21
+
22
+ The 53-fingerprint drone classification DB is the killinchu repo's own drones_db.json
23
+ (verified count = 53), vendored verbatim into the static tree and served same-origin at
24
+ /static/3d/surfaces/data/drones_db.json (killinchu does not expose it as a JSON HTTP
25
+ route — its root path serves the Cesium SPA). Vendored-not-fabricated.
26
+
27
+ HONESTY (killinchu charter / JIATF-401 crosswalk): killinchu SENSES & EVIDENCES — it
28
+ does NOT defeat (no jamming/spoofing/takeover/kinetic). This proxy forwards the
29
+ detect/track/classify/evidence + signed-verdict payloads verbatim; it never invents a
30
+ value. On any upstream failure it returns {"degraded": true, ...} so szl3d_live renders
31
+ the honest DEGRADED state (not a crash). Λ = Conjecture 1 (advisory).
32
+
33
+ ADDITIVE, try/except-guarded, registered BEFORE the SPA catch-all (mirrors
34
+ szl3d_holographic.register + a11oy_active_flux_router.register).
35
+ """
36
+ from __future__ import annotations
37
+
38
+ import os
39
+ from typing import Any, Dict, List
40
+
41
+ # killinchu Space base (overridable for tests / alternate deploys). The drone +
42
+ # evaluate routes are confirmed live (HTTP 200, verified 2026-06-14).
43
+ KILLINCHU_BASE = os.environ.get(
44
+ "KILLINCHU_BASE", "https://szlholdings-killinchu.hf.space"
45
+ ).rstrip("/")
46
+
47
+ # Upstream route map: a11oy-side suffix -> (method, upstream path).
48
+ # evaluate is POST upstream; we expose it as GET so szl3d_live.poll (a GET poller)
49
+ # can drive the live verdict without a custom fetch.
50
+ _UPSTREAM: Dict[str, Dict[str, str]] = {
51
+ "evaluate": {"method": "POST", "path": "/api/killinchu/v1/counter-uas/evaluate"},
52
+ "telemetry": {"method": "GET", "path": "/api/killinchu/drone/telemetry"},
53
+ "cued-tracks": {"method": "GET", "path": "/api/killinchu/drone/cued-tracks"},
54
+ "air-picture": {"method": "GET", "path": "/api/killinchu/drone/air-picture"},
55
+ "gates": {"method": "GET", "path": "/api/killinchu/v1/gates"},
56
+ }
57
+
58
+ _TIMEOUT = float(os.environ.get("KILLINCHU_PROXY_TIMEOUT", "20"))
59
+
60
+
61
+ def _degraded(suffix: str, reason: str, status: int = 0) -> Dict[str, Any]:
62
+ """The honest degraded envelope szl3d_live renders as DEGRADED (never fabricates)."""
63
+ return {
64
+ "degraded": True,
65
+ "surface": "counter-uas",
66
+ "suffix": suffix,
67
+ "upstream": KILLINCHU_BASE,
68
+ "reason": reason,
69
+ "upstream_status": status,
70
+ "doctrine": "v11",
71
+ "lambda_status": "Conjecture 1 (advisory, not a theorem)",
72
+ "posture": "killinchu SENSES & EVIDENCES — does NOT defeat (no jam/spoof/takeover/kinetic)",
73
+ "label": "STRUCTURAL-ONLY",
74
+ }
75
+
76
+
77
+ def register(app, ns: str = "a11oy") -> Dict[str, Any]:
78
+ """Attach the same-origin Counter-UAS proxy. ADDITIVE; never crashes the app."""
79
+ import httpx
80
+ from starlette.responses import JSONResponse
81
+
82
+ prefix = f"/api/{ns}/v1/counter-uas"
83
+ registered: List[str] = []
84
+
85
+ async def _forward(suffix: str):
86
+ spec = _UPSTREAM.get(suffix)
87
+ if spec is None:
88
+ return JSONResponse(
89
+ _degraded(suffix, "route not allowlisted", 404), status_code=404
90
+ )
91
+ url = KILLINCHU_BASE + spec["path"]
92
+ try:
93
+ async with httpx.AsyncClient(timeout=_TIMEOUT) as client:
94
+ if spec["method"] == "POST":
95
+ # evaluate returns a stable live verdict + real DSSE sig; empty
96
+ # body is accepted upstream. We forward an explicit evaluate cue.
97
+ res = await client.post(
98
+ url,
99
+ json={"source": "a11oy-holographic/counter-uas", "doctrine": "v11"},
100
+ headers={"accept": "application/json"},
101
+ )
102
+ else:
103
+ res = await client.get(url, headers={"accept": "application/json"})
104
+ except Exception as e: # network/timeout — honest degraded, not a crash
105
+ return JSONResponse(_degraded(suffix, f"upstream unreachable: {e!r}", 0))
106
+ if res.status_code >= 400:
107
+ return JSONResponse(_degraded(suffix, "upstream error", res.status_code))
108
+ try:
109
+ payload = res.json()
110
+ except Exception:
111
+ return JSONResponse(_degraded(suffix, "upstream non-JSON", res.status_code))
112
+ # Forward verbatim — we never rewrite or fabricate killinchu's values.
113
+ return JSONResponse(payload)
114
+
115
+ # Bind one GET route per suffix (closure-safe via default arg).
116
+ for _suffix in _UPSTREAM:
117
+ async def _route(suffix: str = _suffix):
118
+ return await _forward(suffix)
119
+
120
+ app.add_api_route(
121
+ f"{prefix}/{_suffix}", _route, methods=["GET"], include_in_schema=False
122
+ )
123
+ registered.append(f"GET {prefix}/{_suffix}")
124
+
125
+ async def _info():
126
+ return JSONResponse({
127
+ "capability": "Counter-UAS same-origin live bridge to killinchu",
128
+ "ns": ns,
129
+ "upstream": KILLINCHU_BASE,
130
+ "routes": registered,
131
+ "posture": "senses-and-evidences (no defeat)",
132
+ "lambda": "Conjecture 1",
133
+ "label": "STRUCTURAL-ONLY",
134
+ "doctrine": "v11",
135
+ })
136
+
137
+ app.add_api_route(f"{prefix}/info", _info, methods=["GET"], include_in_schema=False)
138
+ registered.append(f"GET {prefix}/info")
139
+
140
+ return {
141
+ "registered": registered,
142
+ "count": len(registered),
143
+ "capability": "counter-uas live bridge",
144
+ "upstream": KILLINCHU_BASE,
145
+ "data_label": "live-bridge",
146
+ }
147
+
148
+
149
+ def _selftest() -> None:
150
+ # Structural self-test (no network): the route map is well-formed and honest.
151
+ assert "evaluate" in _UPSTREAM and _UPSTREAM["evaluate"]["method"] == "POST"
152
+ assert _UPSTREAM["telemetry"]["path"].endswith("/drone/telemetry")
153
+ d = _degraded("evaluate", "test", 0)
154
+ assert d["degraded"] is True and d["label"] == "STRUCTURAL-ONLY"
155
+ assert "does NOT defeat" in d["posture"]
156
+ print("szl_counter_uas_proxy: ALL OK (route map honest, degraded envelope honest)")
157
+
158
+
159
+ if __name__ == "__main__":
160
+ _selftest()