best-review 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +611 -0
  2. package/dist/best-review.cjs +664 -0
  3. package/dist/defaults/agents/EXAMPLE.md.template +31 -0
  4. package/dist/defaults/agents/bug-hunter.md +35 -0
  5. package/dist/defaults/agents/consistency-check.md +33 -0
  6. package/dist/defaults/agents/general.md +36 -0
  7. package/dist/defaults/agents/performance-check.md +34 -0
  8. package/dist/defaults/agents/security-scan.md +35 -0
  9. package/dist/defaults/agents/validation.md +35 -0
  10. package/dist/defaults/prompts/output-format.md +37 -0
  11. package/dist/defaults/prompts/output-format.test.ts +15 -0
  12. package/dist/defaults/prompts/validation-instructions.md +116 -0
  13. package/dist/defaults/prompts/validation.md +178 -0
  14. package/dist/defaults/rules/EXAMPLE.md.template +32 -0
  15. package/dist/defaults/rules/code-bugs.md +45 -0
  16. package/dist/defaults/rules/code-consistency.md +100 -0
  17. package/dist/defaults/rules/code-general.md +59 -0
  18. package/dist/defaults/rules/code-performance.md +44 -0
  19. package/dist/defaults/rules/code-security.md +39 -0
  20. package/dist/defaults/rules/config-security.md +31 -0
  21. package/package.json +91 -0
  22. package/src/defaults/agents/EXAMPLE.md.template +31 -0
  23. package/src/defaults/agents/bug-hunter.md +35 -0
  24. package/src/defaults/agents/consistency-check.md +33 -0
  25. package/src/defaults/agents/general.md +36 -0
  26. package/src/defaults/agents/performance-check.md +34 -0
  27. package/src/defaults/agents/security-scan.md +35 -0
  28. package/src/defaults/agents/validation.md +35 -0
  29. package/src/defaults/prompts/output-format.md +37 -0
  30. package/src/defaults/prompts/output-format.test.ts +15 -0
  31. package/src/defaults/prompts/validation-instructions.md +116 -0
  32. package/src/defaults/prompts/validation.md +178 -0
  33. package/src/defaults/rules/EXAMPLE.md.template +32 -0
  34. package/src/defaults/rules/code-bugs.md +45 -0
  35. package/src/defaults/rules/code-consistency.md +100 -0
  36. package/src/defaults/rules/code-general.md +59 -0
  37. package/src/defaults/rules/code-performance.md +44 -0
  38. package/src/defaults/rules/code-security.md +39 -0
  39. package/src/defaults/rules/config-security.md +31 -0
