first commit

This commit is contained in:
2026-08-14 23:41:57 +08:00
commit 086803a8dd
471 changed files with 91938 additions and 0 deletions
@@ -0,0 +1,163 @@
---
name: review-it
description: "Code review closeout for Claude Code, Codex, OpenCode, DeepSeek TUI, and Antigravity CLI: local dirty changes, branch vs main, parallel tests."
---
# CC Review
Run automated code review as a closeout check before committing or shipping. Works across multiple AI coding agents.
Use when:
- user asks for code review / review-it / autoreview
- after non-trivial code edits, before final/commit/ship
- reviewing a local branch or PR branch after fixes
## Supported Agents
| Agent | Review Command | Notes |
|-------|---------------|-------|
| Claude Code | `/review` | Built-in, works on uncommitted changes or diff |
| Codex | `codex review` | Pass diff file or let it auto-detect |
| OpenCode | `/review` | Same as Claude Code |
| DeepSeek TUI | `/review` or manual diff review | Pass diff content for analysis |
| Antigravity CLI | `/code-review` | Built-in slash command, auto-detects diff |
## Contract
- Treat review output as advisory. Never blindly apply it.
- Verify every finding by reading the real code path and adjacent files.
- Read dependency docs/source/types when the finding depends on external behavior.
- Reject unrealistic edge cases, speculative risks, broad rewrites, and fixes that over-complicate the codebase.
- Prefer small fixes at the right ownership boundary; no refactor unless it clearly improves the bug class.
- Keep going until review returns no accepted/actionable findings.
- If a review-triggered fix changes code, rerun focused tests and rerun review.
- Stop as soon as the review comes back clean with no actionable findings.
- If rejecting a finding as intentional/not worth fixing, add a brief inline code comment only when it explains a real invariant or ownership decision that future reviewers should know.
- Do not push just to review. Push only when the user requested push/ship/PR update.
## Review Focus
请 review 当前 diff。不要只看语法和明显 bug,请重点检查以下维度,最后按严重程度排序:
1. **隐藏副作用 (Hidden Side Effects)** — 变更是否在非显而易见的地方产生级联影响?是否修改了共享状态、全局变量、或外部依赖的行为?
2. **破坏兼容性 (Breaking Compatibility)** — 是否改变了 API 签名、数据结构、配置文件格式、或命令行接口?现有调用方是否会受影响?
3. **边界情况 (Edge Cases)** — null/空值/空集合、极大/极小值、并发/竞态条件、异常路径是否被正确处理?
4. **性能风险 (Performance Risks)** — 是否引入了不必要的循环嵌套、N+1 查询、大对象分配、阻塞 I/O、或锁竞争?
5. **安全风险 (Security Risks)** — 是否存在注入、越权、敏感信息泄露、不安全的反序列化、或依赖版本漏洞?
6. **命名误导 (Naming Misleading)** — 变量/函数/类型名称是否与实际行为不一致?是否存在名不副实或语义模糊的命名?
7. **测试不足 (Insufficient Testing)** — 关键路径、边界条件、错误处理是否缺少测试覆盖?现有测试是否真正验证了期望行为?
8. **未来维护成本 (Future Maintenance Cost)** — 是否引入了不必要的抽象、重复代码、隐式耦合、或难以追踪的控制流?后来者是否容易理解和修改?
## Pick Target
### Claude Code / OpenCode / DeepSeek TUI
Dirty local work (default — `/review` works on uncommitted changes):
```
/review
```
Branch/PR work — review all changes against base:
First generate a diff, then review it:
```bash
git diff origin/main...HEAD > /tmp/review-it.diff
```
Then review the diff file with a focused prompt:
```
/review the changes in /tmp/review-it.diff against origin/main
```
If an open PR exists, use its actual base:
```bash
base=$(gh pr view --json baseRefName --jq .baseRefName)
git diff "origin/$base"...HEAD > /tmp/review-it.diff
```
### Antigravity CLI (`agy`)
Dirty local work:
```
/code-review
```
Branch/PR work — review all changes against base:
```bash
git diff origin/main...HEAD > /tmp/review-it.diff
```
Then pass the diff to the review command:
```
/code-review the changes in /tmp/review-it.diff against origin/main
```
If an open PR exists, use its actual base:
```bash
base=$(gh pr view --json baseRefName --jq .baseRefName)
git diff "origin/$base"...HEAD > /tmp/review-it.diff
```
### Codex
```bash
# Review uncommitted changes
codex review
# Review branch diff
git diff origin/main...HEAD > /tmp/review-it.diff
codex review /tmp/review-it.diff
```
## Parallel Closeout
Format first if formatting can change line locations. Then it's OK to run tests and review in parallel:
```bash
scripts/review-it --parallel-tests "<focused test command>"
```
Tradeoff: tests may force code changes that stale the review. If tests or review lead to code edits, rerun the affected tests and rerun review until no accepted/actionable findings remain.
## Uncommitted vs Branch Review
Choose the right mode:
- **Uncommitted changes** (staged/unstaged): use `/review` directly (Antigravity: `/code-review`, Codex: `codex review`)
- **Committed, not pushed**: use `git diff origin/main...HEAD` + review
- **Pushed/PR**: same as committed, against the PR base
- **Clean working tree**: skip review if there's truly nothing to review
## Helper
Bundled helper script for parallel test + review orchestration:
```bash
~/.claude/skills/review-it/scripts/review-it --help
```
The helper:
- Detects which agent is running (Claude Code, Antigravity CLI, Codex) via `--agent auto`
- Detects whether to use uncommitted review or branch diff review
- For branch mode: generates diff against `origin/main` (or PR base), then triggers review
- Supports `--parallel-tests` for concurrent test + review execution
- Supports `--dry-run` for checking what command would be used
- Prints `review-it clean: no accepted/actionable findings reported` when review is clean
## Final Report
Include:
- review target (uncommitted / branch / PR base)
- tests/proof run
- findings accepted/rejected, briefly why
- the clean review result, or why a remaining finding was consciously rejected
Do not run another review solely to improve the final report wording. If review exited clean with no actionable findings, report that as clean.
@@ -0,0 +1,248 @@
#!/usr/bin/env bash
# review-it — Code review closeout helper
# Orchestrates /review with optional parallel test execution.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKILL_DIR="$(dirname "$SCRIPT_DIR")"
MODE="auto"
BASE="origin/main"
TESTS=""
DRY_RUN=false
AGENT="auto"
usage() {
cat <<EOF
Usage: review-it [options]
Options:
--mode auto|local|branch Target selection. Default: auto.
auto: uncommitted if dirty, branch diff otherwise
local: force review on uncommitted changes
branch: force diff review against base
--agent auto|claude|antigravity|codex
Agent to target. Default: auto (detects running agent).
--base REF Base ref for branch review. Default: origin/main.
--parallel-tests CMD Run tests in parallel with review.
--dry-run Print what would be executed, don't run.
--help Show this help.
Environment:
CC_REVIEW_OUTPUT File to write review output to (default: stdout only).
For branch mode, generates a git diff against the base and instructs
Claude Code's /review to analyze it.
Examples:
review-it # auto-detect mode and agent
review-it --agent antigravity # use /code-review for Antigravity CLI
review-it --mode local # review uncommitted changes
review-it --mode branch # review branch vs origin/main
review-it --parallel-tests "go test ./..." # review + test in parallel
EOF
exit 0
}
# --- Parse args ---
while [[ $# -gt 0 ]]; do
case "$1" in
--mode) MODE="$2"; shift 2 ;;
--agent) AGENT="$2"; shift 2 ;;
--base) BASE="$2"; shift 2 ;;
--parallel-tests) TESTS="$2"; shift 2 ;;
--dry-run) DRY_RUN=true; shift ;;
--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
# --- Detect state ---
STAGED=$(git diff --cached --name-only 2>/dev/null | wc -l | tr -d ' ')
UNSTAGED=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')
UNTRACKED=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d ' ')
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")
IS_MAIN=false
[[ "$CURRENT_BRANCH" == "main" || "$CURRENT_BRANCH" == "master" ]] && IS_MAIN=true
HAS_DIRTY=false
[[ "$STAGED" -gt 0 || "$UNSTAGED" -gt 0 || "$UNTRACKED" -gt 0 ]] && HAS_DIRTY=true
# --- Detect agent ---
detect_agent() {
# Check environment variables / parent process
if [[ -n "${ANTIGRAVITY_CLI:-}" ]] || [[ -n "${GEMINI_CLI:-}" ]]; then
echo "antigravity"
elif [[ -n "${CLAUDE_CODE:-}" ]] || [[ -n "${CLAUDE_CLI:-}" ]]; then
echo "claude"
elif command -v codex &>/dev/null && [[ -n "${CODEX_CLI:-}" ]]; then
echo "codex"
else
# Default to claude as most common
echo "claude"
fi
}
if [[ "$AGENT" == "auto" ]]; then
DETECTED_AGENT=$(detect_agent)
else
DETECTED_AGENT="$AGENT"
fi
# --- Resolve review command by agent ---
review_cmd_for() {
local mode="$1"
local diff_file="$2"
case "$DETECTED_AGENT" in
antigravity)
if [[ "$mode" == "local" ]]; then
echo "/code-review"
else
echo "/code-review the changes in $diff_file against $BASE"
fi
;;
codex)
if [[ "$mode" == "local" ]]; then
echo "codex review"
else
echo "codex review $diff_file"
fi
;;
claude|*)
if [[ "$mode" == "local" ]]; then
echo "/review"
else
echo "/review the changes in $diff_file against $BASE"
fi
;;
esac
}
# --- Resolve mode ---
if [[ "$MODE" == "auto" ]]; then
if $HAS_DIRTY; then
REVIEW_MODE="local"
elif $IS_MAIN; then
echo "review-it: on main with clean tree, nothing to review."
exit 0
else
REVIEW_MODE="branch"
fi
else
REVIEW_MODE="$MODE"
fi
# --- Check for PR base ---
if [[ "$REVIEW_MODE" == "branch" ]]; then
if command -v gh &>/dev/null; then
PR_BASE=$(gh pr view --json baseRefName --jq .baseRefName 2>/dev/null || echo "")
if [[ -n "$PR_BASE" ]]; then
BASE="origin/$PR_BASE"
fi
fi
# Fetch the base to ensure we have it
if ! $DRY_RUN; then
git fetch origin "$(echo "$BASE" | sed 's|origin/||')" 2>/dev/null || true
fi
fi
# --- Build review command ---
DIFF_FILE=""
case "$REVIEW_MODE" in
local)
REVIEW_DESC="uncommitted changes"
;;
branch)
DIFF_FILE="/tmp/review-it-$$.diff"
REVIEW_DESC="branch $CURRENT_BRANCH vs $BASE"
;;
*)
echo "review-it: unknown mode $REVIEW_MODE"
exit 1
;;
esac
REVIEW_CMD=$(review_cmd_for "$REVIEW_MODE" "$DIFF_FILE")
# --- Dry run ---
if $DRY_RUN; then
echo "mode: $REVIEW_MODE"
echo "agent: $DETECTED_AGENT"
echo "target: $REVIEW_DESC"
echo "review: $REVIEW_CMD"
echo "dirty: staged=$STAGED unstaged=$UNSTAGED untracked=$UNTRACKED"
if [[ "$REVIEW_MODE" == "branch" ]]; then
echo "diff: $DIFF_FILE"
echo "base: $BASE"
fi
if [[ -n "$TESTS" ]]; then
echo "tests: $TESTS"
fi
exit 0
fi
# --- Run ---
echo "review-it: mode=$REVIEW_MODE agent=$DETECTED_AGENT target=$REVIEW_DESC"
echo ""
# Generate diff for branch mode
if [[ "$REVIEW_MODE" == "branch" ]]; then
if ! git diff "$BASE"...HEAD > "$DIFF_FILE" 2>/dev/null; then
echo "review-it: failed to generate diff against $BASE"
exit 1
fi
if [[ ! -s "$DIFF_FILE" ]]; then
echo "review-it: no changes between $BASE and HEAD"
rm -f "$DIFF_FILE"
exit 0
fi
echo "review-it: generated diff ($(wc -l < "$DIFF_FILE" | tr -d ' ') lines) at $DIFF_FILE"
echo ""
fi
# Run tests in background if requested
TEST_PID=""
if [[ -n "$TESTS" ]]; then
echo "review-it: running tests in background: $TESTS"
eval "$TESTS" > /tmp/review-it-tests-$$.log 2>&1 &
TEST_PID=$!
echo "review-it: test PID=$TEST_PID"
echo ""
fi
# Run review (this is a signal to the user — the actual /review
# is executed by Claude Code when it reads this output)
cat <<CCEOF
review-it: ready for review ($REVIEW_DESC)
$REVIEW_CMD
CCEOF
# Wait for tests if running
if [[ -n "$TEST_PID" ]]; then
echo ""
echo "review-it: waiting for tests to complete (PID=$TEST_PID)..."
wait "$TEST_PID" 2>/dev/null || true
TEST_EXIT=$?
echo ""
echo "--- test output ---"
cat /tmp/review-it-tests-$$.log
echo "--- end test output ---"
rm -f /tmp/review-it-tests-$$.log
if [[ $TEST_EXIT -ne 0 ]]; then
echo ""
echo "review-it: tests FAILED (exit=$TEST_EXIT)"
exit $TEST_EXIT
else
echo ""
echo "review-it: tests passed"
fi
fi
# Cleanup
if [[ "$REVIEW_MODE" == "branch" ]]; then
rm -f "$DIFF_FILE"
fi
echo ""
echo "review-it: done"