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
claude/fix 1058 show data dir (#1094)
Ruben Lütkee7a32d2d51f6
diff --git a/docs/product/reference/configuration-reference.md b/docs/product/reference/configuration-reference.mdindex 57ed022a06..eda490e66d 100644--- a/docs/product/reference/configuration-reference.md+++ b/docs/product/reference/configuration-reference.md@@ -67,8 +67,17 @@ value under the `JARVIS_` name, and that is the name a program it starts sees.|---|---|| Active configuration | Non-blank `JARVIS_CONFIG`; otherwise `<project-folder>/jarvis.toml` || Named profiles | `<project-folder>/profiles/<profile>.yaml` |+| Data directory | Non-blank `JARVIS_DATA_DIR`; otherwise `<project-folder>/data` (`data-dev` for the dev instance) || Local credential fallback | `JARVIS_DATA_DIR/credentials.json` when set; otherwise the writable project data directory, with a per-user fallback such as `%LOCALAPPDATA%\Jarvis` on Windows or `~/.jarvis` elsewhere |+The data directory holds the saved agents, chats, memory and other runtime+state. Pointing `JARVIS_DATA_DIR` at a different folder starts the app on that+folder's state: a new or empty folder shows only the default agent, while the+agents and chats in the previous folder stay where they were. Point the+variable back to see them again. Each start logs+`Data directory: <path> (source: JARVIS_DATA_DIR)` or `(source: default)`, and+`GET /api/diagnostics/data-dir` returns the same `path` and `source`.+Nested environment names use two underscores between path segments. Forexample, `JARVIS__UI__LANGUAGE=en` targets the interface language. Commonboolean and numeric forms are converted automatically. Environment overridesdiff --git a/dodaios/core/config.py b/dodaios/core/config.pyindex 5158d34452..324ea5eebc 100644--- a/dodaios/core/config.py+++ b/dodaios/core/config.py@@ -45,7 +45,7 @@ from dodaios.ui.pets.states import DEFAULT_PET_IDfrom .branding import KEYRING_SERVICE_NAME, LEGACY_KEYRING_SERVICE_NAMESfrom .env_prefix import accepted_namesfrom .identity_boot import resolve_config_file-from .instance import current_instance, resolve_data_dir+from .instance import current_instance, data_dir_source, resolve_data_dirfrom .protocols import RiskTier# AckBrainConfig lives under dodaios.brain.ack_brain.config. We cannot@@ -84,6 +84,32 @@ def _resolve_data_dir() -> Path:DATA_DIR = _resolve_data_dir()+# Read in the same import as DATA_DIR, so the two always describe one decision.+DATA_DIR_SOURCE = data_dir_source()+_data_dir_logged = False+++def data_dir_info() -> dict[str, str]:+ """The active data directory and where it came from, for diagnostics."""+ return {"path": str(DATA_DIR), "source": DATA_DIR_SOURCE}+++def log_data_dir_once(log: Any = None) -> bool:+ """Log ``Data directory: <path> (source: ...)`` once per process.++ Agents, chats and settings live under this directory, so a launcher that+ points ``JARVIS_DATA_DIR`` somewhere new looks like lost data unless the+ log says which directory is in use (issue #1058).+ """+ global _data_dir_logged+ if _data_dir_logged:+ return False+ _data_dir_logged = True+ (log or logging.getLogger(__name__)).info(+ "Data directory: %s (source: %s)", DATA_DIR, DATA_DIR_SOURCE+ )+ return True+ASSETS_DIR = PROJECT_ROOT / "assets"# Guards _resolve_writable_data_dir()'s lazy writability probe below. Nameddiff --git a/dodaios/core/instance.py b/dodaios/core/instance.pyindex 81451c8427..130a0ad64a 100644--- a/dodaios/core/instance.py+++ b/dodaios/core/instance.py@@ -353,6 +353,17 @@ def resolve_data_dir(project_root: Path) -> Path:return instance_data_dir(project_root)+def data_dir_source() -> str:+ """Where :func:`resolve_data_dir` takes the directory from right now.++ ``"JARVIS_DATA_DIR"`` when the environment variable set it, else+ ``"default"``. Shown at boot and on the diagnostics API so a switched data+ directory (an apparently empty agent roster, issue #1058) is visible.+ """+ env_dir = os.environ.get(DATA_DIR_ENV_VAR)+ return DATA_DIR_ENV_VAR if env_dir and env_dir.strip() else "default"++__all__ = ["DATA_DIR_ENV_VAR","DEFAULT_ICON_FILE_NAME",@@ -366,6 +377,7 @@ __all__ = ["InstanceIdentity","InstanceNameError","current_instance",+ "data_dir_source","instance_data_dir","normalize_instance_name","resolve_data_dir",diff --git a/dodaios/ui/web/diagnostics_routes.py b/dodaios/ui/web/diagnostics_routes.pyindex 0569d12e39..f5063c0c48 100644--- a/dodaios/ui/web/diagnostics_routes.py+++ b/dodaios/ui/web/diagnostics_routes.py@@ -76,6 +76,20 @@ def _task_snapshot(task: asyncio.Task[Any]) -> dict[str, Any]:}[email protected]("/data-dir")+def data_dir() -> dict[str, str]:+ """The data directory this process reads and writes, and its source.++ ``source`` is ``JARVIS_DATA_DIR`` when the environment variable chose it,+ else ``default``. Agents, chats and settings all live under ``path``, so a+ launcher that switched it explains an apparently empty roster (#1058).+ Authenticated like every ``/api`` route; ``/api/health`` stays path-free.+ """+ from dodaios.core.config import data_dir_info++ return data_dir_info()++@router.get("/event-loop-tasks")async def event_loop_tasks() -> dict[str, Any]:"""Snapshot all tasks on the serving loop, suspects first.diff --git a/dodaios/ui/web/server.py b/dodaios/ui/web/server.pyindex f298b25d23..8ea896fba5 100644--- a/dodaios/ui/web/server.py+++ b/dodaios/ui/web/server.py@@ -2863,6 +2863,12 @@ class WebServer:_attach_permission_bus(self.bus, asyncio.get_running_loop())+ # Which data directory holds the agents, chats and settings this run+ # shows: a switched JARVIS_DATA_DIR otherwise looks like lost data.+ from dodaios.core.config import log_data_dir_once++ log_data_dir_once()+await self.prepare_app()import uvicorndiff --git a/tests/unit/core/test_data_dir_visibility.py b/tests/unit/core/test_data_dir_visibility.pynew file mode 100644index 0000000000..57cf04a7c5--- /dev/null+++ b/tests/unit/core/test_data_dir_visibility.py@@ -0,0 +1,59 @@+"""Issue #1058: the active data directory and its source are visible.++A launcher that points ``JARVIS_DATA_DIR`` at a new folder makes saved agents+look deleted. The boot log and the diagnostics API now name the directory in+use and whether the environment variable or the default chose it.+"""++from __future__ import annotations++import logging+from pathlib import Path++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from dodaios.core import config as config_mod+from dodaios.core.instance import DATA_DIR_ENV_VAR, data_dir_source+++def test_the_source_follows_the_environment(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv(DATA_DIR_ENV_VAR, "/srv/dodaios-data")+ assert data_dir_source() == "JARVIS_DATA_DIR"+ monkeypatch.setenv(DATA_DIR_ENV_VAR, " ")+ assert data_dir_source() == "default"+ monkeypatch.delenv(DATA_DIR_ENV_VAR, raising=False)+ assert data_dir_source() == "default"+++def test_the_boot_line_names_path_and_source_once(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, caplog: pytest.LogCaptureFixture+) -> None:+ monkeypatch.setattr(config_mod, "DATA_DIR", tmp_path)+ monkeypatch.setattr(config_mod, "DATA_DIR_SOURCE", "JARVIS_DATA_DIR")+ monkeypatch.setattr(config_mod, "_data_dir_logged", False)+ with caplog.at_level(logging.INFO, logger="dodaios.core.config"):+ assert config_mod.log_data_dir_once() is True+ assert config_mod.log_data_dir_once() is False+ lines = [r.getMessage() for r in caplog.records if "Data directory" in r.getMessage()]+ assert lines == [f"Data directory: {tmp_path} (source: JARVIS_DATA_DIR)"]+++def test_the_diagnostics_route_reports_path_and_source(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ from dodaios.ui.web.diagnostics_routes import router++ monkeypatch.setattr(config_mod, "DATA_DIR", tmp_path)+ monkeypatch.setattr(config_mod, "DATA_DIR_SOURCE", "default")+ app = FastAPI()+ app.include_router(router)+ response = TestClient(app).get("/api/diagnostics/data-dir")+ assert response.status_code == 200+ assert response.json() == {"path": str(tmp_path), "source": "default"}+++def test_the_import_time_source_matches_the_import_time_directory() -> None:+ assert config_mod.DATA_DIR_SOURCE in {"JARVIS_DATA_DIR", "default"}+ assert config_mod.data_dir_info()["path"] == str(config_mod.DATA_DIR)