job51-gitlab-cr-node-jt-1 2.3.3 → 2.3.5

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.
@@ -139,6 +139,11 @@
139
139
  > - 正确示例代码:必须是**修复后的建议代码**
140
140
  > - 不得将已删除的代码(- 开头的行)作为错误代码展示
141
141
  > - **代码风格一致性**:建议代码应遵循项目现有风格(工具类方法、函数式编程、命名约定等)
142
+ > - **⚠️ 禁止报告不存在的代码**:
143
+ > - **错误代码示例必须是 diff 中实际存在的代码**(`+` 开头或空格开头的行)
144
+ > - **禁止编造 diff 中没有的代码**,如报告中出现 `if (!serviceCode.endsWith("01"))` 但 diff 中根本没有这行代码
145
+ > - **禁止报告与 diff 无关的代码片段**,所有问题涉及的代码必须能在当前 diff 块中找到
146
+ > - **输出前验证**:检查错误代码示例中的每一行,确认都能在 diff 的 `+` 开头或空格开头的行中找到
142
147
  7. 若无某类问题(如无严重问题),则**完全省略该部分**;
143
148
  8. 若同一级别问题有多个,在对应标题下按原代码顺序依次展示;
144
149
  > - **⚠️ 跨块去重规则**:**同一文件中由同一根本原因导致的问题,只报告一次**
@@ -259,3 +264,7 @@
259
264
  > - 如果分析结论包含"当前代码逻辑正确"、"无需修改"、"已有 XX 保护"等描述,**禁止**将该问题报告为严重问题
260
265
  > - **报告前自检**:问题描述、错误代码、修改建议三者逻辑必须一致,不得出现"有判空但说未判空"的矛盾
261
266
  > - **建议写法**:如果确实想提醒注意某行为,但代码已正确处理,应省略该问题,不输出报告
267
+ > - [ ] **已验证错误代码实际存在**:
268
+ > - **错误代码示例中的每一行必须能在 diff 中找到**(`+` 开头或空格开头的行)
269
+ > - **禁止编造 diff 中没有的代码**,如报告中不得出现 diff 中完全不存在的条件判断、方法调用等
270
+ > - **验证方法**:将错误代码示例与 diff 内容逐行对比,确认每行代码都能对应上
package/index.js CHANGED
@@ -61,6 +61,7 @@ class GitLabCodeReviewer {
61
61
  // 最多重试3次,直到结果包含"🤖 AI 代码审查结果"或达到最大重试次数
62
62
  let attempts = 0;
63
63
  const maxAttempts = 5;
64
+ let claudeResult = null;
64
65
 
65
66
  while (attempts < maxAttempts) {
66
67
  attempts++;
@@ -68,7 +69,7 @@ class GitLabCodeReviewer {
68
69
  debugLog(`调用本地AI命令审核文件 (尝试 ${attempts}/${maxAttempts})`);
69
70
 
70
71
  // 直接将prompt内容传递给Claude命令
71
- const claudeResult = await runClaudeCommand(prompt);
72
+ claudeResult = await runClaudeCommand(prompt);
72
73
 
73
74
  debugLog(`本地AI命令审核完成,AI审核结果: ${claudeResult}`);
74
75
 
@@ -83,11 +84,19 @@ class GitLabCodeReviewer {
83
84
  } else {
84
85
  debugLog(`AI审核结果不包含"🤖 AI 代码审查结果" (尝试 ${attempts}),将重试...`);
85
86
  if (attempts >= maxAttempts) {
86
- debugLog(`已达到最大重试次数 ${maxAttempts},返回最后一次结果,${claudeResult}`);
87
+ debugLog(`已达到最大重试次数 ${maxAttempts},返回最后一次结果`);
87
88
 
88
- // 提取REPORT标签内容并返回
89
- // 提取 REPORT 标签和 LINE_INFO 标签内容并返回对象
90
- return extractReportContent(claudeResult);
89
+ // 验证报告有效性:检查 LINE_INFO 是否为空且报告内容是否过短
90
+ const lineInfoEmpty = claudeResult.includes('<LINE_INFO>[]</LINE_INFO>');
91
+ const reportTooShort = claudeResult.length < 100;
92
+
93
+ // 如果 LINE_INFO 为空且报告内容很短,说明无实质问题
94
+ if (lineInfoEmpty && reportTooShort) {
95
+ debugLog(`报告无实质问题,修正为标准无问题格式`);
96
+ claudeResult = '<REPORT>\n## 🤖 AI 代码审查结果\n\n</REPORT>\n\n<LINE_INFO>\n[]\n</LINE_INFO>';
97
+ }
98
+
99
+ return extractReportContent(claudeResult);
91
100
  }
92
101
  }
93
102
  } catch (error) {
@@ -219,6 +228,7 @@ ${diffObject.diff}`;
219
228
  // 最多重试5次,直到结果包含"🤖 AI 代码审查结果"或达到最大重试次数
220
229
  let attempts = 0;
221
230
  const maxAttempts = 5;
231
+ let claudeResult = null;
222
232
 
223
233
  while (attempts < maxAttempts) {
224
234
  attempts++;
@@ -226,7 +236,7 @@ ${diffObject.diff}`;
226
236
  debugLog(`调用本地AI命令审核文件 (尝试 ${attempts}/${maxAttempts})`);
227
237
 
228
238
  // 直接将prompt内容(包含文件路径)传递给Claude命令
229
- const claudeResult = await runClaudeCommand(prompt);
239
+ claudeResult = await runClaudeCommand(prompt);
230
240
  //若结果为空,则记录日志
231
241
  if (!claudeResult) {
232
242
  debugLog(`本地AI命令审核结果为空`);
@@ -242,11 +252,19 @@ ${diffObject.diff}`;
242
252
  } else {
243
253
  debugLog(`AI审核结果不包含"🤖 AI 代码审查结果" (尝试 ${attempts}),将重试...`);
244
254
  if (attempts >= maxAttempts) {
245
- debugLog(`已达到最大重试次数 ${maxAttempts},返回最后一次结果,${claudeResult}`);
255
+ debugLog(`已达到最大重试次数 ${maxAttempts},返回最后一次结果`);
246
256
 
247
- // 提取REPORT标签内容并返回
248
- // 提取 REPORT 标签和 LINE_INFO 标签内容并返回对象
249
- return extractReportContent(claudeResult);
257
+ // 验证报告有效性:检查 LINE_INFO 是否为空且报告内容是否过短
258
+ const lineInfoEmpty = claudeResult.includes('<LINE_INFO>[]</LINE_INFO>');
259
+ const reportTooShort = claudeResult.length < 100;
260
+
261
+ // 如果 LINE_INFO 为空且报告内容很短,说明无实质问题
262
+ if (lineInfoEmpty && reportTooShort) {
263
+ debugLog(`报告无实质问题,修正为标准无问题格式`);
264
+ claudeResult = '<REPORT>\n## 🤖 AI 代码审查结果\n\n</REPORT>\n\n<LINE_INFO>\n[]\n</LINE_INFO>';
265
+ }
266
+
267
+ return extractReportContent(claudeResult);
250
268
  }
251
269
  }
252
270
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "job51-gitlab-cr-node-jt-1",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "GitLab merge request code review tool with AI-powered analysis and project context support",
5
5
  "main": "index.js",
6
6
  "bin": {