You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An experimental version of `apply_diff` allows for applying changes to multiple files within a single tool call. This feature is activated by the `MULTI_FILE_APPLY_DIFF` experiment flag.
125
-
126
-
### Key Features of Experimental Mode
127
-
128
-
-**Multi-File Operations**: Edit multiple files in one request, streamlining complex refactoring tasks.
129
-
-**Batch Approval UI**: When multiple files are targeted, a single UI appears for the user to approve or deny all changes at once, or manage permissions for each file individually.
130
-
-**New XML Format**: Introduces a new, more structured XML format using `<args>` and `<file>` tags to handle multiple operations.
131
-
-**Backward Compatibility**: The experimental tool remains compatible with the legacy single-file `path` and `diff` parameter format.
132
-
133
-
### How It Works (Experimental)
134
-
135
-
1.**Experiment Check**: The tool first checks if the `MULTI_FILE_APPLY_DIFF` experiment is enabled. If not, it falls back to the legacy `apply_diff` implementation.
136
-
2.**Parameter Parsing**: It parses the new `<args>` XML format to identify all target files and their corresponding diff operations. It can also handle the legacy `path`/`diff` parameters.
137
-
3.**Validation and Approval**:
138
-
* It validates that all target files exist and are accessible (not blocked by `.rooignore`).
139
-
* If multiple files are being modified, it presents a **batch approval** dialog to the user.
140
-
4.**Diff Application**: For each approved file, it applies the specified diffs using the `MultiFileSearchReplaceDiffStrategy`. This strategy can apply multiple, non-overlapping changes to a single file.
141
-
5.**Results**: It returns a consolidated result message summarizing the outcome for all attempted operations.
142
-
143
-
### New Diff Format (Experimental)
144
-
145
-
The experimental mode uses a new XML structure within the `<apply_diff>` tool call.
146
-
147
-
-**`<args>`**: A container for all file operations.
148
-
-**`<file>`**: A block for each file to be modified. Contains `<path>` and one or more `<diff>` tags.
149
-
-**`<path>`**: The relative path to the file.
150
-
-**`<diff>`**: A block containing the change.
151
-
-**`<content>`**: The `SEARCH/REPLACE` block.
152
-
-**`<start_line>`**: (Optional) A line number hint.
description: Replace all occurrences of text in files using the edit_file search-and-replace tool in Roo Code.
2
+
description: Replace a uniquely-identified occurrence of text in files using the edit_file search-and-replace tool in Roo Code.
3
3
keywords:
4
4
- edit_file
5
5
- search and replace
@@ -11,7 +11,7 @@ keywords:
11
11
12
12
# edit_file
13
13
14
-
The `edit_file` tool performs search-and-replace operations on files, replacing **all occurrences**of specified text. It provides a straightforward way to make consistent changes across a filewhen you need to update every instance of a pattern.
14
+
The `edit_file` tool performs targeted search-and-replace operations on files. By default it replaces **exactly one**uniquely-identified occurrence and errors if multiple matches are found. It also supports a special file-creation mode when `old_string` is empty.
15
15
16
16
---
17
17
@@ -20,43 +20,46 @@ The `edit_file` tool performs search-and-replace operations on files, replacing
20
20
The tool accepts these parameters:
21
21
22
22
-`file_path` (required): The path of the file to modify relative to the current working directory.
23
-
-`old_string` (required): The exact text to search for and replace.
24
-
-`new_string` (required): The text to replace all occurrences with.
25
-
-`expected_replacements` (optional): Expected number of replacements. If specified, the operation fails if the actual count doesn't match.
23
+
-`old_string` (required): The exact text to search for and replace. Pass an empty string (`""`) to create a new file or append to an existing file.
24
+
-`new_string` (required): The replacement text.
25
+
-`expected_replacements` (optional): Expected number of replacements (defaults to 1). The operation fails if the actual count doesn't match. Use this only when intentionally replacing more than one occurrence.
26
26
27
27
---
28
28
29
29
## What It Does
30
30
31
-
This tool searches for an exact string in a file and replaces **all occurrences** with new text. The replacement is performed globally across the entire file, making it ideal for consistent updates like renaming variables, updating API endpoints, or fixing repeated patterns.
31
+
This tool searches for an exact string in a file and replaces **exactly one**occurrence with new text. The search string must uniquely identify the target location. If multiple matches are found, the tool returns an error unless `expected_replacements` is explicitly set to match. When `old_string` is empty, the tool creates a new file or appends `new_string` to an existing file.
32
32
33
33
---
34
34
35
35
## When is it used?
36
36
37
-
- When renaming variables, functions, or identifiers throughout a file
38
-
- When updating repeated string literals or configuration values
39
-
- When fixing consistent typos or outdated terminology
40
-
- When replacing all instances of a deprecated API or import path
37
+
- When making a targeted change to a specific, uniquely identifiable location in a file
38
+
- When updating a specific string literal or configuration value at a known location
39
+
- When fixing a specific instance of a typo or outdated terminology
40
+
- When replacing a uniquely-identified occurrence of a deprecated API or import path
41
+
- When creating a new file or appending content to an existing file (`old_string=""`)
41
42
- When you need to ensure exact match replacement without fuzzy logic
42
43
43
44
---
44
45
45
46
## Key Features
46
47
47
-
- Replaces **all occurrences** by default (global replacement)
48
+
- Replaces **exactly one** uniquely-identified occurrence by default
49
+
- Errors if multiple matches are found (unless `expected_replacements` is explicitly set)
50
+
-`old_string=""` mode: creates a new file or appends content to an existing file
48
51
- Exact string matching (no regex or fuzzy matching)
49
-
- Optional validation via `expected_replacements`parameter
-Always replaces all occurrences (cannot target specific instances)
62
+
-Errors if the search string matches more than one location (unless `expected_replacements` is set)
60
63
- Cannot use regular expressions or patterns
61
64
- Not suitable for context-dependent replacements
62
65
- Less precise than [`apply_diff`](/advanced-usage/available-tools/apply-diff) for complex edits
@@ -68,10 +71,10 @@ This tool searches for an exact string in a file and replaces **all occurrences*
68
71
When the `edit_file` tool is invoked, it follows this process:
69
72
70
73
1.**Parameter Validation**: Validates required `file_path`, `old_string`, and `new_string` parameters.
71
-
2.**File Loading**: Reads the target file content.
72
-
3.**Search Operation**: Searches for all occurrences of `old_string` in the file.
73
-
4.**Count Validation**: If `expected_replacements` is specified, validates the actual occurrence count matches.
74
-
5.**Replacement**: Replaces all found occurrences with `new_string`.
74
+
2.**File Creation Mode**: If `old_string` is empty (`""`), creates the file with `new_string` as content (or appends if the file already exists), then stops.
75
+
3.**File Loading**: Reads the target file content.
76
+
4.**Uniqueness Check**: Counts occurrences of `old_string`. If the count doesn't match `expected_replacements` (default: 1), returns an error.
77
+
5.**Replacement**: Replaces the matched occurrence(s) with `new_string`.
75
78
6.**User Review**: Shows a preview of changes for user approval.
76
79
7.**Application**: Applies changes to the file if approved.
77
80
8.**Feedback**: Reports the number of replacements made.
@@ -80,9 +83,9 @@ When the `edit_file` tool is invoked, it follows this process:
Copy file name to clipboardExpand all lines: docs/advanced-usage/available-tools/generate-image.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ keywords:
12
12
13
13
# generate_image
14
14
15
-
The `generate_image` tool creates new images from text prompts or modifies existing images using AI models through the OpenRouter API. This experimental feature enables visual content generation and transformation within your development workflow.
15
+
The `generate_image` tool creates new images from text prompts or modifies existing images using AI models. It supports two providers: **OpenRouter** and the **Roo provider**. This experimental feature enables visual content generation and transformation within your development workflow.
16
16
17
17
---
18
18
@@ -48,14 +48,14 @@ This tool generates images from text descriptions or applies transformations to
48
48
-**Image-to-image transformation**: Edit or transform existing images
Copy file name to clipboardExpand all lines: docs/advanced-usage/available-tools/read-file.md
+26-17Lines changed: 26 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,16 +28,25 @@ The `read_file` tool accepts multiple files via the `args` format. Concurrency a
28
28
29
29
## Parameters
30
30
31
-
The tool accepts parameters in two formats depending on your configuration:
31
+
The tool accepts parameters in two formats:
32
32
33
33
### Standard Format (Single File)
34
34
35
35
-`path` (required): The path of the file to read relative to the current working directory
36
-
-`start_line` (optional): The starting line number to read from (1-based indexing)
37
-
-`end_line` (optional): The ending line number to read to (1-based, inclusive)
38
-
39
-
:::note Legacy Format
40
-
While the single-file parameters (`path`, `start_line`, `end_line`) are still supported for backward compatibility, we recommend using the newer `args` format for consistency and future compatibility.
36
+
-`mode` (optional): Reading mode — `"slice"` (default) or `"indentation"`
37
+
-`offset` (optional): 1-based line offset to start reading from (slice mode only, default: `1`)
38
+
-`limit` (optional): Maximum number of lines to return (slice mode only, default: `2000`)
39
+
-`indentation` (optional): Indentation-mode options — only used when `mode="indentation"`:
40
+
-`anchor_line` (required): 1-based line number to anchor the extraction. The tool extracts the complete semantic code block (function, class, method) containing this line.
41
+
-`max_levels` (optional): Maximum indentation levels to include above the anchor.
42
+
-`include_siblings` (optional): Whether to include sibling blocks at the same indentation level.
43
+
-`include_header` (optional): Whether to include file header content (imports, module-level comments) at the top of output.
44
+
-`max_lines` (optional): Hard cap on lines returned in indentation mode.
45
+
46
+
:::note Mode Summary
47
+
-**Slice mode** (default): Reads lines sequentially from `offset` up to `limit` lines. Use for initial file exploration or reading a specific line range.
48
+
-**Indentation mode**: Extracts complete, syntactically valid code blocks around `anchor_line` based on indentation hierarchy. Preferred when you have a target line number (e.g., from search results or error messages) and need the entire function/class without mid-function truncation.
49
+
-**`start_line` and `end_line` do not exist** as parameters. Use `offset` and `limit` for range reads in slice mode.
41
50
:::
42
51
43
52
### Enhanced Format (Multi-File)
@@ -147,7 +156,7 @@ When the `read_file` tool is invoked, it follows this process:
147
156
The tool uses a clear decision hierarchy to determine how to read a file:
148
157
149
158
1.**First Priority: Explicit Line Range**
150
-
-Legacy single‑file format: both `start_line` and `end_line` must be provided for a range read; otherwise it reads normally.
159
+
-Single‑file format: specify `offset` and `limit`for a range read in slice mode, or use `anchor_line` in indentation mode.
151
160
- Multi‑file `args` format: specify one or more `line_range` entries per file.
152
161
- Range reads stream only the requested lines and bypass `maxReadFileLine`, taking precedence over other options.
153
162
@@ -160,7 +169,7 @@ The tool uses a clear decision hierarchy to determine how to read a file:
160
169
161
170
3.**Third Priority: Automatic Truncation for Large Text Files**
162
171
- Applies only when all of the following are true:
163
-
-Neither `start_line` nor `end_line` is specified.
172
+
-No `offset`/`limit` range is specified (slice mode) and no `anchor_line` is provided (indentation mode).
164
173
- The file is identified as a text‑based file (not binary like PDF/DOCX/XLSX/IPYNB).
165
174
- The file's total line count exceeds the `maxReadFileLine` setting (configurable; UI default may be 500; backend uses `-1`—no line limit—when unset).
166
175
- When automatic truncation occurs:
@@ -208,14 +217,14 @@ To read the complete content of a file:
208
217
209
218
### Reading Specific Lines
210
219
211
-
To read only a specific range of lines (e.g., 46-68):
220
+
To read only a specific range of lines (e.g., lines 46-68), use `offset` and `limit` in slice mode:
212
221
213
222
**Input:**
214
223
```xml
215
224
<read_file>
216
225
<path>src/app.js</path>
217
-
<start_line>46</start_line>
218
-
<end_line>68</end_line>
226
+
<offset>46</offset>
227
+
<limit>23</limit>
219
228
</read_file>
220
229
```
221
230
@@ -337,12 +346,12 @@ This behavior ensures that:
337
346
- You receive guidance to use `line_range` for targeted reads
338
347
- Stream errors are handled gracefully
339
348
340
-
**Example with line_range for targeted reading:**
349
+
**Example with offset/limit for targeted reading:**
341
350
```xml
342
351
<read_file>
343
352
<path>logs/massive-debug.log</path>
344
-
<start_line>1000</start_line>
345
-
<end_line>1100</end_line>
353
+
<offset>1000</offset>
354
+
<limit>101</limit>
346
355
</read_file>
347
356
```
348
357
@@ -639,9 +648,9 @@ This allows Roo to analyze documentation, visual diagrams, configuration, and sp
639
648
## Troubleshooting
640
649
641
650
- Range read returns error
642
-
- Cause: `start_line`/`end_line` invalid or `start_line > end_line`
643
-
- Fix: Provide both `start_line`and `end_line`as positive integers with `start_line ≤ end_line`; or use `args` with one or more`line_range` entries.
644
-
- Prevention: Prefer `line_range` in the multi‑file format for targeted reads.
- Fix: Use `offset` (1-based starting line) and `limit` (max lines to return) as positive integers in slice mode; or use `anchor_line` in indentation mode; or use the multi-file `args` format with`line_range` entries.
653
+
- Prevention: Prefer the multi-file `args`format with `line_range`for targeted reads across multiple files.
645
654
646
655
- Large file returned a preview
647
656
- Cause: File exceeded token budget or the large‑file tokenization threshold; a preview was returned.
0 commit comments