|
1 | 1 | ### text_editor |
2 | | -read write or patch text files; binary files are not supported |
3 | | -always use the method form in `tool_name`; never send bare `text_editor` |
4 | | -- `text_editor:read`: `path`, optional `line_from`, `line_to` |
5 | | -- `text_editor:write`: `path`, `content` |
6 | | -- `text_editor:patch`: `path`, `edits[]` |
7 | | -example: |
| 2 | +file read write patch with numbered lines |
| 3 | +not code execution rejects binary |
| 4 | +terminal (grep find sed) advance search/replace |
| 5 | + |
| 6 | +#### text_editor:read |
| 7 | +read file with numbered lines |
| 8 | +args path line_from line_to (inclusive optional) |
| 9 | +no range → first {{default_line_count}} lines |
| 10 | +long lines cropped output may trim by token limit |
| 11 | +read surrounding context before patching |
| 12 | +usage: |
8 | 13 | ~~~json |
9 | 14 | { |
10 | | - "thoughts": ["Need to inspect the file before patching it."], |
11 | | - "headline": "Reading file with text editor", |
12 | | - "tool_name": "text_editor:read", |
13 | | - "tool_args": { |
14 | | - "path": "/path/file.py", |
15 | | - "line_from": 1, |
16 | | - "line_to": 50 |
17 | | - } |
| 15 | + ... |
| 16 | + "tool_name": "text_editor:read", |
| 17 | + "tool_args": { |
| 18 | + "path": "/path/file.py", |
| 19 | + "line_from": 1, |
| 20 | + "line_to": 50 |
| 21 | + } |
| 22 | +} |
| 23 | +~~~ |
| 24 | + |
| 25 | +#### text_editor:write |
| 26 | +create/overwrite file auto-creates dirs |
| 27 | +args path content |
| 28 | +usage: |
| 29 | +~~~json |
| 30 | +{ |
| 31 | + ... |
| 32 | + "tool_name": "text_editor:write", |
| 33 | + "tool_args": { |
| 34 | + "path": "/path/file.py", |
| 35 | + "content": "import os\nprint('hello')\n" |
| 36 | + } |
| 37 | +} |
| 38 | +~~~ |
| 39 | + |
| 40 | +#### text_editor:patch |
| 41 | +line edits on existing file |
| 42 | +args path edits [{from to content}] |
| 43 | +from to inclusive \n in content |
| 44 | +{from:2 to:2 content:"x\n"} replace line |
| 45 | +{from:1 to:3 content:"x\n"} replace range |
| 46 | +{from:2 to:2} delete (no content) |
| 47 | +{from:2 content:"x\n"} insert before (omit to) |
| 48 | +use original line numbers from read |
| 49 | +dont adjust for shifts no overlapping edits |
| 50 | +ensure valid syntax in content (all braces brackets tags closed) |
| 51 | +only replace exact lines needed dont include surrounding unchanged lines |
| 52 | +re-read when insert delete or N≠M replace else patch again ok |
| 53 | +large changes write over multiple patches |
| 54 | +usage: |
| 55 | +~~~json |
| 56 | +{ |
| 57 | + ... |
| 58 | + "tool_name": "text_editor:patch", |
| 59 | + "tool_args": { |
| 60 | + "path": "/path/file.py", |
| 61 | + "edits": [ |
| 62 | + {"from": 1, "content": "import sys\n"}, |
| 63 | + {"from": 5, "to": 5, "content": " if x == 2:\n"} |
| 64 | + ] |
| 65 | + } |
18 | 66 | } |
19 | 67 | ~~~ |
20 | | -patch edit format: `{from,to?,content?}` |
21 | | -- omit `to` to insert before `from` |
22 | | -- omit `content` to delete |
23 | | -- line numbers come from the last read |
24 | | -- avoid overlapping edits; re-read after insert delete or other line shifts |
|
0 commit comments