Skip to content

The agent that grows with you

test: give the rewrite-hint fixtures a read baseline; align docs row with schema

teknium14613f895abc6
diff --git a/tests/tools/test_write_file_rewrite_hint.py b/tests/tools/test_write_file_rewrite_hint.py
index 5ed14c3b60e..16e39ff40c8 100644
--- a/tests/tools/test_write_file_rewrite_hint.py
+++ b/tests/tools/test_write_file_rewrite_hint.py
@@ -5,7 +5,7 @@ while `patch` (1.3k chars/call) succeeded 99.7% of the time; the tool result is
"""
import json
-from tools.file_tools import write_file_tool
+from tools.file_tools import read_file_tool, write_file_tool
def _big(n_lines=800):
@@ -17,6 +17,7 @@ def test_rewrite_of_a_large_file_with_few_changes_gets_a_patch_hint(tmp_path):
old = _big()
f.write_text(old, encoding="utf-8")
new = old.replace("line 400:", "line 400 (edited):").replace("line 401:", "line 401 (edited):")
+ assert "error" not in json.loads(read_file_tool(str(f), task_id="t")) # the read→rewrite pattern the hint targets
r = json.loads(write_file_tool(str(f), new, task_id="t"))
assert r.get("error") is None and f.read_text(encoding="utf-8") == new # the write still happens
assert "use patch" in r["hint"] and "798 of 800 lines were already on disk" in r["hint"]
@@ -27,8 +28,10 @@ def test_new_files_small_files_and_real_rewrites_get_no_hint(tmp_path):
assert "hint" not in json.loads(write_file_tool(str(new_file), _big(), task_id="t"))
small = tmp_path / "small.py"
small.write_text("a\nb\n", encoding="utf-8")
+ read_file_tool(str(small), task_id="t")
assert "hint" not in json.loads(write_file_tool(str(small), "a\nc\n", task_id="t"))
big = tmp_path / "big.py"
big.write_text(_big(), encoding="utf-8")
+ read_file_tool(str(big), task_id="t")
rewritten = "\n".join(f"other {i}: " + "y" * 40 for i in range(800)) + "\n"
assert "hint" not in json.loads(write_file_tool(str(big), rewritten, task_id="t"))
diff --git a/website/docs/reference/tools-reference.md b/website/docs/reference/tools-reference.md
index c84ffd3a429..20f30ae40cd 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. 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. | — |
+| `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 an existing file, call read_file first: write_file refuses (file untouched) when the task has no current full read/write of the file or the file changed on disk since — on refusal, read_file, merge, retry. Auto-runs syntax checks on .py/.json/.yaml/.toml and other linted languages; only NEW errors introduced by the write are surfaced. | — |
## `homeassistant` toolset