概述
Code Review 技能使用已配置的 Provider(Claude、Codex、Gemini 或 OpenCode)为代码提供 AI 驱动的审查。无需额外 API key — 直接使用 pinable-desktop 中已配置的 Provider。
特点:
- 多 Provider 支持(Claude/Codex/Gemini/OpenCode)
- 智能检测工作流
- Council 模式:三角色并行审查(正确性 + 安全性 + 性能)
- 支持 PR、提交、计划文件和未提交变更的审查
命令参数
$ARGUMENTS 可以包含:
显式目标(无需确认):
pr <number> # 按编号审查 GitHub PR
plan <path> # 审查指定计划文件
<file>.md # 计划审查简写形式
<range> # 审查提交范围(如 HEAD~3..HEAD)
范围修饰符:
--staged # 仅审查暂存的变更
--commit # 强制审查上一个提交
模式选项:
--council # 使用三角色并行审查
--provider <id> # 覆盖 Provider(claude/codex/gemini/opencode)智能检测工作流
当 /cr 无显式目标时,自动检测意图并确认:
| 优先级 | 条件 | 操作 |
|---|---|---|
| 1 | 显式参数 | 直接执行,无需确认 |
| 2 | 存在未提交变更 | 确认:审查变更? |
| 3 | 无变更 + 检测到计划 | 确认:审查计划? |
| 4 | 无变更 + 无计划 | 询问:审查提交或指定目标? |
检测步骤
- 检查显式参数 — 找到则跳过检测
- 检查未提交变更 —
git status --porcelain - 检查计划 — 依次检查对话上下文、
plan.md、.plan.md、~/.claude/plans/ - 无变更且无计划 — 询问用户
代码审查工作流(未提交变更)
- 确定范围:
git diff HEAD(默认)或git diff --cached(--staged) - 获取完整 diff 和变更文件列表
- 读取每个变更文件的完整内容
- 查找相关文档(CLAUDE.md、docs 文件夹)
- 包含相关测试文件
- 查找跨文件依赖
- 保存上下文 JSON:bash
CR_CONTEXT_FILE="/tmp/cr-context-$(date +%s)-$RANDOM.json" - 运行审查脚本:bash
~/.claude/venvs/pinable/bin/python ~/.claude/skills/code-review/scripts/review.py \ --type code --context-file "$CR_CONTEXT_FILE" --output-file "$CR_RESULT_FILE" - 保存审查结果:bash
~/.claude/venvs/pinable/bin/python ~/.claude/skills/code-review/scripts/save_review.py \ --result-file "$CR_RESULT_FILE" --type code --mode single \ --sha "$CR_SHA" --workdir "$(pwd)" --provider "<provider>/<model>" \ --changed-files "<files>"
上次提交审查工作流(--commit)
- 检查提交存在:
git log -1 --oneline - 获取 diff:
git diff HEAD~1..HEAD - 获取变更文件列表
- 读取完整内容,查找文档和测试
- 保存上下文并运行审查
- 保存审查结果
提交范围审查工作流(<range>)
- 验证范围:
git rev-parse <start> <end> - 获取 diff 和变更文件
- 读取完整内容
- 运行审查脚本
- 保存结果
SHA 计算:CR_SHA=$(echo "<range>" | sed 's/.*\.\.//' | xargs git rev-parse --short)
计划审查工作流(plan <path> 或 <file>.md)
- 查找并读取完整计划内容
- 解析计划中的文件路径并读取
- 包含对话上下文
- 运行审查(
--type plan) - 保存结果
PR 审查工作流(pr <number>)
- 获取 PR 信息:bash
gh pr view <number> --json title,body,author,baseRefName,headRefName,files,additions,deletions - 获取 PR diff:
gh pr diff <number> - 读取变更文件完整内容
- 运行审查(
--type pr) - 保存结果
Council 模式(--council)
三角色并行审查,由 Agent 合成结果:
| 角色 | 关注点 | Provider |
|---|---|---|
| Correctness | Bug、逻辑错误 | 自动选择 |
| Security | 漏洞、权限问题 | 自动选择 |
| Performance | 扩展性、内存问题 | 自动选择 |
Council 结果合成
Agent 必须生成对比表:
markdown
## Synthesis
### Comparison of All Three Reviews
| Aspect | Correctness | Security | Performance |
|--------|-------------|----------|-------------|
| **Focus** | Bugs, Logic | Vulnerabilities, Auth | Scaling, Memory |
| **Findings** | ... | ... | ... |
| **Verdict** | ... | ... | ... |
### Consensus Issues (Flagged by 2+ reviewers)
- [Issues multiple reviewers agree on]
### Notable Findings
- **Correctness Expert**: [Finding]
- **Security Analyst**: [Finding]
- **Performance Critic**: [Finding]
### Final Recommendation
[APPROVE / APPROVE WITH CHANGES / REQUEST CHANGES]上下文 JSON 格式
json
{
"review_type": "plan|code|pr",
"conversation_context": {
"original_request": "...",
"approach_notes": "...",
"relevant_exchanges": [
{"role": "user", "content": "..."},
{"role": "assistant", "content": "..."}
],
"previous_review_findings": "..."
},
"plan_content": "# Full plan markdown (for plan reviews)",
"diff": "git diff output (for code/pr reviews)",
"changed_files": ["path1", "path2"],
"file_contents": {"path1": "...", "path2": "..."},
"documentation": {"CLAUDE.md": "..."},
"test_files": {"test_foo.py": "..."},
"dependent_files": {"utils.py": "..."},
"pr_metadata": { ... }
}重要:使用 Bash 写入上下文 JSON,勿使用 Write 工具。
配置
从 ~/.claude/skills/code-review/config.json 读取配置:
json
{
"provider": "auto",
"model": "",
"language": "zh",
"council_providers": {
"correctness": "auto",
"security": "auto",
"performance": "auto"
},
"max_file_size": 50000,
"max_context": 128000,
"max_output_tokens": 16384
}language: 输出语言,"zh"= 简体中文,"en"= 英文
无需 API key 文件 — 凭证从 pinable-desktop 的 Provider 配置读取。
审查结果格式
markdown
## Code Review [Single/Council] (from [provider/model])
[Output from the review script]
## My Assessment
| # | Issue | Reviewer Says | My Take | Action |
|---|-------|---------------|---------|--------|
| 1 | [Brief] | [Concern] | OK/Warning/Critical | [What to do] |
## Proposed Actions
**Immediate fixes I can make:**
1. [Fix with file:line]
**Needs your decision:**
1. [Tradeoff to discuss]
**No action needed:**
1. [Why disagree]
## Ask User for Approval
**What would you like me to do?**
1. **Fix all** - Apply all immediate fixes
2. **Fix specific items** - Tell me which (e.g., "fix 1, 3")
3. **Discuss first** - Talk through items
4. **Skip** - No changes重要准则
- 诚实:有理由时不同意审查者意见
- 具体:精确的文件和行号
- 不自动修复:始终等待用户批准
- 优先排序:安全性/Bug 优先,风格最后
- PR 审查:REQUEST CHANGES 时突出阻塞问题
- 对比表:Council 审查必须显示三列表格
