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(obsidian-setup): bootstrap obsidian.json on fresh installs instead of dead-ending
Ruben Lütke1b9a06bec759
diff --git a/docs/adr/0015-obsidian-setup-wizard.md b/docs/adr/0015-obsidian-setup-wizard.mdindex 8ffc33c05b..288ee4359b 100644--- a/docs/adr/0015-obsidian-setup-wizard.md+++ b/docs/adr/0015-obsidian-setup-wizard.md@@ -45,6 +45,34 @@ the whole onboarding flow.The B9 onboarding wizard is a small, narrowly-scoped feature governedby six contracts.+### 2026-07-17 fresh-install amendment (bootstrap on missing config)++A field report from a fresh macOS install showed the wizard dead-ending:+Obsidian was installed but had never been launched, so+`~/Library/Application Support/obsidian/obsidian.json` did not exist and+`register_vault()` refused with `config_missing` — the dialog could only+ask the user to "open Obsidian once and close it, then click again". On+the maintainer's machine (Obsidian long since launched) this path never+fires, which is exactly the §3 "maintainer config as baseline" trap: every+brand-new machine on every OS starts in the config-missing state.++`register_vault()` now bootstraps a missing `obsidian.json` instead of+refusing: it creates the config directory and writes a minimal index+containing only the Jarvis vault entry, through the same tempfile ++`fsync` + `os.replace` pipeline (no backup — there is no original to back+up; on verification failure the created file is removed again). Obsidian+adopts a pre-existing `obsidian.json` on first launch, so bootstrapping+the index is equivalent to registering into an existing one.++The "always-on auto-register" rejection below still stands: the write+still happens only on the explicit **Register now** click, never from the+read-only status probe. `config_missing` remains in the result model for+the HTTP surface (the existing-vault mode reuses it for user-input+errors), and the 409 route mapping stays as a defensive branch.+Additionally, vault-path comparison is now case-insensitive on macOS as+well as Windows — the APFS default volume is case-insensitive, so+differing stored case must not report "not registered".+### 2026-07-12 reliability amendmentVault registration is based on reachability, not string equality. Adiff --git a/docs/product/knowledge-and-sharing/connect-obsidian.md b/docs/product/knowledge-and-sharing/connect-obsidian.mdindex defd03a167..0b23a30522 100644--- a/docs/product/knowledge-and-sharing/connect-obsidian.md+++ b/docs/product/knowledge-and-sharing/connect-obsidian.md@@ -26,10 +26,13 @@ turn Jarvis backups into a device-to-device backup plan.## Before You Start-- Install Obsidian from the [official Obsidian download page](https://obsidian.md/download),- then open it at least once so it can create its local vault list.+- Install Obsidian from the [official Obsidian download page](https://obsidian.md/download).+ You do not need to open it first — when Obsidian has never been launched,+ Jarvis creates the local vault list during registration and Obsidian adopts+ it on its first start.- If you want to use an existing vault, open or create that vault in Obsidian- before starting the Jarvis connection. Close Obsidian before registration so+ before starting the Jarvis connection (the existing-vault picker can only+ offer vaults Obsidian already knows). Close Obsidian before registration soboth apps do not try to update its local vault list at the same time.- Decide who should back up the folder. Jarvis keeps limited recovery snapshotsaround its own writes, but you still need your normal backup or version-history@@ -192,7 +195,7 @@ backup service is working.|---|---|---|| **Obsidian: not installed** after installation | Jarvis did not find the app in a common location, or setup has not refreshed | Start Obsidian once, return to the setup dialog, and retry. A custom install may require using Jarvis without the external-editor launch. || **Use my existing vault** is unavailable | Obsidian's local vault list is missing or has no readable registered vault | Open the desired vault in Obsidian, close Obsidian, then reopen the Jarvis setup dialog. |-| Registration asks you to open Obsidian first | Obsidian has not created its local vault-list file | Open Obsidian once, close it, and select **Register now** again. |+| Registration asks you to open Obsidian first | The vault-list write failed unexpectedly (Jarvis normally creates the list itself when Obsidian has never been launched) | Open Obsidian once, close it, and select **Register now** again. || Registration reports a rollback or unclear status | The local vault-list file could not be read, updated, or verified safely | Stop retrying, confirm Obsidian still opens normally, and keep the recovery copy. Follow the main troubleshooting guide before any manual restore. || Obsidian opens, but Jarvis shows old search results | The files and the derived search index are out of step, or the watcher was unavailable | Confirm the health strip names the expected vault, select **Rebuild index**, and try the search again. || An existing-vault connection shows no older notes | Jarvis intentionally reads only the nested `Jarvis` folder | Move or copy only the notes you deliberately want Jarvis to use, after backing them up and reviewing their privacy. |diff --git a/jarvis/setup/obsidian.py b/jarvis/setup/obsidian.pyindex 6298b9dd0f..e13b7cc1f9 100644--- a/jarvis/setup/obsidian.py+++ b/jarvis/setup/obsidian.py@@ -321,12 +321,14 @@ def _normalize_for_compare(path: Path, platform: str | None = None) -> str:normalise (the expected vault path may not yet exist on disk).* Strip trailing backslashes and forward slashes — both Obsidian andPython sometimes emit a trailing separator on directory paths.- * Lowercase the whole string (Windows file system is case-insensitive- and this is a pure Windows feature).+ * Lowercase the whole string on Windows AND macOS — NTFS and the APFS+ default volume are both case-insensitive, so ``/Users/Casey`` and+ ``/users/casey`` name the same directory there. Linux stays+ case-sensitive."""plat = platform if platform is not None else sys.platformraw = str(path)- windows_style = plat == "win32" or (+ case_insensitive = plat in ("win32", "darwin") or (len(raw) >= 3 and raw[1] == ":" and raw[2] in ("\\", "/"))try:@@ -337,7 +339,7 @@ def _normalize_for_compare(path: Path, platform: str | None = None) -> str:s = str(resolved)while s.endswith(("\\", "/")):s = s[:-1]- return s.lower() if windows_style else s+ return s.lower() if case_insensitive else sdef is_vault_registered(vaults: list[VaultEntry], expected_vault_path: Path) -> bool:@@ -389,11 +391,15 @@ class RegisterResult(BaseModel):``status`` values:* ``"added"`` — vault was newly registered (or would have been, indry-run mode). ``vault_uuid`` is populated; ``backup_path`` is- populated unless this was a dry-run.+ populated unless this was a dry-run or a config bootstrap (a+ freshly created ``obsidian.json`` has no original to back up).* ``"already_registered"`` — the vault was already present in``obsidian.json``; no write happened.- * ``"config_missing"`` — ``obsidian.json`` does not exist. The- caller should ask the user to start Obsidian once first.+ * ``"config_missing"`` — kept for the HTTP surface: the+ ``mode="existing"`` route reuses it for user-input errors.+ :func:`register_vault` itself no longer returns it — a missing+ ``obsidian.json`` (Obsidian installed but never launched) is+ bootstrapped instead of refused.* ``"rolled_back"`` — write attempt failed (pre-validate, post-write verification, or unexpected exception). The original``obsidian.json`` was restored from backup when possible.@@ -427,6 +433,67 @@ def _next_backup_path(config_path: Path) -> Path:counter += 1+def _bootstrap_config_with_vault(+ cfg_path: Path,+ vault_path: Path,+) -> RegisterResult:+ """Create a fresh ``obsidian.json`` containing only the Jarvis vault.++ Runs when Obsidian is installed but has never been launched on this+ machine, so its config file does not exist yet (the normal state of a+ brand-new install on any OS). Obsidian adopts a pre-existing+ ``obsidian.json`` on first launch and shows the vault in its picker,+ so bootstrapping the index is equivalent to registering into an+ existing one. Same atomic pipeline as :func:`register_vault` minus the+ backup step — there is no original file to back up. On any failure the+ freshly created file is removed again so the "config never existed"+ state is restored exactly.+ """+ new_uuid = secrets.token_hex(8)+ tempfile_path: Path | None = None+ try:+ cfg_path.parent.mkdir(parents=True, exist_ok=True)+ data = {+ "vaults": {+ new_uuid: {+ "path": str(vault_path.resolve()),+ "ts": int(time.time() * 1000),+ "open": False,+ }+ }+ }+ tempfile_path = cfg_path.with_suffix(f".json.tmp-{secrets.token_hex(4)}")+ with open(tempfile_path, "w", encoding="utf-8", newline="") as fp:+ json.dump(data, fp, indent=2, ensure_ascii=False)+ fp.flush()+ os.fsync(fp.fileno())+ os.replace(tempfile_path, cfg_path)+ tempfile_path = None # successfully consumed++ verify_state = read_obsidian_vaults(config_path=cfg_path)+ if not is_vault_registered(verify_state.vaults, vault_path):+ try:+ cfg_path.unlink()+ except OSError:+ logger.debug("Could not remove bootstrapped config: %s", cfg_path)+ return RegisterResult(+ status="rolled_back",+ error="post-write verification failed",+ )++ return RegisterResult(status="added", vault_uuid=new_uuid, backup_path=None)++ except Exception as exc: # noqa: BLE001 — we must always return a result+ return RegisterResult(status="rolled_back", error=str(exc))++ finally:+ if tempfile_path is not None and tempfile_path.exists():+ try:+ tempfile_path.unlink()+ except OSError:+ logger.debug("Could not clean up tempfile: %s", tempfile_path)++def register_vault(vault_path: Path,*,@@ -438,7 +505,10 @@ def register_vault(Pipeline (every step is mandatory — no shortcuts):1. Default ``config_path`` to ``%APPDATA%\\obsidian\\obsidian.json``.- 2. If the file does not exist → return ``status="config_missing"``.+ 2. If the file does not exist (Obsidian installed but never launched),+ bootstrap it via :func:`_bootstrap_config_with_vault` and return its+ result. ``dry_run=True`` short-circuits with ``status="added"``+ without touching disk.3. Parse the JSON via :func:`read_obsidian_vaults`. On parse errorreturn ``status="rolled_back"`` with the error message.4. If the vault is already registered → return@@ -471,9 +541,17 @@ def register_vault("""cfg_path = config_path if config_path is not None else _default_obsidian_config_path()- # Step 2: config presence gate.+ # Step 2: config bootstrap. A missing obsidian.json means Obsidian has+ # never been launched on this machine — the normal state of a fresh+ # install. Refusing here used to dead-end the setup wizard ("open+ # Obsidian once, then click again"); Obsidian adopts a pre-created+ # index on first launch, so we create it instead. The write is still+ # user-consented: this function only runs from the explicit register+ # action (wizard click / CLI), never from a status poll (ADR-0015).if not cfg_path.exists():- return RegisterResult(status="config_missing")+ if dry_run:+ return RegisterResult(status="added", vault_uuid=secrets.token_hex(8))+ return _bootstrap_config_with_vault(cfg_path, vault_path)# Step 3: parse existing state.try:diff --git a/jarvis/ui/web/setup_routes.py b/jarvis/ui/web/setup_routes.pyindex 0431235e7e..5b85e9713a 100644--- a/jarvis/ui/web/setup_routes.py+++ b/jarvis/ui/web/setup_routes.py@@ -10,9 +10,11 @@ Endpoints powering the Desktop App's "Obsidian" setup card:(spec A6).* ``POST /api/setup/obsidian/register`` — register a vault for Jarvis'swiki. ``mode="separate"`` (default, backward compatible) registers the- Jarvis-owned vault in ``obsidian.json``, mirroring+ Jarvis-owned vault in ``obsidian.json`` — creating a fresh index when+ Obsidian was installed but never launched — mirroring:class:`jarvis.setup.obsidian.RegisterResult` semantics: ``added`` and- ``already_registered`` => 200, ``config_missing`` => 409,+ ``already_registered`` => 200, ``config_missing`` => 409 (defensive+ only; the separate-mode writer bootstraps a missing config instead),``rolled_back`` => 500. ``mode="existing"`` instead repoints``[wiki_integration].vault_root`` INTO ``<existing_vault>/Jarvis`` soevery wiki write stays contained inside the user's own vault.@@ -319,9 +321,11 @@ def obsidian_register(Status mapping:* ``added`` -> HTTP 200* ``already_registered`` -> HTTP 200 (``separate`` mode only)- * ``config_missing`` -> HTTP 409 for ``separate`` (Obsidian was- never started); HTTP 200 for ``existing`` (the given path does not- exist — a user-input error the UI shows inline, not a server fault)+ * ``config_missing`` -> HTTP 409 for ``separate`` (defensive:+ the writer now bootstraps a missing ``obsidian.json`` itself, so+ this branch only fires on a future regression); HTTP 200 for+ ``existing`` (the given path does not exist — a user-input error+ the UI shows inline, not a server fault)* ``rolled_back`` -> HTTP 500 (write failure, restored)Unexpected exceptions are translated to HTTP 500 with adiff --git a/tests/unit/setup/test_obsidian_detector.py b/tests/unit/setup/test_obsidian_detector.pyindex a02b884c30..f53ac905b0 100644--- a/tests/unit/setup/test_obsidian_detector.py+++ b/tests/unit/setup/test_obsidian_detector.py@@ -344,6 +344,22 @@ def test_is_vault_registered_empty_vault_list() -> None:assert is_vault_registered([], Path(r"C:\anything")) is False+def test_normalize_for_compare_case_insensitive_on_macos() -> None:+ """macOS default APFS volumes are case-insensitive: differing case must+ normalise identically on darwin, but stay distinct on Linux."""+ from jarvis.setup.obsidian import _normalize_for_compare++ upper = Path("/Users/Casey/.personal-jarvis/wiki/obsidian-vault")+ lower = Path("/users/casey/.personal-jarvis/wiki/obsidian-vault")++ assert _normalize_for_compare(upper, platform="darwin") == (+ _normalize_for_compare(lower, platform="darwin")+ )+ assert _normalize_for_compare(upper, platform="linux") != (+ _normalize_for_compare(lower, platform="linux")+ )++def test_is_vault_registered_for_subdirectory_of_registered_vault(tmp_path: Path,) -> None:diff --git a/tests/unit/setup/test_obsidian_register.py b/tests/unit/setup/test_obsidian_register.pyindex c07639391a..e356052a8a 100644--- a/tests/unit/setup/test_obsidian_register.py+++ b/tests/unit/setup/test_obsidian_register.py@@ -31,19 +31,66 @@ def _write_cfg(cfg_path: Path, payload: dict) -> None:# ----------------------------------------------------------------------------# (a) config_missing+# (a) missing config → bootstrap# ----------------------------------------------------------------------------def test_register_vault_config_missing(tmp_path: Path) -> None:- """No obsidian.json on disk → status=config_missing, no side effects."""- cfg = tmp_path / "obsidian" / "obsidian.json" # never created+def test_register_vault_bootstraps_missing_config(tmp_path: Path) -> None:+ """No obsidian.json on disk (Obsidian never launched) → the register+ click creates a fresh index containing the vault, status=added."""+ cfg = tmp_path / "obsidian" / "obsidian.json" # dir + file do not existvault = tmp_path / "Vault"+ vault.mkdir()result = register_vault(vault, config_path=cfg)assert isinstance(result, RegisterResult)- assert result.status == "config_missing"- assert result.vault_uuid is None+ assert result.status == "added"+ assert result.vault_uuid is not None+ # A bootstrapped config has no original to back up.assert result.backup_path is None+ data = json.loads(cfg.read_text(encoding="utf-8"))+ entry = data["vaults"][result.vault_uuid]+ assert Path(entry["path"]).resolve() == vault.resolve()+ assert entry["open"] is False+ # Registering again is idempotent against the bootstrapped file.+ second = register_vault(vault, config_path=cfg)+ assert second.status == "already_registered"+++def test_register_vault_missing_config_dry_run_touches_nothing(+ tmp_path: Path,+) -> None:+ """dry_run with a missing obsidian.json previews success without+ creating the file (parity with the existing-config dry-run contract)."""+ cfg = tmp_path / "obsidian" / "obsidian.json"+ vault = tmp_path / "Vault"+ vault.mkdir()++ result = register_vault(vault, config_path=cfg, dry_run=True)++ assert result.status == "added"+ assert result.vault_uuid is not None+ assert not cfg.exists()+ assert not cfg.parent.exists()+++def test_register_vault_bootstrap_failure_rolls_back(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A failed bootstrap write reports rolled_back and leaves no file."""+ cfg = tmp_path / "obsidian" / "obsidian.json"+ vault = tmp_path / "Vault"+ vault.mkdir()++ def _boom(*_a, **_kw): # type: ignore[no-untyped-def]+ raise OSError("disk full")++ monkeypatch.setattr(mod.json, "dump", _boom)++ result = register_vault(vault, config_path=cfg)++ assert result.status == "rolled_back"+ assert result.error is not None+ assert "disk full" in result.errorassert not cfg.exists()@@ -191,7 +238,7 @@ def test_register_vault_write_failure_rolls_back(original_bytes = cfg.read_bytes()def _boom(*_a, **_kw): # type: ignore[no-untyped-def]- raise IOError("disk full")+ raise OSError("disk full")monkeypatch.setattr(mod.json, "dump", _boom)diff --git a/tests/unit/ui/test_setup_routes.py b/tests/unit/ui/test_setup_routes.pyindex 9e6c31fdc9..7b76ed3e62 100644--- a/tests/unit/ui/test_setup_routes.py+++ b/tests/unit/ui/test_setup_routes.py@@ -252,7 +252,8 @@ def test_register_already_registered(def test_register_config_missing_returns_409(monkeypatch: pytest.MonkeyPatch, client_factory) -> None:- """obsidian.json missing -> 409 so the UI can ask the user to launch Obsidian."""+ """A writer-reported config_missing still maps to 409 (defensive: the+ writer itself now bootstraps a missing obsidian.json instead)."""_, client, _vault = client_factory()monkeypatch.setattr(