# File Editing Tools

Tools that write, remove and restore files, and list their recorded versions.

| Tool | Description |
|---|---|
| `write_file` | `filename` is required and is absolute or relative to the work directory. `mode=write` creates or replaces a file with `write_content`; `mode=patch` applies `patch_contents`. Each patch requires `old_string` and `new_string` and accepts `replace_all`. Anchors resolve against the original contents; edits on the same line are allowed if their ranges do not overlap. An empty `new_string` deletes the match; with `replace_all` it deletes every match. Ambiguous matches without `replace_all`, overlapping edits, and patches that would empty a non-empty file reject the whole batch. Patches are limited to 1 MiB. To change an existing file, read it with `read_files` in this turn and leave it unchanged on disk; a successful write counts as a fresh read. `mode=remove` (added in v1.5.0, replacing `remove_file`) moves the file aside into `~/.config/agenvoy/.store/temp/` instead of deleting it, records the move in file history and returns where it went; `restore_file` puts it back. Every `mode=remove` call asks for confirmation unless the user already allowed every call for this turn, and it is used only on an explicit request or a Skill step; several files at once go through `run_command` `rm`, which moves them aside the same way. Since v1.5.0 a target on `denied_path` or inside `~/.config/agenvoy` (except `download/`) is refused with `[Denied]` in every mode and no approval lifts it; skills → `write_skill`, hooks → `write_hook`, script tools → `write_tool`. Not available to subagent legs. The default display label is `Write`; patch mode displays `Edit` and remove mode `Remove` |
| `restore_file` | Added in v1.3.11, replacing `edit_file(mode=restore)`. Puts a recorded version back by `version` (an id from a `file_history` row, which names both the file and the state; takes precedence over `task_id`), or undoes a whole task with `task_id` (a task id from `chat_history`, or `current` for the task running now), returning every file that task touched to before it ran; `filename` together with `task_id` narrows the undo to that one file. Send all three fields: use `0` for an unused version and an empty string for an unused task ID or filename. It also brings back a file `write_file(mode=remove)` or `run_command` `rm` moved aside. Every call asks for confirmation unless the user already allowed every call for this turn. Not available to subagent legs. The tool-call line reads `Restore(...)` with the path, `version N` or the task id |
| `file_history` | Recorded versions of every file the tools changed — when each changed, what the task was after, and what the content was. `mode=list` returns versions newest-first, filterable by `path`, `task_id`, `from`/`to` local time, and `limit` (capped at 24); `mode=read` diffs the newest recorded version of each path against what is on disk now. This is the snapshot layer `restore_file` restores from |

`remove_file` (added in v1.3.11) was Removed in v1.5.0; use `write_file(mode=remove)`.

`edit_file` was Removed in v1.3.20; use `write_file`. Replace `content` with `write_content` and `targets` with `patch_contents`.
