delete_file
Delete files and directories from the workspace by specifying their path. Clean up or remove unwanted items during development.
Instructions
Delete a file or directory
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to delete |
Implementation Reference
- src/services/FileService.ts:389-421 (handler)The main handler function for the delete_file tool. It resolves the file path via WorkspaceService, checks if it's a directory (using rmdir) or a file (using unlink), clears the stats cache, and returns a success or error result.
/** * Delete a file or directory */ async deleteFile(filePath: string, options?: { force?: boolean }): Promise<ToolResult> { try { const fullPath = this.workspaceService.resolvePath(filePath); const stats = await this.getFileStats(fullPath); if (stats.isDirectory) { await fs.rmdir(fullPath, { recursive: true }); } else { await fs.unlink(fullPath); } // Clear cache this.clearStatsCache(fullPath); return { content: [{ type: 'text', text: `${stats.isDirectory ? 'Directory' : 'File'} successfully deleted: ${fullPath}`, }], }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: error.message || 'Failed to delete file/directory' }] }; } } - src/toolDefinitions.ts:119-129 (schema)The input schema definition for the delete_file tool. It defines the 'path' property as a required string and provides a description.
{ name: 'delete_file', description: 'Delete a file or directory', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to delete' }, }, required: ['path'], }, }, - src/index.ts:165-166 (registration)The dispatch/registration of the 'delete_file' tool command in the main VSCodeAgentServer class. It routes the call to this.fileService.deleteFile(args.path).
case 'delete_file': return await this.fileService.deleteFile(args.path); - tests/utils.ts:269-269 (helper)A jest mock function for deleteFile used in test utilities to create a mock FileService.
deleteFile: jest.fn(),