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

0 Upvotes

25 comments sorted by

7

u/rouch_cornel 1d ago

Git

-1

u/tcpip84 1d ago

Please read the question. 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.

3

u/lukyjay 1d ago

One session touches multiple repos?

Without knowing the software you're developing, I'd suggest breaking your sessions down more. I never have more that one change per session.

Even a feature touching a front end and back end (assuming different repos) would be in two sessions for me

1

u/tcpip84 22h ago

Agreed that the approach would work when building software, but this is for infra changes which seem scattered across multiple repos.

1

u/lukyjay 15h ago

Sorry can't help you.. I usually use planning skills to determine what changes are needed and then the agents will implement those changes so I know ahead of time what it's doing and what repos will be touched.

If you're interested in my workflow, google: matt pocock aihero

2

u/tcpip84 10h ago

Thanks - willcheck it out.

1

u/fschwiet 22h ago

Keep a list of repos and check all of them?

1

u/tcpip84 22h ago

Yea I ended up hooking edit mode to detect and where python/bash direct file changes by model couldn't be detect, gave an option to add the dir manually.

2

u/Dsphar 1d ago

Monorepo.

Or git submodules.

1

u/fyv8 1d ago

I do one session with multiple repos all the time. I guess I don't find it an imposition to just list the changes in each repo that I'm having at work on. Sometimes I'll back up or put a directory under a revision control if I want to track things the agent might do to it.

I like the idea of tracking every change, independently of git, from the harness itself. I don't think I would use it a lot, but it would be a good cross-check to see if it affected anything outside of git's control.

But if your agent is able to do bash, or write or invoke any program that can touch multiple files, a general purpose harness hook that catches everything is a hard problem.

You would ultimately need to rely on something very specific to the os/filesystem or virtualized environment your agent runs in. That's the direction I would look toward for functionality that could enable this.

I can definitely see some utility in what you're asking for here. I just think to solve it properly is much harder problem than writing a hook for pi, and can't be solved practically in a way that generalizes across runtime environments. I'd love to be proved wrong.

1

u/BorgSympathizer 19h ago

I read the question but I struggle to understand what the issue is. I work with multiple repos all the time.

Review each PR in a corresponding repo while track all the changes in the session. What exactly is the problem?

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/tcpip84 22h ago

Thanks - will check it out

1

u/Silver-Ad-8595 1d ago

There are hooks for pre- and post-tool calls...

0

u/tcpip84 1d ago

As called out in the original post - you can have pre/post calls for edit tools but when models bypass them through bash and python tool calls - you can't track them.

1

u/Silver-Ad-8595 1d ago

You can also limit their toolbelt.

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/tcpip84 10h ago

wanted something pi native - for external ways - can always do something like lazygit in the repo dir

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.

1

u/tcpip84 1d ago

Got it - so in your case you are able to check all changes through overlayfs. In my case, I was looking for a way that pi extension can catch changes beyond hooking into edit calls.

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

u/[deleted] 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.