From 2b394123559b2bf900d65fa467e1a61f7cf94566 Mon Sep 17 00:00:00 2001 From: Kenny Van de Maele Date: Tue, 2 Jun 2026 04:45:21 +0200 Subject: [PATCH] Expand ~ in read_file and write_file paths (#781) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit read_file/write_file passed the raw path to open(), so a tilde path like ~/notes.txt failed ("not found") — the shell's ~ expansion never happened because there's no shell. Agents then fell back to bash to reach home-dir files. Expand ~ (and ~user) with os.path.expanduser before opening. Checks: python -m py_compile src/tool_execution.py. --- src/tool_execution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tool_execution.py b/src/tool_execution.py index c4294a6..972960c 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}