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.

fix(modes): read the mode the user picked back from the config

Haraldda77735ff5b5
diff --git a/jarvis/brain/modes.py b/jarvis/brain/modes.py
index b47b458ee4..59882e44eb 100644
--- a/jarvis/brain/modes.py
+++ b/jarvis/brain/modes.py
@@ -145,6 +145,10 @@ class Mode:
voice: str = ""
verbosity: str = VERBOSITY_NORMAL
proactivity: str = PROACTIVITY_NORMAL
+ #: True when a built-in has been overlaid by the user's own file. Only then
+ #: does "restore the original" do anything, so a UI can offer it exactly
+ #: when it means something and label the card as edited.
+ edited: bool = False
def to_payload(self) -> dict[str, object]:
"""JSON-ready shape shared by the REST routes and the CLI."""
@@ -155,6 +159,7 @@ class Mode:
"description": self.description,
"character": self.character,
"built_in": self.built_in,
+ "edited": self.edited,
"voice": self.voice,
"verbosity": self.verbosity,
"proactivity": self.proactivity,
@@ -312,7 +317,8 @@ def list_modes() -> tuple[Mode, ...]:
merged: dict[str, Mode] = dict(builtins)
for slug, mode in overrides.items():
- merged[slug] = replace(mode, built_in=slug in builtins)
+ is_builtin = slug in builtins
+ merged[slug] = replace(mode, built_in=is_builtin, edited=is_builtin)
ordered = [merged[s] for s in BUILTIN_SLUGS if s in merged]
ordered.extend(
@@ -350,12 +356,24 @@ def has_user_copy(slug: str) -> bool:
def _configured_slug() -> str:
- """The user's sticky choice from ``[persona] active_mode``."""
- try:
- from jarvis.core.config import get_config
+ """The user's sticky choice from ``[persona] active_mode``.
+
+ Read through ``load_config()`` — the one accessor the config layer has —
+ which is cached on the file's identity and invalidated by ``config_writer``
+ on every write, so a switch is visible on the very next read without a
+ restart. The first version imported a ``get_config`` that never existed and
+ swallowed the ``ImportError`` in a blanket ``except``: every read came back
+ as the default, the check mark on the modes screen never moved, and the
+ assistant never ran the mode the user had picked. Only failures of the READ
+ itself are tolerated here (a half-written file mid-reload); a broken import
+ is a bug and must surface as one.
+ """
+ from jarvis.core.config import load_config
- raw = getattr(getattr(get_config(), "persona", None), "active_mode", "")
- except Exception: # noqa: BLE001 - config unavailable mid-reload
+ try:
+ raw = getattr(getattr(load_config(), "persona", None), "active_mode", "")
+ except (OSError, ValueError) as exc: # a config that cannot be parsed right now
+ log.warning("Could not read [persona] active_mode (%s) — using %s.", exc, DEFAULT_MODE)
return DEFAULT_MODE
slug = (raw or "").strip().lower()
return slug or DEFAULT_MODE
diff --git a/tests/unit/brain/test_modes.py b/tests/unit/brain/test_modes.py
index 2585466b5b..325fd4869b 100644
--- a/tests/unit/brain/test_modes.py
+++ b/tests/unit/brain/test_modes.py
@@ -14,6 +14,8 @@ Feature 2026-08-13. These lock the four contracts everything else depends on:
"""
from __future__ import annotations
+import functools
+
import pytest
import jarvis.core.config as core_config
@@ -202,10 +204,19 @@ def test_a_user_copy_shadows_a_builtin_but_stays_restorable() -> None:
edited = modes.get_mode(modes.MODE_FRIEND)
assert edited is not None and edited.character == "Totally different."
assert edited.built_in is True, "still offers 'restore the original'"
+ # ``edited`` is what tells a UI that "restore" would actually do something.
+ assert edited.edited is True
+ assert edited.to_payload()["edited"] is True
assert modes.restore_builtin(modes.MODE_FRIEND) is True
restored = modes.get_mode(modes.MODE_FRIEND)
assert restored is not None and "not serving a client" in restored.character
+ assert restored.edited is False
+
+ # A mode of the user's own is not "edited": there is no original under it.
+ modes.save_mode(slug="pirate", name="Pirate", character="Arr.")
+ own = modes.get_mode("pirate")
+ assert own is not None and own.built_in is False and own.edited is False
def test_a_stored_pointer_to_a_vanished_mode_degrades_to_the_default() -> None:
@@ -263,3 +274,49 @@ def test_override_is_never_written_to_config(monkeypatch: pytest.MonkeyPatch) ->
def test_override_naming_an_unknown_mode_raises() -> None:
with pytest.raises(modes.ModeError):
modes.set_section_override("no-such-mode")
+
+
+# ---------------------------------------------------------------------------
+# The real round trip through jarvis.toml
+# ---------------------------------------------------------------------------
+#
+# Every test above stubs ``_configured_slug`` — which is exactly how a broken
+# reader shipped: it imported an accessor the config layer does not have,
+# swallowed the ImportError, and returned the default forever. The switch was
+# written to disk on every click and never read back; the check mark on the
+# modes screen never moved. This test goes through the actual file.
+
+
+def test_the_stored_choice_is_read_back_from_the_real_config(
+ tmp_path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from jarvis.core import config_writer
+
+ monkeypatch.undo() # drop the stubs from ``_isolate``; the file is the point
+ monkeypatch.setattr(core_config, "DATA_DIR", tmp_path)
+ target = tmp_path / "jarvis.toml"
+ target.write_text('[persona]\nactive_mode = "coach"\n', encoding="utf-8")
+ monkeypatch.setenv("JARVIS_CONFIG", str(target))
+ core_config.clear_config_cache()
+
+ assert modes._configured_slug() == "coach"
+ assert modes.active_slug() == "coach"
+
+ # A write through the real writer is visible on the very next read. Only
+ # the target path is redirected; the writer itself is the real one.
+ monkeypatch.setattr(
+ config_writer,
+ "set_active_mode",
+ functools.partial(config_writer.set_active_mode, path=target),
+ )
+ modes.set_active("friend")
+ assert modes._configured_slug() == "friend"
+ assert modes.chosen_slug() == "friend"
+ assert modes.active_slug() == "friend"
+
+ # A stored slug that no longer names a mode degrades to the default — the
+ # config could have come from another machine.
+ target.write_text('[persona]\nactive_mode = "pirate"\n', encoding="utf-8")
+ core_config.clear_config_cache()
+ assert modes._configured_slug() == "pirate"
+ assert modes.active_slug() == modes.DEFAULT_MODE