Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion evals/packages/types/src/roo-code-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const rooCodeDefaults: RooCodeSettings = {
diffEnabled: true,
fuzzyMatchThreshold: 1.0,
experiments: {
search_and_replace: false,
insert_content: false,
powerSteering: false,
},
Expand Down
3 changes: 1 addition & 2 deletions evals/packages/types/src/roo-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export type CustomSupportPrompts = z.infer<typeof customSupportPromptsSchema>
* ExperimentId
*/

export const experimentIds = ["search_and_replace", "insert_content", "powerSteering"] as const
export const experimentIds = ["insert_content", "powerSteering"] as const

export const experimentIdsSchema = z.enum(experimentIds)

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

const experimentsSchema = z.object({
search_and_replace: z.boolean(),
insert_content: z.boolean(),
powerSteering: z.boolean(),
})
Expand Down
611 changes: 514 additions & 97 deletions src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/core/prompts/__tests__/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ describe("SYSTEM_PROMPT", () => {
beforeEach(() => {
// Reset experiments before each test to ensure they're disabled by default
experiments = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: false,
[EXPERIMENT_IDS.INSERT_BLOCK]: false,
}
})
Expand Down Expand Up @@ -482,7 +481,6 @@ describe("SYSTEM_PROMPT", () => {
it("should disable experimental tools by default", async () => {
// Set experiments to explicitly disable experimental tools
const experimentsConfig = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: false,
[EXPERIMENT_IDS.INSERT_BLOCK]: false,
}

Expand All @@ -508,15 +506,13 @@ describe("SYSTEM_PROMPT", () => {
// Check that experimental tool sections are not included
const toolSections = prompt.split("\n## ").slice(1)
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())
expect(toolNames).not.toContain("search_and_replace")
expect(toolNames).not.toContain("insert_content")
expect(prompt).toMatchSnapshot()
})

it("should enable experimental tools when explicitly enabled", async () => {
// Set experiments for testing experimental features
const experimentsEnabled = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
[EXPERIMENT_IDS.INSERT_BLOCK]: true,
}

Expand Down Expand Up @@ -544,15 +540,13 @@ describe("SYSTEM_PROMPT", () => {
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())

// Verify experimental tools are included in the prompt when enabled
expect(toolNames).toContain("search_and_replace")
expect(toolNames).toContain("insert_content")
expect(prompt).toMatchSnapshot()
})

it("should selectively enable experimental tools", async () => {
// Set experiments for testing selective enabling
const experimentsSelective = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
[EXPERIMENT_IDS.INSERT_BLOCK]: false,
}

Expand Down Expand Up @@ -580,14 +574,12 @@ describe("SYSTEM_PROMPT", () => {
const toolNames = toolSections.map((section) => section.split("\n")[0].trim())

// Verify only enabled experimental tools are included
expect(toolNames).toContain("search_and_replace")
expect(toolNames).not.toContain("insert_content")
expect(prompt).toMatchSnapshot()
})

it("should list all available editing tools in base instruction", async () => {
const experiments = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
[EXPERIMENT_IDS.INSERT_BLOCK]: true,
}

Expand Down Expand Up @@ -615,7 +607,6 @@ describe("SYSTEM_PROMPT", () => {
})
it("should provide detailed instructions for each enabled tool", async () => {
const experiments = {
[EXPERIMENT_IDS.SEARCH_AND_REPLACE]: true,
[EXPERIMENT_IDS.INSERT_BLOCK]: true,
}

Expand All @@ -640,7 +631,6 @@ describe("SYSTEM_PROMPT", () => {
"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.",
)
expect(prompt).toContain("The insert_content tool adds lines of text to files")
expect(prompt).toContain("The search_and_replace tool finds and replaces text or regex in files")
})
})

Expand Down
13 changes: 5 additions & 8 deletions src/core/prompts/sections/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
if (experiments?.["insert_content"]) {
availableTools.push("insert_content (for adding lines to existing files)")
}
if (experiments?.["search_and_replace"]) {
availableTools.push("search_and_replace (for finding and replacing individual pieces of text)")
}

availableTools.push("search_and_replace (for finding and replacing individual pieces of text)")

// Base editing instruction mentioning all available tools
if (availableTools.length > 1) {
Expand All @@ -38,11 +37,9 @@ function getEditingInstructions(diffStrategy?: DiffStrategy, experiments?: Recor
)
}

if (experiments?.["search_and_replace"]) {
instructions.push(
"- 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.",
)
}
instructions.push(
"- 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.",
)

if (availableTools.length > 1) {
instructions.push(
Expand Down
69 changes: 28 additions & 41 deletions src/core/prompts/tools/search-and-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,38 @@ import { ToolArgs } from "./types"

export function getSearchAndReplaceDescription(args: ToolArgs): string {
return `## search_and_replace
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.
Parameters:
- path: (required) The path of the file to modify (relative to the current workspace directory ${args.cwd.toPosix()})
- operations: (required) A JSON array of search/replace operations. Each operation is an object with:
* search: (required) The text or pattern to search for
* replace: (required) The text to replace matches with. If multiple lines need to be replaced, use "\n" for newlines
* start_line: (optional) Starting line number for restricted replacement
* end_line: (optional) Ending line number for restricted replacement
* use_regex: (optional) Whether to treat search as a regex pattern
* ignore_case: (optional) Whether to ignore case when matching
* regex_flags: (optional) Additional regex flags when use_regex is true
Usage:
<search_and_replace>
<path>File path here</path>
<operations>[
{
"search": "text to find",
"replace": "replacement text",
"start_line": 1,
"end_line": 10
}
]</operations>
</search_and_replace>
Example: Replace "foo" with "bar" in lines 1-10 of example.ts
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.

Required Parameters:
- path: The path of the file to modify (relative to the current workspace directory ${args.cwd.toPosix()})
- search: The text or pattern to search for
- replace: The text to replace matches with

Optional Parameters:
- start_line: Starting line number for restricted replacement (1-based)
- end_line: Ending line number for restricted replacement (1-based)
- use_regex: Set to "true" to treat search as a regex pattern (default: false)
- ignore_case: Set to "true" to ignore case when matching (default: false)

Notes:
- When use_regex is true, the search parameter is treated as a regular expression pattern
- When ignore_case is true, the search is case-insensitive regardless of regex mode

Examples:

1. Simple text replacement:
<search_and_replace>
<path>example.ts</path>
<operations>[
{
"search": "foo",
"replace": "bar",
"start_line": 1,
"end_line": 10
}
]</operations>
<search>oldText</search>
<replace>newText</replace>
</search_and_replace>
Example: Replace all occurrences of "old" with "new" using regex

2. Case-insensitive regex pattern:
<search_and_replace>
<path>example.ts</path>
<operations>[
{
"search": "old\\w+",
"replace": "new$&",
"use_regex": true,
"ignore_case": true
}
]</operations>
<search>old\w+</search>
<replace>new$&</replace>
<use_regex>true</use_regex>
<ignore_case>true</ignore_case>
</search_and_replace>`
}
Loading