(params: SearchFilesParams, task: Task, callbacks: ToolCallbacks)
| 20 | readonly name = "search_files" as const |
| 21 | |
| 22 | async execute(params: SearchFilesParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 23 | const { askApproval, handleError, pushToolResult } = callbacks |
| 24 | |
| 25 | const relDirPath = params.path |
| 26 | const regex = params.regex |
| 27 | const filePattern = params.file_pattern || undefined |
| 28 | |
| 29 | if (!relDirPath) { |
| 30 | task.consecutiveMistakeCount++ |
| 31 | task.recordToolError("search_files") |
| 32 | task.didToolFailInCurrentTurn = true |
| 33 | pushToolResult(await task.sayAndCreateMissingParamError("search_files", "path")) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | if (!regex) { |
| 38 | task.consecutiveMistakeCount++ |
| 39 | task.recordToolError("search_files") |
| 40 | task.didToolFailInCurrentTurn = true |
| 41 | pushToolResult(await task.sayAndCreateMissingParamError("search_files", "regex")) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | task.consecutiveMistakeCount = 0 |
| 46 | |
| 47 | const absolutePath = path.resolve(task.cwd, relDirPath) |
| 48 | const isOutsideWorkspace = isPathOutsideWorkspace(absolutePath) |
| 49 | |
| 50 | const sharedMessageProps: ClineSayTool = { |
| 51 | tool: "searchFiles", |
| 52 | path: getReadablePath(task.cwd, relDirPath), |
| 53 | regex: regex, |
| 54 | filePattern: filePattern, |
| 55 | isOutsideWorkspace, |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | const results = await regexSearchFiles(task.cwd, absolutePath, regex, filePattern, task.rooIgnoreController) |
| 60 | |
| 61 | const completeMessage = JSON.stringify({ ...sharedMessageProps, content: results } satisfies ClineSayTool) |
| 62 | const didApprove = await askApproval("tool", completeMessage) |
| 63 | |
| 64 | if (!didApprove) { |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | pushToolResult(results) |
| 69 | } catch (error) { |
| 70 | await handleError("searching files", error as Error) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | override async handlePartial(task: Task, block: ToolUse<"search_files">): Promise<void> { |
| 75 | const relDirPath = block.params.path |
nothing calls this directly
no test coverage detected