feat(orchestrator): operator composer with signed text and voice
Stream -> Radio gets one line per station with state, play and stop, autoplay and CSP refusals as row state and toast, and the speaking agent pulsing there and in the Orbit and Chord views. The composer sends on all seven channels; push-to-talk records with MediaRecorder, whisper.cpp transcribes off the request thread under per-minute and per-hour caps, and the recording travels only when "Aufnahme anhängen" is ticked. Every operator message, the mayday clear, the day and night board actions and a settings save that adds a stream origin take the passkey; the hub verifies each signature once against the pinned keys before it relays or acts. The container gets TMPDIR=/scratch so that verification no longer fails on the read-only root. A denial now signs its recipient: the inbox and the signing step resolve it through one function, a claim set naming several agents leaves a direct denial without recipient, and a recipient that changed after the inbox showed it is refused with 409. operator_message returns only the signed reason for a denial, never the agent's own words the radio row quotes, and the permission hook hashes the signed recipient too. 🎯 Fix: 95 % 💥 Break: 3 % 💸 Cost: 99 % ⏱️ Time: 68 % 🛡️ Security: 100 % 🏆 Score: 100 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dbd9ec3311
commit
089f8dbb9f
49 files changed
+1971
-241
No files matched your search
@@ -6,6 +6,7 @@ import re
|
||||
import secrets
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
import wave
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -25,6 +26,10 @@ STT_RATE = 16000
|
||||
STT_SECONDS = 120
|
||||
STT_LIMIT = 44 + STT_RATE * 2 * STT_SECONDS
|
||||
STT_TIMEOUT = 120
|
||||
HEARING_WINDOW = 60
|
||||
HEARING_RATE = 6
|
||||
HEARING_HOUR = 3600
|
||||
HEARING_BUDGET = 5 * STT_SECONDS
|
||||
NOISE = re.compile(r"\[[^\]\n]{0,40}\]")
|
||||
|
||||
|
||||
@@ -138,6 +143,8 @@ class Speech:
|
||||
self.pool = [voice for voice in self.voices if voice != self.operator]
|
||||
self.speaking = threading.Lock()
|
||||
self.hearing = threading.Lock()
|
||||
self.metering = threading.Lock()
|
||||
self.admitted: list[tuple[float, float]] = []
|
||||
|
||||
def env(self) -> dict[str, str]:
|
||||
scratch = str(self.engines.scratch)
|
||||
@@ -232,11 +239,29 @@ class Speech:
|
||||
for path in kept[TTS_KEEP:]:
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
def admit(self, seconds: float) -> None:
|
||||
"""Raises:
|
||||
Unavailable when HEARING_RATE recordings were admitted in the last
|
||||
HEARING_WINDOW seconds, or when this one would take the audio
|
||||
admitted in the last hour past HEARING_BUDGET seconds.
|
||||
"""
|
||||
now = time.monotonic()
|
||||
with self.metering:
|
||||
recent = [(at, length) for at, length in self.admitted if at > now - HEARING_HOUR]
|
||||
if sum(1 for at, _ in recent if at > now - HEARING_WINDOW) >= HEARING_RATE:
|
||||
raise Unavailable(f"the hub transcribes at most {HEARING_RATE} recordings per {HEARING_WINDOW} s: try again in a minute")
|
||||
if sum(length for _, length in recent) + seconds > HEARING_BUDGET:
|
||||
raise Unavailable(f"the hub transcribes at most {HEARING_BUDGET} s of audio per hour; the budget refills as the hour passes")
|
||||
self.admitted = [*recent, (now, seconds)]
|
||||
|
||||
def transcribe(self, body: bytes) -> dict:
|
||||
gap = self.input_gap()
|
||||
if gap:
|
||||
raise Unavailable(f"speech input is off: {gap}")
|
||||
wav_seconds(body)
|
||||
self.admit(wav_seconds(body))
|
||||
return self.whisper(body)
|
||||
|
||||
def whisper(self, body: bytes) -> dict:
|
||||
command = [str(self.engines.whisper), "--model", str(self.engines.whisper_model), "--file", "-", "--output-txt", "--language", "auto", "--no-prints", "--suppress-nst"]
|
||||
with self.hearing:
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user