Diff Review Doc
Generate comprehensive code review documents from git diffs, providing detailed analysis with real code snippets, business flow breakdown, and actionable review recommendations.
Workflow
1. Obtain Diff Content
If user provides diff directly:
- Accept the diff content as-is
- Parse to identify changed files and hunks
If no diff is provided:
2. Analyze the Changes
Parse the diff to extract:
- File paths and change types (added/modified/deleted)
- Line-level changes (+/- lines)
- Context around changes
Read relevant files:
- For significant changes, read the full file to understand context
- For large files (>500 lines), focus on changed sections with surrounding context
- Pay special attention to backend files and large file changes
Identify patterns:
- Consult
references/patterns.md for common code issues
- Look for anti-patterns, security vulnerabilities, performance issues
- Check architectural concerns
3. Structure the Analysis
Follow this analysis framework:
改动概览 (Change Summary)
- Count files changed, lines added/removed
- Identify change type (feature/bugfix/refactor/performance/security)
- List key files with brief descriptions
- Note dependency or configuration changes
业务流程分析 (Business Flow Analysis)
- Explain what functionality is being implemented/changed
- Map out the complete business flow
- Show data flow between components
- Identify all affected modules
关键代码详解 (Key Code Analysis)
- For each significant file:
- Show actual diff snippets (use real code from the diff)
- Explain what the code does and why it changed
- Highlight logic correctness, edge cases, error handling, performance
- Prioritize backend files and large changes (>200 lines)
- Include file paths with line numbers for reference
风险评估 (Risk Assessment)
- Categorize risks as High/Medium/Low
- Identify breaking changes, security concerns, performance impacts
- Suggest mitigation measures
- Flag large file changes and backend-critical changes
4. Generate Review Recommendations
Consult references/review-checklist.md for comprehensive evaluation criteria:
- 代码质量 (Code Quality): Readability, complexity, best practices
- 架构设计 (Architecture): Modularity, coupling, extensibility, data flow
- 功能验证 (Functionality): Business logic, error handling, data consistency
- 安全性 (Security): Input validation, authentication, data protection (if applicable)
- 性能 (Performance): Database queries, resource usage, caching (if applicable)
For each category:
- Give a rating (1-5 stars)
- List strengths (what's done well)
- List issues (what needs improvement)
- Provide specific, actionable recommendations
Final recommendation:
- Must Fix: Critical issues that block merge
- Should Fix: Important issues to address
- Nice to Have: Optional improvements
- Merge decision: Approve / Conditional / Needs Work
5. Write the Review Document
Use assets/review-template.md as the base structure:
- Copy the template structure
- Fill in all sections with actual analysis from steps 2-4
- Ensure all code snippets are real (from the actual diff)
- Include complete business flow explanation
- Provide specific, actionable review suggestions
Output:
- Save as a Markdown file (e.g.,
REVIEW.md)
- Format for easy reading (proper headings, code blocks, lists)
- Include generation timestamp
Key Principles
Base on Real Code
- All code snippets must be extracted from the actual diff
- Never use placeholder or example code
- Show actual line numbers and file paths
Complete Business Context
- Explain the full user journey and data flow
- Connect frontend changes to backend logic
- Show how pieces fit together
Actionable Review Suggestions
- Be specific about what to check
- Identify potential risks with clear explanations
- Provide concrete improvement suggestions
- Prioritize issues by severity
Focus on Critical Areas
- Large file changes: >200 lines need detailed review
- Backend changes: API, database, auth, integrations
- Architectural changes: Design patterns, module boundaries
- Security-sensitive code: Input validation, data access
Resources
scripts/get_diff.sh
Bash script to retrieve git diffs in various scenarios. Supports getting uncommitted changes, staged changes, branch comparisons, and specific commits.
references/review-checklist.md
Comprehensive checklist covering all aspects of code review: quality, architecture, functionality, security, performance, testing, compatibility, operations, and documentation.
Load this reference when generating review recommendations to ensure thorough evaluation.
references/patterns.md
Catalog of common code patterns to watch for, including anti-patterns, security vulnerabilities, performance issues, and architectural concerns.
Load this reference during analysis phase to identify potential issues in the code changes.
assets/review-template.md
Structured Markdown template for the review document. Provides consistent format with sections for change summary, business flow, code analysis, risk assessment, and review recommendations.
Use as the base structure and fill in with actual analysis.
1---2name: diff-review-doc3description: Generate comprehensive, reviewer-ready code review documents from git diffs. Use this when the user provides code changes (git diff output, file changes, or asks to review code changes) and wants a structured review document. Creates detailed analysis covering change overview, business flow, key code explanation, risk assessment, and review recommendations. Supports both manual diff input and automatic git workspace detection. Particularly useful for reviewing pull requests, feature branches, or any code changes requiring thorough documentation for reviewers.4---5
6# Diff Review Doc
7
8Generate comprehensive code review documents from git diffs, providing detailed analysis with real code snippets, business flow breakdown, and actionable review recommendations.
9
10## Workflow
11
12### 1. Obtain Diff Content
13
14**If user provides diff directly:**
15- Accept the diff content as-is
16- Parse to identify changed files and hunks
17
18**If no diff is provided:**
19- Use `scripts/get_diff.sh` to retrieve changes:
20 ```bash
21 # Get all uncommitted changes (default)
22 ./scripts/get_diff.sh
23
24 # Get staged changes only
25 ./scripts/get_diff.sh --staged
26
27 # Compare with a branch
28 ./scripts/get_diff.sh --branch main
29
30 # Get changes from specific commit
31 ./scripts/get_diff.sh --commit abc123
32 ```
33
34### 2. Analyze the Changes
35
36**Parse the diff to extract:**
37- File paths and change types (added/modified/deleted)
38- Line-level changes (+/- lines)
39- Context around changes
40
41**Read relevant files:**
42- For significant changes, read the full file to understand context
43- For large files (>500 lines), focus on changed sections with surrounding context
44- Pay special attention to backend files and large file changes
45
46**Identify patterns:**
47- Consult `references/patterns.md` for common code issues
48- Look for anti-patterns, security vulnerabilities, performance issues
49- Check architectural concerns
50
51### 3. Structure the Analysis
52
53**Follow this analysis framework:**
54
551. **改动概览 (Change Summary)**
56 - Count files changed, lines added/removed
57 - Identify change type (feature/bugfix/refactor/performance/security)
58 - List key files with brief descriptions
59 - Note dependency or configuration changes
60
612. **业务流程分析 (Business Flow Analysis)**
62 - Explain what functionality is being implemented/changed
63 - Map out the complete business flow
64 - Show data flow between components
65 - Identify all affected modules
66
673. **关键代码详解 (Key Code Analysis)**
68 - For each significant file:
69 - Show actual diff snippets (use real code from the diff)
70 - Explain what the code does and why it changed
71 - Highlight logic correctness, edge cases, error handling, performance
72 - Prioritize backend files and large changes (>200 lines)
73 - Include file paths with line numbers for reference
74
754. **风险评估 (Risk Assessment)**
76 - Categorize risks as High/Medium/Low
77 - Identify breaking changes, security concerns, performance impacts
78 - Suggest mitigation measures
79 - Flag large file changes and backend-critical changes
80
81### 4. Generate Review Recommendations
82
83**Consult `references/review-checklist.md` for comprehensive evaluation criteria:**
84
85- **代码质量 (Code Quality)**: Readability, complexity, best practices
86- **架构设计 (Architecture)**: Modularity, coupling, extensibility, data flow
87- **功能验证 (Functionality)**: Business logic, error handling, data consistency
88- **安全性 (Security)**: Input validation, authentication, data protection (if applicable)
89- **性能 (Performance)**: Database queries, resource usage, caching (if applicable)
90
91**For each category:**
92- Give a rating (1-5 stars)
93- List strengths (what's done well)
94- List issues (what needs improvement)
95- Provide specific, actionable recommendations
96
97**Final recommendation:**
98- Must Fix: Critical issues that block merge
99- Should Fix: Important issues to address
100- Nice to Have: Optional improvements
101- Merge decision: Approve / Conditional / Needs Work
102
103### 5. Write the Review Document
104
105**Use `assets/review-template.md` as the base structure:**
106- Copy the template structure
107- Fill in all sections with actual analysis from steps 2-4
108- Ensure all code snippets are real (from the actual diff)
109- Include complete business flow explanation
110- Provide specific, actionable review suggestions
111
112**Output:**
113- Save as a Markdown file (e.g., `REVIEW.md`)
114- Format for easy reading (proper headings, code blocks, lists)
115- Include generation timestamp
116
117## Key Principles
118
119### Base on Real Code
120- All code snippets must be extracted from the actual diff
121- Never use placeholder or example code
122- Show actual line numbers and file paths
123
124### Complete Business Context
125- Explain the full user journey and data flow
126- Connect frontend changes to backend logic
127- Show how pieces fit together
128
129### Actionable Review Suggestions
130- Be specific about what to check
131- Identify potential risks with clear explanations
132- Provide concrete improvement suggestions
133- Prioritize issues by severity
134
135### Focus on Critical Areas
136- **Large file changes**: >200 lines need detailed review
137- **Backend changes**: API, database, auth, integrations
138- **Architectural changes**: Design patterns, module boundaries
139- **Security-sensitive code**: Input validation, data access
140
141## Resources
142
143### scripts/get_diff.sh
144Bash script to retrieve git diffs in various scenarios. Supports getting uncommitted changes, staged changes, branch comparisons, and specific commits.
145
146### references/review-checklist.md
147Comprehensive checklist covering all aspects of code review: quality, architecture, functionality, security, performance, testing, compatibility, operations, and documentation.
148
149Load this reference when generating review recommendations to ensure thorough evaluation.
150
151### references/patterns.md
152Catalog of common code patterns to watch for, including anti-patterns, security vulnerabilities, performance issues, and architectural concerns.
153
154Load this reference during analysis phase to identify potential issues in the code changes.
155
156### assets/review-template.md
157Structured Markdown template for the review document. Provides consistent format with sections for change summary, business flow, code analysis, risk assessment, and review recommendations.
158
159Use as the base structure and fill in with actual analysis.