Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(agent): let read_file resolve bundled workflow prompts

William Liaoaad296551693
diff --git a/agent/src/agent/context.py b/agent/src/agent/context.py
index 3f7c7ee9d..e344c201e 100644
--- a/agent/src/agent/context.py
+++ b/agent/src/agent/context.py
@@ -61,7 +61,7 @@ Choose the workflow by request type:
Do not write `run_backtest.py`.
-For full workflow details, consult `agent/prompts/task_routing.md` and `agent/prompts/identity_resolution.md`.
+For full workflow details, consult `prompts/task_routing.md` and `prompts/identity_resolution.md`.
## Attribution Layers
diff --git a/agent/src/tools/read_file_tool.py b/agent/src/tools/read_file_tool.py
index 7b14b0f99..fccb59780 100644
--- a/agent/src/tools/read_file_tool.py
+++ b/agent/src/tools/read_file_tool.py
@@ -23,7 +23,13 @@ class ReadFileTool(BaseTool):
parameters = {
"type": "object",
"properties": {
- "path": {"type": "string", "description": "File path relative to run_dir or skills/"},
+ "path": {
+ "type": "string",
+ "description": (
+ "File path relative to run_dir, skills/, or prompts/. "
+ "The skills/ and prompts/ prefixes always resolve to the bundled assets."
+ ),
+ },
"limit": {"type": "integer", "description": "Max number of lines to return (default: all)"},
},
"required": ["path"],
@@ -60,28 +66,47 @@ class ReadFileTool(BaseTool):
if skills_dir.exists():
allowed_roots.append(skills_dir.resolve())
+ # Read-only access to bundled agent workflow prompts. These are
+ # referenced by the system prompt for detailed routing guidance.
+ prompts_dir = Path(__file__).resolve().parents[2] / "prompts"
+ if prompts_dir.exists():
+ allowed_roots.append(prompts_dir.resolve())
+
# 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)
- # Strip redundant "skills/" prefix that LLMs sometimes add
- paths_to_try = [file_path]
- if file_path.startswith("skills/"):
- paths_to_try.append(file_path[len("skills/") :])
-
resolved = None
- for root in allowed_roots:
- for p in paths_to_try:
+ namespaced = False
+
+ # `skills/` and `prompts/` are namespaces bound to their dedicated
+ # read-only roots. Binding the prefix prevents a same-named file in
+ # run_dir (or another configured root) from shadowing bundled assets.
+ for prefix, root in (
+ ("skills/", skills_dir),
+ ("prompts/", prompts_dir),
+ ):
+ if file_path.startswith(prefix):
+ namespaced = True
try:
- candidate = _safe_path(p, root)
+ candidate = _safe_path(file_path[len(prefix) :], root)
+ except ValueError:
+ candidate = None
+ if candidate is not None and candidate.exists():
+ resolved = candidate
+ break
+
+ # Unprefixed paths search every allowed root, run_dir first.
+ if resolved is None and not namespaced:
+ for root in allowed_roots:
+ try:
+ candidate = _safe_path(file_path, root)
if candidate.exists():
resolved = candidate
break
except ValueError:
continue
- if resolved:
- break
if resolved is None:
return json.dumps(
diff --git a/agent/tests/test_file_tool_sandbox_security.py b/agent/tests/test_file_tool_sandbox_security.py
index 36b78cc28..e32929209 100644
--- a/agent/tests/test_file_tool_sandbox_security.py
+++ b/agent/tests/test_file_tool_sandbox_security.py
@@ -77,6 +77,61 @@ def test_read_and_edit_file_accept_configured_run_root(tmp_path: Path, monkeypat
assert target.read_text(encoding="utf-8") == "alpha gamma"
+ "path",
+ ("prompts/task_routing.md", "prompts/identity_resolution.md"),
+)
+def test_read_file_allows_bundled_agent_workflow_prompts(path: str) -> None:
+ """Prompt references in the system prompt must be readable by the agent."""
+ body = _body(ReadFileTool().execute(path=path))
+
+ assert body["status"] == "ok"
+ assert body["content"]
+
+
+def test_read_file_prompt_prefix_is_not_shadowed_by_run_dir(
+ tmp_path: Path, monkeypatch
+) -> None:
+ """`prompts/` binds to the bundled prompts root, never to a run_dir decoy."""
+ monkeypatch.setenv("VIBE_TRADING_ALLOWED_RUN_ROOTS", str(tmp_path))
+ decoy = tmp_path / "prompts" / "task_routing.md"
+ decoy.parent.mkdir(parents=True)
+ decoy.write_text("DECOY CONTENT", encoding="utf-8")
+
+ body = _body(
+ ReadFileTool().execute(path="prompts/task_routing.md", run_dir=str(tmp_path))
+ )
+
+ assert body["status"] == "ok"
+ assert "DECOY CONTENT" not in body["content"]
+ assert "Task Routing Reference" in body["content"]
+
+
+def test_read_file_skill_prefix_is_not_shadowed_by_run_dir(
+ tmp_path: Path, monkeypatch
+) -> None:
+ """`skills/` binds to the bundled skills root, never to a run_dir decoy."""
+ monkeypatch.setenv("VIBE_TRADING_ALLOWED_RUN_ROOTS", str(tmp_path))
+ decoy = tmp_path / "skills" / "data-routing" / "SKILL.md"
+ decoy.parent.mkdir(parents=True)
+ decoy.write_text("DECOY CONTENT", encoding="utf-8")
+
+ body = _body(
+ ReadFileTool().execute(path="skills/data-routing/SKILL.md", run_dir=str(tmp_path))
+ )
+
+ assert body["status"] == "ok"
+ assert "DECOY CONTENT" not in body["content"]
+ assert "data-routing" in body["content"]
+
+
+def test_read_file_prompt_prefix_cannot_escape_prompts_root() -> None:
+ """Traversal through the prompts namespace must be rejected."""
+ body = _body(ReadFileTool().execute(path="prompts/../agent.json"))
+
+ assert body["status"] == "error"
+
+
def test_backtest_rejects_unconfigured_absolute_run_dir(tmp_path: Path, monkeypatch) -> None:
monkeypatch.delenv("VIBE_TRADING_ALLOWED_RUN_ROOTS", raising=False)
(tmp_path / "code").mkdir()