An always-on second brain you talk to. Voice notes in Telegram → typed, linked knowledge in your Obsidian vault. Runs 24/7 on the Claude subscription you already have.
Python ai-agentsai-automationclaudeclaude-codeebbinghausknowledge-graphllmmemory-systemobsidianpersonal-assistantpkmproductivitypythonsecond-braintelegram-botvoice-assistant
fix(config): resolve vault_path/runtime_dir to absolute paths
smixsf0abe30c47a5
diff --git a/src/d_brain/config.py b/src/d_brain/config.pyindex de0788f..55143b4 100644--- a/src/d_brain/config.py+++ b/src/d_brain/config.py@@ -72,7 +72,11 @@ class Settings(BaseSettings):def _expand_user(cls, v: Path) -> Path:# pydantic-settings keeps "~" literal; the cron CLI expanduser-s —# expand here too or the bot and CLI split into different state dirs.- return v.expanduser()+ # resolve() makes the path ABSOLUTE: the brain runs `cd vault && cat+ # deploy/brain-system.md`, and a relative vault_path would make that+ # cat (and --mcp-config) resolve against the wrong cwd → persona+ # silently not loaded. One root of absoluteness for all derived paths.+ return v.expanduser().resolve()@propertydef cron_dir(self) -> Path:diff --git a/src/d_brain/cron.py b/src/d_brain/cron.pyindex 655903e..0e93deb 100644--- a/src/d_brain/cron.py+++ b/src/d_brain/cron.py@@ -23,7 +23,11 @@ from d_brain.services.cron_store import (def _default_cron_dir() -> str:- runtime = Path(os.environ.get("RUNTIME_DIR", "~/.dbrain")).expanduser()+ # Mirror Settings._expand_user EXACTLY (expanduser + resolve): the bot+ # ticker reads the resolved dir, so a bare expanduser here would split the+ # CLI's jobs.json from the ticker's under any symlinked runtime path+ # (container bind-mount, NFS home, /home → /srv/home).+ runtime = Path(os.environ.get("RUNTIME_DIR", "~/.dbrain")).expanduser().resolve()return str(runtime / "cron")diff --git a/tests/test_config.py b/tests/test_config.pyindex e5531e2..0de84b7 100644--- a/tests/test_config.py+++ b/tests/test_config.py@@ -44,8 +44,11 @@ def test_cron_fields_have_safe_defaults():def test_cron_dir_lives_under_runtime_dir():+ # Assert the invariant against the resolved runtime_dir — not a literal+ # path: the validator now resolve()s, and on macOS /tmp is a symlink to+ # /private/tmp, so a hardcoded "/tmp/rt/cron" would spuriously mismatch.s = _settings(runtime_dir=Path("/tmp/rt"))- assert s.cron_dir == Path("/tmp/rt/cron")+ assert s.cron_dir == s.runtime_dir / "cron"def test_tilde_paths_are_expanded():@@ -57,3 +60,14 @@ def test_tilde_paths_are_expanded():assert "~" not in s.runtime_dir.partsassert s.vault_path.is_absolute()assert "~" not in s.vault_path.parts+++def test_relative_paths_are_resolved_absolute():+ # The default vault_path is the RELATIVE "./vault". The brain starts with+ # `cd vault && cat deploy/brain-system.md`, so a relative persona path+ # resolves against vault/ after the cd and loads NOTHING — the brain boots+ # with no persona and no reply contract. Resolving here keeps the derived+ # project_root / persona / mcp paths absolute regardless of cwd.+ s = _settings(runtime_dir="./rt", vault_path="./vault")+ assert s.runtime_dir.is_absolute()+ assert s.vault_path.is_absolute()diff --git a/tests/test_cron_cli.py b/tests/test_cron_cli.pyindex adcde5d..1cad894 100644--- a/tests/test_cron_cli.py+++ b/tests/test_cron_cli.py@@ -6,7 +6,8 @@ human-readable output, exit 0 on success, exit 2 on bad input.from datetime import UTC, datetime, timedelta-from d_brain.cron import main+from d_brain.config import Settings+from d_brain.cron import _default_cron_dir, mainfrom d_brain.services.cron_store import CronStore@@ -175,3 +176,25 @@ def test_enable_reenables_and_resets_errors(tmp_path):assert job.enabled is Trueassert job.state.consecutive_errors == 0assert job.state.next_run is not None+++def test_cli_and_bot_agree_on_cron_dir_under_symlinked_runtime(tmp_path, monkeypatch):+ """The CLI default cron dir MUST equal the bot's Settings.cron_dir even+ when RUNTIME_DIR contains a symlink — otherwise the brain's `cron add`+ writes jobs.json where the in-bot ticker never looks (and the two+ jobs.lock files give no mutual exclusion). Both sides resolve()."""+ real = tmp_path / "real_runtime"+ real.mkdir()+ link = tmp_path / "link_runtime"+ link.symlink_to(real)+ monkeypatch.setenv("RUNTIME_DIR", str(link))++ s = Settings(+ telegram_bot_token="t",+ deepgram_api_key="d",+ runtime_dir=str(link),+ _env_file=None,+ )+ from pathlib import Path++ assert Path(_default_cron_dir()) == s.cron_dirdiff --git a/tests/test_runtime.py b/tests/test_runtime.pyindex e5ba745..fdba95d 100644--- a/tests/test_runtime.py+++ b/tests/test_runtime.py@@ -83,6 +83,33 @@ def test_get_cron_session_refuses_without_persona(tmp_path):rt.get_cron_session(s)+def test_relative_vault_path_yields_absolute_brain_paths(tmp_path, monkeypatch):+ """A fork installed with the default relative VAULT_PATH=./vault must+ still get ABSOLUTE paths into the start command. The brain runs+ `cd vault && cat deploy/brain-system.md`: a relative persona path would+ resolve against vault/ AFTER the cd and load nothing — silently booting a+ personality-less agent (the boot assertion passes because it reads from+ the bot's cwd, not the brain's). Resolving vault_path at config time keeps+ project_root / persona / mcp absolute regardless of the brain's cwd."""+ rt.reset()+ monkeypatch.chdir(tmp_path)+ (tmp_path / "vault").mkdir()+ deploy = tmp_path / "deploy"+ deploy.mkdir()+ (deploy / "brain-system.md").write_text("# d-brain session contract\n")+ s = Settings(+ telegram_bot_token="t",+ deepgram_api_key="d",+ vault_path="./vault",+ runtime_dir="./rt",+ _env_file=None,+ )+ sess = rt.get_session(s)+ assert sess.system_prompt_file is not None+ assert sess.system_prompt_file.is_absolute()+ assert sess.work_dir.is_absolute()++def test_get_session_refuses_without_persona(tmp_path):"""runtime.py used to silently pass system_prompt_file=None when thepersona file is missing — booting a personality-less vanilla agent.