Skip to content

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.

chore: auto-save WIP via Claude stop-hook safety net (2026-07-03 16:18)

Ruben Lütkead0fd645a0cb
diff --git a/jarvis/setup/dependencies.py b/jarvis/setup/dependencies.py
index d3cd1719c1..56dbbeb3b9 100644
--- a/jarvis/setup/dependencies.py
+++ b/jarvis/setup/dependencies.py
@@ -30,6 +30,7 @@ from __future__ import annotations
import logging
import shutil
import subprocess
+import sys
from dataclasses import dataclass
from typing import Final
@@ -242,6 +243,48 @@ def install_npm_package(package: str, *, timeout_s: float = 300.0) -> tuple[bool
return True, (result.stdout or "").strip()[:400] or "install reported success"
+def install_pip_package(package: str, *, timeout_s: float = 600.0) -> tuple[bool, str]:
+ """Best-effort ``<python> -m pip install <package>`` into the RUNNING
+ interpreter. Never raises. Returns ``(ok, message)``.
+
+ Used to pull an opt-in runtime extra from inside the app (e.g.
+ ``faster-whisper`` for the any-phrase local wake path), so a user never has
+ to drop to a shell — the CLAUDE.md §3 "recoverable in-app" contract. Runs
+ against ``sys.executable`` so the package lands in the same environment the
+ app imports from, and passes ``NO_WINDOW_CREATIONFLAGS`` so a ``pythonw.exe``
+ host does not flash a console (AP-1). Cross-platform: ``python -m pip`` is
+ the one install invocation that behaves identically on Windows/macOS/Linux.
+ A frozen/no-pip interpreter fails cleanly with a message instead of raising.
+ """
+ if not sys.executable:
+ return False, "no Python interpreter available to run pip"
+
+ logger.info("install_pip_package: %s -m pip install %s", sys.executable, package)
+ try:
+ result = subprocess.run( # noqa: S603 -- args are controlled, not user input
+ [
+ sys.executable, "-m", "pip", "install",
+ "--disable-pip-version-check", package,
+ ],
+ capture_output=True,
+ text=True,
+ timeout=timeout_s,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
+ except subprocess.TimeoutExpired:
+ return False, f"pip install timed out after {timeout_s:.0f}s"
+ except OSError as exc:
+ return False, f"pip spawn failed: {exc}"
+
+ if result.returncode != 0:
+ # The tail of stderr carries pip's actual reason (resolver conflict,
+ # no matching wheel for the platform, network error).
+ stderr = (result.stderr or "").strip()[-600:]
+ return False, f"pip exited {result.returncode}: {stderr or 'no stderr'}"
+
+ return True, (result.stdout or "").strip()[-400:] or "install reported success"
+
+
def install_claude_cli() -> tuple[bool, DependencyStatus]:
"""Auto-install + re-probe ``claude``. Returns the post-install status."""
ok, message = install_npm_package("@anthropic-ai/claude-code")
@@ -264,4 +307,5 @@ __all__ = [
"check_openclaw",
"install_claude_cli",
"install_npm_package",
+ "install_pip_package",
]
diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.py
index a89f8d3683..46f228d293 100644
--- a/jarvis/ui/web/settings_routes.py
+++ b/jarvis/ui/web/settings_routes.py
@@ -361,6 +361,87 @@ def _local_whisper_available() -> bool:
return importlib.util.find_spec("faster_whisper") is not None
+# --- Local-speech (any-phrase wake) opt-in install --------------------------
+# ``faster-whisper`` powers the ``stt_match`` wake path — the ONLY local way to
+# detect an arbitrary, user-invented wake phrase. It is a torch-FREE opt-in
+# package (ctranslate2 CPU wheels, cross-platform) that the cloud-first base
+# install deliberately omits (CLAUDE.md §3). Historically it was dropped from
+# every extra (2026-05-18, "Groq Whisper API is the new default"), so a fresh
+# install could not use a custom wake word at all and silently degraded to the
+# bundled "Hey Rhasspy" model. This endpoint pulls the package from INSIDE the
+# app so any wake word works everywhere without dropping to a shell — the §3
+# "recoverable in-app" contract. The spec is pinned to the [local-voice] extra
+# in pyproject.toml so the two never drift.
+_LOCAL_SPEECH_PACKAGE = "faster-whisper>=1.0"
+
+_local_speech_install_lock = threading.Lock()
+# state ∈ {"idle", "running", "done", "error"}; message is the last pip detail.
+_local_speech_install: dict[str, str] = {"state": "idle", "message": ""}
+
+
+def _run_local_speech_install() -> None:
+ """Blocking pip install, run on a daemon thread; updates shared state."""
+ import importlib
+
+ from jarvis.setup.dependencies import install_pip_package
+
+ ok, message = install_pip_package(_LOCAL_SPEECH_PACKAGE)
+ # Let this same process's find_spec see the freshly-installed package, so the
+ # status endpoint flips to available without a restart (the wake PIPELINE
+ # still needs a restart to actually use it — the UI says so).
+ importlib.invalidate_caches()
+ with _local_speech_install_lock:
+ _local_speech_install["state"] = "done" if ok else "error"
+ _local_speech_install["message"] = message
+ log.info("local-speech install finished: ok=%s msg=%s", ok, message[:200])
+
+
[email protected]("/wake-word/enable-local-speech")
+async def enable_local_speech(request: Request) -> dict[str, object]:
+ """Install the local-speech pack (faster-whisper) so ANY wake word works.
+
+ Idempotent and non-blocking: returns immediately with a ``state`` the UI
+ polls via the status endpoint. A second call while a run is in flight does
+ not start a duplicate install.
+ """
+ if _local_whisper_available():
+ return {
+ "state": "done",
+ "already": True,
+ "available": True,
+ "message": "Local speech pack already installed.",
+ }
+ with _local_speech_install_lock:
+ if _local_speech_install["state"] == "running":
+ return {
+ "state": "running",
+ "available": False,
+ "message": _local_speech_install["message"],
+ }
+ _local_speech_install["state"] = "running"
+ _local_speech_install["message"] = f"Installing {_LOCAL_SPEECH_PACKAGE}"
+ threading.Thread(
+ target=_run_local_speech_install,
+ name="local-speech-install",
+ daemon=True,
+ ).start()
+ return {"state": "running", "available": False, "message": "Install started."}
+
+
[email protected]("/wake-word/enable-local-speech/status")
+async def enable_local_speech_status() -> dict[str, object]:
+ """Report the local-speech install progress + whether the pack is present."""
+ available = _local_whisper_available()
+ with _local_speech_install_lock:
+ state = _local_speech_install["state"]
+ message = _local_speech_install["message"]
+ # Present but this process never ran the installer (e.g. installed manually,
+ # or a prior run before a restart) → report done so the UI is truthful.
+ if available and state in ("idle", "running"):
+ state = "done"
+ return {"state": state, "message": message, "available": available}
+
+
@router.get("/wake-word")
async def get_wake_word(request: Request) -> dict[str, object]:
from jarvis.core.config import WakeWordConfig