ryudi84-sovereign-code-review-helper
全面的代码审查助手,按 PR 文件类型生成审查清单,内置安全、性能、风格与测试检查及 GitHub/GitLab PR 模板。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~ryudi84-sovereign-code-review-helpercURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~ryudi84-sovereign-code-review-helper/file -o ryudi84-sovereign-code-review-helper.md## 概述(中文)
全面的代码审查助手,按 PR 文件类型生成审查清单,内置安全、性能、风格与测试检查及 GitHub/GitLab PR 模板。
## 技能正文
# 代码审查助手
全面的代码审查助手,根据 PR 中的文件类型生成审查清单,内置安全、性能、风格与测试最佳实践检查。
## 概述
代码审查助手通过扫描变更文件并生成以下内容,自动化审查中的繁琐环节:
- **按文件类型的清单**(JavaScript、Python、Go、Rust、SQL 等)
- **安全审计项**(注入、认证、密钥、输入验证)
- **性能审查要点**(N+1 查询、内存泄漏、复杂度)
- **风格一致性检查**(命名、格式化、import 顺序)
- **测试覆盖提醒**(缺失测试、边界情况、mock)
- **PR 审查模板**,可直接粘贴到 GitHub、GitLab 或 Bitbucket
本技能帮助审查者全面且一致,降低遗漏问题进入生产环境的风险。
## 安装
### 通过 ClawHub
```bash
openclaw install code-review-helper
```
### 手动安装
1. 将技能复制到 OpenClaw 技能目录:
```bash
mkdir -p ~/.openclaw/skills/
cp -r code-review-helper/ ~/.openclaw/skills/
```
2. 使脚本可执行:
```bash
chmod +x ~/.openclaw/skills/code-review-helper/scripts/review.sh
```
3. 验证安装:
```bash
openclaw list --installed
```
## 要求
- **git** (version 2.0 or higher)
- **bash** (version 4.0 or higher)
- Standard Unix utilities: **awk**, **grep**, **sed**, **sort**, **wc**
兼容 Linux、macOS 与 Windows(通过 Git Bash、WSL 或 MSYS2)。
## 用法
### 基本用法
在有暂存或已提交变更的 git 仓库中运行:
```bash
openclaw run code-review-helper
```
默认分析当前分支与 `main` 之间的 diff。
### 命令行选项
```bash
openclaw run code-review-helper [OPTIONS]
Options:
--base <branch> Base branch for comparison (default: main)
--head <branch> Head branch/ref to review (default: HEAD)
--pr <number> Pull request number (fetches diff from remote)
--files <pattern> Glob pattern to filter files (e.g., "src/**/*.py")
--security Run security checks only
--performance Run performance checks only
--style Run style checks only
--tests Run test coverage checks only
--all Run all check categories (default)
--severity <level> Minimum severity: critical, warning, info (default: info)
--output <format> Output format: markdown, json, text (default: markdown)
--output-file <path> Write checklist to a file instead of stdout
--template Generate a blank PR review template
--template-style <s> Template style: minimal, standard, thorough (default: standard)
```
### 直接运行脚本
```bash
./scripts/review.sh --base develop --head feature/auth-refactor
```
## 配置
### skill.json 设置
```json
{
"config": {
"check_security": true,
"check_performance": true,
"check_style": true,
"check_tests": true,
"severity_levels": ["critical", "warning", "info"],
"output_format": "markdown"
}
}
```
| 设置 | 类型 | 默认值 | 说明 |
|----------------------|---------|------------|-----------------------------------------|
| `check_security` | boolean | true | 启用安全相关检查 |
| `check_performance` | boolean | true | 启用性能相关检查 |
| `check_style` | boolean | true | 启用风格与格式化检查 |
| `check_tests` | boolean | true | 启用测试覆盖检查 |
| `severity_levels` | array | 全部三项 | 包含哪些严重级别 |
| `output_format` | string | "markdown" | 默认输出格式 |
### 环境变量
```bash
export CRH_BASE_BRANCH=develop
export CRH_SEVERITY=warning
export CRH_OUTPUT=json
export CRH_CHECKS=security,performance
```
## 检查类别
### 安全检查
安全模块扫描常见漏洞与风险模式:
| 检查 | 语言 | 严重级别 |
|---------------------------|------------------|----------|
| 硬编码密钥/令牌 | 全部 | Critical |
| SQL 注入模式 | Python, JS, Go | Critical |
| 命令注入 | Python, JS, Bash | Critical |
| 不安全反序列化 | Python, Java | Critical |
| 缺失输入验证 | 全部 | Warning |
| 不安全正则模式 | 全部 | Warning |
| 使用 HTTP 而非 HTTPS | 全部 | Warning |
| 禁用安全头 | JS, Python | Warning |
| Eval/exec 使用 | Python, JS | Warning |
| 弱加密 | 全部 | Warning |
| 缺失 CSRF 保护 | Python, JS | Info |
| 冗长错误消息 | 全部 | Info |
### 性能检查
性能模块识别潜在瓶颈:
| Check | Languages | Severity |
|------------------------------|----------------|----------|
| N+1 query patterns | Python, JS | Critical |
| 缺失数据库索引 | SQL | Warning |
| 无界列表操作 | All | Warning |
| async 中同步 I/O | Python, JS | Warning |
| 内存中的大对象 | All | Warning |
| 缺失分页 | Python, JS, Go | Warning |
| 冗余重复计算 | All | Info |
| 未优化 import | Python, JS | Info |
| 循环中字符串拼接 | Python, Go | Info |
### 风格检查
风格模块执行一致性:
| Check | Languages | Severity |
|---------------------------|-----------|----------|
| 命名不一致 | All | Warning |
| Tab 与空格混用 | All | Warning |
| Import 顺序 | Python, JS| Info |
| 行长度违规 | All | Info |
| 缺失 docstring | Python | Info |
| 死代码 / 未使用变量 | All | Info |
| TODO/FIXME/HACK 注释 | All | Info |
| 魔法数字 | All | Info |
### 测试检查
测试模块验证充分覆盖:
| Check | Languages | Severity |
|------------------------------|------------|----------|
| 新函数无测试 | All | Warning |
| 缺失边界测试 | All | Warning |
| Mock 外部服务 | All | Info |
| 每测试 assert 数量 | All | Info |
| 测试命名约定 | All | Info |
| 存在集成测试 | All | Info |
## PR 审查模板
生成即用审查模板:
```bash
openclaw run code-review-helper --template --template-style thorough
```
### 模板风格
**Minimal** — 小改动快速审查:
```markdown
## Review
- [ ] Changes look correct
- [ ] No obvious security issues
- [ ] Tests pass
```
**Standard** — 典型 PR 的平衡审查:
```markdown
## Review Summary
**Reviewer**: ___
**Date**: ___
### Correctness
- [ ] Logic is correct and handles edge cases
- [ ] Error handling is appropriate
### Security
- [ ] No hardcoded secrets
- [ ] Input is validated and sanitized
### Performance
- [ ] No obvious performance regressions
- [ ] Database queries are optimized
### Tests
- [ ] New code has test coverage
- [ ] Existing tests still pass
### Notes
_Additional comments here_
```
**Thorough** — 关键变更的深度审查(含 Standard 模板全部章节,另加架构、文档、部署与回滚考量)。
## 示例
### 审查分支间变更
```bash
openclaw run code-review-helper --base main --head feature/payments
```
### 仅安全审查
```bash
openclaw run code-review-helper --security --severity critical
```
### 审查特定文件
```bash
openclaw run code-review-helper --files "src/auth/**/*.py"
```
### 生成 JSON 报告用于自动化
```bash
openclaw run code-review-helper --output json --output-file review.json
```
### 按编号审查特定 PR
```bash
openclaw run code-review-helper --pr 142
```
### 生成 thorough 审查模板
```bash
openclaw run code-review-helper --template --template-style thorough
```
## CI/CD 集成
在流水线中添加自动审查检查:
```yaml
- name: Code Review Checks
run: |
openclaw run code-review-helper \
--base ${{ github.event.pull_request.base.ref }} \
--head ${{ github.event.pull_request.head.sha }} \
--severity warning \
--output json \
--output-file review-results.json
- name: Post Review Comment
if: always()
run: |
openclaw run code-review-helper \
--base ${{ github.event.pull_request.base.ref }} \
--output markdown \
--output-file review-comment.md
gh pr comment ${{ github.event.pull_request.number }} \
--body-file review-comment.md
```
若发现任何 critical 级别问题,脚本以退出码 1 退出,CI 步骤失败并阻止合并。
## 语言支持
| 语言 | 安全 | 性能 | 风格 | 测试 |
|------------|----------|-------------|-------|-------|
| Python | Full | Full | Full | Full |
| JavaScript | Full | Full | Full | Full |
| TypeScript | Full | Full | Full | Full |
| Go | 完整 | 部分 | 完整 | 完整 |
| Rust | 部分 | 部分 | 完整 | 完整 |
| Java | 部分 | 部分 | 完整 | 完整 |
| SQL | Full | Full | N/A | N/A |
| Bash/Shell | 部分 | N/A | 完整 | N/A |
| Ruby | 部分 | 部分 | 完整 | 完整 |
## 故障排除
### 「No changes found」消息
确保 base 与 head 分支之间存在实际差异:
```bash
git diff main...HEAD --stat
```
### 脚本运行过久
对于大 diff(1000+ 文件),过滤到特定目录:
```bash
openc