跳至内容

提交前审查 ​

review-staged 在提交前审查暂存区(git diff --cached)的变更,把 Code Review 提前到 commit 之前。它是 ai-coding 插件中唯一允许 AI 按上下文自动触发的 Skill。

调用触发来源
/ai-coding:review-staged [--fix]手动或 AI 自动触发ai-coding 插件

适用场景 ​

  • 提交前快速检查逻辑错误、安全问题、类型和风格;
  • 改了逻辑却没更新测试时给出提醒;
  • 加 --fix 自动修复 MUST_FIX 与 SHOULD_FIX,并重新暂存修改过的文件。

安装 ​

bash
# 作为插件安装(包含 Issue → PR 与代码审查全部 Skills)
claude plugin install ai-coding@yunyoujun

# 或单独安装
npx skills add YunYouJun/ai --skill=review-staged

使用示例 ​

text
/ai-coding:review-staged
/ai-coding:review-staged --fix

审查分级 ​

级别含义
🔴 MUST_FIXBug、安全问题、数据丢失风险
🟡 SHOULD_FIX风格、类型、可读性、缺失的测试
🔵 NIT可选的小建议
✅ GOOD值得肯定的写法

只审查暂存的改动;已有问题只有在本次改动让它变得更糟时才会指出。最后给出结论:可以提交、有待处理的问题,或存在必须先修复的严重问题。

完整指令 ​

SKILL.md
md
---
name: review-staged
description: "Review staged git changes before committing — catch bugs, security issues, and style problems early."
argument-hint: "[--fix]"
---

Review all staged (`git diff --cached`) changes before committing. Shift-left code review.

## Instructions

1. Get staged changes: `git diff --cached --stat` and `git diff --cached`. If empty, report "No staged changes" and stop.
2. Scan for project conventions (linter configs, `tsconfig.json`, `CLAUDE.md`, `AGENTS.md`) to understand project standards.
3. For each changed file, read the **full file** for context, then review the **staged hunks** specifically:
   - **Correctness**: logic errors, null access, race conditions, missing error handling
   - **Security**: hardcoded secrets, injection, unsafe eval, exposed credentials
   - **Types & style**: missing types, `any` abuse, naming, dead code, unused imports
   - **Tests**: changed logic without corresponding test updates
4. Categorize each finding:
   - 🔴 **MUST_FIX** — bugs, security, data loss risks
   - 🟡 **SHOULD_FIX** — style, types, readability, missing tests
   - 🔵 **NIT** — minor suggestions, optional improvements
   - ✅ **GOOD** — well-written code worth highlighting
5. Focus on staged changes only — don't flag pre-existing issues unless the change makes them worse.
6. If `$ARGUMENTS` contains `--fix`: implement fixes for MUST_FIX and SHOULD_FIX items, re-stage fixed files (`git add <files>`), run `pnpm lint --fix` / `pnpm typecheck` if available. Without `--fix`, report only.
7. Print summary:

```
## Staged Changes Review

Files: <N> | Changes: +<add> / -<del>

| # | Severity | File:Line | Issue | Suggestion |
|---|----------|-----------|-------|------------|

Verdict: ✅ Ready to commit / ⚠️ <N> issues to review / 🚫 <N> critical issues — fix first
```