Spaces:
Running
Running
a11oy.code: full IDE Code tab (streaming chat + CodeMirror editor + sandboxed run + Lambda/Khipu receipts + FAST/HEART/PRIME/FRONTIER tiers); honest-stub until HF_TOKEN set; doctrine sweep (axis rename, role-neutral service names). Built by Perplexity Computer Agent.
Browse files- a11oy_code_ide.html +0 -0
- a11oy_code_orchestrator.py +195 -22
- a11oy_v4_formulas.py +15 -15
a11oy_code_ide.html
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
a11oy_code_orchestrator.py
CHANGED
|
@@ -84,13 +84,18 @@ PROVIDER_KEYS = {
|
|
| 84 |
"cerebras": os.environ.get("CEREBRAS_API_KEY", ""),
|
| 85 |
}
|
| 86 |
|
| 87 |
-
#
|
|
|
|
|
|
|
| 88 |
FLAGSHIP_BASES = {
|
| 89 |
-
"
|
| 90 |
-
"
|
| 91 |
-
"
|
| 92 |
-
"
|
| 93 |
}
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
router = APIRouter(prefix="/api/a11oy/code", tags=["a11oy.code"])
|
| 96 |
|
|
@@ -143,15 +148,15 @@ MODEL_CATALOG = [
|
|
| 143 |
]
|
| 144 |
|
| 145 |
DEFAULT_SYSTEM_PROMPT = (
|
| 146 |
-
"You are a11oy.code, the SZL Holdings conversational orchestrator. You
|
| 147 |
-
"at the highest available quality
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
"
|
| 151 |
-
"
|
| 152 |
-
"
|
| 153 |
-
"
|
| 154 |
-
"
|
| 155 |
)
|
| 156 |
|
| 157 |
# ---------------------------------------------------------------------------
|
|
@@ -258,7 +263,7 @@ def _hukla_check(action: str, context: dict[str, Any]) -> tuple[int, list[str],
|
|
| 258 |
if not context.get("chain_verified", True):
|
| 259 |
fired.append("T01")
|
| 260 |
hard_halt = True
|
| 261 |
-
# T05 PII (very rough heuristic;
|
| 262 |
if re.search(r"\b\d{3}-\d{2}-\d{4}\b", text):
|
| 263 |
fired.append("T05")
|
| 264 |
# T06 cost ceiling
|
|
@@ -440,6 +445,34 @@ def _inference_headers() -> dict[str, str]:
|
|
| 440 |
return {"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"}
|
| 441 |
|
| 442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
async def _call_model_stream(client: httpx.AsyncClient, model: str, payload: dict[str, Any]
|
| 444 |
) -> AsyncGenerator[bytes, None]:
|
| 445 |
body = dict(payload)
|
|
@@ -521,9 +554,9 @@ TOOL_SCHEMAS = [
|
|
| 521 |
"name": "hf_read_space", "description": "List files / read metadata of a Hugging Face Space.",
|
| 522 |
"parameters": {"type": "object", "properties": {"repo_id": {"type": "string"}}, "required": ["repo_id"]}}},
|
| 523 |
{"type": "function", "function": {
|
| 524 |
-
"name": "flagship_call", "description": "Call
|
| 525 |
"parameters": {"type": "object", "properties": {
|
| 526 |
-
"organ": {"type": "string", "enum": ["
|
| 527 |
"path": {"type": "string"}, "method": {"type": "string", "default": "GET"},
|
| 528 |
"json": {"type": "object"}}, "required": ["organ", "path"]}}},
|
| 529 |
{"type": "function", "function": {
|
|
@@ -545,6 +578,71 @@ TOOL_SCHEMAS = [
|
|
| 545 |
|
| 546 |
SHELL_ALLOWLIST = {"ls", "cat", "echo", "wc", "head", "tail", "grep", "find", "python3", "node", "sort", "uniq"}
|
| 547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
|
| 549 |
def _gate_context_for_tool(name: str, args: dict[str, Any], attested: bool) -> dict[str, Any]:
|
| 550 |
risk = "high" if name in STATE_CHANGING_TOOLS else "low"
|
|
@@ -598,7 +696,7 @@ async def _dispatch_tool(name: str, args: dict[str, Any], client: httpx.AsyncCli
|
|
| 598 |
if name == "fs_write":
|
| 599 |
return _tool_fs_write(args["path"], args["content"])
|
| 600 |
if name == "drone_command":
|
| 601 |
-
return await _tool_flagship(client, "
|
| 602 |
"POST", {"command": args["command"]})
|
| 603 |
raise ValueError(f"unknown tool {name}")
|
| 604 |
|
|
@@ -644,10 +742,11 @@ def _tool_hf_space(repo_id: str) -> Any:
|
|
| 644 |
|
| 645 |
|
| 646 |
async def _tool_flagship(client: httpx.AsyncClient, organ: str, path: str, method: str, payload: Any) -> Any:
|
| 647 |
-
|
|
|
|
| 648 |
if not base:
|
| 649 |
-
return {"error": f"
|
| 650 |
-
"hint": f"
|
| 651 |
"gap": True}
|
| 652 |
resp = await client.request(method, f"{base}{path}", json=payload, timeout=60.0)
|
| 653 |
try:
|
|
@@ -830,9 +929,12 @@ def _get_client() -> httpx.AsyncClient:
|
|
| 830 |
async def code_healthz() -> JSONResponse:
|
| 831 |
return JSONResponse({
|
| 832 |
"status": "ok", "component": "a11oy.code orchestrator", "doctrine": "v12 (v11+PURIQ)",
|
| 833 |
-
"inference": "hf-router" if
|
|
|
|
| 834 |
"tiers": list(TIERS.keys()), "tools": [t["function"]["name"] for t in TOOL_SCHEMAS],
|
| 835 |
"puriq_threshold": PURIQ_THRESHOLD, "memory": "sqlite", "signed": "Yachay",
|
|
|
|
|
|
|
| 836 |
"built_by": "Perplexity Computer Agent",
|
| 837 |
})
|
| 838 |
|
|
@@ -853,6 +955,49 @@ async def code_metrics() -> PlainTextResponse:
|
|
| 853 |
return PlainTextResponse(_metrics_text(), media_type="text/plain; version=0.0.4")
|
| 854 |
|
| 855 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 856 |
@router.post("/v1/router")
|
| 857 |
async def v1_router(request: Request) -> JSONResponse:
|
| 858 |
"""7-tier router. Returns OpenAI-compatible response + Khipu receipt."""
|
|
@@ -1028,6 +1173,34 @@ async def chat_stream(request: Request):
|
|
| 1028 |
"model": decision["model"], "license_class": decision["license_class"],
|
| 1029 |
"reason": decision["reason"]})
|
| 1030 |
t0 = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
payload = {"messages": history, "max_tokens": body.get("max_tokens", 1500),
|
| 1032 |
"temperature": body.get("temperature", 0.7)}
|
| 1033 |
if enable_tools:
|
|
|
|
| 84 |
"cerebras": os.environ.get("CEREBRAS_API_KEY", ""),
|
| 85 |
}
|
| 86 |
|
| 87 |
+
# Governed SZL service-role base URLs (in-Space these are relative; orchestrator
|
| 88 |
+
# proxies). Keys are the honest role names exposed to the model/UI; env-var names
|
| 89 |
+
# are kept internal/legacy for deployment compatibility (never user-visible).
|
| 90 |
FLAGSHIP_BASES = {
|
| 91 |
+
"reasoning": os.environ.get("AMARU_BASE", ""),
|
| 92 |
+
"policy": os.environ.get("SENTRA_BASE", ""),
|
| 93 |
+
"operator": os.environ.get("ROSIE_BASE", ""),
|
| 94 |
+
"field-node": os.environ.get("KILLINCHU_BASE", ""),
|
| 95 |
}
|
| 96 |
+
# Accept role aliases used in the tool enum -> canonical FLAGSHIP_BASES key.
|
| 97 |
+
_ROLE_ALIASES = {"governance": "reasoning", "field-node": "field-node",
|
| 98 |
+
"policy": "policy", "operator": "operator", "reasoning": "reasoning"}
|
| 99 |
|
| 100 |
router = APIRouter(prefix="/api/a11oy/code", tags=["a11oy.code"])
|
| 101 |
|
|
|
|
| 148 |
]
|
| 149 |
|
| 150 |
DEFAULT_SYSTEM_PROMPT = (
|
| 151 |
+
"You are a11oy.code, the SZL Holdings conversational coding orchestrator. You "
|
| 152 |
+
"answer at the highest available quality using a unified open-LLM router. You "
|
| 153 |
+
"can orchestrate governed SZL services (Governance, Policy, Operator, Field-Node "
|
| 154 |
+
"roles) and reach outside via GitHub, Hugging Face, web search/fetch/browse, a "
|
| 155 |
+
"sandboxed shell, and a sandboxed filesystem - all of which are exposed to you "
|
| 156 |
+
"as tools. Every action you take is gated by PURIQ (Yuyay 13-axis wisdom + "
|
| 157 |
+
"HUKLLA tripwires) and receipted on the Khipu chain. Be precise, write clear "
|
| 158 |
+
"code, cite sources, refuse cleanly when a gate denies, and prefer streaming. "
|
| 159 |
+
"Never fabricate tool results."
|
| 160 |
)
|
| 161 |
|
| 162 |
# ---------------------------------------------------------------------------
|
|
|
|
| 263 |
if not context.get("chain_verified", True):
|
| 264 |
fired.append("T01")
|
| 265 |
hard_halt = True
|
| 266 |
+
# T05 PII (very rough heuristic; the dedicated egress/immune filter owns full PII)
|
| 267 |
if re.search(r"\b\d{3}-\d{2}-\d{4}\b", text):
|
| 268 |
fired.append("T05")
|
| 269 |
# T06 cost ceiling
|
|
|
|
| 445 |
return {"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"}
|
| 446 |
|
| 447 |
|
| 448 |
+
def has_inference_credential() -> bool:
|
| 449 |
+
"""True iff a real inference credential is present (HF router or a provider key)."""
|
| 450 |
+
return bool(HF_TOKEN) or any(PROVIDER_KEYS.values())
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def honest_stub_text(user_msg: str, decision: dict[str, Any]) -> str:
|
| 454 |
+
"""Deterministic, CLEARLY-LABELED stub. NEVER a fabricated model answer.
|
| 455 |
+
|
| 456 |
+
Emitted only when NO inference credential is present. It states plainly that
|
| 457 |
+
the model text is unavailable and that routing / Lambda / receipts are the
|
| 458 |
+
real, deterministic parts. It does NOT invent a code answer.
|
| 459 |
+
"""
|
| 460 |
+
snippet = (user_msg or "").strip().replace("\n", " ")[:160]
|
| 461 |
+
return (
|
| 462 |
+
"**[deterministic stub \u2014 inference token not yet set]**\n\n"
|
| 463 |
+
"a11oy.code received your request"
|
| 464 |
+
+ (f" (\u201c{snippet}\u201d)" if snippet else "")
|
| 465 |
+
+ f" and routed it to tier **{decision.get('tier')}** \u2192 model "
|
| 466 |
+
f"`{decision.get('model')}` (license {decision.get('license_class')}). "
|
| 467 |
+
"The PURIQ \u039b-gate, tier selection and the signed Khipu receipt below are "
|
| 468 |
+
"REAL deterministic math. The **model completion itself is unavailable** because no "
|
| 469 |
+
"inference credential is configured on this Space \u2014 so no answer is fabricated "
|
| 470 |
+
"(Zero-Bandaid Law).\n\n"
|
| 471 |
+
"_To enable live generation, paste a valid token into the Space secret_ `HF_TOKEN` "
|
| 472 |
+
"_(Settings \u2192 Variables and secrets). Generation then goes live instantly \u2014 no redeploy._"
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
|
| 476 |
async def _call_model_stream(client: httpx.AsyncClient, model: str, payload: dict[str, Any]
|
| 477 |
) -> AsyncGenerator[bytes, None]:
|
| 478 |
body = dict(payload)
|
|
|
|
| 554 |
"name": "hf_read_space", "description": "List files / read metadata of a Hugging Face Space.",
|
| 555 |
"parameters": {"type": "object", "properties": {"repo_id": {"type": "string"}}, "required": ["repo_id"]}}},
|
| 556 |
{"type": "function", "function": {
|
| 557 |
+
"name": "flagship_call", "description": "Call a governed SZL service role (governance/policy/operator/field-node).",
|
| 558 |
"parameters": {"type": "object", "properties": {
|
| 559 |
+
"organ": {"type": "string", "enum": ["governance", "policy", "operator", "field-node"]},
|
| 560 |
"path": {"type": "string"}, "method": {"type": "string", "default": "GET"},
|
| 561 |
"json": {"type": "object"}}, "required": ["organ", "path"]}}},
|
| 562 |
{"type": "function", "function": {
|
|
|
|
| 578 |
|
| 579 |
SHELL_ALLOWLIST = {"ls", "cat", "echo", "wc", "head", "tail", "grep", "find", "python3", "node", "sort", "uniq"}
|
| 580 |
|
| 581 |
+
# ---------------------------------------------------------------------------
|
| 582 |
+
# Sandboxed code runner for the IDE "Run" button. HONEST safety boundary:
|
| 583 |
+
# - only python3 / node interpreters (no arbitrary binaries)
|
| 584 |
+
# - executed inside SANDBOX_DIR with a minimal PATH, NO network reachability is
|
| 585 |
+
# promised (the Space process MAY have egress; we do NOT sandbox the network
|
| 586 |
+
# at the kernel level here, so we LABEL that honestly rather than claim it)
|
| 587 |
+
# - 8s wall-clock timeout, output truncated
|
| 588 |
+
# This is a constrained-interpreter runner, NOT a hardened multi-tenant jail.
|
| 589 |
+
# The label returned to the UI states the boundary plainly (no fake claims).
|
| 590 |
+
# ---------------------------------------------------------------------------
|
| 591 |
+
RUN_INTERPRETERS = {
|
| 592 |
+
"python": ["python3", "-I", "-S"], # -I isolated, -S no site
|
| 593 |
+
"javascript": ["node"],
|
| 594 |
+
"shell": None, # shell handled via the allow-listed _tool_shell path only
|
| 595 |
+
}
|
| 596 |
+
RUN_BOUNDARY = (
|
| 597 |
+
"sandbox: isolated dir + 8s timeout + interpreter-only (python3/node). "
|
| 598 |
+
"Network is NOT kernel-isolated in this Space \u2014 do not run untrusted code "
|
| 599 |
+
"expecting egress containment. Honest boundary, not a hardened jail."
|
| 600 |
+
)
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
def run_code(language: str, code: str) -> dict[str, Any]:
|
| 604 |
+
"""Execute editor code in the constrained sandbox. Returns stdout/stderr/code.
|
| 605 |
+
NO fake run: if the language is unsupported we say so honestly."""
|
| 606 |
+
SANDBOX_DIR.mkdir(parents=True, exist_ok=True)
|
| 607 |
+
lang = (language or "python").lower()
|
| 608 |
+
if lang in ("text/x-csrc", "c"):
|
| 609 |
+
return {"error": "C execution is not enabled in this sandbox (no compiler in image). "
|
| 610 |
+
"Honest limitation \u2014 Python and JavaScript run live.",
|
| 611 |
+
"boundary": RUN_BOUNDARY, "code": None}
|
| 612 |
+
if lang == "shell":
|
| 613 |
+
return {"error": "Shell is restricted to the allow-listed shell_exec tool, not the Run button.",
|
| 614 |
+
"boundary": RUN_BOUNDARY, "code": None}
|
| 615 |
+
interp = RUN_INTERPRETERS.get(lang)
|
| 616 |
+
if not interp:
|
| 617 |
+
return {"error": f"unsupported language '{language}'", "boundary": RUN_BOUNDARY, "code": None}
|
| 618 |
+
suffix = {"python": ".py", "javascript": ".js"}[lang]
|
| 619 |
+
src = SANDBOX_DIR / f"_run_{uuid.uuid4().hex[:8]}{suffix}"
|
| 620 |
+
try:
|
| 621 |
+
src.write_text(code, "utf-8")
|
| 622 |
+
t0 = time.time()
|
| 623 |
+
out = subprocess.run(
|
| 624 |
+
[*interp, str(src)], capture_output=True, text=True, timeout=8,
|
| 625 |
+
cwd=str(SANDBOX_DIR),
|
| 626 |
+
env={"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": str(SANDBOX_DIR),
|
| 627 |
+
"PYTHONIOENCODING": "utf-8"},
|
| 628 |
+
)
|
| 629 |
+
elapsed = int((time.time() - t0) * 1000)
|
| 630 |
+
rec = khipu_emit("code.run", {"language": lang, "bytes": len(code), "exit": out.returncode})
|
| 631 |
+
return {"stdout": out.stdout[:8000], "stderr": out.stderr[:4000], "code": out.returncode,
|
| 632 |
+
"elapsed_ms": elapsed, "boundary": RUN_BOUNDARY,
|
| 633 |
+
"khipu_hash": rec["hash"]}
|
| 634 |
+
except subprocess.TimeoutExpired:
|
| 635 |
+
return {"error": "timeout (8s wall-clock)", "boundary": RUN_BOUNDARY, "code": 124}
|
| 636 |
+
except FileNotFoundError as exc:
|
| 637 |
+
return {"error": f"interpreter not available in image: {exc}", "boundary": RUN_BOUNDARY, "code": None}
|
| 638 |
+
except Exception as exc:
|
| 639 |
+
return {"error": str(exc)[:400], "boundary": RUN_BOUNDARY, "code": None}
|
| 640 |
+
finally:
|
| 641 |
+
try:
|
| 642 |
+
src.unlink(missing_ok=True)
|
| 643 |
+
except Exception:
|
| 644 |
+
pass
|
| 645 |
+
|
| 646 |
|
| 647 |
def _gate_context_for_tool(name: str, args: dict[str, Any], attested: bool) -> dict[str, Any]:
|
| 648 |
risk = "high" if name in STATE_CHANGING_TOOLS else "low"
|
|
|
|
| 696 |
if name == "fs_write":
|
| 697 |
return _tool_fs_write(args["path"], args["content"])
|
| 698 |
if name == "drone_command":
|
| 699 |
+
return await _tool_flagship(client, "field-node", f"/drones/{args['drone_id']}/command",
|
| 700 |
"POST", {"command": args["command"]})
|
| 701 |
raise ValueError(f"unknown tool {name}")
|
| 702 |
|
|
|
|
| 742 |
|
| 743 |
|
| 744 |
async def _tool_flagship(client: httpx.AsyncClient, organ: str, path: str, method: str, payload: Any) -> Any:
|
| 745 |
+
role = _ROLE_ALIASES.get(organ, organ)
|
| 746 |
+
base = FLAGSHIP_BASES.get(role, "")
|
| 747 |
if not base:
|
| 748 |
+
return {"error": f"service role '{role}' base URL not configured",
|
| 749 |
+
"hint": f"configure the '{role}' service base when that Space ships.",
|
| 750 |
"gap": True}
|
| 751 |
resp = await client.request(method, f"{base}{path}", json=payload, timeout=60.0)
|
| 752 |
try:
|
|
|
|
| 929 |
async def code_healthz() -> JSONResponse:
|
| 930 |
return JSONResponse({
|
| 931 |
"status": "ok", "component": "a11oy.code orchestrator", "doctrine": "v12 (v11+PURIQ)",
|
| 932 |
+
"inference": "hf-router" if has_inference_credential() else "NO-CREDENTIAL",
|
| 933 |
+
"mode": "live" if has_inference_credential() else "deterministic_stub",
|
| 934 |
"tiers": list(TIERS.keys()), "tools": [t["function"]["name"] for t in TOOL_SCHEMAS],
|
| 935 |
"puriq_threshold": PURIQ_THRESHOLD, "memory": "sqlite", "signed": "Yachay",
|
| 936 |
+
"ide": "/api/a11oy/code/ide", "run": "/api/a11oy/code/run",
|
| 937 |
+
"token_secret": "HF_TOKEN",
|
| 938 |
"built_by": "Perplexity Computer Agent",
|
| 939 |
})
|
| 940 |
|
|
|
|
| 955 |
return PlainTextResponse(_metrics_text(), media_type="text/plain; version=0.0.4")
|
| 956 |
|
| 957 |
|
| 958 |
+
# ---------------------------------------------------------------------------
|
| 959 |
+
# IDE page (full-screen coding assistant). Self-contained HTML with vendored
|
| 960 |
+
# CodeMirror (0 runtime CDN). Served from a sibling file so it can be edited
|
| 961 |
+
# without touching this module.
|
| 962 |
+
# ---------------------------------------------------------------------------
|
| 963 |
+
_IDE_HTML_PATH = Path(__file__).with_name("a11oy_code_ide.html")
|
| 964 |
+
|
| 965 |
+
|
| 966 |
+
@router.get("/ide")
|
| 967 |
+
async def code_ide():
|
| 968 |
+
"""Serve the full IDE-style Code tab page (streaming chat + editor + run +
|
| 969 |
+
receipts). 0 runtime CDN \u2014 all assets inlined."""
|
| 970 |
+
try:
|
| 971 |
+
html = _IDE_HTML_PATH.read_text("utf-8")
|
| 972 |
+
except Exception as exc: # honest failure, never a fake page
|
| 973 |
+
return PlainTextResponse(
|
| 974 |
+
f"a11oy.code IDE page not found on this Space ({exc}). "
|
| 975 |
+
"The orchestrator API is live at /api/a11oy/code/* regardless.",
|
| 976 |
+
status_code=404)
|
| 977 |
+
from fastapi.responses import HTMLResponse
|
| 978 |
+
return HTMLResponse(html)
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
@router.post("/run")
|
| 982 |
+
async def code_run(request: Request) -> JSONResponse:
|
| 983 |
+
"""Execute editor code in the constrained sandbox. Honest safety boundary is
|
| 984 |
+
returned in the response (see RUN_BOUNDARY). PURIQ-gated + Khipu-receipted."""
|
| 985 |
+
body = await request.json()
|
| 986 |
+
language = body.get("language", "python")
|
| 987 |
+
code = body.get("code", "")
|
| 988 |
+
if not isinstance(code, str) or not code.strip():
|
| 989 |
+
return JSONResponse({"error": "empty code", "boundary": RUN_BOUNDARY, "code": None})
|
| 990 |
+
# Gate the run as a sandboxed exec action.
|
| 991 |
+
gate = puriq_decide("shell_exec", _gate_context_for_tool("shell_exec", {"run": language}, attested=True))
|
| 992 |
+
if not gate["allow"]:
|
| 993 |
+
_METRICS["gate_denied_total"] += 1
|
| 994 |
+
return JSONResponse({"error": f"PURIQ gate denied: {gate['reason']}",
|
| 995 |
+
"boundary": RUN_BOUNDARY, "code": None})
|
| 996 |
+
result = await asyncio.get_event_loop().run_in_executor(None, run_code, language, code)
|
| 997 |
+
result["gate"] = {"allow": gate["allow"], "score": gate["score"], "lambda": gate["lambda"]}
|
| 998 |
+
return JSONResponse(result)
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
@router.post("/v1/router")
|
| 1002 |
async def v1_router(request: Request) -> JSONResponse:
|
| 1003 |
"""7-tier router. Returns OpenAI-compatible response + Khipu receipt."""
|
|
|
|
| 1173 |
"model": decision["model"], "license_class": decision["license_class"],
|
| 1174 |
"reason": decision["reason"]})
|
| 1175 |
t0 = time.time()
|
| 1176 |
+
|
| 1177 |
+
# ----------------------------------------------------------------
|
| 1178 |
+
# HONEST-STUB BRANCH: if there is NO inference credential, do NOT
|
| 1179 |
+
# error out and do NOT fabricate. Stream a clearly-labeled stub plus
|
| 1180 |
+
# the real signed receipt, then finish cleanly. This keeps the tab
|
| 1181 |
+
# fully operational (routing + Lambda + receipt) while being honest
|
| 1182 |
+
# that the model text is unavailable until a token is pasted.
|
| 1183 |
+
# ----------------------------------------------------------------
|
| 1184 |
+
if not has_inference_credential():
|
| 1185 |
+
stub = honest_stub_text(user_msg, decision)
|
| 1186 |
+
for word in re.findall(r"\S+\s*", stub):
|
| 1187 |
+
yield sse("token", {"text": word})
|
| 1188 |
+
await asyncio.sleep(0)
|
| 1189 |
+
latency_ms = int((time.time() - t0) * 1000)
|
| 1190 |
+
y13 = yuyay13_response_score(stub, None, latency_ms)
|
| 1191 |
+
rec = khipu_emit("chat.completion.stub", {
|
| 1192 |
+
"conversation_id": conv_id, "model": decision["model"],
|
| 1193 |
+
"tier": decision["tier"], "mode": "deterministic_stub", "yuyay13": y13})
|
| 1194 |
+
mem_add_message(conv_id, "assistant", stub, model=decision["model"],
|
| 1195 |
+
tier=decision["tier"], latency_ms=latency_ms, cost_usd=0.0,
|
| 1196 |
+
yuyay13=y13, khipu_hash=rec["hash"])
|
| 1197 |
+
yield sse("done", {"conversation_id": conv_id, "tier": decision["tier"],
|
| 1198 |
+
"model": decision["model"], "license_class": decision["license_class"],
|
| 1199 |
+
"latency_ms": latency_ms, "cost_usd": 0.0, "yuyay13": y13,
|
| 1200 |
+
"khipu_hash": rec["hash"], "chain_verified": True,
|
| 1201 |
+
"mode": "deterministic_stub"})
|
| 1202 |
+
return
|
| 1203 |
+
|
| 1204 |
payload = {"messages": history, "max_tokens": body.get("max_tokens", 1500),
|
| 1205 |
"temperature": body.get("temperature", 0.7)}
|
| 1206 |
if enable_tools:
|
a11oy_v4_formulas.py
CHANGED
|
@@ -623,7 +623,7 @@ _LIVE = {
|
|
| 623 |
_REGISTRY: List[Dict[str, Any]] = [
|
| 624 |
# ---- 5 LIVE ----
|
| 625 |
{"name": "AdversarialRobustness", "id": "TH8", "leanTheorem": "robustness_preserved_by_composition",
|
| 626 |
-
"leanFile": "Lutar/Composition/AdversarialRobustness.lean", "leanStatus": "conjecture-open", "axis": "
|
| 627 |
"severity": "enforced", "gates": "Allows pipeline deploy only when composed perturbation ε₂=L₁·L₂·δ ≤ maxEpsilon.",
|
| 628 |
"status": "live", "ts": "packages/policy/src/gates/adversarialRobustness_gate.ts",
|
| 629 |
"sample": {"lipschitz1": 0.8, "lipschitz2": 0.9, "delta": 0.5}, "config": {"maxEpsilon": 1.0}},
|
|
@@ -648,35 +648,35 @@ _REGISTRY: List[Dict[str, Any]] = [
|
|
| 648 |
"status": "live", "ts": "packages/policy/src/gates/summationInvariant_gate.ts",
|
| 649 |
"sample": {"khipuId": "k1", "organs": [{"organId": "o1", "decisions": [{"decisionId": "d1", "value": 3}, {"decisionId": "d2", "value": 4}]}], "primaryCord": 7}, "config": {}},
|
| 650 |
# ---- 10 MORE LIVE (Phase 3, ported below) are interleaved by id; remaining 20 ts-only ----
|
| 651 |
-
{"name": "SoundnessAxiom", "id": "A1", "leanTheorem": "soundness_axiom", "leanFile": "Lutar/Gate/SoundnessAxiom.lean", "leanStatus": "theorem", "axis": "
|
| 652 |
{"name": "MoralGroundingFloor", "id": "A2", "leanTheorem": "moral_grounding_floor", "leanFile": "Lutar/Gate/MoralGrounding.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Action must clear moral grounding floor.", "status": "ts-only", "ts": "packages/policy/src/gates/moralGroundingFloor_gate.ts"},
|
| 653 |
{"name": "MeasurabilityHonestyFloor", "id": "A3", "leanTheorem": "measurability_honesty_floor", "leanFile": "Lutar/Gate/MeasurabilityHonesty.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Claims must be measurable / honest.", "status": "ts-only", "ts": "packages/policy/src/gates/measurabilityHonestyFloor_gate.ts"},
|
| 654 |
{"name": "DualWitnessDisjointness", "id": "A4", "leanTheorem": "dualWitnessDisjointness", "leanFile": "Lutar/Gate/DualWitness.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows \u03c1-closure write only when witness_1_id \u2260 witness_2_id (two independent witnesses, no single-witness collapse).", "status": "live", "ts": "packages/policy/src/gates/dualWitnessDisjointness_gate.ts", "sample": {"witness1Id": "alice", "witness2Id": "bob"}, "config": {}},
|
| 655 |
{"name": "DeterministicReplay", "id": "A5", "leanTheorem": "deterministicReplay", "leanFile": "Lutar/Gate/DeterministicReplay.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows production op only when N replay runs yield exactly 1 unique (byte-identical) Merkle root.", "status": "live", "ts": "packages/policy/src/gates/deterministicReplay_gate.ts", "sample": {"replayRoots": ["abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00"]}, "config": {"requiredRuns": 5}},
|
| 656 |
{"name": "HashChainIntegrity", "id": "A6", "leanTheorem": "hashChainIntegrity", "leanFile": "Lutar/Gate/HashChainIntegrity.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows chain advancement only when every entry.chainHash == SHA256(JSON of previous entry) \u2014 Khipu chain continuity.", "status": "live", "ts": "packages/policy/src/gates/hashChainIntegrity_gate.ts", "sample": {"entries": [{"entryId": "e0", "payload": "genesis", "chainHash": "genesis"}, {"entryId": "e1", "payload": "second", "chainHash": "45bd824b7e4aadbb7ea4a865d057e4cd832d718a268169680f898274b89c5a8d"}, {"entryId": "e2", "payload": "third", "chainHash": "ae7da7c40007478c3e412457553c0aa235a1804ec65f446e1b2d472548ca50d9"}]}, "config": {}},
|
| 657 |
-
{"name": "BekensteinBound", "id": "A7", "leanTheorem": "bekenstein_bound", "leanFile": "Lutar/Gate/BekensteinBound.lean", "leanStatus": "conjectured", "axis": "
|
| 658 |
-
{"name": "IngestDiscipline", "id": "A8", "leanTheorem": "ingest_discipline", "leanFile": "Lutar/Gate/IngestDiscipline.lean", "leanStatus": "theorem", "axis": "
|
| 659 |
-
{"name": "DoctrineCompleteness", "id": "A9", "leanTheorem": "doctrineCompleteness", "leanFile": "Lutar/Gate/DoctrineCompleteness.lean", "leanStatus": "theorem", "axis": "
|
| 660 |
{"name": "TemporalConsistency", "id": "A10", "leanTheorem": "temporalConsistency", "leanFile": "Lutar/Gate/TemporalConsistency.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows receipt only when |evalTime \u2212 receiptTime| \u2264 clockDriftBound (verdict invariant under bounded clock drift).", "status": "live", "ts": "packages/policy/src/gates/temporalConsistency_gate.ts", "sample": {"receiptTimestampMs": 1700000000000, "evalTimestampMs": 1700000000500}, "config": {"clockDriftBoundMs": 1000}},
|
| 661 |
-
{"name": "CausalSeparability", "id": "A11", "leanTheorem": "causal_separability", "leanFile": "Lutar/Gate/CausalSeparability.lean", "leanStatus": "theorem", "axis": "
|
| 662 |
{"name": "ConstructiveTransparency", "id": "A12", "leanTheorem": "constructive_transparency", "leanFile": "Lutar/Gate/ConstructiveTransparency.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Decisions must be constructively transparent.", "status": "ts-only", "ts": "packages/policy/src/gates/constructiveTransparency_gate.ts"},
|
| 663 |
{"name": "EconomicGrounding", "id": "A14", "leanTheorem": "economic_grounding", "leanFile": "Lutar/Gate/EconomicGrounding.lean", "leanStatus": "theorem", "axis": "KALLPA", "severity": "enforced", "gates": "Action must be economically grounded (cost).", "status": "ts-only", "ts": "packages/policy/src/gates/economicGrounding_gate.ts"},
|
| 664 |
-
{"name": "RhoClosureComposition", "id": "T1", "leanTheorem": "rho_closure_composition", "leanFile": "Lutar/Gate/RhoClosureComposition.lean", "leanStatus": "theorem", "axis": "
|
| 665 |
{"name": "LambdaMonotonicity", "id": "T2", "leanTheorem": "lambdaMonotonicity", "leanFile": "Lutar/Gate/LambdaMonotonicity.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Allows evidence augmentation only when every \u039b axis score weakly increases (no decreasing/conflicting axis).", "status": "live", "ts": "packages/policy/src/gates/lambdaMonotonicity_gate.ts", "sample": {"originalScores": [0.9, 0.85], "augmentedScores": [0.95, 0.9]}, "config": {"tolerance": 1e-9}},
|
| 666 |
{"name": "MerkleDagBatch", "id": "T3", "leanTheorem": "merkleDagBatch", "leanFile": "Lutar/Gate/MerkleDagBatch.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows batch only when (B<minBatch) or build p50 \u2264 maxBuildP50Us \u2014 the O(log B) Merkle-DAG latency bound.", "status": "live", "ts": "packages/policy/src/gates/merkleDagBatch_gate.ts", "sample": {"batchSize": 7, "buildP50Us": 4}, "config": {"maxBuildP50Us": 5, "minBatchSize": 7}},
|
| 667 |
-
{"name": "BekensteinEntropyMeasure", "id": "T4", "leanTheorem": "bekenstein_entropy_measure", "leanFile": "Lutar/Gate/BekensteinEntropyMeasure.lean", "leanStatus": "conjectured", "axis": "
|
| 668 |
{"name": "ReplayDeterminism", "id": "T5", "leanTheorem": "replayDeterminism", "leanFile": "Lutar/Gate/ReplayDeterminism.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows deploy only when all requiredRuns replay roots equal the pinned canonical Merkle root (Codex-Kernel determinism).", "status": "live", "ts": "packages/policy/src/gates/replayDeterminism_gate.ts", "sample": {"replayRoots": ["1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678"]}, "config": {"canonicalRoot": "1ed4d253cafebabe12345678", "requiredRuns": 5}},
|
| 669 |
{"name": "ConjunctiveGateCounterexample", "id": "T6", "leanTheorem": "conjunctive_gate_counterexample", "leanFile": "Lutar/Gate/ConjunctiveGate.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Conjunctive gate counterexample search.", "status": "ts-only", "ts": "packages/policy/src/gates/conjunctiveGateCounterexample_gate.ts"},
|
| 670 |
-
{"name": "PrivacyMask", "id": "T7", "leanTheorem": "privacy_mask", "leanFile": "Lutar/Gate/PrivacyMask.lean", "leanStatus": "theorem", "axis": "
|
| 671 |
{"name": "SingleWitnessExclusion", "id": "T8", "leanTheorem": "singleWitnessExclusion", "leanFile": "Lutar/Gate/SingleWitnessExclusion.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows closure only when cross-actor (or same-actor by default) decisions carry \u2265 2 witnesses \u2014 excludes single-witness.", "status": "live", "ts": "packages/policy/src/gates/singleWitnessExclusion_gate.ts", "sample": {"actor1Id": "alice", "actor2Id": "bob", "witnessCount": 2}, "config": {}},
|
| 672 |
{"name": "CrossRegionPolicy", "id": "T9", "leanTheorem": "cross_region_policy", "leanFile": "Lutar/Gate/CrossRegionPolicy.lean", "leanStatus": "theorem", "axis": "KALLPA", "severity": "enforced", "gates": "Cross-region data policy enforced.", "status": "ts-only", "ts": "packages/policy/src/gates/crossRegionPolicy_gate.ts"},
|
| 673 |
-
{"name": "DoctrineEnforcement", "id": "T10", "leanTheorem": "doctrine_enforcement", "leanFile": "Lutar/Gate/DoctrineEnforcement.lean", "leanStatus": "theorem", "axis": "
|
| 674 |
-
{"name": "Composability", "id": "TH1", "leanTheorem": "composability", "leanFile": "Lutar/Composition/Composability.lean", "leanStatus": "theorem", "axis": "
|
| 675 |
{"name": "ReplayDoiDuality", "id": "TH2", "leanTheorem": "replay_doi_duality", "leanFile": "Lutar/Composition/ReplayDoiDuality.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Replay ↔ DOI duality holds.", "status": "ts-only", "ts": "packages/policy/src/gates/replayDoiDuality_gate.ts"},
|
| 676 |
-
{"name": "AnatomyReduction", "id": "TH3", "leanTheorem": "anatomy_reduction", "leanFile": "Lutar/Composition/AnatomyReduction.lean", "leanStatus": "theorem", "axis": "
|
| 677 |
{"name": "LambdaCategoryComposability", "id": "TH4", "leanTheorem": "lambda_category_composability", "leanFile": "Lutar/LaxFunctor.lean", "leanStatus": "conjectured", "axis": "YUYAY", "severity": "advisory", "gates": "Advisory (STAGED): Λ lax-functor composition.", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaCategoryComposability_gate.ts"},
|
| 678 |
{"name": "ReceiptChainConfluence", "id": "TH5", "leanTheorem": "receipt_chain_confluence", "leanFile": "Lutar/Composition/ReceiptChainConfluence.lean", "leanStatus": "conjectured", "axis": "YAWAR", "severity": "enforced", "gates": "Receipt chain confluent under merge.", "status": "ts-only", "ts": "packages/policy/src/gates/receiptChainConfluence_gate.ts"},
|
| 679 |
-
{"name": "BekensteinEntropyDpi", "id": "TH6", "leanTheorem": "bekenstein_entropy_dpi", "leanFile": "Lutar/EntropyBound.lean", "leanStatus": "theorem", "axis": "
|
| 680 |
{"name": "CurryHowardReceiptCalculus", "id": "TH7", "leanTheorem": "curry_howard_receipt_calculus", "leanFile": "Lutar/CurryHoward.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Receipt calculus = proof terms (Curry-Howard).", "status": "ts-only", "ts": "packages/policy/src/gates/curryHowardReceiptCalculus_gate.ts"},
|
| 681 |
# ---- Hickok cognitive-neuroscience ingest (A36/A37/A38) ----
|
| 682 |
# Axis `Hickok`. All ts-only (honest): the Lean anchor files carry `sorry`
|
|
@@ -696,8 +696,8 @@ _REGISTRY: List[Dict[str, Any]] = [
|
|
| 696 |
_SUPPLEMENTARY: List[Dict[str, Any]] = [
|
| 697 |
{"name": "LambdaUniquenessConjecture", "id": "TH_L1", "leanTheorem": "lambdaUniquenessConjecture", "leanFile": "Lutar/Uniqueness.lean", "leanStatus": "conjecture", "axis": "YUYAY", "severity": "advisory-conjecture", "gates": "Lambda fixed-point uniqueness, Conjecture 1 (2 sorry in wider repo; NOT a theorem — Doctrine v11 LOCKED).", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaUniquenessConjecture_gate.ts", "is_conjecture": True, "proven": False, "lambda_statement": "Conjecture 1 (NOT a theorem — LOCKED)"},
|
| 698 |
{"name": "LambdaMinMaxBounds", "id": "TH_L2", "leanTheorem": "lambda_min_max_bounds", "leanFile": "Lutar/Bound.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Λ score min/max bounds (2 sorry in wider repo).", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaMinMaxBounds_gate.ts"},
|
| 699 |
-
{"name": "BekensteinSoundness", "id": "TH_L3", "leanTheorem": "bekenstein_soundness", "leanFile": "Lutar/BekensteinSoundness.lean", "leanStatus": "measured/conjectured", "axis": "
|
| 700 |
-
{"name": "RhoClosureProduction", "id": "TH_L4", "leanTheorem": "rho_closure_production", "leanFile": "Lutar/RhoClosureProduction.lean", "leanStatus": "measured", "axis": "
|
| 701 |
]
|
| 702 |
|
| 703 |
# Canonical 35 anchor formulas (_REGISTRY) are what GET /formulas returns and what
|
|
|
|
| 623 |
_REGISTRY: List[Dict[str, Any]] = [
|
| 624 |
# ---- 5 LIVE ----
|
| 625 |
{"name": "AdversarialRobustness", "id": "TH8", "leanTheorem": "robustness_preserved_by_composition",
|
| 626 |
+
"leanFile": "Lutar/Composition/AdversarialRobustness.lean", "leanStatus": "conjecture-open", "axis": "CHAPAQ",
|
| 627 |
"severity": "enforced", "gates": "Allows pipeline deploy only when composed perturbation ε₂=L₁·L₂·δ ≤ maxEpsilon.",
|
| 628 |
"status": "live", "ts": "packages/policy/src/gates/adversarialRobustness_gate.ts",
|
| 629 |
"sample": {"lipschitz1": 0.8, "lipschitz2": 0.9, "delta": 0.5}, "config": {"maxEpsilon": 1.0}},
|
|
|
|
| 648 |
"status": "live", "ts": "packages/policy/src/gates/summationInvariant_gate.ts",
|
| 649 |
"sample": {"khipuId": "k1", "organs": [{"organId": "o1", "decisions": [{"decisionId": "d1", "value": 3}, {"decisionId": "d2", "value": 4}]}], "primaryCord": 7}, "config": {}},
|
| 650 |
# ---- 10 MORE LIVE (Phase 3, ported below) are interleaved by id; remaining 20 ts-only ----
|
| 651 |
+
{"name": "SoundnessAxiom", "id": "A1", "leanTheorem": "soundness_axiom", "leanFile": "Lutar/Gate/SoundnessAxiom.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "Gate composition soundness floor.", "status": "ts-only", "ts": "packages/policy/src/gates/soundnessAxiom_gate.ts"},
|
| 652 |
{"name": "MoralGroundingFloor", "id": "A2", "leanTheorem": "moral_grounding_floor", "leanFile": "Lutar/Gate/MoralGrounding.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Action must clear moral grounding floor.", "status": "ts-only", "ts": "packages/policy/src/gates/moralGroundingFloor_gate.ts"},
|
| 653 |
{"name": "MeasurabilityHonestyFloor", "id": "A3", "leanTheorem": "measurability_honesty_floor", "leanFile": "Lutar/Gate/MeasurabilityHonesty.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Claims must be measurable / honest.", "status": "ts-only", "ts": "packages/policy/src/gates/measurabilityHonestyFloor_gate.ts"},
|
| 654 |
{"name": "DualWitnessDisjointness", "id": "A4", "leanTheorem": "dualWitnessDisjointness", "leanFile": "Lutar/Gate/DualWitness.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows \u03c1-closure write only when witness_1_id \u2260 witness_2_id (two independent witnesses, no single-witness collapse).", "status": "live", "ts": "packages/policy/src/gates/dualWitnessDisjointness_gate.ts", "sample": {"witness1Id": "alice", "witness2Id": "bob"}, "config": {}},
|
| 655 |
{"name": "DeterministicReplay", "id": "A5", "leanTheorem": "deterministicReplay", "leanFile": "Lutar/Gate/DeterministicReplay.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows production op only when N replay runs yield exactly 1 unique (byte-identical) Merkle root.", "status": "live", "ts": "packages/policy/src/gates/deterministicReplay_gate.ts", "sample": {"replayRoots": ["abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00", "abc123deadbeef00"]}, "config": {"requiredRuns": 5}},
|
| 656 |
{"name": "HashChainIntegrity", "id": "A6", "leanTheorem": "hashChainIntegrity", "leanFile": "Lutar/Gate/HashChainIntegrity.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows chain advancement only when every entry.chainHash == SHA256(JSON of previous entry) \u2014 Khipu chain continuity.", "status": "live", "ts": "packages/policy/src/gates/hashChainIntegrity_gate.ts", "sample": {"entries": [{"entryId": "e0", "payload": "genesis", "chainHash": "genesis"}, {"entryId": "e1", "payload": "second", "chainHash": "45bd824b7e4aadbb7ea4a865d057e4cd832d718a268169680f898274b89c5a8d"}, {"entryId": "e2", "payload": "third", "chainHash": "ae7da7c40007478c3e412457553c0aa235a1804ec65f446e1b2d472548ca50d9"}]}, "config": {}},
|
| 657 |
+
{"name": "BekensteinBound", "id": "A7", "leanTheorem": "bekenstein_bound", "leanFile": "Lutar/Gate/BekensteinBound.lean", "leanStatus": "conjectured", "axis": "CHAPAQ", "severity": "advisory", "gates": "Advisory (STAGED): entropy/information bound.", "status": "ts-only", "ts": "packages/policy/src/gates/bekensteinBound_gate.ts"},
|
| 658 |
+
{"name": "IngestDiscipline", "id": "A8", "leanTheorem": "ingest_discipline", "leanFile": "Lutar/Gate/IngestDiscipline.lean", "leanStatus": "theorem", "axis": "CHAPAQ", "severity": "enforced", "gates": "Ingest must follow discipline schema.", "status": "ts-only", "ts": "packages/policy/src/gates/ingestDiscipline_gate.ts"},
|
| 659 |
+
{"name": "DoctrineCompleteness", "id": "A9", "leanTheorem": "doctrineCompleteness", "leanFile": "Lutar/Gate/DoctrineCompleteness.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "Allows artifact only when SHA-256(doctrine.json) == canonical AND all 8 forbidden patterns enumerated (doctrine-check.sh parity).", "status": "live", "ts": "packages/policy/src/gates/doctrineCompleteness_gate.ts", "sample": {"doctrineJsonRaw": "{\"version\":\"1.0.0\",\"patterns\":[\"FP\",\"FP\",\"FP\",\"FP\",\"FP\",\"FP\",\"FP\",\"FP\"]}", "detectedPatterns": ["FP", "FP", "FP", "FP", "FP", "FP", "FP", "FP"]}, "config": {"canonicalSha256": "1ebcac54bde49c4062648d0e9757a4364858d6826b60f1f14e79bc1964f1f4fb"}},
|
| 660 |
{"name": "TemporalConsistency", "id": "A10", "leanTheorem": "temporalConsistency", "leanFile": "Lutar/Gate/TemporalConsistency.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows receipt only when |evalTime \u2212 receiptTime| \u2264 clockDriftBound (verdict invariant under bounded clock drift).", "status": "live", "ts": "packages/policy/src/gates/temporalConsistency_gate.ts", "sample": {"receiptTimestampMs": 1700000000000, "evalTimestampMs": 1700000000500}, "config": {"clockDriftBoundMs": 1000}},
|
| 661 |
+
{"name": "CausalSeparability", "id": "A11", "leanTheorem": "causal_separability", "leanFile": "Lutar/Gate/CausalSeparability.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "Causal graph must be separable.", "status": "ts-only", "ts": "packages/policy/src/gates/causalSeparability_gate.ts"},
|
| 662 |
{"name": "ConstructiveTransparency", "id": "A12", "leanTheorem": "constructive_transparency", "leanFile": "Lutar/Gate/ConstructiveTransparency.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Decisions must be constructively transparent.", "status": "ts-only", "ts": "packages/policy/src/gates/constructiveTransparency_gate.ts"},
|
| 663 |
{"name": "EconomicGrounding", "id": "A14", "leanTheorem": "economic_grounding", "leanFile": "Lutar/Gate/EconomicGrounding.lean", "leanStatus": "theorem", "axis": "KALLPA", "severity": "enforced", "gates": "Action must be economically grounded (cost).", "status": "ts-only", "ts": "packages/policy/src/gates/economicGrounding_gate.ts"},
|
| 664 |
+
{"name": "RhoClosureComposition", "id": "T1", "leanTheorem": "rho_closure_composition", "leanFile": "Lutar/Gate/RhoClosureComposition.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "ρ-closure composes under pipeline.", "status": "ts-only", "ts": "packages/policy/src/gates/rhoClosureComposition_gate.ts"},
|
| 665 |
{"name": "LambdaMonotonicity", "id": "T2", "leanTheorem": "lambdaMonotonicity", "leanFile": "Lutar/Gate/LambdaMonotonicity.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Allows evidence augmentation only when every \u039b axis score weakly increases (no decreasing/conflicting axis).", "status": "live", "ts": "packages/policy/src/gates/lambdaMonotonicity_gate.ts", "sample": {"originalScores": [0.9, 0.85], "augmentedScores": [0.95, 0.9]}, "config": {"tolerance": 1e-9}},
|
| 666 |
{"name": "MerkleDagBatch", "id": "T3", "leanTheorem": "merkleDagBatch", "leanFile": "Lutar/Gate/MerkleDagBatch.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows batch only when (B<minBatch) or build p50 \u2264 maxBuildP50Us \u2014 the O(log B) Merkle-DAG latency bound.", "status": "live", "ts": "packages/policy/src/gates/merkleDagBatch_gate.ts", "sample": {"batchSize": 7, "buildP50Us": 4}, "config": {"maxBuildP50Us": 5, "minBatchSize": 7}},
|
| 667 |
+
{"name": "BekensteinEntropyMeasure", "id": "T4", "leanTheorem": "bekenstein_entropy_measure", "leanFile": "Lutar/Gate/BekensteinEntropyMeasure.lean", "leanStatus": "conjectured", "axis": "CHAPAQ", "severity": "enforced", "gates": "Entropy measure ≤ Bekenstein bound.", "status": "ts-only", "ts": "packages/policy/src/gates/bekensteinEntropyMeasure_gate.ts"},
|
| 668 |
{"name": "ReplayDeterminism", "id": "T5", "leanTheorem": "replayDeterminism", "leanFile": "Lutar/Gate/ReplayDeterminism.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Allows deploy only when all requiredRuns replay roots equal the pinned canonical Merkle root (Codex-Kernel determinism).", "status": "live", "ts": "packages/policy/src/gates/replayDeterminism_gate.ts", "sample": {"replayRoots": ["1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678", "1ed4d253cafebabe12345678"]}, "config": {"canonicalRoot": "1ed4d253cafebabe12345678", "requiredRuns": 5}},
|
| 669 |
{"name": "ConjunctiveGateCounterexample", "id": "T6", "leanTheorem": "conjunctive_gate_counterexample", "leanFile": "Lutar/Gate/ConjunctiveGate.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Conjunctive gate counterexample search.", "status": "ts-only", "ts": "packages/policy/src/gates/conjunctiveGateCounterexample_gate.ts"},
|
| 670 |
+
{"name": "PrivacyMask", "id": "T7", "leanTheorem": "privacy_mask", "leanFile": "Lutar/Gate/PrivacyMask.lean", "leanStatus": "theorem", "axis": "CHAPAQ", "severity": "enforced", "gates": "PII mask must cover sensitive fields.", "status": "ts-only", "ts": "packages/policy/src/gates/privacyMask_gate.ts"},
|
| 671 |
{"name": "SingleWitnessExclusion", "id": "T8", "leanTheorem": "singleWitnessExclusion", "leanFile": "Lutar/Gate/SingleWitnessExclusion.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Allows closure only when cross-actor (or same-actor by default) decisions carry \u2265 2 witnesses \u2014 excludes single-witness.", "status": "live", "ts": "packages/policy/src/gates/singleWitnessExclusion_gate.ts", "sample": {"actor1Id": "alice", "actor2Id": "bob", "witnessCount": 2}, "config": {}},
|
| 672 |
{"name": "CrossRegionPolicy", "id": "T9", "leanTheorem": "cross_region_policy", "leanFile": "Lutar/Gate/CrossRegionPolicy.lean", "leanStatus": "theorem", "axis": "KALLPA", "severity": "enforced", "gates": "Cross-region data policy enforced.", "status": "ts-only", "ts": "packages/policy/src/gates/crossRegionPolicy_gate.ts"},
|
| 673 |
+
{"name": "DoctrineEnforcement", "id": "T10", "leanTheorem": "doctrine_enforcement", "leanFile": "Lutar/Gate/DoctrineEnforcement.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "Doctrine v11 LOCKED enforcement.", "status": "ts-only", "ts": "packages/policy/src/gates/doctrineEnforcement_gate.ts"},
|
| 674 |
+
{"name": "Composability", "id": "TH1", "leanTheorem": "composability", "leanFile": "Lutar/Composition/Composability.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "Allows A\u2218B cross-system deploy only when doctrine SHAs match, A exit floor \u2264 B entry floor, and A2A headers present.", "status": "live", "ts": "packages/policy/src/gates/composability_gate.ts", "sample": {"doctrineShaA": "abc123sha256", "doctrineShaB": "abc123sha256", "aExitFloor": 0.9, "bEntryFloor": 0.92, "hasA2AHeaders": True}, "config": {}},
|
| 675 |
{"name": "ReplayDoiDuality", "id": "TH2", "leanTheorem": "replay_doi_duality", "leanFile": "Lutar/Composition/ReplayDoiDuality.lean", "leanStatus": "theorem", "axis": "UNAY", "severity": "enforced", "gates": "Replay ↔ DOI duality holds.", "status": "ts-only", "ts": "packages/policy/src/gates/replayDoiDuality_gate.ts"},
|
| 676 |
+
{"name": "AnatomyReduction", "id": "TH3", "leanTheorem": "anatomy_reduction", "leanFile": "Lutar/Composition/AnatomyReduction.lean", "leanStatus": "theorem", "axis": "YACHAY", "severity": "enforced", "gates": "7-organ anatomy reduces correctly.", "status": "ts-only", "ts": "packages/policy/src/gates/anatomyReduction_gate.ts"},
|
| 677 |
{"name": "LambdaCategoryComposability", "id": "TH4", "leanTheorem": "lambda_category_composability", "leanFile": "Lutar/LaxFunctor.lean", "leanStatus": "conjectured", "axis": "YUYAY", "severity": "advisory", "gates": "Advisory (STAGED): Λ lax-functor composition.", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaCategoryComposability_gate.ts"},
|
| 678 |
{"name": "ReceiptChainConfluence", "id": "TH5", "leanTheorem": "receipt_chain_confluence", "leanFile": "Lutar/Composition/ReceiptChainConfluence.lean", "leanStatus": "conjectured", "axis": "YAWAR", "severity": "enforced", "gates": "Receipt chain confluent under merge.", "status": "ts-only", "ts": "packages/policy/src/gates/receiptChainConfluence_gate.ts"},
|
| 679 |
+
{"name": "BekensteinEntropyDpi", "id": "TH6", "leanTheorem": "bekenstein_entropy_dpi", "leanFile": "Lutar/EntropyBound.lean", "leanStatus": "theorem", "axis": "CHAPAQ", "severity": "enforced", "gates": "DPI entropy bound (discharges A7 formally).", "status": "ts-only", "ts": "packages/policy/src/gates/bekensteinEntropyDpi_gate.ts"},
|
| 680 |
{"name": "CurryHowardReceiptCalculus", "id": "TH7", "leanTheorem": "curry_howard_receipt_calculus", "leanFile": "Lutar/CurryHoward.lean", "leanStatus": "theorem", "axis": "YAWAR", "severity": "enforced", "gates": "Receipt calculus = proof terms (Curry-Howard).", "status": "ts-only", "ts": "packages/policy/src/gates/curryHowardReceiptCalculus_gate.ts"},
|
| 681 |
# ---- Hickok cognitive-neuroscience ingest (A36/A37/A38) ----
|
| 682 |
# Axis `Hickok`. All ts-only (honest): the Lean anchor files carry `sorry`
|
|
|
|
| 696 |
_SUPPLEMENTARY: List[Dict[str, Any]] = [
|
| 697 |
{"name": "LambdaUniquenessConjecture", "id": "TH_L1", "leanTheorem": "lambdaUniquenessConjecture", "leanFile": "Lutar/Uniqueness.lean", "leanStatus": "conjecture", "axis": "YUYAY", "severity": "advisory-conjecture", "gates": "Lambda fixed-point uniqueness, Conjecture 1 (2 sorry in wider repo; NOT a theorem — Doctrine v11 LOCKED).", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaUniquenessConjecture_gate.ts", "is_conjecture": True, "proven": False, "lambda_statement": "Conjecture 1 (NOT a theorem — LOCKED)"},
|
| 698 |
{"name": "LambdaMinMaxBounds", "id": "TH_L2", "leanTheorem": "lambda_min_max_bounds", "leanFile": "Lutar/Bound.lean", "leanStatus": "theorem", "axis": "YUYAY", "severity": "enforced", "gates": "Λ score min/max bounds (2 sorry in wider repo).", "status": "ts-only", "ts": "packages/policy/src/gates/lambdaMinMaxBounds_gate.ts"},
|
| 699 |
+
{"name": "BekensteinSoundness", "id": "TH_L3", "leanTheorem": "bekenstein_soundness", "leanFile": "Lutar/BekensteinSoundness.lean", "leanStatus": "measured/conjectured", "axis": "CHAPAQ", "severity": "advisory", "gates": "Advisory (STAGED): Bekenstein soundness.", "status": "ts-only", "ts": "packages/policy/src/gates/bekensteinSoundness_gate.ts"},
|
| 700 |
+
{"name": "RhoClosureProduction", "id": "TH_L4", "leanTheorem": "rho_closure_production", "leanFile": "Lutar/RhoClosureProduction.lean", "leanStatus": "measured", "axis": "YACHAY", "severity": "enforced", "gates": "ρ-closure measured in production.", "status": "ts-only", "ts": "packages/policy/src/gates/rhoClosureProduction_gate.ts"},
|
| 701 |
]
|
| 702 |
|
| 703 |
# Canonical 35 anchor formulas (_REGISTRY) are what GET /formulas returns and what
|