llm审阅者
使用LLMs(CLI+MCP服务器)检查任何AI代理的代码更改。支持GitHub Copilot、本地Ollama模型和任何与OpenAI兼容的端点。
安装
# Install globally from GitHub
npm install -g github:asheshv/llm-reviewer
# Or use without installing:
npx --yes github:asheshv/llm-reviewer --help快速开始
# Review uncommitted local changes (uses Copilot by default)
llm-reviewer
# Review changes in a feature branch vs main
llm-reviewer branch main
# Review a pull request
llm-reviewer pr 123
# Review with a local Ollama model
llm-reviewer local --provider ollama --model qwen2.5-coder:14b
# Review with any OpenAI-compatible endpoint
LLM_REVIEWER_API_KEY="sk-..." llm-reviewer local \
--provider custom --base-url https://openrouter.ai/api/v1 \
--model google/gemini-2.5-flash命令行用法
llm-reviewer [mode] [options]
Modes (default: local):
unstaged Working tree vs index
staged Index vs HEAD
local Working tree vs HEAD (default)
branch [base] Current branch vs base (default: main)
pr Pull request diff
commits Last N commits
range .. Arbitrary ref range
Options:
--model Model to use (default: auto)
--format text | markdown | json (default: markdown)
--stream Force streaming output
--no-stream Force buffered output
--prompt Override review prompt
--config
Override config file path
--provider Review provider: copilot, ollama, custom, custom:
--chunking auto | always | never (default: auto)
--timeout Request timeout (default: 30 for copilot/custom, 120 for ollama)
--ollama-url Ollama base URL (default: http://localhost:11434)
--base-url Base URL for custom provider (OpenAI-compatible endpoint)
--verbose Enable debug logging to stderr
--help Show help
--version Show version
Subcommands:
llm-reviewer models List available models
llm-reviewer chat "" Free-form LLM chat
llm-reviewer status Show provider connectivity and configuration例子
# Review staged changes before committing
llm-reviewer staged
# Review the last 3 commits
llm-reviewer commits 3
# Review a ref range
llm-reviewer range v1.0.0..HEAD
# Use a specific model with JSON output
llm-reviewer branch main --model gpt-4.1 --format json
# Custom review instructions
llm-reviewer --prompt "Focus on security and error handling"
# Review with Ollama (local LLM)
llm-reviewer local --provider ollama --model qwen2.5-coder:14b
# List Ollama models
llm-reviewer models --provider ollama
# Check provider status
llm-reviewer status --provider ollama
# Force chunking for large diffs
llm-reviewer branch main --chunking always
# Longer timeout for large models
llm-reviewer commits 1 --provider ollama --model qwen2.5-coder:32b --timeout 300提供商
副驾驶(默认)
使用GitHub Copilot的聊天API。需要GitHub令牌(请参阅 认证).
llm-reviewer local # auto-selects model
llm-reviewer local --model gpt-4.1 # specific model
llm-reviewer models # list available modelsOllama(当地)
使用本地运行 奥拉玛 例子无需身份验证。
# Start Ollama (if not running)
ollama serve
# List available models
llm-reviewer models --provider ollama
# Review with a specific model (model is required for Ollama)
llm-reviewer local --provider ollama --model qwen2.5-coder:14b
# Custom Ollama URL
llm-reviewer local --provider ollama --ollama-url http://remote:11434 --model codellama
# Non-streaming for cleaner output
llm-reviewer commits 1 --provider ollama --model qwen2.5-coder:14b --no-stream自定义提供者(兼容OpenAI)
连接到实现OpenAI聊天完成API的任何端点-OpenRouter、Groq、Together AI、Fireworks、LM Studio、vLLM等。
基本URL必须包括完整的API路径(例如。,https://api.groq.com/openai/v1,不https://api.groq.com).如果您遇到404错误,请检查您的URL是否包含/v1或提供者的等效路径前缀。
# Quick start: API key via env var, endpoint via --base-url
LLM_REVIEWER_API_KEY="sk-or-..." llm-reviewer local \
--provider custom --base-url https://openrouter.ai/api/v1 \
--model google/gemini-2.5-flash
# Named provider from config file (see config example below)
llm-reviewer local --provider custom:groq --model llama-3.3-70b-versatile
# List models from a custom endpoint
llm-reviewer models --provider custom --base-url https://api.groq.com/openai/v1
# Dynamic auth with a shell command
# Config: { "providerOptions": { "gcp": { "baseUrl": "https://...", "apiKeyCommand": "gcloud auth print-access-token" } } }
llm-reviewer local --provider custom:gcp --model gemini-2.5-flash
# Bare "custom" picks from providerOptions if --base-url is not set (see Named Configurations)
llm-reviewer local --provider custom --model google/gemini-2.5-flash
# Local endpoint (no auth required)
llm-reviewer local --provider custom --base-url http://localhost:1234/v1 --model local-model模型始终是必需的 对于自定义提供程序,没有自动选择。集 --model 或添加 "model" 到您的配置文件。
命名配置
使用以下命令在配置文件中定义多个端点 providerOptions:
{
"providerOptions": {
"groq": {
"baseUrl": "https://api.groq.com/openai/v1",
"apiKeyCommand": "op read 'op://Dev/Groq/api-key'"
},
"openrouter": {
"baseUrl": "https://openrouter.ai/api/v1",
"apiKeyCommand": "cat ~/.config/openrouter/key"
}
}
}然后使用它们 --provider custom::
llm-reviewer local --provider custom:groq --model llama-3.3-70b-versatile
llm-reviewer local --provider custom:openrouter --model anthropic/claude-sonnet-4使用裸机时 --provider custom,解析顺序为:
--base-urlCLI标志或LLM_REVIEWER_BASE_URLenv 是providerOptions.custom进入- 第一个非内置
providerOptions进入
认证
自定义提供程序支持三种身份验证模式:
| 模式 | 配置字段 | 描述 |
|---|---|---|
| 静态密钥 | apiKey | 每次请求都会发送承载令牌 |
| 动态命令 | apiKeyCommand | 执行Shell命令以获取密钥;缓存,直到身份验证失败 |
| 无身份验证 | _(省略两者)_ | 没有 Authorization 标头(用于本地端点) |
当两者都 apiKey 和 apiKeyCommand 存在, apiKeyCommand 获胜(动态胜过静态)。
在401(或没有速率限制标头的403)上,通过重新运行命令刷新密钥,并重试一次请求。
流行的OpenAI兼容端点
| 提供者 | 基本URL | 身份验证 | 模型示例 |
|---|---|---|---|
| OpenRouter | https://openrouter.ai/api/v1 | 承载密钥 | google/gemini-2.5-flash, anthropic/claude-sonnet-4 |
| Groq | https://api.groq.com/openai/v1 | 承载密钥 | llama-3.3-70b-versatile, mixtral-8x7b-32768 |
| 一起AI | https://api.together.xyz/v1 | 承载密钥 | meta-llama/Llama-3.3-70B-Instruct-Turbo |
| 烟花 | https://api.fireworks.ai/inference/v1 | 承载密钥 | accounts/fireworks/models/llama-v3p3-70b-instruct |
| LM工作室 | http://localhost:1234/v1 | 无 | 无论加载何种模型 |
| vLLM | http://localhost:8000/v1 | 无 | 取决于部署 |
安全说明
apiKeyCommand以完全用户权限执行shell命令。像对待它一样对待它package.jsonscripts——在不受信任的存储库中运行之前,请检查项目配置文件。- 不要 存储静态
apiKey项目配置文件中可能提交到版本控制的值。使用apiKeyCommand或LLM_REVIEWER_API_KEY取而代之的是env-var。 - API密钥从不出现在错误消息中。从所有错误输出中编辑命令字符串。
超时
自定义提供程序使用默认的30秒超时(与Copilot相同)。云API很快。对于自定义端点后面的本地模型,设置 --timeout 120 或 "timeout": 120 在配置中。
状态命令
检查提供程序连接、已解析的配置和可用型号:
llm-reviewer status # default provider (copilot)
llm-reviewer status --provider ollama # check Ollama
llm-reviewer status --provider custom:groq # check custom endpoint
llm-reviewer status --json # machine-readable output分块评论
对于超出模型上下文窗口的较大差异, llm-reviewer 自动将差异拆分为块,独立审查每个块,然后通过reduce pass聚合结果。
auto(默认)--当diff超过模型上下文的80%时,执行块always--总是大块,即使是很小的差异never--如果差异太大,则失败(对CI硬限制有用)
llm-reviewer branch main --chunking always # force chunking
llm-reviewer branch main --chunking never # disable chunking
# Kill switch via environment variable
LLM_REVIEWER_CHUNKING=never llm-reviewer local分块评论显示stderr的进展:
Reviewing chunk 1/3 (src/auth.ts, src/config.ts)... done (3,200 tokens)
Reviewing chunk 2/3 (src/review.ts, src/prompt.ts)... done (2,800 tokens)
Reviewing chunk 3/3 (src/cli.ts)... done (1,950 tokens)
Aggregating findings... done (4,500 tokens)MCP服务器设置
MCP服务器将LLM审查功能作为AI代理(Claude Code、Cursor、Zed、Cline等)的工具公开。
克劳德代码
添加 .mcp.json 在您的项目根目录中或 ~/.config/claude/mcp.json:
{
"mcpServers": {
"llm-reviewer": {
"command": "llm-reviewer",
"args": ["--mcp"]
}
}
}适用于通用MCP客户端
{
"llm-reviewer": {
"type": "stdio",
"command": "llm-reviewer",
"args": ["--mcp"]
}
}或者,如果在本地使用(不是全局安装):
{
"llm-reviewer": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/llm-reviewer/dist/cli.js", "--mcp"]
}
}可用的MCP工具
llm_review--查看代码更改(支持所有7种模式)llm_chat--与LLM免费聊天(可选代码上下文)llm_models--列出可用型号
克劳德代码技能
您还可以添加 llm-reviewer 作为 Claude代码技能 因此,当您请求代码审查时,Claude可以自动调用它。
设置
# Copy the skill into your Claude skills directory
mkdir -p ~/.claude/skills/llm-reviewer
cp skills/SKILL.md ~/.claude/skills/llm-reviewer/SKILL.md用法
安装后,Claude Code将自动使用 llm-reviewer 当你:
- 要求查看代码更改、差异或PR
- 完成一个功能并寻求第二意见
- 请求积极的多轮审查
您还可以显式调用它:
/llm-reviewer该技能支持所有提供者(Copilot、Ollama、Custom)、分块、跨模型审查和完整的CLI功能集。看 skills/SKILL.md 以供完整参考。
配置
配置从多个层加载(从最低优先级到最高优先级):
- 内置默认值 --随工具发货
- 环境变量 —
LLM_REVIEWER_*(见下文) - 全局配置 —
~/.llm-reviewer/config.json或config.md - 项目配置 —
/.llm-reviewer/config.json或config.md - 命令行标志 —
--model,--format,--provider等等。(最高优先级)
环境变量
| 变量 | 描述 | 示例 |
|---|---|---|
LLM_REVIEWER_PROVIDER | 覆盖提供者 | ollama, custom |
LLM_REVIEWER_OLLAMA_URL 基础 URL | http://remote:11434 | |
LLM_REVIEWER_BASE_URL | 自定义提供程序基本URL | https://api.groq.com/openai/v1 |
LLM_REVIEWER_API_KEY | 自定义提供程序API密钥(静态) | sk-... |
LLM_REVIEWER_API_KEY_COMMAND | 获取API密钥的Shell命令 | op read 'op://Dev/key' |
LLM_REVIEWER_CHUNKING | 分块模式(关闭开关) | never |
当两者都 LLM_REVIEWER_API_KEY 和 LLM_REVIEWER_API_KEY_COMMAND 被设置, API_KEY 优先(env-var使用静态排序而不是动态排序,因为用户显式地设置了这两种排序)。在配置文件内, apiKeyCommand 赢得青睐 apiKey (动态多于静态)。这些环境变量只影响裸机 --provider custom,未指定提供者,如 custom:groq.
config.json架构
{
"model": "auto",
"format": "markdown",
"stream": true,
"mode": "extend",
"prompt": "path/to/custom-prompt.md",
"defaultBase": "main",
"ignorePaths": ["*.lock", "dist/**"],
"provider": "copilot",
"providerOptions": {
"ollama": {
"baseUrl": "http://localhost:11434"
},
"groq": {
"baseUrl": "https://api.groq.com/openai/v1",
"apiKeyCommand": "op read 'op://Dev/Groq/api-key'"
},
"openrouter": {
"baseUrl": "https://openrouter.ai/api/v1",
"apiKeyCommand": "cat ~/.config/openrouter/key"
}
},
"chunking": "auto",
"timeout": 30
}| 字段 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model | 字符串 | "auto" | 型号ID或 "auto" 用于自动选择 |
format | 字符串 | "markdown" | 输出格式: text, markdown,或 json |
stream | 布尔值 | true | 启用流式输出 |
mode | 字符串 | "extend" | 快速合并策略: extend 或 replace |
prompt | string | -- | 内联文本或路径 .md 文件(相对于配置目录) |
defaultBase | 字符串 | "main" | 默认基础分支 branch 模式 |
ignorePaths | string\[\] | [] | 要从差异中排除的全局模式(跨层合并) |
provider | 字符串 | "copilot" | 提供商: copilot, ollama, custom, custom: |
providerOptions | 对象 | {} | 特定于提供商的配置(Ollama URL、自定义端点) |
chunking | 字符串 | "auto" | 分块模式: auto, always,或 never |
timeout | 编号 | 30 | 请求超时(秒)(Ollama自动:120) |
快速定制
您可以通过两种方式自定义审核说明:
- 在config.json中内联:
{
"mode": "extend",
"prompt": "Focus on TypeScript type safety and error handling."
}- 单独的config.md文件:
# Project-Specific Review Guidelines
- Check React hooks dependencies
- Verify error boundaries are present
- Flag any `any` types提示合并模式
"extend"(默认)--将您的指令附加到默认提示"replace"--将默认提示完全替换为您的提示
多层合并示例(全部使用 "extend"):
[Default prompt from prompts/default-review.md]
## Additional Instructions (Global)
[Global ~/.llm-reviewer/config.md]
## Project Instructions
[Project .llm-reviewer/config.md]如果项目配置使用 "mode": "replace",仅使用项目提示。
命令行界面 --prompt 标志总是取代一切:
llm-reviewer --prompt "Only check for SQL injection"默认审核提示
内置提示符按优先级顺序检查代码更改:
- 安全 --SQL注入、XSS、命令注入、身份验证旁路、OWASP Top 10
- 正确性 --边缘情况、竞争条件、错误路径、无效假设
- 演出 --N+1个查询、缺失索引、算法复杂性
- 可读性 --命名不明确、评论误导、不必要的复杂性
- 简洁 --过度工程化、过早抽象、违反YAGNI
结果分为高、中或低严重程度。安全问题总是很严重。
要自定义,请添加 config.md 归档 ~/.llm-reviewer/ (全球)或 /.llm-reviewer/ (项目)。
输出格式
Markdown(默认)
### HIGH SQL Injection in query builder
**File:** `src/db.ts` **Line:** 42
**Category:** Security
User input is concatenated directly into SQL query.
**Suggestion:**
Use parameterized queries instead...文本
无标记格式的纯文本输出。适用于不支持markdown的终端或工具。
JSON
在单个JSON对象中完成结构化输出:
{
"review": {
"content": "### HIGH SQL Injection...",
"model": "gpt-4.1",
"usage": { "totalTokens": 1234 }
},
"diff": {
"filesChanged": 5,
"insertions": 120,
"deletions": 45,
"files": [
{ "path": "src/db.ts", "status": "modified" }
]
},
"warnings": [],
"exitCode": 1
}对于分块评论,使用情况包括细分:
"usage": {
"totalTokens": 12450,
"chunkedBreakdown": { "mapTokens": 7950, "reduceTokens": 4500, "chunks": 3 }
}NDJSON(流式JSON)
使用 --stream --format json 对于换行符分隔的JSON流:
llm-reviewer --stream --format json | while read line; do
echo "$line" | jq -r '.text // empty'
done每一行都是一个有效的JSON对象。启用流输出的实时机器消费。
退出代码
| 代码 | 含义 | 用例 | ||
|---|---|---|---|---|
| 0 | 成功--无严重性问题 | 正常完成 | ||
| 1 | 审查已完成,结果为高 | CI门控: `llm-reviewer branch main \ | \ | exit 1` |
| 2 | 身份验证失败 | 未找到GitHub令牌 | ||
| 3 | Diff错误 | Diff为空,不是git仓库等。 | ||
| 4 | API/型号错误 | 速率限制,服务器错误,型号不可用 | ||
| 5 | 配置错误 | 配置文件格式不正确 |
CI集成示例
# Fail the build if high-severity issues are found
llm-reviewer branch main || exit 1
# Or capture the exit code
llm-reviewer branch main
if [ $? -eq 1 ]; then
echo "High-severity issues found. Please review."
exit 1
fi认证
GitHub令牌按优先级顺序解析。第一场比赛获胜。
$GITHUB_TOKEN环境变量
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
llm-reviewer- 副驾驶配置文件 (由编辑器扩展创建)
- ~/.config/github-copilot/hosts.json - ~/.config/github-copilot/apps.json
- GitHub命令行界面(
gh)
gh auth login
llm-reviewer该工具会自动将您的OAuth令牌交换为会话令牌,并为后续请求缓存它。
注: 仅Copilot提供者需要GitHub令牌身份验证。Ollama不需要授权。自定义提供程序使用自己的身份验证(请参阅 自定义提供商).
设置身份验证
选项1:GitHub CLI(推荐)
gh auth login选项2:环境变量
# Get a token from https://github.com/settings/tokens
# Scopes required: read:user, copilot
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"选项3:使用副驾驶扩展
在VS Code、Neovim或JetBrains中登录GitHub Copilot。该工具将使用缓存的令牌。
发展
# Clone the repository
git clone https://github.com/asheshv/llm-reviewer.git
cd llm-reviewer
# Install dependencies
npm install
# Run tests
npm test
# Build the project
npm run build
# Run the CLI locally
node dist/cli.js --help
# Or link globally for testing
npm link
llm-reviewer --help项目结构
llm-reviewer/
├── src/
│ ├── cli.ts # CLI entry point
│ ├── mcp-server.ts # MCP server entry point
│ └── lib/
│ ├── providers/ # Provider abstraction layer
│ │ ├── types.ts # ReviewProvider interface
│ │ ├── openai-chat-provider.ts # Shared OpenAI-compatible base
│ │ ├── copilot-provider.ts # GitHub Copilot provider
│ │ ├── ollama-provider.ts # Ollama local provider
│ │ ├── custom-provider.ts # OpenAI-compatible custom provider
│ │ └── index.ts # Provider factory
│ ├── auth.ts # Token resolution + session exchange
│ ├── chunking.ts # Diff splitting + bin-packing
│ ├── config.ts # Multi-layer config loading
│ ├── diff.ts # Git diff collection (7 modes)
│ ├── formatter.ts # Output formatting (text/markdown/json)
│ ├── prompt.ts # Prompt assembly + file manifests
│ ├── review.ts # Review orchestration + map-reduce chunking
│ ├── streaming.ts # SSE parser
│ ├── truncation.ts # Severity-aware truncation for reduce pass
│ ├── types.ts # Shared type definitions
│ └── index.ts # Public API exports
├── test/ # Tests (vitest + msw)
├── prompts/
│ └── default-review.md # Built-in review prompt
├── skills/
│ └── SKILL.md # Claude Code skill definition
├── docs/
│ ├── spec/ # Design specifications
│ ├── adr/ # Architecture decision records
│ ├── plans/ # Implementation plans
│ └── reference/ # API documentation
└── .llm-reviewer/ # Project-level config (dogfooding)
├── config.json
└── config.md许可证
MIT许可证。看 许可证 了解详情。
______________________________________________________________________
问题或议题? 打开一个问题 .