package/README.md ADDED
@@ -0,0 +1,611 @@
1
+ # best-review
2
+
3
+ `best-review` 是一个本地多 Agent 代码审查 CLI。它读取 Git diff,匹配规则,调度多个审查 Agent,直接调用 OpenAI Chat Completions 兼容模型服务或 DeepSeek API,最后输出风险结论、质量评分、CI 门禁结果和可落盘/上报的审查报告。
4
+
5
+ 这个项目的重点不是替代人工 Review,而是把可重复的风险检查前置到本地、CI 和 GitLab Merge Request 流程里:
6
+
7
+ - 本地审查未提交变更、提交范围、指定文件或完整文件内容。
8
+ - GitLab MR 远程审查,并把问题回评到 MR 行内 discussion。
9
+ - 内置 `general`、`bug-hunter`、`security-scan`、`performance-check`、`consistency-check`、`validation` Agent。
10
+ - 支持项目规则、全局规则、共享 `extends` 规则包和项目级 `skills/` 审查增强。
11
+ - 默认执行置信度过滤、去重、validation 复核,减少泛泛建议和误报。
12
+ - 支持显式自动修复严重风险,先生成 unified diff,并通过 `git apply --check` 后才写入。
13
+ - 生成本地 JSON 报告,可选上报到内部效能统计系统。
14
+
15
+ ## 快速开始
16
+
17
+ ### 运行要求
18
+
19
+ - Node.js 18+
20
+ - npm
21
+ - Git 仓库
22
+ - 可用模型服务:
23
+ - DeepSeek API
24
+ - OpenAI Chat Completions 兼容 API
25
+
26
+ ### 安装和初始化
27
+
28
+ ```bash
29
+ npm install -g best-review
30
+
31
+ best-review init
32
+ best-review review
33
+ ```
34
+
35
+ `best-review review` 默认审查未提交变更;如果工作区没有变更,会回退审查最近一次提交。
36
+
37
+ 如果使用 OpenAI 兼容服务:
38
+
39
+ ```bash
40
+ best-review init --provider openai
41
+ best-review review
42
+ ```
43
+
44
+ `best-review init` 会以选项式流程写入用户级 `~/.best-review/config.json`。`.best-review.json` 已弃用,CLI 不再生成或默认读取它。
45
+
46
+ ## 常用命令
47
+
48
+ ```bash
49
+ # 审查未提交变更;工作区干净时审查最近一次提交
50
+ best-review review
51
+
52
+ # 审查 HEAD 相对 main 的变更
53
+ best-review review --base main
54
+
55
+ # 审查指定分支相对默认分支的变更;"." 表示当前分支
56
+ best-review review --branch .
57
+ best-review review --branch feature/login --base main
58
+
59
+ # 只审查指定文件的 Git 变更
60
+ best-review review --files src/auth.ts
61
+ best-review review --files src/auth.ts,src/user.ts --base main
62
+
63
+ # 审查完整文件内容,不依赖 Git diff
64
+ best-review review --files src/auth.ts --full
65
+
66
+ # 临时忽略目录或文件
67
+ best-review review --ignore dist,coverage/**,fixtures/**
68
+
69
+ # 控制 Agent、规则、严重级别和置信度
70
+ best-review review --agent security-scan
71
+ best-review review --exclude-agent performance-check
72
+ best-review review --rule code-security,config-security
73
+ best-review review --severity critical,high
74
+ best-review review --confidence 80
75
+
76
+ # 覆盖执行器或模型
77
+ best-review review --executor deepseek-api --model deepseek-v4-flash
78
+ best-review review --executor openai-compatible-api --model gpt-4o-mini
79
+
80
+ # 输出 JSON,适合 CI
81
+ best-review review --base main --json
82
+
83
+ # 检查当前配置是否可以直接 review
84
+ best-review config
85
+ best-review doctor
86
+
87
+ # 展示每个 pipeline 阶段耗时
88
+ best-review review --log-steps
89
+
90
+ # 显式自动修复严重风险
91
+ best-review review --fix-critical
92
+ best-review review --fix-severity critical,high --fix-dry-run
93
+ best-review review --fix-critical --fix-max-issues 3 --fix-patch-file .best-review/fix.patch
94
+
95
+ # GitLab MR 远程审查
96
+ GITLAB_TOKEN=<token> best-review review-mr https://gitlab.example.com/group/project/-/merge_requests/123
97
+
98
+ # 查看内置资产和执行器
99
+ best-review agents
100
+ best-review rules
101
+ best-review executors
102
+
103
+ # 运行 golden fixture 质量评测
104
+ best-review eval
105
+ best-review eval evals/golden --min-recall 0.9 --min-precision 0.75 --max-duplicate-rate 0.25
106
+ ```
107
+
108
+ `package.json` 同时暴露 `br` 别名;本地已 link 后可用 `br review`。
109
+
110
+ ## 模型服务
111
+
112
+ 内置执行器只有两个:
113
+
114
+ | executor | 用途 |
115
+ | --- | --- |
116
+ | `deepseek-api` | DeepSeek Chat Completions API,默认执行器 |
117
+ | `openai-compatible-api` | OpenAI Chat Completions 兼容服务 |
118
+
119
+ 运行时模型配置统一来自用户级 `~/.best-review/config.json` 的 `llm` 字段;`.env` / 环境变量仅作为旧配置兼容回退:
120
+
121
+ | 字段 | 说明 |
122
+ | --- | --- |
123
+ | `llm.platform` | `deepseek` 或 `openai`;未设置时默认 `deepseek` |
124
+ | `llm.baseUrl` | 模型服务 base URL;未设置时使用平台默认值 |
125
+ | `llm.apiKey` | 模型服务密钥,必填 |
126
+ | `llm.model` | 模型名称;DeepSeek 默认 `deepseek-v4-flash`,OpenAI 默认 `gpt-4o-mini` |
127
+
128
+ 默认情况下,review 和 validation 使用同一个 `llm.model`。如果希望 validation 单独使用更强模型,需要在用户级配置里显式配置阶段级 `model`。模型优先级为:
129
+
130
+ ```text
131
+ CLI --model > workflow run model > executors.<executor>.<stage>.model > llm.model > MODEL 环境变量 > 平台默认模型
132
+ ```
133
+
134
+ 审查和验证都会请求:
135
+
136
+ ```text
137
+ POST <llm.baseUrl>/chat/completions
138
+ ```
139
+
140
+ 执行器期望模型按 prompt 输出可解析的 `<json>...</json>` 结果。`best-review review` 和 `best-review review-mr` 会在真正审查前先检查执行器、API Key、模型配置,并发起一次轻量 Chat Completions 联通校验;失败会直接退出并给出修复建议。
141
+
142
+ 旧配置中的 `opencode-cli` 会在加载时归一化为当前默认模型 API 执行器。新配置和命令行参数应使用 `deepseek-api` 或 `openai-compatible-api`。
143
+
144
+ ## 配置
145
+
146
+ 配置文件位于用户根目录下的 `~/.best-review/config.json`。`best-review init` 会写入模型服务配置和基础执行器配置:
147
+
148
+ ```json
149
+ {
150
+ "executor": "deepseek-api",
151
+ "llm": {
152
+ "platform": "deepseek",
153
+ "baseUrl": "https://api.deepseek.com",
154
+ "apiKey": "<your-api-key>",
155
+ "model": "deepseek-v4-flash"
156
+ },
157
+ "executors": {
158
+ "openai-compatible-api": {
159
+ "review": { "concurrency": 2 },
160
+ "validation": { "timeout": 1800, "batchSize": 10, "concurrency": 1 }
161
+ },
162
+ "deepseek-api": {
163
+ "review": { "concurrency": 2 },
164
+ "validation": { "timeout": 1800, "batchSize": 10, "concurrency": 1 }
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ 配置优先级:
171
+
172
+ ```text
173
+ 默认值 < ~/.best-review/config.json < CLI 参数
174
+ ```
175
+
176
+ 可配置项包括:
177
+
178
+ ```json
179
+ {
180
+ "extends": ["https://github.com/org/best-review-rules.git#v1.0.0"],
181
+ "excludePatterns": ["dist/**", "coverage/**", "docs/**", "*.md"],
182
+ "concurrency": 2,
183
+ "executor": "deepseek-api",
184
+ "llm": {
185
+ "platform": "deepseek",
186
+ "baseUrl": "https://api.deepseek.com",
187
+ "apiKey": "<your-api-key>",
188
+ "model": "deepseek-v4-flash"
189
+ },
190
+ "executors": {
191
+ "deepseek-api": {
192
+ "review": { "concurrency": 2 },
193
+ "validation": {
194
+ "timeout": 1800,
195
+ "batchSize": 10,
196
+ "concurrency": 1
197
+ }
198
+ }
199
+ },
200
+ "agents": {
201
+ "security-scan": { "enabled": true, "timeout": 1800 }
202
+ },
203
+ "rules": {
204
+ "code-security": { "enabled": true, "agent": "security-scan" }
205
+ },
206
+ "skills": {
207
+ "domain-review": { "enabled": true }
208
+ },
209
+ "reporting": {
210
+ "localDir": ".best-review/reports",
211
+ "enabled": false,
212
+ "includeDiffs": false,
213
+ "failOnError": false
214
+ },
215
+ "qualityScore": {
216
+ "base": 100,
217
+ "min": 0,
218
+ "weights": {
219
+ "critical": 40,
220
+ "high": 15,
221
+ "medium": 6,
222
+ "low": 2
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ 可选:让 validation 使用更强模型时,只在配置里添加阶段级 `model`:
229
+
230
+ ```json
231
+ {
232
+ "executors": {
233
+ "deepseek-api": {
234
+ "review": { "model": "<cheap-review-model>", "concurrency": 2 },
235
+ "validation": { "model": "<strong-validation-model>", "timeout": 1800 }
236
+ }
237
+ }
238
+ }
239
+ ```
240
+
241
+ `workflows` 只允许配置模型,不允许在 workflow 条目里配置 executor:
242
+
243
+ ```json
244
+ {
245
+ "workflows": {
246
+ "review": [{ "model": "gpt-4o-mini" }, { "model": "deepseek-v4-flash" }],
247
+ "validation": [{ "model": "gpt-4o-mini" }]
248
+ }
249
+ }
250
+ ```
251
+
252
+ 相关命令:
253
+
254
+ ```bash
255
+ best-review config
256
+ best-review init
257
+ best-review config show
258
+ best-review config edit
259
+ best-review doctor
260
+ ```
261
+
262
+ `best-review init` 用来初始化或更新 `~/.best-review/config.json`;`best-review config` 会用当前用户级配置做一次简化诊断;`best-review doctor` 输出同一套诊断结果,适合在本地或 CI 中确认当前机器是否可以直接执行 review。
263
+
264
+ ## 审查流程
265
+
266
+ 默认 pipeline 顺序:
267
+
268
+ ```mermaid
269
+ flowchart LR
270
+ A["Git diff / MR diff"] --> B["load-rules"]
271
+ B --> C["match-rules"]
272
+ C --> D["review"]
273
+ D --> E["aggregate-results"]
274
+ E --> F["confidence-filter"]
275
+ F --> G["deduplication"]
276
+ G --> H["validation"]
277
+ H --> I["gitlab-mr-issue-filter"]
278
+ I --> J["autofix"]
279
+ J --> K["reporting"]
280
+ K --> L["gitlab-reporting"]
281
+ ```
282
+
283
+ 关键行为:
284
+
285
+ - `filterReviewableDiffs()` 默认跳过二进制、生成物、文档和命中排除规则的文件。
286
+ - 本地 review 会补充变更文件全文和一层相对依赖上下文,避免模型只看 diff。
287
+ - diff 输入默认压缩,只保留 hunk 行号、变更行和少量上下文。
288
+ - 默认是多 Agent 独立审查;设置 `BEST_REVIEW_MULTI_AGENT=false` 可把多个专业 Agent 合并成一次快速审查。
289
+ - `confidence-filter` 默认按最小置信度 70 过滤低质量问题,可用 `--confidence` 调整。
290
+ - `validation` Agent 会复核候选问题并过滤误报;`--skip-validation` 会跳过该阶段。
291
+ - 自动修复必须显式开启,并且不能和 `--skip-validation` 同时使用。
292
+ - `reporting` 会尽量执行,把当前上下文保存为本地 JSON 报告。
293
+
294
+ ## Agent、规则和 Skill
295
+
296
+ 内置 Agent:
297
+
298
+ | Agent | 关注点 |
299
+ | --- | --- |
300
+ | `general` | 通用质量、可读性、职责边界和可维护性 |
301
+ | `bug-hunter` | 逻辑错误、边界条件、异常路径和运行时风险 |
302
+ | `security-scan` | 认证授权、敏感信息、注入、越权和真实攻击路径 |
303
+ | `performance-check` | 复杂度、重复调用、资源使用和真实规模下的性能退化 |
304
+ | `consistency-check` | 命名、返回形态、接口约定和架构模式一致性 |
305
+ | `validation` | 复核其他 Agent 的发现,过滤误报 |
306
+
307
+ 默认规则在 `src/defaults/rules/`,可审查 TypeScript、JavaScript、Python、Go、Rust、Java、Ruby、PHP、Kotlin、Shell、C/C++ 以及常见配置文件。
308
+
309
+ 自定义规则可以放在:
310
+
311
+ ```text
312
+ .best-review/rules/*.md
313
+ ~/.best-review/rules/*.md
314
+ ```
315
+
316
+ 规则示例:
317
+
318
+ ```markdown
319
+ ---
320
+ name: input-validation
321
+ description: 所有用户输入必须使用 schema 校验
322
+ version: 1
323
+ patterns:
324
+ - "src/**/*.ts"
325
+ agent: security-scan
326
+ ---
327
+
328
+ 发现新增入口参数、请求体、环境变量读取时,检查是否有集中 schema 校验。
329
+ 只报告有实际风险的缺失校验,不报告已经被上游可靠校验的代码。
330
+ ```
331
+
332
+ 自定义 Agent 可以放在:
333
+
334
+ ```text
335
+ .best-review/agents/*.md
336
+ ~/.best-review/agents/*.md
337
+ ```
338
+
339
+ 规则和 Agent 加载优先级:
340
+
341
+ ```text
342
+ defaults < extends < user < project
343
+ ```
344
+
345
+ 共享规则包:
346
+
347
+ ```bash
348
+ best-review extends install https://github.com/org/best-review-rules.git
349
+ best-review extends install --force
350
+ best-review extends list
351
+ best-review extends remove https://github.com/org/best-review-rules.git
352
+ ```
353
+
354
+ 项目级 Skill 放在 `skills/<skill-name>/SKILL.md`,可选附带 `references/*.md` 和 `agents/agent.yaml`。启用后会被注入 review prompt,适合放业务域约束、框架约定或团队审查标准。
355
+
356
+ ## GitLab Merge Request
357
+
358
+ `review-mr` 会直接读取 GitLab MR diff 和远程文件内容,运行同一套 pipeline,并默认启用 GitLab Reporting。
359
+
360
+ ```bash
361
+ export GITLAB_TOKEN=<token>
362
+
363
+ best-review review-mr https://gitlab.example.com/group/project/-/merge_requests/123
364
+ best-review review-mr <mr-url> --agent security-scan --log-steps
365
+ best-review review-mr <mr-url> --executor deepseek-api --model deepseek-v4-flash
366
+ ```
367
+
368
+ 可选变量:
369
+
370
+ | 变量 | 说明 |
371
+ | --- | --- |
372
+ | `GITLAB_TOKEN` | 读取 MR 和发布 discussion 的 token |
373
+ | `GITLAB_HOST` | GitLab API host 覆盖值;可传 `https://gitlab.example.com` 或完整 `/api/v4` |
374
+ | `BEST_REVIEW_GITLAB_ENABLED` | 本地 `review` 模式下设置为 `true` 时启用 GitLab Reporting |
375
+ | `GITLAB_PROJECT_ID` / `CI_PROJECT_ID` | 非 `review-mr` 模式下用于定位项目 |
376
+ | `GITLAB_MR_IID` / `CI_MERGE_REQUEST_IID` | 非 `review-mr` 模式下用于定位 MR |
377
+
378
+ GitLab Reporting 会优先发布行内 discussion;无法映射到 diff position 的问题会汇总到 summary discussion。`review-mr` 模式下会清理旧的 best-review comment marker,避免重复刷屏。
379
+
380
+ ## 自动修复
381
+
382
+ 自动修复默认关闭,必须显式开启:
383
+
384
+ ```bash
385
+ # 只修复 critical
386
+ best-review review --fix-critical
387
+
388
+ # 修复 critical/high,但只校验补丁,不写入文件
389
+ best-review review --fix-severity critical,high --fix-dry-run
390
+
391
+ # 限制修复数量,并保存补丁
392
+ best-review review --fix-critical --fix-max-issues 3 --fix-patch-file .best-review/fix.patch
393
+ ```
394
+
395
+ 安全约束:
396
+
397
+ - 只在 validation 之后运行。
398
+ - 拒绝 `--skip-validation`。
399
+ - 只读取目标问题涉及的文件。
400
+ - 只接受 unified diff。
401
+ - 拒绝二进制、新增、删除、重命名、复制文件变更。
402
+ - 补丁只能修改目标问题涉及文件。
403
+ - 先执行 `git apply --check`,通过后才写入文件。
404
+ - `--fix-dry-run` 只生成并校验补丁,不写入源码。
405
+
406
+ 可调变量:
407
+
408
+ ```bash
409
+ BEST_REVIEW_FIX_MAX_ISSUES=5
410
+ BEST_REVIEW_FIX_MAX_FILE_CHARS=60000
411
+ ```
412
+
413
+ ## 输出、质量评分和 CI
414
+
415
+ 终端输出会包含:
416
+
417
+ - pipeline 是否成功。
418
+ - Agent 成功/失败数量。
419
+ - 模型调用次数、缓存命中次数、token 用量和缓存节省估算。
420
+ - 风险结论。
421
+ - 原始问题数、置信度过滤后、validation 后、最终计分问题数。
422
+ - 质量评分。
423
+ - 按文件分组的问题详情。
424
+
425
+ 风险枚举:
426
+
427
+ | 内部 severity | 终端标签 |
428
+ | --- | --- |
429
+ | `critical` | 严重风险 |
430
+ | `high` | 高风险 |
431
+ | `medium` | 中风险 |
432
+ | `low` | 低风险 |
433
+
434
+ 示例风险结论:
435
+
436
+ ```text
437
+ 风险结论:严重 1,高 2,中 0,低 3;整体风险:严重
438
+ ```
439
+
440
+ JSON 输出包含:
441
+
442
+ - `stats`
443
+ - `riskSummary`
444
+ - `qualityScore`
445
+ - `reviewSummary`
446
+ - `rawIssues`
447
+ - `finalIssues`
448
+ - `issues`
449
+ - `files`
450
+ - `autofix`
451
+ - `usage`
452
+
453
+ CI 建议:
454
+
455
+ ```bash
456
+ best-review review --base origin/main --json
457
+ ```
458
+
459
+ 当 pipeline 失败或最终存在 `critical` 问题时,CLI 会返回非 0 exit code。`high`、`medium`、`low` 默认不阻断,可由 CI 根据 JSON 自定义策略。
460
+
461
+ ## Reporting
462
+
463
+ 每次 review 都会尽量生成本地报告,默认目录:
464
+
465
+ ```text
466
+ .best-review/reports/
467
+ ```
468
+
469
+ 报告包含仓库信息、base/head、模型、Agent 结果、阶段结果、风险结论、质量评分、issue audit trail、最终问题和 diff 摘要。默认不保存完整 diff。
470
+
471
+ 配置上报:
472
+
473
+ ```json
474
+ {
475
+ "reporting": {
476
+ "localDir": ".best-review/reports",
477
+ "enabled": true,
478
+ "url": "https://efficiency.example.com/api/ai-review/usages",
479
+ "token": "replace-with-token",
480
+ "includeDiffs": false,
481
+ "failOnError": false
482
+ }
483
+ }
484
+ ```
485
+
486
+ 环境变量覆盖:
487
+
488
+ ```bash
489
+ BEST_REVIEW_REPORT_DIR=.best-review/reports
490
+ BEST_REVIEW_REPORT_URL=https://efficiency.example.com/api/ai-review/usages
491
+ BEST_REVIEW_REPORT_TOKEN=replace-with-token
492
+ BEST_REVIEW_REPORT_INCLUDE_DIFFS=false
493
+ BEST_REVIEW_REPORT_FAIL_ON_ERROR=false
494
+ ```
495
+
496
+ 上报失败默认不阻断 review;如果 CI 要求上报失败即失败,设置 `failOnError: true` 或 `BEST_REVIEW_REPORT_FAIL_ON_ERROR=true`。
497
+
498
+ ## 审查质量评测
499
+
500
+ `best-review eval` 会实时调用当前模型跑 golden fixtures,流程包含 review、confidence filter、deduplication 和 validation,用于评估 prompt、规则或模型变更是否造成质量回归。
501
+
502
+ ```bash
503
+ best-review eval
504
+ best-review eval evals/golden --json
505
+ best-review eval --model gpt-4o-mini --min-recall 0.9 --min-precision 0.75 --max-duplicate-rate 0.25
506
+ best-review eval --use-cache
507
+ ```
508
+
509
+ fixture 支持:
510
+
511
+ - `diffs`:输入 Git diff。
512
+ - `supplementalContextFiles`:可选补充上下文。
513
+ - `expectedIssues`:最终应该保留的问题。
514
+ - `expectedFilteredIssues`:如果模型产出,应该被过滤的问题。
515
+ - `thresholds`:单 fixture 门禁。
516
+
517
+ 主要指标:
518
+
519
+ - `precision`、`recall`、`f1`
520
+ - `falsePositives`、`falseNegatives`
521
+ - `severityMismatches`
522
+ - `rawDuplicateRate`
523
+ - `validationRetentionRate`
524
+ - `reviewCoverageRate`
525
+ - `expectedFilteredObserved`、`expectedFilteredLeaked`
526
+
527
+ 默认 eval 禁用 review/validation 缓存;调试成本时可用 `--use-cache`。
528
+
529
+ ## 性能和成本控制
530
+
531
+ ```bash
532
+ # 关闭缓存
533
+ BEST_REVIEW_CACHE=false best-review review
534
+
535
+ # 兼容旧变量:关闭缓存
536
+ BEST_REVIEW_DISABLE_CACHE=true best-review review
537
+
538
+ # 调整 batch token 和文件数量
539
+ BEST_REVIEW_BATCH_TOKENS=36000 best-review review
540
+ BEST_REVIEW_MAX_FILES_PER_BATCH=20 best-review review
541
+
542
+ # 使用完整 diff,不做压缩
543
+ BEST_REVIEW_FULL_DIFF=true best-review review
544
+
545
+ # 调整 diff 压缩上下文和单文件输入上限
546
+ BEST_REVIEW_DIFF_CONTEXT_LINES=2 best-review review
547
+ BEST_REVIEW_MAX_DIFF_CHARS_PER_FILE=30000 best-review review
548
+
549
+ # 合并多个专业 Agent 为一次快速审查
550
+ BEST_REVIEW_MULTI_AGENT=false best-review review
551
+
552
+ # 关闭智能规则路由
553
+ BEST_REVIEW_DISABLE_SMART_ROUTING=true best-review review
554
+ ```
555
+
556
+ 默认缓存目录:
557
+
558
+ ```text
559
+ .best-review/cache/review
560
+ .best-review/cache/validation
561
+ ```
562
+
563
+ 缓存 key 包含模型、base URL、temperature、prompt、规则和 diff 输入。相同输入会复用成功结果,并在终端/JSON 中统计缓存命中和节省 token。
564
+
565
+ ## 开发
566
+
567
+ ```bash
568
+ npm install
569
+
570
+ # 直接运行 TypeScript CLI
571
+ npm run dev -- review --base main
572
+
573
+ # 类型检查、测试、构建
574
+ npm run ts-check
575
+ npm test
576
+ npm run build
577
+
578
+ # lint 和格式化
579
+ npm run lint
580
+ npm run format:check
581
+
582
+ # 本地 link 后用全局命令调试
583
+ npm run link:local
584
+ best-review review --base main
585
+ ```
586
+
587
+ 常用源码入口:
588
+
589
+ | 路径 | 作用 |
590
+ | --- | --- |
591
+ | `src/cli/` | CLI 命令、参数校验、review/review-mr runner |
592
+ | `src/config/` | 默认配置、用户级配置、旧配置归一化 |
593
+ | `src/providers/` | 模型运行时配置解析 |
594
+ | `src/executors/` | OpenAI-compatible 和 DeepSeek API 执行器 |
595
+ | `src/stages/` | pipeline 各阶段 |
596
+ | `src/review/` | issue 解析、格式化、缓存、评分、用量统计 |
597
+ | `src/git/` | 本地 diff、文件过滤、补充上下文 |
598
+ | `src/gitlab/` | GitLab MR 数据读取 |
599
+ | `src/defaults/agents/` | 内置 Agent prompt |
600
+ | `src/defaults/rules/` | 内置规则 |
601
+ | `src/eval/` | golden fixture 评测 |
602
+
603
+ 更多设计说明:
604
+
605
+ - [架构说明](docs/ARCHITECTURE.md)
606
+ - [执行流程图](docs/EXECUTION_FLOW.md)
607
+ - [AI 代码评审工具建设方案](docs/AI_REVIEW_TOOL_README.md)
608
+
609
+ ## License
610
+
611
+ MIT