@dongowu/git-ai-cli 1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ <p align="center">
2
+ <h1 align="center">git-ai-cli</h1>
3
+ <p align="center">
4
+ <strong>AI-powered Git commit message generator</strong>
5
+ </p>
6
+ <p align="center">
7
+ 极速、隐私优先、支持任意模型的 Git 智能提交助手
8
+ </p>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/git-ai-cli"><img src="https://img.shields.io/npm/v/git-ai-cli.svg?style=flat-square" alt="npm version"></a>
13
+ <a href="https://www.npmjs.com/package/git-ai-cli"><img src="https://img.shields.io/npm/dm/git-ai-cli.svg?style=flat-square" alt="npm downloads"></a>
14
+ <a href="https://github.com/dongowu/git-ai-cli/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/git-ai-cli.svg?style=flat-square" alt="license"></a>
15
+ <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/git-ai-cli.svg?style=flat-square" alt="node version"></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="#-快速开始">快速开始</a> •
20
+ <a href="#-特性">特性</a> •
21
+ <a href="#-支持的模型">支持的模型</a> •
22
+ <a href="#english">English</a>
23
+ </p>
24
+
25
+ ---
26
+
27
+ ## 演示
28
+
29
+ ```bash
30
+ $ git add .
31
+ $ git-ai
32
+
33
+ 📁 Staged files:
34
+ src/utils/ai.ts
35
+ src/commands/commit.ts
36
+
37
+ ✨ Generated commit message:
38
+
39
+ feat(ai): add multi-model support for commit generation
40
+
41
+ ? What would you like to do?
42
+ ❯ 🚀 Commit
43
+ 📝 Edit
44
+ 🔄 Regenerate
45
+ ❌ Cancel
46
+ ```
47
+
48
+ ---
49
+
50
+ ## 🚀 快速开始
51
+
52
+ ```bash
53
+ # 安装
54
+ npm install -g git-ai-cli
55
+
56
+ # 配置 (选择 AI 服务商,输入 API Key)
57
+ git-ai config
58
+
59
+ # 使用
60
+ git add .
61
+ git-ai
62
+ ```
63
+
64
+ ## ✨ 特性
65
+
66
+ | 特性 | 描述 |
67
+ |------|------|
68
+ | 🤖 **多模型支持** | DeepSeek、通义千问、智谱GLM、Moonshot、OpenAI 等 10+ 模型 |
69
+ | 🏠 **本地部署** | 支持 Ollama、LM Studio,数据不出本机 |
70
+ | 🔍 **智能 Diff** | 自动过滤 lock 文件,Token 优化截断 |
71
+ | 💬 **交互式** | 提交 / 编辑 / 重新生成 / 取消 |
72
+ | 📝 **规范化** | 遵循 Conventional Commits 标准 |
73
+ | 🌍 **中英双语** | 支持中文和英文输出 |
74
+
75
+ ## 🤖 支持的模型
76
+
77
+ ### 国内大模型(推荐)
78
+
79
+ | 服务商 | 默认模型 | 获取 API Key |
80
+ |--------|----------|--------------|
81
+ | **DeepSeek** (深度求索) | `deepseek-chat` | [platform.deepseek.com](https://platform.deepseek.com/) |
82
+ | **Qwen** (通义千问) | `qwen-turbo` | [dashscope.console.aliyun.com](https://dashscope.console.aliyun.com/) |
83
+ | **Zhipu** (智谱 GLM) | `glm-4-flash` | [open.bigmodel.cn](https://open.bigmodel.cn/) |
84
+ | **Moonshot** (月之暗面) | `moonshot-v1-8k` | [platform.moonshot.cn](https://platform.moonshot.cn/) |
85
+ | **Baichuan** (百川) | `Baichuan4` | [platform.baichuan-ai.com](https://platform.baichuan-ai.com/) |
86
+ | **Yi** (零一万物) | `yi-lightning` | [platform.lingyiwanwu.com](https://platform.lingyiwanwu.com/) |
87
+ | **Doubao** (豆包) | `doubao-lite-4k` | [console.volcengine.com](https://console.volcengine.com/ark) |
88
+ | **Spark** (讯飞星火) | `generalv3.5` | [xinghuo.xfyun.cn](https://xinghuo.xfyun.cn/) |
89
+ | **SiliconFlow** (硅基流动) | `Qwen2.5-7B` | [cloud.siliconflow.cn](https://cloud.siliconflow.cn/) |
90
+
91
+ ### 国际大模型
92
+
93
+ | 服务商 | 默认模型 | 获取 API Key |
94
+ |--------|----------|--------------|
95
+ | **OpenAI** | `gpt-4o-mini` | [platform.openai.com](https://platform.openai.com/) |
96
+
97
+ ### 本地部署(无需 API Key)
98
+
99
+ | 服务商 | 默认模型 | 说明 |
100
+ |--------|----------|------|
101
+ | **Ollama** | `qwen2.5:7b` | [ollama.ai](https://ollama.ai/) |
102
+ | **LM Studio** | `local-model` | [lmstudio.ai](https://lmstudio.ai/) |
103
+
104
+ ## ⚙️ 配置
105
+
106
+ ### 配置命令
107
+
108
+ ```bash
109
+ git-ai config
110
+ ```
111
+
112
+ 交互式配置:
113
+ 1. 选择 AI 服务商
114
+ 2. 输入 API Key(本地模型跳过)
115
+ 3. 选择模型
116
+ 4. 选择输出语言(中文/英文)
117
+ 5. 可选:自定义 System Prompt
118
+
119
+ ### 配置文件位置
120
+
121
+ | 系统 | 路径 |
122
+ |------|------|
123
+ | macOS | `~/Library/Preferences/git-ai-cli-nodejs/config.json` |
124
+ | Linux | `~/.config/git-ai-cli-nodejs/config.json` |
125
+ | Windows | `%APPDATA%/git-ai-cli-nodejs/Config/config.json` |
126
+
127
+ ## 🔧 高级功能
128
+
129
+ ### 自动忽略的文件
130
+
131
+ 以下文件会自动从 Diff 分析中排除,避免浪费 Token:
132
+
133
+ - **Lock 文件**: `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb`
134
+ - **压缩文件**: `*.min.js`, `*.min.css`, `*.map`
135
+ - **构建产物**: `dist/`, `build/`, `.next/`
136
+
137
+ ### 自定义 Prompt
138
+
139
+ 在配置时选择「自定义 System Prompt」,可以:
140
+ - 强制添加 Emoji 前缀
141
+ - 使用特定语言
142
+ - 遵循团队规范
143
+
144
+ ---
145
+
146
+ ## English
147
+
148
+ ### Installation
149
+
150
+ ```bash
151
+ npm install -g git-ai-cli
152
+ ```
153
+
154
+ ### Quick Start
155
+
156
+ ```bash
157
+ # Configure AI provider
158
+ git-ai config
159
+
160
+ # Generate commit message
161
+ git add .
162
+ git-ai
163
+ ```
164
+
165
+ ### Features
166
+
167
+ - **Multi-model**: DeepSeek, Qwen, Zhipu GLM, Moonshot, OpenAI, and 10+ more
168
+ - **Local deployment**: Ollama, LM Studio - keep your data private
169
+ - **Smart diff**: Auto-filter lock files, token optimization
170
+ - **Interactive**: Commit / Edit / Regenerate / Cancel
171
+ - **Conventional Commits**: Standard commit message format
172
+
173
+ ### Workflow
174
+
175
+ ```
176
+ ┌─────────────────┐
177
+ │ git add . │
178
+ └────────┬────────┘
179
+
180
+ ┌─────────────────┐
181
+ │ git-ai │
182
+ └────────┬────────┘
183
+
184
+ ┌─────────────────┐
185
+ │ Analyze Diff │
186
+ └────────┬────────┘
187
+
188
+ ┌─────────────────┐
189
+ │ AI Generate │
190
+ └────────┬────────┘
191
+
192
+ ┌─────────────────────────────┐
193
+ │ Choose Action: │
194
+ │ • Commit │
195
+ │ • Edit │
196
+ │ • Regenerate │
197
+ │ • Cancel │
198
+ └─────────────────────────────┘
199
+ ```
200
+
201
+ ---
202
+
203
+ ## 🤝 Contributing
204
+
205
+ 欢迎贡献代码!请查看 [CONTRIBUTING.md](CONTRIBUTING.md)。
206
+
207
+ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).
208
+
209
+ ## 📄 License
210
+
211
+ [MIT](LICENSE)
212
+
213
+ ---
214
+
215
+ <p align="center">
216
+ Made with ❤️ for developers who hate writing commit messages
217
+ </p>
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { cac } from 'cac';
3
+ import chalk from 'chalk';
4
+ import { runConfig } from './commands/config.js';
5
+ import { runCommit } from './commands/commit.js';
6
+ const cli = cac('git-ai');
7
+ cli
8
+ .command('', 'Generate AI-powered commit message')
9
+ .action(async () => {
10
+ try {
11
+ await runCommit();
12
+ }
13
+ catch (error) {
14
+ const message = error instanceof Error ? error.message : 'Unknown error';
15
+ console.error(chalk.red(`\n❌ Error: ${message}\n`));
16
+ process.exit(1);
17
+ }
18
+ });
19
+ cli
20
+ .command('config', 'Configure AI provider settings')
21
+ .action(async () => {
22
+ try {
23
+ await runConfig();
24
+ }
25
+ catch (error) {
26
+ const message = error instanceof Error ? error.message : 'Unknown error';
27
+ console.error(chalk.red(`\n❌ Error: ${message}\n`));
28
+ process.exit(1);
29
+ }
30
+ });
31
+ cli.help();
32
+ cli.version('1.0.0');
33
+ cli.parse();
34
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;AAE1B,GAAG;KACA,OAAO,CAAC,EAAE,EAAE,oCAAoC,CAAC;KACjD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,SAAS,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,OAAO,IAAI,CAAC,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,GAAG;KACA,OAAO,CAAC,QAAQ,EAAE,gCAAgC,CAAC;KACnD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,SAAS,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,OAAO,IAAI,CAAC,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAErB,GAAG,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function runCommit(): Promise<void>;
2
+ //# sourceMappingURL=commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../src/commands/commit.ts"],"names":[],"mappings":"AAeA,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAyF/C"}
@@ -0,0 +1,123 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { getConfig } from '../utils/config.js';
5
+ import { isGitInstalled, isInGitRepo, getStagedFiles, getFilteredDiff, commit, } from '../utils/git.js';
6
+ import { createAIClient, generateCommitMessage } from '../utils/ai.js';
7
+ export async function runCommit() {
8
+ // Environment checks
9
+ if (!(await isGitInstalled())) {
10
+ console.error(chalk.red('❌ Git is not installed. Please install git first.'));
11
+ process.exit(1);
12
+ }
13
+ if (!(await isInGitRepo())) {
14
+ console.error(chalk.red('❌ Not in a git repository.'));
15
+ process.exit(1);
16
+ }
17
+ const stagedFiles = await getStagedFiles();
18
+ if (stagedFiles.length === 0) {
19
+ console.error(chalk.red('❌ No staged changes found.'));
20
+ console.log(chalk.gray(' Use `git add <files>` to stage your changes first.'));
21
+ process.exit(1);
22
+ }
23
+ // Check config
24
+ const config = getConfig();
25
+ if (!config) {
26
+ console.error(chalk.red('❌ Configuration not found.'));
27
+ console.log(chalk.gray(' Run `git ai config` to set up your AI provider.'));
28
+ process.exit(1);
29
+ }
30
+ // Show staged files
31
+ console.log(chalk.cyan('\n📁 Staged files:'));
32
+ stagedFiles.forEach((file) => {
33
+ console.log(chalk.gray(` ${file}`));
34
+ });
35
+ // Get filtered diff
36
+ const { diff, truncated } = await getFilteredDiff();
37
+ if (truncated) {
38
+ console.log(chalk.yellow('\n⚠️ Diff was truncated due to size limits.'));
39
+ }
40
+ // Create AI client
41
+ const client = createAIClient(config);
42
+ let commitMessage = await generateWithSpinner(client, diff, config);
43
+ // Interactive loop
44
+ while (true) {
45
+ console.log(chalk.green('\n✨ Generated commit message:\n'));
46
+ console.log(chalk.white.bold(` ${commitMessage.split('\n').join('\n ')}`));
47
+ console.log('');
48
+ const { action } = await inquirer.prompt([
49
+ {
50
+ type: 'list',
51
+ name: 'action',
52
+ message: 'What would you like to do?',
53
+ choices: [
54
+ { name: '🚀 Commit', value: 'commit' },
55
+ { name: '📝 Edit', value: 'edit' },
56
+ { name: '🔄 Regenerate', value: 'regenerate' },
57
+ { name: '❌ Cancel', value: 'cancel' },
58
+ ],
59
+ },
60
+ ]);
61
+ if (action === 'commit') {
62
+ await performCommit(commitMessage);
63
+ break;
64
+ }
65
+ else if (action === 'edit') {
66
+ const { editedMessage } = await inquirer.prompt([
67
+ {
68
+ type: 'editor',
69
+ name: 'editedMessage',
70
+ message: 'Edit your commit message:',
71
+ default: commitMessage,
72
+ },
73
+ ]);
74
+ commitMessage = editedMessage.trim();
75
+ if (!commitMessage) {
76
+ console.log(chalk.yellow('⚠️ Commit message cannot be empty.'));
77
+ continue;
78
+ }
79
+ }
80
+ else if (action === 'regenerate') {
81
+ commitMessage = await generateWithSpinner(client, diff, config);
82
+ }
83
+ else {
84
+ console.log(chalk.gray('\n👋 Commit cancelled.\n'));
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ async function generateWithSpinner(client, diff, config) {
90
+ const spinner = ora({
91
+ text: 'Generating commit message...',
92
+ color: 'cyan',
93
+ }).start();
94
+ try {
95
+ const message = await generateCommitMessage(client, diff, config);
96
+ spinner.succeed('Commit message generated!');
97
+ return message;
98
+ }
99
+ catch (error) {
100
+ spinner.fail('Failed to generate commit message');
101
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
102
+ console.error(chalk.red(`\n❌ Error: ${errorMessage}`));
103
+ process.exit(1);
104
+ }
105
+ }
106
+ async function performCommit(message) {
107
+ const spinner = ora({
108
+ text: 'Creating commit...',
109
+ color: 'cyan',
110
+ }).start();
111
+ try {
112
+ await commit(message);
113
+ spinner.succeed('Commit created successfully!');
114
+ console.log(chalk.green('\n🎉 Done!\n'));
115
+ }
116
+ catch (error) {
117
+ spinner.fail('Failed to create commit');
118
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
119
+ console.error(chalk.red(`\n❌ Error: ${errorMessage}`));
120
+ process.exit(1);
121
+ }
122
+ }
123
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.js","sourceRoot":"","sources":["../../src/commands/commit.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE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"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAKA,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAwG/C"}
@@ -0,0 +1,96 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import { setConfig, getConfigPath } from '../utils/config.js';
4
+ import { PROVIDER_PRESETS } from '../types.js';
5
+ export async function runConfig() {
6
+ console.log(chalk.cyan('\n🔧 Git AI Configuration\n'));
7
+ const providerChoices = Object.entries(PROVIDER_PRESETS).map(([key, preset]) => ({
8
+ name: preset.name,
9
+ value: key,
10
+ }));
11
+ const { provider } = await inquirer.prompt([
12
+ {
13
+ type: 'list',
14
+ name: 'provider',
15
+ message: 'Select your AI provider:',
16
+ choices: providerChoices,
17
+ },
18
+ ]);
19
+ const preset = PROVIDER_PRESETS[provider];
20
+ let baseUrl = preset.baseUrl;
21
+ let apiKey = '';
22
+ if (provider === 'custom') {
23
+ const customAnswers = await inquirer.prompt([
24
+ {
25
+ type: 'input',
26
+ name: 'baseUrl',
27
+ message: 'Enter the API base URL:',
28
+ validate: (input) => input.trim() ? true : 'Base URL is required',
29
+ },
30
+ ]);
31
+ baseUrl = customAnswers.baseUrl;
32
+ }
33
+ if (preset.requiresKey) {
34
+ const keyAnswer = await inquirer.prompt([
35
+ {
36
+ type: 'password',
37
+ name: 'apiKey',
38
+ message: 'Enter your API Key:',
39
+ mask: '*',
40
+ validate: (input) => input.trim() ? true : 'API Key is required',
41
+ },
42
+ ]);
43
+ apiKey = keyAnswer.apiKey;
44
+ }
45
+ const { model } = await inquirer.prompt([
46
+ {
47
+ type: 'input',
48
+ name: 'model',
49
+ message: 'Enter the model name:',
50
+ default: preset.defaultModel,
51
+ },
52
+ ]);
53
+ const { locale } = await inquirer.prompt([
54
+ {
55
+ type: 'list',
56
+ name: 'locale',
57
+ message: 'Select output language for commit messages:',
58
+ choices: [
59
+ { name: 'English', value: 'en' },
60
+ { name: '中文', value: 'zh' },
61
+ ],
62
+ },
63
+ ]);
64
+ const { configurePrompt } = await inquirer.prompt([
65
+ {
66
+ type: 'confirm',
67
+ name: 'configurePrompt',
68
+ message: 'Would you like to configure a custom system prompt?',
69
+ default: false,
70
+ },
71
+ ]);
72
+ let customPrompt;
73
+ if (configurePrompt) {
74
+ const promptAnswer = await inquirer.prompt([
75
+ {
76
+ type: 'editor',
77
+ name: 'customPrompt',
78
+ message: 'Enter your custom system prompt:',
79
+ },
80
+ ]);
81
+ customPrompt = promptAnswer.customPrompt.trim() || undefined;
82
+ }
83
+ const config = {
84
+ provider,
85
+ apiKey,
86
+ baseUrl,
87
+ model,
88
+ locale,
89
+ customPrompt,
90
+ };
91
+ setConfig(config);
92
+ console.log(chalk.green('\n✅ Configuration saved successfully!'));
93
+ console.log(chalk.gray(` Config file: ${getConfigPath()}`));
94
+ console.log(chalk.cyan('\n💡 You can now use `git ai` to generate commit messages.\n'));
95
+ }
96
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAC;IAEvD,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/E,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,GAAG;KACX,CAAC,CAAC,CAAC;IAEJ,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AC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,18 @@
1
+ export interface AIConfig {
2
+ provider: string;
3
+ apiKey: string;
4
+ baseUrl: string;
5
+ model: string;
6
+ locale: 'zh' | 'en';
7
+ customPrompt?: string;
8
+ }
9
+ export interface ProviderPreset {
10
+ name: string;
11
+ baseUrl: string;
12
+ defaultModel: string;
13
+ requiresKey: boolean;
14
+ }
15
+ export declare const PROVIDER_PRESETS: Record<string, ProviderPreset>;
16
+ export declare const DIFF_BLACKLIST: string[];
17
+ export declare const MAX_DIFF_LENGTH = 5000;
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAmF3D,CAAC;AAEF,eAAO,MAAM,cAAc,UAW1B,CAAC;AAEF,eAAO,MAAM,eAAe,OAAO,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,98 @@
1
+ export const PROVIDER_PRESETS = {
2
+ // 国内大模型 (推荐)
3
+ deepseek: {
4
+ name: 'DeepSeek (深度求索)',
5
+ baseUrl: 'https://api.deepseek.com/v1',
6
+ defaultModel: 'deepseek-chat',
7
+ requiresKey: true,
8
+ },
9
+ qwen: {
10
+ name: 'Qwen (通义千问)',
11
+ baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
12
+ defaultModel: 'qwen-turbo',
13
+ requiresKey: true,
14
+ },
15
+ zhipu: {
16
+ name: 'Zhipu (智谱 GLM)',
17
+ baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
18
+ defaultModel: 'glm-4-flash',
19
+ requiresKey: true,
20
+ },
21
+ moonshot: {
22
+ name: 'Moonshot (月之暗面 Kimi)',
23
+ baseUrl: 'https://api.moonshot.cn/v1',
24
+ defaultModel: 'moonshot-v1-8k',
25
+ requiresKey: true,
26
+ },
27
+ baichuan: {
28
+ name: 'Baichuan (百川)',
29
+ baseUrl: 'https://api.baichuan-ai.com/v1',
30
+ defaultModel: 'Baichuan4',
31
+ requiresKey: true,
32
+ },
33
+ yi: {
34
+ name: 'Yi (零一万物)',
35
+ baseUrl: 'https://api.lingyiwanwu.com/v1',
36
+ defaultModel: 'yi-lightning',
37
+ requiresKey: true,
38
+ },
39
+ doubao: {
40
+ name: 'Doubao (豆包/字节)',
41
+ baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
42
+ defaultModel: 'doubao-lite-4k',
43
+ requiresKey: true,
44
+ },
45
+ spark: {
46
+ name: 'Spark (讯飞星火)',
47
+ baseUrl: 'https://spark-api-open.xf-yun.com/v1',
48
+ defaultModel: 'generalv3.5',
49
+ requiresKey: true,
50
+ },
51
+ // 国际大模型
52
+ openai: {
53
+ name: 'OpenAI',
54
+ baseUrl: 'https://api.openai.com/v1',
55
+ defaultModel: 'gpt-4o-mini',
56
+ requiresKey: true,
57
+ },
58
+ silicon: {
59
+ name: 'SiliconFlow (硅基流动)',
60
+ baseUrl: 'https://api.siliconflow.cn/v1',
61
+ defaultModel: 'Qwen/Qwen2.5-7B-Instruct',
62
+ requiresKey: true,
63
+ },
64
+ // 本地部署
65
+ ollama: {
66
+ name: 'Ollama (本地部署)',
67
+ baseUrl: 'http://localhost:11434/v1',
68
+ defaultModel: 'qwen2.5:7b',
69
+ requiresKey: false,
70
+ },
71
+ lmstudio: {
72
+ name: 'LM Studio (本地部署)',
73
+ baseUrl: 'http://localhost:1234/v1',
74
+ defaultModel: 'local-model',
75
+ requiresKey: false,
76
+ },
77
+ // 自定义
78
+ custom: {
79
+ name: 'Custom (自定义)',
80
+ baseUrl: '',
81
+ defaultModel: '',
82
+ requiresKey: true,
83
+ },
84
+ };
85
+ export const DIFF_BLACKLIST = [
86
+ 'package-lock.json',
87
+ 'yarn.lock',
88
+ 'pnpm-lock.yaml',
89
+ 'bun.lockb',
90
+ '*.min.js',
91
+ '*.min.css',
92
+ '*.map',
93
+ 'dist/',
94
+ 'build/',
95
+ '.next/',
96
+ ];
97
+ export const MAX_DIFF_LENGTH = 5000;
98
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,gBAAgB,GAAmC;IAC9D,aAAa;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,6BAA6B;QACtC,YAAY,EAAE,eAAe;QAC7B,WAAW,EAAE,IAAI;KAClB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,mDAAmD;QAC5D,YAAY,EAAE,YAAY;QAC1B,WAAW,EAAE,IAAI;KAClB;IACD,KAAK,EAAE;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,sCAAsC;QAC/C,YAAY,EAAE,aAAa;QAC3B,WAAW,EAAE,IAAI;KAClB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,4BAA4B;QACrC,YAAY,EAAE,gBAAgB;QAC9B,WAAW,EAAE,IAAI;KAClB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,eAAe;QACr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AO;IACP,QAAQ;IACR,QAAQ;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC"}
@@ -0,0 +1,5 @@
1
+ import OpenAI from 'openai';
2
+ import type { AIConfig } from '../types.js';
3
+ export declare function createAIClient(config: AIConfig): OpenAI;
4
+ export declare function generateCommitMessage(client: OpenAI, diff: string, config: AIConfig): Promise<string>;
5
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/utils/ai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA8B5C,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAKvD;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,GACf,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
@@ -0,0 +1,52 @@
1
+ import OpenAI from 'openai';
2
+ const DEFAULT_SYSTEM_PROMPT_EN = `You are an expert at writing Git commit messages following the Conventional Commits specification.
3
+
4
+ Based on the git diff provided, generate a concise and descriptive commit message.
5
+
6
+ Rules:
7
+ 1. Use the format: <type>(<scope>): <subject>
8
+ 2. Types: feat, fix, docs, style, refactor, perf, test, chore, build, ci
9
+ 3. Keep the subject line under 50 characters
10
+ 4. Use imperative mood ("add" not "added")
11
+ 5. Don't end the subject line with a period
12
+ 6. If needed, add a blank line followed by a body for more details
13
+
14
+ Only output the commit message, nothing else.`;
15
+ const DEFAULT_SYSTEM_PROMPT_ZH = `你是一个专业的 Git commit message 编写专家,遵循 Conventional Commits 规范。
16
+
17
+ 根据提供的 git diff,生成简洁且描述性的提交信息。
18
+
19
+ 规则:
20
+ 1. 使用格式: <type>(<scope>): <subject>
21
+ 2. type 类型: feat, fix, docs, style, refactor, perf, test, chore, build, ci
22
+ 3. subject 保持在 50 字符以内
23
+ 4. 使用祈使语气
24
+ 5. subject 末尾不要加句号
25
+ 6. 如需要,空一行后添加 body 提供更多细节
26
+
27
+ 只输出 commit message,不要输出其他内容。`;
28
+ export function createAIClient(config) {
29
+ return new OpenAI({
30
+ apiKey: config.apiKey || 'ollama',
31
+ baseURL: config.baseUrl,
32
+ });
33
+ }
34
+ export async function generateCommitMessage(client, diff, config) {
35
+ const systemPrompt = config.customPrompt ||
36
+ (config.locale === 'zh' ? DEFAULT_SYSTEM_PROMPT_ZH : DEFAULT_SYSTEM_PROMPT_EN);
37
+ const response = await client.chat.completions.create({
38
+ model: config.model,
39
+ messages: [
40
+ { role: 'system', content: systemPrompt },
41
+ { role: 'user', content: `Here is the git diff:\n\n${diff}` },
42
+ ],
43
+ temperature: 0.7,
44
+ max_tokens: 500,
45
+ });
46
+ const message = response.choices[0]?.message?.content?.trim();
47
+ if (!message) {
48
+ throw new Error('Failed to generate commit message: empty response');
49
+ }
50
+ return message;
51
+ }
52
+ //# sourceMappingURL=ai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../../src/utils/ai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;8CAYa,CAAC;AAE/C,MAAM,wBAAwB,GAAG;;;;;;;;;;;;6BAYJ,CAAC;AAE9B,MAAM,UAAU,cAAc,CAAC,MAAgB;IAC7C,OAAO,IAAI,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,QAAQ;QACjC,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAAc,EACd,IAAY,EACZ,MAAgB;IAEhB,MAAM,YAAY,GAChB,MAAM,CAAC,YAAY;QACnB,CAAC,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC;IAEjF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACpD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE;YACzC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,IAAI,EAAE,EAAE;SAC9D;QACD,WAAW,EAAE,GAAG;QAChB,UAAU,EAAE,GAAG;KAChB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { AIConfig } from '../types.js';
2
+ export declare function getConfig(): AIConfig | null;
3
+ export declare function setConfig(newConfig: Partial<AIConfig>): void;
4
+ export declare function clearConfig(): void;
5
+ export declare function getConfigPath(): string;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAiC5C,wBAAgB,SAAS,IAAI,QAAQ,GAAG,IAAI,CAa3C;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAM5D;AAED,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
@@ -0,0 +1,59 @@
1
+ import Conf from 'conf';
2
+ const config = new Conf({
3
+ projectName: 'git-ai-cli',
4
+ schema: {
5
+ provider: {
6
+ type: 'string',
7
+ default: '',
8
+ },
9
+ apiKey: {
10
+ type: 'string',
11
+ default: '',
12
+ },
13
+ baseUrl: {
14
+ type: 'string',
15
+ default: '',
16
+ },
17
+ model: {
18
+ type: 'string',
19
+ default: '',
20
+ },
21
+ locale: {
22
+ type: 'string',
23
+ enum: ['zh', 'en'],
24
+ default: 'en',
25
+ },
26
+ customPrompt: {
27
+ type: 'string',
28
+ default: '',
29
+ },
30
+ },
31
+ });
32
+ export function getConfig() {
33
+ const provider = config.get('provider');
34
+ if (!provider) {
35
+ return null;
36
+ }
37
+ return {
38
+ provider: config.get('provider'),
39
+ apiKey: config.get('apiKey'),
40
+ baseUrl: config.get('baseUrl'),
41
+ model: config.get('model'),
42
+ locale: config.get('locale'),
43
+ customPrompt: config.get('customPrompt'),
44
+ };
45
+ }
46
+ export function setConfig(newConfig) {
47
+ for (const [key, value] of Object.entries(newConfig)) {
48
+ if (value !== undefined) {
49
+ config.set(key, value);
50
+ }
51
+ }
52
+ }
53
+ export function clearConfig() {
54
+ config.clear();
55
+ }
56
+ export function getConfigPath() {
57
+ return config.path;
58
+ }
59
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,MAAM,GAAG,IAAI,IAAI,CAAW;IAChC,WAAW,EAAE,YAAY;IACzB,MAAM,EAAE;QACN,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE;SACZ;QACD,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE;SACZ;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE;SACZ;QACD,KAAK,EAAE;YACL,IA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declare function isGitInstalled(): Promise<boolean>;
2
+ export declare function isInGitRepo(): Promise<boolean>;
3
+ export declare function getStagedDiff(): Promise<string>;
4
+ export declare function getStagedFiles(): Promise<string[]>;
5
+ export declare function isBlacklisted(filename: string): boolean;
6
+ export declare function getFilteredDiff(): Promise<{
7
+ diff: string;
8
+ truncated: boolean;
9
+ }>;
10
+ export declare function commit(message: string): Promise<void>;
11
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAGA,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAOvD;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAOpD;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAGrD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAGxD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWvD;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC,CA2BrF;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D"}
@@ -0,0 +1,68 @@
1
+ import { execa } from 'execa';
2
+ import { DIFF_BLACKLIST, MAX_DIFF_LENGTH } from '../types.js';
3
+ export async function isGitInstalled() {
4
+ try {
5
+ await execa('git', ['--version']);
6
+ return true;
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }
12
+ export async function isInGitRepo() {
13
+ try {
14
+ await execa('git', ['rev-parse', '--is-inside-work-tree']);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ export async function getStagedDiff() {
22
+ const { stdout } = await execa('git', ['diff', '--cached']);
23
+ return stdout;
24
+ }
25
+ export async function getStagedFiles() {
26
+ const { stdout } = await execa('git', ['diff', '--cached', '--name-only']);
27
+ return stdout.split('\n').filter(Boolean);
28
+ }
29
+ export function isBlacklisted(filename) {
30
+ return DIFF_BLACKLIST.some((pattern) => {
31
+ if (pattern.endsWith('/')) {
32
+ return filename.startsWith(pattern) || filename.includes(`/${pattern}`);
33
+ }
34
+ if (pattern.startsWith('*.')) {
35
+ const ext = pattern.slice(1);
36
+ return filename.endsWith(ext);
37
+ }
38
+ return filename === pattern || filename.endsWith(`/${pattern}`);
39
+ });
40
+ }
41
+ export async function getFilteredDiff() {
42
+ const files = await getStagedFiles();
43
+ const diffParts = [];
44
+ for (const file of files) {
45
+ if (isBlacklisted(file)) {
46
+ diffParts.push(`[File: ${file}] (content ignored - blacklisted)`);
47
+ continue;
48
+ }
49
+ try {
50
+ const { stdout } = await execa('git', ['diff', '--cached', '--', file]);
51
+ diffParts.push(stdout);
52
+ }
53
+ catch {
54
+ diffParts.push(`[File: ${file}] (unable to get diff)`);
55
+ }
56
+ }
57
+ let fullDiff = diffParts.join('\n');
58
+ let truncated = false;
59
+ if (fullDiff.length > MAX_DIFF_LENGTH) {
60
+ fullDiff = fullDiff.slice(0, MAX_DIFF_LENGTH) + '\n\n...[Diff Truncated]';
61
+ truncated = true;
62
+ }
63
+ return { diff: fullDiff, truncated };
64
+ }
65
+ export async function commit(message) {
66
+ await execa('git', ['commit', '-m', message]);
67
+ }
68
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,C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AAE,OAAO,CAAC,CAAC,CAAC;AAChD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@dongowu/git-ai-cli",
3
+ "version": "1.0.0",
4
+ "description": "Fast, privacy-first, bring-your-own-model Git commit message generator",
5
+ "type": "module",
6
+ "main": "dist/cli.js",
7
+ "bin": {
8
+ "git-ai": "dist/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch",
13
+ "start": "node dist/cli.js",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "git",
18
+ "ai",
19
+ "commit",
20
+ "cli",
21
+ "openai",
22
+ "deepseek",
23
+ "ollama"
24
+ ],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "engines": {
28
+ "node": ">=18.0.0"
29
+ },
30
+ "dependencies": {
31
+ "cac": "^6.7.14",
32
+ "chalk": "^5.3.0",
33
+ "conf": "^12.0.0",
34
+ "execa": "^8.0.1",
35
+ "inquirer": "^9.2.12",
36
+ "openai": "^4.28.0",
37
+ "ora": "^8.0.1"
38
+ },
39
+ "devDependencies": {
40
+ "@types/inquirer": "^9.0.7",
41
+ "@types/node": "^20.11.0",
42
+ "typescript": "^5.3.3"
43
+ }
44
+ }