@dongowu/git-ai-cli 1.0.19 → 1.0.21

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 (63) hide show
  1. package/README.md +171 -94
  2. package/README_EN.md +179 -84
  3. package/dist/cli.js +2 -135
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli_main.d.ts +2 -0
  6. package/dist/cli_main.d.ts.map +1 -0
  7. package/dist/cli_main.js +255 -0
  8. package/dist/cli_main.js.map +1 -0
  9. package/dist/commands/branch.d.ts +11 -0
  10. package/dist/commands/branch.d.ts.map +1 -0
  11. package/dist/commands/branch.js +279 -0
  12. package/dist/commands/branch.js.map +1 -0
  13. package/dist/commands/commit.d.ts.map +1 -1
  14. package/dist/commands/commit.js +52 -9
  15. package/dist/commands/commit.js.map +1 -1
  16. package/dist/commands/config_manage.d.ts +14 -0
  17. package/dist/commands/config_manage.d.ts.map +1 -0
  18. package/dist/commands/config_manage.js +394 -0
  19. package/dist/commands/config_manage.js.map +1 -0
  20. package/dist/commands/hook.d.ts.map +1 -1
  21. package/dist/commands/hook.js +124 -6
  22. package/dist/commands/hook.js.map +1 -1
  23. package/dist/commands/msg.d.ts +1 -0
  24. package/dist/commands/msg.d.ts.map +1 -1
  25. package/dist/commands/msg.js +40 -6
  26. package/dist/commands/msg.js.map +1 -1
  27. package/dist/commands/pr.d.ts +8 -0
  28. package/dist/commands/pr.d.ts.map +1 -0
  29. package/dist/commands/pr.js +96 -0
  30. package/dist/commands/pr.js.map +1 -0
  31. package/dist/commands/release.d.ts +8 -0
  32. package/dist/commands/release.d.ts.map +1 -0
  33. package/dist/commands/release.js +95 -0
  34. package/dist/commands/release.js.map +1 -0
  35. package/dist/commands/report.d.ts +7 -2
  36. package/dist/commands/report.d.ts.map +1 -1
  37. package/dist/commands/report.js +99 -15
  38. package/dist/commands/report.js.map +1 -1
  39. package/dist/types.d.ts +26 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js.map +1 -1
  42. package/dist/utils/agent_lite.d.ts +5 -0
  43. package/dist/utils/agent_lite.d.ts.map +1 -0
  44. package/dist/utils/agent_lite.js +263 -0
  45. package/dist/utils/agent_lite.js.map +1 -0
  46. package/dist/utils/ai.d.ts +22 -0
  47. package/dist/utils/ai.d.ts.map +1 -1
  48. package/dist/utils/ai.js +852 -37
  49. package/dist/utils/ai.js.map +1 -1
  50. package/dist/utils/config.d.ts +5 -0
  51. package/dist/utils/config.d.ts.map +1 -1
  52. package/dist/utils/config.js +157 -5
  53. package/dist/utils/config.js.map +1 -1
  54. package/dist/utils/git.d.ts +17 -0
  55. package/dist/utils/git.d.ts.map +1 -1
  56. package/dist/utils/git.js +275 -49
  57. package/dist/utils/git.js.map +1 -1
  58. package/dist/utils/update.d.ts +3 -1
  59. package/dist/utils/update.d.ts.map +1 -1
  60. package/dist/utils/update.js +53 -2
  61. package/dist/utils/update.js.map +1 -1
  62. package/package.json +1 -1
  63. package/release_notes.md +3 -2
package/README.md CHANGED
@@ -18,144 +18,223 @@
18
18
  <p align="center">
19
19
  <a href="./README_EN.md">English</a> •
20
20
  <a href="#-快速开始">快速开始</a> •
21
- <a href="#-核心特性">核心特性</a> •
22
- <a href="#-git-flow-最佳实践">Git Flow</a> •
23
- <a href="#-智能周报">智能周报</a>
21
+ <a href="#-使用指南推荐流程">使用指南</a> •
22
+ <a href="#-配置">配置</a> •
23
+ <a href="#-命令速查">命令</a>
24
24
  </p>
