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
Copy file name to clipboardExpand all lines: src/core/prompts/tools/insert-content.ts
+23-19Lines changed: 23 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -5,31 +5,35 @@ export function getInsertContentDescription(args: ToolArgs): string {
5
5
Description: Inserts content at specific line positions in a file. This is the primary tool for adding new content and code (functions/methods/classes, imports, attributes etc.) as it allows for precise insertions without overwriting existing content. The tool uses an efficient line-based insertion system that maintains file integrity and proper ordering of multiple insertions. Beware to use the proper indentation. This tool is the preferred way to add new content and code to files.
6
6
Parameters:
7
7
- path: (required) The path of the file to insert content into (relative to the current workspace directory ${args.cwd.toPosix()})
8
-
- operations: (required) A JSON array of insertion operations. Each operation is an object with:
9
-
* start_line: (required) The line number where the content should be inserted. The content currently at that line will end up below the inserted content.
10
-
* content: (required) The content to insert at the specified position. IMPORTANT NOTE: If the content is a single line, it can be a string. If it's a multi-line content, it should be a string with newline characters (\n) for line breaks. Make sure to include the correct indentation for the content.
8
+
- operations: (required) An XML list of insertion operations. Each operation is defined with:
9
+
* <operation>: Container for each insertion operation
10
+
* <start_line>: (required) The line number where the content should be inserted. The content currently at that line will end up below the inserted content.
11
+
* <content>: (required) The content to insert at the specified position. Can be single line or multi-line content. Make sure to include the correct indentation for the content.
11
12
Usage:
12
13
<insert_content>
13
14
<path>File path here</path>
14
-
<operations>[
15
-
{
16
-
"start_line": 10,
17
-
"content": "Your content here"
18
-
}
19
-
]</operations>
15
+
<operations>
16
+
<operation>
17
+
<start_line>10</start_line>
18
+
<content>Your content here</content>
19
+
</operation>
20
+
</operations>
20
21
</insert_content>
21
22
Example: Insert a new function and its import statement
22
23
<insert_content>
23
24
<path>File path here</path>
24
-
<operations>[
25
-
{
26
-
"start_line": 1,
27
-
"content": "import { sum } from './utils';"
28
-
},
29
-
{
30
-
"start_line": 10,
31
-
"content": "function calculateTotal(items: number[]): number {\n return items.reduce((sum, item) => sum + item, 0);\n}"
32
-
}
33
-
]</operations>
25
+
<operations>
26
+
<operation>
27
+
<start_line>1</start_line>
28
+
<content>import { sum } from './utils';</content>
29
+
</operation>
30
+
<operation>
31
+
<start_line>10</start_line>
32
+
<content>function calculateTotal(items: number[]): number {
33
+
return items.reduce((sum, item) => sum + item, 0);
Copy file name to clipboardExpand all lines: src/core/prompts/tools/search-and-replace.ts
+50-26Lines changed: 50 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ export function getSearchAndReplaceDescription(args: ToolArgs): string {
5
5
Description: Request to perform search and replace operations on a file. Each operation can specify a search pattern (string or regex) and replacement text, with optional line range restrictions and regex flags. Shows a diff preview before applying changes.
6
6
Parameters:
7
7
- path: (required) The path of the file to modify (relative to the current workspace directory ${args.cwd.toPosix()})
8
-
- operations: (required) A JSON array of search/replace operations. Each operation is an object with:
8
+
- operations: (required) A list of search/replace operations as XML elements. Each operation can have these elements:
9
9
* search: (required) The text or pattern to search for
10
-
* replace: (required) The text to replace matches with. If multiple lines need to be replaced, use "\n" for newlines
10
+
* replace: (required) The text to replace matches with.
11
11
* start_line: (optional) Starting line number for restricted replacement
12
12
* end_line: (optional) Ending line number for restricted replacement
13
13
* use_regex: (optional) Whether to treat search as a regex pattern
@@ -16,37 +16,61 @@ Parameters:
16
16
Usage:
17
17
<search_and_replace>
18
18
<path>File path here</path>
19
-
<operations>[
20
-
{
21
-
"search": "text to find",
22
-
"replace": "replacement text",
23
-
"start_line": 1,
24
-
"end_line": 10
25
-
}
26
-
]</operations>
19
+
<operations>
20
+
<operation>
21
+
<search>text to find</search>
22
+
<replace>replacement text</replace>
23
+
<start_line>1</start_line>
24
+
<end_line>10</end_line>
25
+
</operation>
26
+
</operations>
27
27
</search_and_replace>
28
28
Example: Replace "foo" with "bar" in lines 1-10 of example.ts
29
29
<search_and_replace>
30
30
<path>example.ts</path>
31
-
<operations>[
32
-
{
33
-
"search": "foo",
34
-
"replace": "bar",
35
-
"start_line": 1,
36
-
"end_line": 10
37
-
}
38
-
]</operations>
31
+
<operations>
32
+
<operation>
33
+
<search>foo</search>
34
+
<replace>bar</replace>
35
+
<start_line>1</start_line>
36
+
<end_line>10</end_line>
37
+
</operation>
38
+
</operations>
39
39
</search_and_replace>
40
40
Example: Replace all occurrences of "old" with "new" using regex
41
41
<search_and_replace>
42
42
<path>example.ts</path>
43
-
<operations>[
44
-
{
45
-
"search": "old\\w+",
46
-
"replace": "new$&",
47
-
"use_regex": true,
48
-
"ignore_case": true
49
-
}
50
-
]</operations>
43
+
<operations>
44
+
<operation>
45
+
<search>old\\w+</search>
46
+
<replace>new$&</replace>
47
+
<use_regex>true</use_regex>
48
+
<ignore_case>true</ignore_case>
49
+
</operation>
50
+
</operations>
51
+
</search_and_replace>
52
+
53
+
Example: Multiple replacements in a JavaScript file
0 commit comments