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.

feat(setup): jarvis --prefetch downloads all voice models the config needs

Ruben Lütkea57fa43c66d1
diff --git a/jarvis/__main__.py b/jarvis/__main__.py
index 247ad98956..ccd170e1e4 100644
--- a/jarvis/__main__.py
+++ b/jarvis/__main__.py
@@ -65,6 +65,12 @@ def _build_parser() -> argparse.ArgumentParser:
dest="reset_onboarding",
help="Clear onboarding markers so the first-run guide shows again.",
)
+ parser.add_argument(
+ "--prefetch",
+ action="store_true",
+ help="Download all voice models the current config needs, then exit. "
+ "Used by the installer so the first launch has nothing left to fetch.",
+ )
parser.add_argument(
"--uninstall",
action="store_true",
@@ -484,6 +490,10 @@ def main(argv: list[str] | None = None) -> int:
return _cmd_uninstall(args)
if args.reset_onboarding:
return _cmd_reset_onboarding()
+ if args.prefetch:
+ from jarvis.setup.prefetch import prefetch_all
+
+ return prefetch_all()
if args.command == "serve":
# Headless web UI — the cloud-first path (no desktop/tray). Delegates to
# the web launcher so `jarvis serve` == `python -m jarvis.ui.web.launcher --headless`.
diff --git a/jarvis/setup/prefetch.py b/jarvis/setup/prefetch.py
new file mode 100644
index 0000000000..98f8c778a7
--- /dev/null
+++ b/jarvis/setup/prefetch.py
@@ -0,0 +1,103 @@
+"""Download-everything prefetch shared by the installer and the app.
+
+Called by ``python -m jarvis --prefetch`` (which ``install/installer.py``
+invokes) so that when the install command finishes, the first launch has
+nothing left to download. Resolution reuses the SAME config defaults the
+runtime reads, so the installer and the app can never disagree about which
+models are needed.
+
+Every step is best-effort: a failed download prints an honest note and the
+runtime's lazy download remains the safety net — a flaky mirror must never
+brick an install (CLAUDE.md section 3). Works headless: no audio device,
+GPU, or keyring is touched, only the on-disk model caches.
+"""
+from __future__ import annotations
+
+import importlib.util
+from collections.abc import Callable
+from typing import Any
+
+
+def _wakeword_bundle_present() -> bool:
+ """The always-on neural wake models ship in-repo (jarvis/assets/wakeword)."""
+ try:
+ import jarvis.assets
+
+ return jarvis.assets.bundled_wakeword_models() is not None
+ except Exception: # noqa: BLE001 — a probe must never crash the prefetch
+ return False
+
+
+def _faster_whisper_available() -> bool:
+ """True when the optional local-Whisper stack is installed."""
+ return importlib.util.find_spec("faster_whisper") is not None
+
+
+def _load_config() -> Any:
+ """Seam for tests — the heavy config import stays out of module import."""
+ from jarvis.core.config import load_config
+
+ return load_config()
+
+
+def _whisper_models_needed() -> list[str]:
+ """The faster-whisper model names the CURRENT config would load at runtime.
+
+ Mirrors ``jarvis/plugins/stt``: the wake-match model always
+ (``stt.wake_model``, default ``base``); the utterance model only when the
+ local provider is selected. Order = download order (small first).
+ """
+ cfg = _load_config()
+ models = [cfg.stt.wake_model]
+ if cfg.stt.provider == "faster-whisper" and cfg.stt.model not in models:
+ models.append(cfg.stt.model)
+ return models
+
+
+def _download_whisper_model(name: str) -> None:
+ """Fetch one faster-whisper model into the standard HuggingFace cache —
+ the exact cache ``WhisperModel(name)`` resolves at runtime."""
+ from faster_whisper.utils import download_model
+
+ download_model(name)
+
+
+def prefetch_all(echo: Callable[[str], None] = print) -> int:
+ """Prefetch every artifact the default voice path needs. 0 = complete.
+
+ Returns 1 when at least one download failed — callers keep going (the
+ runtime lazy-download remains the safety net), the exit code just keeps
+ the installer's summary honest.
+ """
+ failed = False
+
+ if _wakeword_bundle_present():
+ echo("wake-word models: bundled with the app - nothing to download")
+ else:
+ echo(
+ "wake-word models: bundle missing - openWakeWord will auto-download "
+ "on first use"
+ )
+
+ if not _faster_whisper_available():
+ echo(
+ "local Whisper models: skipped (faster-whisper not installed - "
+ "cloud STT is the default)"
+ )
+ return 0
+
+ for name in _whisper_models_needed():
+ echo(f"downloading speech model '{name}' (one-time, cached for every later start)")
+ try:
+ _download_whisper_model(name)
+ echo(f"speech model '{name}': ready")
+ except Exception as exc: # noqa: BLE001 — honest note, never fatal
+ failed = True
+ echo(
+ f"speech model '{name}' could not be downloaded ({exc}); "
+ "it will download on first launch instead"
+ )
+ return 1 if failed else 0
+
+
+__all__ = ["prefetch_all"]
diff --git a/tests/unit/setup/test_prefetch.py b/tests/unit/setup/test_prefetch.py
new file mode 100644
index 0000000000..6780791cf0
--- /dev/null
+++ b/tests/unit/setup/test_prefetch.py
@@ -0,0 +1,65 @@
+"""prefetch_all: resolves the same models the runtime uses; degrades cleanly."""
+from jarvis.setup import prefetch
+
+
+def test_reports_bundled_wakeword(monkeypatch) -> None:
+ lines: list[str] = []
+ monkeypatch.setattr(prefetch, "_wakeword_bundle_present", lambda: True)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: False)
+ rc = prefetch.prefetch_all(echo=lines.append)
+ assert rc == 0
+ assert any("wake-word models" in line for line in lines)
+ assert any("skipped" in line.lower() for line in lines) # whisper skipped
+
+
+def test_downloads_wake_model_when_faster_whisper_present(monkeypatch) -> None:
+ downloaded: list[str] = []
+ monkeypatch.setattr(prefetch, "_wakeword_bundle_present", lambda: True)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: True)
+ monkeypatch.setattr(prefetch, "_download_whisper_model", downloaded.append)
+ monkeypatch.setattr(prefetch, "_whisper_models_needed", lambda: ["base"])
+ rc = prefetch.prefetch_all(echo=lambda _line: None)
+ assert rc == 0
+ assert downloaded == ["base"]
+
+
+def test_download_failure_is_nonfatal(monkeypatch) -> None:
+ def _boom(_name: str) -> None:
+ raise OSError("mirror down")
+
+ monkeypatch.setattr(prefetch, "_wakeword_bundle_present", lambda: True)
+ monkeypatch.setattr(prefetch, "_faster_whisper_available", lambda: True)
+ monkeypatch.setattr(prefetch, "_download_whisper_model", _boom)
+ monkeypatch.setattr(prefetch, "_whisper_models_needed", lambda: ["base"])
+ lines: list[str] = []
+ rc = prefetch.prefetch_all(echo=lines.append)
+ assert rc == 1
+ assert any("first launch" in line for line in lines) # honest fallback note
+
+
+def test_whisper_models_needed_includes_utterance_model_for_local_provider(
+ monkeypatch,
+) -> None:
+ class _Stt:
+ wake_model = "base"
+ provider = "faster-whisper"
+ model = "large-v3-turbo"
+
+ class _Cfg:
+ stt = _Stt()
+
+ monkeypatch.setattr(prefetch, "_load_config", lambda: _Cfg())
+ assert prefetch._whisper_models_needed() == ["base", "large-v3-turbo"]
+
+
+def test_whisper_models_needed_wake_only_for_cloud_provider(monkeypatch) -> None:
+ class _Stt:
+ wake_model = "base"
+ provider = "groq-api"
+ model = "large-v3-turbo"
+
+ class _Cfg:
+ stt = _Stt()
+
+ monkeypatch.setattr(prefetch, "_load_config", lambda: _Cfg())
+ assert prefetch._whisper_models_needed() == ["base"]