25
25
 
26
26
  ---
27
27
 
28
- **git-ai-cli** 不仅仅是一个 Commit Message 生成器,它是你的**全能 AI 开发助手**。它能读懂你的代码 Diff,看懂你的分支意图,甚至帮你写好周报。
28
+ **git-ai-cli** 不只是 Commit Message 生成器,它是你的**全能 AI 开发助手**:理解 diff、识别分支意图、统一团队规范、自动生成周报/PR/Release Notes。
29
29
 
30
30
  ---
31
31
 
32
32
  ## 🚀 快速开始
33
33
 
34
34
  ```bash
35
- # 1. 安装
35
+ # 1) 安装
36
36
  npm install -g @dongowu/git-ai-cli
37
37
 
38
- # 2. 初始化 (自动探测本地模型或配置 API)
38
+ # 2) 初始化 (自动探测本地模型或配置 API)
39
39
  git-ai init
40
40
 
41
- # 3. 使用
41
+ # 3) 使用
42
42
  git add .
43
43
  git-ai
44
44
  ```
45
45
 
46
46
  ---
47
47
 
48
- ## 核心特性
49
-
50
- ### 1. 🇨🇳 极致本土化 & 隐私优先
51
- - **DeepSeek/Qwen 深度优化**:内置专家级提示词,针对中文代码语境优化,不只是翻译 Diff,而是理解“意图”。
52
- - **Ollama 零配置**:自动探测本地运行的 Ollama 模型(如 `llama3`, `deepseek-coder`),无需手动输入模型名。数据完全不出网,绝对安全。
48
+ ## 使用指南(推荐流程)
53
49
 
54
- ### 2. 🧠 上下文感知 (Context Aware)
55
- - **风格学习**:自动分析您最近的 10 次提交记录,模仿您的语气、格式(如 Emoji 使用习惯)和语言风格。
56
- - **分支感知**:读取当前分支名(如 `feat/user-login`, `fix/JIRA-123`),生成包含 Issue ID 或功能模块的规范提交信息。
50
+ 1) **安装与初始化**
51
+ ```bash
52
+ npm install -g @dongowu/git-ai-cli
53
+ git-ai init
54
+ ```
57
55
 
58
- ### 3. 🤖 Agent 智能体 (New)
59
- 从单纯的“文本生成”进化为“智能代码专家”。
60
- - **Smart Diff**: 遇到超大变更不再瞎编。Agent 会自动分析统计数据,只读取核心文件的代码,彻底解决 Token 限制问题。
61
- - **影响分析 (Impact Analysis)**: 修改了核心 API?Agent 会主动**搜索整个代码库**(`git grep`),检查调用方是否同步修改,并在 Commit Body 中提示潜在风险。
62
- - **Git Flow 护航**: 在 `release/*` 或 `hotfix/*` 分支上自动开启深度检查,守卫生产环境。
56
+ 2) **团队配置(推荐)**:在项目根目录写 `.git-ai.json`
57
+ ```json
58
+ {
59
+ "provider": "deepseek",
60
+ "baseUrl": "https://api.deepseek.com/v1",
61
+ "model": "deepseek-reasoner",
62
+ "agentModel": "deepseek-chat",
63
+ "locale": "en",
64
+ "enableFooter": false,
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
+ }
83
+ }
84
+ ```
63
85
 
64
- ### 4. ⚙️ 工程化配置 (Project Config)
65
- - **项目级配置**:支持在项目根目录创建 `.git-ai.json`,团队统一共享模型和 Prompt 配置(优先级 > 全局配置)。
66
- - **智能忽略**:支持 `.git-aiignore` 文件,排除自动生成文件(如 `package-lock.json`)或大文件,节省 Token 并提高准确性。
86
+ 3) **日常提交**
87
+ ```bash
88
+ git add .
89
+ git-ai
90
+ ```
67
91
 
