Requirement 005: every radio message in the Stream and the radio log shows the avatars of the agents that read it, with read time and an ack badge where a receipt exists; receipt rows no longer appear as entries of their own, and the sender shows once. Read times come from seen marks, stamped only after a fresh presence pass no older than two sighting intervals; a stored time before its row is refused. An operator message links to its relay row through the ts radio.py prints first on stdout right after store(), checked against an exact row (sender Operator, relay text, targets, no to_sessions); a ts shared by two rows shows no readers. radio.py clips printed addresses; the hub keeps the first stdout line whole. Accepted MEDUSA false positives: MM-SCAN-058 at server.py:73, JB-SCAN-641 and JB-SCAN-616 at radio.py:389 (clip, the output sanitizer), FLA-SCAN-055 at radio.py:109. Committed below the 90/5 bar on the operator's word; the receipts e2e runs through the queue. 🎯 Fix: 89 % 💥 Break: 6 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 84 🚦 Gate: ⛔ fix 89 % < 90, break 6 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
197 lines
6.1 KiB
Python
197 lines
6.1 KiB
Python
from __future__ import annotations
|
|
|
|
import functools
|
|
import threading
|
|
import time
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
import jinja2
|
|
from markupsafe import Markup
|
|
|
|
from .approving import Approving
|
|
from .artifacts import Touched
|
|
from .asking import Asking
|
|
from .batches import Pending
|
|
from .choosing import Choosing
|
|
from .cleanup import Cleaning, Spool
|
|
from .crons import History, queue_live
|
|
from .denying import Denying
|
|
from .engines import Engines, Speech
|
|
from .events import Log, Watch
|
|
from .gating import Gating
|
|
from .icons import sheet
|
|
from .inbox import Inbox
|
|
from .jobs import Jobs
|
|
from .language import Language, Model
|
|
from .ledger import Ledger, Marks, Reviews
|
|
from .mcp import Mcp
|
|
from .messaging import Messaging
|
|
from .names import Names
|
|
from .offices import Offices
|
|
from .presence import SNAPSHOT
|
|
from .receipts import (
|
|
NAMES,
|
|
READS,
|
|
SIGHTING,
|
|
ReceiptNames,
|
|
ReceiptReads,
|
|
sight,
|
|
sighting_pass,
|
|
)
|
|
from .redirects import Redirects
|
|
from .requesting import Requesting
|
|
from .resources import RESOURCES, SAMPLES
|
|
from .reviewing import Reviewing
|
|
from .rules import Rules
|
|
from .settings import Settings
|
|
from .signed import signing
|
|
from .skill_scripts import Runner
|
|
from .sources import Sources
|
|
from .speechgate import CpuGate
|
|
from .tasking import Tasking
|
|
from .timeline import Timeline
|
|
from .transcripts import Transcripts
|
|
from .tree import TREE_HEARTBEAT, Tree
|
|
from .view import RADIO_WINDOW, View
|
|
from .voicenotes import VoiceNotes
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Places:
|
|
tree_file: Path
|
|
timers: Path
|
|
vendor: Path
|
|
cleanup: Path
|
|
offices: Path
|
|
kept: Path
|
|
|
|
|
|
def environment(templates: Path) -> jinja2.Environment:
|
|
env = jinja2.Environment(
|
|
loader=jinja2.FileSystemLoader(templates),
|
|
autoescape=True,
|
|
undefined=jinja2.StrictUndefined,
|
|
trim_blocks=True,
|
|
lstrip_blocks=True,
|
|
)
|
|
env.policies["json.dumps_kwargs"] = {"sort_keys": False}
|
|
return env
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Hub(Mcp, Reviewing, Asking, Messaging, Choosing, Approving, Denying, Requesting, Cleaning, Offices, Tasking, Gating, Inbox, Rules, Jobs, Sources, Timeline, View, Language):
|
|
council: Path
|
|
pages: Path
|
|
public_port: int
|
|
reviews: Reviews
|
|
asks: Ledger
|
|
decisions: Ledger
|
|
messages: Ledger
|
|
rule_requests: Ledger
|
|
uploads: Path
|
|
host_state: Path
|
|
transcripts: Transcripts
|
|
scripts: Runner
|
|
templates: jinja2.Environment
|
|
rules: Ledger
|
|
jobs: Ledger
|
|
marks: Marks
|
|
log: Log
|
|
batches: Pending
|
|
names: Names
|
|
receipt_names: ReceiptNames
|
|
receipt_reads: ReceiptReads
|
|
watch: Watch
|
|
tree: Tree
|
|
agent_sessions: Path
|
|
model: Model
|
|
timers: Path
|
|
kept: Path
|
|
settings: Settings
|
|
redirects: Redirects
|
|
speech: Speech
|
|
speech_gate: CpuGate
|
|
approvers: Path
|
|
vendor: Path
|
|
icons: Markup
|
|
spool: Spool
|
|
office_spool: Spool
|
|
touched: Touched
|
|
voice_notes: VoiceNotes
|
|
replay: Path
|
|
history: History
|
|
|
|
def hosts(self) -> tuple[str, str]:
|
|
return f"127.0.0.1:{self.public_port}", f"localhost:{self.public_port}"
|
|
|
|
def url(self) -> str:
|
|
return f"{signing.origin_of(self.public_port)}/"
|
|
|
|
|
|
def sighting(hub: Hub, stop: threading.Event) -> threading.Thread:
|
|
"""Args:
|
|
hub: the hub whose receipt stores record the host snapshot's names
|
|
and the first sighting of each read row.
|
|
stop: ends the thread once set.
|
|
|
|
Returns:
|
|
The started daemon thread that runs sighting_pass() every SIGHTING
|
|
seconds, whether or not a page builds the state.
|
|
"""
|
|
step = functools.partial(sighting_pass, hub.scripts.skills, hub.council, hub.receipt_names, hub.receipt_reads, hub.agent_sessions, RADIO_WINDOW)
|
|
thread = threading.Thread(target=sight, args=(step, hub.receipt_reads, stop, SIGHTING), name="receipt names", daemon=True)
|
|
thread.start()
|
|
return thread
|
|
|
|
|
|
def open_hub(council: Path, pages: Path, public_port: int, state: Path, host_state: Path, transcripts: Path, scripts: Runner, templates: Path, places: Places, model: Model, engines: Engines, approvers: Path, redirects: Redirects) -> Hub:
|
|
uploads = state / "uploads"
|
|
uploads.mkdir(exist_ok=True)
|
|
reviews = Reviews(state)
|
|
speech = Speech(engines, state / "tts")
|
|
messages = Ledger(state / "messages.json")
|
|
settings = Settings(state / "settings.json")
|
|
return Hub(
|
|
speech_gate=CpuGate(samples=places.kept / RESOURCES / SAMPLES, threshold=lambda: settings.get()["speech"]["threshold"], clock=time.time),
|
|
vendor=places.vendor,
|
|
icons=sheet(places.vendor, templates),
|
|
spool=Spool(places.cleanup).ready(),
|
|
office_spool=Spool(places.offices).ready(),
|
|
touched=Touched(reviews.stored),
|
|
approvers=approvers,
|
|
speech=speech,
|
|
voice_notes=VoiceNotes(state / "voice", host_state / "voice", speech, lambda: {message["voice"] for message in messages.listed() if message.get("voice")}),
|
|
replay=state / "replay" / "messages.json",
|
|
rules=Ledger(state / "rules.json"),
|
|
jobs=Ledger(state / "jobs.json"),
|
|
marks=Marks(state / "marks.json"),
|
|
log=Log(state / "log.jsonl"),
|
|
batches=Pending(),
|
|
names=Names(state / "names.json"),
|
|
receipt_names=ReceiptNames(state / NAMES),
|
|
receipt_reads=ReceiptReads(state / READS),
|
|
settings=settings,
|
|
redirects=redirects,
|
|
watch=Watch(),
|
|
tree=Tree(file=places.tree_file, heartbeat=state / TREE_HEARTBEAT, lock=threading.Lock(), cached=None, stamp=None),
|
|
agent_sessions=state / SNAPSHOT,
|
|
model=model,
|
|
timers=places.timers,
|
|
kept=places.kept,
|
|
council=council,
|
|
history=History(council / queue_live.HISTORY),
|
|
pages=pages,
|
|
public_port=public_port,
|
|
reviews=reviews,
|
|
asks=Ledger(state / "asks.json"),
|
|
decisions=Ledger(state / "decisions.json"),
|
|
messages=messages,
|
|
rule_requests=Ledger(state / "rule-requests.json"),
|
|
uploads=uploads,
|
|
host_state=host_state,
|
|
transcripts=Transcripts(transcripts),
|
|
scripts=scripts,
|
|
templates=environment(templates),
|
|
)
|