Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
chore: auto-save WIP via Claude stop-hook safety net (2026-07-01 13:46)
Ruben Lütke7b2794b9772e
diff --git a/jarvis/plugins/wake/openwakeword_provider.py b/jarvis/plugins/wake/openwakeword_provider.pyindex 915e2027b6..74bc015ed9 100644--- a/jarvis/plugins/wake/openwakeword_provider.py+++ b/jarvis/plugins/wake/openwakeword_provider.py@@ -15,11 +15,11 @@ from __future__ import annotationsimport asyncioimport loggingimport time-from collections import dequefrom collections.abc import AsyncIteratorimport numpy as np+from jarvis.audio.wake_normalizer import AdaptiveWakeNormalizerfrom jarvis.core.protocols import AudioChunklog = logging.getLogger("jarvis.wake")@@ -79,70 +79,57 @@ PRODUCTION_WAKE_THRESHOLD = 0.15class WakeGainNormalizer:- """Amplify-only, noise-gated, capped streaming AGC for the OWW wake path.-- Root cause of "the wake word only triggers when I shout" (2026-06-28): in the- default lightweight config the fast openWakeWord detector is the SOLE wake- path (the ``RollingWhisperWake`` low-volume backstop is a power-user opt-in- behind ``cfg.trigger.heavy_local_whisper``), and it fed RAW int16 frames into- the neural model. openWakeWord's activation score scales with input level, so- on this project's documented quiet-mic hardware (normal-speech rms ~0.01-0.02)- a genuine "Hey Jarvis" peaks at ~0.10-0.14 — just *below* the pinned 0.15- threshold. Only shouting lifted the level over the bar.-- The threshold cannot move (``test_wake_threshold`` pins the BUG-009 floor), so- this brings the SAME peak normalization the ``RollingWhisperWake`` backstop- already uses to the default OWW path. Per-frame behaviour:-- * the gain is derived from a rolling peak over the last ``window_s`` of audio- (not the single frame) so it stays stable across the wake phrase and the- intra-phrase envelope the model relies on is preserved;- * it is AMPLIFY-ONLY — an already-loud wake is never turned down, so the- genuine-peak band the threshold was calibrated on never regresses;- * it is gated by ``noise_floor_peak`` — digital silence / idle hiss below the- floor is returned UNCHANGED so the AGC can never manufacture an ambient- false-fire band (the AGC-level analogue of the BUG-009 guard);- * the gain is capped at ``max_gain_db`` so a near-silent floor cannot be blown- up to full scale.-- Pure mechanism — no I/O, no model. ``reset()`` clears the rolling envelope so- a stale loud burst does not suppress the gain on the next quiet utterance.+ """Amplify-only, adaptive-floor, capped streaming AGC for the OWW wake path.++ Thin adapter over the shared :class:`jarvis.audio.wake_normalizer.+ AdaptiveWakeNormalizer` so the default openWakeWord path and the+ ``RollingWhisperWake`` backstop share ONE input-normalization mechanism+ (mission 2026-06-30). It exists as its own name for the OWW-specific defaults+ (frame size 1280) and the existing call sites/tests.++ Root cause of "the wake word only triggers when I shout" (2026-06-28): the+ fast openWakeWord detector fed RAW int16 frames into the neural model, whose+ activation score scales with input level, so on a quiet mic a genuine+ "Hey Jarvis" under-scored the pinned 0.15 threshold and only a shout crossed+ it. The 2026-06-28 fix added peak normalization but gated it on a FIXED+ ``noise_floor_peak=0.02`` — a genuinely quiet wake between that floor and true+ silence still got zero gain. This now uses an ADAPTIVE floor (mission+ 2026-06-30): on a quiet mic the floor settles to the real ambient level, so a+ quiet wake rises above it and is amplified, while flat silence / steady+ sub-floor hiss is still left unchanged. The 0.15 threshold and the+ amplify-only + sub-floor guards are unchanged, so quiet wakes are lifted+ without widening the ambient false-fire band."""def __init__(self,target_peak_dbfs: float = -3.0,- max_gain_db: float = 20.0,- noise_floor_peak: float = 0.02,+ max_gain_db: float = 30.0,+ # Now the ADAPTIVE floor's STARTING value (was a fixed hard gate). Lower+ # than the legacy 0.02 so a quiet-but-real wake is above the fresh-session+ # speech threshold; it adapts further down on a quiet mic.+ noise_floor_peak: float = 0.006,window_s: float = 1.5,sample_rate: int = OWW_SAMPLE_RATE,frame_samples: int = OWW_FRAME_SAMPLES,) -> None:- self._target_peak = float(10.0 ** (target_peak_dbfs / 20.0)) # -3 dBFS ≈ 0.707- self._max_gain = float(10.0 ** (max_gain_db / 20.0)) # 20 dB = 10x- self._noise_floor = float(noise_floor_peak)- frame_s = frame_samples / sample_rate # 80 ms- self._window_frames = max(1, int(round(window_s / frame_s)))- self._recent_peaks: deque[float] = deque(maxlen=self._window_frames)+ self._norm = AdaptiveWakeNormalizer(+ target_peak_dbfs=target_peak_dbfs,+ max_gain_db=max_gain_db,+ floor_start=noise_floor_peak,+ window_s=window_s,+ sample_rate=sample_rate,+ frame_samples=frame_samples,+ )def reset(self) -> None:"""Forget the rolling envelope (called on detector stop / re-arm)."""- self._recent_peaks.clear()+ self._norm.reset()def process(self, frame: np.ndarray) -> np.ndarray:"""Return ``frame`` (int16) amplified toward the target peak, or- unchanged when below the noise floor / already loud enough."""- f32 = frame.astype(np.float32) / 32768.0- frame_peak = float(np.max(np.abs(f32))) if f32.size else 0.0- self._recent_peaks.append(frame_peak)- rolling_peak = max(self._recent_peaks) if self._recent_peaks else frame_peak- if rolling_peak < self._noise_floor:- return frame # silence / sub-floor hiss — leave it alone (gain 1.0)- gain = min(self._target_peak / rolling_peak, self._max_gain)- if gain <= 1.0:- return frame # already loud enough — amplify-only, never attenuate- boosted = np.clip(f32 * gain, -1.0, 1.0)- return (boosted * 32767.0).astype(np.int16)+ unchanged when below the adaptive floor / already loud enough."""+ return self._norm.process(frame)class OpenWakeWordProvider:@@ -326,9 +313,29 @@ class OpenWakeWordProvider:# offline-fähig beim ersten Start.self._model = Model(**self._model_kwargs())+ def _warmup_model(self) -> None:+ """Run ONE throwaway inference so the first real wake frame is not cold.++ ``_ensure_model`` only LOADS the ONNX graph; the first ``predict`` still+ pays the onnxruntime graph-init / melspec+embedding warm cost, and that+ used to land on the user's first "Hey Jarvis" (a swallowed wake + a+ visible delay before the bar — mission 2026-06-30 "~0.5 s delay"). Priming+ it here moves the cost off the wake path. Fail-closed: a warm-up error+ (e.g. a partially-loaded model) degrades to a no-op, never breaks boot.+ """+ model = self._model+ if model is None:+ return+ try:+ dummy = np.zeros(OWW_FRAME_SAMPLES, dtype=np.int16)+ model.predict(dummy)+ except Exception as exc: # noqa: BLE001 — warm-up must never break boot+ log.debug("OWW warm-up inference skipped: %s", exc)+async def start(self) -> None:- """Pre-load Model — spart Latenz beim ersten Audio-Frame."""+ """Pre-load AND warm the model — spart Kaltstart-Latenz beim ersten Frame."""await asyncio.to_thread(self._ensure_model)+ await asyncio.to_thread(self._warmup_model)async def stop(self) -> None:self._model = Nonediff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.pyindex ea0d85b499..3967784d7f 100644--- a/jarvis/speech/rolling_whisper_wake.py+++ b/jarvis/speech/rolling_whisper_wake.py@@ -128,7 +128,11 @@ class RollingWhisperWake:# ``.search(text)`` returning an object with ``.group(0)``.pattern: Any = DEFAULT_PATTERN,window_s: float = 1.8, # kürzer = weniger Stille-Anteil = höhere avg-RMS- poll_interval_s: float = 0.3, # schnellere Wake-Reaktion+ # 2026-06-30 ("~0.5 s delay"): 0.3 -> 0.2 so a spoken custom wake reaches+ # the bar within one snappier poll. The gates skip silence cheaply, so the+ # extra polls only transcribe when a window actually passes the audio+ # gates — negligible extra cost, a visibly faster reaction.+ poll_interval_s: float = 0.2,cooldown_s: float = 5.0, # längerer Cooldown → weniger Over-Triggeringsample_rate: int = 16_000,# 2026-04-22 (3. Iteration): RMS/Peak-Gates zurueck auf niedrig. Die@@ -143,12 +147,14 @@ class RollingWhisperWake:# 2026-06-29 (mission "wake only triggers when shouting"): the raw peak# gate runs BEFORE transcription on a quiet mic, so a normal-volume# custom wake ("Hey Nico") whose window peaks below the legacy 0.02 was- # dropped silently — only a shout cleared it. Lowered to 0.012 so a- # genuinely quiet wake reaches Whisper; the ``min_rms`` silence guard- # (pinned >= 0.003 by test_wake_hallucination_guard) still rejects digital- # silence/idle hiss, and the confidence + no_speech + pattern gates below- # are the real false-positive guards on whatever does reach Whisper.- min_peak: float = 0.012,+ # dropped silently — only a shout cleared it. 2026-06-30: lowered further+ # 0.012 -> 0.008 because a downloader on an even quieter built-in laptop+ # mic still peaked below 0.012. 0.008 still sits well above the ~0.0046+ # idle-hiss level (pinned gated by test_stats_count_a_sub_peak_window),+ # and the ``min_rms`` silence guard (pinned >= 0.003) plus the confidence ++ # no_speech + pattern gates remain the real false-positive guards on+ # whatever does reach Whisper.+ min_peak: float = 0.008,save_debug_wavs: bool = False, # Watchdog-Modus — OFF in prod (env opt-in)heartbeat_interval_s: float = 3.0,# Peak-Normalization statt fester Gain: misst Audio-Peak, wendetdiff --git a/scripts/voice_style_eval.py b/scripts/voice_style_eval.pyindex d81c9d6c87..21748c3079 100644--- a/scripts/voice_style_eval.py+++ b/scripts/voice_style_eval.py@@ -159,7 +159,7 @@ async def run() -> int:if args.persona_file:from jarvis.brain.persona_loader import _extract_fence_after_marker- file_text = Path(args.persona_file).read_text(encoding="utf-8")+ file_text = Path(args.persona_file).read_text(encoding="utf-8") # noqa: ASYNC240 — one-shot script setup read# A full JARVIS_PERSONA.md carries the prompt inside the fence after the# "## System-Prompt" marker; a bare prompt file is used verbatim.override_text = _extract_fence_after_marker(file_text) or file_textdiff --git a/tests/unit/brain/test_output_filter.py b/tests/unit/brain/test_output_filter.pyindex 4242833d68..037dbedef8 100644--- a/tests/unit/brain/test_output_filter.py+++ b/tests/unit/brain/test_output_filter.py@@ -159,7 +159,7 @@ def test_self_reference_is_removed() -> None:("Got it. I am noting that down. The capital is Rome.", "en","noting", "rome"),("Sure. Let me look at the last transcription. It is 25 degrees.", "en",- "transcription", "25 degrees"),+ "transcription", "twenty-five degrees"),("Entendido, tomo nota. La capital es Roma.", "es", "tomo nota", "roma"),],)@@ -367,10 +367,11 @@ def test_ascii_double_hyphen_dash_aside_becomes_comma() -> None:def test_ascii_hyphen_compound_and_range_survive_double_hyphen_filter() -> None:"""No false positive: a compound ('T-Shirt') or numeric range ('20-30') has- no surrounding spaces and must survive the double-hyphen scrub."""+ no surrounding spaces and must survive the double-hyphen scrub. The range+ endpoints are spelled out for speech, but the joining hyphen is preserved."""result = scrub_for_voice("Dein T-Shirt kostet 20-30 Euro.")assert "T-Shirt" in result.cleaned- assert "20-30" in result.cleaned+ assert "zwanzig-dreißig" in result.cleaneddef test_fallback_used_true_only_for_stacktrace() -> None:@@ -562,8 +563,8 @@ def test_generic_tool_call_tags_are_removed() -> None:assert "<tool_response>" not in result.cleanedassert "</tool_response>" not in result.cleanedassert "removed_tool_json" in result.actions- # Kerninhalt bleibt- assert "09:17" in result.cleaned+ # Kerninhalt bleibt (die Uhrzeit wird fuer die Sprachausgabe ausgeschrieben)+ assert "neun Uhr siebzehn" in result.cleaneddef test_base64_image_block_is_removed() -> None:@@ -771,7 +772,7 @@ def test_http_url_is_stripped_from_voice() -> None:result = scrub_for_voice(text)assert "http" not in result.cleaned.lower()assert "km.bayern.de" not in result.cleaned.lower()- assert "190 minuten" in result.cleaned.lower()+ assert "einhundertneunzig minuten" in result.cleaned.lower()assert "removed_source_artifacts" in result.actions@@ -782,7 +783,7 @@ def test_serp_more_results_footer_is_stripped() -> None:low = result.cleaned.lower()assert "gutefrage" not in lowassert "weitere ergebnisse" not in low- assert "note 2" in low+ assert "note zwei" in lowassert "removed_source_artifacts" in result.actions@@ -792,7 +793,7 @@ def test_bare_www_domain_is_stripped_from_voice() -> None:result = scrub_for_voice(text)assert "www." not in result.cleaned.lower()assert "realschule.bayern.de" not in result.cleaned.lower()- assert "190 minuten" in result.cleaned.lower()+ assert "einhundertneunzig minuten" in result.cleaned.lower()assert "viel erfolg" in result.cleaned.lower()diff --git a/tests/unit/speech/test_wake_latency.py b/tests/unit/speech/test_wake_latency.pyindex 4582c7df56..bb34fb016a 100644--- a/tests/unit/speech/test_wake_latency.py+++ b/tests/unit/speech/test_wake_latency.py@@ -14,8 +14,18 @@ regress the custom-wake reaction time back toward half a second."""from __future__ import annotations+import time+from types import SimpleNamespace++from jarvis.core.events import WakeCandidateDetected, WakeWordDetectedfrom jarvis.plugins.stt.fwhisper import FasterWhisperProviderfrom jarvis.speech.rolling_whisper_wake import RollingWhisperWake+from ui.orb.bus_bridge import OrbBusBridge++# Instrumented ceiling for the reveal EVENT path (wake detected -> bar shown).+# The bar window itself is pre-created and merely deiconified, so the reveal is+# fast; this budget guards the event/handler path from a future regression.+_REVEAL_BUDGET_MS = 100.0def test_rolling_whisper_poll_interval_is_snappy() -> None:@@ -24,3 +34,55 @@ def test_rolling_whisper_poll_interval_is_snappy() -> None:"the custom-wake detector must poll at least every 200 ms so a spoken ""wake reaches the bar quickly")+++class _StampingOrb:+ """Records the monotonic time and mode of the show() that reveals the bar."""++ def __init__(self) -> None:+ self.show_monotonic: float | None = None+ self.shown_mode: str | None = None+ self.animations: list[str] = []++ def show(self, mode: str = "idle") -> None:+ self.show_monotonic = time.perf_counter()+ self.shown_mode = mode++ def hide(self) -> None: # pragma: no cover - not exercised here+ pass++ def play_animation(self, name: str) -> None:+ self.animations.append(name)+++async def test_wake_word_to_bar_reveal_event_path_is_under_budget() -> None:+ """Authoritative wake event -> the bar's show() call, instrumented in ms."""+ orb = _StampingOrb()+ bridge = OrbBusBridge(bus=SimpleNamespace(), orb=orb)+ t0 = time.perf_counter()+ await bridge._on_wake_word_detected( # noqa: SLF001+ WakeWordDetected(source_layer="speech", keyword="hey_nico")+ )+ assert orb.shown_mode == "listen", "wake must reveal the listening bar"+ assert orb.show_monotonic is not None+ latency_ms = (orb.show_monotonic - t0) * 1000.0+ assert latency_ms <= _REVEAL_BUDGET_MS, (+ f"reveal event path took {latency_ms:.2f} ms (budget {_REVEAL_BUDGET_MS} ms)"+ )+++async def test_optimistic_candidate_reveal_event_path_is_under_budget() -> None:+ """The optimistic OWW candidate pops the bar BEFORE the STT verify — the+ fast path. Instrument it too so it stays instant."""+ orb = _StampingOrb()+ bridge = OrbBusBridge(bus=SimpleNamespace(), orb=orb)+ t0 = time.perf_counter()+ await bridge._on_wake_candidate( # noqa: SLF001+ WakeCandidateDetected(source_layer="speech", active=True)+ )+ assert orb.shown_mode == "listen"+ assert orb.show_monotonic is not None+ latency_ms = (orb.show_monotonic - t0) * 1000.0+ assert latency_ms <= _REVEAL_BUDGET_MS, (+ f"candidate reveal took {latency_ms:.2f} ms (budget {_REVEAL_BUDGET_MS} ms)"+ )