feat(orchestrator): S8 shared speech service and sealed model transport

Requirement 001 S8: the hub can use a shared OpenAI-style speech service (KVB_ORCHESTRATOR_SPEECH_URL, key from a mounted file) instead of the local piper and whisper engines, and the image takes its pinned artefacts through an optional INFINITO_ARTEFACT_BASE cache. A new transport serves speech and the LLM: one wall-clock deadline over DNS, connect, TLS handshake and body, certificate and hostname always verified, no redirect followed. A key travels only over https or to loopback; both the speech and the LLM start refuse it otherwise. Key files are capped at 4096 bytes. Streamed WAV answers with placeholder sizes are accepted only when the data chunk runs to the end, and are rewritten before caching. Accepted MEDUSA false positives (41, independent review, operator pick): raw client socket patterns in transport.py, AIC-EXFIL-005 on the sealed key path, JB-SCAN-2237 on the hub's own system prompt, STG009 on the RIFF pad byte and LLM01 at language.py:111, where agent-written titles reach the NL prompt but the model only proposes a plan the operator confirms.

🎯 Fix: 93 %
💥 Break: 4 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 89
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-13 16:57:52 +00:00
1 parent 590b430d37
commit 6d2bca77f7
16 files changed
+1253 -56

No files matched your search

+25 -25
View File
@@ -2,15 +2,15 @@ from __future__ import annotations
import json
import time
import urllib.request
from dataclasses import dataclass
from pathlib import Path
from dataclasses import dataclass, field
from . import transport
from .council import NEWS, ordered, read_claims
from .denying import DENIABLE
from .errors import ToolError
from .events import VIEWS
from .fields import bounded, decode, expect, message_text
from .keys import bearer, sealed
from .records import read_jsonl
from .register import REGISTER, agent_order, read_register
@@ -18,14 +18,6 @@ NL_LIMIT = 2000
NL_ACTION_LIMIT = 20
LLM_TIMEOUT = 60
LLM_REPLY = 1 << 20
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None
LLM_OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect)
SCREENS = ("stream", "inbox", "rules", "agents", "artifacts", "tasks")
IDS = {"type": "array", "items": {"type": "string"}, "minItems": 1, "description": "Ids from items."}
NL_ACTIONS = [
@@ -139,9 +131,23 @@ def nl_actions(reply: str, items: list[dict], agents: list[str]) -> dict:
@dataclass(frozen=True)
class Model:
"""Args:
url: base URL of an OpenAI-compatible chat endpoint; empty turns the
natural-language command line off.
model: the model name sent to it.
key: the bearer key it expects; empty sends none. It never shows in
the repr or in any message.
"""
url: str
model: str
key: str
key: str = field(repr=False)
def __post_init__(self) -> None:
if self.key and not bearer(self.key):
raise ToolError("the model endpoint key must be printable ASCII without whitespace: check KVB_ORCHESTRATOR_LLM_KEY_FILE")
if self.url and self.key and not sealed(self.url):
raise ToolError("the model endpoint key travels only over https or to 127.0.0.1, localhost or ::1: set an https KVB_ORCHESTRATOR_LLM_URL or empty KVB_ORCHESTRATOR_LLM_KEY_FILE")
def enabled(self) -> bool:
return bool(self.url and self.model)
@@ -153,25 +159,19 @@ class Model:
if self.key:
headers["Authorization"] = f"Bearer {self.key}"
body = json.dumps({"model": self.model, "messages": messages, "temperature": 0, "response_format": {"type": "json_object"}}).encode()
request = urllib.request.Request(target, data=body, headers=headers, method="POST")
try:
with LLM_OPENER.open(request, timeout=LLM_TIMEOUT) as response:
data = json.loads(response.read(LLM_REPLY))
content = data["choices"][0]["message"]["content"]
except (OSError, ValueError, KeyError, IndexError, TypeError) as error:
raise ToolError(f"the model endpoint failed: {error}") from None
reply = transport.post(target, body, headers, LLM_REPLY, LLM_TIMEOUT)
except transport.Failure as failure:
raise ToolError(f"the model endpoint {failure}") from None
try:
content = json.loads(reply)["choices"][0]["message"]["content"]
except (ValueError, RecursionError, KeyError, IndexError, TypeError) as error:
raise ToolError(f"the model endpoint failed: {type(error).__name__}") from None
if not isinstance(content, str):
raise ToolError("the model endpoint answered no text")
return content
def read_key(path: Path) -> str:
try:
return path.read_text(encoding="utf-8").strip()
except (OSError, ValueError):
return ""
class Language:
def nl(self, body: bytes) -> dict:
if not self.model.enabled():