Delete a workspace file or directory.
(
path: Annotated[str, ParamMeta(description="Workspace-relative file or folder path")],
*,
recursive: Annotated[
bool,
ParamMeta(description="Allow deleting non-empty directories recursively"),
] = False,
missing_ok: Annotated[bool, ParamMeta(description="Suppress error if path is missing")]
= False,
_context: Dict[str, Any] | None = None,
)
| 267 | |
| 268 | |
| 269 | def delete_path( |
| 270 | path: Annotated[str, ParamMeta(description="Workspace-relative file or folder path")], |
| 271 | *, |
| 272 | recursive: Annotated[ |
| 273 | bool, |
| 274 | ParamMeta(description="Allow deleting non-empty directories recursively"), |
| 275 | ] = False, |
| 276 | missing_ok: Annotated[bool, ParamMeta(description="Suppress error if path is missing")] |
| 277 | = False, |
| 278 | _context: Dict[str, Any] | None = None, |
| 279 | ) -> Dict[str, Any]: |
| 280 | """Delete a workspace file or directory.""" |
| 281 | |
| 282 | if not path: |
| 283 | raise ValueError("path must be provided") |
| 284 | |
| 285 | _check_attachments_not_modified(path) |
| 286 | |
| 287 | ctx = FileToolContext(_context) |
| 288 | target = ctx.resolve_under_workspace(path) |
| 289 | |
| 290 | if not target.exists(): |
| 291 | if missing_ok: |
| 292 | return { |
| 293 | "path": ctx.to_workspace_relative(target), |
| 294 | "absolute_path": str(target), |
| 295 | "deleted": False, |
| 296 | "reason": "missing", |
| 297 | } |
| 298 | raise FileNotFoundError(f"Path not found: {path}") |
| 299 | |
| 300 | if target.is_dir(): |
| 301 | if not recursive: |
| 302 | raise IsADirectoryError("Set recursive=True to delete directories") |
| 303 | shutil.rmtree(target) |
| 304 | deleted_type = "directory" |
| 305 | else: |
| 306 | target.unlink() |
| 307 | deleted_type = "file" |
| 308 | |
| 309 | return { |
| 310 | "path": ctx.to_workspace_relative(target), |
| 311 | "absolute_path": str(target), |
| 312 | "deleted": True, |
| 313 | "type": deleted_type, |
| 314 | } |
| 315 | |
| 316 | |
| 317 | def load_file( |
nothing calls this directly
no test coverage detected