68
- ### 4. 🪝 无感集成 (Git Hook)
69
- - **零打扰**:安装 Hook 后,只需执行 `git commit`(不带 `-m`),AI 自动填充消息并打开编辑器。
70
- - **兼容性**:完美兼容现有 Git 工作流,支持 `git commit --no-verify` 跳过。
92
+ 4) **Hook 无感集成(强烈推荐)**
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
+ ```
71
100
 
72
- ### 4. 📊 智能周报 (AI Report)
73
- - **一键生成**:`git-ai report` 自动分析你最近的代码提交。
74
- - **价值导向**:将零碎的 Commit 转化为结构化的“核心产出”、“问题修复”和“技术优化”报告。
101
+ 5) **脚本 / CI**
102
+ ```bash
103
+ git-ai msg --json
104
+ ```
75
105
 
76
- ---
106
+ 6) **创建分支(交互式)**
107
+ ```bash
108
+ git-ai branch
109
+ ```
77
110
 
78
- ## ⚙️ 高级配置
111
+ 7) **PR / Release / Report**
112
+ ```bash
113
+ # PR 描述
114
+ git-ai pr --base main --head HEAD
79
115
 
80
- ### 项目级配置文件 `.git-ai.json`
81
- 在项目根目录创建此文件,可覆盖全局设置,方便团队统一规范:
116
+ # Release Notes
117
+ git-ai release --from v1.0.0 --to HEAD
82
118
 
83
- ```json
84
- {
85
- "model": "deepseek-coder",
86
- "temperature": 0.5,
87
- "locale": "zh-CN",
88
- "customPrompt": "Always start with an emoji."
89
- }
119
+ # 周报
120
+ git-ai report --days 7
90
121
  ```
91
122
 
92
- ### 忽略文件 `.git-aiignore`
93
- 在项目根目录创建,用于排除不想发送给 AI 的文件(语法同 `.gitignore`):
123
+ ---
94
124
 
95
- ```text
96
- package-lock.json
97
- dist/
98
- *.min.js
99
- ```
125
+ ## ✨ 核心特性
126
+
127
+ - **DeepSeek/Qwen 深度优化**:理解意图而不是简单翻译 diff
128
+ - **本地模型隐私优先**:Ollama / LM Studio 即插即用
129
+ - **上下文感知**:分支规则、提交风格学习、智能 scope
130
+ - **Agent 智能体**:大改动时自动做影响分析
131
+ - **团队规则**:规则模板 + 强校验(policy)
132
+ - **Hook 集成**:无感生成提交信息
133
+ - **AI 报告**:日报/周报/PR/Release Notes 一键生成
100
134
 
101
135
  ---
102
136
 
103
- ## 📖 使用方式
137
+ ## ⚙️ 配置
138
+
139
+ ### 项目级配置 `.git-ai.json`
140
+ - `provider / baseUrl / model / agentModel`
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 设置(可脚本化)
160
+ ```bash
161
+ # 查看当前生效配置
162
+ git-ai config get --json
104
163
 
105
- ### 场景一:交互式提交 (Interactive)
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"
106
168
 
107
- ```bash
108
- git add .
109
- git-ai
110
- ```
169
+ # 设置规则(JSON 或 @文件)
170
+ git-ai config set rules '{"types":["feat","fix"]}'
171
+ git-ai config set rules @rules.json --local
111
172
 
112
- ### 场景二:Git Flow 最佳实践 (Hook) 🌟 推荐
173
+ # 设置分支规则
174
+ git-ai config set branch '{"types":["feat","fix"],"pattern":"{type}/{issue?}{name}"}'
175
+ ```
113
176
 
114
- 这是最流畅的体验。你不需要改变任何习惯,只需一次安装:
177
+ ---
115
178
 
116
- ```bash
117
- # 在当前项目安装
118
- git-ai hook install
179
+ ## 🛠 命令速查
119
180
 
120
- # 或者全局安装(所有项目生效)
121
- git-ai hook install --global
122
- ```
181
+ | 命令 | 说明 |
182
+ |------|------|
183
+ | `git-ai init` | 初始化配置 |
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 |
123
193
 
124
- **之后只需:**
125
- ```bash
126
- git checkout -b feature/awesome-login
127
- # ... 写代码 ...
128
- git add .
129
- git commit # ✨ AI 自动帮你写好了 "feat(login): implement awesome login logic"
130
- ```
194
+ ---
131
195
 
