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-10 19:04)
Ruben Lütkea787f3597e4a
diff --git a/jarvis/core/config.py b/jarvis/core/config.pyindex bae444031e..0a82eabd98 100644--- a/jarvis/core/config.py+++ b/jarvis/core/config.py@@ -2453,6 +2453,24 @@ def load_config(# installed ONLY when the current backend is the no-op fail.Keyring)._KEYRING_BACKEND_READY: bool = False_FILE_BACKEND_ACTIVE: bool = False+_SECRET_REVISION_LOCK = threading.Lock()+_SECRET_REVISIONS: dict[str, int] = {}+++def secret_revision(key: str) -> int:+ """Return the in-process revision for one credential slot.++ Provider instances use this cheap counter to refresh a replaced credential+ without performing a keyring read on every request. External credential-store+ edits still require a process restart; in-app writes increment the counter.+ """+ with _SECRET_REVISION_LOCK:+ return _SECRET_REVISIONS.get(key, 0)+++def _mark_secret_changed(key: str) -> None:+ with _SECRET_REVISION_LOCK:+ _SECRET_REVISIONS[key] = _SECRET_REVISIONS.get(key, 0) + 1# Serializes _FileCredStore's load-mutate-save cycle so two in-process@@ -2803,6 +2821,7 @@ def set_secret(key: str, value: str) -> bool:store.delete(KEYRING_SERVICE, key)except Exception: # noqa: BLE001, S110 — secure write already succeededpass+ _mark_secret_changed(key)return Trueexcept Exception as exc: # noqa: BLE001# A reachable-but-unusable OS keyring (e.g. a locked Linux Secret Service)@@ -2814,6 +2833,7 @@ def set_secret(key: str, value: str) -> bool:import keyringkeyring.set_password(KEYRING_SERVICE, key, value)+ _mark_secret_changed(key)return Trueexcept Exception: # noqa: BLE001return False@@ -2867,6 +2887,8 @@ def delete_secret(key: str) -> bool:file_ok = Trueexcept Exception: # noqa: BLE001, S110pass+ if keyring_ok or file_ok:+ _mark_secret_changed(key)return keyring_ok and file_okdiff --git a/jarvis/plugins/stt/openrouter_stt.py b/jarvis/plugins/stt/openrouter_stt.pyindex 8ac97a593e..fd3d0a0b66 100644--- a/jarvis/plugins/stt/openrouter_stt.py+++ b/jarvis/plugins/stt/openrouter_stt.py@@ -136,6 +136,7 @@ class OpenRouterSTT:self._client = http_clientself._owns_client = http_client is Noneself._endpoint_url: str | None = None+ self._resolved_secret_revision = -1# ------------------------------------------------------------------# Public API (STTProvider contract + pipeline compat shims)@@ -226,17 +227,28 @@ class OpenRouterSTT:OpenRouter credential is configured, so the factory / pipeline can fallback to the local floor (AP-22)."""+ if self._api_key_is_explicit and self._endpoint_url is not None and self._api_key:+ return self._endpoint_url+base = self._base_url or DEFAULT_BASE_URLif not self._api_key_is_explicit:# Import here (not at module top) to keep the plugin ``jarvis.*``-free# at import time; the entry-point loader tolerates a lazy internal use.from jarvis.core import config as _cfg+ current_revision = _cfg.secret_revision("openrouter_api_key")+ if (+ self._endpoint_url is not None+ and self._api_key+ and self._resolved_secret_revision == current_revision+ ):+ return self._endpoint_urlep = _cfg.resolve_provider_endpoint("openrouter", vendor_default_base_url=DEFAULT_BASE_URL)self._api_key = ep.credential or Nonebase = ep.base_url or DEFAULT_BASE_URL+ self._resolved_secret_revision = current_revisionif not self._api_key:raise RuntimeError(diff --git a/jarvis/plugins/tts/openrouter_tts.py b/jarvis/plugins/tts/openrouter_tts.pyindex b90651c7ee..133fa68231 100644--- a/jarvis/plugins/tts/openrouter_tts.py+++ b/jarvis/plugins/tts/openrouter_tts.py@@ -103,6 +103,7 @@ class OpenRouterTTS:# caller-owned and is never replaced here.self._resolved_credential: str | None = Noneself._resolved_base_url: str | None = None+ self._resolved_secret_revision = -1# Overridden by _ensure_client with the resolved endpoint; a default here# lets a directly-injected client (tests / warm reuse) synthesise without# re-resolving the key.@@ -125,6 +126,12 @@ class OpenRouterTTS:# credential marker and stays caller-owned.if self._client is not None and self._resolved_credential is None:return+ current_revision = cfg.secret_revision("openrouter_api_key")+ if (+ self._client is not None+ and self._resolved_secret_revision == current_revision+ ):+ returnep = cfg.resolve_provider_endpoint("openrouter", vendor_default_base_url=BASE_URL)@@ -142,6 +149,7 @@ class OpenRouterTTS:and self._resolved_credential == ep.credentialand self._resolved_base_url == resolved_base_url):+ self._resolved_secret_revision = current_revisionreturnold_client = self._client@@ -158,6 +166,7 @@ class OpenRouterTTS:)self._resolved_credential = ep.credentialself._resolved_base_url = resolved_base_url+ self._resolved_secret_revision = current_revisionif old_client is not None:try:await old_client.aclose()@@ -173,6 +182,7 @@ class OpenRouterTTS:self._client = Noneself._resolved_credential = Noneself._resolved_base_url = None+ self._resolved_secret_revision = -1# ------------------------------------------------------------------# Voice resolutiondiff --git a/tests/unit/brain/test_model_catalog_optional_auth.py b/tests/unit/brain/test_model_catalog_optional_auth.pynew file mode 100644index 0000000000..d69f809385--- /dev/null+++ b/tests/unit/brain/test_model_catalog_optional_auth.py@@ -0,0 +1,75 @@+"""Public model catalogs stay available when an optional key is stale."""+from __future__ import annotations++from typing import Any++import httpx+import pytest++from jarvis.brain import model_catalog as catalog_module+from jarvis.brain.model_catalog import ModelCatalog+++class _SequenceClient:+ def __init__(self, responses: list[httpx.Response]) -> None:+ self.responses = list(responses)+ self.calls: list[dict[str, Any]] = []++ async def __aenter__(self) -> _SequenceClient:+ return self++ async def __aexit__(self, *_exc: object) -> bool:+ return False++ async def get(+ self,+ url: str,+ *,+ headers: dict[str, str] | None = None,+ params: dict[str, str] | None = None,+ ) -> httpx.Response:+ self.calls.append({"url": url, "headers": dict(headers or {}), "params": params})+ return self.responses.pop(0)+++def _response(status: int, payload: dict[str, Any]) -> httpx.Response:+ request = httpx.Request("GET", "https://catalog.example/models")+ return httpx.Response(status, request=request, json=payload)+++async def test_optional_bearer_retries_public_catalog_anonymously_after_401(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path,+) -> None:+ client = _SequenceClient([+ _response(401, {"error": {"message": "invalid key"}}),+ _response(200, {"data": [{"id": "openai/gpt-5.5", "name": "GPT-5.5"}]}),+ ])+ monkeypatch.setattr(catalog_module.cfg, "get_provider_secret", lambda _provider: "stale")+ catalog = ModelCatalog(+ cache_path=tmp_path / "catalog.json", http_client_factory=lambda: client+ )++ models = await catalog._fetch_raw("openrouter")++ assert [model.id for model in models] == ["openai/gpt-5.5"]+ assert client.calls[0]["headers"]["Authorization"] == "Bearer stale"+ assert "Authorization" not in client.calls[1]["headers"]+++async def test_required_bearer_does_not_retry_authentication_failure_anonymously(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path,+) -> None:+ client = _SequenceClient([_response(401, {"error": {"message": "invalid key"}})])+ monkeypatch.setattr(catalog_module.cfg, "get_provider_secret", lambda _provider: "stale")+ catalog = ModelCatalog(+ cache_path=tmp_path / "catalog.json", http_client_factory=lambda: client+ )++ with pytest.raises(httpx.HTTPStatusError):+ await catalog._fetch_raw("openai")++ assert len(client.calls) == 1diff --git a/tests/unit/brain/test_openrouter_catalog_surfaces.py b/tests/unit/brain/test_openrouter_catalog_surfaces.pynew file mode 100644index 0000000000..67a049b745--- /dev/null+++ b/tests/unit/brain/test_openrouter_catalog_surfaces.py@@ -0,0 +1,38 @@+"""The shared OpenRouter credential exposes every selectable app surface."""+from __future__ import annotations++import pytest++from jarvis.brain.model_catalog import ModelCatalog, catalog_spec+from jarvis.ui.web.provider_spec import get_spec++[email protected]("provider_id", ["openrouter", "openrouter-tts", "openrouter-stt"])+def test_every_openrouter_surface_uses_the_shared_credential(provider_id: str) -> None:+ provider = get_spec(provider_id)+ assert provider is not None+ assert provider.secret_keys == ("openrouter_api_key",)+++def test_every_openrouter_surface_has_a_model_catalog() -> None:+ brain = catalog_spec("openrouter")+ tts = catalog_spec("openrouter-tts")+ stt = catalog_spec("openrouter-stt")++ assert brain is not None and brain.tier == "brain" and brain.live is True+ assert tts is not None and tts.tier == "tts" and tts.selects == "model"+ assert stt is not None and stt.tier == "stt" and stt.selects == "model"+ assert brain.curated+ assert tts.curated+ assert stt.curated+++async def test_openrouter_voice_catalogs_are_available_without_a_network_call(tmp_path) -> None:+ catalog = ModelCatalog(cache_path=tmp_path / "catalog.json")++ tts = await catalog.list_models("openrouter-tts")+ stt = await catalog.list_models("openrouter-stt")++ assert tts.source == "curated" and tts.models+ assert stt.source == "curated" and stt.modelsdiff --git a/tests/unit/core/test_keyring_backend_recovery.py b/tests/unit/core/test_keyring_backend_recovery.pyindex 8ce5674c3e..28c2692f86 100644--- a/tests/unit/core/test_keyring_backend_recovery.py+++ b/tests/unit/core/test_keyring_backend_recovery.py@@ -64,6 +64,7 @@ def test_explicit_save_restores_platform_backend_and_removes_stale_fallback(monkeypatch.setattr(keyring.core, "init_backend", _restore_platform)+ revision_before = cfg.secret_revision("openrouter_api_key")assert cfg.set_secret("openrouter_api_key", "new-file-value") is Trueassert (platform_backend.get_password(cfg.KEYRING_SERVICE, "openrouter_api_key")@@ -71,6 +72,7 @@ def test_explicit_save_restores_platform_backend_and_removes_stale_fallback()assert store.get(cfg.KEYRING_SERVICE, "openrouter_api_key") is Noneassert cfg._FILE_BACKEND_ACTIVE is False+ assert cfg.secret_revision("openrouter_api_key") == revision_before + 1def test_explicit_save_keeps_file_backend_when_platform_store_is_still_unusable(diff --git a/tests/unit/plugins/stt/test_openrouter_stt.py b/tests/unit/plugins/stt/test_openrouter_stt.pyindex 7db3a6379d..2fd553b710 100644--- a/tests/unit/plugins/stt/test_openrouter_stt.py+++ b/tests/unit/plugins/stt/test_openrouter_stt.py@@ -278,6 +278,42 @@ async def test_key_is_resolved_lazily_from_config(assert captured["url"] == "https://proxy.example/v1/audio/transcriptions"+async def test_shared_key_replacement_applies_to_the_next_transcription(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A config-resolved key is refreshed without rebuilding the STT instance."""+ from jarvis.core import config as cfg++ state: dict[str, object] = {"key": "old-key", "revision": 0}+ seen_auth: list[str] = []+ monkeypatch.setattr(+ cfg,+ "resolve_provider_endpoint",+ lambda *a, **k: SimpleNamespace(+ credential=state["key"],+ base_url="https://openrouter.ai/api/v1",+ via_proxy=False,+ ),+ )+ monkeypatch.setattr(cfg, "secret_revision", lambda _key: state["revision"])++ async def handler(request: httpx.Request) -> httpx.Response:+ seen_auth.append(request.headers["Authorization"])+ return httpx.Response(200, json=_JSON_OK)++ stt = OpenRouterSTT(http_client=_mock_client(handler))+ try:+ await stt.transcribe_pcm(_silent_pcm())+ state["key"] = "new-key"+ state["revision"] = 1+ await stt.transcribe_pcm(_silent_pcm())+ finally:+ await stt.aclose()++ assert seen_auth == ["Bearer old-key", "Bearer new-key"]++# ---------------------------------------------------------------------------# Transcription-model filter (the STT picker guard)# ---------------------------------------------------------------------------diff --git a/tests/unit/plugins/tts/test_openrouter_tts.py b/tests/unit/plugins/tts/test_openrouter_tts.pyindex a9cba773f2..dc058e6445 100644--- a/tests/unit/plugins/tts/test_openrouter_tts.py+++ b/tests/unit/plugins/tts/test_openrouter_tts.py@@ -9,6 +9,7 @@ only speech models survive).from __future__ import annotationsfrom collections.abc import AsyncIterator+from types import SimpleNamespacefrom typing import Anyimport pytest@@ -178,6 +179,50 @@ async def test_missing_key_raises_clear_error(monkeypatch: pytest.MonkeyPatch) -_ = [c async for c in tts.synthesize("Test.")]+async def test_shared_key_replacement_refreshes_the_internal_client(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ state: dict[str, Any] = {"key": "old-key", "revision": 0}+ created: list[Any] = []++ class _ManagedClient:+ def __init__(self, **kwargs: Any) -> None:+ self.headers = kwargs["headers"]+ self.closed = False+ created.append(self)++ async def aclose(self) -> None:+ self.closed = True++ monkeypatch.setattr(+ ortts.cfg,+ "resolve_provider_endpoint",+ lambda *a, **k: SimpleNamespace(+ credential=state["key"], base_url=ortts.BASE_URL, via_proxy=False+ ),+ )+ monkeypatch.setattr(+ ortts.cfg, "secret_revision", lambda _key: state["revision"]+ )+ monkeypatch.setattr("httpx.AsyncClient", _ManagedClient)++ tts = OpenRouterTTS()+ await tts._ensure_client()+ first = tts._client+ await tts._ensure_client()+ assert len(created) == 1, "an unchanged credential must reuse the keep-alive client"++ state["key"] = "new-key"+ state["revision"] += 1+ await tts._ensure_client()++ assert len(created) == 2+ assert first.closed is True+ assert tts._client.headers["Authorization"] == "Bearer new-key"+ await tts.aclose()++# --------------------------------------------------------------------------- ## Voice resolution + list_voices ## --------------------------------------------------------------------------- #