Perform systematic pre-PR code review covering quality, security, performance, testing, and documentation with Exa search and Context7 verification
Systematic pre-PR code review that analyzes changes for security vulnerabilities, performance issues, and quality gaps. Uses Exa search and Context7 to verify uncertain patterns against best practices before flagging issues.
/plugin marketplace add blogic-cz/blogic-marketplace/plugin install agent-kit@blogic-marketplaceSystematic code review for pull request readiness. Identifies critical issues, suggests fixes, and provides actionable feedback.
Use this command to:
Overview:
Ask the user what to review:
Options:
Commands to use:
# Recent commits
git log -5 --oneline
git diff HEAD~5..HEAD
# Specific files
git diff main..HEAD -- path/to/files
# Branch comparison
git diff main..HEAD
For each changed file, perform systematic analysis across five categories:
Check for:
Readability Issues:
Design Patterns:
Maintainability:
Patterns to grep:
# Find long functions (JavaScript/TypeScript)
grep -n "function.*{" file.ts | # check line counts
# Find magic numbers
grep -E "[^a-zA-Z0-9][0-9]{2,}[^a-zA-Z0-9]" file.ts
# Find TODO/FIXME comments
grep -n "TODO\|FIXME" file.ts
Check for:
Injection Vulnerabilities:
Authentication/Authorization:
Data Protection:
Patterns to grep:
# Find potential SQL injection
grep -n "query.*+\|query.*\${" file.ts
# Find hardcoded secrets
grep -iE "api[_-]?key|password|secret|token" file.ts
# Find console.log with sensitive data
grep -n "console\.log" file.ts
# Find eval usage
grep -n "eval(" file.ts
Common Issues:
eval() usageinnerHTML without sanitizationCheck for:
Algorithm Complexity:
Resource Usage:
Optimization Opportunities:
Patterns to check:
# Find nested loops
grep -A 5 "for.*{" file.ts | grep "for.*{"
# Find array operations in loops
grep -E "forEach|map|filter|reduce" file.ts
# Find synchronous operations
grep -n "readFileSync\|execSync" file.ts
Common Issues:
.map() or .forEach() callsCheck for:
Test Coverage:
Test Quality:
Test Patterns:
# Check if test file exists for source file
test -f src/utils/helper.test.ts || echo "Missing test"
# Find test files
find . -name "*.test.ts" -o -name "*.spec.ts"
# Check test coverage (if configured)
npm run test:coverage || bun test --coverage
Common Gaps:
Check for:
Code Documentation:
Project Documentation:
Patterns to check:
# Find public functions without JSDoc
grep -B 2 "export function" file.ts | grep -v "/**"
# Check for README
test -f README.md || echo "README missing"
# Find undocumented breaking changes
git log --oneline | grep -i "break\|breaking"
Common Issues:
MANDATORY when unsure about:
exa-get_code_context_exa)Best for finding real-world patterns and implementation examples:
When you find:
- Unfamiliar framework patterns (e.g., React hooks usage)
- Security-sensitive code you're uncertain about
- Performance patterns (e.g., caching strategies)
- Error handling approaches
- API integration patterns
- Testing strategies for specific features
Example queries:
exa-get_code_context_exa(query: "React useEffect cleanup memory leaks best practices")
exa-get_code_context_exa(query: "Express.js SQL injection prevention parameterized queries")
exa-get_code_context_exa(query: "Next.js API routes rate limiting implementation")
exa-get_code_context_exa(query: "TypeScript discriminated unions error handling patterns")
context7-resolve-library-id + context7-get-library-docs)Best for getting official documentation and API references:
When you need:
- Official API documentation for a library/framework
- Correct usage of specific library methods
- Verification of deprecated APIs
- Type definitions and interfaces
- Configuration options and parameters
Example workflow:
1. context7-resolve-library-id(libraryName: "next")
โ Returns: /vercel/next.js
2. context7-get-library-docs(
context7CompatibleLibraryID: "/vercel/next.js",
topic: "API routes middleware"
)
โ Returns: Official Next.js docs on middleware
Found uncertain code pattern?
โ
โโ Is it about a SPECIFIC library/framework API?
โ โโ YES โ Use Context7
โ 1. Resolve library ID
โ 2. Get official docs for the specific topic
โ 3. Compare with code being reviewed
โ
โโ Is it about GENERAL patterns or best practices?
โโ YES โ Use Exa Search
1. Search for real-world implementations
2. Analyze patterns from multiple sources
3. Identify common pitfalls or anti-patterns
Identify Uncertain Patterns
During review, flag code where you're unsure:
- "Is this the correct way to use React.memo?"
- "Is this SQL query properly parameterized?"
- "Does this Next.js pattern follow best practices?"
Choose Verification Tool
Framework/library-specific โ Context7
General patterns/practices โ Exa Search
Both needed โ Use both (Context7 first, then Exa for real-world examples)
Execute Verification
Run the appropriate MCP tool with specific queries
Compare & Validate
- Compare reviewed code against verified patterns
- Note discrepancies or anti-patterns
- Update severity if needed (e.g., "might be okay" โ "MAJOR issue")
Document Findings
Include verification sources in review comments:
"Based on Next.js official docs [Context7] and production examples [Exa],
this pattern violates best practices..."
Found in code:
useEffect(() => {
fetchData();
}, []);
Uncertainty: "Should fetchData be in dependency array?"
Verification:
exa-get_code_context_exa(query: "React useEffect missing dependency warning ESLint exhaustive-deps")Review comment:
โ ๏ธ MAJOR: Missing dependency in useEffect
File: src/components/DataFetcher.tsx:15
Current code has fetchData outside dependency array, which can cause stale closures.
[Verified via Exa search of React best practices]
Fix:
- Option 1: Add to deps array (may cause extra renders)
- Option 2: Wrap fetchData in useCallback with proper deps
Found in code:
const query = `SELECT * FROM users WHERE email = '${email}'`;
Uncertainty: "Is this vulnerable to SQL injection?"
Verification:
exa-get_code_context_exa(query: "SQL injection prevention parameterized queries node.js")Review comment:
๐จ CRITICAL: SQL Injection Vulnerability
File: src/api/auth.ts:42
String interpolation in SQL queries allows injection attacks.
[Verified via Exa search - confirmed security anti-pattern]
Fix:
const query = 'SELECT * FROM users WHERE email = ?';
const result = await db.execute(query, [email]);
Found in code:
export default function handler(req, res) {
// No rate limiting
const data = await processRequest(req.body);
res.json(data);
}
Uncertainty: "Should API routes have rate limiting? What's the standard approach?"
Verification:
context7-resolve-library-id(libraryName: "next")context7-get-library-docs(context7CompatibleLibraryID: "/vercel/next.js", topic: "API routes middleware")exa-get_code_context_exa(query: "Next.js API routes rate limiting production best practices")Review comment:
โ ๏ธ MAJOR: Missing Rate Limiting on Public API
File: pages/api/process.ts:1
Public API routes should implement rate limiting to prevent abuse.
[Verified via Context7 (Next.js docs) + Exa (production patterns)]
Suggested approach:
1. Install: npm install express-rate-limit
2. Implement middleware pattern from Next.js docs
3. Consider per-user vs per-IP limits based on auth
Always verify when you encounter:
DON'T verify for:
Verification adds value when:
Organize all findings by severity:
Criteria:
Example:
- [Security] src/api/auth.ts:42 - SQL injection vulnerability
Current code uses string concatenation in query:
```typescript
const query = `SELECT * FROM users WHERE id = ${userId}`;
Fix: Use parameterized queries:
const query = `SELECT * FROM users WHERE id = ?`;
const result = await db.execute(query, [userId]);
### โ ๏ธ MAJOR (Should Fix)
**Criteria:**
- Performance issues (O(nยฒ) algorithms, memory leaks)
- Missing error handling on critical paths
- Poor code quality affecting maintainability
- Missing tests for critical functionality
- Significant technical debt
**Example:**
```markdown
- [Performance] src/utils/search.ts:15 - O(nยฒ) nested loops
Nested iteration over arrays causing slow searches:
```typescript
items.forEach(item => {
categories.forEach(cat => { /* check */ });
});
Fix: Use Map for O(n) lookup:
const catMap = new Map(categories.map(c => [c.id, c]));
items.forEach(item => {
const cat = catMap.get(item.categoryId);
});
### ๐ก MINOR (Consider Fixing)
**Criteria:**
- Style inconsistencies
- Minor code smells
- Non-critical refactoring opportunities
- Optional documentation improvements
- Nice-to-have optimizations
**Example:**
```markdown
- [Style] src/components/Button.tsx:8 - Inconsistent naming
Component uses `onClick` and `onPress` inconsistently.
Consider standardizing to `onClick` across all components.
# Code Review Report
**Scope:** [Brief description of what was reviewed]
**Reviewed:** [Number of files, lines changed]
**Date:** [Current date]
---
## ๐จ CRITICAL ISSUES (Must Fix Before Merge)
[If any critical issues found, list them with file:line, description, and fix]
[If none:]
โ
No critical issues found
---
## โ ๏ธ MAJOR ISSUES (Should Fix)
[List major issues with file:line, description, and suggested fix]
[If none:]
โ
No major issues found
---
## ๐ก MINOR ISSUES (Consider Fixing)
[List minor issues with file:line and brief description]
[If none:]
โ
No minor issues found
---
## โ
POSITIVE OBSERVATIONS
[Highlight good practices found in the code:]
- Well-structured test coverage in src/api/
- Clean separation of concerns in components
- Comprehensive error handling in auth flow
- Clear documentation in README updates
---
## ๐ SUMMARY
**Overall Assessment:** [APPROVE / NEEDS_WORK / REJECT]
**Recommendation:**
[Specific next steps based on findings]
**Key Takeaways:**
- [Most important points]
- [Action items]
---
## Quick Stats
- Files reviewed: [N]
- Lines changed: [+X, -Y]
- Issues found: [Critical: N, Major: N, Minor: N]
- Test coverage: [X%] (if available)
After completing the code review, run automated quality checks to verify builds and tests pass.
Recommended: Use the /check-after-stop command to run project-configured checks:
/check-after-stop
This command will:
.claude/check-after-stop.sh configurationbun run build, dotnet build)bun test, npm run test:ci)Why this matters:
Example flow:
1. /code-review โ Manual review (quality, security, performance)
2. Fix critical issues โ Address findings from review
3. /check-after-stop โ Automated checks (build, tests)
4. Create PR โ All checks passed
If automated checks fail, document failures in the review report and recommend fixing before merge.
APPROVE โ
NEEDS_WORK โ ๏ธ
REJECT โ
/check-after-stop to verify builds and testseval()innerHTML without sanitizationdangerouslySetInnerHTML in ReactUser: /code-review src/api/
Assistant:
exa-get_code_context_exa to verify SQL query patterns