Skip to content

Self-hosted AI workspace.

Python

Expand ~ in read_file and write_file paths (#781)

Kenny Van de Maelee70df6cfe871
diff --git a/src/tool_execution.py b/src/tool_execution.py
index c4294a6a0..972960c11 100644
--- a/src/tool_execution.py
+++ b/src/tool_execution.py
@@ -373,7 +373,7 @@ async def _direct_fallback(
return {"output": output or "(no output)", "exit_code": rc or 0}
if tool == "read_file":
- path = content.split("\n", 1)[0].strip()
+ path = os.path.expanduser(content.split("\n", 1)[0].strip())
if not path:
return {"error": "read_file: path required", "exit_code": 1}
try:
@@ -395,7 +395,7 @@ async def _direct_fallback(
if tool == "write_file":
lines = content.split("\n", 1)
- path = lines[0].strip()
+ path = os.path.expanduser(lines[0].strip())
body = lines[1] if len(lines) > 1 else ""
if not path:
return {"error": "write_file: path required", "exit_code": 1}