goodiffer 1.1.0 → 1.1.1

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/bin/goodiffer.js CHANGED
@@ -12,7 +12,7 @@ import { reportCommand } from '../src/commands/report.js';
12
12
  program
13
13
  .name('goodiffer')
14
14
  .description('AI-powered git diff analyzer for code review')
15
- .version('1.1.0');
15
+ .version('1.1.1');
16
16
 
17
17
  // 默认命令 - 分析
18
18
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goodiffer",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AI-powered git diff analyzer for code review - 智能代码审查工具",
5
5
  "type": "module",
6
6
  "bin": {
@@ -98,11 +98,12 @@ export async function analyzeCommand(options) {
98
98
  // 检查是否启用代码上下文模式
99
99
  const useContext = options.context;
100
100
 
101
- // 如果启用上下文模式,检查环境
101
+ // 如果启用上下文模式,提示信息
102
102
  if (useContext) {
103
- if (!MCPClientService.isInClaudeCode()) {
104
- logger.warning('--context 选项需要在 Claude Code 环境中运行');
105
- logger.info('将使用本地文件读取作为后备方案');
103
+ if (MCPClientService.isInClaudeCode()) {
104
+ logger.info('已启用代码上下文模式 (MCP)');
105
+ } else {
106
+ logger.info('已启用代码上下文模式 (本地文件读取)');
106
107
  }
107
108
  }
108
109
 
@@ -91,11 +91,14 @@ export class AIClient {
91
91
 
92
92
  const data = await response.json();
93
93
 
94
+ // 检查停止原因
95
+ const stopReason = data.stop_reason;
96
+
94
97
  // 检查是否需要调用工具
95
98
  const toolUseBlocks = data.content.filter(block => block.type === 'tool_use');
96
99
 
97
- if (toolUseBlocks.length === 0) {
98
- // 没有工具调用,返回文本结果
100
+ // 如果停止原因是 end_turn 或没有工具调用,返回文本结果
101
+ if (stopReason === 'end_turn' || toolUseBlocks.length === 0) {
99
102
  const textContent = data.content
100
103
  .filter(block => block.type === 'text')
101
104
  .map(block => block.text)
@@ -16,10 +16,10 @@ export class CodeContextService {
16
16
 
17
17
  /**
18
18
  * 初始化服务
19
- * @param {boolean} enableMCP - 是否启用 MCP
19
+ * @param {boolean} enableMCP - 是否启用 MCP (仅在 Claude Code 环境中有效)
20
20
  */
21
21
  async initialize(enableMCP = false) {
22
- if (enableMCP) {
22
+ if (enableMCP && MCPClientService.isInClaudeCode()) {
23
23
  this.mcpClient = getMCPClient();
24
24
 
25
25
  // 尝试连接 Claude Code MCP
@@ -28,11 +28,8 @@ export class CodeContextService {
28
28
  });
29
29
 
30
30
  this.useMCP = connected;
31
-
32
- if (!connected) {
33
- logger.warning('MCP 连接失败,将使用本地文件读取');
34
- }
35
31
  }
32
+ // 默认使用本地文件读取,无需警告
36
33
  }
37
34
 
38
35
  /**
@@ -35,12 +35,24 @@ export class MCPClientService {
35
35
  * @param {string} options.cwd - 工作目录
36
36
  */
37
37
  async connect(options = {}) {
38
+ // 如果不在 Claude Code 环境中,跳过 MCP 连接
39
+ if (!MCPClientService.isInClaudeCode()) {
40
+ this.connected = false;
41
+ return false;
42
+ }
43
+
38
44
  const {
39
- command = 'npx',
40
- args = ['-y', '@anthropic-ai/claude-code-mcp'],
45
+ command,
46
+ args,
41
47
  cwd = process.cwd()
42
48
  } = options;
43
49
 
50
+ // 如果没有提供 command,无法连接
51
+ if (!command) {
52
+ this.connected = false;
53
+ return false;
54
+ }
55
+
44
56
  try {
45
57
  this.client = new Client({
46
58
  name: 'goodiffer',
@@ -54,7 +66,7 @@ export class MCPClientService {
54
66
  // 创建 stdio transport
55
67
  this.transport = new StdioClientTransport({
56
68
  command,
57
- args,
69
+ args: args || [],
58
70
  cwd,
59
71
  env: {
60
72
  ...process.env,