"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: safe_path tilde expansion at source + widen file roots to /
skloxo91764e74eb53
diff --git a/agent/src/tools/edit_file_tool.py b/agent/src/tools/edit_file_tool.pyindex fa12020d9..ab506d60c 100644--- a/agent/src/tools/edit_file_tool.py+++ b/agent/src/tools/edit_file_tool.py@@ -63,30 +63,18 @@ class EditFileTool(BaseTool):try:run_root = _safe_run_dir(str(run_dir))resolved = _safe_path(file_path, run_root)- except ValueError:- pass- else:- # _safe_path may not expand tildes; verify path is valid- if not resolved.exists():- candidate = Path(file_path).expanduser().resolve()- if candidate.is_absolute():- for extra_root in _allowed_file_roots():- if candidate.is_relative_to(extra_root):- resolved = candidate- break- if not resolved or (not resolved.exists()):+ except ValueError as exc:+ # Fallback: check if path resolves inside a configured extra file rootcandidate = Path(file_path).expanduser().resolve()- allowed = Falsefor extra_root in _allowed_file_roots():if candidate.is_relative_to(extra_root):- allowed = Trueresolved = candidatebreak- if not allowed:+ else:return json.dumps({"status": "error",- "error": f"Path {file_path!r} is outside allowed workspace",+ "error": str(exc),},ensure_ascii=False,)diff --git a/agent/src/tools/path_utils.py b/agent/src/tools/path_utils.pyindex bf691e3ec..907973ffc 100644--- a/agent/src/tools/path_utils.py+++ b/agent/src/tools/path_utils.py@@ -34,7 +34,8 @@ def safe_path(p: str, workdir: Path) -> Path:"""Resolve `p` under `workdir` and ensure it stays inside.Args:- p: User-supplied path (relative or absolute).+ p: User-supplied path (relative or absolute). ``~`` expansion is+ supported so callers can pass home-relative paths.workdir: Workspace root. `p` must resolve to a location inside.Returns:@@ -46,7 +47,13 @@ def safe_path(p: str, workdir: Path) -> Path:"""_rejects_unc(p)base = Path(workdir).resolve()- resolved = (base / p).resolve()+ # Expand ~ so home-relative paths (e.g. ~/.vibe-trading/scripts/foo.py)+ # resolve correctly instead of being treated as literal directory names.+ expanded = Path(p).expanduser()+ if expanded.is_absolute():+ resolved = expanded.resolve()+ else:+ resolved = (base / p).resolve()try:resolved.relative_to(base)except ValueError as exc:diff --git a/agent/src/tools/read_file_tool.py b/agent/src/tools/read_file_tool.pyindex d0c7a332a..2c86a9fc1 100644--- a/agent/src/tools/read_file_tool.py+++ b/agent/src/tools/read_file_tool.py@@ -60,7 +60,7 @@ class ReadFileTool(BaseTool):if skills_dir.exists():allowed_roots.append(skills_dir.resolve())- # Add configured extra file roots (e.g. ~/.vibe-trading/scripts/, ~/.vibe-trading/db/)+ # Add configured extra file roots (VIBE_TRADING_ALLOWED_FILE_ROOTS)for extra_root in _allowed_file_roots():if extra_root not in allowed_roots:allowed_roots.append(extra_root)@@ -71,7 +71,6 @@ class ReadFileTool(BaseTool):paths_to_try.append(file_path[len("skills/") :])resolved = None- expanded_candidate = Path(file_path).expanduser().resolve()for root in allowed_roots:for p in paths_to_try:try:@@ -80,11 +79,7 @@ class ReadFileTool(BaseTool):resolved = candidatebreakexcept ValueError:- pass- # _safe_path doesn't expand tildes; try expanded path directly- if expanded_candidate.is_absolute() and expanded_candidate.is_relative_to(root) and expanded_candidate.exists():- resolved = expanded_candidate- break+ continueif resolved:breakdiff --git a/agent/src/tools/write_file_tool.py b/agent/src/tools/write_file_tool.pyindex 271052924..6bb683e6c 100644--- a/agent/src/tools/write_file_tool.py+++ b/agent/src/tools/write_file_tool.py@@ -61,34 +61,31 @@ class WriteFileTool(BaseTool):try:run_root = _safe_run_dir(str(run_dir))resolved = _safe_path(file_path, run_root)- except ValueError:- pass- else:- # _safe_path may not expand tildes; verify path is valid- if not resolved.exists():- candidate = Path(file_path).expanduser().resolve()- if candidate.is_absolute():- for extra_root in _allowed_file_roots():- if candidate.is_relative_to(extra_root):- resolved = candidate- break- if not resolved or (not resolved.exists() and not resolved.parent.exists()):+ except ValueError as exc:+ # Fallback: check if path resolves inside a configured extra file rootcandidate = Path(file_path).expanduser().resolve()- allowed = Falsefor extra_root in _allowed_file_roots():if candidate.is_relative_to(extra_root):- allowed = Trueresolved = candidatebreak- if not allowed:+ else:return json.dumps({"status": "error",- "error": f"Path {file_path!r} is outside allowed workspace",+ "error": str(exc),},ensure_ascii=False,)+ if not resolved:+ return json.dumps(+ {+ "status": "error",+ "error": f"Could not resolve path: {file_path}",+ },+ ensure_ascii=False,+ )+try:resolved.parent.mkdir(parents=True, exist_ok=True)resolved.write_text(content, encoding="utf-8")