opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add user diff tracking to show external file changes between generations

Open R44VC0RP opened this issue 1 month ago • 1 comments

Summary

This PR implements a "user diff" feature that tracks and displays external file changes made by users between AI generations. When a user modifies files outside of OpenCode and submits a new prompt, the system now shows what changed.

  • Captures a snapshot at the end of each successful AI generation
  • Computes diff against the snapshot when a new prompt is submitted
  • Shows changes in the TUI with file status indicators (A/M/D)
  • Injects diff context into the conversation for the AI to understand
  • Includes protections against context overload (max 50 files, 10k chars)
  • Ignores common non-essential files (node_modules, dist, lock files, etc.)

Changes

  • Added lastGenerationSnapshot field to Session schema
  • Created new UserDiffPart message part type
  • New user-diff.ts module for diff computation and formatting
  • Modified SessionProcessor to capture snapshots at end of generation
  • Modified SessionPrompt to compute and inject user diffs
  • Added TUI rendering for user diff display
  • Regenerated SDK types

Design Doc

See specs/user-diff.md for the full design specification.

R44VC0RP avatar Dec 26 '25 21:12 R44VC0RP

this is a POC do not merge

R44VC0RP avatar Dec 26 '25 21:12 R44VC0RP