← 返回
未分类

Code Review Assistant

AI-powered code review assistant that analyzes pull requests for bugs, security issues, performance problems, and style violations with actionable feedback.
AI驱动的代码审查助手,分析PR中的缺陷、安全问题、性能瓶颈和风格违规,并给出可操作的反馈。
charlie-morrison charlie-morrison 来源
未分类 clawhub v1.0.0 1 版本 99656.4 Key: 无需
★ 0
Stars
📥 290
下载
💾 0
安装
1
版本
#latest

概述

Code Review Assistant

Perform thorough AI-powered code reviews on pull requests or local changes. Analyzes diffs for bugs, security vulnerabilities, performance issues, maintainability concerns, and style violations. Provides actionable, specific feedback — not generic advice.

Usage

"Review the current PR"
"Review the changes on this branch vs main"
"Review these specific files for security issues"
"Do a deep review of the authentication changes"

How It Works

1. Gather Changes

Collect the diff and context:

# PR review
gh pr diff <number> --color=never

# Branch review
git diff main...HEAD

# Staged changes
git diff --cached

Also gather:

  • File history (recently changed = higher risk)
  • Test coverage for changed files
  • Related open issues or previous reviews

2. Multi-Pass Analysis

Each pass focuses on a different concern:

Pass 1 — Correctness:

  • Logic errors (off-by-one, null handling, race conditions)
  • Edge cases not covered (empty input, boundary values, overflow)
  • Error handling gaps (uncaught exceptions, missing error propagation)
  • State management issues (stale closures, mutation of shared state)
  • Concurrency bugs (deadlocks, data races, missing synchronization)

Pass 2 — Security:

  • Injection vulnerabilities (SQL, command, XSS, template)
  • Authentication/authorization gaps
  • Sensitive data exposure (logs, errors, responses)
  • Insecure cryptography or random number generation
  • Missing input validation at trust boundaries
  • Hardcoded secrets or credentials

Pass 3 — Performance:

  • N+1 query patterns
  • Missing or incorrect caching
  • Unnecessary allocations in hot paths
  • Blocking operations in async contexts
  • Missing pagination or unbounded queries
  • Inefficient algorithms (quadratic loops on large data)

Pass 4 — Maintainability:

  • Complex functions that should be split (cyclomatic complexity >10)
  • Missing or misleading names
  • Dead code or unreachable branches
  • Duplicated logic that should be extracted
  • Missing types or overly broad types (any, Object)
  • Tight coupling between modules

Pass 5 — Testing:

  • Changed logic without corresponding test changes
  • Test quality (testing implementation vs behavior)
  • Missing edge case tests
  • Flaky test patterns (timing, ordering, external deps)
  • Adequate error path coverage

3. Severity Classification

Each finding gets a severity:

  • 🔴 Must Fix: Bug, security issue, data loss risk, crash
  • 🟡 Should Fix: Performance issue, maintainability concern, missing test
  • 🟢 Consider: Style improvement, minor optimization, suggestion
  • 💡 Nitpick: Optional improvement, personal preference

4. Actionable Feedback

Every comment includes:

  • What: The specific issue found
  • Where: Exact file and line number
  • Why: Why this is a problem (not just "this is bad")
  • How: Concrete fix suggestion with code

5. Summary

Overall assessment with:

  • Risk level (safe to merge / needs changes / needs redesign)
  • Top 3 most important findings
  • Positive observations (good patterns, improvements)
  • Suggested follow-up items (not blocking merge)

Output

## Code Review Summary

**Risk Level:** 🟡 Needs Changes (2 must-fix, 4 should-fix)
**Files Reviewed:** 12 files, +342/-89 lines

### 🔴 Must Fix

1. **SQL Injection in user search** — `src/api/users.ts:47`
   The search query interpolates user input directly:
   ```typescript
   // Current (vulnerable)
   db.query(`SELECT * FROM users WHERE name LIKE '%${query}%'`)
   // Fix: use parameterized query
   db.query('SELECT * FROM users WHERE name LIKE $1', [`%${query}%`])
   ```

2. **Race condition in balance update** — `src/services/wallet.ts:112-118`
   Read-then-write without transaction. Two concurrent requests
   can both read the same balance and overwrite each other.
   Fix: wrap in a database transaction with SELECT FOR UPDATE.

### 🟡 Should Fix

3. **N+1 query in order listing** — `src/api/orders.ts:23`
   Each order triggers a separate query for user details.
   Use a JOIN or batch load users by ID.

4. **Missing error handling** — `src/services/payment.ts:67`
   API call result is not checked for errors before accessing `.data`.

[...]

### 👍 Good Stuff
- Clean separation of concerns in the new service layer
- Comprehensive input validation on the registration endpoint
- Good use of TypeScript discriminated unions for payment status

### 📋 Follow-up (non-blocking)
- Consider adding request rate limiting to the search endpoint
- The `formatDate` utility is duplicated in 3 files — extract to shared utils

Configuration

The review depth adapts to PR size:

  • Small (<100 lines): Full deep review, every line examined
  • Medium (100-500 lines): Focused review on high-risk areas
  • Large (500+ lines): Architectural review + spot-check critical paths, suggest splitting PR

Integration

Works with:

  • GitHub PRs (via gh CLI)
  • GitLab MRs (via glab CLI)
  • Local git branches (via git diff)
  • Patch files (via git apply --stat)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 03:51 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Slack Messaging

charlie-morrison
Slack 消息—通过 CLI 和 API 发送消息、管理频道、上传文件、添加反应并自动化团队通知。
★ 0 📥 462

API Mock Generator

charlie-morrison
Generate mock API servers from OpenAPI 3.x and Swagger 2.0 specs. Use when creating mock/stub APIs for frontend developm
★ 0 📥 461

Pyproject Toml Validator

charlie-morrison
依据 PEP 517/621 规则校验 pyproject.toml 文件,验证项目元数据、构建系统和工具配置,并提供详细报告。
★ 0 📥 473