raye-deng/open-code-review

GitHub: raye-deng/open-code-review

开源AI代码审查工具,专注检测AI生成代码中的幻觉包、过时API和安全反模式,支持本地LLM零成本运行。

Stars: 4 | Forks: 2

# Open Code Review ![Open Code Review](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/288d0aedca223005.png) [![npm version](https://img.shields.io/npm/v/@opencodereview/cli?style=flat-square&label=v2.1.0)](https://www.npmjs.com/package/@opencodereview/cli) [![npm downloads](https://img.shields.io/npm/dw/@opencodereview/cli?style=flat-square)](https://www.npmjs.com/package/@opencodereview/cli) [![License: BUSL-1.1](https://img.shields.io/badge/License-BUSL--1.1-blue.svg)](LICENSE) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/869ed5fbd5223006.svg)](https://github.com/raye-deng/open-code-review/actions/workflows/ci.yml) [![GitHub Stars](https://img.shields.io/github/stars/raye-deng/open-code-review?style=social)](https://github.com/raye-deng/open-code-review) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) ## AI Linters 遗漏了什么 AI 编程助手(Copilot、Cursor、Claude)生成的代码包含**传统工具完全遗漏的缺陷**: | 缺陷 | 示例 | ESLint / SonarQube | |--------|---------|-------------------| | **幻觉导入 (Hallucinated imports)** | `import { x } from 'non-existent-pkg'` | ❌ 遗漏 | | **过时 API (Stale APIs)** | 使用训练数据中已废弃的 API | ❌ 遗漏 | | **上下文窗口残留 (Context window artifacts)** | 跨文件逻辑矛盾 | ❌ 遗漏 | | **过度设计模式 (Over-engineered patterns)** | 不必要的抽象、死代码 | ❌ 遗漏 | | **安全反模式 (Security anti-patterns)** | 硬编码示例密钥、`eval()` | ❌ 部分 | Open Code Review 可以检测所有这些问题 —— 覆盖 **6 种语言**,且完全**免费**。 ## 演示 ![L2 HTML Report Screenshot](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/37769d14bc223011.png) 📄 [查看完整的交互式 HTML 报告](docs/demo-reports/v4-l2/self-scan.html) ### 快速预览 ``` $ ocr scan src/ --sla L3 ╔══════════════════════════════════════════════════════════════╗ ║ Open Code Review — Deep Scan Report ║ ╚══════════════════════════════════════════════════════════════╝ Project: packages/core/src SLA: L3 Deep — Structural + Embedding + LLM Analysis 112 issues found in 110 files Overall Score: 67/100 D Threshold: 70 | Status: FAILED Files Scanned: 110 | Languages: typescript | Duration: 12.3s ``` ## 深度扫描 (L3) — 工作原理 L3 结合三层分析以实现最大覆盖率: ``` Layer 1: Structural Detection Layer 2: Semantic Analysis Layer 3: LLM Deep Scan ├── Hallucinated imports (npm/PyPI) ├── Embedding similarity recall ├── Cross-file coherence check ├── Stale API detection ├── Risk scoring ├── Logic bug detection ├── Security patterns ├── Context window artifacts ├── Confidence scoring ├── Over-engineering metrics └── Enhanced severity ranking └── AI-powered fix suggestions └── A+ → F quality scoring ``` **由本地 LLM 或任何 OpenAI 兼容的 API 提供支持。** 运行 Ollama 进行 100% 本地分析,或连接到任何远程 LLM 提供商 —— 接口保持一致。 ``` # 本地分析 (Ollama) ocr scan src/ --sla L3 --provider ollama --model qwen3-coder # 任意 OpenAI-compatible provider ocr scan src/ --sla L3 --provider openai-compatible \ --api-base https://your-llm-endpoint/v1 --model your-model --api-key YOUR_KEY ``` ## AI 自动修复 — `ocr heal` 让 AI 自动修复其发现的问题。在应用前审查更改。 ``` # 预览修复而不更改文件 ocr heal src/ --dry-run # 应用修复 + 生成 IDE rules ocr heal src/ --provider ollama --model qwen3-coder --setup-ide # 仅生成 IDE rules (Cursor, Copilot, Augment) ocr setup src/ ``` ## 多语言检测 针对 **6 种语言** 的特定检测器,以及幻觉包数据库(npm、PyPI、Maven、Go modules): | 语言 | 特定检测器 | |----------|-------------------| | **TypeScript / JavaScript** | 幻觉导入 (npm)、过时 API、过度工程化 | | **Python** | 裸 `except`、`eval()`、可变默认参数、幻觉导入 (PyPI) | | **Java** | `System.out.println` 泄露、已废弃的 `Date/Calendar`、幻觉导入 (Maven) | | **Go** | 未处理错误、已废弃的 `ioutil`、库代码中的 `panic` | | **Kotlin** | `!!` 滥用、`println` 泄露、空安全反模式 | ## 横向对比 | | Open Code Review | Claude Code Review | CodeRabbit | GitHub Copilot | |---|---|---|---|---| | **价格** | **免费** | $15–25/PR | $24/月/席位 | $10–39/月 | | **开源** | ✅ | ❌ | ❌ | ❌ | | **自托管** | ✅ | ❌ | 企业版 | ❌ | | **AI 幻觉检测** | ✅ | ❌ | ❌ | ❌ | | **过时 API 检测** | ✅ | ❌ | ❌ | ❌ | | **深度 LLM 分析** | ✅ | ❌ | ❌ | ❌ | | **AI 自动修复** | ✅ | ❌ | ❌ | ❌ | | **多语言支持** | ✅ 6 种语言 | ❌ | JS/TS | JS/TS | | **注册表验证** | ✅ npm/PyPI/Maven | ❌ | ❌ | ❌ | | **SARIF 输出** | ✅ | ❌ | ❌ | ❌ | | **GitHub + GitLab** | ✅ 两者均支持 | 仅 GitHub | 两者均支持 | 仅 GitHub | | **数据隐私** | ✅ 100% 本地 | ❌ 云端 | ❌ 云端 | ❌ 云端 | ## 快速开始 ``` # 安装 npm install -g @opencodereview/cli # 快速扫描 — 无需 AI ocr scan src/ # 深度扫描 — 使用本地 LLM (Ollama) ocr scan src/ --sla L3 --provider ollama --model qwen3-coder # 深度扫描 — 使用任意 OpenAI-compatible provider ocr scan src/ --sla L3 --provider openai-compatible \ --api-base https://your-provider/v1 --model your-model --api-key YOUR_KEY ``` ## CI/CD 集成 ### GitHub Actions (30 秒) ``` name: Code Review on: [pull_request] jobs: review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: raye-deng/open-code-review@v1 with: sla: L1 threshold: 60 github-token: ${{ secrets.GITHUB_TOKEN }} ``` ### GitLab CI ``` code-review: script: - npx @opencodereview/cli scan src/ --sla L1 --threshold 60 --format json --output ocr-report.json artifacts: reports: codequality: ocr-report.json ``` ### 输出格式 ``` ocr scan src/ --format terminal # Pretty terminal output ocr scan src/ --format json # JSON for CI pipelines ocr scan src/ --format sarif # SARIF for GitHub Code Scanning ocr scan src/ --format html # Interactive HTML report ``` ### 配置 ``` # .ocrrc.yml sla: L3 ai: embedding: provider: ollama model: nomic-embed-text baseUrl: http://localhost:11434 llm: provider: ollama model: qwen3-coder endpoint: http://localhost:11434 # Or use any OpenAI-compatible provider: # provider: openai-compatible # apiBase: https://your-llm-endpoint/v1 # model: your-model ``` ## 项目结构 ``` packages/ core/ # Detection engine + scoring (@opencodereview/core) cli/ # CLI tool — ocr command (@opencodereview/cli) github-action/ # GitHub Action wrapper ``` ## 适用人群? - **使用 AI 编程助手的团队** — Copilot、Cursor、Claude Code、Codex 或任何生成生产代码的基于 LLM 的工具 - **开源维护者** — 在合并之前审查 AI 生成的 PR,检查幻觉导入、过时 API 和安全反模式 - **DevOps / 平台工程师** — 无需将代码发送到云服务即可向 CI/CD 管道添加质量门禁 - **注重安全的团队** — 在本地运行一切 (Ollama),将代码保留在你的机器上 - **独立开发者** — 免费、快速且无需配置即可工作 (`npx @opencodereview/cli scan src/`) ## 许可证 [BSL-1.1](LICENSE) — 个人和非商业用途免费。于 2030-03-11 转换为 Apache 2.0。 商业用途需要 [团队或企业许可证](https://codes.evallab.ai/pricing)。 **如果你觉得有用,请给这个仓库点个 Star —— 它的帮助超乎你的想象!**
标签:AI 代码审查, AI风险缓解, API 废弃检测, CI/CD 质量门禁, DevSecOps, DLL 劫持, IDE 插件, IPv6支持, LLM评估, MITM代理, NPM 包, Ollama, Petitpotam, SAST, 上游代理, 云安全监控, 代码安全, 大语言模型, 幽灵依赖, 开源安全工具, 本地推理, 漏洞枚举, 盲注攻击, 自动化代码评审, 自动化攻击, 软件供应链安全, 远程方法调用, 逆向工程平台, 逻辑漏洞, 零成本, 静态分析