fix(tools): refuse an empty write_file body that would truncate a file

The handler opened the target in "w" mode without looking at the body, so a
call whose content section was lost by a parser cut the file to 0 bytes and
still answered exit_code=0 (#6414). Gate the truncating open on the size the
file has on disk — the read just above it answers "" for bytes it cannot
decode, so an undecodable target would otherwise look empty — and let only an
inline-JSON content key that is literally an empty string declare the clear.

Also stop turning a null content into the four characters "None", which could
be neither refused as a lost body nor honoured as an empty write.
This commit is contained in:
Aashish
2026-10-01 20:18:33 -06:00
committed by Nicholai
parent 6749d6cd81
commit 9056bac95b
3 changed files with 252 additions and 2 deletions
+3 -1
View File
@@ -609,7 +609,9 @@ Read a file and return its contents.""",
<file path>
<file contents>
```
Write content to a file. First line is the path, rest is the content.""",
Write content to a file. First line is the path, rest is the content. An empty body is
refused when the target already holds data — to clear a file on purpose, send
`{"path": "<file path>", "content": ""}` instead.""",
"edit_file": """\
```edit_file