stigmergy 1.0.68 → 1.0.70
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/README.en.md +306 -300
- package/README.md +469 -301
- package/package.json +97 -81
- package/scripts/publish.js +268 -0
- package/scripts/simple-publish.js +59 -0
- package/src/index.js +12 -0
- package/test/enhanced-main-alignment.test.js +298 -0
- package/test/hook-system-integration-test.js +307 -0
- package/test/natural-language-skills-test.js +320 -0
- package/test/nl-integration-test.js +179 -0
- package/test/parameter-parsing-test.js +143 -0
- package/test/real-test.js +435 -0
- package/test/system-compatibility-test.js +447 -0
- package/test/tdd-fixes-test.js +211 -0
- package/test/third-party-skills-test.js +321 -0
- package/test/tool-selection-integration-test.js +157 -0
- package/test/unit/cli-scanner.test.js +291 -0
- package/test/unit/cross-cli-executor.test.js +399 -0
- package/src/adapters/claude/__init__.py +0 -13
- package/src/adapters/claude/claude_skills_integration.py +0 -609
- package/src/adapters/claude/hook_adapter.py +0 -663
- package/src/adapters/claude/install_claude_integration.py +0 -265
- package/src/adapters/claude/skills_hook_adapter.py +0 -841
- package/src/adapters/claude/standalone_claude_adapter.py +0 -384
- package/src/adapters/cline/__init__.py +0 -20
- package/src/adapters/cline/config.py +0 -108
- package/src/adapters/cline/install_cline_integration.py +0 -617
- package/src/adapters/cline/mcp_server.py +0 -713
- package/src/adapters/cline/standalone_cline_adapter.py +0 -459
- package/src/adapters/codebuddy/__init__.py +0 -13
- package/src/adapters/codebuddy/buddy_adapter.py +0 -1125
- package/src/adapters/codebuddy/install_codebuddy_integration.py +0 -279
- package/src/adapters/codebuddy/skills_hook_adapter.py +0 -672
- package/src/adapters/codebuddy/skills_integration.py +0 -395
- package/src/adapters/codebuddy/standalone_codebuddy_adapter.py +0 -403
- package/src/adapters/codex/__init__.py +0 -11
- package/src/adapters/codex/base.py +0 -46
- package/src/adapters/codex/install_codex_integration.py +0 -311
- package/src/adapters/codex/mcp_server.py +0 -493
- package/src/adapters/codex/natural_language_parser.py +0 -82
- package/src/adapters/codex/slash_command_adapter.py +0 -326
- package/src/adapters/codex/standalone_codex_adapter.py +0 -362
- package/src/adapters/copilot/__init__.py +0 -13
- package/src/adapters/copilot/install_copilot_integration.py +0 -564
- package/src/adapters/copilot/mcp_adapter.py +0 -772
- package/src/adapters/copilot/mcp_server.py +0 -168
- package/src/adapters/copilot/standalone_copilot_adapter.py +0 -114
- package/src/adapters/gemini/__init__.py +0 -13
- package/src/adapters/gemini/extension_adapter.py +0 -690
- package/src/adapters/gemini/install_gemini_integration.py +0 -257
- package/src/adapters/gemini/standalone_gemini_adapter.py +0 -366
- package/src/adapters/iflow/__init__.py +0 -7
- package/src/adapters/iflow/hook_adapter.py +0 -1038
- package/src/adapters/iflow/hook_installer.py +0 -536
- package/src/adapters/iflow/install_iflow_integration.py +0 -271
- package/src/adapters/iflow/official_hook_adapter.py +0 -1272
- package/src/adapters/iflow/standalone_iflow_adapter.py +0 -48
- package/src/adapters/iflow/workflow_adapter.py +0 -793
- package/src/adapters/qoder/hook_installer.py +0 -732
- package/src/adapters/qoder/install_qoder_integration.py +0 -265
- package/src/adapters/qoder/notification_hook_adapter.py +0 -863
- package/src/adapters/qoder/standalone_qoder_adapter.py +0 -48
- package/src/adapters/qwen/__init__.py +0 -17
- package/src/adapters/qwencode/__init__.py +0 -13
- package/src/adapters/qwencode/inheritance_adapter.py +0 -818
- package/src/adapters/qwencode/install_qwencode_integration.py +0 -276
- package/src/adapters/qwencode/standalone_qwencode_adapter.py +0 -399
- package/src/atomic_collaboration_handler.py +0 -461
- package/src/cli_collaboration_agent.py +0 -697
- package/src/collaboration/hooks.py +0 -315
- package/src/core/__init__.py +0 -21
- package/src/core/ai_environment_scanner.py +0 -331
- package/src/core/base_adapter.py +0 -220
- package/src/core/cli_hook_integration.py +0 -406
- package/src/core/cross_cli_executor.py +0 -713
- package/src/core/cross_cli_mapping.py +0 -1165
- package/src/core/cross_platform_encoding.py +0 -365
- package/src/core/cross_platform_safe_cli.py +0 -894
- package/src/core/direct_cli_executor.py +0 -805
- package/src/core/direct_cli_hook_system.py +0 -958
- package/src/core/enhanced_init_processor.py +0 -467
- package/src/core/graceful_cli_executor.py +0 -912
- package/src/core/md_enhancer.py +0 -342
- package/src/core/md_generator.py +0 -619
- package/src/core/models.py +0 -218
- package/src/core/parser.py +0 -108
- package/src/core/real_cli_hook_system.py +0 -852
- package/src/core/real_cross_cli_system.py +0 -925
- package/src/core/verified_cross_cli_system.py +0 -961
- package/src/deploy.js +0 -737
- package/src/enhanced-main.js +0 -626
- package/src/enhanced_deploy.js +0 -303
- package/src/enhanced_universal_cli_setup.py +0 -930
- package/src/kimi_wrapper.py +0 -104
- package/src/main.js +0 -1309
- package/src/shell_integration.py +0 -398
- package/src/simple-main.js +0 -315
- package/src/smart_router_creator.py +0 -323
- package/src/universal_cli_setup.py +0 -1289
- package/src/utils/__init__.py +0 -12
- package/src/utils/cli_detector.py +0 -445
- package/src/utils/file_utils.py +0 -246
package/src/core/base_adapter.py
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
BaseCrossCLIAdapter - 跨CLI适配器基类
|
|
3
|
-
定义所有CLI适配器的统一接口和基础功能
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import abc
|
|
7
|
-
import logging
|
|
8
|
-
from typing import Dict, Any, Optional
|
|
9
|
-
from datetime import datetime
|
|
10
|
-
from dataclasses import dataclass, field
|
|
11
|
-
|
|
12
|
-
logger = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@dataclass
|
|
16
|
-
class IntentResult:
|
|
17
|
-
"""意图解析结果"""
|
|
18
|
-
is_cross_cli: bool = False
|
|
19
|
-
target_cli: Optional[str] = None
|
|
20
|
-
task: str = ""
|
|
21
|
-
confidence: float = 1.0
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class BaseCrossCLIAdapter(abc.ABC):
|
|
25
|
-
"""
|
|
26
|
-
跨CLI适配器抽象基类
|
|
27
|
-
定义所有CLI适配器必须实现的接口和提供的基础功能
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
def __init__(self, cli_name: str):
|
|
31
|
-
"""
|
|
32
|
-
初始化适配器
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
cli_name: CLI工具名称
|
|
36
|
-
"""
|
|
37
|
-
self.cli_name = cli_name
|
|
38
|
-
self.version = "1.0.0"
|
|
39
|
-
self.initialized = False
|
|
40
|
-
self.initialization_time: Optional[datetime] = None
|
|
41
|
-
|
|
42
|
-
# 统计信息
|
|
43
|
-
self.execution_count = 0
|
|
44
|
-
self.error_count = 0
|
|
45
|
-
self.successful_executions = 0
|
|
46
|
-
self.total_execution_time = 0.0
|
|
47
|
-
|
|
48
|
-
# 错误记录
|
|
49
|
-
self.last_error: Optional[str] = None
|
|
50
|
-
self.last_error_time: Optional[datetime] = None
|
|
51
|
-
|
|
52
|
-
@abc.abstractmethod
|
|
53
|
-
async def execute_task(self, task: str, context: Dict[str, Any]) -> str:
|
|
54
|
-
"""
|
|
55
|
-
执行跨CLI任务 - 抽象方法,必须由子类实现
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
task: 要执行的任务描述
|
|
59
|
-
context: 执行上下文信息
|
|
60
|
-
|
|
61
|
-
Returns:
|
|
62
|
-
str: 任务执行结果
|
|
63
|
-
"""
|
|
64
|
-
pass
|
|
65
|
-
|
|
66
|
-
@abc.abstractmethod
|
|
67
|
-
def is_available(self) -> bool:
|
|
68
|
-
"""
|
|
69
|
-
检查适配器是否可用 - 抽象方法,必须由子类实现
|
|
70
|
-
|
|
71
|
-
Returns:
|
|
72
|
-
bool: 是否可用
|
|
73
|
-
"""
|
|
74
|
-
pass
|
|
75
|
-
|
|
76
|
-
async def initialize(self) -> bool:
|
|
77
|
-
"""
|
|
78
|
-
初始化适配器 - 可由子类重写
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
bool: 初始化是否成功
|
|
82
|
-
"""
|
|
83
|
-
self.initialized = True
|
|
84
|
-
self.initialization_time = datetime.now()
|
|
85
|
-
logger.info(f"{self.cli_name} 适配器初始化完成")
|
|
86
|
-
return True
|
|
87
|
-
|
|
88
|
-
async def health_check(self) -> Dict[str, Any]:
|
|
89
|
-
"""
|
|
90
|
-
健康检查
|
|
91
|
-
|
|
92
|
-
Returns:
|
|
93
|
-
Dict[str, Any]: 健康状态信息
|
|
94
|
-
"""
|
|
95
|
-
return {
|
|
96
|
-
'cli_name': self.cli_name,
|
|
97
|
-
'version': self.version,
|
|
98
|
-
'initialized': self.initialized,
|
|
99
|
-
'available': self.is_available(),
|
|
100
|
-
'execution_count': self.execution_count,
|
|
101
|
-
'error_count': self.error_count,
|
|
102
|
-
'success_rate': self.get_success_rate(),
|
|
103
|
-
'last_error': self.last_error,
|
|
104
|
-
'last_error_time': self.last_error_time.isoformat() if self.last_error_time else None,
|
|
105
|
-
'initialization_time': self.initialization_time.isoformat() if self.initialization_time else None
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
def get_statistics(self) -> Dict[str, Any]:
|
|
109
|
-
"""
|
|
110
|
-
获取适配器统计信息
|
|
111
|
-
|
|
112
|
-
Returns:
|
|
113
|
-
Dict[str, Any]: 统计信息
|
|
114
|
-
"""
|
|
115
|
-
return {
|
|
116
|
-
'cli_name': self.cli_name,
|
|
117
|
-
'version': self.version,
|
|
118
|
-
'execution_count': self.execution_count,
|
|
119
|
-
'error_count': self.error_count,
|
|
120
|
-
'successful_executions': self.successful_executions,
|
|
121
|
-
'total_execution_time': self.total_execution_time,
|
|
122
|
-
'success_rate': self.get_success_rate(),
|
|
123
|
-
'average_execution_time': (
|
|
124
|
-
self.total_execution_time / self.successful_executions
|
|
125
|
-
if self.successful_executions > 0 else 0
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
def get_success_rate(self) -> float:
|
|
130
|
-
"""
|
|
131
|
-
计算成功率
|
|
132
|
-
|
|
133
|
-
Returns:
|
|
134
|
-
float: 成功率 (0.0 - 1.0)
|
|
135
|
-
"""
|
|
136
|
-
if self.execution_count == 0:
|
|
137
|
-
return 1.0
|
|
138
|
-
return self.successful_executions / self.execution_count
|
|
139
|
-
|
|
140
|
-
def record_execution(self, execution_time: float, success: bool = True):
|
|
141
|
-
"""
|
|
142
|
-
记录执行统计
|
|
143
|
-
|
|
144
|
-
Args:
|
|
145
|
-
execution_time: 执行时间(秒)
|
|
146
|
-
success: 是否执行成功
|
|
147
|
-
"""
|
|
148
|
-
self.execution_count += 1
|
|
149
|
-
self.total_execution_time += execution_time
|
|
150
|
-
|
|
151
|
-
if success:
|
|
152
|
-
self.successful_executions += 1
|
|
153
|
-
else:
|
|
154
|
-
self.error_count += 1
|
|
155
|
-
|
|
156
|
-
def record_error(self, error_message: Optional[str] = None):
|
|
157
|
-
"""
|
|
158
|
-
记录错误
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
error_message: 错误信息
|
|
162
|
-
"""
|
|
163
|
-
self.error_count += 1
|
|
164
|
-
self.last_error = error_message or "Unknown error"
|
|
165
|
-
self.last_error_time = datetime.now()
|
|
166
|
-
|
|
167
|
-
async def cleanup(self) -> bool:
|
|
168
|
-
"""
|
|
169
|
-
清理适配器资源 - 可由子类重写
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
bool: 清理是否成功
|
|
173
|
-
"""
|
|
174
|
-
logger.info(f"{self.cli_name} 适配器清理完成")
|
|
175
|
-
return True
|
|
176
|
-
|
|
177
|
-
def __str__(self):
|
|
178
|
-
return f"{self.__class__.__name__}(cli_name='{self.cli_name}', version='{self.version}')"
|
|
179
|
-
|
|
180
|
-
def __repr__(self):
|
|
181
|
-
return self.__str__()
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
# 全局适配器工厂
|
|
185
|
-
_adapters_registry: Dict[str, BaseCrossCLIAdapter] = {}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def register_adapter(cli_name: str, adapter: BaseCrossCLIAdapter):
|
|
189
|
-
"""
|
|
190
|
-
注册适配器到全局注册表
|
|
191
|
-
|
|
192
|
-
Args:
|
|
193
|
-
cli_name: CLI工具名称
|
|
194
|
-
adapter: 适配器实例
|
|
195
|
-
"""
|
|
196
|
-
_adapters_registry[cli_name] = adapter
|
|
197
|
-
logger.info(f"注册适配器: {cli_name}")
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def get_cross_cli_adapter(cli_name: str) -> Optional[BaseCrossCLIAdapter]:
|
|
201
|
-
"""
|
|
202
|
-
获取跨CLI适配器
|
|
203
|
-
|
|
204
|
-
Args:
|
|
205
|
-
cli_name: CLI工具名称
|
|
206
|
-
|
|
207
|
-
Returns:
|
|
208
|
-
Optional[BaseCrossCLIAdapter]: 适配器实例
|
|
209
|
-
"""
|
|
210
|
-
return _adapters_registry.get(cli_name)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
def get_all_adapters() -> Dict[str, BaseCrossCLIAdapter]:
|
|
214
|
-
"""
|
|
215
|
-
获取所有注册的适配器
|
|
216
|
-
|
|
217
|
-
Returns:
|
|
218
|
-
Dict[str, BaseCrossCLIAdapter]: 所有适配器
|
|
219
|
-
"""
|
|
220
|
-
return _adapters_registry.copy()
|
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
CLI Hook Integration - CLI工具钩子集成模块
|
|
3
|
-
将增强的 /init 指令集成到各个CLI工具的钩子系统
|
|
4
|
-
"""
|
|
5
|
-
import os
|
|
6
|
-
import asyncio
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from typing import Optional, Dict, Any
|
|
9
|
-
import logging
|
|
10
|
-
|
|
11
|
-
from .enhanced_init_processor import EnhancedInitProcessor
|
|
12
|
-
|
|
13
|
-
logger = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CLIHookIntegration:
|
|
17
|
-
"""CLI工具钩子集成 - 统一处理各CLI工具的钩子集成"""
|
|
18
|
-
|
|
19
|
-
def __init__(self):
|
|
20
|
-
self.processors = {} # 缓存不同CLI的处理器实例
|
|
21
|
-
|
|
22
|
-
async def handle_init_command(self, current_cli: str, project_path: str = None) -> str:
|
|
23
|
-
"""统一处理 /init 斜杠指令"""
|
|
24
|
-
try:
|
|
25
|
-
logger.info(f"处理 {current_cli} 的 /init 指令")
|
|
26
|
-
|
|
27
|
-
# 获取项目路径
|
|
28
|
-
if not project_path:
|
|
29
|
-
project_path = os.getcwd()
|
|
30
|
-
|
|
31
|
-
# 获取或创建处理器实例
|
|
32
|
-
processor = self._get_processor(current_cli)
|
|
33
|
-
|
|
34
|
-
# 处理初始化命令
|
|
35
|
-
result = await processor.process_init_command(project_path)
|
|
36
|
-
|
|
37
|
-
# 生成用户友好的响应消息
|
|
38
|
-
response_message = self._generate_response_message(result, current_cli)
|
|
39
|
-
|
|
40
|
-
return response_message
|
|
41
|
-
|
|
42
|
-
except Exception as e:
|
|
43
|
-
logger.error(f"处理 /init 指令失败: {e}")
|
|
44
|
-
return f"❌ 处理失败: {str(e)}"
|
|
45
|
-
|
|
46
|
-
def _get_processor(self, current_cli: str) -> EnhancedInitProcessor:
|
|
47
|
-
"""获取或创建处理器实例"""
|
|
48
|
-
if current_cli not in self.processors:
|
|
49
|
-
self.processors[current_cli] = EnhancedInitProcessor(current_cli)
|
|
50
|
-
return self.processors[current_cli]
|
|
51
|
-
|
|
52
|
-
def _generate_response_message(self, result, current_cli: str) -> str:
|
|
53
|
-
"""生成用户友好的响应消息"""
|
|
54
|
-
try:
|
|
55
|
-
if not result.ai_environment:
|
|
56
|
-
return result.message
|
|
57
|
-
|
|
58
|
-
env = result.ai_environment
|
|
59
|
-
available_tools = len(env.available_clis)
|
|
60
|
-
|
|
61
|
-
base_message = f"""
|
|
62
|
-
🎯 **AI CLI Router - 项目初始化完成**
|
|
63
|
-
|
|
64
|
-
📊 **项目状态**: {result.project_type}
|
|
65
|
-
🤖 **可用AI工具**: {available_tools} 个
|
|
66
|
-
⏱️ **处理时间**: {result.processing_time:.2f} 秒
|
|
67
|
-
|
|
68
|
-
**详细结果**:
|
|
69
|
-
{result.message}
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
# 添加工具状态信息
|
|
73
|
-
if result.project_type == "existing_project":
|
|
74
|
-
enhanced_count = len(result.enhanced_documents)
|
|
75
|
-
base_message += f"""
|
|
76
|
-
📝 **增强的文档**: {enhanced_count} 个
|
|
77
|
-
"""
|
|
78
|
-
if enhanced_count > 0:
|
|
79
|
-
base_message += "\n✅ 以下文档已添加协作感知:\n"
|
|
80
|
-
for doc_name in result.enhanced_documents.keys():
|
|
81
|
-
base_message += f" - `{doc_name}.md`\n"
|
|
82
|
-
|
|
83
|
-
else: # new_project
|
|
84
|
-
generated_count = len(result.generated_documents)
|
|
85
|
-
base_message += f"""
|
|
86
|
-
🆕 **生成的文档**: {generated_count} 个
|
|
87
|
-
"""
|
|
88
|
-
if generated_count > 0:
|
|
89
|
-
base_message += "\n📄 以下文档已生成:\n"
|
|
90
|
-
for doc_name in result.generated_documents.keys():
|
|
91
|
-
base_message += f" - `{doc_name}.md`\n"
|
|
92
|
-
|
|
93
|
-
# 添加可用工具列表
|
|
94
|
-
base_message += f"""
|
|
95
|
-
🔧 **可用AI工具**:
|
|
96
|
-
"""
|
|
97
|
-
for tool_name, tool_info in env.available_clis.items():
|
|
98
|
-
status_icon = "✅" if tool_info.status.value == "available" else "❌"
|
|
99
|
-
base_message += f" {status_icon} **{tool_info.display_name}** v{tool_info.version}\n"
|
|
100
|
-
|
|
101
|
-
# 添加快速开始指南
|
|
102
|
-
base_message += f"""
|
|
103
|
-
🚀 **快速开始**:
|
|
104
|
-
|
|
105
|
-
现在您可以使用跨AI工具协作指令:
|
|
106
|
-
|
|
107
|
-
**中文示例**:
|
|
108
|
-
- `请用{self._get_other_tool(env.available_clis, current_cli)}帮我生成代码`
|
|
109
|
-
- `调用{self._get_other_tool(env.available_clis, current_cli)}分析性能问题`
|
|
110
|
-
- `用{self._get_other_tool(env.available_clis, current_cli)}审查代码质量`
|
|
111
|
-
|
|
112
|
-
**英文示例**:
|
|
113
|
-
- `use {self._get_other_tool(env.available_clis, current_cli)} to generate tests`
|
|
114
|
-
- `call {self._get_other_tool(env.available_clis, current_cli)} for code review`
|
|
115
|
-
- `ask {self._get_other_tool(env.available_clis, current_cli)} to optimize performance`
|
|
116
|
-
|
|
117
|
-
💡 **提示**:
|
|
118
|
-
- 查看生成的 `.md` 文件获取详细的协作指南
|
|
119
|
-
- 使用 `/init` 命令重新扫描AI环境
|
|
120
|
-
- 项目配置保存在 `.ai-cli-project/` 目录中
|
|
121
|
-
|
|
122
|
-
🔗 **相关命令**:
|
|
123
|
-
- `ai-cli-router status` - 查看所有工具状态
|
|
124
|
-
- `ai-cli-router scan` - 重新扫描AI环境
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
return base_message
|
|
128
|
-
|
|
129
|
-
except Exception as e:
|
|
130
|
-
logger.error(f"生成响应消息失败: {e}")
|
|
131
|
-
return result.message
|
|
132
|
-
|
|
133
|
-
def _get_other_tool(self, available_clis: Dict[str, Any], current_cli: str) -> str:
|
|
134
|
-
"""获取另一个可用的工具名称"""
|
|
135
|
-
for tool_name in available_clis.keys():
|
|
136
|
-
if tool_name != current_cli:
|
|
137
|
-
return tool_name
|
|
138
|
-
return "其他工具"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
# 各CLI工具的具体钩子集成实现
|
|
142
|
-
|
|
143
|
-
class ClaudeHookIntegration:
|
|
144
|
-
"""Claude CLI 钩子集成"""
|
|
145
|
-
|
|
146
|
-
@staticmethod
|
|
147
|
-
async def on_user_prompt_submit(context: Dict[str, Any]) -> Optional[str]:
|
|
148
|
-
"""处理用户提示词提交钩子"""
|
|
149
|
-
try:
|
|
150
|
-
user_input = context.get("prompt", "").strip()
|
|
151
|
-
|
|
152
|
-
# 检测 /init 指令
|
|
153
|
-
if user_input == "/init":
|
|
154
|
-
hook_integration = CLIHookIntegration()
|
|
155
|
-
return await hook_integration.handle_init_command("claude")
|
|
156
|
-
|
|
157
|
-
# 检测其他相关指令(可以扩展)
|
|
158
|
-
elif user_input.startswith("/ai-cli"):
|
|
159
|
-
# 处理其他AI CLI Router指令
|
|
160
|
-
return await ClaudeHookIntegration._handle_ai_cli_commands(user_input)
|
|
161
|
-
|
|
162
|
-
return None
|
|
163
|
-
|
|
164
|
-
except Exception as e:
|
|
165
|
-
logger.error(f"Claude钩子处理失败: {e}")
|
|
166
|
-
return None
|
|
167
|
-
|
|
168
|
-
@staticmethod
|
|
169
|
-
async def _handle_ai_cli_commands(command: str) -> str:
|
|
170
|
-
"""处理AI CLI Router相关命令"""
|
|
171
|
-
try:
|
|
172
|
-
parts = command.split()
|
|
173
|
-
if len(parts) < 2:
|
|
174
|
-
return "❌ 无效的AI CLI Router命令"
|
|
175
|
-
|
|
176
|
-
sub_command = parts[1]
|
|
177
|
-
hook_integration = CLIHookIntegration()
|
|
178
|
-
|
|
179
|
-
if sub_command == "status":
|
|
180
|
-
# 检查状态
|
|
181
|
-
return await hook_integration.handle_init_command("claude")
|
|
182
|
-
elif sub_command == "scan":
|
|
183
|
-
# 重新扫描
|
|
184
|
-
return await hook_integration.handle_init_command("claude")
|
|
185
|
-
else:
|
|
186
|
-
return f"❌ 未知命令: {sub_command}"
|
|
187
|
-
|
|
188
|
-
except Exception as e:
|
|
189
|
-
return f"❌ 命令执行失败: {str(e)}"
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
class GeminiExtensionIntegration:
|
|
193
|
-
"""Gemini CLI 扩展集成"""
|
|
194
|
-
|
|
195
|
-
@staticmethod
|
|
196
|
-
async def on_prompt_submit(context: Dict[str, Any]) -> Optional[str]:
|
|
197
|
-
"""处理提示词提交扩展"""
|
|
198
|
-
try:
|
|
199
|
-
prompt = context.get("prompt", "").strip()
|
|
200
|
-
|
|
201
|
-
if prompt == "/init":
|
|
202
|
-
hook_integration = CLIHookIntegration()
|
|
203
|
-
return await hook_integration.handle_init_command("gemini")
|
|
204
|
-
|
|
205
|
-
return None
|
|
206
|
-
|
|
207
|
-
except Exception as e:
|
|
208
|
-
logger.error(f"Gemini扩展处理失败: {e}")
|
|
209
|
-
return None
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
class QwenCodeInheritanceIntegration:
|
|
213
|
-
"""QwenCode CLI 继承集成"""
|
|
214
|
-
|
|
215
|
-
@staticmethod
|
|
216
|
-
async def on_prompt_received(context: Dict[str, Any]) -> Optional[str]:
|
|
217
|
-
"""处理提示词接收"""
|
|
218
|
-
try:
|
|
219
|
-
prompt = context.get("prompt", "").strip()
|
|
220
|
-
|
|
221
|
-
if prompt == "/init":
|
|
222
|
-
hook_integration = CLIHookIntegration()
|
|
223
|
-
return await hook_integration.handle_init_command("qwen")
|
|
224
|
-
|
|
225
|
-
return None
|
|
226
|
-
|
|
227
|
-
except Exception as e:
|
|
228
|
-
logger.error(f"QwenCode继承处理失败: {e}")
|
|
229
|
-
return None
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
class IFlowWorkflowIntegration:
|
|
233
|
-
"""iFlow CLI 工作流集成"""
|
|
234
|
-
|
|
235
|
-
@staticmethod
|
|
236
|
-
async def on_workflow_start(context: Dict[str, Any]) -> Optional[str]:
|
|
237
|
-
"""处理工作流开始"""
|
|
238
|
-
try:
|
|
239
|
-
workflow_config = context.get("workflow_config", {})
|
|
240
|
-
command = workflow_config.get("command", "").strip()
|
|
241
|
-
|
|
242
|
-
if command == "/init":
|
|
243
|
-
hook_integration = CLIHookIntegration()
|
|
244
|
-
return await hook_integration.handle_init_command("iflow")
|
|
245
|
-
|
|
246
|
-
return None
|
|
247
|
-
|
|
248
|
-
except Exception as e:
|
|
249
|
-
logger.error(f"iFlow工作流处理失败: {e}")
|
|
250
|
-
return None
|
|
251
|
-
|
|
252
|
-
@staticmethod
|
|
253
|
-
async def on_user_prompt_submit(context: Dict[str, Any]) -> Optional[str]:
|
|
254
|
-
"""处理用户提示词提交(备用)"""
|
|
255
|
-
try:
|
|
256
|
-
user_input = context.get("prompt", "").strip()
|
|
257
|
-
|
|
258
|
-
if user_input == "/init":
|
|
259
|
-
hook_integration = CLIHookIntegration()
|
|
260
|
-
return await hook_integration.handle_init_command("iflow")
|
|
261
|
-
|
|
262
|
-
return None
|
|
263
|
-
|
|
264
|
-
except Exception as e:
|
|
265
|
-
logger.error(f"iFlow钩子处理失败: {e}")
|
|
266
|
-
return None
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
class QoderNotificationIntegration:
|
|
270
|
-
"""Qoder CLI 通知集成"""
|
|
271
|
-
|
|
272
|
-
@staticmethod
|
|
273
|
-
async def on_command_execution(context: Dict[str, Any]) -> Optional[str]:
|
|
274
|
-
"""处理命令执行"""
|
|
275
|
-
try:
|
|
276
|
-
command = context.get("command", "").strip()
|
|
277
|
-
|
|
278
|
-
if command == "/init":
|
|
279
|
-
hook_integration = CLIHookIntegration()
|
|
280
|
-
return await hook_integration.handle_init_command("qoder")
|
|
281
|
-
|
|
282
|
-
return None
|
|
283
|
-
|
|
284
|
-
except Exception as e:
|
|
285
|
-
logger.error(f"Qoder通知处理失败: {e}")
|
|
286
|
-
return None
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
class CodeBuddySkillsIntegration:
|
|
290
|
-
"""CodeBuddy CLI 技能集成"""
|
|
291
|
-
|
|
292
|
-
@staticmethod
|
|
293
|
-
async def on_skill_activation(context: Dict[str, Any]) -> Optional[str]:
|
|
294
|
-
"""处理技能激活"""
|
|
295
|
-
try:
|
|
296
|
-
skill_name = context.get("skill_name", "")
|
|
297
|
-
|
|
298
|
-
if skill_name == "ai_cli_init":
|
|
299
|
-
hook_integration = CLIHookIntegration()
|
|
300
|
-
return await hook_integration.handle_init_command("codebuddy")
|
|
301
|
-
|
|
302
|
-
return None
|
|
303
|
-
|
|
304
|
-
except Exception as e:
|
|
305
|
-
logger.error(f"CodeBuddy技能处理失败: {e}")
|
|
306
|
-
return None
|
|
307
|
-
|
|
308
|
-
@staticmethod
|
|
309
|
-
async def on_user_command(context: Dict[str, Any]) -> Optional[str]:
|
|
310
|
-
"""处理用户命令(备用)"""
|
|
311
|
-
try:
|
|
312
|
-
command = context.get("command", "").strip()
|
|
313
|
-
|
|
314
|
-
if command == "/init":
|
|
315
|
-
hook_integration = CLIHookIntegration()
|
|
316
|
-
return await hook_integration.handle_init_command("codebuddy")
|
|
317
|
-
|
|
318
|
-
return None
|
|
319
|
-
|
|
320
|
-
except Exception as e:
|
|
321
|
-
logger.error(f"CodeBuddy命令处理失败: {e}")
|
|
322
|
-
return None
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
class CopilotMCPIntegration:
|
|
326
|
-
"""Copilot CLI MCP集成"""
|
|
327
|
-
|
|
328
|
-
@staticmethod
|
|
329
|
-
async def on_agent_execution(context: Dict[str, Any]) -> Optional[str]:
|
|
330
|
-
"""处理代理执行"""
|
|
331
|
-
try:
|
|
332
|
-
agent_request = context.get("request", "")
|
|
333
|
-
|
|
334
|
-
if agent_request.strip() == "/init":
|
|
335
|
-
hook_integration = CLIHookIntegration()
|
|
336
|
-
return await hook_integration.handle_init_command("copilot")
|
|
337
|
-
|
|
338
|
-
return None
|
|
339
|
-
|
|
340
|
-
except Exception as e:
|
|
341
|
-
logger.error(f"Copilot MCP处理失败: {e}")
|
|
342
|
-
return None
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
class CodexSlashIntegration:
|
|
346
|
-
"""Codex CLI 斜杠命令集成"""
|
|
347
|
-
|
|
348
|
-
@staticmethod
|
|
349
|
-
async def on_slash_command(context: Dict[str, Any]) -> Optional[str]:
|
|
350
|
-
"""处理斜杠命令"""
|
|
351
|
-
try:
|
|
352
|
-
command = context.get("command", "")
|
|
353
|
-
args = context.get("args", [])
|
|
354
|
-
|
|
355
|
-
if command == "init" and not args:
|
|
356
|
-
hook_integration = CLIHookIntegration()
|
|
357
|
-
return await hook_integration.handle_init_command("codex")
|
|
358
|
-
|
|
359
|
-
return None
|
|
360
|
-
|
|
361
|
-
except Exception as e:
|
|
362
|
-
logger.error(f"Codex斜杠命令处理失败: {e}")
|
|
363
|
-
return None
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
# 集成映射表
|
|
367
|
-
CLI_INTEGRATIONS = {
|
|
368
|
-
"claude": ClaudeHookIntegration,
|
|
369
|
-
"gemini": GeminiExtensionIntegration,
|
|
370
|
-
"qwen": QwenCodeInheritanceIntegration,
|
|
371
|
-
"iflow": IFlowWorkflowIntegration,
|
|
372
|
-
"qoder": QoderNotificationIntegration,
|
|
373
|
-
"codebuddy": CodeBuddySkillsIntegration,
|
|
374
|
-
"copilot": CopilotMCPIntegration,
|
|
375
|
-
"codex": CodexSlashIntegration
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
def get_cli_integration(cli_name: str):
|
|
380
|
-
"""获取CLI工具的集成类"""
|
|
381
|
-
return CLI_INTEGRATIONS.get(cli_name)
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
# 通用钩子处理器(用于适配器集成)
|
|
385
|
-
async def universal_init_handler(current_cli: str, context: Dict[str, Any]) -> Optional[str]:
|
|
386
|
-
"""通用的 /init 处理器,适用于所有CLI工具"""
|
|
387
|
-
try:
|
|
388
|
-
# 从上下文中提取用户输入
|
|
389
|
-
user_input = ""
|
|
390
|
-
|
|
391
|
-
# 尝试从不同的上下文字段中获取用户输入
|
|
392
|
-
for field in ["prompt", "command", "request", "user_input"]:
|
|
393
|
-
if field in context:
|
|
394
|
-
user_input = str(context[field]).strip()
|
|
395
|
-
break
|
|
396
|
-
|
|
397
|
-
# 检查是否为 /init 指令
|
|
398
|
-
if user_input == "/init":
|
|
399
|
-
hook_integration = CLIHookIntegration()
|
|
400
|
-
return await hook_integration.handle_init_command(current_cli, context.get("project_path"))
|
|
401
|
-
|
|
402
|
-
return None
|
|
403
|
-
|
|
404
|
-
except Exception as e:
|
|
405
|
-
logger.error(f"通用 /init 处理器失败: {e}")
|
|
406
|
-
return None
|