(params: SearchReplaceParams, task: Task, callbacks: ToolCallbacks)
| 25 | readonly name = "search_replace" as const |
| 26 | |
| 27 | async execute(params: SearchReplaceParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 28 | const { file_path, old_string, new_string } = params |
| 29 | const { askApproval, handleError, pushToolResult } = callbacks |
| 30 | |
| 31 | try { |
| 32 | // Validate required parameters |
| 33 | if (!file_path) { |
| 34 | task.consecutiveMistakeCount++ |
| 35 | task.recordToolError("search_replace") |
| 36 | pushToolResult(await task.sayAndCreateMissingParamError("search_replace", "file_path")) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | if (!old_string) { |
| 41 | task.consecutiveMistakeCount++ |
| 42 | task.recordToolError("search_replace") |
| 43 | pushToolResult(await task.sayAndCreateMissingParamError("search_replace", "old_string")) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if (new_string === undefined) { |
| 48 | task.consecutiveMistakeCount++ |
| 49 | task.recordToolError("search_replace") |
| 50 | pushToolResult(await task.sayAndCreateMissingParamError("search_replace", "new_string")) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | // Validate that old_string and new_string are different |
| 55 | if (old_string === new_string) { |
| 56 | task.consecutiveMistakeCount++ |
| 57 | task.recordToolError("search_replace") |
| 58 | pushToolResult( |
| 59 | formatResponse.toolError("The 'old_string' and 'new_string' parameters must be different."), |
| 60 | ) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | // Determine relative path - file_path can be absolute or relative |
| 65 | let relPath: string |
| 66 | if (path.isAbsolute(file_path)) { |
| 67 | relPath = path.relative(task.cwd, file_path) |
| 68 | } else { |
| 69 | relPath = file_path |
| 70 | } |
| 71 | |
| 72 | const accessAllowed = task.rooIgnoreController?.validateAccess(relPath) |
| 73 | |
| 74 | if (!accessAllowed) { |
| 75 | await task.say("rooignore_error", relPath) |
| 76 | pushToolResult(formatResponse.rooIgnoreError(relPath)) |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | // Check if file is write-protected |
| 81 | const isWriteProtected = task.rooProtectedController?.isWriteProtected(relPath) || false |
| 82 | |
| 83 | const absolutePath = path.resolve(task.cwd, relPath) |
| 84 |
nothing calls this directly
no test coverage detected