r/PiCodingAgent • • 55m 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?

1 Upvotes

3 comments sorted by

2

u/schmurfy2 42m 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 33m 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 1m 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.