vite-plugin-ai-diagnostic 1.0.3 → 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/dist/index.mjs CHANGED
@@ -1,18 +1,17 @@
1
- import fs from 'fs';
2
- import { StateGraph, START, END } from '@langchain/langgraph';
3
- import { ChatOpenAI } from '@langchain/openai';
4
- import { SystemMessage, HumanMessage } from '@langchain/core/messages';
5
- import { extractSourceFile } from 'vite-plugin-ai-shared';
6
- import path from 'path';
7
-
8
1
  // src/index.ts
2
+ import fs2 from "fs";
3
+
4
+ // src/langgraph.ts
5
+ import { StateGraph, END, START } from "@langchain/langgraph";
6
+ import { ChatOpenAI } from "@langchain/openai";
7
+ import { HumanMessage, SystemMessage } from "@langchain/core/messages";
9
8
  var DiagnosticGraph = class {
10
9
  constructor(apiKey, apiUrl, model = "gpt-4", maxRetries = 3) {
11
10
  this.maxRetries = maxRetries;
12
- console.log("\u{1F527} [LangGraph] \u521D\u59CB\u5316 LLM...");
13
- console.log("\u{1F4DD} [\u914D\u7F6E] \u6A21\u578B:", model);
14
- console.log("\u{1F4DD} [\u914D\u7F6E] API URL:", apiUrl);
15
- console.log("\u{1F4DD} [\u914D\u7F6E] API Key:", apiKey ? "\u5DF2\u914D\u7F6E" : "\u672A\u914D\u7F6E");
11
+ console.log("🔧 [LangGraph] 初始化 LLM...");
12
+ console.log("📝 [配置] 模型:", model);
13
+ console.log("📝 [配置] API URL:", apiUrl);
14
+ console.log("📝 [配置] API Key:", apiKey ? "已配置" : "未配置");
16
15
  this.llm = new ChatOpenAI({
17
16
  openAIApiKey: apiKey,
18
17
  configuration: {
@@ -45,21 +44,21 @@ var DiagnosticGraph = class {
45
44
  return workflow.compile();
46
45
  }
47
46
  async analyzeNode(state) {
48
- console.log("\u{1F50D} [LangGraph] \u6B63\u5728\u5206\u6790\u9519\u8BEF...");
47
+ console.log("🔍 [LangGraph] 正在分析错误...");
49
48
  const systemPrompt = new SystemMessage(
50
- "\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684\u524D\u7AEF\u4EE3\u7801\u8BCA\u65AD\u4E13\u5BB6\uFF0C\u7CBE\u901A Vue3\u3001TypeScript\u3001Vite \u548C uni-app\u3002\u8BF7\u7B80\u6D01\u660E\u4E86\u5730\u5206\u6790\u95EE\u9898\u3002"
49
+ "你是一个专业的前端代码诊断专家,精通 Vue3、TypeScript、Vite uni-app。请简洁明了地分析问题。"
51
50
  );
52
51
  const userPrompt = new HumanMessage(`
53
- \u8BF7\u5206\u6790\u4EE5\u4E0B\u6784\u5EFA\u9519\u8BEF\uFF1A
52
+ 请分析以下构建错误:
54
53
 
55
- \u9519\u8BEF\u7C7B\u578B: ${state.error.type}
56
- \u9519\u8BEF\u4FE1\u606F: ${state.error.message}
57
- \u6587\u4EF6\u8DEF\u5F84: ${state.error.file || "\u672A\u77E5"}
54
+ 错误类型: ${state.error.type}
55
+ 错误信息: ${state.error.message}
56
+ 文件路径: ${state.error.file || "未知"}
58
57
 
59
- \u8BF7\u7B80\u6D01\u5730\u8BF4\u660E\uFF083-5\u53E5\u8BDD\uFF09\uFF1A
60
- 1. \u9519\u8BEF\u7684\u6839\u672C\u539F\u56E0
61
- 2. \u5F71\u54CD\u8303\u56F4
62
- 3. \u4E25\u91CD\u7A0B\u5EA6
58
+ 请简洁地说明(3-5句话):
59
+ 1. 错误的根本原因
60
+ 2. 影响范围
61
+ 3. 严重程度
63
62
  `);
64
63
  const response = await this.llm.invoke([systemPrompt, userPrompt]);
65
64
  const analysis = response.content.toString();
@@ -69,25 +68,25 @@ var DiagnosticGraph = class {
69
68
  };
70
69
  }
71
70
  async suggestNode(state) {
72
- console.log("\u{1F4A1} [LangGraph] \u6B63\u5728\u751F\u6210\u4FEE\u590D\u5EFA\u8BAE...");
71
+ console.log("💡 [LangGraph] 正在生成修复建议...");
73
72
  const userPrompt = new HumanMessage(`
74
- \u57FA\u4E8E\u4EE5\u4E0B\u9519\u8BEF\u5206\u6790\uFF0C\u8BF7\u63D0\u4F9B\u5177\u4F53\u7684\u4FEE\u590D\u5EFA\u8BAE\uFF1A
73
+ 基于以下错误分析,请提供具体的修复建议:
75
74
 
76
- \u9519\u8BEF\u5206\u6790\uFF1A
75
+ 错误分析:
77
76
  ${state.analysis}
78
77
 
79
- \u9519\u8BEF\u8BE6\u60C5\uFF1A
80
- - \u7C7B\u578B: ${state.error.type}
81
- - \u4FE1\u606F: ${state.error.message}
82
- - \u6587\u4EF6: ${state.error.file || "\u672A\u77E5"}
78
+ 错误详情:
79
+ - 类型: ${state.error.type}
80
+ - 信息: ${state.error.message}
81
+ - 文件: ${state.error.file || "未知"}
83
82
 
84
- \u8BF7\u7B80\u6D01\u5730\u63D0\u4F9B\uFF1A
85
- 1. \u5177\u4F53\u7684\u4FEE\u590D\u6B65\u9AA4\uFF083-5\u6B65\u5373\u53EF\uFF09
86
- 2. \u9700\u8981\u4FEE\u6539\u7684\u4EE3\u7801\u4F4D\u7F6E\uFF08\u884C\u53F7\uFF09
87
- 3. \u4FEE\u6539\u540E\u7684\u4EE3\u7801\u793A\u4F8B\uFF08\u53EA\u663E\u793A\u5173\u952E\u90E8\u5206\uFF09
88
- 4. \u4E00\u53E5\u8BDD\u9884\u9632\u5EFA\u8BAE
83
+ 请简洁地提供:
84
+ 1. 具体的修复步骤(3-5步即可)
85
+ 2. 需要修改的代码位置(行号)
86
+ 3. 修改后的代码示例(只显示关键部分)
87
+ 4. 一句话预防建议
89
88
 
90
- \u6CE8\u610F\uFF1A\u8BF7\u76F4\u63A5\u7ED9\u51FA\u5EFA\u8BAE\uFF0C\u4E0D\u8981\u91CD\u590D\u9519\u8BEF\u5206\u6790\u7684\u5185\u5BB9\u3002
89
+ 注意:请直接给出建议,不要重复错误分析的内容。
91
90
  `);
92
91
  const response = await this.llm.invoke([...state.messages, userPrompt]);
93
92
  const suggestion = response.content.toString();
@@ -177,12 +176,12 @@ ${state.analysis}
177
176
  messages: []
178
177
  };
179
178
  try {
180
- console.log("\u{1F680} [LangGraph] \u542F\u52A8\u8BCA\u65AD\u5DE5\u4F5C\u6D41...\n");
179
+ console.log("🚀 [LangGraph] 启动诊断工作流...\n");
181
180
  const result = await this.graph.invoke(initialState);
182
- console.log("\u2728 [LangGraph] \u8BCA\u65AD\u5DE5\u4F5C\u6D41\u5B8C\u6210\n");
181
+ console.log(" [LangGraph] 诊断工作流完成\n");
183
182
  return result;
184
183
  } catch (error2) {
185
- console.error("\u274C [LangGraph] \u5DE5\u4F5C\u6D41\u6267\u884C\u5931\u8D25:", error2.message);
184
+ console.error(" [LangGraph] 工作流执行失败:", error2.message);
186
185
  throw error2;
187
186
  }
188
187
  }
@@ -202,8 +201,8 @@ var AIErrorDiagnostic = class {
202
201
  async diagnose(error, autoFix = false) {
203
202
  if (!this.options.apiKey) {
204
203
  return {
205
- analysis: "\u672A\u914D\u7F6E API Key\uFF0C\u65E0\u6CD5\u4F7F\u7528 AI \u8BCA\u65AD\u529F\u80FD",
206
- suggestion: "\u8BF7\u5728 .env \u6587\u4EF6\u4E2D\u914D\u7F6E OPENAI_API_KEY",
204
+ analysis: "未配置 API Key,无法使用 AI 诊断功能",
205
+ suggestion: "请在 .env 文件中配置 OPENAI_API_KEY",
207
206
  fixedCode: void 0,
208
207
  filePath: void 0
209
208
  };
@@ -218,10 +217,10 @@ var AIErrorDiagnostic = class {
218
217
  filePath: void 0
219
218
  };
220
219
  } catch (error2) {
221
- console.error("\u274C AI \u8BCA\u65AD\u5931\u8D25\uFF1A", error2.message);
220
+ console.error(" AI 诊断失败:", error2.message);
222
221
  return {
223
- analysis: `\u8BCA\u65AD\u8FC7\u7A0B\u51FA\u9519: ${error2.message}`,
224
- suggestion: "\u8BF7\u68C0\u67E5 API \u914D\u7F6E\u548C\u7F51\u7EDC\u8FDE\u63A5",
222
+ analysis: `诊断过程出错: ${error2.message}`,
223
+ suggestion: "请检查 API 配置和网络连接",
225
224
  fixedCode: void 0,
226
225
  filePath: void 0
227
226
  };
@@ -243,6 +242,13 @@ var AIErrorDiagnostic = class {
243
242
  // }
244
243
  // }
245
244
  };
245
+
246
+ // src/index.ts
247
+ import { extractSourceFile } from "vite-plugin-ai-shared";
248
+
249
+ // src/reporter.ts
250
+ import fs from "fs";
251
+ import path from "path";
246
252
  var DiagnosticReporter = class {
247
253
  /**
248
254
  * 生成报告(根据配置生成多种格式)
@@ -268,7 +274,7 @@ var DiagnosticReporter = class {
268
274
  <head>
269
275
  <meta charset="UTF-8">
270
276
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
271
- <title>AI \u8BCA\u65AD\u62A5\u544A</title>
277
+ <title>AI 诊断报告</title>
272
278
  <style>
273
279
  * { margin: 0; padding: 0; box-sizing: border-box; }
274
280
  body {
@@ -427,48 +433,48 @@ var DiagnosticReporter = class {
427
433
  <body>
428
434
  <div class="container">
429
435
  <div class="header">
430
- <h1>\u{1F916} AI \u8BCA\u65AD\u62A5\u544A</h1>
431
- <div class="time">\u751F\u6210\u65F6\u95F4: ${report.timestamp}</div>
436
+ <h1>🤖 AI 诊断报告</h1>
437
+ <div class="time">生成时间: ${report.timestamp}</div>
432
438
  </div>
433
439
 
434
440
  <div class="content">
435
- <!-- \u9519\u8BEF\u4FE1\u606F -->
441
+ <!-- 错误信息 -->
436
442
  <div class="section">
437
- <div class="section-title">\u274C \u9519\u8BEF\u4FE1\u606F</div>
443
+ <div class="section-title">❌ 错误信息</div>
438
444
  <div class="error-box">
439
445
  <span class="error-type">${report.error.type}</span>
440
446
  <div class="error-message">${this.escapeHtml(
441
447
  report.error.message
442
448
  )}</div>
443
- <div class="error-file">\u{1F4C2} ${report.error.file}</div>
449
+ <div class="error-file">📂 ${report.error.file}</div>
444
450
  ${report.error.stack ? `<div class="stack-trace">${this.escapeHtml(
445
451
  report.error.stack
446
452
  )}</div>` : ""}
447
453
  </div>
448
454
  </div>
449
455
 
450
- <!-- AI \u5206\u6790 -->
456
+ <!-- AI 分析 -->
451
457
  <div class="section">
452
- <div class="section-title">\u{1F50D} AI \u5206\u6790</div>
458
+ <div class="section-title">🔍 AI 分析</div>
453
459
  <div class="analysis-box">
454
460
  ${this.formatText(report.analysis)}
455
461
  </div>
456
462
  </div>
457
463
 
458
- <!-- \u4FEE\u590D\u5EFA\u8BAE -->
464
+ <!-- 修复建议 -->
459
465
  <div class="section">
460
- <div class="section-title">\u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE</div>
466
+ <div class="section-title">💡 修复建议</div>
461
467
  <div class="suggestion-box">
462
468
  ${this.formatText(report.suggestion)}
463
469
  </div>
464
470
  </div>
465
471
 
466
- <!-- \u4FEE\u590D\u72B6\u6001 -->
472
+ <!-- 修复状态 -->
467
473
  <div class="section">
468
- <div class="section-title">\u{1F527} \u4FEE\u590D\u72B6\u6001</div>
469
- ${report.fixed ? `<div class="fixed-badge">\u2705 \u5DF2\u81EA\u52A8\u4FEE\u590D</div>
470
- <div style="margin-top: 10px; color: #666;">\u4FEE\u590D\u6587\u4EF6: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">\u26A0\uFE0F \u672A\u81EA\u52A8\u4FEE\u590D</div>
471
- <div style="margin-top: 10px; color: #666;">\u8BF7\u6839\u636E\u4E0A\u8FF0\u5EFA\u8BAE\u624B\u52A8\u4FEE\u590D</div>`}
474
+ <div class="section-title">🔧 修复状态</div>
475
+ ${report.fixed ? `<div class="fixed-badge">✅ 已自动修复</div>
476
+ <div style="margin-top: 10px; color: #666;">修复文件: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">⚠️ 未自动修复</div>
477
+ <div style="margin-top: 10px; color: #666;">请根据上述建议手动修复</div>`}
472
478
  </div>
473
479
  </div>
474
480
 
@@ -487,7 +493,7 @@ var DiagnosticReporter = class {
487
493
  const reportPath = path.resolve(reportsDir, "diagnostic-report.html");
488
494
  fs.writeFileSync(reportPath, html, "utf-8");
489
495
  console.log(`
490
- \u{1F4C4} \u8BCA\u65AD\u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}
496
+ 📄 诊断报告已生成: ${reportPath}
491
497
  `);
492
498
  }
493
499
  /**
@@ -525,22 +531,22 @@ var DiagnosticReporter = class {
525
531
  * 生成 Markdown 报告
526
532
  */
527
533
  static async generateMarkdownReport(report) {
528
- const markdown = `# \u{1F916} AI \u8BCA\u65AD\u62A5\u544A
534
+ const markdown = `# 🤖 AI 诊断报告
529
535
 
530
- **\u751F\u6210\u65F6\u95F4**: ${report.timestamp}
536
+ **生成时间**: ${report.timestamp}
531
537
 
532
538
  ---
533
539
 
534
- ## \u274C \u9519\u8BEF\u4FE1\u606F
540
+ ## 错误信息
535
541
 
536
- **\u7C7B\u578B**: \`${report.error.type}\`
537
- **\u6587\u4EF6**: \`${report.error.file}\`
538
- **\u6D88\u606F**:
542
+ **类型**: \`${report.error.type}\`
543
+ **文件**: \`${report.error.file}\`
544
+ **消息**:
539
545
  \`\`\`
540
546
  ${report.error.message}
541
547
  \`\`\`
542
548
 
543
- ${report.error.stack ? `**\u5806\u6808\u8DDF\u8E2A**:
549
+ ${report.error.stack ? `**堆栈跟踪**:
544
550
  \`\`\`
545
551
  ${report.error.stack}
546
552
  \`\`\`
@@ -548,25 +554,25 @@ ${report.error.stack}
548
554
 
549
555
  ---
550
556
 
551
- ## \u{1F50D} AI \u5206\u6790
557
+ ## 🔍 AI 分析
552
558
 
553
559
  ${report.analysis}
554
560
 
555
561
  ---
556
562
 
557
- ## \u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE
563
+ ## 💡 修复建议
558
564
 
559
565
  ${report.suggestion}
560
566
 
561
567
  ---
562
568
 
563
- ## \u{1F527} \u4FEE\u590D\u72B6\u6001
569
+ ## 🔧 修复状态
564
570
 
565
- ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
571
+ ${report.fixed ? `✅ **已自动修复**
566
572
 
567
- \u4FEE\u590D\u6587\u4EF6: \`${report.fixedFilePath}\`` : `\u26A0\uFE0F **\u672A\u81EA\u52A8\u4FEE\u590D**
573
+ 修复文件: \`${report.fixedFilePath}\`` : `⚠️ **未自动修复**
568
574
 
569
- \u8BF7\u6839\u636E\u4E0A\u8FF0\u5EFA\u8BAE\u624B\u52A8\u4FEE\u590D`}
575
+ 请根据上述建议手动修复`}
570
576
 
571
577
  ---
572
578
 
@@ -579,7 +585,7 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
579
585
  }
580
586
  const reportPath = path.resolve(reportsDir, "diagnostic-report.md");
581
587
  fs.writeFileSync(reportPath, markdown, "utf-8");
582
- console.log(`\u{1F4C4} Markdown \u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}`);
588
+ console.log(`📄 Markdown 报告已生成: ${reportPath}`);
583
589
  }
584
590
  /**
585
591
  * 生成 JSON 报告
@@ -609,7 +615,7 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
609
615
  }
610
616
  const reportPath = path.resolve(reportsDir, "diagnostic-report.json");
611
617
  fs.writeFileSync(reportPath, JSON.stringify(jsonReport, null, 2), "utf-8");
612
- console.log(`\u{1F4C4} JSON \u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}`);
618
+ console.log(`📄 JSON 报告已生成: ${reportPath}`);
613
619
  }
614
620
  };
615
621
 
@@ -640,38 +646,38 @@ function vitePluginAIDiagnostic(options = {}) {
640
646
  async function processError(error) {
641
647
  const errorKey = `${error.file}:${error.message}`;
642
648
  if (processedErrors.has(errorKey)) {
643
- console.log("\u{1F50D} [\u8C03\u8BD5] \u8DF3\u8FC7\u91CD\u590D\u9519\u8BEF:", errorKey);
649
+ console.log("🔍 [调试] 跳过重复错误:", errorKey);
644
650
  return;
645
651
  }
646
652
  processedErrors.add(errorKey);
647
653
  try {
648
- console.log("\n\u26A0\uFE0F \u68C0\u6D4B\u5230\u9519\u8BEF\uFF0C\u6B63\u5728\u4F7F\u7528 AI \u5206\u6790...\n");
649
- console.log(`\u{1F4DD} \u9519\u8BEF\u4FE1\u606F: ${error.message}`);
650
- console.log(`\u{1F4C2} \u6587\u4EF6\u8DEF\u5F84: ${error.file || "\u672A\u77E5"}`);
654
+ console.log("\n⚠️ 检测到错误,正在使用 AI 分析...\n");
655
+ console.log(`📝 错误信息: ${error.message}`);
656
+ console.log(`📂 文件路径: ${error.file || "未知"}`);
651
657
  console.log(
652
- `\u{1F4C4} \u4EE3\u7801\u957F\u5EA6: ${error.code ? error.code.length + " \u5B57\u7B26" : "\u65E0"}`
658
+ `📄 代码长度: ${error.code ? error.code.length + " 字符" : ""}`
653
659
  );
654
- console.log(`\u{1F527} \u81EA\u52A8\u4FEE\u590D: ${autoFix ? "\u662F" : "\u5426"}
660
+ console.log(`🔧 自动修复: ${autoFix ? "" : ""}
655
661
  `);
656
662
  if (!error.file || !error.code) {
657
- console.log("\u26A0\uFE0F \u8DF3\u8FC7\u6B64\u9519\u8BEF\uFF1A\u7F3A\u5C11\u6587\u4EF6\u8DEF\u5F84\u6216\u4EE3\u7801\u5185\u5BB9\n");
663
+ console.log("⚠️ 跳过此错误:缺少文件路径或代码内容\n");
658
664
  return;
659
665
  }
660
666
  const result = await diagnostic.diagnose(error, autoFix);
661
667
  if (output.console !== false) {
662
- console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
663
- console.log("\u{1F50D} \u9519\u8BEF\u5206\u6790\uFF1A");
668
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
669
+ console.log("🔍 错误分析:");
664
670
  console.log(result.analysis);
665
- console.log("\n\u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE\uFF1A");
671
+ console.log("\n💡 修复建议:");
666
672
  console.log(result.suggestion);
667
673
  if (result.fixedCode && result.filePath) {
668
- console.log("\n\u2705 \u5DF2\u81EA\u52A8\u4FEE\u590D\u4EE3\u7801");
669
- console.log("\u4FEE\u590D\u7684\u6587\u4EF6\uFF1A", result.filePath);
670
- console.log("\n\u{1F4A1} \u8BF7\u91CD\u65B0\u8FD0\u884C\u6784\u5EFA\u547D\u4EE4");
674
+ console.log("\n 已自动修复代码");
675
+ console.log("修复的文件:", result.filePath);
676
+ console.log("\n💡 请重新运行构建命令");
671
677
  } else if (autoFix) {
672
- console.log("\n\u26A0\uFE0F \u65E0\u6CD5\u81EA\u52A8\u4FEE\u590D\uFF1AAI \u672A\u751F\u6210\u4FEE\u590D\u4EE3\u7801");
678
+ console.log("\n⚠️ 无法自动修复:AI 未生成修复代码");
673
679
  }
674
- console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n");
680
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
675
681
  }
676
682
  const report = {
677
683
  timestamp: (/* @__PURE__ */ new Date()).toLocaleString("zh-CN"),
@@ -688,7 +694,7 @@ function vitePluginAIDiagnostic(options = {}) {
688
694
  };
689
695
  await DiagnosticReporter.generate(report, output);
690
696
  } catch (err) {
691
- console.error("\u274C AI \u8BCA\u65AD\u5931\u8D25\uFF1A", err.message);
697
+ console.error(" AI 诊断失败:", err.message);
692
698
  }
693
699
  }
694
700
  return {
@@ -696,18 +702,18 @@ function vitePluginAIDiagnostic(options = {}) {
696
702
  // 确保插件在其他插件之后执行,以捕获更多错误
697
703
  enforce: "post",
698
704
  configResolved(config) {
699
- console.log("\n\u{1F916} AI \u8BCA\u65AD\u52A9\u624B\u5DF2\u542F\u52A8...");
700
- console.log(`\u2699\uFE0F \u81EA\u52A8\u4FEE\u590D: ${autoFix ? "\u2705 \u5DF2\u542F\u7528" : "\u274C \u672A\u542F\u7528"}`);
701
- console.log(`\u{1F4DD} \u6839\u76EE\u5F55: ${config.root}`);
705
+ console.log("\n🤖 AI 诊断助手已启动...");
706
+ console.log(`⚙️ 自动修复: ${autoFix ? " 已启用" : " 未启用"}`);
707
+ console.log(`📝 根目录: ${config.root}`);
702
708
  console.log(
703
- `\u{1F4DD} \u5165\u53E3: ${config.build.rollupOptions?.input || "index.html"}
709
+ `📝 入口: ${config.build.rollupOptions?.input || "index.html"}
704
710
  `
705
711
  );
706
712
  },
707
713
  buildStart() {
708
714
  buildErrors = [];
709
715
  processedErrors.clear();
710
- console.log("\u{1F50D} [\u8C03\u8BD5] buildStart \u5DF2\u6267\u884C");
716
+ console.log("🔍 [调试] buildStart 已执行");
711
717
  },
712
718
  // 解析模块时捕获错误
713
719
  async resolveId(source, importer, options2) {
@@ -720,10 +726,10 @@ function vitePluginAIDiagnostic(options = {}) {
720
726
  // Rollup 钩子:模块解析完成后调用
721
727
  moduleParsed(moduleInfo) {
722
728
  if (moduleInfo.meta && moduleInfo.meta.error) {
723
- console.log("\n\u26A0\uFE0F moduleParsed \u68C0\u6D4B\u5230\u9519\u8BEF:", moduleInfo.id);
729
+ console.log("\n⚠️ moduleParsed 检测到错误:", moduleInfo.id);
724
730
  let code = void 0;
725
- if (moduleInfo.id && fs.existsSync(moduleInfo.id)) {
726
- code = fs.readFileSync(moduleInfo.id, "utf-8");
731
+ if (moduleInfo.id && fs2.existsSync(moduleInfo.id)) {
732
+ code = fs2.readFileSync(moduleInfo.id, "utf-8");
727
733
  }
728
734
  const errorInfo = {
729
735
  type: "module",
@@ -736,18 +742,18 @@ function vitePluginAIDiagnostic(options = {}) {
736
742
  }
737
743
  },
738
744
  buildEnd(error) {
739
- console.log("\u{1F50D} [\u8C03\u8BD5] buildEnd \u5DF2\u6267\u884C, \u6709\u9519\u8BEF:", !!error);
745
+ console.log("🔍 [调试] buildEnd 已执行, 有错误:", !!error);
740
746
  if (error) {
741
- console.log("\n\u26A0\uFE0F buildEnd \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
747
+ console.log("\n⚠️ buildEnd 捕获到错误:", error.message);
742
748
  const realFilePath = extractSourceFile(error, lastTransformFile);
743
749
  let code = void 0;
744
- if (realFilePath && fs.existsSync(realFilePath)) {
750
+ if (realFilePath && fs2.existsSync(realFilePath)) {
745
751
  try {
746
- code = fs.readFileSync(realFilePath, "utf-8");
747
- console.log(`\u{1F4C2} \u8BFB\u53D6\u6E90\u6587\u4EF6\u6210\u529F: ${realFilePath}`);
748
- console.log(`\u{1F4C4} \u6E90\u6587\u4EF6\u957F\u5EA6: ${code.length} \u5B57\u7B26`);
752
+ code = fs2.readFileSync(realFilePath, "utf-8");
753
+ console.log(`📂 读取源文件成功: ${realFilePath}`);
754
+ console.log(`📄 源文件长度: ${code.length} 字符`);
749
755
  } catch (e) {
750
- console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6:", realFilePath);
756
+ console.warn("⚠️ 无法读取文件:", realFilePath);
751
757
  }
752
758
  }
753
759
  const errorInfo = {
@@ -762,21 +768,21 @@ function vitePluginAIDiagnostic(options = {}) {
762
768
  },
763
769
  // Rollup 输出生成阶段的钩子
764
770
  renderStart(outputOptions, inputOptions) {
765
- console.log("\u{1F50D} [\u8C03\u8BD5] renderStart \u5DF2\u6267\u884C");
771
+ console.log("🔍 [调试] renderStart 已执行");
766
772
  },
767
773
  renderError(error) {
768
- console.log("\u{1F50D} [\u8C03\u8BD5] renderError \u5DF2\u6267\u884C");
774
+ console.log("🔍 [调试] renderError 已执行");
769
775
  if (!error) return;
770
- console.log("\n\u26A0\uFE0F renderError \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
776
+ console.log("\n⚠️ renderError 捕获到错误:", error.message);
771
777
  const realFilePath = extractSourceFile(error, lastTransformFile);
772
778
  let code = void 0;
773
- if (realFilePath && fs.existsSync(realFilePath)) {
779
+ if (realFilePath && fs2.existsSync(realFilePath)) {
774
780
  try {
775
- code = fs.readFileSync(realFilePath, "utf-8");
776
- console.log(`\u{1F4C2} \u8BFB\u53D6\u6E90\u6587\u4EF6\u6210\u529F: ${realFilePath}`);
777
- console.log(`\u{1F4C4} \u6E90\u6587\u4EF6\u957F\u5EA6: ${code.length} \u5B57\u7B26`);
781
+ code = fs2.readFileSync(realFilePath, "utf-8");
782
+ console.log(`📂 读取源文件成功: ${realFilePath}`);
783
+ console.log(`📄 源文件长度: ${code.length} 字符`);
778
784
  } catch (e) {
779
- console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6:", realFilePath);
785
+ console.warn("⚠️ 无法读取文件:", realFilePath);
780
786
  }
781
787
  }
782
788
  const errorInfo = {
@@ -790,20 +796,20 @@ function vitePluginAIDiagnostic(options = {}) {
790
796
  },
791
797
  // 监听所有阶段的错误
792
798
  watchChange(id, change) {
793
- console.log("\u{1F50D} [\u8C03\u8BD5] watchChange:", id);
799
+ console.log("🔍 [调试] watchChange:", id);
794
800
  },
795
801
  async closeBundle() {
796
802
  if (buildErrors.length > 0) {
797
803
  console.log(
798
804
  `
799
- \u{1F50D} [\u8C03\u8BD5] closeBundle \u68C0\u6D4B\u5230 ${buildErrors.length} \u4E2A\u9519\u8BEF
805
+ 🔍 [调试] closeBundle 检测到 ${buildErrors.length} 个错误
800
806
  `
801
807
  );
802
808
  for (const error of buildErrors) {
803
809
  await processError(error);
804
810
  }
805
811
  } else {
806
- console.log("\u2728 \u6784\u5EFA\u5B8C\u6210\uFF0C\u672A\u68C0\u6D4B\u5230\u9519\u8BEF\n");
812
+ console.log(" 构建完成,未检测到错误\n");
807
813
  }
808
814
  },
809
815
  transform(code, id) {
@@ -811,7 +817,7 @@ function vitePluginAIDiagnostic(options = {}) {
811
817
  try {
812
818
  return null;
813
819
  } catch (error) {
814
- console.log("\n\u26A0\uFE0F transform \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
820
+ console.log("\n⚠️ transform 捕获到错误:", error.message);
815
821
  buildErrors.push({
816
822
  type: "transform",
817
823
  message: error.message,
@@ -825,7 +831,8 @@ function vitePluginAIDiagnostic(options = {}) {
825
831
  };
826
832
  }
827
833
  var index_default = vitePluginAIDiagnostic;
828
-
829
- export { index_default as default, vitePluginAIDiagnostic };
830
- //# sourceMappingURL=index.mjs.map
834
+ export {
835
+ index_default as default,
836
+ vitePluginAIDiagnostic
837
+ };
831
838
  //# sourceMappingURL=index.mjs.map