naveenkumarbaskaran/codewise
GitHub: naveenkumarbaskaran/codewise
一款与 LLM 提供商无关的 AI 代码审查与安全扫描工具,集代码审查、漏洞检测、测试生成和文档生成为一体,支持 CLI、MCP Server、GitHub Action 及 Git Hook 多种集成方式。
Stars: 0 | Forks: 0
# codewise
**与 LLM 无关的代码审查、安全扫描、测试生成和文档生成工具 — 可作为 CLI、MCP server、GitHub Action 或 git hook 使用。**
适用于**任何 LLM 提供商**:OpenAI、Anthropic、Google Gemini、Ollama、Azure OpenAI、AWS Bedrock — 由 [litellm](https://github.com/BerriAI/litellm) 提供支持。
## 🎬 演示
codewise reviewing code, scanning for vulnerabilities, and generating tests — all from the CLI
## 功能
| 功能 | 描述 |
|------------|-------------|
| **Code Review (代码审查)** | Bug、性能、可维护性、最佳实践 |
| **Security Scan (安全扫描)** | OWASP/CWE 分类,用于 GitHub Security 选项卡的 SARIF 输出 |
| **Test Generation (测试生成)** | 生成可运行的测试 (pytest, jest, go, junit) |
| **Doc Generation (文档生成)** | Docstrings、类型提示、内联注释 |
| **Configurable Rules (可配置规则)** | 标准规则包 + 自定义 regex/LLM 规则 |
| **Git Hooks** | 具有可配置阈值的 Pre-commit 和 pre-push 钩子 |
| **MCP Server** | 可从任何兼容 MCP 的编辑器(VS Code、Cursor 等)中使用 |
| **GitHub Action** | 带有 SARIF 上传的自动 PR 审查 |
## 快速开始
```
pip install codewise-ai
```
### 审查代码
```
# Review 未提交的更改
codewise review
# Review 暂存的更改 (pre-commit 风格)
codewise review --staged
# Push 前 Review
codewise review --push
# Review PR 分支
codewise review --branch main
# Review 指定文件
codewise review src/main.py src/utils.py
# 安全扫描
codewise security --staged
# 生成测试
codewise testgen src/handler.py --framework pytest
# 生成 docs
codewise docgen src/handler.py
```
### 配置
```
# 在你的 repo 中创建 .codewise.yaml
codewise init
# 查看活跃规则
codewise rules show
# 列出可用的 Rule Pack
codewise rules list-packs
```
## 配置说明
在你的代码库根目录创建 `.codewise.yaml` 文件:
```
model: gpt-4o-mini
temperature: 0.1
min_severity: low
fail_on: high
output_format: terminal
rules:
enable_packs:
- python-best-practices
- security-basics
custom:
- id: no-debug-flags
pattern: "DEBUG\\s*=\\s*True"
file_pattern: "*.py"
severity: high
message: "Remove debug flags before merging."
- id: require-error-handling
llm_check: "Ensure all HTTP calls have try/except."
file_pattern: "*.py"
severity: high
- id: no-fixme-on-main
pattern: "FIXME|HACK"
file_pattern: "*.py"
severity: medium
branches: [main, master]
hooks:
pre_commit:
enabled: true
fail_on: high
pre_push:
enabled: true
fail_on: high
max_files: 20
timeout: 120
```
### 规则类型
| 类型 | 描述 | 需要 LLM? |
|------|-------------|------|
| **Regex** | 基于模式匹配,即时生效,无需 API 调用 | 否 |
| **LLM** | 为审查器提供的自然语言指令 | 是 |
| **Composite** | Regex 预过滤 + LLM 分析 | 是 |
### 标准规则包
| 规则包 | 规则数 | 语言 |
|------|-------|-----------|
| `python-best-practices` | 6 | Python |
| `javascript-best-practices` | 4 | JS/TS |
| `security-basics` | 5 | 所有 |
| `go-best-practices` | 3 | Go |
| `java-best-practices` | 3 | Java |
| `rust-best-practices` | 2 | Rust |
## Git Hooks
```
# 安装 pre-commit + pre-push hooks
codewise hooks install
# Check 状态
codewise hooks status
# 移除 hooks
codewise hooks uninstall
```
**Pre-push 钩子** 会审查所有即将推送的 commit 与远程分支的差异。如果发现的问题超过配置的严重性阈值,它将阻止推送。用户始终可以通过 `git push --no-verify` 绕过。
在 `.codewise.yaml` 中配置钩子行为:
```
hooks:
pre_push:
enabled: true
review: true
security: true
fail_on: high
max_files: 20 # Skip if too many files (avoid slow pushes)
timeout: 120 # Max seconds
```
## LLM 提供商
codewise 使用 [litellm](https://github.com/BerriAI/litellm) — 它支持的任何模型均可运行:
```
# OpenAI (默认)
export CODEWISE_API_KEY=sk-...
codewise review
# Anthropic
codewise review --model claude-sonnet-4-20250514
export ANTHROPIC_API_KEY=sk-ant-...
# Google Gemini
codewise review --model gemini/gemini-2.0-flash
export GEMINI_API_KEY=...
# Ollama (本地, 免费)
codewise review --model ollama/llama3.1
# Azure OpenAI
codewise review --model azure/gpt-4o-mini
export AZURE_API_KEY=...
export AZURE_API_BASE=https://your-deployment.openai.azure.com
# AWS Bedrock
codewise review --model bedrock/anthropic.claude-sonnet-4-20250514-v2:0
```
## MCP Server
从任何兼容 MCP 的编辑器中使用 codewise:
```
# stdio transport (用于 VS Code / Cursor)
codewise mcp
# SSE transport (用于 web 客户端)
codewise mcp --transport sse --port 3000
```
### MCP 工具
| 工具 | 描述 |
|------|-------------|
| `review_code` | 审查代码或 diff |
| `scan_security` | 安全漏洞扫描 |
| `generate_tests` | 生成测试用例 |
| `generate_docs` | 生成文档 |
| `check_rules` | 运行 regex 规则(无需 LLM) |
| `list_rule_packs` | 列出可用的规则包 |
### VS Code MCP 配置
```
{
"mcpServers": {
"codewise": {
"command": "codewise",
"args": ["mcp"]
}
}
}
```
## GitHub Action
```
name: Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: naveenkumarbaskaran/codewise@v2.0.0
with:
api_key: ${{ secrets.OPENAI_API_KEY }}
mode: both # review + security
model: gpt-4o-mini
fail_on: high
output_format: markdown
# Optional: upload SARIF to GitHub Security tab
- uses: naveenkumarbaskaran/codewise@v2.0.0
with:
api_key: ${{ secrets.OPENAI_API_KEY }}
mode: security
sarif_file: codewise.sarif
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: codewise.sarif
```
## Pre-commit 集成
```
# .pre-commit-config.yaml
repos:
- repo: https://github.com/naveenkumarbaskaran/codewise
rev: v2.0.0
hooks:
- id: codewise-review
- id: codewise-security
```
## 输出格式
| 格式 | 适用场景 |
|--------|----------|
| `terminal` | 交互式 CLI(默认),丰富色彩 |
| `json` | 管道传输,编程式调用 |
| `sarif` | GitHub Security 选项卡,IDE 集成 |
| `markdown` | PR 评论,CI 构件 |
```
codewise review --format json | jq '.findings[] | select(.severity == "critical")'
codewise security --format sarif > report.sarif
codewise review --format markdown >> pr-comment.md
```
## 架构
```
codewise/
├── cli.py # Click CLI with subcommands
├── config.py # YAML config loader (layered)
├── models.py # Pydantic data models
├── rules.py # Configurable rules engine
├── core/
│ ├── diff.py # Diff parsing, language detection
│ ├── reviewer.py # Code review engine
│ ├── security.py # Security scanner
│ ├── testgen.py # Test generation
│ └── docgen.py # Doc generation
├── llm/
│ ├── provider.py # litellm wrapper
│ └── prompts.py # Prompt templates
├── integrations/
│ └── git.py # Git diff extraction + hook management
├── mcp/
│ └── server.py # MCP server
└── output/
├── terminal.py # Rich terminal output
├── json_fmt.py # JSON output
├── sarif_fmt.py # SARIF 2.1.0 output
└── markdown_fmt.py # Markdown output
```
## 许可证
MIT
标签:AI编程助手, Anthropic, AWS Bedrock, Azure OpenAI, CISA项目, CIS基准, DevSecOps, DLL 劫持, Git Hook, GitHub Action, IDE插件, LLM无关, LLM评估, MCP服务器, Ollama, OpenAI, SARIF, SAST, 上游代理, 人工智能, 代码安全, 代码审查, 代码自动化, 代码规范, 内存规避, 多模型支持, 大语言模型, 大语言模型蜜罐, 威胁情报, 安全扫描, 开发者工具, 开源, 文档生成, 时序注入, 测试生成, 漏洞枚举, 用户模式Hook绕过, 盲注攻击, 逆向工具, 静态应用安全测试