edit_file
Replace a targeted line range in a file with new content, with options for base64 encoding and preserving the original indentation style.
Instructions
编辑文件内容,按行范围替换(startLine-endLine,1-based)。行号是必填的,必须指定要替换的行范围。Content is auto-normalized: CRLF/CR converted to LF, leading/trailing newlines stripped. Use content_base64 to avoid JSON escaping issues. Set preserve_indent=true to auto-convert new content indentation to match the original file's style (e.g., spaces → TABs).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Full path where to write/edit the file. Supports all drives. Example: D:\output\result.txt | |
| content | No | Content to write or insert into the file. Alternative to content_base64. | |
| endLine | No | 可选:结束行号(1-based,包含)。不传则只替换 startLine 这一行。 | |
| encoding | No | File encoding (default: utf8) | |
| startLine | Yes | 必填:起始行号(1-based,包含),指定要替换的起始行。 | |
| content_base64 | No | Base64-encoded content to write or insert into the file. Alternative to content, avoids JSON escaping issues for complex content (code with newlines, quotes, etc.). | |
| return_content | No | Optional: If true, returns the new file content in the response. Default: false (not returned). | |
| preserve_indent | No | Optional: If true, auto-convert new content indentation to match the original file's indentation style (TABs vs spaces). Default: false. Example: if original uses TABs and new content uses 4-space indentation, the tool will convert 4 spaces → 1 TAB, 8 spaces → 2 TABs, etc. |