Introduction¶
When running automated scripts or conversations in a DSH environment, accidental use of the rm command often leads to irreversible data loss. nattocb/dsh-safe-delete is a DSH plugin that intercepts rm operations in all bash sessions and rewrites them to move items to the macOS Trash instead of deleting them directly, providing a recoverable deletion method.
Positioning¶
This is a host-side DSH plugin maintained by NattoCB under the MIT License. Its core purpose is to register a guard at the DSH tool registry level to intercept all rm command executions.
Core Features¶
The plugin provides the following capabilities:
1. Recoverable deletion: intercepts rm and rewrites it to /usr/bin/trash; the model receives a report of the moved target.
2. Global coverage: registered once in the DSH tool registry, it covers GUI chat, automated runs, headless bridging, and subagent sessions.
3. Shell-aware interception: handles rm in sudo rm, xargs rm, and compound commands (&&, ||, ;, |).
4. Fail-safe design: for constructs that may conceal rm (subshells, backticks, heredocs, eval), the plugin refuses execution and provides a hint instead of silently processing it.
5. Runtime toggle: supports enabling or disabling through the Web GUI, HTTP API, or file configuration.
Installation and Enablement¶
Installing the plugin requires restarting the DSH Web process for it to take effect.
dsh plugin --profile web add github:NattoCB/dsh-safe-delete
After startup, the logs display rm guard active, indicating that the guard is ready.
Typical Usage¶
The plugin is enabled by default. Users can directly use the rm command, and the system automatically moves targets to the Trash instead of deleting them.
* Web GUI toggle: access the Settings → General → Safe Delete switch.
* HTTP API configuration: send a POST request to /safe-delete/config with { "enabled": true/false }.
* Check configuration status: inspect the file $DSH_HOME/storages/safe-delete or $DSH_HOME/storages/safe-delete.json.
Applicable Scenarios and Notes¶
- Suitable scenarios: suitable for system administration, automated deployment, and script writing scenarios that need to prevent accidental deletion.
- Coverage: intercepts
rm,sudo rm, absolute pathrm, andxargs rm. - Non-covered scenarios: does not cover
find -delete,unlink,git clean, or language runtime file APIs. - Permission limitations: although
sudo rmis intercepted, if a file requires root privileges, thetrashoperation may fail; the error message is reported as-is.
Conclusion¶
Through a zero-dependency guard pattern, the plugin protects against the most common deletion commands. For related documentation and source code, refer to the directory page and GitHub repository below.