Skip to content

Conversation

@R44VC0RP
Copy link
Collaborator

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.

image

Changes

  • New FileTracking module (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-start and step-finish to detect external git operations
  • Diff filtering: Excludes git-modified files from session diffs unless they were also explicitly edited by tools

How It Works

  1. At step-start: Records the project's git HEAD
  2. During execution: If bash runs a git op, tracks changed files immediately
  3. At step-finish: Records the new git HEAD
  4. 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)

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, showing thousands of lines changed that weren't
actually edited by the agent.

This change:
- Tracks the project's git HEAD at step boundaries (step-start/step-finish)
- Detects git worktree-modifying commands in the bash tool
- Computes files changed by git operations (HEAD changes between steps)
- Filters session diffs to exclude git-modified files
- Still includes files if they were explicitly edited by tools after being pulled

This preserves user external edits while excluding bulk changes from git ops.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

- FileTracking module tests for tracking git-modified files
- Snapshot.getProjectHead and getProjectChangedFiles tests
- Bash tool git operation detection and tracking tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant