smart-review 1.0.4 → 1.2.0
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.
- package/README.en-US.md +66 -6
- package/README.md +70 -14
- package/lib/ai-client-pool.js +1 -0
- package/lib/ai-client.js +1053 -74
- package/lib/default-config.js +10 -2
- package/lib/reviewer.js +25 -13
- package/lib/utils/i18n.js +68 -4
- package/package.json +29 -4
- package/templates/smart-review.json +10 -2
- package/templates/rules/best-practices.js +0 -111
- package/templates/rules/performance.js +0 -123
- package/templates/rules/security.js +0 -311
package/README.en-US.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
## ✨ Features
|
|
8
8
|
|
|
9
9
|
- Static rule checks for Security, Performance, Best Practices
|
|
10
|
-
- AI analysis
|
|
10
|
+
- AI analysis with unified OpenAI / Anthropic / Gemini integration
|
|
11
|
+
- Skill-driven review orchestration to enforce detailed risk and fix outputs
|
|
11
12
|
- Smart batching and chunked processing for large files
|
|
12
13
|
- Git Hook integration (pre-commit)
|
|
13
14
|
- Highly configurable and multilingual output
|
|
@@ -128,6 +129,7 @@ Add to `package.json` if you use Husky:
|
|
|
128
129
|
- Works in Git Bash, CMD, and PowerShell
|
|
129
130
|
- Press `q` or `Esc` during review to interrupt and print completed results
|
|
130
131
|
- Interruptions do not fail the review; only blocking risks stop the commit
|
|
132
|
+
|
|
131
133
|
## ⚙️ Config
|
|
132
134
|
|
|
133
135
|
Main config `.smart-review/smart-review.json` example:
|
|
@@ -136,6 +138,7 @@ Main config `.smart-review/smart-review.json` example:
|
|
|
136
138
|
{
|
|
137
139
|
"ai": {
|
|
138
140
|
"enabled": true,
|
|
141
|
+
"provider": "openai",
|
|
139
142
|
"model": "deepseek-chat",
|
|
140
143
|
"baseURL": "https://api.deepseek.com/v1",
|
|
141
144
|
"reviewOnlyChanges": true,
|
|
@@ -145,6 +148,37 @@ Main config `.smart-review/smart-review.json` example:
|
|
|
145
148
|
"useStaticHints": true,
|
|
146
149
|
"maxRequestTokens": 8000,
|
|
147
150
|
"temperature": 0,
|
|
151
|
+
"skills": {
|
|
152
|
+
"enabled": true,
|
|
153
|
+
"strict": false,
|
|
154
|
+
"maxSkillsPerRequest": 4,
|
|
155
|
+
"required": ["DIFF_RISK_GUARD", "EVIDENCE_ENFORCER"],
|
|
156
|
+
"optional": ["SECURITY_DEEP", "LOGIC_CORRECTNESS", "API_CONTRACT"],
|
|
157
|
+
"routes": [
|
|
158
|
+
{
|
|
159
|
+
"match": ["**/auth/**", "**/security/**"],
|
|
160
|
+
"modes": ["diff", "batch", "segment"],
|
|
161
|
+
"add": ["SECURITY_DEEP", "API_CONTRACT"]
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
"tools": {
|
|
166
|
+
"enabled": false,
|
|
167
|
+
"maxCalls": 2,
|
|
168
|
+
"maxReadLines": 400,
|
|
169
|
+
"maxSearchMatches": 50,
|
|
170
|
+
"maxSearchFiles": 120,
|
|
171
|
+
"maxListFiles": 200,
|
|
172
|
+
"allow": [
|
|
173
|
+
"read_file",
|
|
174
|
+
"get_staged_diff",
|
|
175
|
+
"list_files",
|
|
176
|
+
"search_in_file",
|
|
177
|
+
"get_file_outline",
|
|
178
|
+
"search_in_repo",
|
|
179
|
+
"list_changed_files"
|
|
180
|
+
]
|
|
181
|
+
},
|
|
148
182
|
"concurrency": 3
|
|
149
183
|
},
|
|
150
184
|
"riskLevels": {
|
|
@@ -162,8 +196,9 @@ Main config `.smart-review/smart-review.json` example:
|
|
|
162
196
|
|
|
163
197
|
#### AI (`ai`)
|
|
164
198
|
- `enabled`: Enable AI analysis
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
199
|
+
- `provider`: Model provider, supports `openai`, `anthropic`, `gemini`
|
|
200
|
+
- `model`: Model name for the selected provider
|
|
201
|
+
- `apiKey`: Unified API key field (or use environment variables)
|
|
167
202
|
- `baseURL`: API base URL
|
|
168
203
|
- `reviewOnlyChanges`: Enable Git Diff incremental review; true analyzes only changed lines
|
|
169
204
|
- `maxResponseTokens`: Max tokens in AI response
|
|
@@ -177,7 +212,28 @@ Main config `.smart-review/smart-review.json` example:
|
|
|
177
212
|
- `includeStaticHints`: Include rule hints in AI analysis
|
|
178
213
|
- `temperature`: Model creativity; 0 favors deterministic outputs
|
|
179
214
|
- `concurrency`: Number of concurrent AI requests
|
|
180
|
-
|
|
215
|
+
- `skills.enabled`: Enable review skill orchestration
|
|
216
|
+
- `skills.strict`: Enforce output constraints (path/snippet/reason/suggestion)
|
|
217
|
+
- `skills.maxSkillsPerRequest`: Max skills applied in one request
|
|
218
|
+
- `skills.required`: Required skill list
|
|
219
|
+
- `skills.optional`: Optional skill list (mode-based supplement)
|
|
220
|
+
- `skills.routes`: Dynamically append skills by file path and mode (`match/modes/add`)
|
|
221
|
+
- `tools.enabled`: Enable local read-only tool calling (see tool list below)
|
|
222
|
+
- `tools.maxCalls`: Max tool-call rounds per request
|
|
223
|
+
- `tools.maxReadLines`: Max lines for single `read_file` call
|
|
224
|
+
- `tools.maxSearchMatches`: Max returned matches for `search_in_file` / `search_in_repo`
|
|
225
|
+
- `tools.maxSearchFiles`: Max scanned files for one `search_in_repo` call
|
|
226
|
+
- `tools.maxListFiles`: Max returned files for one `list_files` call
|
|
227
|
+
- `tools.allow`: Tool allowlist (only listed tools can be called by the model)
|
|
228
|
+
|
|
229
|
+
#### AI Read-Only Tool List (`ai.tools.allow`)
|
|
230
|
+
- `read_file`: Read specific line ranges from one file
|
|
231
|
+
- `get_staged_diff`: Get staged Git diff (optionally filtered by path)
|
|
232
|
+
- `list_files`: Recursively list repository files (supports subdir and keyword/wildcard filtering)
|
|
233
|
+
- `search_in_file`: Search text or regex in a single file
|
|
234
|
+
- `get_file_outline`: Extract lightweight file outline (class/function/method signatures)
|
|
235
|
+
- `search_in_repo`: Search text or regex across repository files (with scan and result caps)
|
|
236
|
+
- `list_changed_files`: List changed Git files (supports staged/unstaged and status filtering)
|
|
181
237
|
#### Risk Levels (`riskLevels`)
|
|
182
238
|
- `critical` / `high` / `medium` / `low` / `suggestion`
|
|
183
239
|
- Each level supports `block` to decide whether to block commits
|
|
@@ -534,7 +590,11 @@ To add a new language (e.g., `ja-JP`), create `templates/rules/ja-JP/` with the
|
|
|
534
590
|
## 🌍 Environment Variables
|
|
535
591
|
|
|
536
592
|
```bash
|
|
593
|
+
export AI_API_KEY="your-api-key"
|
|
537
594
|
export OPENAI_API_KEY="your-api-key"
|
|
595
|
+
export ANTHROPIC_API_KEY="your-api-key"
|
|
596
|
+
export GEMINI_API_KEY="your-api-key"
|
|
597
|
+
export GOOGLE_API_KEY="your-api-key"
|
|
538
598
|
export DEBUG_SMART_REVIEW=true
|
|
539
599
|
export SMART_REVIEW_LOCALE=en-US
|
|
540
600
|
```
|
|
@@ -543,7 +603,7 @@ To use a custom OpenAI-compatible endpoint, set `ai.baseURL` in `.smart-review/s
|
|
|
543
603
|
|
|
544
604
|
```json
|
|
545
605
|
{
|
|
546
|
-
"ai": { "baseURL": "https://api.openai.com/v1" }
|
|
606
|
+
"ai": { "provider": "openai", "baseURL": "https://api.openai.com/v1" }
|
|
547
607
|
}
|
|
548
608
|
```
|
|
549
609
|
|
|
@@ -581,4 +641,4 @@ smart-review --staged --debug
|
|
|
581
641
|
4. Push the branch (`git push origin feature/amazing-feature`)
|
|
582
642
|
5. Open a Pull Request
|
|
583
643
|
|
|
584
|
-
⭐ If this project helps you, please star the repo!
|
|
644
|
+
⭐ If this project helps you, please star the repo!
|
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
## ✨ 特性
|
|
8
8
|
|
|
9
9
|
- 🔍 **静态规则检测** - 内置安全、性能、最佳实践规则
|
|
10
|
-
- 🧠 **AI智能分析** -
|
|
10
|
+
- 🧠 **AI智能分析** - 支持 OpenAI / Anthropic / Gemini 的统一对接
|
|
11
|
+
- 🧩 **审查技能编排** - 支持 Skills 约束输出,强制细化风险分析与修复建议
|
|
11
12
|
- ⚡ **Git Diff增量审查** - 智能识别变更内容,只审查修改的代码行,大幅提升审查效率
|
|
12
13
|
- 🚀 **智能分批处理** - 自动优化大文件处理,支持分段分析
|
|
13
14
|
- 📊 **大文件支持** - 智能分段处理超大文件,突破token限制
|
|
@@ -130,10 +131,12 @@ node bin/review.js --files test/src/large-test-file.js
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
```
|
|
134
|
+
|
|
133
135
|
#### 中断与终端兼容
|
|
134
136
|
- 支持在 Git Bash、CMD、PowerShell 中进行交互中断
|
|
135
137
|
- 审查过程中输入 `q` 或按 `Esc` 可中断审查并输出已完成结果
|
|
136
138
|
- 中断不会被视为审查失败,只有存在阻断风险才会阻止提交
|
|
139
|
+
|
|
137
140
|
## ⚙️ 配置文件
|
|
138
141
|
|
|
139
142
|
### 主配置文件 `.smart-review/smart-review.json`
|
|
@@ -142,6 +145,7 @@ node bin/review.js --files test/src/large-test-file.js
|
|
|
142
145
|
{
|
|
143
146
|
"ai": {
|
|
144
147
|
"enabled": true,
|
|
148
|
+
"provider": "openai",
|
|
145
149
|
"model": "deepseek-chat",
|
|
146
150
|
"apiKey": "your-api-key",
|
|
147
151
|
"baseURL": "https://api.deepseek.com/v1",
|
|
@@ -156,6 +160,37 @@ node bin/review.js --files test/src/large-test-file.js
|
|
|
156
160
|
"tokenRatio": 4,
|
|
157
161
|
"chunkOverlapLines": 5,
|
|
158
162
|
"includeStaticHints": true,
|
|
163
|
+
"skills": {
|
|
164
|
+
"enabled": true,
|
|
165
|
+
"strict": false,
|
|
166
|
+
"maxSkillsPerRequest": 4,
|
|
167
|
+
"required": ["DIFF_RISK_GUARD", "EVIDENCE_ENFORCER"],
|
|
168
|
+
"optional": ["SECURITY_DEEP", "LOGIC_CORRECTNESS", "API_CONTRACT"],
|
|
169
|
+
"routes": [
|
|
170
|
+
{
|
|
171
|
+
"match": ["**/auth/**", "**/security/**"],
|
|
172
|
+
"modes": ["diff", "batch", "segment"],
|
|
173
|
+
"add": ["SECURITY_DEEP", "API_CONTRACT"]
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
"tools": {
|
|
178
|
+
"enabled": false,
|
|
179
|
+
"maxCalls": 2,
|
|
180
|
+
"maxReadLines": 400,
|
|
181
|
+
"maxSearchMatches": 50,
|
|
182
|
+
"maxSearchFiles": 120,
|
|
183
|
+
"maxListFiles": 200,
|
|
184
|
+
"allow": [
|
|
185
|
+
"read_file",
|
|
186
|
+
"get_staged_diff",
|
|
187
|
+
"list_files",
|
|
188
|
+
"search_in_file",
|
|
189
|
+
"get_file_outline",
|
|
190
|
+
"search_in_repo",
|
|
191
|
+
"list_changed_files"
|
|
192
|
+
]
|
|
193
|
+
},
|
|
159
194
|
"temperature": 0,
|
|
160
195
|
"concurrency": 3
|
|
161
196
|
},
|
|
@@ -186,8 +221,9 @@ node bin/review.js --files test/src/large-test-file.js
|
|
|
186
221
|
|
|
187
222
|
#### AI 配置 (`ai`)
|
|
188
223
|
- `enabled`: 是否启用AI分析
|
|
189
|
-
- `
|
|
190
|
-
- `
|
|
224
|
+
- `provider`: 模型提供方,支持 `openai`、`anthropic`、`gemini`
|
|
225
|
+
- `model`: 对应提供方的模型名称
|
|
226
|
+
- `apiKey`: 统一 API 密钥字段(也可通过环境变量注入)
|
|
191
227
|
- `baseURL`: API基础URL
|
|
192
228
|
- `reviewOnlyChanges`: 是否启用Git Diff增量审查模式。`true`时只审查变更的代码行,`false`时审查整个文件内容。默认为`true`,大幅提升审查效率
|
|
193
229
|
- `maxResponseTokens`: AI响应最大token数
|
|
@@ -202,6 +238,28 @@ node bin/review.js --files test/src/large-test-file.js
|
|
|
202
238
|
- `includeStaticHints`: 是否在AI分析中包含静态规则提示
|
|
203
239
|
- `temperature`: AI模型的创造性参数,0表示最确定性的输出
|
|
204
240
|
- `concurrency`: 并发AI请求数量,默认3个。设置为1或更小时使用串行处理,大于1时启用并发处理以提升性能
|
|
241
|
+
- `skills.enabled`: 是否启用审查技能编排
|
|
242
|
+
- `skills.strict`: 是否强制检查输出是否满足“路径/片段/原因/建议”约束
|
|
243
|
+
- `skills.maxSkillsPerRequest`: 单次请求最多启用的技能数量
|
|
244
|
+
- `skills.required`: 必选技能列表
|
|
245
|
+
- `skills.optional`: 可选技能列表(按模式补充)
|
|
246
|
+
- `skills.routes`: 按文件路径和模式动态追加技能(`match/modes/add`)
|
|
247
|
+
- `tools.enabled`: 启用本地只读工具调用(见下方工具清单)
|
|
248
|
+
- `tools.maxCalls`: 单次请求最多工具调用轮次
|
|
249
|
+
- `tools.maxReadLines`: `read_file` 单次读取最大行数
|
|
250
|
+
- `tools.maxSearchMatches`: `search_in_file` / `search_in_repo` 单次最多返回匹配条数
|
|
251
|
+
- `tools.maxSearchFiles`: `search_in_repo` 单次最多扫描文件数
|
|
252
|
+
- `tools.maxListFiles`: `list_files` 单次最多返回文件数
|
|
253
|
+
- `tools.allow`: 工具白名单(仅允许模型调用白名单中的工具)
|
|
254
|
+
|
|
255
|
+
#### AI 只读工具清单 (`ai.tools.allow`)
|
|
256
|
+
- `read_file`: 读取指定文件的行区间
|
|
257
|
+
- `get_staged_diff`: 获取暂存区 diff(可按文件路径过滤)
|
|
258
|
+
- `list_files`: 递归列出仓库内文件(支持子目录和关键字/通配符过滤)
|
|
259
|
+
- `search_in_file`: 在单个文件内按文本或正则搜索
|
|
260
|
+
- `get_file_outline`: 提取文件结构轮廓(类/函数/方法等)
|
|
261
|
+
- `search_in_repo`: 在仓库范围内按文本或正则搜索(支持扫描文件数和结果数上限)
|
|
262
|
+
- `list_changed_files`: 获取 Git 变更文件列表(支持 staged/unstaged 和状态过滤)
|
|
205
263
|
|
|
206
264
|
#### 风险等级配置 (`riskLevels`)
|
|
207
265
|
- `critical`: 致命风险
|
|
@@ -563,8 +621,15 @@ const reviewer = new CodeReviewer(customConfig, defaultRules);
|
|
|
563
621
|
可通过环境变量配置:
|
|
564
622
|
|
|
565
623
|
```bash
|
|
566
|
-
#
|
|
624
|
+
# 统一 API 配置(最高优先级)
|
|
625
|
+
export AI_API_KEY="your-api-key"
|
|
626
|
+
|
|
627
|
+
# 按 Provider 配置
|
|
567
628
|
export OPENAI_API_KEY="your-api-key"
|
|
629
|
+
export ANTHROPIC_API_KEY="your-api-key"
|
|
630
|
+
export GEMINI_API_KEY="your-api-key"
|
|
631
|
+
# 或 Google 生态变量
|
|
632
|
+
export GOOGLE_API_KEY="your-api-key"
|
|
568
633
|
|
|
569
634
|
# 调试模式
|
|
570
635
|
export DEBUG_SMART_REVIEW=true
|
|
@@ -581,7 +646,7 @@ export SMART_REVIEW_LOCALE=zh-CN # 或 en-US
|
|
|
581
646
|
|
|
582
647
|
```json
|
|
583
648
|
{
|
|
584
|
-
"ai": { "baseURL": "https://api.openai.com/v1" }
|
|
649
|
+
"ai": { "provider": "openai", "baseURL": "https://api.openai.com/v1" }
|
|
585
650
|
}
|
|
586
651
|
```
|
|
587
652
|
|
|
@@ -743,13 +808,4 @@ smart-review --staged --debug
|
|
|
743
808
|
4. 推送到分支 (`git push origin feature/amazing-feature`)
|
|
744
809
|
5. 开启 Pull Request
|
|
745
810
|
|
|
746
|
-
## 📞 支持
|
|
747
|
-
|
|
748
|
-
- 📧 邮箱: zlife@vip.qq.com
|
|
749
|
-
- 🐛 问题反馈: [GitHub Issues](https://github.com/vlinr/smart-review/issues)
|
|
750
|
-
|
|
751
|
-
---
|
|
752
|
-
|
|
753
811
|
⭐ 如果这个项目对你有帮助,请给个 Star!
|
|
754
|
-
|
|
755
|
-
|