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
fix(wiki): resolve vault root against repo root, not CWD
Ruben Lütke3fc8e28e6ffc
diff --git a/jarvis/brain/factory.py b/jarvis/brain/factory.pyindex 638b710877..d31536d410 100644--- a/jarvis/brain/factory.py+++ b/jarvis/brain/factory.py@@ -280,26 +280,24 @@ def _resolve_wiki_vault_root(config: Any) -> Path:Reads ``config.wiki_integration.vault_root`` — the SAME field everyother wiki consumer uses (``wiki_recall._build_search_instance``,- ``wiki_routes._resolve_vault_root``). Falls back to the standard- ``<project>/wiki/obsidian-vault`` path only as a last resort when the- config has no ``wiki_integration`` section (older config) or its value- is empty.+ ``wiki_routes._resolve_vault_root``) — and resolves it through the+ canonical :func:`jarvis.memory.wiki.vault_root.resolve_vault_root`+ (spec A7), so a relative root anchors to the repo root, never the+ process CWD. Falls back to the resolver's standard+ ``<project>/wiki/obsidian-vault`` default when the config has no+ ``wiki_integration`` section (older config) or its value is empty.Historical bug: this previously read ``config.memory.vault_root``,a field that never existed on ``MemoryConfig`` — so it alwaysresolved to ``None`` and a user's ``[wiki_integration].vault_root``was silently ignored on the voice path."""- from jarvis.core import config as cfg+ from jarvis.memory.wiki.vault_root import resolve_vault_rootraw = getattr(getattr(config, "wiki_integration", None), "vault_root", None)- if raw is None or str(raw).strip() == "":- # Last-resort default: the standard in-repo vault location.- return cfg.PROJECT_ROOT / "wiki" / "obsidian-vault"- path = Path(raw)- if not path.is_absolute():- path = (cfg.PROJECT_ROOT / path)- return path+ if raw is not None and str(raw).strip() == "":+ raw = None+ return resolve_vault_root(raw).pathdef _load_tools_for_tier(diff --git a/jarvis/memory/wiki/vault_root.py b/jarvis/memory/wiki/vault_root.pynew file mode 100644index 0000000000..b2f7ba001b--- /dev/null+++ b/jarvis/memory/wiki/vault_root.py@@ -0,0 +1,77 @@+"""Single canonical vault-root resolution (spec A7).++Every consumer of ``[wiki_integration].vault_root`` resolves through+:func:`resolve_vault_root`. A relative root anchors to the repo root+(``jarvis/core/paths.repo_root()``), never to ``Path.cwd()`` — a desktop+launch from another directory used to read/write a different vault than+the UI displayed.++Legacy migration: installs that ran with the old CWD-based resolution may+hold a populated vault under ``<old cwd>/wiki/obsidian-vault``. When that+legacy vault is populated and the anchored one is empty/missing, the+populated one wins; the ambiguity is flagged for the health surface+instead of silently forking the vault.+"""+from __future__ import annotations++import threading+from dataclasses import dataclass+from pathlib import Path++from jarvis.core.paths import repo_root++_DEFAULT_RELATIVE = Path("wiki/obsidian-vault")++_lock = threading.Lock()+_last: VaultRootResolution | None = None+++@dataclass(frozen=True, slots=True)+class VaultRootResolution:+ path: Path+ source: str # "absolute" | "repo_root" | "legacy_cwd"+ legacy_conflict: bool+++def _non_empty_dir(p: Path) -> bool:+ try:+ return p.is_dir() and any(p.iterdir())+ except OSError:+ return False+++def resolve_vault_root(+ raw: str | Path | None, *, cwd: Path | None = None,+) -> VaultRootResolution:+ """Resolve the configured vault root to an absolute path.++ ``cwd`` is injectable for tests; production callers omit it.+ """+ raw_path = Path(raw) if raw else _DEFAULT_RELATIVE+ if raw_path.is_absolute():+ res = VaultRootResolution(raw_path.resolve(), "absolute", False)+ return _remember(res)++ anchored = (repo_root() / raw_path).resolve()+ legacy = ((cwd or Path.cwd()) / raw_path).resolve()+ if legacy == anchored:+ return _remember(VaultRootResolution(anchored, "repo_root", False))+ legacy_populated = _non_empty_dir(legacy)+ if legacy_populated and not _non_empty_dir(anchored):+ return _remember(VaultRootResolution(legacy, "legacy_cwd", True))+ return _remember(+ VaultRootResolution(anchored, "repo_root", legacy_populated)+ )+++def _remember(res: VaultRootResolution) -> VaultRootResolution:+ global _last+ with _lock:+ _last = res+ return res+++def last_resolution() -> VaultRootResolution | None:+ """Most recent resolution — read by the wiki health snapshot."""+ with _lock:+ return _lastdiff --git a/jarvis/plugins/tool/wiki_page_read.py b/jarvis/plugins/tool/wiki_page_read.pyindex 1e683aa208..c89dfe757e 100644--- a/jarvis/plugins/tool/wiki_page_read.py+++ b/jarvis/plugins/tool/wiki_page_read.py@@ -154,27 +154,31 @@ def _build_page_read_tool() -> "WikiPageReadTool":"""Construct a :class:`WikiPageReadTool` with the configured vault root.Mirrors :func:`jarvis.plugins.tool.wiki_recall._build_search_instance` so- the factory can wire both tools the same way. Falls back to- ``Path("wiki/obsidian-vault")`` (relative to CWD) when the config field- is absent, and logs a single WARNING in that case.+ the factory can wire both tools the same way. Resolves through+ :func:`jarvis.memory.wiki.vault_root.resolve_vault_root` (spec A7), so a+ relative root anchors to the repo root, never the process CWD. Falls+ back to the resolver's default vault location when the config field is+ absent, and logs a single WARNING in that case."""- vault_root: Path | None = None+ from jarvis.memory.wiki.vault_root import resolve_vault_root++ raw: str | Path | None = Nonetry:from jarvis.core import config as cfgloaded = cfg.load_config()wiki_cfg = getattr(loaded, "wiki_integration", None)if wiki_cfg is not None:- vault_root = Path(wiki_cfg.vault_root)+ raw = wiki_cfg.vault_rootexcept Exception as exc: # noqa: BLE001log.debug("wiki-page-read: config load skipped: %s", exc)- if vault_root is None:- vault_root = Path("wiki/obsidian-vault")+ if raw is None:log.warning("wiki-page-read: cfg.wiki_integration.vault_root not found; "- "defaulting to %s",- vault_root.resolve(),+ "defaulting to the standard vault location",)+ vault_root = resolve_vault_root(raw).path+return WikiPageReadTool(vault_root=vault_root)diff --git a/jarvis/plugins/tool/wiki_recall.py b/jarvis/plugins/tool/wiki_recall.pyindex 37f56d5709..c10d3c134b 100644--- a/jarvis/plugins/tool/wiki_recall.py+++ b/jarvis/plugins/tool/wiki_recall.py@@ -22,10 +22,12 @@ Privacy rule (AP-7 / §5 overview):Query text is logged only at DEBUG level. Hit count summary isINFO level.-Vault-root fallback (§6 AGENT-B):- If ``cfg.wiki_integration.vault_root`` is unavailable at construction- time, the tool defaults to ``Path("wiki/obsidian-vault")`` relative- to the current working directory and logs a single WARNING.+Vault-root resolution (§6 AGENT-B, spec A7):+ ``cfg.wiki_integration.vault_root`` is resolved through the canonical+ :func:`jarvis.memory.wiki.vault_root.resolve_vault_root` — a relative+ root anchors to the repo root, never the process CWD. If the config+ field is unavailable at construction time, the tool falls back to the+ resolver's default vault location and logs a single WARNING."""from __future__ import annotations@@ -142,12 +144,15 @@ class WikiRecallTool:def _build_search_instance() -> "VaultSearch":"""Build a ``VaultSearch`` with the configured vault root.- Falls back to ``Path("wiki/obsidian-vault")`` (relative to cwd) when- the config field is absent. Logs a single WARNING in that case.+ Resolves through :func:`jarvis.memory.wiki.vault_root.resolve_vault_root`+ (spec A7), so a relative root anchors to the repo root, never the+ process CWD. Falls back to the resolver's default vault location when+ the config field is absent, logging a single WARNING in that case."""from jarvis.memory.wiki.search import VaultSearch+ from jarvis.memory.wiki.vault_root import resolve_vault_root- vault_root: Path | None = None+ raw: str | Path | None = Nonetry:from jarvis.core import config as cfg@@ -155,16 +160,14 @@ def _build_search_instance() -> "VaultSearch":# Agent A defines wiki_integration.vault_root; it may not exist yet.wiki_cfg = getattr(loaded, "wiki_integration", None)if wiki_cfg is not None:- vault_root = Path(wiki_cfg.vault_root)+ raw = wiki_cfg.vault_rootexcept Exception as exc: # noqa: BLE001log.debug("wiki-recall: config load skipped: %s", exc)- if vault_root is None:- vault_root = Path("wiki/obsidian-vault")+ if raw is None:log.warning("wiki-recall: cfg.wiki_integration.vault_root not found; "- "defaulting to %s",- vault_root.resolve(),+ "defaulting to the standard vault location",)- return VaultSearch(vault_root)+ return VaultSearch(resolve_vault_root(raw).path)diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.pyindex db1a960a5c..d8123ab49a 100644--- a/jarvis/ui/web/server.py+++ b/jarvis/ui/web/server.py@@ -2183,11 +2183,9 @@ class WebServer:returnrepo = MarkdownPageRepository()- vault_root = Path(wiki_cfg.vault_root)- if not vault_root.is_absolute():- # Resolve relative to the repo root (same convention as the rest- # of the app — CWD is the repo root at runtime).- vault_root = Path.cwd() / vault_root+ from jarvis.memory.wiki.vault_root import resolve_vault_root++ vault_root = resolve_vault_root(wiki_cfg.vault_root).pathdef _wiki_scheduler_factory(*, curator): # noqa: ANN001, ANN202"""Build the CuratorScheduler (cooldown + VaultLock, Wave-2 B4).@@ -2247,9 +2245,9 @@ class WebServer:if not wiki_cfg.enabled:return- vault_root = Path(wiki_cfg.vault_root)- if not vault_root.is_absolute():- vault_root = Path.cwd() / vault_root+ from jarvis.memory.wiki.vault_root import resolve_vault_root++ vault_root = resolve_vault_root(wiki_cfg.vault_root).pathif not vault_root.is_dir():logger.info("wiki_boot_index: vault missing — skipping ({})", vault_root)return@@ -2285,6 +2283,7 @@ class WebServer:the desktop app must boot when the vault is empty or watchdogcannot start an observer."""+ from jarvis.memory.wiki.vault_root import resolve_vault_rootfrom jarvis.memory.wiki.watcher import WikiWatcherwiki_cfg = self.cfg.wiki_integration@@ -2292,9 +2291,7 @@ class WebServer:logger.info("wiki_watcher: wiki_integration disabled — skipping")return- vault_root = Path(wiki_cfg.vault_root)- if not vault_root.is_absolute():- vault_root = Path.cwd() / vault_root+ vault_root = resolve_vault_root(wiki_cfg.vault_root).pathwatcher = WikiWatcher(vault_root=vault_root, bus=self.bus)try:diff --git a/jarvis/ui/web/setup_routes.py b/jarvis/ui/web/setup_routes.pyindex e35d168ee9..a05bd8810a 100644--- a/jarvis/ui/web/setup_routes.py+++ b/jarvis/ui/web/setup_routes.py@@ -11,9 +11,10 @@ Two endpoints power the Desktop App's "Obsidian" setup card:=> 409, ``rolled_back`` => 500.The vault root is read from ``app.state.config.wiki_integration.vault_root``-(same surface as :mod:`jarvis.ui.web.wiki_routes`). When the path is-relative, it is resolved against ``app.state.repo_root`` if present,-otherwise against ``Path.cwd()``. No mutation of app state happens here.+(same surface as :mod:`jarvis.ui.web.wiki_routes`) and resolved through the+canonical :func:`jarvis.memory.wiki.vault_root.resolve_vault_root` (spec+A7) — a relative path anchors to the repo root, never the process CWD. No+mutation of app state happens here.This module owns only the HTTP surface. All detection + write logic livesin :mod:`jarvis.setup.obsidian` (Sub-Agents 1 + 2). This file is a pure@@ -28,6 +29,7 @@ from typing import Literalfrom fastapi import APIRouter, HTTPException, Query, Requestfrom pydantic import BaseModel+from jarvis.memory.wiki.vault_root import resolve_vault_rootfrom jarvis.setup.obsidian import (detect_obsidian,is_vault_registered,@@ -92,10 +94,12 @@ class SetupStateResponse(BaseModel):def _resolve_vault_path(request: Request) -> Path:"""Return the absolute vault path the wizard should target.- Falls back to ``<cwd>/wiki/obsidian-vault`` when no config is wired up- so the route stays useful in minimal test apps. Resolves a relative- ``vault_root`` against ``app.state.repo_root`` when present, otherwise- against ``Path.cwd()`` (same as :mod:`jarvis.ui.web.wiki_routes`).+ Resolves through the canonical+ :func:`jarvis.memory.wiki.vault_root.resolve_vault_root` (spec A7) —+ same resolver used by :mod:`jarvis.ui.web.wiki_routes` — so a relative+ ``vault_root`` anchors to the repo root, never the process CWD. Falls+ back to the resolver's default vault location when no config is wired+ up, so the route stays useful in minimal test apps."""config = getattr(request.app.state, "config", None)raw: Path | str | None = None@@ -104,17 +108,7 @@ def _resolve_vault_path(request: Request) -> Path:if wiki_cfg is not None:raw = getattr(wiki_cfg, "vault_root", None)- if raw is None:- raw = Path("wiki/obsidian-vault")-- path = Path(raw)- if not path.is_absolute():- repo_root = getattr(request.app.state, "repo_root", None)- base = Path(repo_root) if repo_root is not None else Path.cwd()- path = (base / path).resolve()- else:- path = path.resolve()- return path+ return resolve_vault_root(raw).path# ---------------------------------------------------------------------------diff --git a/jarvis/ui/web/wiki_routes.py b/jarvis/ui/web/wiki_routes.pyindex da7d9f274c..d6cb305dd6 100644--- a/jarvis/ui/web/wiki_routes.py+++ b/jarvis/ui/web/wiki_routes.py@@ -37,6 +37,7 @@ from jarvis.memory.wiki.protocols import WikiPagefrom jarvis.memory.wiki.search import VaultSearchfrom jarvis.memory.wiki.telemetry import telemetry as _telemetryfrom jarvis.memory.wiki.vault_index import VaultIndex+from jarvis.memory.wiki.vault_root import resolve_vault_rootfrom jarvis.memory.wiki.wikilink import _canonicalise as _canonicalise_link # type: ignore[attr-defined]log = logging.getLogger(__name__)@@ -64,6 +65,10 @@ _BACKLINK_SNIPPET_MAX = 200def _resolve_vault_root(request: Request) -> Path | None:"""Return the configured vault root, or ``None`` when the app has no config.+ Resolves through the canonical+ :func:`jarvis.memory.wiki.vault_root.resolve_vault_root` (spec A7) — a+ relative root anchors to the repo root, never the process CWD.+The route handlers tolerate a missing root by returning an empty-but-validresponse (per §3.1 edge cases). They do not raise."""@@ -76,10 +81,7 @@ def _resolve_vault_root(request: Request) -> Path | None:raw = getattr(wiki_cfg, "vault_root", None)if raw is None:return None- path = Path(raw)- if not path.is_absolute():- path = (Path.cwd() / path).resolve()- return path+ return resolve_vault_root(raw).path# ----------------------------------------------------------------------diff --git a/tests/unit/memory/wiki/test_vault_root.py b/tests/unit/memory/wiki/test_vault_root.pynew file mode 100644index 0000000000..c7fa943060--- /dev/null+++ b/tests/unit/memory/wiki/test_vault_root.py@@ -0,0 +1,33 @@+"""Vault-root resolution must not depend on the process CWD (spec A7)."""+from jarvis.core.paths import repo_root+from jarvis.memory.wiki.vault_root import resolve_vault_root+++def test_relative_root_anchors_to_repo_root_not_cwd(tmp_path):+ res = resolve_vault_root("wiki/obsidian-vault", cwd=tmp_path)+ assert res.path == (repo_root() / "wiki" / "obsidian-vault").resolve()+ assert res.source == "repo_root"+++def test_absolute_root_passes_through(tmp_path):+ res = resolve_vault_root(tmp_path / "vault", cwd=tmp_path)+ assert res.path == (tmp_path / "vault").resolve()+ assert res.source == "absolute"+ assert res.legacy_conflict is False+++def test_populated_legacy_cwd_vault_wins_and_flags_conflict(tmp_path):+ legacy = tmp_path / "wiki" / "obsidian-vault"+ legacy.mkdir(parents=True)+ (legacy / "log.md").write_text("# log\n", encoding="utf-8")+ res = resolve_vault_root("wiki/obsidian-vault", cwd=tmp_path)+ # The anchored repo-root vault exists and is populated in this repo, so+ # the anchor wins; the conflict must still be flagged for the health+ # surface. If the anchored path were empty, legacy would win (see module).+ assert res.legacy_conflict is True+++def test_none_falls_back_to_default_relative_root(tmp_path):+ res = resolve_vault_root(None, cwd=tmp_path)+ assert res.path.name == "obsidian-vault"+ assert res.path.is_absolute()diff --git a/tests/unit/ui/test_setup_routes.py b/tests/unit/ui/test_setup_routes.pyindex 68dae8c09c..9e6c31fdc9 100644--- a/tests/unit/ui/test_setup_routes.py+++ b/tests/unit/ui/test_setup_routes.py@@ -6,9 +6,11 @@ detector + writer in :mod:`jarvis.setup.obsidian` so the realHTTP shapes / status codes documented in the route module.The tests use a tiny ``SimpleNamespace`` config so we never have to-construct a full :class:`JarvisConfig`. The vault path resolution path-through ``app.state.repo_root`` is exercised by passing ``tmp_path`` as-the repo root.+construct a full :class:`JarvisConfig`. Vault path resolution goes through+the canonical ``jarvis.memory.wiki.vault_root.resolve_vault_root`` (spec+A7), which anchors a relative ``vault_root`` to the repo root — the routes+under test only ever inspect the resolved path's suffix, so they stay+agnostic to which concrete repo root the resolver picks."""from __future__ import annotations@@ -41,17 +43,11 @@ from jarvis.ui.web.setup_routes import router as setup_routerdef _make_app(tmp_path: Path) -> FastAPI:- """Build a minimal FastAPI app with the setup router mounted.-- ``app.state.repo_root`` is set to ``tmp_path`` so a relative- ``vault_root`` resolves into a writable scratch directory rather- than the real repo.- """+ """Build a minimal FastAPI app with the setup router mounted."""app = FastAPI()app.include_router(setup_router)wiki_cfg = SimpleNamespace(vault_root=Path("wiki/obsidian-vault"))app.state.config = SimpleNamespace(wiki_integration=wiki_cfg)- app.state.repo_root = tmp_pathreturn app