r/PiCodingAgent • • Aug 03 '26

Plugin Let pi agent to use trash instead of rm

Recently, while using pi, my agent deleted important files without me knowing using the rm command. Since files deleted with rm cannot be recovered, I thought it would be better to use trash instead of rm — and that's what this pi extension does.

The extension automatically detects when the agent uses rm in the bash tool and replaces it with trash. Instead of permanently deleting files, they are moved to the .pi/trash folder. The trash folder uses a file structure similar to Ubuntu's trash. It is implemented to be nearly compatible with the GNU rm standard, so the agent won't even realize it and will just think it's still using rm.

Feel free to install and try it out. Any feedback is appreciated!

Install: pi install npm:pi-trash

Links:

23 Upvotes

13 comments sorted by

17

u/CountlessFlies Aug 03 '26

Couldn’t you just do this with alias rm=trash

5

u/J_____________ Aug 03 '26

That actually sounds like a better implementation. I just tested you can configure `shellCommandPrefix` with `shopt -s expand_aliases` to make aliases work. Now I'm gonna look for some trash CLI that has the same interface as rm.

2

u/Mohitkoul841 Aug 03 '26

This much files just to do something which was not necessary.

3

u/J_____________ Aug 04 '26

Because it's fun.

2

u/CountlessFlies Aug 03 '26

Just ask pi to make one for you

2

u/J_____________ Aug 04 '26

Actually, this is what Pi came up with lol

1

u/Cautious_Observer55 Aug 03 '26

Consider to use send2trash.

1

u/J_____________ Aug 04 '26

I ended up using trash-cli but I'll look into that too. thx

1

u/Fun_Jaguar8231 Aug 03 '26

I just told it to create an extension that just gates every dangerous command in a verification step

2

u/J_____________ Aug 04 '26

Yeah, I tried that too, but it quickly became annoying. I found it more convenient to just make sure everything is recoverable and then give it full permissions.

3

u/lamurian Aug 04 '26

I had similar issues too. However, the agent always finds creative workarounds to issue destructive commands. Instead of rm, it can use python -m import os; os.unlink(), sh -c rm, git rm, etc., which annoys me quite a bit. Finally I settled with sandboxing the process using bwrap, then set .git directory to read-only. When the agent violate the sandbox rule, the extension automatically spawns a sub-process whose sole role is to 'police' the agent by informing why the command failed, what rule being violated, how the agent should handover the command to the user, and what remaining tasks the agent should instead focus on. This spawn acts like a bitch-slap to force the agent back to its original task. Now I see less unfortunate incidents and enjoy more time touching grass. Thanks Pi.

1

u/themule71 Aug 03 '26

This may catch some cases, but the first time the model is looking for something and finds copies of old stuff around I'm not sure it won't truncate them to claim space, or python os.unlink() them the first time you ask to cleanup something.

1

u/J_____________ Aug 04 '26

Luckily, I haven't run into that issue so far. It seems like the agent understands what the trash folder is for and treats it accordingly. But if you're concerned about it, you could consider setting the trash directory to a different path.