ai-git-tools 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,7 +29,9 @@ npx ai-git-tools commit
29
29
 
30
30
  ```bash
31
31
  npm install -g ai-git-tools
32
- gitai init
32
+ ai-git-tools init
33
+ # 或使用 npx(無需全域安裝)
34
+ npx ai-git-tools init
33
35
  ```
34
36
 
35
37
  ### 專案內安裝
@@ -40,9 +42,9 @@ npm install --save-dev ai-git-tools
40
42
  # 加入 package.json scripts
41
43
  {
42
44
  "scripts": {
43
- "commit": "gitai commit",
44
- "commit:all": "gitai commit-all",
45
- "pr": "gitai pr"
45
+ "commit": "ai-git-tools commit",
46
+ "commit:all": "ai-git-tools commit-all",
47
+ "pr": "ai-git-tools pr"
46
48
  }
47
49
  }
48
50
  ```
@@ -52,7 +54,7 @@ npm install --save-dev ai-git-tools
52
54
  ### 1. 初始化配置
53
55
 
54
56
  \`\`\`bash
55
- npx gitai init
57
+ npx ai-git-tools init
56
58
  \`\`\`
57
59
 
58
60
  這會在您的專案根目錄創建 \`.ai-git-config.js\` 配置檔。
@@ -65,7 +67,7 @@ npx gitai init
65
67
 
66
68
  \`\`\`bash
67
69
  git add src/components/Button.jsx
68
- npx gitai commit
70
+ npx ai-git-tools commit
69
71
  \`\`\`
70
72
 
71
73
  #### 智能批量 Commit
@@ -73,15 +75,15 @@ npx gitai commit
73
75
  自動分析所有變更並分組提交:
74
76
 
75
77
  \`\`\`bash
76
- npx gitai commit-all
78
+ npx ai-git-tools commit-all
77
79
  # 或簡寫
78
- npx gitai ca
80
+ npx ai-git-tools ca
79
81
  \`\`\`
80
82
 
81
83
  #### 創建 PR
82
84
 
83
85
  \`\`\`bash
84
- npx gitai pr
86
+ npx ai-git-tools pr
85
87
  \`\`\`
86
88
 
87
89
  #### 完整工作流程
@@ -89,9 +91,9 @@ npx gitai pr
89
91
  Commit + PR 一次完成:
90
92
 
91
93
  \`\`\`bash
92
- npx gitai workflow
94
+ npx ai-git-tools workflow
93
95
  # 或簡寫
94
- npx gitai wf
96
+ npx ai-git-tools wf
95
97
  \`\`\`
96
98
 
97
99
  ## 📖 命令說明
@@ -101,7 +103,7 @@ npx gitai wf
101
103
  初始化配置檔案
102
104
 
103
105
  \`\`\`bash
104
- npx gitai init
106
+ npx ai-git-tools init
105
107
  \`\`\`
106
108
 
107
109
  ### \`gitai commit\`
@@ -109,7 +111,7 @@ npx gitai init
109
111
  為已 staged 的變更生成並執行 commit
110
112
 
111
113
  \`\`\`bash
112
- npx gitai commit [選項]
114
+ npx ai-git-tools commit [選項]
113
115
 
114
116
  選項:
115
117
  -m, --model <model> 指定 AI 模型
@@ -121,9 +123,9 @@ npx gitai commit [選項]
121
123
  **範例:**
122
124
 
123
125
  \`\`\`bash
124
- npx gitai commit
125
- npx gitai commit --model claude-haiku-4.5
126
- npx gitai commit --verbose
126
+ npx ai-git-tools commit
127
+ npx ai-git-tools commit --model claude-haiku-4.5
128
+ npx ai-git-tools commit --verbose
127
129
  \`\`\`
128
130
 
129
131
  ### \`gitai commit-all\` (別名: \`ca\`)
@@ -131,7 +133,7 @@ npx gitai commit --verbose
131
133
  智能分析所有變更並自動分組提交
132
134
 
133
135
  \`\`\`bash
134
- npx gitai commit-all [選項]
136
+ npx ai-git-tools commit-all [選項]
135
137
 
136
138
  選項:
137
139
  -m, --model <model> 指定 AI 模型
@@ -143,8 +145,8 @@ npx gitai commit-all [選項]
143
145
  **範例:**
144
146
 
145
147
  \`\`\`bash
146
- npx gitai commit-all
147
- npx gitai ca --verbose
148
+ npx ai-git-tools commit-all
149
+ npx ai-git-tools ca --verbose
148
150
  \`\`\`
149
151
 
150
152
  ### \`gitai pr\`
@@ -152,7 +154,7 @@ npx gitai ca --verbose
152
154
  生成 PR 並發送到 GitHub
153
155
 
154
156
  \`\`\`bash
155
- npx gitai pr [選項]
157
+ npx ai-git-tools pr [選項]
156
158
 
157
159
  選項:
158
160
  -b, --base <branch> 目標分支
@@ -170,10 +172,10 @@ npx gitai pr [選項]
170
172
  **範例:**
171
173
 
172
174
  \`\`\`bash
173
- npx gitai pr
174
- npx gitai pr --draft
175
- npx gitai pr --base main --auto-reviewers
176
- npx gitai pr --preview
175
+ npx ai-git-tools pr
176
+ npx ai-git-tools pr --draft
177
+ npx ai-git-tools pr --base main --auto-reviewers
178
+ npx ai-git-tools pr --preview
177
179
  \`\`\`
178
180
 
179
181
  ### \`gitai workflow\` (別名: \`wf\`)
@@ -181,7 +183,7 @@ npx gitai pr --preview
181
183
  完整工作流程:commit-all + pr
182
184
 
183
185
  \`\`\`bash
184
- npx gitai workflow [選項]
186
+ npx ai-git-tools workflow [選項]
185
187
 
186
188
  選項:
187
189
  -m, --model <model> 指定 AI 模型
@@ -195,8 +197,8 @@ npx gitai workflow [選項]
195
197
  **範例:**
196
198
 
197
199
  \`\`\`bash
198
- npx gitai workflow
199
- npx gitai wf --draft --auto-reviewers
200
+ npx ai-git-tools workflow
201
+ npx ai-git-tools wf --draft --auto-reviewers
200
202
  \`\`\`
201
203
 
202
204
  ## ⚙️ 配置
@@ -251,7 +253,7 @@ export default {
251
253
 
252
254
  \`\`\`bash
253
255
  git add src/components/LoginForm.jsx
254
- npx gitai commit
256
+ npx ai-git-tools commit
255
257
  # ✅ 自動生成:feat(auth): 新增登入表單元件
256
258
  \`\`\`
257
259
 
@@ -260,7 +262,7 @@ npx gitai commit
260
262
  累積了多個功能變更,想要分開提交:
261
263
 
262
264
  \`\`\`bash
263
- npx gitai commit-all
265
+ npx ai-git-tools commit-all
264
266
  # AI 會自動分析並分組:
265
267
  # ✅ Commit 1: feat(auth): 新增登入功能
266
268
  # ✅ Commit 2: fix(ui): 修正導航列顯示問題
@@ -270,7 +272,7 @@ npx gitai commit-all
270
272
  ### 場景 3:快速發 PR
271
273
 
272
274
  \`\`\`bash
273
- npx gitai pr --auto-reviewers --auto-labels
275
+ npx ai-git-tools pr --auto-reviewers --auto-labels
274
276
  # ✅ 自動生成完整的 PR 標題和描述
275
277
  # ✅ 建議合適的 reviewers
276
278
  # ✅ 添加相關的 labels
@@ -279,7 +281,7 @@ npx gitai pr --auto-reviewers --auto-labels
279
281
  ### 場景 4:完整工作流程
280
282
 
281
283
  \`\`\`bash
282
- npx gitai workflow
284
+ npx ai-git-tools workflow
283
285
  # ✅ 自動分析並提交所有變更
284
286
  # ✅ 創建 PR 並添加 reviewers 和 labels
285
287
  \`\`\`
package/bin/cli.js CHANGED
@@ -17,9 +17,9 @@ import { initCommand } from '../src/commands/init.js';
17
17
  const program = new Command();
18
18
 
19
19
  program
20
- .name('gitai')
20
+ .name('ai-git-tools')
21
21
  .description('AI-powered Git automation tools')
22
- .version('1.0.0');
22
+ .version('1.0.4');
23
23
 
24
24
  // Init 命令
25
25
  program
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "gitai": "./bin/cli.js",
9
8
  "ai-git-tools": "./bin/cli.js"
10
9
  },
11
10
  "scripts": {
@@ -149,9 +149,23 @@ async function commitGroup(group, files, config, logger) {
149
149
  GitOperations.resetStaged();
150
150
 
151
151
  // Add 這組的檔案
152
+ const addedFiles = [];
152
153
  for (const file of files) {
153
154
  console.log(` ├─ ${file.filePath}`);
154
- GitOperations.addFile(file.filePath);
155
+ try {
156
+ GitOperations.addFile(file.filePath);
157
+ addedFiles.push(file.filePath);
158
+ } catch (error) {
159
+ logger.warn(`無法 add 檔案 ${file.filePath}: ${error.message}`);
160
+ // 繼續處理其他檔案,不要中斷
161
+ continue;
162
+ }
163
+ }
164
+
165
+ // 如果沒有成功 add 任何檔案,跳過這個群組
166
+ if (addedFiles.length === 0) {
167
+ logger.warn('沒有檔案被成功 add,跳過此群組');
168
+ return false;
155
169
  }
156
170
 
157
171
  // 生成 commit message
@@ -240,9 +254,31 @@ export async function commitAllCommand(options) {
240
254
  let successCount = 0;
241
255
  for (let i = 0; i < groups.length; i++) {
242
256
  const group = groups[i];
243
- const groupFiles = group.file_indices.map(index => changes[index]);
257
+
258
+ // 驗證並過濾有效的檔案索引
259
+ const validFiles = group.file_indices
260
+ .filter(index => {
261
+ if (index < 0 || index >= changes.length) {
262
+ logger.warn(`無效的檔案索引: ${index}`);
263
+ return false;
264
+ }
265
+ return true;
266
+ })
267
+ .map(index => changes[index])
268
+ .filter(file => {
269
+ if (!file || !file.filePath) {
270
+ logger.warn('檔案資訊不完整,已跳過');
271
+ return false;
272
+ }
273
+ return true;
274
+ });
275
+
276
+ if (validFiles.length === 0) {
277
+ logger.warn(`群組 ${i + 1} 沒有有效的檔案,跳過`);
278
+ continue;
279
+ }
244
280
 
245
- const success = await commitGroup(group, groupFiles, config, logger);
281
+ const success = await commitGroup(group, validFiles, config, logger);
246
282
  if (success) {
247
283
  successCount++;
248
284
  }
@@ -154,6 +154,23 @@ export class GitOperations {
154
154
  * Add 檔案
155
155
  */
156
156
  static addFile(filePath) {
157
+ // 檢查檔案是否存在(對於新檔案和已修改檔案)
158
+ if (!existsSync(filePath)) {
159
+ // 可能是 git 追蹤的檔案但在工作目錄中不存在
160
+ // 嘗試使用 git ls-files 確認
161
+ try {
162
+ const tracked = GitOperations.exec(`git ls-files "${filePath}"`, {
163
+ silent: true,
164
+ throwOnError: false
165
+ });
166
+ if (!tracked || !tracked.trim()) {
167
+ throw new Error(`檔案不存在: ${filePath}`);
168
+ }
169
+ } catch (error) {
170
+ throw new Error(`檔案不存在或無法追蹤: ${filePath}`);
171
+ }
172
+ }
173
+
157
174
  GitOperations.exec(`git add "${filePath}"`);
158
175
  }
159
176