( absolutePath: string, relPath: string, task: Task, callbacks: ToolCallbacks, isWriteProtected: boolean, )
| 231 | } |
| 232 | |
| 233 | private async handleDeleteFile( |
| 234 | absolutePath: string, |
| 235 | relPath: string, |
| 236 | task: Task, |
| 237 | callbacks: ToolCallbacks, |
| 238 | isWriteProtected: boolean, |
| 239 | ): Promise<void> { |
| 240 | const { askApproval, pushToolResult } = callbacks |
| 241 | |
| 242 | // Check if file exists |
| 243 | const fileExists = await fileExistsAtPath(absolutePath) |
| 244 | if (!fileExists) { |
| 245 | task.consecutiveMistakeCount++ |
| 246 | task.recordToolError("apply_patch") |
| 247 | const errorMessage = `File not found: ${relPath}. Cannot delete a non-existent file.` |
| 248 | await task.say("error", errorMessage) |
| 249 | pushToolResult(formatResponse.toolError(errorMessage)) |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | const isOutsideWorkspace = isPathOutsideWorkspace(absolutePath) |
| 254 | |
| 255 | const sharedMessageProps: ClineSayTool = { |
| 256 | tool: "appliedDiff", |
| 257 | path: getReadablePath(task.cwd, relPath), |
| 258 | diff: `File will be deleted: ${relPath}`, |
| 259 | isOutsideWorkspace, |
| 260 | } |
| 261 | |
| 262 | const completeMessage = JSON.stringify({ |
| 263 | ...sharedMessageProps, |
| 264 | content: `Delete file: ${relPath}`, |
| 265 | isProtected: isWriteProtected, |
| 266 | } satisfies ClineSayTool) |
| 267 | |
| 268 | const didApprove = await askApproval("tool", completeMessage, undefined, isWriteProtected) |
| 269 | |
| 270 | if (!didApprove) { |
| 271 | pushToolResult("Delete operation was rejected by the user.") |
| 272 | return |
| 273 | } |
| 274 | |
| 275 | // Delete the file |
| 276 | try { |
| 277 | await fs.unlink(absolutePath) |
| 278 | } catch (error) { |
| 279 | const errorMessage = `Failed to delete file '${relPath}': ${error instanceof Error ? error.message : String(error)}` |
| 280 | await task.say("error", errorMessage) |
| 281 | pushToolResult(formatResponse.toolError(errorMessage)) |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | task.didEditFile = true |
| 286 | pushToolResult(`Successfully deleted ${relPath}`) |
| 287 | task.processQueuedMessages() |
| 288 | } |
| 289 | |
| 290 | private async handleUpdateFile( |
no test coverage detected