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
// Verify only enabled experimental tools are included
577
-
expect(toolNames).toContain("search_and_replace")
578
-
expect(prompt).toMatchSnapshot()
579
-
})
580
-
581
-
it("should list all available editing tools in base instruction",async()=>{
582
-
constexperiments={
583
-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
584
-
}
585
-
586
-
constprompt=awaitSYSTEM_PROMPT(
587
-
mockContext,
588
-
"/test/path",
589
-
false,
590
-
undefined,
591
-
newMultiSearchReplaceDiffStrategy(),
592
-
undefined,
593
-
defaultModeSlug,
594
-
undefined,
595
-
undefined,
596
-
undefined,
597
-
true,// diffEnabled
598
-
experiments,// experiments
599
-
true,// enableMcpServerCreation
600
-
)
601
-
602
-
// Verify base instruction lists all available tools
603
-
expect(prompt).toContain("apply_diff (for replacing lines in existing files)")
604
-
expect(prompt).toContain("write_to_file (for creating new files or complete file rewrites)")
605
-
expect(prompt).toContain("insert_content (for adding lines to existing files)")
606
-
expect(prompt).toContain("search_and_replace (for finding and replacing individual pieces of text)")
607
-
})
608
-
it("should provide detailed instructions for each enabled tool",async()=>{
609
-
constexperiments={
610
-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
611
-
}
612
-
613
-
constprompt=awaitSYSTEM_PROMPT(
614
-
mockContext,
615
-
"/test/path",
616
-
false,
617
-
undefined,
618
-
newMultiSearchReplaceDiffStrategy(),
619
-
undefined,
620
-
defaultModeSlug,
621
-
undefined,
622
-
undefined,
623
-
undefined,
624
-
true,// diffEnabled
625
-
experiments,
626
-
true,// enableMcpServerCreation
627
-
)
628
-
629
-
// Verify detailed instructions for each tool
630
-
expect(prompt).toContain(
631
-
"You should always prefer using other editing tools over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files.",
632
-
)
633
-
expect(prompt).toContain("The search_and_replace tool finds and replaces text or regex in files")
Copy file name to clipboardExpand all lines: src/core/prompts/sections/rules.ts
+4-10Lines changed: 4 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,8 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
15
15
}
16
16
17
17
availableTools.push("append_to_file (for appending content to the end of files)")
18
-
19
18
availableTools.push("insert_content (for adding lines to existing files)")
20
-
21
-
if(experiments?.["search_and_replace"]){
22
-
availableTools.push("search_and_replace (for finding and replacing individual pieces of text)")
23
-
}
19
+
availableTools.push("search_and_replace (for finding and replacing individual pieces of text)")
24
20
25
21
// Base editing instruction mentioning all available tools
26
22
if(availableTools.length>1){
@@ -35,11 +31,9 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
35
31
"- The insert_content tool adds lines of text to files at a specific line number, such as adding a new function to a JavaScript file or inserting a new route in a Python file. Use line number 0 to append at the end of the file, or any positive number to insert before that line.",
36
32
)
37
33
38
-
if(experiments?.["search_and_replace"]){
39
-
instructions.push(
40
-
"- The search_and_replace tool finds and replaces text or regex in files. This tool allows you to search for a specific regex pattern or text and replace it with another value. Be cautious when using this tool to ensure you are replacing the correct text. It can support multiple operations at once.",
41
-
)
42
-
}
34
+
instructions.push(
35
+
"- The search_and_replace tool finds and replaces text or regex in files. This tool allows you to search for a specific regex pattern or text and replace it with another value. Be cautious when using this tool to ensure you are replacing the correct text. It can support multiple operations at once.",
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
-
Parameters:
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:
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
11
-
* start_line: (optional) Starting line number for restricted replacement
12
-
* end_line: (optional) Ending line number for restricted replacement
13
-
* use_regex: (optional) Whether to treat search as a regex pattern
14
-
* ignore_case: (optional) Whether to ignore case when matching
15
-
* regex_flags: (optional) Additional regex flags when use_regex is true
16
-
Usage:
17
-
<search_and_replace>
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>
27
-
</search_and_replace>
28
-
Example: Replace "foo" with "bar" in lines 1-10 of example.ts
5
+
Description: Request to perform a search and replace operation on a file. Supports both literal text and regex patterns. Shows a diff preview before applying changes.
6
+
7
+
Required Parameters:
8
+
- path: The path of the file to modify (relative to the current workspace directory ${args.cwd.toPosix()})
9
+
- search: The text or pattern to search for
10
+
- replace: The text to replace matches with
11
+
12
+
Optional Parameters:
13
+
- start_line: Starting line number for restricted replacement (1-based)
14
+
- end_line: Ending line number for restricted replacement (1-based)
15
+
- use_regex: Set to "true" to treat search as a regex pattern (default: false)
16
+
- ignore_case: Set to "true" to ignore case when matching (default: false)
17
+
18
+
Notes:
19
+
- When use_regex is true, the search parameter is treated as a regular expression pattern
20
+
- When ignore_case is true, the search is case-insensitive regardless of regex mode
21
+
22
+
Examples:
23
+
24
+
1. Simple text replacement:
29
25
<search_and_replace>
30
26
<path>example.ts</path>
31
-
<operations>[
32
-
{
33
-
"search": "foo",
34
-
"replace": "bar",
35
-
"start_line": 1,
36
-
"end_line": 10
37
-
}
38
-
]</operations>
27
+
<search>oldText</search>
28
+
<replace>newText</replace>
39
29
</search_and_replace>
40
-
Example: Replace all occurrences of "old" with "new" using regex
0 commit comments