jayantsingh924/reviewmind-cli
GitHub: jayantsingh924/reviewmind-cli
一款开源的 AST 与正则代码扫描 CLI 工具,支持将团队 PR 审查规则自动化并在本地 pre-commit 阶段强制执行。
Stars: 4 | Forks: 1
# ReviewMind CLI
ReviewMind 可将重复的 PR 审查评论转化为自动化、可强制执行的规则。
此 CLI 会在每次提交前,在本地对你的暂存文件运行这些规则——
在它们发起 pull request 之前就捕获违规行为。
## 工作原理
```
Your team writes a PR comment: "Don't use eval() — use safe_parse instead"
↓
ReviewMind extracts an enforceable rule (on the SaaS dashboard)
↓
Rule is approved by your team lead
↓
reviewmind CLI enforces it on every future commit — locally, instantly
```
## 安装说明
```
pip install reviewmind
```
或者使用 [pipx](https://pipx.pypa.io/):
```
pipx install reviewmind
```
## 快速开始
### 本地无账号启动
```
pip install reviewmind
reviewmind init
reviewmind check
```
`reviewmind init` 会扫描当前代码库,并创建一个包含初始规则的本地 `rules.yml`。
如果你尚未进行身份验证,`reviewmind check` 将自动使用该本地文件。
### GitHub Actions
将此工作流添加到 `.github/workflows/reviewmind.yml`:
```
name: ReviewMind
on:
pull_request:
jobs:
reviewmind:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: reviewmind/reviewmind-action@v1
with:
init: "true"
all-files: "true"
```
对于团队规则,请传入 CLI token:
```
- uses: reviewmind/reviewmind-action@v1
with:
token: ${{ secrets.REVIEWMIND_TOKEN }}
```
### 社区规则包
浏览并安装精选的本地规则包:
```
reviewmind rules browse
reviewmind rules install python-security
reviewmind rules install node-best-practices
reviewmind check
```
### SaaS/团队启动
#### 1. 通过 GitHub 进行身份验证
```
reviewmind login
```
这会在浏览器中打开 `https://github.com/login/device`,并在终端显示一段简短的代码。
在 GitHub 上输入该代码,批准该应用,CLI 就会自动完成身份验证——无需复制或粘贴任何 token。
批准后,系统会提示你选择 ReviewMind 应在哪个仓库上强制执行规则。
#### 2. 设置 pre-commit hook
```
cd your-project
reviewmind setup
```
安装一个 pre-commit hook,它会在每次执行 `git commit` 之前自动运行 `reviewmind check`。
#### 3. 运行手动扫描
```
reviewmind check
```
#### 4. 验证你的设置
```
reviewmind doctor
```
检查身份验证、后端连接性以及配置目录的权限。
## 示例输出
```
ReviewMind scanning 3 staged files...
src/auth.py
❌ [RM001] Dangerous Eval Usage — Line 12, Col 4
Using eval() is dangerous. Use safe_parse_json() instead.
src/utils.py
⚠️ [RM004] Direct Print Statement — Line 8
Use the logger instead of print().
─────────────────────────────────────────────
2 violations found. Commit blocked.
Run `reviewmind check --fix` to apply AI suggestions.
```
## 引擎 — 开源核心
此仓库包含被以下两者使用的**核心扫描引擎**:
- 此 CLI(本地 pre-commit 扫描)
- [ReviewMind SaaS](https://reviewmind.ai)(GitHub PR 扫描)
### 引擎功能
| 功能 | 状态 |
|---|---|
| 正则表达式匹配 | ✅ |
| Python AST 扫描 | ✅ |
| JavaScript / TypeScript AST | ✅ |
| Agentic LLM 语义扫描 | ✅ (通过 Gemini) |
| SARIF 导出 | ✅ |
| 忽略配置 (`.reviewmind.yml`) | ✅ |
| 列精度高亮 | ✅ |
| Fingerprint 去重 | ✅ |
### 直接使用引擎
```
from reviewmind import AnalysisEngine, EngineRule
rules = [
EngineRule(
rule_code="RM001",
title="No eval()",
check_type="regex",
check_pattern=r"eval\(",
check_language="python",
severity="error",
what_is_wrong="eval() is dangerous",
what_is_correct="Use safe_parse_json()",
)
]
engine = AnalysisEngine(rules=rules)
findings = engine.run_scan([
{
"filename": "src/main.py",
"content": open("src/main.py").read(),
"added_lines": {10, 11, 12}, # lines changed in this commit
}
])
for f in findings:
print(f"{f.rule_code} | {f.file_path}:{f.line} | {f.message}")
```
## 配置
在你的仓库根目录下创建 `.reviewmind.yml` 以忽略特定路径:
```
ignore:
- "tests/**"
- "migrations/**"
- "generated/**"
- "*.min.js"
```
## 环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
| `REVIEWMIND_API_URL` | `http://localhost:8080/api` | 后端 API URL |
| `REVIEWMIND_GITHUB_CLIENT_ID` | *(内置)* | 覆盖 GitHub OAuth App 的 client ID |
| `REVIEWMIND_SKIP` | `false` | 设置为 `true` 或 `1` 以跳过 ReviewMind 的 pre-commit 执行 |
| `REVIEWMIND_HOOK_PROFILE` | *(无)* | 仅运行属于某个配置文件的规则(`security`、`error`、`warning`、`style` 或自定义关键字) |
| `REVIEWMIND_DISABLED_HOOKS` | *(无)* | 逗号分隔的规则代码/ID 列表(例如 `RM001,RM002`),用于禁用/跳过 |
| `GEMINI_API_KEY` | *(无)* | `agentic` 评估引擎使用的本地 Gemini API key |
身份验证是在 `reviewmind login` 期间通过 GitHub OAuth Device Flow 处理的。
GitHub token 存储在 `~/.reviewmind/config.json` 中,并作为所有 API 请求中的 `x-cli-token` header 发送。
## 许可证
MIT — 详情请见 [LICENSE](LICENSE)
## 链接
- 🌐 [ReviewMind SaaS 平台](https://reviewmind.ai) — 完整的控制面板、GitHub App、团队管理
- 📖 [文档](https://docs.reviewmind.ai)
- 🐛 [问题追踪器](https://github.com/jayantsingh924/reviewmind-cli/issues)
标签:代码质量审查, 自动化payload嵌入, 逆向工具, 错误基检测, 静态代码分析