(params: ListFilesParams, task: Task, callbacks: ToolCallbacks)
| 20 | readonly name = "list_files" as const |
| 21 | |
| 22 | async execute(params: ListFilesParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 23 | const { path: relDirPath, recursive } = params |
| 24 | const { askApproval, handleError, pushToolResult } = callbacks |
| 25 | |
| 26 | try { |
| 27 | if (!relDirPath) { |
| 28 | task.consecutiveMistakeCount++ |
| 29 | task.recordToolError("list_files") |
| 30 | task.didToolFailInCurrentTurn = true |
| 31 | pushToolResult(await task.sayAndCreateMissingParamError("list_files", "path")) |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | task.consecutiveMistakeCount = 0 |
| 36 | |
| 37 | const absolutePath = path.resolve(task.cwd, relDirPath) |
| 38 | const isOutsideWorkspace = isPathOutsideWorkspace(absolutePath) |
| 39 | |
| 40 | const [files, didHitLimit] = await listFiles(absolutePath, recursive || false, 200) |
| 41 | const { showRooIgnoredFiles = false } = (await task.providerRef.deref()?.getState()) ?? {} |
| 42 | |
| 43 | const result = formatResponse.formatFilesList( |
| 44 | absolutePath, |
| 45 | files, |
| 46 | didHitLimit, |
| 47 | task.rooIgnoreController, |
| 48 | showRooIgnoredFiles, |
| 49 | task.rooProtectedController, |
| 50 | ) |
| 51 | |
| 52 | const sharedMessageProps: ClineSayTool = { |
| 53 | tool: !recursive ? "listFilesTopLevel" : "listFilesRecursive", |
| 54 | path: getReadablePath(task.cwd, relDirPath), |
| 55 | isOutsideWorkspace, |
| 56 | } |
| 57 | |
| 58 | const completeMessage = JSON.stringify({ ...sharedMessageProps, content: result } satisfies ClineSayTool) |
| 59 | const didApprove = await askApproval("tool", completeMessage) |
| 60 | |
| 61 | if (!didApprove) { |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | pushToolResult(result) |
| 66 | } catch (error) { |
| 67 | await handleError("listing files", error) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | override async handlePartial(task: Task, block: ToolUse<"list_files">): Promise<void> { |
| 72 | const relDirPath: string | undefined = block.params.path |
nothing calls this directly
no test coverage detected