edit_file
Apply text replacements to a file, generate a unified diff of changes, and update the file atomically. Specify file path and edit operations with 'oldText' and 'newText' keys.
Instructions
Apply multiple text replacements to a file and return a unified diff.
Args: path (str): File path to edit (absolute or relative to allowed directories) edits (List[Dict[str, str]]): List of edit operations, each with 'oldText' and 'newText' keys
Returns: str: Unified diff showing changes made, or error message if failed
Note: - Path must be within allowed directory roots - File must be a UTF-8 text file - Edits are applied sequentially in the order provided - Each 'oldText' must match exactly (first occurrence is replaced) - Returns unified diff format showing before/after changes - File is atomically updated using temporary file - If no changes made, returns 'No changes made.'
Input Schema
Name | Required | Description | Default |
---|---|---|---|
edits | Yes | ||
path | Yes |