feat: matrix/graph data views, wire-generated anomalies, http cookie fix
- auth: session cookie Secure only over https — plain-http LAN access was
silently dropping the cookie, killing WS auth ('connection unstable')
- wire ghost: server-side spike detection on jitter baseline (3σ + 2.5×mean,
20KB/s floor, 20s throttle) — wire anomalies now flood every session with
zero hardware, pushed to clients as {type:'anomaly'} frames
- telemetry cadence 3-5s for live graphs; ambient whispers unchanged
- frontend: MATRIX view (data-rain interleaved with live utterances/anomaly/
telemetry strings), GRAPHS view (scrolling jitter/variance/dns lines +
anomaly markers + counters), BOARD/MATRIX/GRAPHS switcher
- connection banner: 'connecting' is now neutral 'tuning the veil…', only
unstable/closed warns
- db: recreated quantumancy(+_test) as UTF8 (was SQL_ASCII — crashed on
non-ASCII spirit text); README quickstart updated
- i18n: seance.views.* EN/ES
This commit is contained in:
@@ -17,6 +17,7 @@ the wire.
|
||||
import asyncio
|
||||
import contextlib
|
||||
import random
|
||||
import time
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
@@ -36,7 +37,7 @@ from app.models.entity import Entity
|
||||
from app.models.entity_sighting import EntitySighting
|
||||
from app.models.event import Event
|
||||
from app.rate_limit import RateLimiter
|
||||
from app.telemetry import sample_network
|
||||
from app.telemetry import detect_wire_spike, sample_network
|
||||
from app.tts.piper import synthesize_spirit_voice
|
||||
from app.tts.voices import pick_voice
|
||||
|
||||
@@ -71,6 +72,8 @@ class SeanceState:
|
||||
anomalies: list[dict] = field(default_factory=list)
|
||||
history: list[dict] = field(default_factory=list)
|
||||
ambient_task: asyncio.Task | None = None
|
||||
wire_jitter_history: list[float] = field(default_factory=list)
|
||||
last_wire_anomaly_at: float = 0.0
|
||||
|
||||
|
||||
def serialize_entity(entity: Entity) -> dict:
|
||||
@@ -324,16 +327,36 @@ async def _handle_question(state: SeanceState, text: str) -> None:
|
||||
|
||||
|
||||
async def _ambient_loop(state: SeanceState) -> None:
|
||||
"""The Wire Ghost's pulse: telemetry every few seconds, a whisper only
|
||||
when the LLM box has been quiet long enough."""
|
||||
"""The Wire Ghost's pulse: telemetry every few seconds. Spikes in the
|
||||
jitter baseline become first-class anomaly events (driving fragments and
|
||||
the client's data views); quieter ticks may earn an ambient whisper."""
|
||||
try:
|
||||
while True:
|
||||
await asyncio.sleep(random.uniform(6, 10))
|
||||
await asyncio.sleep(random.uniform(3, 5))
|
||||
try:
|
||||
sample = await sample_network(period_s=1.0)
|
||||
except Exception:
|
||||
continue
|
||||
await state.send_queue.put({"type": "telemetry", **sample.as_dict()})
|
||||
|
||||
jitter = sample.jitter_bytes_per_s
|
||||
ratio = detect_wire_spike(state.wire_jitter_history, jitter)
|
||||
state.wire_jitter_history = (state.wire_jitter_history + [jitter])[-60:]
|
||||
|
||||
now = time.monotonic()
|
||||
if ratio is not None and now - state.last_wire_anomaly_at > 20:
|
||||
state.last_wire_anomaly_at = now
|
||||
anomaly = {
|
||||
"source": "wire",
|
||||
"frequency": round(jitter, 1),
|
||||
"magnitude": round(ratio * 10, 1),
|
||||
}
|
||||
# Tell the client first so its matrix/graph views light up,
|
||||
# then run the anomaly through the usual séance pipeline.
|
||||
await state.send_queue.put({"type": "anomaly", **anomaly})
|
||||
await _handle_anomaly(state, anomaly)
|
||||
continue
|
||||
|
||||
if not spirit_service.ambient_ready():
|
||||
continue
|
||||
whisper = await spirit_service.wire_whisper(sample.as_dict(), state.language)
|
||||
|
||||
Reference in New Issue
Block a user