@dongowu/git-ai-cli 1.0.21 → 2.0.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.md +200 -157
- package/bin/git-ai.cjs +57 -0
- package/install.cjs +50 -0
- package/package.json +27 -28
- package/.claude/settings.local.json +0 -17
- package/CHANGELOG.md +0 -46
- package/README_EN.md +0 -264
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -17
- package/dist/cli.js.map +0 -1
- package/dist/cli_main.d.ts +0 -2
- package/dist/cli_main.d.ts.map +0 -1
- package/dist/cli_main.js +0 -255
- package/dist/cli_main.js.map +0 -1
- package/dist/commands/branch.d.ts +0 -11
- package/dist/commands/branch.d.ts.map +0 -1
- package/dist/commands/branch.js +0 -279
- package/dist/commands/branch.js.map +0 -1
- package/dist/commands/commit.d.ts +0 -9
- package/dist/commands/commit.d.ts.map +0 -1
- package/dist/commands/commit.js +0 -326
- package/dist/commands/commit.js.map +0 -1
- package/dist/commands/config.d.ts +0 -2
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/config.js +0 -164
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/config_manage.d.ts +0 -14
- package/dist/commands/config_manage.d.ts.map +0 -1
- package/dist/commands/config_manage.js +0 -394
- package/dist/commands/config_manage.js.map +0 -1
- package/dist/commands/hook.d.ts +0 -5
- package/dist/commands/hook.d.ts.map +0 -1
- package/dist/commands/hook.js +0 -528
- package/dist/commands/hook.js.map +0 -1
- package/dist/commands/msg.d.ts +0 -20
- package/dist/commands/msg.d.ts.map +0 -1
- package/dist/commands/msg.js +0 -148
- package/dist/commands/msg.js.map +0 -1
- package/dist/commands/pr.d.ts +0 -8
- package/dist/commands/pr.d.ts.map +0 -1
- package/dist/commands/pr.js +0 -96
- package/dist/commands/pr.js.map +0 -1
- package/dist/commands/release.d.ts +0 -8
- package/dist/commands/release.d.ts.map +0 -1
- package/dist/commands/release.js +0 -95
- package/dist/commands/release.js.map +0 -1
- package/dist/commands/report.d.ts +0 -9
- package/dist/commands/report.d.ts.map +0 -1
- package/dist/commands/report.js +0 -162
- package/dist/commands/report.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -86
- package/dist/types.js.map +0 -1
- package/dist/utils/agent.d.ts +0 -5
- package/dist/utils/agent.d.ts.map +0 -1
- package/dist/utils/agent.js +0 -308
- package/dist/utils/agent.js.map +0 -1
- package/dist/utils/agent_lite.d.ts +0 -5
- package/dist/utils/agent_lite.d.ts.map +0 -1
- package/dist/utils/agent_lite.js +0 -263
- package/dist/utils/agent_lite.js.map +0 -1
- package/dist/utils/ai.d.ts +0 -43
- package/dist/utils/ai.d.ts.map +0 -1
- package/dist/utils/ai.js +0 -1103
- package/dist/utils/ai.js.map +0 -1
- package/dist/utils/config.d.ts +0 -11
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -239
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/git.d.ts +0 -42
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js +0 -456
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/update.d.ts +0 -4
- package/dist/utils/update.d.ts.map +0 -1
- package/dist/utils/update.js +0 -122
- package/dist/utils/update.js.map +0 -1
- package/release_notes.md +0 -9
- package/scripts/release.sh +0 -34
- package/test_agent_feature.ts +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<strong>🤖 AI-Powered Git Assistant: Commit, Context & Report</strong>
|
|
5
5
|
</p>
|
|
6
6
|
<p align="center">
|
|
7
|
-
🚀 <strong>DeepSeek</strong> 深度优化 | 🏠 <strong>Ollama</strong> 隐私优先 | 🧠 <strong>分支感知</strong> | 📊 <strong>智能周报</strong>
|
|
7
|
+
🚀 <strong>DeepSeek</strong> 深度优化 | 🏠 <strong>Ollama</strong> 隐私优先 | 🧠 <strong>分支感知</strong> | 🛡️ <strong>Copilot 守护</strong> | 📊 <strong>智能周报</strong>
|
|
8
8
|
</p>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
@@ -18,223 +18,264 @@
|
|
|
18
18
|
<p align="center">
|
|
19
19
|
<a href="./README_EN.md">English</a> •
|
|
20
20
|
<a href="#-快速开始">快速开始</a> •
|
|
21
|
-
<a href="
|
|
22
|
-
<a href="
|
|
23
|
-
<a href="
|
|
21
|
+
<a href="#-核心特性">核心特性</a> •
|
|
22
|
+
<a href="#-git-flow-最佳实践">Git Flow</a> •
|
|
23
|
+
<a href="#-智能周报">智能周报</a>
|
|
24
24
|
</p>
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
-
**git-ai-cli**
|
|
28
|
+
**git-ai-cli** 不仅仅是一个 Commit Message 生成器,它是你的**全能 AI 开发助手**。它能读懂你的代码 Diff,看懂你的分支意图,甚至帮你写好周报。
|
|
29
29
|
|
|
30
30
|
---
|
|
31
31
|
|
|
32
|
+
## 🦀 Rust 版说明(当前默认发布)
|
|
33
|
+
|
|
34
|
+
从 **2.x** 开始,`git-ai-cli` 默认发布 **Rust 版**(更快、单文件二进制)。推荐通过 npm 安装(会自动下载对应平台的二进制):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g @dongowu/git-ai-cli
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
> Rust 版目前包含 **agent-lite**(影响分析/符号搜索),增强安全/性能分析功能仍在迁移中。
|
|
41
|
+
|
|
42
|
+
> 如需旧版 TypeScript(1.x)请自行固定版本号安装。
|
|
43
|
+
|
|
32
44
|
## 🚀 快速开始
|
|
33
45
|
|
|
34
46
|
```bash
|
|
35
|
-
# 1
|
|
47
|
+
# 1. 安装
|
|
36
48
|
npm install -g @dongowu/git-ai-cli
|
|
37
49
|
|
|
38
|
-
# 2
|
|
39
|
-
git-ai
|
|
50
|
+
# 2. 初始化 (自动探测本地模型或配置 API)
|
|
51
|
+
git-ai config
|
|
40
52
|
|
|
41
|
-
# 3
|
|
53
|
+
# 3. 使用
|
|
42
54
|
git add .
|
|
43
55
|
git-ai
|
|
44
56
|
```
|
|
45
57
|
|
|
46
58
|
---
|
|
47
59
|
|
|
48
|
-
##
|
|
60
|
+
## ✨ 核心特性
|
|
49
61
|
|
|
50
|
-
1
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
### 1. 🇨🇳 极致本土化 & 隐私优先
|
|
63
|
+
- **DeepSeek/Qwen 深度优化**:内置专家级提示词,针对中文代码语境优化,不只是翻译 Diff,而是理解“意图”。
|
|
64
|
+
- **Ollama 零配置**:自动探测本地运行的 Ollama 模型(如 `llama3`, `deepseek-coder`),无需手动输入模型名。数据完全不出网,绝对安全。
|
|
65
|
+
|
|
66
|
+
### 2. 🧠 上下文感知 (Context Aware)
|
|
67
|
+
- **风格学习**:自动分析您最近的 10 次提交记录,模仿您的语气、格式(如 Emoji 使用习惯)和语言风格。
|
|
68
|
+
- **分支感知**:读取当前分支名(如 `feat/user-login`, `fix/JIRA-123`),生成包含 Issue ID 或功能模块的规范提交信息。
|
|
69
|
+
|
|
70
|
+
### 3. 🤖 Agent 智能体
|
|
71
|
+
从单纯的"文本生成"进化为"智能代码专家"。
|
|
72
|
+
- **Smart Diff**: 遇到超大变更不再瞎编。Agent 会自动分析统计数据,只读取核心文件的代码,大幅降低 Token 限制带来的影响。
|
|
73
|
+
- **影响分析 (Impact Analysis)**: 修改了核心 API?Agent 会主动**搜索整个代码库**(`git grep`),检查调用方是否同步修改,并在 Commit Body 中提示潜在风险。
|
|
74
|
+
- **Git Flow 护航**: 在 `release/*` 或 `hotfix/*` 分支上自动开启深度检查,守卫生产环境。
|
|
75
|
+
|
|
76
|
+
### 4. 🛡️ GitHub Copilot CLI 智能守护 (New)
|
|
77
|
+
双层 AI 架构:专业 Commit 生成 + 深度代码分析。
|
|
78
|
+
- **代码影响分析**: 使用 GitHub Copilot CLI 深度分析代码变更的影响范围和潜在风险
|
|
79
|
+
- **风险检测**: 自动识别破坏性变更、潜在 Bug 和安全隐患
|
|
80
|
+
- **测试建议**: 智能推荐需要测试的场景和用例
|
|
81
|
+
- **受影响区域**: 分析哪些模块和文件可能受到影响
|
|
82
|
+
- **可选启用**: 通过 `--copilot` 参数按需启用,不强制依赖
|
|
83
|
+
|
|
84
|
+
### 5. ⚙️ 工程化配置 (Project Config)
|
|
85
|
+
- **项目级配置**:支持在项目根目录创建 `.git-ai.json`,团队统一共享模型和 Prompt 配置(优先级 > 全局配置)。
|
|
86
|
+
- **智能忽略**:支持 `.git-aiignore` 文件,排除自动生成文件(如 `package-lock.json`)或大文件,节省 Token 并提高准确性。
|
|
87
|
+
|
|
88
|
+
### 6. 🪝 无感集成 (Git Hook)
|
|
89
|
+
- **零打扰**:安装 Hook 后,只需执行 `git commit`(不带 `-m`),AI 自动填充消息并打开编辑器。
|
|
90
|
+
- **兼容性**:完美兼容现有 Git 工作流,支持 `git commit --no-verify` 跳过。
|
|
91
|
+
|
|
92
|
+
### 7. 📊 智能周报 (AI Report)
|
|
93
|
+
- **一键生成**:`git-ai report` 自动分析你最近的代码提交。
|
|
94
|
+
- **价值导向**:将零碎的 Commit 转化为结构化的"核心产出"、"问题修复"和"技术优化"报告。
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## ⚙️ 高级配置
|
|
99
|
+
|
|
100
|
+
### 项目级配置文件 `.git-ai.json`
|
|
101
|
+
在项目根目录创建此文件,可覆盖全局设置,方便团队统一规范:
|
|
55
102
|
|
|
56
|
-
2) **团队配置(推荐)**:在项目根目录写 `.git-ai.json`
|
|
57
103
|
```json
|
|
58
104
|
{
|
|
59
105
|
"provider": "deepseek",
|
|
60
106
|
"baseUrl": "https://api.deepseek.com/v1",
|
|
61
107
|
"model": "deepseek-reasoner",
|
|
62
108
|
"agentModel": "deepseek-chat",
|
|
63
|
-
"locale": "
|
|
64
|
-
"enableFooter":
|
|
65
|
-
"rulesPreset": "conventional",
|
|
66
|
-
"fallbackModels": ["deepseek-chat", "qwen-turbo"],
|
|
67
|
-
"policy": { "strict": true },
|
|
68
|
-
"rules": {
|
|
69
|
-
"types": ["feat", "fix", "docs", "refactor", "perf", "test", "chore", "build", "ci"],
|
|
70
|
-
"maxSubjectLength": 50,
|
|
71
|
-
"requireScope": false,
|
|
72
|
-
"issuePattern": "[A-Z]+-\\d+",
|
|
73
|
-
"issuePlacement": "footer",
|
|
74
|
-
"issueFooterPrefix": "Refs",
|
|
75
|
-
"requireIssue": false
|
|
76
|
-
},
|
|
77
|
-
"branch": {
|
|
78
|
-
"types": ["feat", "fix", "docs"],
|
|
79
|
-
"pattern": "{type}/{issue?}{name}",
|
|
80
|
-
"issueSeparator": "-",
|
|
81
|
-
"nameMaxLength": 50
|
|
82
|
-
}
|
|
109
|
+
"locale": "zh",
|
|
110
|
+
"enableFooter": true
|
|
83
111
|
}
|
|
84
112
|
```
|
|
85
113
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
说明:
|
|
115
|
+
- `model`:基础模式生成提交信息的模型
|
|
116
|
+
- `agentModel`:Agent 模式(`-a`)专用模型(建议选择稳定支持 tools 的模型;DeepSeek 常用 `deepseek-chat`)
|
|
117
|
+
- `locale`:仅支持 `zh` / `en`
|
|
118
|
+
- `apiKey` 建议通过环境变量或全局配置设置,不要提交到仓库
|
|
91
119
|
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
git-ai hook install
|
|
95
|
-
# 失败阻断提交(可选)
|
|
96
|
-
GIT_AI_HOOK_STRICT=1 git commit
|
|
97
|
-
# 失败时关闭兜底(可选)
|
|
98
|
-
GIT_AI_HOOK_FALLBACK=0 git commit
|
|
99
|
-
```
|
|
120
|
+
### 命令行配置(可脚本化)
|
|
100
121
|
|
|
101
|
-
5) **脚本 / CI**
|
|
102
122
|
```bash
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
# 查看当前生效配置(包含环境变量覆盖)
|
|
124
|
+
git-ai config get --json
|
|
105
125
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
# 设置全局配置(写入全局配置文件)
|
|
127
|
+
git-ai config set model deepseek-chat
|
|
128
|
+
|
|
129
|
+
# 设置项目级配置(写入当前项目 .git-ai.json)
|
|
130
|
+
git-ai config set agentModel deepseek-chat --local
|
|
131
|
+
|
|
132
|
+
# 查看可配置项 / 环境变量覆盖
|
|
133
|
+
git-ai config describe
|
|
109
134
|
```
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
### 环境变量(CI/脚本)
|
|
137
|
+
|
|
138
|
+
常用环境变量(优先级高于配置文件):
|
|
139
|
+
- `GIT_AI_PROVIDER` / `GIT_AI_BASE_URL` / `GIT_AI_MODEL` / `GIT_AI_AGENT_MODEL`
|
|
140
|
+
- `GIT_AI_API_KEY`(也支持 `DEEPSEEK_API_KEY`、`OPENAI_API_KEY`)
|
|
141
|
+
- `GIT_AI_TIMEOUT_MS`(请求超时,默认 120000)
|
|
142
|
+
- `GIT_AI_MAX_DIFF_CHARS`(控制 diff 截断长度)
|
|
143
|
+
- `GIT_AI_MAX_OUTPUT_TOKENS`(控制输出 token 上限)
|
|
144
|
+
- `GIT_AI_DEBUG=1`(打印更详细错误)
|
|
145
|
+
|
|
146
|
+
OpenCommit 兼容变量(可直接复用):
|
|
147
|
+
- `OCO_AI_PROVIDER` / `OCO_MODEL` / `OCO_API_KEY`
|
|
148
|
+
- `OCO_TOKENS_MAX_INPUT` / `OCO_TOKENS_MAX_OUTPUT`
|
|
115
149
|
|
|
116
|
-
|
|
117
|
-
|
|
150
|
+
### 忽略文件 `.git-aiignore`
|
|
151
|
+
在项目根目录创建,用于排除不想发送给 AI 的文件(语法同 `.gitignore`):
|
|
118
152
|
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
```text
|
|
154
|
+
package-lock.json
|
|
155
|
+
dist/
|
|
156
|
+
*.min.js
|
|
121
157
|
```
|
|
122
158
|
|
|
123
|
-
|
|
159
|
+
同时兼容 OpenCommit 的 `.opencommitignore`(两者都会读取)。
|
|
124
160
|
|
|
125
|
-
|
|
161
|
+
### 常见问题
|
|
162
|
+
|
|
163
|
+
**1) 401 / API Key 无效**
|
|
164
|
+
- 先看生效配置:`git-ai config get --json --local`
|
|
165
|
+
- 再检查环境变量是否覆盖:`GIT_AI_API_KEY / DEEPSEEK_API_KEY / OPENAI_API_KEY / OCO_API_KEY`
|
|
126
166
|
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
-
|
|
133
|
-
- **AI 报告**:日报/周报/PR/Release Notes 一键生成
|
|
167
|
+
**2) Diff 被截断**
|
|
168
|
+
- 通过 `.git-aiignore` / `.opencommitignore` 忽略大文件(lock/build/map)
|
|
169
|
+
- 或设置 `GIT_AI_MAX_DIFF_CHARS`(也兼容 `OCO_TOKENS_MAX_INPUT`)
|
|
170
|
+
|
|
171
|
+
**3) Agent 自动回退到基础模式**
|
|
172
|
+
- 设置 `GIT_AI_DEBUG=1` 可以看到回退原因(超时/限流/鉴权等)
|
|
134
173
|
|
|
135
174
|
---
|
|
136
175
|
|
|
137
|
-
##
|
|
138
|
-
|
|
139
|
-
###
|
|
140
|
-
|
|
141
|
-
- `locale`: `zh` / `en`
|
|
142
|
-
- `outputFormat`: `text` / `json`
|
|
143
|
-
- `rulesPreset`: `conventional` / `angular` / `minimal`
|
|
144
|
-
- `fallbackModels`: 主模型失败时的回退模型列表
|
|
145
|
-
- `policy.strict`: 是否阻断不合规提交
|
|
146
|
-
- `rules`: 提交规范(类型、scope、长度、issue 等)
|
|
147
|
-
- `branch`: 分支规范(类型、pattern、长度等)
|
|
148
|
-
|
|
149
|
-
### 规则与策略
|
|
150
|
-
- `issuePattern`: 任务号正则(如 `PROJ-123` / `#123`)
|
|
151
|
-
- `issuePlacement`: `scope | subject | footer`
|
|
152
|
-
- `requireIssue`: 是否必须包含任务号
|
|
153
|
-
- `policy.strict`: 不合规则阻断提交
|
|
154
|
-
- `branch.pattern`: 分支模板(如 `{type}/{issue?}{name}`)
|
|
155
|
-
- `branch.types`: 分支类型列表
|
|
156
|
-
- `branch.issueSeparator`: issue 分隔符(默认 `-`)
|
|
157
|
-
- `branch.nameMaxLength`: 分支名长度上限
|
|
158
|
-
|
|
159
|
-
### CLI 设置(可脚本化)
|
|
176
|
+
## 📖 使用方式
|
|
177
|
+
|
|
178
|
+
### 场景一:交互式提交 (Interactive)
|
|
179
|
+
|
|
160
180
|
```bash
|
|
161
|
-
|
|
162
|
-
git-ai
|
|
181
|
+
git add .
|
|
182
|
+
git-ai
|
|
183
|
+
```
|
|
163
184
|
|
|
164
|
-
|
|
165
|
-
git-ai config set rulesPreset conventional
|
|
166
|
-
git-ai config set policy '{"strict":true}'
|
|
167
|
-
git-ai config set fallbackModels "deepseek-chat,qwen-turbo"
|
|
185
|
+
### 场景二:Copilot 智能守护模式 🌟 推荐
|
|
168
186
|
|
|
169
|
-
|
|
170
|
-
git
|
|
171
|
-
git-ai
|
|
187
|
+
```bash
|
|
188
|
+
git add .
|
|
189
|
+
git-ai --copilot
|
|
190
|
+
# 1. 使用 DeepSeek/Ollama 生成专业 commit message
|
|
191
|
+
# 2. GitHub Copilot CLI 深度分析代码影响
|
|
192
|
+
# 3. 展示风险提示和测试建议
|
|
193
|
+
# 4. 确认后提交
|
|
194
|
+
```
|
|
172
195
|
|
|
173
|
-
|
|
174
|
-
git-ai config set branch '{"types":["feat","fix"],"pattern":"{type}/{issue?}{name}"}'
|
|
196
|
+
**输出示例:**
|
|
175
197
|
```
|
|
198
|
+
✨ Generated commit message(s):
|
|
176
199
|
|
|
177
|
-
|
|
200
|
+
feat(auth): implement JWT token refresh mechanism
|
|
178
201
|
|
|
179
|
-
|
|
202
|
+
📊 Impact Analysis:
|
|
203
|
+
Modified authentication flow to support automatic token refresh
|
|
180
204
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
| `git-ai config get/set/describe` | 配置管理 |
|
|
185
|
-
| `git-ai` / `git-ai commit` | 交互式提交 |
|
|
186
|
-
| `git-ai -a` | Agent 模式 |
|
|
187
|
-
| `git-ai msg` | 仅输出消息(脚本/Hook) |
|
|
188
|
-
| `git-ai branch` | 交互式创建分支 |
|
|
189
|
-
| `git-ai hook install/remove` | Git Hook 管理 |
|
|
190
|
-
| `git-ai report` | 生成 AI 周报 |
|
|
191
|
-
| `git-ai pr` | 生成 PR 描述 |
|
|
192
|
-
| `git-ai release` | 生成 Release Notes |
|
|
205
|
+
⚠️ Potential Risks:
|
|
206
|
+
• Breaking change: Old tokens will be invalidated
|
|
207
|
+
• Session management logic needs update
|
|
193
208
|
|
|
194
|
-
|
|
209
|
+
🔗 Affected Areas:
|
|
210
|
+
• Login component
|
|
211
|
+
• API middleware
|
|
212
|
+
• User session store
|
|
195
213
|
|
|
196
|
-
|
|
214
|
+
✅ Test Recommendations:
|
|
215
|
+
• Test token expiration handling
|
|
216
|
+
• Verify refresh token rotation
|
|
217
|
+
• Check concurrent request handling
|
|
218
|
+
```
|
|
197
219
|
|
|
198
|
-
|
|
199
|
-
- `GIT_AI_API_KEY`(也支持 `DEEPSEEK_API_KEY`, `OPENAI_API_KEY`)
|
|
200
|
-
- `GIT_AI_TIMEOUT_MS`
|
|
201
|
-
- `GIT_AI_MAX_DIFF_CHARS` / `GIT_AI_MAX_OUTPUT_TOKENS`
|
|
202
|
-
- `GIT_AI_RULES_PRESET`
|
|
203
|
-
- `GIT_AI_FALLBACK_MODELS`
|
|
204
|
-
- `GIT_AI_POLICY_STRICT`
|
|
205
|
-
- `GIT_AI_ISSUE_PATTERN` / `GIT_AI_ISSUE_PLACEMENT` / `GIT_AI_REQUIRE_ISSUE`
|
|
206
|
-
- `GIT_AI_OUTPUT_FORMAT=json`
|
|
207
|
-
- `GIT_AI_MSG_DELIM=<<<GIT_AI_END>>>`
|
|
208
|
-
- `GIT_AI_HOOK_STRICT=1` / `GIT_AI_HOOK_FALLBACK=0`
|
|
209
|
-
- `GIT_AI_BRANCH_PATTERN` / `GIT_AI_BRANCH_TYPES`
|
|
210
|
-
- `GIT_AI_BRANCH_ISSUE_SEPARATOR` / `GIT_AI_BRANCH_NAME_MAXLEN`
|
|
220
|
+
### 场景三:Git Flow 最佳实践 (Hook)
|
|
211
221
|
|
|
212
|
-
|
|
222
|
+
这是最流畅的体验。你不需要改变任何习惯,只需一次安装:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# 在当前项目安装
|
|
226
|
+
git-ai hook install
|
|
213
227
|
|
|
214
|
-
|
|
228
|
+
# 或者全局安装(所有项目生效)
|
|
229
|
+
git-ai hook install --global
|
|
230
|
+
```
|
|
215
231
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
232
|
+
**之后只需:**
|
|
233
|
+
```bash
|
|
234
|
+
git checkout -b feature/awesome-login
|
|
235
|
+
# ... 写代码 ...
|
|
236
|
+
git add .
|
|
237
|
+
git commit # ✨ AI 自动帮你写好了 "feat(login): implement awesome login logic"
|
|
220
238
|
```
|
|
221
239
|
|
|
222
|
-
|
|
240
|
+
### 场景四:生成周报 (Report)
|
|
223
241
|
|
|
224
|
-
|
|
242
|
+
每逢周五不想写周报?
|
|
225
243
|
|
|
226
|
-
|
|
244
|
+
```bash
|
|
245
|
+
# 生成本周日报/周报
|
|
246
|
+
git-ai report
|
|
227
247
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
- 检查环境变量是否覆盖
|
|
248
|
+
# 生成最近 30 天的汇报
|
|
249
|
+
git-ai report --days 30
|
|
231
250
|
|
|
232
|
-
|
|
233
|
-
-
|
|
234
|
-
|
|
251
|
+
# 从“上次 tag”到当前代码生成版本功能描述
|
|
252
|
+
git-ai report --from-last-tag
|
|
253
|
+
|
|
254
|
+
# 指定 tag 范围生成发布说明(例如 v1.0.21 -> v2.0.0)
|
|
255
|
+
git-ai report --from-tag v1.0.21 --to-ref v2.0.0
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 🛠 命令速查
|
|
235
261
|
|
|
236
|
-
|
|
237
|
-
|
|
262
|
+
| 命令 | 别名 | 说明 |
|
|
263
|
+
|------|------|------|
|
|
264
|
+
| `git-ai config` | `config` | **初始化配置**(设置模型、Key、语言) |
|
|
265
|
+
| `git-ai config get` | | 查看当前生效配置(支持 `--json` / `--local`) |
|
|
266
|
+
| `git-ai config set <key> <value>` | | 设置配置(支持 `--local` / `--json`) |
|
|
267
|
+
| `git-ai config describe` | | 查看可配置项与环境变量覆盖 |
|
|
268
|
+
| `git-ai` | | 交互式生成并提交 |
|
|
269
|
+
| `git-ai --copilot` | | **Copilot 守护模式** (代码影响分析 & 风险检测) |
|
|
270
|
+
| `git-ai -a` | | **Agent 模式** (深度分析 & 影响检查) |
|
|
271
|
+
| `git-ai -a --copilot` | | **终极模式** (Agent + Copilot 双重保障) |
|
|
272
|
+
| `git-ai -y` | | 跳过确认直接提交 |
|
|
273
|
+
| `git-ai -n 3` | | 生成 3 条候选消息 |
|
|
274
|
+
| `git-ai -l en` | | 强制输出语言(en/zh) |
|
|
275
|
+
| `git-ai hook install` | | **安装 Git Hook** (支持 `--global`) |
|
|
276
|
+
| `git-ai hook remove` | | 移除 Git Hook |
|
|
277
|
+
| `git-ai report` | | **生成 AI 周报 / 版本说明** (支持 `--days` / `--from-last-tag` / `--from-tag --to-ref`) |
|
|
278
|
+
| `git-ai msg` | | 仅输出消息(供脚本调用) |
|
|
238
279
|
|
|
239
280
|
---
|
|
240
281
|
|
|
@@ -242,18 +283,20 @@ dist/
|
|
|
242
283
|
|
|
243
284
|
| 类型 | 服务商 | 优势 | 配置方式 |
|
|
244
285
|
|------|--------|------|----------|
|
|
245
|
-
| **本地隐私** | **Ollama** |
|
|
286
|
+
| **本地隐私** | **Ollama** | 免费、离线、绝对隐私 | `git-ai config` 自动探测 |
|
|
246
287
|
| | **LM Studio** | 兼容性好 | 手动输入 URL |
|
|
247
|
-
| **国内高速** | **DeepSeek** |
|
|
248
|
-
| | **通义千问** |
|
|
249
|
-
| | **智谱/Moonshot** |
|
|
288
|
+
| **国内高速** | **DeepSeek** | **性价比之王**,代码能力极强 | API Key |
|
|
289
|
+
| | **通义千问** | 阿里生态,长文本能力强 | API Key |
|
|
290
|
+
| | **智谱/Moonshot** | 国内主流模型 | API Key |
|
|
250
291
|
| **国际通用** | **OpenAI** | GPT-4o 基准能力 | API Key |
|
|
251
292
|
|
|
252
293
|
---
|
|
253
294
|
|
|
295
|
+
|
|
296
|
+
|
|
254
297
|
## 📄 License
|
|
255
298
|
|
|
256
|
-
[
|
|
299
|
+
[Apache 2.0](LICENSE)
|
|
257
300
|
|
|
258
301
|
---
|
|
259
302
|
|
package/bin/git-ai.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
|
|
8
|
+
// Detect platform and architecture
|
|
9
|
+
const platform = os.platform();
|
|
10
|
+
const arch = os.arch();
|
|
11
|
+
|
|
12
|
+
// Map Node.js platform/arch to our naming convention
|
|
13
|
+
const platformMap = {
|
|
14
|
+
'linux-x64': 'linux-x64',
|
|
15
|
+
'linux-arm64': 'linux-arm64',
|
|
16
|
+
'darwin-x64': 'darwin-x64',
|
|
17
|
+
'darwin-arm64': 'darwin-arm64',
|
|
18
|
+
'win32-x64': 'win32-x64',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const key = `${platform}-${arch}`;
|
|
22
|
+
const platformKey = platformMap[key];
|
|
23
|
+
|
|
24
|
+
if (!platformKey) {
|
|
25
|
+
console.error(`Error: Unsupported platform: ${platform} ${arch}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Find the binary from the platform-specific package
|
|
30
|
+
const packageName = `@dongowu/git-ai-cli-${platformKey}`;
|
|
31
|
+
const nodeModulesPath = path.join(__dirname, '..', 'node_modules');
|
|
32
|
+
const binaryName = platform === 'win32' ? 'git-ai.exe' : 'git-ai';
|
|
33
|
+
const binaryPath = path.join(nodeModulesPath, packageName, 'bin', binaryName);
|
|
34
|
+
|
|
35
|
+
// Check if binary exists
|
|
36
|
+
if (!fs.existsSync(binaryPath)) {
|
|
37
|
+
console.error(`Error: Binary not found at ${binaryPath}`);
|
|
38
|
+
console.error(`Please ensure the ${packageName} package is installed.`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Spawn the binary with all arguments
|
|
43
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
44
|
+
stdio: 'inherit',
|
|
45
|
+
shell: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Forward exit code
|
|
49
|
+
child.on('exit', (code) => {
|
|
50
|
+
process.exit(code || 0);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Handle errors
|
|
54
|
+
child.on('error', (err) => {
|
|
55
|
+
console.error(`Error executing binary: ${err.message}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
package/install.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
// Detect platform and architecture
|
|
8
|
+
const platform = os.platform();
|
|
9
|
+
const arch = os.arch();
|
|
10
|
+
|
|
11
|
+
// Map Node.js platform/arch to our naming convention
|
|
12
|
+
const platformMap = {
|
|
13
|
+
'linux-x64': 'linux-x64',
|
|
14
|
+
'linux-arm64': 'linux-arm64',
|
|
15
|
+
'darwin-x64': 'darwin-x64',
|
|
16
|
+
'darwin-arm64': 'darwin-arm64',
|
|
17
|
+
'win32-x64': 'win32-x64',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const key = `${platform}-${arch}`;
|
|
21
|
+
const platformKey = platformMap[key];
|
|
22
|
+
|
|
23
|
+
if (!platformKey) {
|
|
24
|
+
console.error(`Unsupported platform: ${platform} ${arch}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Try to find the binary from the platform-specific package
|
|
29
|
+
const packageName = `@dongowu/git-ai-cli-${platformKey}`;
|
|
30
|
+
const nodeModulesPath = path.join(__dirname, 'node_modules');
|
|
31
|
+
const binaryName = platform === 'win32' ? 'git-ai.exe' : 'git-ai';
|
|
32
|
+
const binaryPath = path.join(nodeModulesPath, packageName, 'bin', binaryName);
|
|
33
|
+
|
|
34
|
+
// Check if binary exists
|
|
35
|
+
if (!fs.existsSync(binaryPath)) {
|
|
36
|
+
console.warn(`Warning: Binary not found at ${binaryPath}`);
|
|
37
|
+
console.warn(`Please ensure the ${packageName} package is installed.`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Make binary executable on Unix-like systems
|
|
42
|
+
if (process.platform !== 'win32') {
|
|
43
|
+
try {
|
|
44
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.warn(`Warning: Could not make binary executable: ${err.message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(`✅ git-ai binary installed for ${platformKey}`);
|
package/package.json
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dongowu/git-ai-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"main": "dist/cli.js",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Generate git commit messages using AI - Rust Edition",
|
|
5
|
+
"main": "bin/git-ai.cjs",
|
|
7
6
|
"bin": {
|
|
8
|
-
"git-ai": "
|
|
7
|
+
"git-ai": "bin/git-ai.cjs"
|
|
9
8
|
},
|
|
10
9
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"prepublishOnly": "npm run build",
|
|
10
|
+
"postinstall": "node install.cjs",
|
|
11
|
+
"build:rust": "cargo build --release",
|
|
12
|
+
"test": "cargo test",
|
|
15
13
|
"release": "npm version patch && git push --follow-tags",
|
|
16
14
|
"release:minor": "npm version minor && git push --follow-tags",
|
|
17
|
-
"release:major": "npm version major && git push --follow-tags"
|
|
18
|
-
"tag": "npm version patch && git push && git push --tags",
|
|
19
|
-
"tag:minor": "npm version minor && git push && git push --tags",
|
|
20
|
-
"tag:major": "npm version major && git push && git push --tags"
|
|
15
|
+
"release:major": "npm version major && git push --follow-tags"
|
|
21
16
|
},
|
|
22
17
|
"keywords": [
|
|
23
18
|
"git",
|
|
@@ -27,27 +22,31 @@
|
|
|
27
22
|
"openai",
|
|
28
23
|
"deepseek",
|
|
29
24
|
"ollama",
|
|
25
|
+
"rust",
|
|
30
26
|
"style-learning",
|
|
31
27
|
"git-hook",
|
|
32
28
|
"productivity"
|
|
33
29
|
],
|
|
34
|
-
"author": "",
|
|
30
|
+
"author": "dongowu <dongowu@gmail.com>",
|
|
35
31
|
"license": "MIT",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/dongowu/git-ai-cli"
|
|
38
35
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"chalk": "^5.3.0",
|
|
42
|
-
"conf": "^12.0.0",
|
|
43
|
-
"execa": "^8.0.1",
|
|
44
|
-
"inquirer": "^9.2.12",
|
|
45
|
-
"openai": "^4.28.0",
|
|
46
|
-
"ora": "^8.0.1"
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=14.0.0"
|
|
47
38
|
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
39
|
+
"files": [
|
|
40
|
+
"bin/git-ai.cjs",
|
|
41
|
+
"install.cjs",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"optionalDependencies": {
|
|
46
|
+
"@dongowu/git-ai-cli-linux-x64": "2.0.0",
|
|
47
|
+
"@dongowu/git-ai-cli-linux-arm64": "2.0.0",
|
|
48
|
+
"@dongowu/git-ai-cli-darwin-x64": "2.0.0",
|
|
49
|
+
"@dongowu/git-ai-cli-darwin-arm64": "2.0.0",
|
|
50
|
+
"@dongowu/git-ai-cli-win32-x64": "2.0.0"
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(git-ai msg:*)",
|
|
5
|
-
"Bash(git-ai hook:*)",
|
|
6
|
-
"Bash(npm run build:*)",
|
|
7
|
-
"Bash(npm install:*)",
|
|
8
|
-
"Bash(node dist/cli.js hook status:*)",
|
|
9
|
-
"Bash(node dist/cli.js:*)",
|
|
10
|
-
"Bash(git config:*)",
|
|
11
|
-
"Bash(git add:*)",
|
|
12
|
-
"Bash(where:*)",
|
|
13
|
-
"Bash(GIT_EDITOR=\"cat\" git commit:*)",
|
|
14
|
-
"Bash(git reset:*)"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}
|