ai-git-tools 2.0.42 → 2.0.44

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.42",
3
+ "version": "2.0.44",
4
4
  "description": "AI-powered Git automation tools for commit messages and PR generation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -28,23 +28,45 @@ export class CodeGenerator {
28
28
  async generateCodeFiles(issueData, projectRoot = process.cwd()) {
29
29
  const prompt = this._buildPrompt(issueData, projectRoot);
30
30
 
31
- console.log(' 🤖 調用 AI 生成代碼框架...');
31
+ console.log(' 🤖 調用 AI 生成代碼框架(最多等待 3 分鐘)...');
32
32
 
33
33
  let response;
34
34
  try {
35
+ // 代碼生成需要較長時間,使用 180 秒 timeout
35
36
  response = await AIClient.sendAndWait(
36
37
  prompt,
37
38
  this.model,
38
- this.config.maxRetries || 3
39
+ this.config.maxRetries || 3,
40
+ 180_000
39
41
  );
40
42
  } catch (error) {
43
+ // 顯示完整錯誤訊息方便除錯
41
44
  console.warn(` ⚠️ AI 調用失敗:${error.message}`);
45
+ if (error.cause) console.warn(` 原因:${error.cause}`);
46
+ return [];
47
+ }
48
+
49
+ if (!response) {
50
+ console.warn(' ⚠️ AI 回傳空回應');
42
51
  return [];
43
52
  }
44
53
 
45
54
  // 解析 AI 回應
46
55
  const files = this._parseResponse(response);
47
- console.log(` 生成 ${files.length} 個檔案`);
56
+ if (files.length === 0) {
57
+ console.warn(' ⚠️ AI 未回傳任何檔案(可能 JSON 格式有誤)');
58
+ if (process.env.AUTODEV_DEBUG) {
59
+ console.log(' --- AI 原始回應 ---');
60
+ console.log(response.slice(0, 500));
61
+ console.log(' (設定 AUTODEV_DEBUG=1 可看到完整回應)');
62
+ }
63
+ } else {
64
+ console.log(` ✅ AI 規劃生成 ${files.length} 個檔案:`);
65
+ files.forEach((f) => {
66
+ const icon = f.filePath.includes('.test.') || f.filePath.includes('__tests__') ? '🧪' : '📄';
67
+ console.log(` ${icon} ${f.filePath}`);
68
+ });
69
+ }
48
70
  return files;
49
71
  }
50
72
 
@@ -63,7 +85,8 @@ export class CodeGenerator {
63
85
 
64
86
  for (const file of files) {
65
87
  if (file.type === 'skip') {
66
- skipped.push(`${file.filePath} (${file.reason})`);
88
+ console.log(` ⏭️ 跳過 ${file.filePath}${file.reason ? ` (${file.reason})` : ''}`);
89
+ skipped.push(`${file.filePath}${file.reason ? ` (${file.reason})` : ''}`);
67
90
  continue;
68
91
  }
69
92
 
@@ -76,17 +99,21 @@ export class CodeGenerator {
76
99
  mkdirSync(dir, { recursive: true });
77
100
  }
78
101
  } catch (e) {
79
- console.warn(` ⚠️ 無法建立目錄 ${dir}`);
102
+ console.warn(` ⚠️ 無法建立目錄 ${dir}:${e.message}`);
80
103
  skipped.push(file.filePath);
81
104
  continue;
82
105
  }
83
106
 
84
- // 寫入檔案
107
+ // 寫入檔案(即時顯示)
85
108
  try {
109
+ const isTest = file.filePath.includes('.test.') || file.filePath.includes('__tests__');
110
+ const icon = isTest ? '🧪' : '📄';
111
+ const existed = existsSync(fullPath);
86
112
  writeFileSync(fullPath, file.content, 'utf-8');
87
113
  written.push(file.filePath);
114
+ console.log(` ${icon} ${existed ? '更新' : '新建'} ${file.filePath}`);
88
115
  } catch (e) {
89
- console.warn(` ⚠️ 無法寫入 ${file.filePath}`);
116
+ console.warn(` ⚠️ 無法寫入 ${file.filePath}:${e.message}`);
90
117
  skipped.push(file.filePath);
91
118
  }
92
119
  }
@@ -196,15 +196,28 @@ export class AutodevWorkflow {
196
196
  return [];
197
197
  }
198
198
 
199
- // 寫入檔案
199
+ // 寫入檔案(每個檔案會即時顯示名稱)
200
200
  const { written, skipped } = await this.codeGenerator.writeFiles(files, projectRoot);
201
- console.log(` ✅ 已寫入 ${written.length} 個檔案`);
201
+
202
202
  if (skipped.length > 0) {
203
203
  console.warn(` ⚠️ 跳過 ${skipped.length} 個檔案`);
204
204
  }
205
205
 
206
- if (options.verbose) {
207
- written.forEach((f) => console.log(` 新建: ${f}`));
206
+ // 顯示 git diff --stat 讓用戶看到實際變動
207
+ if (written.length > 0) {
208
+ console.log(`\n ✅ 共寫入 ${written.length} 個檔案,git 變動摘要:`);
209
+ try {
210
+ const { execSync } = await import('child_process');
211
+ const stat = execSync('git diff --stat HEAD 2>/dev/null || git status --short', {
212
+ cwd: projectRoot,
213
+ encoding: 'utf-8',
214
+ }).trim();
215
+ if (stat) {
216
+ stat.split('\n').forEach((line) => console.log(` ${line}`));
217
+ }
218
+ } catch (_) {
219
+ // git diff 失敗不影響流程
220
+ }
208
221
  }
209
222
 
210
223
  return written;