132
- ### 场景三:生成周报 (Report)
196
+ ## 环境变量(常用)
197
+
198
+ - `GIT_AI_PROVIDER` / `GIT_AI_BASE_URL` / `GIT_AI_MODEL` / `GIT_AI_AGENT_MODEL`
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`
133
211
 
134
- 每逢周五不想写周报?
212
+ ---
135
213
 
136
- ```bash
137
- # 生成本周日报/周报
138
- git-ai report
214
+ ## 🧩 忽略文件 `.git-aiignore`
139
215
 
140
- # 生成最近 30 天的汇报
141
- git-ai report --days 30
216
+ ```text
217
+ package-lock.json
218
+ dist/
219
+ *.min.js
142
220
  ```
143
221
 
222
+ 同时兼容 OpenCommit 的 `.opencommitignore`。
223
+
144
224
  ---
145
225
 
146
- ## 🛠 命令速查
226
+ ## ❓常见问题
227
+
228
+ **1) 401 / API Key 无效**
229
+ - 先看配置:`git-ai config get --json --local`
230
+ - 检查环境变量是否覆盖
231
+
232
+ **2) Diff 被截断**
233
+ - 用 `.git-aiignore` 忽略大文件
234
+ - 或设置 `GIT_AI_MAX_DIFF_CHARS`
147
235
 
148
- | 命令 | 别名 | 说明 |
149
- |------|------|------|
150
- | `git-ai init` | `config` | **初始化配置**(设置模型、Key、语言) |
151
- | `git-ai` | | 交互式生成并提交 |
152
- | `git-ai -a` | | **Agent 模式** (深度分析 & 影响检查) |
153
- | `git-ai -y` | | 跳过确认直接提交 |
154
- | `git-ai -n 3` | | 生成 3 条候选消息 |
155
- | `git-ai hook install` | | **安装 Git Hook** (支持 `--global`) |
156
- | `git-ai hook remove` | | 移除 Git Hook |
157
- | `git-ai report` | | **生成 AI 周报** (支持 `--days`) |
158
- | `git-ai msg` | | 仅输出消息(供脚本调用) |
236
+ **3) Agent 自动回退**
237
+ - 设置 `GIT_AI_DEBUG=1` 查看原因
159
238
 
160
239
  ---
161
240
 
@@ -163,17 +242,15 @@ git-ai report --days 30
163
242
 
164
243
  | 类型 | 服务商 | 优势 | 配置方式 |
165
244
  |------|--------|------|----------|
166
- | **本地隐私** | **Ollama** | 免费、离线、绝对隐私 | `git-ai init` 自动探测 |
245
+ | **本地隐私** | **Ollama** | 免费、离线、隐私 | `git-ai init` 自动探测 |
167
246
  | | **LM Studio** | 兼容性好 | 手动输入 URL |
168
- | **国内高速** | **DeepSeek** | **性价比之王**,代码能力极强 | API Key |
169
- | | **通义千问** | 阿里生态,长文本能力强 | API Key |
170
- | | **智谱/Moonshot** | 国内主流模型 | API Key |
247
+ | **国内高速** | **DeepSeek** | 性价比高 | API Key |
248
+ | | **通义千问** | 长文本能力强 | API Key |
249
+ | | **智谱/Moonshot** | 国内主流 | API Key |
171
250
  | **国际通用** | **OpenAI** | GPT-4o 基准能力 | API Key |
172
251
 
173
252
  ---
174
253
 
175
-
176
-
177
254
  ## 📄 License
178
255
 
179
256
  [MIT](LICENSE)
@@ -184,4 +261,4 @@ git-ai report --days 30
184
261
  Made with ❤️ by git-ai team
185
262
  <br>
186
263
  <sub>🤖 Generated by git-ai 🚀</sub>
187
- </p>
264
+ </p>
package/README_EN.md CHANGED
@@ -18,141 +18,236 @@
18
18
  <p align="center">
19
19
  <a href="./README.md">中文文档</a> •
20
20
  <a href="#-quick-start">Quick Start</a> •
