patch_file
Replace the first exact occurrence of a string in a file with a new string, preserving whitespace and indentation. Use for targeted edits without rewriting the entire file.
Instructions
Find the FIRST (and only) occurrence of old_str in a file and replace it with new_str. PREFER this over write_file for edits to existing files — only send the changed part. old_str must match EXACTLY, including whitespace and indentation. Make it specific enough that it is unique in the file. Returns the line number of the edit on success, or an error with a file preview to help you correct old_str.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| new_str | Yes | ||
| old_str | Yes | ||
| file_path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |