opencode
opencode copied to clipboard
fix: filter git operations from session diffs
Summary
When git operations like pull, merge, or checkout are run (either through OpenCode or in a separate terminal), the changed files would inflate the session diff counts in the sidebar, showing thousands of lines changed that weren't actually edited by the agent.
Changes
-
New
FileTrackingmodule (session/file-tracking.ts): Tracks files modified by git operations during a session -
Bash tool updates: Detects git worktree-modifying commands (
pull,merge,checkout,rebase, etc.) and tracks affected files -
Step boundary tracking: Records the project's git HEAD at
step-startandstep-finishto detect external git operations - Diff filtering: Excludes git-modified files from session diffs unless they were also explicitly edited by tools
How It Works
- At
step-start: Records the project's git HEAD - During execution: If bash runs a git op, tracks changed files immediately
- At
step-finish: Records the new git HEAD - When computing diffs:
- Compares HEAD at step boundaries to find all git-modified files (catches external git ops)
- Filters the final diff to exclude git-modified files
- Still includes files if they were explicitly edited by edit/write/patch tools
Handles
- Git ops run through OpenCode's bash tool
- Git ops run in a separate terminal by the user
- User external edits (preserved - they show in snapshot diff but NOT in git-modified list)
- Files that are both pulled AND subsequently edited by tools (included)