21
- <a href="#-features">Features</a> •
22
- <a href="#-usage">Usage</a> •
23
- <a href="#-configuration">Configuration</a>
21
+ <a href="#-usage-guide-recommended">Usage</a> •
22
+ <a href="#-configuration">Configuration</a> •
23
+ <a href="#-command-reference">Commands</a>
24
24
  </p>
25
25
 
26
26
  ---
27
27
 
28
- **git-ai-cli** is more than just a commit message generator. It's your **AI Development Assistant**. It understands your code diffs, recognizes your branch intent, and even writes your weekly reports.
28
+ **git-ai-cli** is more than a commit message generator. It understands diffs, enforces team rules, and generates reports, PR descriptions, and release notes.
29
29
 
30
30
  ---
31
31
 
32
32
  ## 🚀 Quick Start
33
33
 
34
34
  ```bash
35
- # 1. Install
35
+ # 1) Install
36
36
  npm install -g @dongowu/git-ai-cli
37
37
 
38
- # 2. Initialize (Auto-detects local models or configures API)
38
+ # 2) Initialize (auto-detect local models or configure API)
39
39
  git-ai init
40
40
 
41
- # 3. Use
41
+ # 3) Use
42
42
  git add .
43
43
  git-ai
44
44
  ```
45
45
 
46
46
  ---
47
47
 
48
- ## Features
48
+ ## Usage Guide (Recommended)
49
49
 
50
- ### 1. 🔒 Privacy First & Local Models
51
- - **Ollama Zero-Config**: Automatically detects locally running Ollama models (like `llama3`, `deepseek-coder`). No manual setup required. Your data never leaves your machine.
52
- - **DeepSeek/OpenAI**: Built-in support for popular API providers with optimized prompts.
50
+ 1) **Install & Init**
51
+ ```bash
52
+ npm install -g @dongowu/git-ai-cli
53
+ git-ai init
54
+ ```
53
55
 
54
- ### 2. 🧠 Context Aware
55
- - **Style Learning**: Automatically analyzes your recent 10 commits to mimic your personal tone, format (e.g., emojis), and language style.
56
- - **Branch Awareness**: Reads your current branch name (e.g., `feat/user-login`, `fix/JIRA-123`) to generate semantic commits with Issue IDs or scopes.
56
+ 2) **Team config (recommended)**: create `.git-ai.json` in project root
57
+ ```json
58
+ {
59
+ "provider": "deepseek",
60
+ "baseUrl": "https://api.deepseek.com/v1",
61
+ "model": "deepseek-reasoner",
62
+ "agentModel": "deepseek-chat",
63
+ "locale": "en",
64
+ "enableFooter": false,
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
+ }
83
+ }
84
+ ```
57
85
 
58
- ### 3. 🤖 Agent Intelligence (New)
59
- Evolving from a text generator to a code expert.
60
- - **Smart Diff**: No more truncated diffs. The Agent automatically analyzes file stats and reads only the critical source code, solving token limits for large refactors.
61
- - **Impact Analysis**: Changing a core API? The Agent proactively searches your codebase (`git grep`) to find usages and warns you about potential breaking changes in the commit body.
62
- - **Git Flow Guard**: Automatically enables deep analysis on `release/*` or `hotfix/*` branches to protect production code.
86
+ 3) **Daily commit**
87
+ ```bash
88
+ git add .
89
+ git-ai
90
+ ```
63
91
 
64
- ### 4. ⚙️ Engineering Ready
65
- - **Project Config**: Create a `.git-ai.json` in your project root to share settings (model, prompts) with your team.
66
- - **Smart Ignore**: Use `.git-aiignore` to exclude auto-generated files (like `package-lock.json`) or large files to save tokens and improve accuracy.
92
+ 4) **Hook (recommended)**
93
+ ```bash
94
+ git-ai hook install
95
+ # Block commit on failure (optional)
96
+ GIT_AI_HOOK_STRICT=1 git commit
97
+ # Disable fallback message (optional)
98
+ GIT_AI_HOOK_FALLBACK=0 git commit
99
+ ```
67
100
 
