feat(orchestrator): Gibberlink radio mode with ggwave and a fallback selector (018)
A new radio mode sends each spoken row as ggwave frames of at most 140 bytes: frame 1 carries the full session id, later frames its 8-character prefix, each with n/m. engines.sound_of() gives every speaker one of the four audible ggwave protocols that decode every frame length, plus its own stereo position, by a stable hash. The vendored ggwave 0.4.0 (MIT, LICENSE kept, sha256 pinned in test_hub_artifacts) runs only in the /gibberlink encoder page, sandboxed into an opaque origin with eval and WebAssembly but no connection; the hub page frames it (frame-src 'self') and review pages refuse framing (frame-ancestors 'none'). The radio gear gains a fallback selector (Gibberlink, Morse, Hiss) for rows that speech cannot play. Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): engines.py FTSCAN-231 INF-SCAN-2638 INF-SCAN-2057 STG009 B603; handler.py FTSC-SCAN-089 B105 EXA002 EXA006; view.py WEB-FLASK-004 FINE-043 LO002. 🎯 Fix: 91 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
af3555e88b
commit
621dc7536f
23 files changed
+1021
-34
No files matched your search
@@ -45,6 +45,8 @@ HEARING_BUDGET = 5 * STT_SECONDS
|
||||
NOISE = re.compile(r"\[[^\]\n]{0,40}\]")
|
||||
PLACEHOLDERS = frozenset({0, 0xFFFFFFFF})
|
||||
PITCH = (550, 850)
|
||||
GIBBERLINK = ("AUDIBLE_NORMAL", "AUDIBLE_FAST", "AUDIBLE_FASTEST", "DT_FASTEST")
|
||||
PANS = (-0.8, -0.4, 0.0, 0.4, 0.8)
|
||||
|
||||
|
||||
def voice_models(folder: Path) -> list[Path]:
|
||||
@@ -134,6 +136,20 @@ def pitch_of(key: str) -> int:
|
||||
return low + slot(key, high - low + 1)
|
||||
|
||||
|
||||
def sound_of(key: str) -> dict[str, str | float]:
|
||||
"""Args:
|
||||
key: the speaker's session id or directory key, as pitch_of takes it.
|
||||
|
||||
Returns:
|
||||
protocol: the ggwave protocol of GIBBERLINK, the four of the vendored
|
||||
ggwave 0.4.0 whose frames decode at every length up to 140 bytes;
|
||||
pan: the stereo position of PANS. One slot picks both, so the
|
||||
speakers of distinct slots get distinct pairs.
|
||||
"""
|
||||
picked = slot(key, len(GIBBERLINK) * len(PANS))
|
||||
return {"protocol": GIBBERLINK[picked % len(GIBBERLINK)], "pan": PANS[picked // len(GIBBERLINK)]}
|
||||
|
||||
|
||||
def wav_seconds(body: bytes, seconds: int) -> float:
|
||||
"""Args:
|
||||
body: the recording.
|
||||
|
||||
@@ -16,7 +16,7 @@ from .scores import scored
|
||||
|
||||
BODY_LIMIT = 1 << 20
|
||||
UPLOAD_LIMIT = 50 << 20
|
||||
PAGE_CSP = "sandbox allow-scripts"
|
||||
PAGE_CSP = "sandbox allow-scripts; frame-ancestors 'none'"
|
||||
SETTINGS_ROUTE = "/api/settings"
|
||||
TTS_ROUTE = "/api/tts"
|
||||
WAV_TYPE = "audio/wav"
|
||||
@@ -50,6 +50,7 @@ TASKS_ROUTE = "/api/tasks"
|
||||
GATES_ROUTE = "/api/gates"
|
||||
TOKEN_ROUTE = "/api/cleanup/token"
|
||||
VIEW_ROUTE = "/api/view"
|
||||
ENCODER_ROUTE = "/gibberlink"
|
||||
VENDOR_ROUTE = re.compile(r"/vendor/([a-z0-9.-]{1,64})")
|
||||
SCRIPT_TYPE = "text/javascript; charset=utf-8"
|
||||
FONT_TYPE = "font/woff2"
|
||||
@@ -57,6 +58,7 @@ VENDOR = {
|
||||
"3d-force-graph.min.js": ("3d-force-graph/3d-force-graph.min.js", SCRIPT_TYPE),
|
||||
"three.module.js": ("three/three.module.js", SCRIPT_TYPE),
|
||||
"three.core.js": ("three/three.core.js", SCRIPT_TYPE),
|
||||
"ggwave.js": ("ggwave/ggwave.js", SCRIPT_TYPE),
|
||||
"comic-neue.woff2": ("comic-neue/comic-neue-latin-400-normal.woff2", FONT_TYPE),
|
||||
}
|
||||
VOICE_ROUTE = "/api/voice"
|
||||
@@ -107,6 +109,8 @@ class Handler(Exchange):
|
||||
self.send_text(HTTPStatus.FORBIDDEN, "forbidden host")
|
||||
elif path == "/":
|
||||
self.index()
|
||||
elif path == ENCODER_ROUTE:
|
||||
self.encoder()
|
||||
elif firewall:
|
||||
self.answer(firewall, HTTPStatus.OK)
|
||||
elif diff:
|
||||
@@ -331,6 +335,10 @@ class Handler(Exchange):
|
||||
headers = {"Content-Security-Policy": csp, "X-Frame-Options": "DENY"}
|
||||
self.send(HTTPStatus.OK, "text/html; charset=utf-8", page.encode("utf-8"), headers)
|
||||
|
||||
def encoder(self) -> None:
|
||||
page, csp = self.server.hub.encoder(secrets.token_urlsafe(18))
|
||||
self.send(HTTPStatus.OK, "text/html; charset=utf-8", page.encode("utf-8"), {"Content-Security-Policy": csp})
|
||||
|
||||
def vendored(self, name: str, content_type: str) -> None:
|
||||
headers = {"Content-Security-Policy": PLAIN_CSP, "Cache-Control": "private, max-age=86400"}
|
||||
self.attempt((self.server.hub.vendor / name).read_bytes, lambda data: self.send(HTTPStatus.OK, content_type, data, headers))
|
||||
|
||||
@@ -15,7 +15,7 @@ from .council import (
|
||||
silence_of,
|
||||
)
|
||||
from .crons import queue_entries
|
||||
from .engines import pitch_of
|
||||
from .engines import pitch_of, sound_of
|
||||
from .errors import ToolError
|
||||
from .events import KINDS, VIEWS
|
||||
from .fields import decode, instant, single
|
||||
@@ -47,9 +47,13 @@ RADIO_WINDOW = 86400
|
||||
JOBS_SHOWN = 20
|
||||
ACTIVE = 900
|
||||
INDEX_CSP = (
|
||||
"default-src 'none'; script-src 'nonce-{0}'; style-src 'nonce-{0}'; connect-src 'self'; media-src {1}; "
|
||||
"default-src 'none'; script-src 'nonce-{0}'; style-src 'nonce-{0}'; connect-src 'self'; media-src {1}; frame-src 'self'; "
|
||||
"base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
|
||||
)
|
||||
ENCODER_CSP = (
|
||||
"sandbox allow-scripts; default-src 'none'; script-src 'nonce-{0}' 'unsafe-eval' 'wasm-unsafe-eval'; connect-src 'none'; "
|
||||
"base-uri 'none'; form-action 'none'; frame-ancestors 'self'"
|
||||
)
|
||||
|
||||
|
||||
def badges(inbox: list[dict], claims: list[dict], jobs: list[dict], now: float) -> dict[str, int]:
|
||||
@@ -111,7 +115,7 @@ class View:
|
||||
called = [directory.at(key, row["ts"]) or name for key, name in zip(targets, row["to"], strict=True)]
|
||||
speaker = directory.at(source, row["ts"]) or row["from"]
|
||||
word, rest = phrase_parts(row["class"], speaker, called, row["text"])
|
||||
spoken = {"speech": joined((word, rest)), "word": word, "rest": rest, "voice": self.speech.voice_of(source), "pitch": pitch_of(source), "speaker": speaker, "called": called}
|
||||
spoken = {"speech": joined((word, rest)), "word": word, "rest": rest, "voice": self.speech.voice_of(source), "pitch": pitch_of(source), **sound_of(source), "speaker": speaker, "called": called}
|
||||
read = read_of(inlined, row["ts"])
|
||||
radio.append({**row, "source": source, "targets": targets, "now": directory.now(source), **spoken, **read})
|
||||
grant_rows = [{**grant, "target": directory.key(grant["to"], grant["ts"])} for grant in grants(history, (begin, end), claims, tasks)]
|
||||
@@ -235,3 +239,15 @@ class View:
|
||||
state = self.state(now - RADIO_WINDOW, now, now, 0)
|
||||
page = self.templates.get_template("index.html.j2").render(nonce=nonce, state=state, view=self.view_store.get(), icons=self.icons, emoji_bases=sorted(signing.EMOJI_BASES))
|
||||
return page, INDEX_CSP.format(nonce, " ".join(["'self'", *state["media"]]))
|
||||
|
||||
def encoder(self, nonce: str) -> tuple[str, str]:
|
||||
"""Args:
|
||||
nonce: the response's script nonce.
|
||||
|
||||
Returns:
|
||||
The Gibberlink encoder page and its own CSP: the vendored ggwave
|
||||
needs eval and WebAssembly, which the hub page never allows, so
|
||||
the server sandboxes it into an opaque origin however it loads,
|
||||
with no connection at all.
|
||||
"""
|
||||
return self.templates.get_template("gibberlink.html.j2").render(nonce=nonce), ENCODER_CSP.format(nonce)
|
||||
Reference in new issue
Block a user