diff --git a/tests/tools/test_write_verification.py b/tests/tools/test_write_verification.py index bf6812ac14..d784ded760 100644 --- a/tests/tools/test_write_verification.py +++ b/tests/tools/test_write_verification.py @@ -33,6 +33,10 @@ class TestWriteVerification: # still report verified. f = workdir / "win.txt" f.write_bytes(b"old line\r\n") + # Establish a full-read baseline: write_file refuses to overwrite + # existing files the task has never read (stale-write guard). + from tools.file_tools import read_file_tool + json.loads(read_file_tool(str(f), task_id="t-wv")) r = json.loads(write_file_tool(str(f), "new line\nsecond\n", task_id="t-wv")) assert "error" not in r assert r.get("verified") is True diff --git a/website/docs/reference/tools-reference.md b/website/docs/reference/tools-reference.md index 49cff5f2a0..c84ffd3a42 100644 --- a/website/docs/reference/tools-reference.md +++ b/website/docs/reference/tools-reference.md @@ -115,7 +115,7 @@ Scoped to the Feishu document-comment handler. Drives comment read/write operati | `patch` | Targeted find-and-replace edits in files. Use this instead of sed/awk in terminal. Uses fuzzy matching (9 strategies) so minor whitespace/indentation differences won't break it. Returns a unified diff. Auto-runs syntax checks after editing… | — | | `read_file` | Read a text file with line numbers and pagination. Use this instead of cat/head/tail in terminal. Output format: 'LINE_NUM\|CONTENT'. Suggests similar filenames if not found. Use offset and limit for large files. Reads exceeding ~100K characters are truncated on a line boundary and return a next_offset. Jupyter notebooks (.ipynb), Word documents (.docx), and Excel workbooks (.xlsx) a… | — | | `search_files` | Search file contents or find files by name. Use this instead of grep/rg/find/ls in terminal. Ripgrep-backed, faster than shell equivalents. Content search (target='content'): Regex search inside files. Output modes: full matches with line… | — | -| `write_file` | Write content to a file, completely replacing existing content. Use this instead of echo/cat heredoc in terminal. Creates parent directories automatically. OVERWRITES the entire file — use 'patch' for targeted edits. Auto-runs syntax checks on .py/.json/.yaml/.toml and other linted languages; only NEW errors introduced by the write are surfaced. | — | +| `write_file` | Write content to a file, completely replacing existing content. Use this instead of echo/cat heredoc in terminal. Creates parent directories automatically. OVERWRITES the entire file — use 'patch' for targeted edits. For existing files in host-visible workspaces, the file must be read (full, unredacted) or written by the same task first: writes without a current baseline, and writes after an external on-disk modification, are refused before any disk mutation so a stale conversation copy can never clobber newer content. Auto-runs syntax checks on .py/.json/.yaml/.toml and other linted languages; only NEW errors introduced by the write are surfaced. | — | ## `homeassistant` toolset