68
- ### 4. 🪝 Seamless Integration (Git Hook)
69
- - **Zero Distraction**: After installing the hook, just run `git commit` (without `-m`). AI automatically fills in the message and opens your editor.
70
- - **Compatibility**: Perfectly compatible with existing Git workflows. Supports `git commit --no-verify`.
101
+ 5) **Scripts / CI**
102
+ ```bash
103
+ git-ai msg --json
104
+ ```
105
+
106
+ 6) **Create branch (interactive)**
107
+ ```bash
108
+ git-ai branch
109
+ ```
110
+
111
+ 7) **PR / Release / Report**
112
+ ```bash
113
+ # PR description
114
+ git-ai pr --base main --head HEAD
115
+
116
+ # Release notes
117
+ git-ai release --from v1.0.0 --to HEAD
71
118
 
72
- ### 5. 📊 AI Reports
73
- - **One-Click Generation**: `git-ai report` analyzes your recent commits.
74
- - **Value Driven**: Transforms fragmented commits into structured reports highlighting "Core Outputs", "Bug Fixes", and "Technical Improvements".
119
+ # Weekly report
120
+ git-ai report --days 7
121
+ ```
122
+
123
+ ---
124
+
125
+ ## ✨ Features
126
+
127
+ - **DeepSeek/Qwen optimized**: intent-focused prompts
128
+ - **Local privacy**: Ollama / LM Studio support
129
+ - **Context aware**: branch rules, style learning, smart scope
130
+ - **Agent mode**: impact analysis for large diffs
131
+ - **Team rules**: presets + strict policy
132
+ - **Git hooks**: zero-friction commits
133
+ - **AI reports**: weekly report / PR / release notes
75
134
 
76
135
  ---
77
136
 
78
137
  ## ⚙️ Configuration
79
138
 
