Skip to content

Commit 9f61240

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/improve-insert-block-content
2 parents def6fad + 80b2984 commit 9f61240

File tree

33 files changed

+782
-1898
lines changed

33 files changed

+782
-1898
lines changed

evals/packages/types/src/roo-code-defaults.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const rooCodeDefaults: RooCodeSettings = {
5656
diffEnabled: true,
5757
fuzzyMatchThreshold: 1.0,
5858
experiments: {
59-
search_and_replace: false,
6059
powerSteering: false,
6160
},
6261

evals/packages/types/src/roo-code.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export type CustomSupportPrompts = z.infer<typeof customSupportPromptsSchema>
271271
* ExperimentId
272272
*/
273273

274-
export const experimentIds = ["search_and_replace", "powerSteering"] as const
274+
export const experimentIds = ["powerSteering"] as const
275275

276276
export const experimentIdsSchema = z.enum(experimentIds)
277277

@@ -282,7 +282,6 @@ export type ExperimentId = z.infer<typeof experimentIdsSchema>
282282
*/
283283

284284
const experimentsSchema = z.object({
285-
search_and_replace: z.boolean(),
286285
powerSteering: z.boolean(),
287286
})
288287

src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Lines changed: 420 additions & 1443 deletions
Large diffs are not rendered by default.

src/core/prompts/__tests__/system.test.ts

Lines changed: 1 addition & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ describe("SYSTEM_PROMPT", () => {
170170

171171
beforeEach(() => {
172172
// Reset experiments before each test to ensure they're disabled by default
173-
experiments = {
174-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: false,
175-
}
173+
experiments = {}
176174
})
177175

178176
beforeEach(() => {
@@ -477,163 +475,6 @@ describe("SYSTEM_PROMPT", () => {
477475
expect(prompt.indexOf(modes[0].roleDefinition)).toBeLessThan(prompt.indexOf("TOOL USE"))
478476
})
479477

480-
describe("experimental tools", () => {
481-
it("should disable experimental tools by default", async () => {
482-
// Set experiments to explicitly disable experimental tools
483-
const experimentsConfig = {
484-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: false,
485-
}
486-
487-
// Reset experiments
488-
experiments = experimentsConfig
489-
490-
const prompt = await SYSTEM_PROMPT(
491-
mockContext,
492-
"/test/path",
493-
false, // supportsComputerUse
494-
undefined, // mcpHub
495-
undefined, // diffStrategy
496-
undefined, // browserViewportSize
497-
defaultModeSlug, // mode
498-
undefined, // customModePrompts
499-
undefined, // customModes
500-
undefined, // globalCustomInstructions
501-
undefined, // diffEnabled
502-
experimentsConfig, // Explicitly disable experimental tools
503-
true, // enableMcpServerCreation
504-
)
505-
506-
// Check that experimental tool sections are not included
507-
const toolSections = prompt.split("\n## ").slice(1)
508-
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())
509-
expect(toolNames).not.toContain("search_and_replace")
510-
expect(prompt).toMatchSnapshot()
511-
})
512-
513-
it("should enable experimental tools when explicitly enabled", async () => {
514-
// Set experiments for testing experimental features
515-
const experimentsEnabled = {
516-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
517-
}
518-
519-
// Reset default experiments
520-
experiments = undefined
521-
522-
const prompt = await SYSTEM_PROMPT(
523-
mockContext,
524-
"/test/path",
525-
false, // supportsComputerUse
526-
undefined, // mcpHub
527-
undefined, // diffStrategy
528-
undefined, // browserViewportSize
529-
defaultModeSlug, // mode
530-
undefined, // customModePrompts
531-
undefined, // customModes
532-
undefined, // globalCustomInstructions
533-
undefined, // diffEnabled
534-
experimentsEnabled, // Use the enabled experiments
535-
true, // enableMcpServerCreation
536-
)
537-
538-
// Get all tool sections
539-
const toolSections = prompt.split("## ").slice(1) // Split by section headers and remove first non-tool part
540-
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())
541-
542-
// Verify experimental tools are included in the prompt when enabled
543-
expect(toolNames).toContain("search_and_replace")
544-
expect(prompt).toMatchSnapshot()
545-
})
546-
547-
it("should selectively enable experimental tools", async () => {
548-
// Set experiments for testing selective enabling
549-
const experimentsSelective = {
550-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
551-
}
552-
553-
// Reset default experiments
554-
experiments = undefined
555-
556-
const prompt = await SYSTEM_PROMPT(
557-
mockContext,
558-
"/test/path",
559-
false, // supportsComputerUse
560-
undefined, // mcpHub
561-
undefined, // diffStrategy
562-
undefined, // browserViewportSize
563-
defaultModeSlug, // mode
564-
undefined, // customModePrompts
565-
undefined, // customModes
566-
undefined, // globalCustomInstructions
567-
undefined, // diffEnabled
568-
experimentsSelective, // Use the selective experiments
569-
true, // enableMcpServerCreation
570-
)
571-
572-
// Get all tool sections
573-
const toolSections = prompt.split("## ").slice(1) // Split by section headers and remove first non-tool part
574-
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())
575-
576-
// 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-
const experiments = {
583-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
584-
}
585-
586-
const prompt = await SYSTEM_PROMPT(
587-
mockContext,
588-
"/test/path",
589-
false,
590-
undefined,
591-
new MultiSearchReplaceDiffStrategy(),
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-
const experiments = {
610-
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
611-
}
612-
613-
const prompt = await SYSTEM_PROMPT(
614-
mockContext,
615-
"/test/path",
616-
false,
617-
undefined,
618-
new MultiSearchReplaceDiffStrategy(),
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")
634-
})
635-
})
636-
637478
afterAll(() => {
638479
jest.restoreAllMocks()
639480
})

src/core/prompts/sections/rules.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
1515
}
1616

1717
availableTools.push("append_to_file (for appending content to the end of files)")
18-
1918
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)")
2420

2521
// Base editing instruction mentioning all available tools
2622
if (availableTools.length > 1) {
@@ -35,11 +31,9 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
3531
"- 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.",
3632
)
3733

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.",
36+
)
4337

4438
if (availableTools.length > 1) {
4539
instructions.push(

src/core/prompts/tools/search-and-replace.ts

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,38 @@ import { ToolArgs } from "./types"
22

33
export function getSearchAndReplaceDescription(args: ToolArgs): string {
44
return `## search_and_replace
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-
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:
2925
<search_and_replace>
3026
<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>
3929
</search_and_replace>
40-
Example: Replace all occurrences of "old" with "new" using regex
30+
31+
2. Case-insensitive regex pattern:
4132
<search_and_replace>
4233
<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>
34+
<search>old\w+</search>
35+
<replace>new$&</replace>
36+
<use_regex>true</use_regex>
37+
<ignore_case>true</ignore_case>
5138
</search_and_replace>`
5239
}

0 commit comments

Comments
 (0)