Skip to content

feature: add AI-powered Git diff analysis for working tree and commit range comparison#2457

Open
YuHaoLiaoTony wants to merge 1 commit into
sourcegit-scm:developfrom
YuHaoLiaoTony:tony/AIDiffContext
Open

feature: add AI-powered Git diff analysis for working tree and commit range comparison#2457
YuHaoLiaoTony wants to merge 1 commit into
sourcegit-scm:developfrom
YuHaoLiaoTony:tony/AIDiffContext

Conversation

@YuHaoLiaoTony

@YuHaoLiaoTony YuHaoLiaoTony commented Jun 18, 2026

Copy link
Copy Markdown

This PR adds an AI-powered Git diff analysis feature that lets users get a natural-language summary of their changes using their configured OpenAI-compatible AI service.

What's new

  • Working tree analysis: Analyze staged + unstaged changes directly from the commit message toolbar
  • Commit range analysis: Select two commits in History and analyze the diff between them, accessible via right-click context menu or the Revision Compare toolbar button
  • Locale-aware AI output: Automatically maps the app's UI locale (16 languages) into the AI prompt, so the summary is generated in the user's language
  • Large diff protection: Automatically truncates diffs exceeding 100K characters or 3K lines; individual files over 20K chars are skipped
  • Binary/LFS skipping: Binary files and LFS pointers are automatically detected and excluded from the analysis payload
  • Markdown rendering: AI output is rendered with proper heading, code block, and inline code formatting using a new MarkdownResultView control
  • Model selection: The analysis dialog includes a model ComboBox matching the existing AI commit message UX, disabled during analysis to prevent mid-request model switching

Architecture

All new code follows the existing MVVM and AI module patterns:

  • AI/ layer: AIDiffContextData (data model), AIDiffContextBuilder (git command execution with SHA validation), DiffPrompts (prompt templates + locale mapping), DiffAgent (thin API call wrapper)
  • ViewModels/AIDiffAnalysis.cs: state management, cancellation, retry, error mapping
  • Views/AIDiffAnalysis.axaml + MarkdownResultView.axaml: popup dialog with Markdown rendering

Existing file changes

Minimal modifications to 7 existing files:

  • RevisionCompare.cs: exposed GetSHA() and Repository property (internal → public)
  • CommitMessageToolBox.axaml + .cs: one toolbar button + handler
  • Histories.axaml.cs: context menu item for 2-commit selection + helper
  • RevisionCompare.axaml + .cs: one title bar button + handler
  • AIAssistant.axaml.cs: enabled WordWrap on AIResponseView
  • en_US.axaml + 14 locale files: 18 new localization keys each

Verification

  • dotnet build succeeds (0 errors, 0 warnings)
  • No AI service configured → user notification shown
  • No changes to analyze → user notification shown
  • Single AI service → dialog opens directly
  • Multiple AI services → service selection menu shown
  • Binary/LFS files → skipped with mention in output
  • Large diffs → truncated to stat-only mode

… range comparison

- Add AIDiffContextBuilder with safe git command execution, SHA validation,
  large diff protection (100K chars / 3K lines), binary/LFS file skipping
- Add DiffPrompts with 16-locale language mapping and two prompt templates
- Add DiffAgent as thin AI API call layer reusing existing AI.Service
- Add AIDiffAnalysis ViewModel with analysis state, cancellation, retry
- Add model selection ComboBox matching existing AI commit message UX
- Add MarkdownResultView to render AI output (headings, code, inline code)
- Add working tree analysis button in CommitMessageToolBox toolbar
- Add two-commit analysis via History context menu and RevisionCompare toolbar
- Add 18 locale keys across all 15 locale files
- Fix AIAssistant AIResponseView to enable WordWrap
@YuHaoLiaoTony YuHaoLiaoTony changed the title feature: add AI-powered Git diff analysis for working tree and commit… feature: add AI-powered Git diff analysis for working tree and commit range comparison Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant