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-06-30 16:42)

Ruben Lütke0f34fb4c9708
diff --git a/.claude/skills/ship-public-release/references/distribution-denylist.txt b/.claude/skills/ship-public-release/references/distribution-denylist.txt
index 0c9efdefad..fc0ea63bc0 100644
--- a/.claude/skills/ship-public-release/references/distribution-denylist.txt
+++ b/.claude/skills/ship-public-release/references/distribution-denylist.txt
@@ -161,3 +161,12 @@ tools/**
# docs/qa/ is the maintainer's internal voice-QA checklist — same internal-
# process class as docs/superpowers/** / docs/plans/** already withheld above.
docs/qa/**
+
+# --- Internal privacy/red-team agent spec (2026-06-30) ----------------------
+# docs-privacy-reviewer.md is the maintainer's OWN depersonalization red-team
+# guide: in source it enumerates the real maintainer identity (real name in
+# every spelling incl. the accented 'Rubén', alt name 'Harald Herz', the private
+# email shapes, GitHub login) and the entire scrub scheme. Shipping the doc that
+# lists what to hide is itself the leak (2026-06-30 sub-agent review). It is an
+# internal dev tool with no downstream value; a fork writes its own.
+.claude/agents/docs-privacy-reviewer.md
diff --git a/.claude/skills/ship-public-release/references/pii-scrub.tsv b/.claude/skills/ship-public-release/references/pii-scrub.tsv
index 4c839b4b6e..c919b09431 100644
--- a/.claude/skills/ship-public-release/references/pii-scrub.tsv
+++ b/.claude/skills/ship-public-release/references/pii-scrub.tsv
@@ -32,6 +32,12 @@ scrub luetke maintainer maintainer surname (lowercase residue in slugs)
# --- the user (address) and "Harald" is an example third person mentioned. ---
scrub Ruben Alex maintainer first name (sample/address user) -> neutral
scrub ruben alex maintainer first name lowercase (config defaults, slugs, branch tags)
+# Accented spelling 'Rubén' — the ASCII 'Ruben' rules above do NOT match the é,
+# so the accented real first name shipped through (2026-06-30 sub-agent review:
+# docs/phase-b1-wiki-curator/*, tests/unit/memory/wiki/test_page.py, etc.).
+scrub Rubén Alex maintainer first name accented (é) -> neutral
+scrub rubén alex maintainer first name accented lowercase
+scrub RUBÉN ALEX maintainer first name accented all-caps (regression guard)
scrub Harald Sam maintainer alt first name (example person in prompts/tests)
scrub harald sam maintainer alt first name lowercase (ADR owner field, slugs, test emails)
diff --git a/jarvis/core/self_mod/__init__.py b/jarvis/core/self_mod/__init__.py
index 0a82d083b8..e221c90664 100644
--- a/jarvis/core/self_mod/__init__.py
+++ b/jarvis/core/self_mod/__init__.py
@@ -13,6 +13,7 @@ from .errors import (
AllowlistViolationError,
BackupError,
PreValidateError,
+ ProviderSwitchLockedError,
ReloadError,
RollbackError,
SecretAccessError,
@@ -20,6 +21,7 @@ from .errors import (
TypeMismatchError,
)
from .pending import PendingMutation, PendingMutationStore
+from .provider_lock import PROVIDER_LOCK_PATHS, is_provider_lock_path
from .registry import FORBIDDEN_PATTERNS, SelfModRegistry
from .schema import (
AuditActor,
@@ -35,6 +37,7 @@ from .writer import AtomicConfigWriter
__all__ = [
"FORBIDDEN_PATTERNS",
+ "PROVIDER_LOCK_PATHS",
"AllowlistViolationError",
"AtomicConfigWriter",
"AuditActor",
@@ -48,6 +51,7 @@ __all__ = [
"PendingMutation",
"PendingMutationStore",
"PreValidateError",
+ "ProviderSwitchLockedError",
"ReloadError",
"RollbackError",
"SecretAccessError",
@@ -56,4 +60,5 @@ __all__ = [
"SelfModRegistry",
"SelfModRiskTier",
"TypeMismatchError",
+ "is_provider_lock_path",
]
diff --git a/jarvis/core/self_mod/errors.py b/jarvis/core/self_mod/errors.py
index 591f139295..7e333da30d 100644
--- a/jarvis/core/self_mod/errors.py
+++ b/jarvis/core/self_mod/errors.py
@@ -23,6 +23,16 @@ class SecretAccessError(SelfModError):
"""
+class ProviderSwitchLockedError(SelfModError):
+ """A non-USER actor tried to change a brain provider-selection key.
+
+ The active brain provider is the user's hard choice — it changes ONLY
+ through an explicit user action (the control CLI or the manual provider
+ switch in the desktop app, `actor=USER`), never through Jarvis itself
+ (voice/chat self-mod) or any automatic mechanism. See `provider_lock.py`.
+ """
+
+
class TypeMismatchError(SelfModError):
"""Value type does not match the expected Pydantic field type."""
diff --git a/jarvis/core/self_mod/provider_lock.py b/jarvis/core/self_mod/provider_lock.py
new file mode 100644
index 0000000000..282aa0874d
--- /dev/null
+++ b/jarvis/core/self_mod/provider_lock.py
@@ -0,0 +1,46 @@
+"""User-only provider-selection lock.
+
+The active brain provider — and the other brain provider-selection keys that
+decide which provider actually runs a turn — is the user's HARD choice. It may
+change ONLY through an explicit user action: the control CLI or the manual
+provider switch in the desktop app (``actor=AuditActor.USER``). It must NEVER
+change through Jarvis itself (a voice/chat self-mod, ``actor != USER``) or any
+automatic mechanism.
+
+This is deliberately NARROWER than ``forbidden.py``: a forbidden path is never
+self-mutable at all, whereas a locked path stays fully writable by the user —
+it is only Jarvis (and other non-user actors) that is refused. So the lock is
+enforced *together with* the actor in the writer, not as a blanket deny.
+
+Kept dependency-free (string patterns + ``fnmatch`` only) so both the writer
+and the schema introspector can consult it without an import cycle, mirroring
+``forbidden.py``.
+"""
+from __future__ import annotations
+
+from fnmatch import fnmatch
+
+# The brain provider-selection keys. ``brain.primary`` is the active provider;
+# the routing/fallback keys are included because the router runs first every
+# turn, so letting Jarvis flip them would switch the live provider just as
+# effectively as flipping ``primary``. The per-provider MODEL picker
+# (``brain.providers.<p>.model``) and the TTS/STT provider switches are
+# intentionally NOT here — only the brain provider is locked.
+PROVIDER_LOCK_PATHS: tuple[str, ...] = (
+ "brain.primary",
+ "brain.fallback",
+ "brain.deep_brain",
+ "brain.routing_provider",
+ "brain.router.provider",
+ "brain.router.fallback_provider",
+)
+
+
+def is_provider_lock_path(path: str) -> bool:
+ """True if ``path`` is a brain provider-selection key that only the user
+ (CLI / manual UI switch) may change — never Jarvis itself or an automation.
+ """
+ return any(fnmatch(path, pattern) for pattern in PROVIDER_LOCK_PATHS)
+
+
+__all__ = ["PROVIDER_LOCK_PATHS", "is_provider_lock_path"]
diff --git a/jarvis/core/self_mod/writer.py b/jarvis/core/self_mod/writer.py
index 8e43855c2c..5559999fd4 100644
--- a/jarvis/core/self_mod/writer.py
+++ b/jarvis/core/self_mod/writer.py
@@ -58,12 +58,15 @@ from .errors import (
AllowlistViolationError,
BackupError,
PreValidateError,
+ ProviderSwitchLockedError,
ReloadError,
RollbackError,
SecretAccessError,
)
+from .provider_lock import is_provider_lock_path
from .registry import SelfModRegistry
from .schema import (
+ AuditActor,
AuditEvent,
BackupRef,
MutableSpec,
@@ -165,6 +168,22 @@ class AtomicConfigWriter:
- `ReloadError` (step 8; backup has been restored)
- `RollbackError` (step 8; backup restore itself failed)
"""
+ # Step 0 — provider-selection lock. The active brain provider is the
+ # user's hard choice: only an explicit user action (the control CLI or
+ # the manual provider switch in the desktop app, actor=USER) may change
+ # it — never Jarvis itself (voice/chat self-mod) or any automation. The
+ # UI button + `jarvis brain switch` use config_writer.set_brain_primary
+ # and never reach this writer, so this gate sits purely on the self-mod
+ # / Control-API surface and leaves those sanctioned paths untouched.
+ if is_provider_lock_path(request.path) and request.actor != AuditActor.USER:
+ error = (
+ f"provider_switch_locked: {request.path} can only be changed by "
+ "the user (the CLI or the manual provider switch in the desktop "
+ f"app), not by {request.actor.value}."
+ )
+ self._audit_failure(request, old_value=None, error=error)
+ raise ProviderSwitchLockedError(error)
+
# Step 1 — no lock required (ClassVar read).
try:
spec = SelfModRegistry.require_spec(request.path)
diff --git a/jarvis/plugins/tool/switch_provider.py b/jarvis/plugins/tool/switch_provider.py
index fb7a7f7a5f..683743c45e 100644
--- a/jarvis/plugins/tool/switch_provider.py
+++ b/jarvis/plugins/tool/switch_provider.py
@@ -99,6 +99,26 @@ class SwitchProviderTool:
output=None,
error=f"invalid_input: tier must be one of {', '.join(_TIERS)}",
)
+ if tier == "brain":
+ # The active brain provider is the user's HARD choice. Jarvis (which
+ # is what invokes this tool) must NOT switch it — only the user, via
+ # the control CLI or the manual provider switch in the desktop app's
+ # API-Keys section. TTS / STT / subagent stay voice-switchable. This
+ # mirrors the self-mod writer's provider-selection lock so a brain
+ # switch is refused on EVERY Jarvis-initiated path.
+ return ToolResult(
+ success=False,
+ output={
+ "error_kind": "provider_switch_locked",
+ "tier": tier,
+ "provider": provider,
+ },
+ error=(
+ "provider_switch_locked: I can't switch the brain provider "
+ "myself. The active brain provider is your choice — change it "
+ "in the desktop app's API-Keys section or with the CLI."
+ ),
+ )
if not provider:
return ToolResult(
success=False, output=None, error="invalid_input: 'provider' is required"
diff --git a/scripts/config-soll.json b/scripts/config-soll.json
index 65f5a5e4a6..6945500ca7 100644
--- a/scripts/config-soll.json
+++ b/scripts/config-soll.json
@@ -32,7 +32,7 @@
"allow_sapi5_fallback": false
},
"brain": {
- "primary": "gemini",
+ "primary": "openrouter",
"fallback": "gemini",
"deep_brain": "gemini",
"routing_provider": "gemini",
@@ -89,6 +89,6 @@
"model": "gemini-3.5-flash"
},
"brain.providers.openrouter": {
- "model": "openai/gpt-oss-120b:free"
+ "model": "deepseek/deepseek-v4-flash"
}
}
diff --git a/tests/unit/plugins/tool/test_switch_provider_brain_lock.py b/tests/unit/plugins/tool/test_switch_provider_brain_lock.py
new file mode 100644
index 0000000000..b81907a303
--- /dev/null
+++ b/tests/unit/plugins/tool/test_switch_provider_brain_lock.py
@@ -0,0 +1,60 @@
+"""The voice/chat ``switch-provider`` tool may NOT switch the brain provider.
+
+The active brain provider is the user's hard choice: it changes only via the
+control CLI or the manual provider switch in the desktop app. Jarvis itself —
+which is what calls this tool — must refuse a brain switch with an honest
+message and never reach the actual switch path. TTS / STT / subagent switches
+stay fully voice-controllable.
+"""
+from __future__ import annotations
+
+import jarvis.brain.app_control as app_control
+from jarvis.plugins.tool.switch_provider import SwitchProviderTool
+
+
+async def test_brain_switch_is_refused_and_never_applied(monkeypatch) -> None:
+ calls: list[tuple] = []
+
+ async def _spy(*args, **kwargs): # pragma: no cover - must not run
+ calls.append((args, kwargs))
+ return {"ok": True}
+
+ monkeypatch.setattr(app_control, "apply_provider_switch", _spy, raising=True)
+
+ tool = SwitchProviderTool()
+ result = await tool.execute(
+ {"tier": "brain", "provider": "gemini", "reason": "switch to gemini"},
+ None, # ctx is unused by the tool
+ )
+
+ assert result.success is False
+ assert "provider_switch_locked" in (result.error or "")
+ assert calls == [] # the real switch was never attempted
+
+
+async def test_tts_switch_still_reaches_apply(monkeypatch) -> None:
+ seen: dict[str, str] = {}
+
+ async def _spy(tier, provider, *, cfg, persist=True):
+ seen["tier"] = tier
+ return {
+ "ok": True,
+ "tier": tier,
+ "old_provider": "gemini-flash-tts",
+ "new_provider": provider,
+ "persisted": True,
+ "applied_live": True,
+ "requires_restart": False,
+ }
+
+ monkeypatch.setattr(app_control, "apply_provider_switch", _spy, raising=True)
+ monkeypatch.setattr(app_control, "resolve_running_cfg", lambda: object(), raising=True)
+
+ tool = SwitchProviderTool()
+ result = await tool.execute(
+ {"tier": "tts", "provider": "elevenlabs", "reason": "use elevenlabs"},
+ None,
+ )
+
+ assert seen.get("tier") == "tts"
+ assert result.success is True
diff --git a/tests/unit/self_mod/test_provider_lock.py b/tests/unit/self_mod/test_provider_lock.py
new file mode 100644
index 0000000000..a83cd0d77a
--- /dev/null
+++ b/tests/unit/self_mod/test_provider_lock.py
@@ -0,0 +1,176 @@
+"""Provider-selection lock — Jarvis may not switch its own brain provider.
+
+The active brain provider (and the other brain provider-selection keys) is the
+user's HARD choice. It changes ONLY through an explicit user action — the
+control CLI or the manual provider switch in the desktop app (``actor=USER``) —
+never through Jarvis itself (voice/chat self-mod, ``actor != USER``) or any
+automatic mechanism.
+
+This guards the self-mod writer, the convergence point of every self-mod /
+Control-API mutation, so the lock holds regardless of which tool initiates the
+write. The dedicated ``config_writer.set_brain_primary`` path used by the UI
+button + ``jarvis brain switch`` does NOT flow through here and stays allowed.
+"""
+from __future__ import annotations
+
+import json
+import tomllib
+from pathlib import Path
+
+import pytest
+
+from jarvis.core.config import JarvisConfig
+from jarvis.core.self_mod import (
+ AtomicConfigWriter,
+ AuditActor,
+ AuditSource,
+ MutationRequest,
+ ProviderSwitchLockedError,
+ SelfModAudit,
+)
+from jarvis.core.self_mod.provider_lock import (
+ PROVIDER_LOCK_PATHS,
+ is_provider_lock_path,
+)
+
+FIXTURE = Path(__file__).parent / "fixtures" / "minimal_jarvis.toml"
+
+
+def _isolated_loader(path: Path) -> JarvisConfig:
+ """Loader without JARVIS__* ENV overrides (test isolation)."""
+ raw = path.read_bytes()
+ if raw.startswith(b"\xef\xbb\xbf"):
+ raw = raw[3:]
+ return JarvisConfig.model_validate(tomllib.loads(raw.decode("utf-8")))
+
+
+def fixture_path(tmp_path: Path) -> Path:
+ target = tmp_path / "jarvis.toml"
+ target.write_text(FIXTURE.read_text(encoding="utf-8"), encoding="utf-8")
+ return target
+
+
+def writer(fixture_path: Path, tmp_path: Path) -> AtomicConfigWriter:
+ return AtomicConfigWriter(
+ config_path=fixture_path,
+ backup_dir=tmp_path / "backups",
+ audit=SelfModAudit(path=tmp_path / "audit.log"),
+ config_loader=_isolated_loader,
+ )
+
+
+def _req(path: str, value: object, actor: AuditActor) -> MutationRequest:
+ return MutationRequest(
+ path=path, new_value=value, actor=actor, source=AuditSource.VOICE
+ )
+
+
+# ----------------------------------------------------------------------
+# Policy — which paths are user-only
+# ----------------------------------------------------------------------
+
+
+class TestPolicy:
+ def test_brain_provider_selection_keys_are_locked(self) -> None:
+ for path in (
+ "brain.primary",
+ "brain.fallback",
+ "brain.deep_brain",
+ "brain.routing_provider",
+ "brain.router.provider",
+ "brain.router.fallback_provider",
+ ):
+ assert is_provider_lock_path(path) is True, path
+
+ def test_locked_paths_constant_matches_helper(self) -> None:
+ for path in PROVIDER_LOCK_PATHS:
+ assert is_provider_lock_path(path) is True, path
+
+ def test_unrelated_keys_are_not_locked(self) -> None:
+ # tts/stt provider switches, the per-provider MODEL picker, and other
+ # settings stay freely self-mutable — the lock is brain-provider only.
+ for path in (
+ "tts.provider",
+ "stt.provider",
+ "brain.providers.gemini.model",
+ "brain.reply_language",
+ "tts.speed",
+ ):
+ assert is_provider_lock_path(path) is False, path
+
+
+# ----------------------------------------------------------------------
+# Enforcement — the self-mod writer refuses a non-USER provider switch
+# ----------------------------------------------------------------------
+
+
+class TestWriterEnforcement:
+ def test_hauptjarvis_cannot_switch_brain_primary(
+ self, writer: AtomicConfigWriter, fixture_path: Path
+ ) -> None:
+ with pytest.raises(ProviderSwitchLockedError):
+ writer.mutate(_req("brain.primary", "gemini", AuditActor.HAUPTJARVIS))
+ # The file must be untouched — no write, no drift.
+ assert _isolated_loader(fixture_path).brain.primary == "claude-api"
+
+ def test_user_can_switch_brain_primary(
+ self, writer: AtomicConfigWriter, fixture_path: Path
+ ) -> None:
+ # The CLI / manual UI path (actor=USER) is the sanctioned channel and
+ # must still go through.
+ result = writer.mutate(_req("brain.primary", "gemini", AuditActor.USER))
+ assert result.ok is True
+ assert _isolated_loader(fixture_path).brain.primary == "gemini"
+
+ def test_hauptjarvis_can_still_switch_unrelated_setting(
+ self, writer: AtomicConfigWriter, fixture_path: Path
+ ) -> None:
+ # The lock is narrow: Jarvis keeps full voice control over everything
+ # else (here: the TTS provider).
+ result = writer.mutate(_req("tts.provider", "elevenlabs", AuditActor.HAUPTJARVIS))
+ assert result.ok is True
+ assert _isolated_loader(fixture_path).tts.provider == "elevenlabs"
+
+ def test_refused_switch_is_audited(
+ self, writer: AtomicConfigWriter, tmp_path: Path
+ ) -> None:
+ with pytest.raises(ProviderSwitchLockedError):
+ writer.mutate(_req("brain.primary", "gemini", AuditActor.HAUPTJARVIS))
+ entries = [
+ json.loads(line)
+ for line in (tmp_path / "audit.log").read_text(encoding="utf-8").splitlines()
+ if line.strip()
+ ]
+ assert any(
+ e["path"] == "brain.primary"
+ and e["ok"] is False
+ and "provider_switch_locked" in e["error"]
+ for e in entries
+ )
+
+
+# ----------------------------------------------------------------------
+# The voice/chat self-mod config tool turns the lock into an honest message
+# ----------------------------------------------------------------------
+
+
+class TestSelfModConfigTool:
+ async def test_brain_primary_is_refused_honestly(
+ self, writer: AtomicConfigWriter, fixture_path: Path
+ ) -> None:
+ from jarvis.brain.tools.self_mod_tools import SetConfigValueTool
+ from jarvis.core.self_mod import PendingMutationStore
+
+ store = PendingMutationStore(writer=writer, auto_apply="all")
+ tool = SetConfigValueTool(pending_store=store) # default actor=HAUPTJARVIS
+
+ result = await tool.execute(
+ {"path": "brain.primary", "new_value": "gemini", "reason": "x"}, None
+ )
+
+ assert result.success is False
+ assert "provider_switch_locked" in (result.error or "")
+ # The provider must be untouched.
+ assert _isolated_loader(fixture_path).brain.primary == "claude-api"