r/PiCodingAgent • u/tcpip84 • 1d ago
Question How do you track which files a pi session changed, including edits made through bash?
I want to keep track of the files my pi session changes, and look them up at any point during the session. One session often touches 3 or 4 repos, so `git status` in pi's working dir doesn't give me that list.
I thought this would be easy: hook into `edit` and collect the changed files. But some models edit files through bash or python instead. In https://github.com/earendil-works/pi/issues/11876 a maintainer replied that this is model behaviour and pi can't do much about it. So how do you keep track of the files a session changed when some of the edits never go through `edit`?
What I have so far
I wrote a small extension that hooks `tool_result` for the `edit` and `write` tools:
- For each file, it runs `git rev-parse --show-toplevel` and records the file and its repo root in a JSON file for that session.
- It skips files that aren't in a git repo.
- A picker reads that list and opens a diff review for the repo I choose.
This works well for anything the model changes through `edit` or `write`.
The gap
The extension never sees changes the model makes through bash, such as `sed -i`, `perl -i`, or a `python3 - <<EOF` heredoc.
What I've looked at
- https://pi.dev/packages/pi-workspace-history It snapshots the workspace with git, so it does catch bash edits. But it tracks a single workspace, it's off in the home dir by default, and it skips nested repos, so it doesn't fit my setup.
- Running `git status` after every bash call in the repos the session already knows about. This catches bash edits in those repos, but it's expensive: one `git status` per known repo after every bash call. It also can't find a repo the session didn't already know about, so a repo the model only ever touched through bash is still missed.
- Blocking `sed -i` and similar commands in a permission-gate extension, with a message telling the model to use `edit`. That enforces the rule, but sometimes a bash edit is the right call, for example a rename across many files.
Has anyone found a reliable way to catch the files a model writes through bash?
2
u/schmurfy2 1d ago
I tried the extension path at first but I finally approached that with another angle.
I always run my agents in a sandbox but I increased the restrictions, I use a tool called nono and the agent only has access to a feature folder with all the worktrees it need checked out below (most if not all my work involves at least two repositories), the agent only has rw access to this folder, don't have access to my credentials, and no write access to the mais clone of each repositories so it can't commit.
I review the changes and make the commit myself. I have a legacy diff extension but I no longer use it and it will be removed soon.
1
u/tcpip84 1d ago
Thanks, that's a different way to look at it. If the agent can only write inside one feature folder, it doesn't matter whether it uses edit or sed, because every change lands somewhere you already know about. Then it's just `git status` in each worktree.
How do you handle a task that turns out to need a repo you didn't set up at the start? Do you stop the session, add a worktree and relaunch, or do you plan the repo list before you start?
1
u/schmurfy2 1d ago
I have a cli tool to create worktrees from a list of available sources coupled with agent instructions to ask whenever it needs a new worktrees.
I also configured nono so that the agent as ro access to the main repositories to be able to look at them.It works very well for me and another side effects is that all my pi sessions are tied to the feature folder making it easier to find them later if needed.
2
u/soulsizzle 23h ago
If you work from a shared parent directory, T3Code has this multi-repo awareness. I'd consider pointing your agent at its source code to see how it accomplishes this.
1
u/Silver-Ad-8595 1d ago
There are hooks for pre- and post-tool calls...
1
u/our_sole 21h ago
IIF you are using windows:
Open up a VS Code instance for each repo, starting in the repo root. Run pi in one of them. Use git for each repo.
As pi changes files, flip between the VS Code windows, watching the git tab for changes.
1
u/dir3ctly 1d ago
If you are on Linux:
I use overlayfs when I want to be sure the agent does not mess anything up. The agent works on the mounted (virtual) filesystem on top of your real data and once done, I can do a diff and review the changes before applying them. I wrote some tooling around that.
Also, the agent runs inside a container where the filesystem is mounted.
0
u/Slow-Secretary4262 1d ago
its easy if it changes files in a single repo and only 1 session at the time, for multiple repos i guess it could be possible if its still 1 session at the time
0
1d ago
[deleted]
1
u/tcpip84 1d ago
The question is around pi handling multiple repos and then the user being able to list out those repos during a session. The code is obviously tracked in git but when working through multiple repos, I want a way to list out the state of each repo by tracking them in pi. It was earlier possible by having extensions which hook on to edit calls, but now with models bypassing that and using direct bash tools for it - pi can't track it.
7
u/rouch_cornel 1d ago
Git