80
- ### Project-Level Config `.git-ai.json`
81
- Create this file in your project root to override global settings:
139
+ ### Project-level config `.git-ai.json`
140
+ - `provider / baseUrl / model / agentModel`
141
+ - `locale`: `zh` / `en`
142
+ - `outputFormat`: `text` / `json`
143
+ - `rulesPreset`: `conventional` / `angular` / `minimal`
144
+ - `fallbackModels`: fallback list when the primary model fails
145
+ - `policy.strict`: block commit when rules are violated
146
+ - `rules`: types/scopes/length/issue rules
147
+ - `branch`: branch naming rules (types/pattern/length)
148
+
149
+ ### Rules & Policy
150
+ - `issuePattern`: regex for issue IDs
151
+ - `issuePlacement`: `scope | subject | footer`
152
+ - `requireIssue`: enforce issue id
153
+ - `policy.strict`: block commit when invalid
154
+ - `branch.pattern`: branch template (e.g., `{type}/{issue?}{name}`)
155
+ - `branch.types`: branch type list
156
+ - `branch.issueSeparator`: issue separator (default `-`)
157
+ - `branch.nameMaxLength`: max length for name
158
+
159
+ ### CLI config
160
+ ```bash
161
+ # Show effective config
162
+ git-ai config get --json
82
163
 
83
- ```json
84
- {
85
- "model": "deepseek-coder",
86
- "temperature": 0.5,
87
- "locale": "en",
88
- "customPrompt": "Always start with an emoji."
89
- }
90
- ```
164
+ # Preset / policy / fallback
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"
91
168
 
92
- ### Ignore File `.git-aiignore`
93
- Exclude specific files from AI analysis (syntax similar to `.gitignore`):
169
+ # Rules (JSON or @file)
170
+ git-ai config set rules '{"types":["feat","fix"]}'
171
+ git-ai config set rules @rules.json --local
94
172
 
95
- ```text
96
- package-lock.json
97
- dist/
98
- *.min.js
173
+ # Branch rules
174
+ git-ai config set branch '{"types":["feat","fix"],"pattern":"{type}/{issue?}{name}"}'
99
175
  ```
100
176
 
101
177
  ---
102
178
 
103
- ## 📖 Usage
179
+ ## 🛠 Command Reference
104
180
 
105
- ### Scenario 1: Interactive
106
- ```bash
107
- git add .
108
- git-ai
109
- ```
181
+ | Command | Description |
182
+ |--------|-------------|
183
+ | `git-ai init` | Initialize config |
184
+ | `git-ai config get/set/describe` | Config management |
185
+ | `git-ai` / `git-ai commit` | Interactive commit |
186
+ | `git-ai -a` | Agent mode |
187
+ | `git-ai msg` | Message only (scripts/hooks) |
188
+ | `git-ai branch` | Create branch interactively |
189
+ | `git-ai hook install/remove` | Hook management |
190
+ | `git-ai report` | Weekly report |
191
+ | `git-ai pr` | PR description |
192
+ | `git-ai release` | Release notes |
110
193
 
111
- ### Scenario 2: Git Hook (Recommended) 🌟
112
- The smoothest experience. Install once, use forever.
194
+ ---
113
195
 
114
- ```bash
115
- # Install for current project
116
- git-ai hook install
196
+ ## ⚡ Environment Variables
197
+
198
+ - `GIT_AI_PROVIDER` / `GIT_AI_BASE_URL` / `GIT_AI_MODEL` / `GIT_AI_AGENT_MODEL`
199
+ - `GIT_AI_API_KEY` (also `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`
117
211
 
118
- # Or install globally (for all projects)
119
- git-ai hook install --global
120
- ```
212
+ ---
121
213
 
122
- **Then just run:**
123
- ```bash
124
- git checkout -b feature/awesome-login
125
- # ... write code ...
126
- git add .
127
- git commit # ✨ AI generates "feat(login): implement awesome login logic"
214
+ ## 🧩 Ignore File `.git-aiignore`
215
+
216
+ ```text
217
+ package-lock.json
218
+ dist/
219
+ *.min.js
128
220
  ```
129
221
 
130
- ### Scenario 3: Generate Reports
131
- Hate writing weekly reports?
222
+ Also compatible with `.opencommitignore`.
132
223
 
133
- ```bash
134
- # Generate report for this week
135
- git-ai report
224
+ ---
136
225
 
137
- # Generate report for the last 30 days
138
- git-ai report --days 30
139
- ```
226
+ ## ❓Troubleshooting
227
+
228
+ **1) 401 / Invalid API key**
229
+ - `git-ai config get --json --local`
230
+ - Check env overrides
231
+
232
+ **2) Diff truncated**
233
+ - Ignore large files via `.git-aiignore`
234
+ - Or set `GIT_AI_MAX_DIFF_CHARS`
235
+
236
+ **3) Agent falls back**
237
+ - Set `GIT_AI_DEBUG=1` to see reasons
140
238
 
141
239
  ---
142
240
 
143
- ## 🛠 Command Reference
241
+ ## 🤖 Supported Models
144
242
 
145
- | Command | Alias | Description |
146
- |---------|-------|-------------|
147
- | `git-ai init` | `config` | **Initialize Config** (Provider, Key, Language) |
148
- | `git-ai` | | Interactive generation & commit |
149
- | `git-ai -a` | | **Agent Mode** (Deep analysis & Impact check) |
150
- | `git-ai -y` | | Skip confirmation and commit directly |
151
- | `git-ai -n 3` | | Generate 3 options to choose from |
152
- | `git-ai -l en` | | Force language (en/zh) |
153
- | `git-ai hook install` | | **Install Git Hook** (supports `--global`) |
154
- | `git-ai report` | | **Generate AI Report** (supports `--days`) |
155
- | `git-ai msg` | | Generate message only (stdout for scripts) |
243
+ | Type | Provider | Notes | Setup |
244
+ |------|----------|------|-------|
245
+ | **Local** | **Ollama** | Offline & private | `git-ai init` auto-detect |
246
+ | | **LM Studio** | Good compatibility | Manual URL |
247
+ | **CN** | **DeepSeek** | High value | API Key |
248
+ | | **Qwen** | Long context | API Key |
249
+ | | **Zhipu/Moonshot** | Popular in CN | API Key |
250
+ | **Global** | **OpenAI** | Baseline GPT-4o | API Key |
156
251
 
157
252
  ---
158
253