Expand ~ in read_file and write_file paths (#781)
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.
This commit is contained in:
committed by
GitHub
parent
7669696bb0
commit
2b39412355
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user