Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(config): honor VIBE_TRADING_HOME for autopilot runs, alpha-bench cache/reports and gildata codes

Rudy Celekli6302b1e1d747
diff --git a/agent/backtest/loaders/gildata_codes.py b/agent/backtest/loaders/gildata_codes.py
index 9fbec8074..589251179 100644
--- a/agent/backtest/loaders/gildata_codes.py
+++ b/agent/backtest/loaders/gildata_codes.py
@@ -27,6 +27,7 @@ from pathlib import Path
from typing import Any, Callable, Dict, Optional
from src.config.writer import _write_json_atomically
+from src.config.paths import get_runtime_root
logger = logging.getLogger(__name__)
@@ -56,7 +57,7 @@ def _normalize_ref(code: str) -> str:
def _cache_path() -> Path:
- return Path.home() / ".vibe-trading" / "cache" / _CACHE_FILENAME
+ return get_runtime_root() / "cache" / _CACHE_FILENAME
def _load_cache() -> Dict[str, Any]:
diff --git a/agent/src/tools/alpha_bench_tool.py b/agent/src/tools/alpha_bench_tool.py
index 574ceca73..617b3b4e6 100644
--- a/agent/src/tools/alpha_bench_tool.py
+++ b/agent/src/tools/alpha_bench_tool.py
@@ -45,6 +45,7 @@ import pandas as pd
from backtest.loaders.cn_adjust import apply_qfq as _apply_qfq
from src.agent.tools import BaseTool
from src.config.accessor import get_env_config
+from src.config.paths import get_runtime_root
logger = logging.getLogger(__name__)
@@ -124,7 +125,7 @@ def _load_universe_panel(
)
start, end = _parse_period(period)
- cache_dir = Path.home() / ".vibe-trading" / "cache"
+ cache_dir = get_runtime_root() / "cache"
cache_path = cache_dir / f"{universe}_{start}_{end}.pkl"
if use_cache and cache_path.is_file():
cached = _read_pickle_cache(cache_path)
@@ -1251,7 +1252,7 @@ def _render_html_manual(ctx: dict[str, Any]) -> str:
def _default_output_dir() -> Path:
- return Path.home() / ".vibe-trading" / "reports"
+ return get_runtime_root() / "reports"
def run_alpha_bench(**kwargs: Any) -> dict[str, Any]:
diff --git a/agent/src/tools/autopilot_tool.py b/agent/src/tools/autopilot_tool.py
index 575bd9ed4..91cecdbbb 100644
--- a/agent/src/tools/autopilot_tool.py
+++ b/agent/src/tools/autopilot_tool.py
@@ -16,6 +16,7 @@ from pathlib import Path
from typing import Any
from src.agent.tools import BaseTool
+from src.config.paths import get_runs_dir
from src.hypotheses import HypothesisRegistry
@@ -250,7 +251,7 @@ def _validate_backtest_dates(start_date: str, end_date: str) -> None:
def _run_dir_for_hypothesis(hypothesis_id: str) -> Path:
"""Return a path-contained run directory for any persisted hypothesis id."""
suffix = hashlib.sha256(hypothesis_id.encode("utf-8")).hexdigest()[:12]
- return Path.home() / ".vibe-trading" / "runs" / f"autopilot_{suffix}"
+ return get_runs_dir() / f"autopilot_{suffix}"
class GenerateBacktestConfigTool(BaseTool):
diff --git a/agent/tests/test_runtime_root_cache_report_dirs.py b/agent/tests/test_runtime_root_cache_report_dirs.py
new file mode 100644
index 000000000..bbf34cf35
--- /dev/null
+++ b/agent/tests/test_runtime_root_cache_report_dirs.py
@@ -0,0 +1,35 @@
+"""Autopilot run dirs, alpha-bench cache/reports and the gildata code cache
+must follow ``VIBE_TRADING_HOME`` like the rest of the runtime state."""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+
+
+def custom_root(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
+ root = tmp_path / "vt-home"
+ monkeypatch.setenv("VIBE_TRADING_HOME", str(root))
+ return root
+
+
+def test_autopilot_run_dir_honors_runtime_root(custom_root: Path) -> None:
+ from src.tools import autopilot_tool
+
+ run_dir = autopilot_tool._run_dir_for_hypothesis("hyp-1")
+ assert run_dir.parent == custom_root / "runs"
+ assert run_dir.name.startswith("autopilot_")
+
+
+def test_alpha_bench_report_dir_honors_runtime_root(custom_root: Path) -> None:
+ from src.tools import alpha_bench_tool
+
+ assert alpha_bench_tool._default_output_dir() == custom_root / "reports"
+
+
+def test_gildata_code_cache_honors_runtime_root(custom_root: Path) -> None:
+ from backtest.loaders import gildata_codes
+
+ assert gildata_codes._cache_path() == custom_root / "cache" / "gildata-codes.json"