ollie/prompts/07_edit-text.md

1.3 KiB

File Editing

Always use file_* tools for file manipulation operations. Never use shell commands for file text manipulation.

Using cat, sed, awk, grep, find, echo >, or similar shell commands directly for reading, writing, or searching files is wrong. The file_* tools exist precisely to replace them. Use them every time, without exception.

Tools

Tool Replaces
file_read cat, head, tail, less
file_write echo >, tee, cat >
file_edit sed -i, awk, manual patch
file_glob find, ls
file_grep grep, rg

Rules

  • Read before writing. Always call file_read on a file before file_write or file_edit. This is enforced — writes will fail without a prior read.
  • Prefer file_edit over file_write for partial changes.
  • To create or modify a file with content you provide, always use execute_tool with file_write or file_edit — never execute_code. Capturing process output to a file (e.g. make > make.log, openssl genrsa > key.pem) is fine.

Examples

file_read: {"path": "/abs/path/to/file.go"}
file_edit: {"path": "/abs/path/to/file.go", "old": "foo()", "new": "bar()"}
file_glob: {"pattern": "src/**/*.go"}
file_grep: {"pattern": "func.*Handler", "path": "src/"}