@zhuxb-clouds/ai-code-review 1.3.1 → 1.3.2

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.md CHANGED
@@ -1,241 +1,247 @@
1
1
  # AI Code Reviewer & Commit Generator
2
2
 
3
- 基于 Node.js 和 OpenAI-compatible API 的 Git Hooks 集成方案。在执行 `git commit` 时自动进行代码审查,并根据 Diff 自动生成符合 [Conventional Commits](https://www.conventionalcommits.org/) 规范的提交信息。
3
+ [English] | [简体中文](./README.zh-CN.md)
4
4
 
5
- **支持的 AI 提供商**: OpenAI, DeepSeek
5
+ A Git Hooks integration solution built with Node.js and OpenAI-compatible APIs. It automatically performs code reviews during `git commit` and generates commit messages that follow the [Conventional Commits](https://www.conventionalcommits.org/) specification based on your code changes.
6
6
 
7
- ## 🚀 核心特性
7
+ **Supported AI Providers**: OpenAI, DeepSeek, and more.
8
8
 
9
- - **自动化审查**:在代码提交前拦截潜在 Bug 或不规范实践
10
- - **语义化提交**:自动撰写符合 Conventional Commits 规范的提交信息
11
- - **无感集成**:通过 Git Hooks 实现,无需改变原有开发习惯
12
- - **成本可控**:支持 Diff 大小限制,避免 Token 浪费
13
- - **一键安装**:作为 npm 包安装到任何项目
14
- - **多提供商支持**:支持 OpenAI、DeepSeek 等兼容 API
15
- - **代理支持**:支持 HTTP/HTTPS/SOCKS5 代理
9
+ ## 🚀 Key Features
10
+
11
+ * **Automated Review**: Intercepts potential bugs or sub-optimal practices before the commit is finalized.
12
+ * **Semantic Commits**: Automatically drafts commit messages adhering to the Conventional Commits standard.
13
+ * **Seamless Integration**: Powered by Git Hooks; requires no changes to your existing development workflow.
14
+ * **Cost Efficiency**: Supports diff size limits to prevent excessive Token usage.
15
+ * **One-Click Installation**: Easily installable as an npm package in any project.
16
+ * **Multi-Provider Support**: Compatible with OpenAI, DeepSeek, and other OpenAI-compliant APIs.
17
+ * **Proxy Support**: Full support for HTTP/HTTPS/SOCKS5 proxies.
16
18
 
17
19
  ---
18
20
 
19
- ## 🛠️ 技术架构
21
+ ## 🛠️ Technical Architecture
20
22
 
21
23
  ```
22
24
  git commit → Husky (prepare-commit-msg) → ai-review-hook → AI API (OpenAI/DeepSeek)
23
25
 
24
- 通过:自动填充 Commit Message
25
- 失败:拦截提交并输出建议
26
+ Pass: Auto-fill Commit Message
27
+ Fail: Block commit & output suggestions
28
+
26
29
  ```
27
30
 
28
31
  ---
29
32
 
30
- ## 📦 快速开始
33
+ ## 📦 Quick Start
31
34
 
32
- ### 1. 安装到你的项目
35
+ ### 1. Install in your project
33
36
 
34
37
  ```bash
35
- # 安装为开发依赖
38
+ # Install as a dev dependency
36
39
  npm install ai-code-review -D
37
40
 
38
- # 初始化(自动安装 Husky 并配置 Git Hook)
41
+ # Initialize (Automatically installs Husky and configures Git Hooks)
39
42
  npx ai-review init
43
+
40
44
  ```
41
45
 
42
- ### 2. 配置环境变量
46
+ ### 2. Configure Environment Variables
43
47
 
44
- 复制生成的 `.env.example` `.env` 并填入你的 API Key
48
+ Copy the generated `.env.example` to `.env` and enter your API Key:
45
49
 
46
50
  ```bash
47
51
  cp .env.example .env
52
+
48
53
  ```
49
54
 
50
- #### 使用 OpenAI
55
+ #### Using OpenAI
51
56
 
52
57
  ```bash
53
58
  AI_PROVIDER=openai
54
59
  OPENAI_API_KEY=sk-your-openai-key-here
55
60
  OPENAI_MODEL=gpt-4o-mini
61
+
56
62
  ```
57
63
 
58
- #### 使用 DeepSeek
64
+ #### Using DeepSeek
59
65
 
60
66
  ```bash
61
67
  AI_PROVIDER=deepseek
62
68
  DEEPSEEK_API_KEY=sk-your-deepseek-key-here
63
- # OPENAI_MODEL=deepseek-chat # 可选,默认 deepseek-chat
69
+ # OPENAI_MODEL=deepseek-chat # Optional, defaults to deepseek-chat
70
+
64
71
  ```
65
72
 
66
- #### 使用代理
73
+ #### Using Proxies
67
74
 
68
75
  ```bash
69
76
  HTTPS_PROXY=http://127.0.0.1:7890
77
+
70
78
  ```
71
79
 
72
- > ⚠️ **安全提示**:`.env` 已自动添加到 `.gitignore`,请勿手动提交!
80
+ > ⚠️ **Security Note**: `.env` is automatically added to `.gitignore`. Never commit your API keys!
73
81
 
74
- ### 3. 开始使用
82
+ ### 3. Usage
75
83
 
76
84
  ```bash
77
- # 正常开发并暂存更改
85
+ # Develop and stage your changes as usual
78
86
  git add .
79
87
 
80
- # 发起提交(推荐不带 -m,让 AI 生成)
88
+ # Execute commit (Recommended: omit -m to let AI generate the message)
81
89
  git commit
82
90
 
83
- # AI 会自动审查并生成提交信息
84
- # 🔍 正在进行 AI 代码审查...
85
- # ✅ AI Review 通过
86
- # 📝 生成的提交信息: feat(auth): add JWT token validation
91
+ # AI will automatically review and generate the message
92
+ # 🔍 Running AI Code Review...
93
+ # ✅ AI Review Passed
94
+ # 📝 Generated Message: feat(auth): add JWT token validation
95
+
87
96
  ```
88
97
 
89
98
  ---
90
99
 
91
- ## 📂 安装后的目录结构
100
+ ## 📂 Post-Installation Directory Structure
92
101
 
93
102
  ```
94
103
  your-project/
95
104
  ├── .husky/
96
- │ └── prepare-commit-msg # Git Hook(自动创建)
97
- ├── .env # API Key(自己创建,不要提交!)
98
- ├── .env.example # 配置示例(自动创建)
99
- ├── .reviewignore # AI 审查忽略文件(可选)
100
- ├── .reviewignore.example # 忽略规则示例(自动创建)
101
- ├── .gitignore # 已包含 .env
102
- └── package.json # 包含 ai-code-review 依赖
105
+ │ └── prepare-commit-msg # Git Hook (Auto-generated)
106
+ ├── .env # API Keys (User-created, do not commit!)
107
+ ├── .env.example # Configuration template (Auto-generated)
108
+ ├── .reviewignore # AI Review ignore file (Optional)
109
+ ├── .reviewignore.example # Ignore rules template (Auto-generated)
110
+ ├── .gitignore # Now includes .env
111
+ └── package.json # Contains ai-code-review dependency
112
+
103
113
  ```
104
114
 
105
115
  ---
106
116
 
107
- ## 🚫 文件忽略配置 (.reviewignore)
117
+ ## 🚫 File Exclusion (.reviewignore)
108
118
 
109
- 创建 `.reviewignore` 文件来跳过某些文件的 AI 审查,语法类似 `.gitignore`:
119
+ Create a `.reviewignore` file to skip AI reviews for specific files. The syntax is identical to `.gitignore`:
110
120
 
111
121
  ```bash
112
- # 复制示例文件
122
+ # Copy the example file
113
123
  cp .reviewignore.example .reviewignore
124
+
114
125
  ```
115
126
 
116
- ### 支持的语法
127
+ ### Supported Syntax
117
128
 
118
129
  ```gitignore
119
- # 注释
120
- # 这是一个注释
130
+ # Comments
131
+ # This is a comment
121
132
 
122
- # 通配符
123
- package-lock.json # 匹配特定文件
124
- *.min.js # * 匹配任意字符(不包括 /)
125
- dist/ # 匹配整个目录
126
- **/*.snap # ** 匹配任意路径层级
133
+ # Wildcards
134
+ package-lock.json # Match specific file
135
+ *.min.js # * matches any string (excluding /)
136
+ dist/ # Match entire directory
137
+ **/*.snap # ** matches any path depth
138
+
139
+ # Negation patterns
140
+ *.md # Ignore all markdown files
141
+ !README.md # Do NOT ignore README.md
127
142
 
128
- # 否定模式
129
- *.md # 忽略所有 markdown
130
- !README.md # 但不忽略 README.md
131
143
  ```
132
144
 
133
- ### 常见配置示例
145
+ ### Common Configuration Examples
134
146
 
135
147
  ```gitignore
136
- # 锁文件
148
+ # Lock files
137
149
  package-lock.json
138
150
  pnpm-lock.yaml
139
151
  yarn.lock
140
152
 
141
- # 生成的文件
153
+ # Generated files
142
154
  *.min.js
143
155
  *.bundle.js
144
156
  dist/
145
157
  build/
146
158
 
147
- # 文档和资源
159
+ # Docs and Assets
148
160
  *.md
149
161
  *.svg
150
162
  *.png
151
163
 
152
- # 测试快照
164
+ # Test Snapshots
153
165
  __snapshots__/
154
166
  *.snap
167
+
155
168
  ```
156
169
 
157
170
  ---
158
171
 
159
- ## ⌨️ CLI 命令
172
+ ## ⌨️ CLI Commands
160
173
 
161
174
  ```bash
162
- # 完整初始化(安装 Husky + 配置 Hook
175
+ # Full Initialization (Install Husky + Config Hook)
163
176
  npx ai-review init
164
177
 
165
- # 仅配置 Hook(如果 Husky 已安装)
178
+ # Configure Hook Only (If Husky is already installed)
166
179
  npx ai-review setup
167
180
 
168
- # 显示帮助
181
+ # Display help information
169
182
  npx ai-review help
183
+
170
184
  ```
171
185
 
172
- ### 跳过 AI Review
186
+ ### Skipping AI Review
173
187
 
174
188
  ```bash
175
- # 使用 -m 参数时自动跳过 AI 生成(直接使用你的消息)
176
- git commit -m "feat: your message"
189
+ # Manual messages using -m will automatically skip AI generation
190
+ git commit -m "feat: your manual message"
177
191
 
178
- # merge/squash/amend 提交也会自动跳过
192
+ # Merge, squash, and amend operations also skip the review automatically
179
193
  git merge feature-branch
180
194
  git commit --amend
195
+
181
196
  ```
182
197
 
183
198
  ---
184
199
 
185
- ## ⚙️ 配置选项
200
+ ## ⚙️ Configuration Options
186
201
 
187
- 通过环境变量配置:
202
+ Configure your setup via environment variables in the `.env` file:
188
203
 
189
- ### 基础配置
204
+ ### Base Configuration
190
205
 
191
- | 环境变量 | 默认值 | 说明 |
192
- | ------------------ | -------- | ---------------------------------------------------------------- |
193
- | `AI_PROVIDER` | `openai` | AI 提供商:`openai` `deepseek` |
194
- | `OPENAI_API_KEY` | - | OpenAI API Key(使用 OpenAI 时必填) |
195
- | `DEEPSEEK_API_KEY` | - | DeepSeek API Key(使用 DeepSeek 时必填) |
196
- | `OPENAI_BASE_URL` | 自动设置 | 自定义 API 地址(可覆盖默认) |
197
- | `OPENAI_MODEL` | 自动设置 | 模型名称(OpenAI 默认 gpt-4o-miniDeepSeek 默认 deepseek-chat |
206
+ | Variable | Default | Description |
207
+ | ------------------ | -------- | --------------------------------------------------------- |
208
+ | `AI_PROVIDER` | `openai` | AI Provider: `openai` or `deepseek` |
209
+ | `OPENAI_API_KEY` | - | OpenAI API Key (Required if using OpenAI) |
210
+ | `DEEPSEEK_API_KEY` | - | DeepSeek API Key (Required if using DeepSeek) |
211
+ | `OPENAI_BASE_URL` | Auto | Custom API endpoint URL |
212
+ | `OPENAI_MODEL` | Auto | Model name (OpenAI: gpt-4o-mini, DeepSeek: deepseek-chat) |
198
213
 
199
- ### 网络配置
214
+ ### Network Configuration
200
215
 
201
- | 环境变量 | 默认值 | 说明 |
202
- | ------------- | ------ | -------------------------- |
203
- | `HTTPS_PROXY` | - | HTTP/HTTPS/SOCKS5 代理地址 |
204
- | `HTTP_PROXY` | - | 同上,备选 |
216
+ | Variable | Default | Description |
217
+ | ------------- | ------- | ------------------------------- |
218
+ | `HTTPS_PROXY` | - | HTTP/HTTPS/SOCKS5 proxy address |
219
+ | `HTTP_PROXY` | - | Alternative proxy address |
205
220
 
206
- ### 行为配置
221
+ ### Behavior Configuration
207
222
 
208
- | 环境变量 | 默认值 | 说明 |
209
- | ------------------------- | --------------- | -------------------------- |
210
- | `AI_REVIEW_MAX_DIFF_SIZE` | `15000` | 最大 Diff 字符数,超出截断 |
211
- | `AI_REVIEW_TIMEOUT` | `30000` | API 请求超时时间(毫秒) |
212
- | `AI_REVIEW_MAX_RETRIES` | `3` | 失败时最大重试次数 |
213
- | `AI_REVIEW_RETRY_DELAY` | `1000` | 重试间隔时间(毫秒) |
214
- | `AI_REVIEW_VERBOSE` | `false` | 启用详细日志 |
215
- | `AI_REVIEW_SKIP_BUILD` | `false` | 跳过构建检查 |
216
- | `AI_REVIEW_BUILD_COMMAND` | `npm run build` | 构建命令 |
223
+ | Variable | Default | Description |
224
+ | ------------------------- | ------- | ---------------------------------------------- |
225
+ | `AI_REVIEW_MAX_DIFF_SIZE` | `15000` | Max characters in diff (truncated if exceeded) |
226
+ | `AI_REVIEW_TIMEOUT` | `30000` | API request timeout in milliseconds |
227
+ | `AI_REVIEW_MAX_RETRIES` | `3` | Max retries on failure |
228
+ | `AI_REVIEW_RETRY_DELAY` | `1000` | Delay between retries in milliseconds |
229
+ | `AI_REVIEW_VERBOSE` | `false` | Enable detailed logging |
217
230
 
218
- ---
231
+ ### Build Checks (Optional)
219
232
 
220
- ## 🔄 替代方案对比
233
+ Build checks have been moved to the hook script. You can customize them by editing `.husky/prepare-commit-msg`:
221
234
 
222
- | 方案 | 优点 | 缺点 |
223
- | ------------------------------------------------- | --------------------------------- | ---------------------- |
224
- | **本方案 (ai-code-review)** | 一键安装、代码审查 + 提交信息生成 | 需要 OpenAI API Key |
225
- | [aicommits](https://github.com/Nutlope/aicommits) | 开箱即用的 CLI | 不含代码审查功能 |
226
- | [cz-git](https://cz-git.qbb.sh/) + AI | 交互式提交、规范完善 | 配置较复杂 |
227
- | GitHub Copilot | IDE 集成、体验好 | 需要订阅、无 Hook 集成 |
228
-
229
- ---
235
+ ```bash
236
+ # Open the hook file
237
+ vim .husky/prepare-commit-msg
230
238
 
231
- ## ⚠️ 注意事项
239
+ # Uncomment the following lines to enable build checks
240
+ echo "🔨 Running build check..."
241
+ npm run build || exit 1
242
+ echo "✅ Build passed"
232
243
 
233
- 1. **网络环境**:确保可访问 OpenAI API(或配置代理/自定义 Base URL)
234
- 2. **成本控制**:
235
- - 默认使用 `gpt-4o-mini`,成本约为 GPT-4 的 1/10
236
- - 大改动建议分批 `git add` 提交
237
- 3. **安全**:`.env` 文件绝对不要提交到仓库
238
- 4. **容错**:脚本在 API 出错时会允许提交,不阻塞开发
244
+ ```
239
245
 
240
246
  ---
241
247
 
@@ -0,0 +1,224 @@
1
+ # AI Code Reviewer & Commit Generator
2
+
3
+ [English](./README.md) | [简体中文]
4
+
5
+ 基于 Node.js 和 OpenAI-compatible API 的 Git Hooks 集成方案。在执行 `git commit` 时自动进行代码审查,并根据 Diff 自动生成符合 [Conventional Commits](https://www.conventionalcommits.org/) 规范的提交信息。
6
+
7
+ **支持的 AI 提供商**: OpenAI, DeepSeek
8
+
9
+ ## 🚀 核心特性
10
+
11
+ - **自动化审查**:在代码提交前拦截潜在 Bug 或不规范实践
12
+ - **语义化提交**:自动撰写符合 Conventional Commits 规范的提交信息
13
+ - **无感集成**:通过 Git Hooks 实现,无需改变原有开发习惯
14
+ - **成本可控**:支持 Diff 大小限制,避免 Token 浪费
15
+ - **一键安装**:作为 npm 包安装到任何项目
16
+ - **多提供商支持**:支持 OpenAI、DeepSeek 等兼容 API
17
+ - **代理支持**:支持 HTTP/HTTPS/SOCKS5 代理
18
+
19
+ ---
20
+
21
+ ## 🛠️ 技术架构
22
+
23
+ ```
24
+ git commit → Husky (prepare-commit-msg) → ai-review-hook → AI API (OpenAI/DeepSeek)
25
+
26
+ ✅ 通过:自动填充 Commit Message
27
+ ❌ 失败:拦截提交并输出建议
28
+ ```
29
+
30
+ ---
31
+
32
+ ## 📦 快速开始
33
+
34
+ ### 1. 安装到你的项目
35
+
36
+ ```bash
37
+ # 安装为开发依赖
38
+ npm install ai-code-review -D
39
+
40
+ # 初始化(自动安装 Husky 并配置 Git Hook)
41
+ npx ai-review init
42
+ ```
43
+
44
+ ### 2. 配置环境变量
45
+
46
+ 复制生成的 `.env.example` 为 `.env` 并填入你的 API Key:
47
+
48
+ ```bash
49
+ cp .env.example .env
50
+ ```
51
+
52
+ #### 使用 OpenAI
53
+
54
+ ```bash
55
+ AI_PROVIDER=openai
56
+ OPENAI_API_KEY=sk-your-openai-key-here
57
+ OPENAI_MODEL=gpt-4o-mini
58
+ ```
59
+
60
+ #### 使用 DeepSeek
61
+
62
+ ```bash
63
+ AI_PROVIDER=deepseek
64
+ DEEPSEEK_API_KEY=sk-your-deepseek-key-here
65
+ # OPENAI_MODEL=deepseek-chat # 可选,默认 deepseek-chat
66
+ ```
67
+
68
+ #### 使用代理
69
+
70
+ ```bash
71
+ HTTPS_PROXY=http://127.0.0.1:7890
72
+ ```
73
+
74
+ > ⚠️ **安全提示**:`.env` 已自动添加到 `.gitignore`,请勿手动提交!
75
+
76
+ ### 3. 开始使用
77
+
78
+ ```bash
79
+ # 正常开发并暂存更改
80
+ git add .
81
+
82
+ # 发起提交(推荐不带 -m,让 AI 生成)
83
+ git commit
84
+
85
+ # AI 会自动审查并生成提交信息
86
+ # 🔍 正在进行 AI 代码审查...
87
+ # ✅ AI Review 通过
88
+ # 📝 生成的提交信息: feat(auth): add JWT token validation
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 📂 安装后的目录结构
94
+
95
+ ```
96
+ your-project/
97
+ ├── .husky/
98
+ │ └── prepare-commit-msg # Git Hook(自动创建)
99
+ ├── .env # API Key(自己创建,不要提交!)
100
+ ├── .env.example # 配置示例(自动创建)
101
+ ├── .reviewignore # AI 审查忽略文件(可选)
102
+ ├── .reviewignore.example # 忽略规则示例(自动创建)
103
+ ├── .gitignore # 已包含 .env
104
+ └── package.json # 包含 ai-code-review 依赖
105
+ ```
106
+
107
+ ---
108
+
109
+ ## 🚫 文件忽略配置 (.reviewignore)
110
+
111
+ 创建 `.reviewignore` 文件来跳过某些文件的 AI 审查,语法类似 `.gitignore`:
112
+
113
+ ```bash
114
+ # 复制示例文件
115
+ cp .reviewignore.example .reviewignore
116
+ ```
117
+
118
+ ### 支持的语法
119
+
120
+ ```gitignore
121
+ # 注释
122
+ # 这是一个注释
123
+
124
+ # 通配符
125
+ package-lock.json # 匹配特定文件
126
+ *.min.js # * 匹配任意字符(不包括 /)
127
+ dist/ # 匹配整个目录
128
+ **/*.snap # ** 匹配任意路径层级
129
+
130
+ # 否定模式
131
+ *.md # 忽略所有 markdown
132
+ !README.md # 但不忽略 README.md
133
+ ```
134
+
135
+ ### 常见配置示例
136
+
137
+ ```gitignore
138
+ # 锁文件
139
+ package-lock.json
140
+ pnpm-lock.yaml
141
+ yarn.lock
142
+
143
+ # 生成的文件
144
+ *.min.js
145
+ *.bundle.js
146
+ dist/
147
+ build/
148
+
149
+ # 文档和资源
150
+ *.md
151
+ *.svg
152
+ *.png
153
+
154
+ # 测试快照
155
+ __snapshots__/
156
+ *.snap
157
+ ```
158
+
159
+ ---
160
+
161
+ ## ⌨️ CLI 命令
162
+
163
+ ```bash
164
+ # 完整初始化(安装 Husky + 配置 Hook)
165
+ npx ai-review init
166
+
167
+ # 仅配置 Hook(如果 Husky 已安装)
168
+ npx ai-review setup
169
+
170
+ # 显示帮助
171
+ npx ai-review help
172
+ ```
173
+
174
+ ### 跳过 AI Review
175
+
176
+ ```bash
177
+ # 使用 -m 参数时自动跳过 AI 生成(直接使用你的消息)
178
+ git commit -m "feat: your message"
179
+
180
+ # merge/squash/amend 提交也会自动跳过
181
+ git merge feature-branch
182
+ git commit --amend
183
+ ```
184
+
185
+ ---
186
+
187
+ ## ⚙️ 配置选项
188
+
189
+ 通过环境变量配置:
190
+
191
+ ### 基础配置
192
+
193
+ | 环境变量 | 默认值 | 说明 |
194
+ | ------------------ | -------- | ---------------------------------------------------------------- |
195
+ | `AI_PROVIDER` | `openai` | AI 提供商:`openai` 或 `deepseek` |
196
+ | `OPENAI_API_KEY` | - | OpenAI API Key(使用 OpenAI 时必填) |
197
+ | `DEEPSEEK_API_KEY` | - | DeepSeek API Key(使用 DeepSeek 时必填) |
198
+ | `OPENAI_BASE_URL` | 自动设置 | 自定义 API 地址(可覆盖默认) |
199
+ | `OPENAI_MODEL` | 自动设置 | 模型名称(OpenAI 默认 gpt-4o-mini,DeepSeek 默认 deepseek-chat) |
200
+
201
+ ### 网络配置
202
+
203
+ | 环境变量 | 默认值 | 说明 |
204
+ | ------------- | ------ | -------------------------- |
205
+ | `HTTPS_PROXY` | - | HTTP/HTTPS/SOCKS5 代理地址 |
206
+ | `HTTP_PROXY` | - | 同上,备选 |
207
+
208
+ ### 行为配置
209
+
210
+ | 环境变量 | 默认值 | 说明 |
211
+ | ------------------------- | --------------- | -------------------------- |
212
+ | `AI_REVIEW_MAX_DIFF_SIZE` | `15000` | 最大 Diff 字符数,超出截断 |
213
+ | `AI_REVIEW_TIMEOUT` | `30000` | API 请求超时时间(毫秒) |
214
+ | `AI_REVIEW_MAX_RETRIES` | `3` | 失败时最大重试次数 |
215
+ | `AI_REVIEW_RETRY_DELAY` | `1000` | 重试间隔时间(毫秒) |
216
+ | `AI_REVIEW_VERBOSE` | `false` | 启用详细日志 |
217
+ | `AI_REVIEW_SKIP_BUILD` | `false` | 跳过构建检查 |
218
+ | `AI_REVIEW_BUILD_COMMAND` | `npm run build` | 构建命令 |
219
+
220
+ ---
221
+
222
+ ## 📄 License
223
+
224
+ MIT
package/bin/cli.mjs CHANGED
@@ -27,7 +27,15 @@ const HOOK_CONTENT = `#!/bin/sh
27
27
  # AI Code Review Hook
28
28
  # $1: 提交消息文件路径
29
29
  # $2: 提交来源 (message, template, merge, squash, commit)
30
- # 当使用 git commit -m "xxx" 时,$2 为 "message",自动跳过 AI 生成
30
+
31
+ # ======== 可选:构建检查 ========
32
+ # 取消下面的注释来启用构建检查,可自行修改命令
33
+ # echo "🔨 正在运行构建检查..."
34
+ # npm run build || exit 1
35
+ # echo "✅ 构建通过"
36
+ # ================================
37
+
38
+ # AI 代码审查和 commit message 生成
31
39
  npx ai-review-hook "$1" "$2"
32
40
  `;
33
41
 
@@ -51,8 +59,6 @@ OPENAI_API_KEY=sk-your-openai-api-key-here
51
59
  # AI_REVIEW_MAX_RETRIES=3
52
60
  # AI_REVIEW_RETRY_DELAY=1000
53
61
  # AI_REVIEW_VERBOSE=false
54
- # AI_REVIEW_SKIP_BUILD=false
55
- # AI_REVIEW_BUILD_COMMAND=npm run build
56
62
  `;
57
63
 
58
64
  function showHelp() {
package/bin/hook.mjs CHANGED
@@ -77,8 +77,6 @@ const CONFIG = {
77
77
  model: aiConfig.model,
78
78
  maxDiffSize: parseInt(process.env.AI_REVIEW_MAX_DIFF_SIZE) || 15000,
79
79
  timeout: parseInt(process.env.AI_REVIEW_TIMEOUT) || 30000,
80
- skipBuild: process.env.AI_REVIEW_SKIP_BUILD === "true",
81
- buildCommand: process.env.AI_REVIEW_BUILD_COMMAND || "npm run build",
82
80
  verbose: process.env.AI_REVIEW_VERBOSE === "true",
83
81
  maxRetries: parseInt(process.env.AI_REVIEW_MAX_RETRIES) || 3,
84
82
  retryDelay: parseInt(process.env.AI_REVIEW_RETRY_DELAY) || 1000,
@@ -351,7 +349,6 @@ async function runAIReview() {
351
349
  logVerbose(`模型: ${CONFIG.model}`);
352
350
  logVerbose(`最大 Diff 大小: ${CONFIG.maxDiffSize}`);
353
351
  logVerbose(`超时时间: ${CONFIG.timeout}ms`);
354
- logVerbose(`跳过构建: ${CONFIG.skipBuild}`);
355
352
  if (process.env.OPENAI_BASE_URL) {
356
353
  logVerbose(`API Base URL: ${process.env.OPENAI_BASE_URL}`);
357
354
  }
@@ -386,28 +383,7 @@ async function runAIReview() {
386
383
 
387
384
  logVerbose(`过滤后 Diff 大小: ${(diff.length / 1000).toFixed(2)}KB`);
388
385
 
389
- // 2. 运行构建检查
390
- if (!CONFIG.skipBuild) {
391
- console.log(`🔨 正在运行构建检查: ${CONFIG.buildCommand}`);
392
- const buildTimer = logTime("构建检查");
393
- try {
394
- execSync(CONFIG.buildCommand, {
395
- cwd: projectRoot,
396
- stdio: "inherit",
397
- encoding: "utf-8",
398
- });
399
- console.log("✅ 构建通过");
400
- logTimeEnd(buildTimer);
401
- } catch (buildError) {
402
- console.error("❌ 构建失败,请修复后重新提交");
403
- console.error("\n使用 git commit --no-verify 可跳过检查");
404
- process.exit(1);
405
- }
406
- } else {
407
- logVerbose("跳过构建检查 (AI_REVIEW_SKIP_BUILD=true)");
408
- }
409
-
410
- // 3. 检查 Diff 大小
386
+ // 2. 检查 Diff 大小
411
387
  if (diff.length > CONFIG.maxDiffSize) {
412
388
  console.warn(`⚠️ Diff 过大 (${(diff.length / 1000).toFixed(1)}KB),建议分批提交`);
413
389
  console.warn(` 当前限制: ${CONFIG.maxDiffSize / 1000}KB,超出部分将被截断`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhuxb-clouds/ai-code-review",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "基于 OpenAI API 的 Git Hooks 集成方案,自动代码审查并生成 Conventional Commits 提交信息",
5
5
  "type": "module",
6
6
  "bin": {