feat(tools): add remove_dir tool#277
Merged
LeeCheneler merged 2 commits intomainfrom Apr 10, 2026
Merged
Conversation
Prep for the upcoming remove_dir tool, which will add a "removeDir" operation to this type. Renames FileOperation → PathOperation and checkFilePermission → checkPathPermission to reflect that the helper covers both files and directories. Pure rename, no behaviour change.
Adds a new remove_dir tool so the model can delete directories directly instead of escaping into run_command rm / rm -rf. The tool has two modes: - Non-recursive (default): removes an empty directory, fails on non-empty. Gated by new cwdRemoveDir / globalRemoveDir permission keys that follow the existing optional-boolean pattern. - Recursive: removes the entire tree. Always prompts for confirmation regardless of permission state — the permission flag only gates the safe single-empty-dir case, not arbitrary tree removal. The mock-fs test helper now tracks explicit empty directories via a dirs Set alongside the file map. ensureDir registers paths (was a no-op), an optional second ctor arg accepts initial empty dirs, and a new removeDir spy enforces ENOENT / ENOTEMPTY semantics. This lets the non-recursive "removes empty dir" cases be tested without standing up a real filesystem. Closes #251
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
remove_dirtool so the model can delete directories directly without escaping intorun_command rm -rf. Two modes: non-recursive (permission-gated, safe single-empty-dir case) and recursive (always prompts regardless of permissions).GitHub Issue
Closes #251
What Changed
New tool.
remove_dirtakespath+ optionalrecursive(default false). Error ordering: path-is-file → suggestremove_file; path doesn't exist → error; non-recursive + non-empty → error suggestingrecursive: true.formatCallreturnspathorpath (recursive)so the collapsed tool header reflects the mode.Two confirmation paths. Non-recursive uses the standard permission resolution against the new
cwdRemoveDir/globalRemoveDirkeys and only prompts when not pre-granted. Recursive always prompts regardless of permission state — the permission flag is not authorisation for arbitrary tree removal, only for the safe single-empty-dir case. Both modes use label"Remove directory?"; recursive adds(recursive)to the detail line so the prompt header visibly signals the bigger blast radius.Schema.
cwdRemoveDir/globalRemoveDirfollow the optional-boolean pattern alongside the existing read/write/remove keys.removeDirjoinstoolsSchemawith the field-level.default({ enabled: true })pattern we standardised in #276, so adding this tool is non-breaking for existing configs.PathOperationextended. The union already covered"read" | "write" | "remove"; now also"removeDir". ThePERMISSION_KEYSmap gets a new entry — no branching changes, uniform handling across all four operations. (FileOperation→PathOperationrename happened in the prep commit e0ce922.)mock-fs upgrade. The test helper previously had no concept of an empty directory — directories were inferred from file prefixes, so
isDirectory("/empty/dir")was always false unless files existed under it. That broke the non-recursive "removes empty dir" cases. Fixed by tracking explicit dirs in aSet<string>alongside the file map:ensureDirnow registers paths instead of being a no-op.initialDirs: string[]for test convenience.isDirectoryreturns true if path is indirsOR has files under it.removeDirspy enforces ENOENT (missing path) and ENOTEMPTY (non-empty non-recursive) semantics.getDirs()helper on the returned state.Settings UI. New "Remove Directory" entry in the tools toggle list and two "Remove directories (current directory / global)" entries in the permissions toggle list.
Docs. README tools table, permissions YAML example, new "recursive always prompts" callout explaining the non-authorisation semantics of the permission flag, and CONTRIBUTING's
src/tree comment.Notes for Reviewers
FileOperation→PathOperation,checkFilePermission→checkPathPermission) to prep for the new"removeDir"operation, no behaviour change. Second is the feature itself. Happy to squash on merge either way.remove-dir.ts:66-77. Theif (parsed.recursive)branch unconditionally callscontext.confirmbefore reaching the permission check. The permission matrix test "still prompts when cwdRemoveDir is granted" covers this explicitly.fileExists && !isDirectory→ file → suggestremove_file(check first). Then!isDirectory→ doesn't exist. If reordered, the file-path case would report "does not exist" instead.stub-context.tsdefault permissions now includecwdRemoveDir: truefor happy-path test convenience. Permission-matrix tests still pin explicit values.remove-dir.tsand the updatedmock-fs.ts.