Skip to content

Commit aa18092

Browse files
3.14 Part A (#151)
1 parent b9ea58e commit aa18092

File tree

16 files changed

+333
-121
lines changed

16 files changed

+333
-121
lines changed

docs/features/footgun-prompting.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ sidebar_label: 'Footgun Prompting'
44

55
# Footgun Prompting: Override System Prompts
66

7-
Footgun Prompting, AKA Overriding System Prompt, allows advanced users to completely replace the default system prompt for a specific Roo Code mode. This provides granular control over the AI's behavior but bypasses built-in safeguards.
7+
Footgun Prompting (System Prompt Override) lets you replace the default system prompt for a specific Roo Code mode. This offers granular control but bypasses built-in safeguards. Use with caution.
8+
9+
<img src="/img/footgun-prompting/footgun-prompting-1.png" alt="Warning indicator for active system prompt override" width="600" />
10+
**Warning Indicator:** When a system prompt override is active for the current mode, Roo Code will display a warning icon in the chat input area to remind you that the default behavior has been modified.
11+
812

913
:::info **footgun** _(noun)_
1014

@@ -32,7 +36,7 @@ Footgun Prompting, AKA Overriding System Prompt, allows advanced users to comple
3236
3337
## Accessing the Feature
3438
35-
You can find the option and instructions within the Roo Code UI:
39+
Find the option and instructions in the Roo Code UI:
3640
3741
1. Click the <Codicon name="notebook" /> icon in the Roo Code top menu bar.
3842
2. Expand the **"Advanced: Override System Prompt"** section.
@@ -63,7 +67,7 @@ The project is located at: {{workspace}}.
6367
Please respond in {{language}}.
6468
```
6569
66-
Roo Code will substitute these placeholders before sending the prompt to the AI model.
70+
Roo Code substitutes these placeholders before sending the prompt to the model.
6771
6872
## Key Considerations & Warnings
6973
@@ -73,5 +77,4 @@ Roo Code will substitute these placeholders before sending the prompt to the AI
7377
- **No File, No Override:** If the `.roo/system-prompt-{mode-slug}` file doesn't exist, Roo Code uses the standard system prompt generation process for that mode.
7478
- **Blank Files Ignored:** If the override file exists but is empty (blank), it will be ignored and the default system prompt will be used.
7579
- **Directory Creation:** Roo Code ensures the `.roo` directory exists before attempting to read or create the override file.
76-
77-
Use this feature cautiously. While powerful for customization, incorrect implementation can significantly degrade Roo Code's performance and reliability for the affected mode.
80+
Use this feature cautiously. Incorrect implementation can significantly degrade Roo Code's performance and reliability for the affected mode.

docs/features/tools/append-to-file.md

Lines changed: 0 additions & 87 deletions
This file was deleted.

docs/features/tools/apply-diff.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# apply_diff
22

3-
The `apply_diff` tool makes precise, surgical changes to files by specifying exactly what content to replace. It uses multiple sophisticated strategies for finding and applying changes while maintaining proper code formatting and structure.
3+
The `apply_diff` tool makes precise, surgical changes to files by specifying exactly what content to replace. It uses a sophisticated strategy for finding and applying changes while maintaining proper code formatting and structure.
44

55
## Parameters
66

77
The tool accepts these parameters:
88

99
- `path` (required): The path of the file to modify relative to the current working directory.
1010
- `diff` (required): The search/replace block defining the changes using a format specific to the active diff strategy.
11-
- `start_line` (optional): A hint for where the search content begins, used by some strategies.
12-
- `end_line` (optional): A hint for where the search content ends, used by some strategies.
11+
- `start_line` (optional): A hint for where the search content begins. _Note: This top-level parameter appears unused by the current main strategy, which relies on `:start_line:` within the diff content._
12+
- `end_line` (optional): A hint for where the search content ends. _Note: This top-level parameter appears unused by the current main strategy._
1313

1414
## What It Does
1515

16-
This tool applies targeted changes to existing files using sophisticated strategies to locate and replace content precisely. Unlike simple search and replace, it uses intelligent matching algorithms (including fuzzy matching) that adapt to different content types and file sizes, with fallback mechanisms for complex edits.
16+
This tool applies targeted changes to existing files using fuzzy matching guided by line number hints to locate and replace content precisely. Unlike simple search and replace, it identifies the exact block for replacement based on the provided content and location hints.
1717

1818
## When is it used?
1919

@@ -24,11 +24,10 @@ This tool applies targeted changes to existing files using sophisticated strateg
2424

2525
## Key Features
2626

27-
- Uses intelligent fuzzy matching with configurable confidence thresholds (typically 0.8-1.0).
27+
- Uses fuzzy matching (Levenshtein distance on normalized strings) guided by a `:start_line:` hint, with configurable confidence thresholds (typically 0.8-1.0).
2828
- Provides context around matches using `BUFFER_LINES` (default 40).
29-
- Employs an overlapping window approach for searching large files.
30-
- Preserves code formatting and indentation automatically.
31-
- Combines overlapping matches for improved confidence scoring.
29+
- Performs a middle-out search within a configurable context window (`bufferLines`) around the hinted start line.
30+
- Preserves code formatting and indentation passively by replacing exact blocks.
3231
- Shows changes in a diff view for user review and editing before applying.
3332
- Tracks consecutive errors per file (`consecutiveMistakeCountForApplyDiff`) to prevent repeated failures.
3433
- Validates file access against `.rooignore` rules.
@@ -49,8 +48,8 @@ When the `apply_diff` tool is invoked, it follows this process:
4948
1. **Parameter Validation**: Validates required `path` and `diff` parameters.
5049
2. **RooIgnore Check**: Validates if the target file path is allowed by `.rooignore` rules.
5150
3. **File Analysis**: Loads the target file content.
52-
4. **Match Finding**: Uses the selected strategy's algorithms (exact, fuzzy, overlapping windows) to locate the target content, considering confidence thresholds and context (`BUFFER_LINES`).
53-
5. **Change Preparation**: Generates the proposed changes, preserving indentation.
51+
4. **Match Finding**: Uses a fuzzy matching algorithm (Levenshtein on normalized strings) guided by the `:start_line:` hint within a context window (`BUFFER_LINES`), searching middle-out to locate the target content based on the confidence threshold.
52+
5. **Change Preparation**: Generates the proposed changes by replacing the identified block.
5453
6. **User Interaction**:
5554
* Displays the changes in a diff view.
5655
* Allows the user to review and potentially edit the proposed changes.
@@ -59,16 +58,11 @@ When the `apply_diff` tool is invoked, it follows this process:
5958
8. **Error Handling**: If errors occur (e.g., match failure, partial application), increments the `consecutiveMistakeCountForApplyDiff` for the file and reports the failure type.
6059
9. **Feedback**: Returns the result, including any user feedback or error details.
6160

62-
## Diff Strategy
61+
## Diff Format Requirements
6362

64-
Roo Code uses this strategy for applying diffs:
63+
The `<diff>` parameter requires a specific format supporting one or more changes in a single request. Each change block requires a line number hint for the original content.
6564

66-
### MultiSearchReplaceDiffStrategy
67-
68-
An enhanced search/replace format supporting multiple changes in one request. Requires line numbers for each search block.
69-
70-
* **Best for**: Multiple, distinct changes where line numbers are known or can be estimated.
71-
* **Requires**: Exact match for the `SEARCH` block content, including whitespace and indentation. Line numbers (`:start_line:`, `:end_line:`) are mandatory. Markers within content must be escaped (`\`).
65+
* **Requires**: Exact match for the `SEARCH` block content (within the fuzzy threshold), including whitespace and indentation. The `:start_line:` number hint is mandatory within each block. The `:end_line:` hint is optional (but supported by the parser). Markers like `<<<<<<<` within the file's content must be escaped (`\\`) in the SEARCH block.
7266

7367
Example format for the `<diff>` block:
7468

@@ -94,5 +88,4 @@ Example format for the `<diff>` block:
9488
const defaultTimeout = 5000;
9589
=======
9690
const defaultTimeout = 10000; // Increased timeout
97-
>>>>>>> REPLACE
98-
```
91+
>>>>>>> REPLACE
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# insert_content
2+
3+
The `insert_content` tool adds new lines of content into an existing file without modifying the original content. It's ideal for inserting code blocks, configuration entries, or log lines at specific locations.
4+
5+
## Parameters
6+
7+
The tool accepts these parameters:
8+
9+
- `path` (required): The relative path (from the workspace root) of the file to insert content into.
10+
- `line` (required): The 1-based line number *before* which the content should be inserted. Use `0` to append the content to the end of the file.
11+
- `content` (required): The text content to insert.
12+
13+
## What It Does
14+
15+
This tool reads the target file, identifies the specified insertion point based on the `line` parameter, and inserts the provided `content` at that location. If `line` is `0`, the content is added to the end. Changes are presented in a diff view for user approval before being saved.
16+
17+
## When is it used?
18+
19+
- When adding new import statements at the beginning of a file.
20+
- When inserting new functions or methods into existing code.
21+
- When adding configuration blocks to settings files.
22+
- When appending log entries or data records.
23+
- When adding any multi-line text block without altering existing lines.
24+
25+
## Key Features
26+
27+
- **Targeted Insertion**: Adds content precisely at the specified line number or appends to the end.
28+
- **Preserves Existing Content**: Does not modify or delete original file lines.
29+
- **Interactive Approval**: Shows proposed insertions in a diff view, requiring explicit user approval.
30+
- **User Edit Support**: Allows editing the proposed content directly within the diff view before final approval.
31+
- **Handles Line Numbers**: Correctly interprets the `line` parameter (1-based or 0 for append).
32+
- **Context Tracking**: Records the file edit operation for context management.
33+
- **Error Handling**: Checks for missing parameters, invalid line numbers, and file access issues.
34+
35+
## Limitations
36+
37+
- **Insert Only**: Cannot replace or delete existing content. Use `apply_diff` or `search_and_replace` for modifications.
38+
- **Requires Existing File**: The target file specified by `path` must exist.
39+
- **Review Overhead**: The mandatory diff view approval adds an interactive step.
40+
41+
## How It Works
42+
43+
When the `insert_content` tool is invoked, it follows this process:
44+
45+
1. **Parameter Validation**: Checks for required `path`, `line`, and `content`. Validates `line` is a non-negative integer.
46+
2. **File Reading**: Reads the content of the target file specified by `path`.
47+
3. **Insertion Point Calculation**: Converts the 1-based `line` parameter to a 0-based index for internal processing (`-1` for appending).
48+
4. **Content Insertion**: Uses an internal utility (`insertGroups`) to merge the original file lines with the new `content` at the calculated index.
49+
5. **Diff View Interaction**:
50+
* Opens the file in the diff view (`cline.diffViewProvider.open`).
51+
* Updates the diff view with the proposed content (`cline.diffViewProvider.update`).
52+
6. **User Approval**: Presents the change via `askApproval`. Reverts if rejected.
53+
7. **Saving Changes**: If approved, saves the changes using `cline.diffViewProvider.saveChanges`.
54+
8. **File Context Tracking**: Tracks the edit using `cline.getFileContextTracker().trackFileContext`.
55+
9. **Handling User Edits**: If the user edited the content in the diff view, reports the final merged content back.
56+
10. **Result Reporting**: Reports success (including user edits) or failure back to the AI model.
57+
58+
## Usage Examples
59+
60+
Inserting import statements at the beginning of a file (`line: 1`):
61+
62+
```xml
63+
<insert_content>
64+
<path>src/utils.ts</path>
65+
<line>1</line>
66+
<content>
67+
// Add imports at start of file
68+
import { sum } from './math';
69+
import { parse } from 'date-fns';
70+
</content>
71+
</insert_content>
72+
```
73+
74+
Appending content to the end of a file (`line: 0`):
75+
76+
```xml
77+
<insert_content>
78+
<path>config/routes.yaml</path>
79+
<line>0</line>
80+
<content>
81+
- path: /new-feature
82+
component: NewFeatureComponent
83+
auth_required: true
84+
</content>
85+
</insert_content>
86+
```
87+
88+
Inserting a function before line 50:
89+
90+
```xml
91+
<insert_content>
92+
<path>src/services/api.js</path>
93+
<line>50</line>
94+
<content>
95+
async function fetchUserData(userId) {
96+
const response = await fetch(`/api/users/${userId}`);
97+
if (!response.ok) {
98+
throw new Error('Failed to fetch user data');
99+
}
100+
return response.json();
101+
}
102+
</content>
103+
</insert_content>
104+
```

docs/features/tools/list-files.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ This tool lists all files and directories in a specified location, providing a c
2828
- Intelligently ignores common large directories like `node_modules` and `.git` in recursive mode
2929
- Respects `.gitignore` rules when in recursive mode
3030
- Marks files ignored by `.rooignore` with a lock symbol (🔒) when `showRooIgnoredFiles` is enabled
31-
- Optimizes performance with level-by-level directory traversal
31+
- Optimizes file listing performance by leveraging the `ripgrep` tool.
3232
- Sorts results to show directories before their contents, maintaining a logical hierarchy
3333
- Presents results in a clean, organized format
3434
- Automatically creates a mental map of your project structure
3535

3636
## Limitations
3737

3838
- File listing is capped at about 200 files by default to prevent performance issues
39-
- Has a 10-second timeout for directory traversal to prevent hanging on complex directory structures
39+
- The underlying `ripgrep` file listing process has a 10-second timeout; if exceeded, partial results may be returned.
4040
- When the file limit is hit, it adds a note suggesting to use `list_files` on specific subdirectories
4141
- Not designed for confirming the existence of files you've just created
4242
- May have reduced performance in very large directory structures
@@ -49,10 +49,10 @@ When the `list_files` tool is invoked, it follows this process:
4949
1. **Parameter Validation**: Validates the required `path` parameter and optional `recursive` parameter
5050
2. **Path Resolution**: Resolves the relative path to an absolute path
5151
3. **Security Checks**: Prevents listing files in sensitive locations like root or home directories
52-
4. **Directory Scanning**:
53-
- For non-recursive mode: Lists only the top-level contents
54-
- For recursive mode: Traverses the directory structure level by level with a 10-second timeout
55-
- If timeout occurs, returns partial results collected up to that point
52+
4. **Directory/File Scanning**:
53+
- Uses the `ripgrep` tool to efficiently list files, applying a 10-second timeout.
54+
- Uses Node.js `fs` module to list directories.
55+
- Applies different filtering logic for recursive vs. non-recursive modes.
5656
5. **Result Filtering**:
5757
- In recursive mode, skips common large directories like `node_modules`, `.git`, etc.
5858
- Respects `.gitignore` rules when in recursive mode

0 commit comments

Comments
 (0)