"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: expand read_file/write_file/edit_file to access configured extra file roots
skloxo360a0696c628
diff --git a/agent/src/tools/edit_file_tool.py b/agent/src/tools/edit_file_tool.pyindex 1f636ef60..eefc5de21 100644--- a/agent/src/tools/edit_file_tool.py+++ b/agent/src/tools/edit_file_tool.py@@ -3,11 +3,13 @@from __future__ import annotationsimport json+from pathlib import Pathfrom typing import Anyfrom src.agent.tools import BaseToolfrom src.tools.path_utils import safe_path as _safe_pathfrom src.tools.path_utils import safe_run_dir as _safe_run_dir+from src.tools.path_utils import _allowed_file_rootsfrom src.tools.redaction import redact_internal_paths@@ -43,25 +45,41 @@ class EditFileTool(BaseTool):run_dir = kwargs.get("run_dir")if not run_dir:- return json.dumps(- {- "status": "error",- "error": "run_dir is required for edit_file",- },- ensure_ascii=False,- )-- try:- run_root = _safe_run_dir(str(run_dir))- resolved = _safe_path(file_path, run_root)- except ValueError as exc:- return json.dumps(- {- "status": "error",- "error": str(exc),- },- ensure_ascii=False,- )+ # Allow edit if path resolves inside a configured extra file root+ candidate = Path(file_path).expanduser().resolve()+ for extra_root in _allowed_file_roots():+ if candidate.is_relative_to(extra_root):+ resolved = candidate+ break+ else:+ return json.dumps(+ {+ "status": "error",+ "error": "run_dir is required for edit_file",+ },+ ensure_ascii=False,+ )+ else:+ try:+ run_root = _safe_run_dir(str(run_dir))+ resolved = _safe_path(file_path, run_root)+ except ValueError as exc:+ # Fallback: check if path resolves inside a configured extra file root+ candidate = Path(file_path).expanduser().resolve()+ allowed = False+ for extra_root in _allowed_file_roots():+ if candidate.is_relative_to(extra_root):+ allowed = True+ resolved = candidate+ break+ if not allowed:+ return json.dumps(+ {+ "status": "error",+ "error": str(exc),+ },+ ensure_ascii=False,+ )if not resolved.exists():return json.dumps(diff --git a/agent/src/tools/read_file_tool.py b/agent/src/tools/read_file_tool.pyindex 8882849ac..92ffcc5fc 100644--- a/agent/src/tools/read_file_tool.py+++ b/agent/src/tools/read_file_tool.py@@ -9,6 +9,7 @@ from typing import Anyfrom src.agent.tools import BaseToolfrom src.tools.path_utils import safe_path as _safe_pathfrom src.tools.path_utils import safe_run_dir as _safe_run_dir+from src.tools.path_utils import _allowed_file_rootsfrom src.tools.redaction import redact_internal_paths_OUTPUT_LIMIT = 50_000@@ -59,6 +60,11 @@ 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/)+ for extra_root in _allowed_file_roots():+ if extra_root not in allowed_roots:+ allowed_roots.append(extra_root)+# Strip redundant "skills/" prefix that LLMs sometimes addpaths_to_try = [file_path]if file_path.startswith("skills/"):diff --git a/agent/src/tools/write_file_tool.py b/agent/src/tools/write_file_tool.pyindex fbfcf03e0..293c4d9f5 100644--- a/agent/src/tools/write_file_tool.py+++ b/agent/src/tools/write_file_tool.py@@ -3,11 +3,13 @@from __future__ import annotationsimport json+from pathlib import Pathfrom typing import Anyfrom src.agent.tools import BaseToolfrom src.tools.path_utils import safe_path as _safe_pathfrom src.tools.path_utils import safe_run_dir as _safe_run_dir+from src.tools.path_utils import _allowed_file_rootsfrom src.tools.redaction import redact_internal_paths@@ -41,25 +43,41 @@ class WriteFileTool(BaseTool):run_dir = kwargs.get("run_dir")if not run_dir:- return json.dumps(- {- "status": "error",- "error": "run_dir is required for write_file",- },- ensure_ascii=False,- )-- try:- run_root = _safe_run_dir(str(run_dir))- resolved = _safe_path(file_path, run_root)- except ValueError as exc:- return json.dumps(- {- "status": "error",- "error": str(exc),- },- ensure_ascii=False,- )+ # Allow write if path resolves inside a configured extra file root+ candidate = Path(file_path).expanduser().resolve()+ for extra_root in _allowed_file_roots():+ if candidate.is_relative_to(extra_root):+ resolved = candidate+ break+ else:+ return json.dumps(+ {+ "status": "error",+ "error": "run_dir is required for write_file",+ },+ ensure_ascii=False,+ )+ else:+ try:+ run_root = _safe_run_dir(str(run_dir))+ resolved = _safe_path(file_path, run_root)+ except ValueError as exc:+ # Fallback: check if path resolves inside a configured extra file root+ candidate = Path(file_path).expanduser().resolve()+ allowed = False+ for extra_root in _allowed_file_roots():+ if candidate.is_relative_to(extra_root):+ allowed = True+ resolved = candidate+ break+ if not allowed:+ return json.dumps(+ {+ "status": "error",+ "error": str(exc),+ },+ ensure_ascii=False,+ )try:resolved.parent.mkdir(parents=True, exist_ok=True)