Code reviewer

From cwinvestments/memstack · View interactive version

Code reviewer is an AI agent skill from the GitHub repository cwinvestments/memstack. Use this skill when the user says 'review code', 'code review', 'check my code', 'audit this', 'review PR', 'review changes', 'what's wrong with this', or is requesting a structured review of code quality, security, performance, or maintainability. Do NOT use for refactoring plans or test generation

How to use this skill

Skill file

🔍 Code Reviewer: Reviewing code for issues and improvements...

Systematic code review across security, performance, maintainability, error handling, testing, and accessibility, with severity-ranked findings and specific fixes.

Activation

When this skill activates, output:

🔍 Code Reviewer: Scanning for issues...

Then execute the protocol below.

| Context | Status |

|---------|--------|

| User says "review code" or "code review" or "check my code" | ACTIVE |

| User says "audit this" or "review PR" or "review changes" | ACTIVE |

| User asks "what's wrong with this" about code | ACTIVE |

| Reviewing a specific file or set of changes | ACTIVE |

| User is writing code and hasn't asked for review | DORMANT |

| Discussing code architecture at a high level | DORMANT |

Anti-patterns

| Trap | Reality Check |

|------|---------------|

| "This looks fine to me" | Check every category systematically. Skimming misses auth gaps and N+1 queries. |

| "Style issues are important" | Linters handle style. Focus on logic, security, and correctness. |

| "I'll flag everything I see" | Noise kills reviews. Only report issues with real impact. Severity matters. |

| "The code works so it's fine" | Working does not mean correct. Race conditions, edge cases, and security holes all "work" until they don't. |

| "I'll suggest a complete rewrite" | Review what's there. Propose targeted fixes, not architectural overhauls. |

Severity Levels

| Level | Label | Meaning | Action |

|-------|-------|---------|--------|

| 🔴 | Critical | Security vulnerability, data loss risk, crash in production | Fix before merge |

| 🟠 | High | Bug, incorrect behavior, significant performance issue | Fix this sprint |

| 🟡 | Medium | Code smell, minor performance issue, missing edge case | Fix when touching the file |

| 🔵 | Low | Style preference, minor improvement, documentation gap | Consider for future |

Protocol

Step 1: Security Review

Scan for security vulnerabilities: this category takes priority.

Authentication gaps:

Search for route handlers and verify each has auth checks:

grep -rn "export async function\|export function" --include="*.ts" app/api/ | head -20

Flag these patterns:

Exposed secrets:

Search for hardcoded credentials:

grep -rn "sk_live\|sk_test\|password\s*=\s*['\"]" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.env" . | grep -v node_modules | grep -v .env.example

Flag these patterns:

Injection vulnerabilities:

Search for unsafe input handling:

grep -rn "\.raw(\|\.unsafeRaw\|innerHTML\s*=" --include="*.ts" --include="*.tsx" --include="*.js" . | grep -v node_modules

Flag these patterns:

Step 2: Performance Review

Identify patterns that degrade under load.

N+1 queries:

# Find loops that might contain database calls
grep -rn "\.forEach\|\.map\|for.*of\|for.*in" --include="*.ts" --include="*.tsx" . | grep -v node_modules | head -20

Flag these patterns:

Missing indexes:

Frontend performance:

# Check for large imports that should be tree-shaken
grep -rn "import .* from ['\"]lodash['\"]" --include="*.ts" --include="*.tsx" . | grep -v node_modules

Flag these patterns:

Data fetching:

Step 3: Maintainability Review

Evaluate code clarity and organization.

Dead code:

grep -rn "export " --include="*.ts" --include="*.tsx" . | grep -v node_modules | head -30

Flag these patterns:

Duplicated logic:

Naming clarity:

Type safety:

Step 4: Error Handling Review

Check that errors are caught and handled appropriately.

Uncaught promises:

grep -rn "await " --include="*.ts" --include="*.tsx" . | grep -v "try\|catch\|\.catch" | grep -v node_modules | head -20

Flag these patterns:

Error quality:

Edge cases:

Step 5: Testing Review

Assess test coverage for critical paths.

Untested critical paths:

Missing edge cases:

Test quality:

Step 6: Accessibility Review

Check that UI code is usable by everyone.

Image and media:

Keyboard navigation:

ARIA and semantics:

Color and contrast:

Step 7: Output Per-File Report

For each file reviewed, output findings grouped by file:

file: app/api/organizations/[orgId]/route.ts

🔴 Critical: No auth check on DELETE handler
   Line 45: export async function DELETE(req) { ... }
   Fix: Add getAuthContext + verifyOrgAccess + admin role check
   ```typescript
   const auth = await getAuthContext(req);
   if (!auth) return apiError('Authentication required', 401);
   const access = await verifyOrgAccess(auth.userId, params.orgId);
   if (!access || access.role !== 'owner') return apiError('Access denied', 403);
   ```

🟠 High: N+1 query in project listing
   Line 62: projects.map(async (p) => await getProjectMembers(p.id))
   Fix: Batch fetch members for all projects in one query
   ```typescript
   const membersByProject = await db.members.findByProjectIds(
     projects.map(p => p.id)
   );
   ```

🟡 Medium: Generic error message
   Line 78: catch (e) { return apiError('Something went wrong', 500); }
   Fix: Log the error with context, return safe message
   ```typescript
   catch (error) {
     console.error('DELETE /organizations failed:', { orgId: params.orgId, error });
     return apiError('Failed to delete organization', 500);
   }
   ```

🔵 Low: Missing return type on handler
   Line 45: export async function DELETE(req)
   Fix: Add explicit return type
   ```typescript
   export async function DELETE(req: NextRequest): Promise<NextResponse>
   ```

Step 8: Summary Report

After reviewing all files, output a summary:

🔍 Code Review: Complete

Files reviewed: [count]
Issues found: [total]

By severity:
  🔴 Critical: [count], fix before merge
  🟠 High:     [count], fix this sprint
  🟡 Medium:   [count], fix when touching the file
  🔵 Low:      [count]: consider for future

By category:
  Security:        [count] issues
  Performance:     [count] issues
  Maintainability: [count] issues
  Error handling:  [count] issues
  Testing:         [count] issues
  Accessibility:   [count] issues

Top 3 priorities:
  1. [Most critical issue with file:line]
  2. [Second most critical]
  3. [Third most critical]

Estimated fix effort:
  Critical + High: ~[X] hours
  All issues: ~[X] hours

Level History

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.