ai-git-tools 2.0.23 → 2.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-git-tools",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -91,7 +91,7 @@ function getAllChanges() {
91
91
  async function analyzeAndGroupChanges(changes, config) {
92
92
  console.log('🤖 正在使用 AI 分析變更並分組...\n');
93
93
 
94
- // 準備變更摘要
94
+ // 準備變更摘要(限制每個檔案的 diff 長度)
95
95
  const maxDiffPerFile = Math.floor(config.ai.maxDiffLength / Math.max(changes.length, 1));
96
96
  const changeSummary = changes
97
97
  .map((change, index) => {
@@ -159,7 +159,7 @@ ${changeSummary}
159
159
 
160
160
  請只輸出 JSON,不要其他文字。`;
161
161
 
162
- const response = await AIClient.sendAndWait(prompt, config.ai.model);
162
+ const response = await AIClient.sendAndWait(prompt, config.ai.model, config.ai.maxRetries);
163
163
 
164
164
  try {
165
165
  return AIClient.parseJSON(response);
@@ -208,7 +208,7 @@ feat(auth): 新增使用者登入功能
208
208
  - 新增登入頁面 UI
209
209
  - 整合 JWT 認證機制`;
210
210
 
211
- const response = await AIClient.sendAndWait(prompt, config.ai.model);
211
+ const response = await AIClient.sendAndWait(prompt, config.ai.model, config.ai.maxRetries);
212
212
 
213
213
  // 清理可能的 markdown code block 標記
214
214
  let commitMessage = response.trim();
@@ -336,10 +336,46 @@ export async function commitAllCommand() {
336
336
  process.exit(1);
337
337
  }
338
338
 
339
+ // 驗證所有檔案都被包含在分組中
340
+ const groupedIndices = new Set();
341
+ groups.forEach((group) => {
342
+ group.file_indices.forEach((index) => {
343
+ groupedIndices.add(index);
344
+ });
345
+ });
346
+
347
+ const ungroupedIndices = [];
348
+ for (let i = 0; i < changes.length; i++) {
349
+ if (!groupedIndices.has(i)) {
350
+ ungroupedIndices.push(i);
351
+ }
352
+ }
353
+
354
+ // 如果有檔案未被分組,創建一個 "其他變更" 群組
355
+ if (ungroupedIndices.length > 0) {
356
+ console.log(`\n⚠️ 發現 ${ungroupedIndices.length} 個未分組的檔案,將自動歸類:`);
357
+ ungroupedIndices.forEach((index) => {
358
+ console.log(` - ${changes[index].filePath}`);
359
+ });
360
+
361
+ groups.push({
362
+ group_name: '其他變更',
363
+ commit_type: 'chore',
364
+ commit_scope: 'misc',
365
+ file_indices: ungroupedIndices,
366
+ description: '未能自動分類的其他變更',
367
+ });
368
+ }
369
+
339
370
  logger.success(`AI 分析完成,共分為 ${groups.length} 個群組:\n`);
340
371
  groups.forEach((group, index) => {
341
372
  console.log(` 群組 ${index + 1}: ${group.group_name} (${group.commit_type})`);
342
373
  console.log(` └─ 包含 ${group.file_indices.length} 個檔案`);
374
+ if (config.output.verbose) {
375
+ group.file_indices.forEach((fileIndex) => {
376
+ console.log(` - [${fileIndex}] ${changes[fileIndex].filePath}`);
377
+ });
378
+ }
343
379
  });
344
380
 
345
381
  // 3. 依序提交每個群組
@@ -352,6 +388,14 @@ export async function commitAllCommand() {
352
388
  const group = groups[i];
353
389
  const groupFiles = group.file_indices.map((index) => changes[index]);
354
390
 
391
+ // 驗證檔案索引是否有效
392
+ const invalidIndices = group.file_indices.filter((idx) => idx >= changes.length);
393
+ if (invalidIndices.length > 0) {
394
+ console.error(`\n❌ 群組 ${i + 1} 包含無效的檔案索引:`, invalidIndices);
395
+ console.log(` 跳過此群組: ${group.group_name}`);
396
+ continue;
397
+ }
398
+
355
399
  const success = await commitGroup(group, groupFiles, config);
356
400
  if (success) {
357
401
  successCount++;
@@ -363,9 +407,18 @@ export async function commitAllCommand() {
363
407
  logger.success(`完成!成功提交 ${successCount}/${groups.length} 個群組`);
364
408
  logger.separator('=', 60);
365
409
 
410
+ if (successCount < groups.length) {
411
+ const failedCount = groups.length - successCount;
412
+ console.log(`\n⚠️ 有 ${failedCount} 個群組提交失敗`);
413
+ }
414
+
366
415
  // 顯示最近的幾個 commits
367
- console.log('\n📋 最近的 commits:');
368
- execSync(`git log -${successCount} --oneline`, { stdio: 'inherit' });
416
+ if (successCount > 0) {
417
+ console.log('\n📋 最近的 commits:');
418
+ execSync(`git log -${successCount} --oneline`, { stdio: 'inherit' });
419
+ } else {
420
+ console.log('\n⚠️ 沒有成功的提交');
421
+ }
369
422
 
370
423
  // Reset 任何剩餘的 staged 檔案
371
424
  try {