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
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Codex CLI MCP 服务器 - 基于 Model Context Protocol 的跨CLI集成
|
|
3
|
-
|
|
4
|
-
提供标准的 MCP 接口,支持 Codex CLI 通过 MCP 协议进行跨CLI调用
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import asyncio
|
|
8
|
-
import json
|
|
9
|
-
import logging
|
|
10
|
-
from typing import Dict, Any, Optional, List
|
|
11
|
-
from datetime import datetime
|
|
12
|
-
|
|
13
|
-
logger = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CrossCliMCPServer:
|
|
17
|
-
"""
|
|
18
|
-
跨CLI调用 MCP 服务器
|
|
19
|
-
|
|
20
|
-
实现标准 MCP 协议,为 Codex CLI 提供跨CLI调用能力
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
def __init__(self):
|
|
24
|
-
"""初始化 MCP 服务器"""
|
|
25
|
-
self.server_name = "cross-cli-mcp-server"
|
|
26
|
-
self.version = "1.0.0"
|
|
27
|
-
self.tools = {
|
|
28
|
-
"execute_cross_cli_call": {
|
|
29
|
-
"name": "execute_cross_cli_call",
|
|
30
|
-
"description": "执行跨CLI调用,支持在不同AI CLI工具间无缝切换",
|
|
31
|
-
"inputSchema": {
|
|
32
|
-
"type": "object",
|
|
33
|
-
"properties": {
|
|
34
|
-
"target_cli": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "目标CLI工具名称 (claude, gemini, qwencode, iflow, qoder, codebuddy)",
|
|
37
|
-
"enum": ["claude", "gemini", "qwencode", "iflow", "qoder", "codebuddy", "copilot"]
|
|
38
|
-
},
|
|
39
|
-
"task": {
|
|
40
|
-
"type": "string",
|
|
41
|
-
"description": "要在目标CLI中执行的任务描述"
|
|
42
|
-
},
|
|
43
|
-
"context": {
|
|
44
|
-
"type": "object",
|
|
45
|
-
"description": "执行上下文信息(可选)",
|
|
46
|
-
"properties": {
|
|
47
|
-
"source_cli": {"type": "string"},
|
|
48
|
-
"session_id": {"type": "string"},
|
|
49
|
-
"user_id": {"type": "string"},
|
|
50
|
-
"priority": {"type": "string", "enum": ["low", "normal", "high"]}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"required": ["target_cli", "task"]
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
"list_supported_clis": {
|
|
58
|
-
"name": "list_supported_clis",
|
|
59
|
-
"description": "列出所有支持跨CLI调用的工具及其状态",
|
|
60
|
-
"inputSchema": {
|
|
61
|
-
"type": "object",
|
|
62
|
-
"properties": {
|
|
63
|
-
"check_availability": {
|
|
64
|
-
"type": "boolean",
|
|
65
|
-
"description": "是否检查工具可用性",
|
|
66
|
-
"default": True
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
"get_cross_cli_help": {
|
|
72
|
-
"name": "get_cross_cli_help",
|
|
73
|
-
"description": "获取跨CLI调用系统的帮助信息",
|
|
74
|
-
"inputSchema": {
|
|
75
|
-
"type": "object",
|
|
76
|
-
"properties": {
|
|
77
|
-
"target_cli": {
|
|
78
|
-
"type": "string",
|
|
79
|
-
"description": "指定获取某个特定CLI的帮助信息(可选)"
|
|
80
|
-
},
|
|
81
|
-
"language": {
|
|
82
|
-
"type": "string",
|
|
83
|
-
"description": "帮助信息语言 (zh, en)",
|
|
84
|
-
"enum": ["zh", "en"],
|
|
85
|
-
"default": "zh"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
# 直接处理器引用
|
|
93
|
-
self._direct_handlers = {}
|
|
94
|
-
|
|
95
|
-
async def initialize(self):
|
|
96
|
-
"""初始化 MCP 服务器 - 直接加载,无需Factory"""
|
|
97
|
-
try:
|
|
98
|
-
# 直接加载跨CLI处理器
|
|
99
|
-
self._direct_handlers = {}
|
|
100
|
-
self._load_direct_handlers()
|
|
101
|
-
|
|
102
|
-
logger.info(f"MCP 服务器 {self.server_name} 初始化成功(直接模式)")
|
|
103
|
-
return True
|
|
104
|
-
except Exception as e:
|
|
105
|
-
logger.error(f"MCP 服务器初始化失败: {e}")
|
|
106
|
-
return False
|
|
107
|
-
|
|
108
|
-
def _load_direct_handlers(self):
|
|
109
|
-
"""
|
|
110
|
-
直接加载CLI处理器,无需Factory中介
|
|
111
|
-
"""
|
|
112
|
-
try:
|
|
113
|
-
# 直接导入Claude CLI处理器
|
|
114
|
-
from ..claude.hook_adapter import get_claude_hook_adapter
|
|
115
|
-
self._direct_handlers['claude'] = get_claude_hook_adapter()
|
|
116
|
-
logger.info("Claude CLI 处理器直接加载成功")
|
|
117
|
-
except Exception as e:
|
|
118
|
-
logger.warning(f"Claude CLI 处理器加载失败: {e}")
|
|
119
|
-
|
|
120
|
-
# 可以继续添加其他CLI处理器
|
|
121
|
-
|
|
122
|
-
async def handle_tool_call(self, tool_name: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
|
123
|
-
"""
|
|
124
|
-
处理 MCP 工具调用
|
|
125
|
-
|
|
126
|
-
Args:
|
|
127
|
-
tool_name: 工具名称
|
|
128
|
-
arguments: 工具参数
|
|
129
|
-
|
|
130
|
-
Returns:
|
|
131
|
-
Dict[str, Any]: 工具执行结果
|
|
132
|
-
"""
|
|
133
|
-
try:
|
|
134
|
-
if tool_name not in self.tools:
|
|
135
|
-
return {
|
|
136
|
-
"success": False,
|
|
137
|
-
"error": f"未知工具: {tool_name}",
|
|
138
|
-
"available_tools": list(self.tools.keys())
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if tool_name == "execute_cross_cli_call":
|
|
142
|
-
return await self._execute_cross_cli_call(arguments)
|
|
143
|
-
elif tool_name == "list_supported_clis":
|
|
144
|
-
return await self._list_supported_clis(arguments)
|
|
145
|
-
elif tool_name == "get_cross_cli_help":
|
|
146
|
-
return await self._get_cross_cli_help(arguments)
|
|
147
|
-
else:
|
|
148
|
-
return {
|
|
149
|
-
"success": False,
|
|
150
|
-
"error": f"工具 {tool_name} 尚未实现"
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
except Exception as e:
|
|
154
|
-
logger.error(f"处理工具调用失败 {tool_name}: {e}")
|
|
155
|
-
return {
|
|
156
|
-
"success": False,
|
|
157
|
-
"error": f"工具执行异常: {str(e)}"
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async def _execute_cross_cli_call(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
161
|
-
"""执行跨CLI调用 - 直接原生模式"""
|
|
162
|
-
try:
|
|
163
|
-
target_cli = args.get("target_cli")
|
|
164
|
-
task = args.get("task")
|
|
165
|
-
context = args.get("context", {})
|
|
166
|
-
|
|
167
|
-
if not target_cli or not task:
|
|
168
|
-
return {
|
|
169
|
-
"success": False,
|
|
170
|
-
"error": "缺少必需参数: target_cli 和 task"
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
# 直接获取目标CLI处理器
|
|
174
|
-
if not hasattr(self, '_direct_handlers'):
|
|
175
|
-
await self.initialize()
|
|
176
|
-
|
|
177
|
-
target_handler = self._direct_handlers.get(target_cli.lower())
|
|
178
|
-
|
|
179
|
-
if not target_handler:
|
|
180
|
-
return {
|
|
181
|
-
"success": False,
|
|
182
|
-
"error": f"目标CLI工具 '{target_cli}' 不可用或未配置",
|
|
183
|
-
"available_clis": list(self._direct_handlers.keys())
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
# 检查处理器可用性
|
|
187
|
-
if hasattr(target_handler, 'is_available') and not target_handler.is_available():
|
|
188
|
-
return {
|
|
189
|
-
"success": False,
|
|
190
|
-
"error": f"目标CLI工具 '{target_cli}' 当前不可用",
|
|
191
|
-
"suggestion": "请检查该工具是否正确安装和配置"
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
# 构建执行上下文
|
|
195
|
-
execution_context = {
|
|
196
|
-
'source_cli': 'codex_mcp',
|
|
197
|
-
'target_cli': target_cli.lower(),
|
|
198
|
-
'original_task': task,
|
|
199
|
-
'mcp_call': True,
|
|
200
|
-
'direct_call': True,
|
|
201
|
-
'timestamp': datetime.now().isoformat(),
|
|
202
|
-
**context
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
# 直接执行任务 - 通过原生机制
|
|
206
|
-
if hasattr(target_handler, 'execute_task'):
|
|
207
|
-
result = await target_handler.execute_task(task, execution_context)
|
|
208
|
-
else:
|
|
209
|
-
result = f"[{target_cli.upper()} MCP原生调用] {task} - 直接处理完成"
|
|
210
|
-
|
|
211
|
-
# 返回标准 MCP 响应格式
|
|
212
|
-
return {
|
|
213
|
-
"success": True,
|
|
214
|
-
"result": result,
|
|
215
|
-
"metadata": {
|
|
216
|
-
"target_cli": target_cli,
|
|
217
|
-
"task": task,
|
|
218
|
-
"execution_time": datetime.now().isoformat(),
|
|
219
|
-
"result_length": len(result),
|
|
220
|
-
"call_method": "direct_mcp_native"
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
except Exception as e:
|
|
225
|
-
logger.error(f"跨CLI调用执行失败: {e}")
|
|
226
|
-
return {
|
|
227
|
-
"success": False,
|
|
228
|
-
"error": f"执行跨CLI调用失败: {str(e)}"
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async def _list_supported_clis(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
232
|
-
"""列出支持的CLI工具"""
|
|
233
|
-
try:
|
|
234
|
-
check_availability = args.get("check_availability", True)
|
|
235
|
-
|
|
236
|
-
if not self.adapter_factory:
|
|
237
|
-
await self.initialize()
|
|
238
|
-
|
|
239
|
-
supported_clis = ["claude", "gemini", "qwencode", "iflow", "qoder", "codebuddy", "copilot"]
|
|
240
|
-
|
|
241
|
-
result = {
|
|
242
|
-
"success": True,
|
|
243
|
-
"supported_clis": supported_clis,
|
|
244
|
-
"cli_details": {}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if check_availability and self.adapter_factory:
|
|
248
|
-
available_map = self.adapter_factory.list_available_adapters()
|
|
249
|
-
health_results = await self.adapter_factory.health_check_all()
|
|
250
|
-
|
|
251
|
-
for cli in supported_clis:
|
|
252
|
-
result["cli_details"][cli] = {
|
|
253
|
-
"available": available_map.get(cli, False),
|
|
254
|
-
"health": health_results.get(cli, {}).get("status", "unknown"),
|
|
255
|
-
"description": self._get_cli_description(cli)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return result
|
|
259
|
-
|
|
260
|
-
except Exception as e:
|
|
261
|
-
return {
|
|
262
|
-
"success": False,
|
|
263
|
-
"error": f"获取CLI列表失败: {str(e)}"
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
async def _get_cross_cli_help(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
267
|
-
"""获取跨CLI帮助信息"""
|
|
268
|
-
try:
|
|
269
|
-
target_cli = args.get("target_cli")
|
|
270
|
-
language = args.get("language", "zh")
|
|
271
|
-
|
|
272
|
-
if target_cli:
|
|
273
|
-
# 返回特定CLI的帮助
|
|
274
|
-
help_text = self._get_specific_cli_help(target_cli.lower(), language)
|
|
275
|
-
else:
|
|
276
|
-
# 返回通用帮助
|
|
277
|
-
help_text = self._get_general_help(language)
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
"success": True,
|
|
281
|
-
"help_text": help_text,
|
|
282
|
-
"metadata": {
|
|
283
|
-
"target_cli": target_cli,
|
|
284
|
-
"language": language,
|
|
285
|
-
"format": "markdown"
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
except Exception as e:
|
|
290
|
-
return {
|
|
291
|
-
"success": False,
|
|
292
|
-
"error": f"获取帮助信息失败: {str(e)}"
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
def _get_cli_description(self, cli: str) -> str:
|
|
296
|
-
"""获取CLI工具描述"""
|
|
297
|
-
descriptions = {
|
|
298
|
-
"claude": "Claude CLI - Anthropic 的AI助手CLI工具",
|
|
299
|
-
"gemini": "Gemini CLI - Google 的AI模型CLI工具",
|
|
300
|
-
"qwencode": "QwenCode CLI - 阿里云的代码生成CLI工具",
|
|
301
|
-
"iflow": "iFlow CLI - 智能流程编排CLI工具",
|
|
302
|
-
"qoder": "Qoder CLI - 智能编码助手CLI工具",
|
|
303
|
-
"codebuddy": "CodeBuddy CLI - 代码伙伴CLI工具",
|
|
304
|
-
"copilot": "GitHub Copilot CLI - GitHub的AI编程助手"
|
|
305
|
-
}
|
|
306
|
-
return descriptions.get(cli, "未知的CLI工具")
|
|
307
|
-
|
|
308
|
-
def _get_specific_cli_help(self, cli: str, language: str) -> str:
|
|
309
|
-
"""获取特定CLI的帮助信息"""
|
|
310
|
-
if language == "en":
|
|
311
|
-
return f"""## {cli.upper()} CLI Integration Help
|
|
312
|
-
|
|
313
|
-
### Usage via MCP
|
|
314
|
-
```python
|
|
315
|
-
# Execute cross-CLI call
|
|
316
|
-
result = await mcp.call_tool("execute_cross_cli_call", {{
|
|
317
|
-
"target_cli": "{cli}",
|
|
318
|
-
"task": "your task description"
|
|
319
|
-
}})
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### Usage via Slash Commands
|
|
323
|
-
```
|
|
324
|
-
/x {cli} your task description
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Common Tasks
|
|
328
|
-
- Code generation and analysis
|
|
329
|
-
- Debugging and refactoring
|
|
330
|
-
- Testing and documentation
|
|
331
|
-
- Code review and optimization
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
*Powered by Cross-CLI Integration System*"""
|
|
335
|
-
else:
|
|
336
|
-
return f"""## {cli.upper()} CLI 集成帮助
|
|
337
|
-
|
|
338
|
-
### 通过 MCP 使用
|
|
339
|
-
```python
|
|
340
|
-
# 执行跨CLI调用
|
|
341
|
-
result = await mcp.call_tool("execute_cross_cli_call", {{
|
|
342
|
-
"target_cli": "{cli}",
|
|
343
|
-
"task": "您的任务描述"
|
|
344
|
-
}})
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### 通过斜杠命令使用
|
|
348
|
-
```
|
|
349
|
-
/x {cli} 您的任务描述
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### 常用任务
|
|
353
|
-
- 代码生成和分析
|
|
354
|
-
- 调试和重构
|
|
355
|
-
- 测试和文档生成
|
|
356
|
-
- 代码审查和优化
|
|
357
|
-
|
|
358
|
-
---
|
|
359
|
-
*由跨CLI集成系统提供支持*"""
|
|
360
|
-
|
|
361
|
-
def _get_general_help(self, language: str) -> str:
|
|
362
|
-
"""获取通用帮助信息"""
|
|
363
|
-
if language == "en":
|
|
364
|
-
return """## Cross-CLI Integration System Help
|
|
365
|
-
|
|
366
|
-
### Overview
|
|
367
|
-
The Cross-CLI Integration System allows you to seamlessly call different AI CLI tools from within Codex CLI using either MCP (Model Context Protocol) or slash commands.
|
|
368
|
-
|
|
369
|
-
### Available Methods
|
|
370
|
-
|
|
371
|
-
#### 1. MCP Tools
|
|
372
|
-
- `execute_cross_cli_call` - Execute cross-CLI calls
|
|
373
|
-
- `list_supported_clis` - List all supported CLI tools
|
|
374
|
-
- `get_cross_cli_help` - Get help information
|
|
375
|
-
|
|
376
|
-
#### 2. Slash Commands
|
|
377
|
-
```
|
|
378
|
-
/x <cli> <task>
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Supported CLI Tools
|
|
382
|
-
- `claude` - Anthropic Claude CLI
|
|
383
|
-
- `gemini` - Google Gemini CLI
|
|
384
|
-
- `qwencode` - Alibaba QwenCode CLI
|
|
385
|
-
- `iflow` - Intelligent Flow CLI
|
|
386
|
-
- `qoder` - Qoder CLI
|
|
387
|
-
- `codebuddy` - CodeBuddy CLI
|
|
388
|
-
- `copilot` - GitHub Copilot CLI
|
|
389
|
-
|
|
390
|
-
### Examples
|
|
391
|
-
```bash
|
|
392
|
-
# Using slash commands
|
|
393
|
-
/x claude help me write a Python function
|
|
394
|
-
/x gemini analyze this code performance
|
|
395
|
-
/x qwencode refactor this React component
|
|
396
|
-
|
|
397
|
-
# Using MCP tools
|
|
398
|
-
await mcp.call_tool("execute_cross_cli_call", {
|
|
399
|
-
"target_cli": "claude",
|
|
400
|
-
"task": "help me write a Python function"
|
|
401
|
-
})
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
---
|
|
405
|
-
*Powered by Cross-CLI Integration System*"""
|
|
406
|
-
else:
|
|
407
|
-
return """## 跨CLI集成系统帮助
|
|
408
|
-
|
|
409
|
-
### 概述
|
|
410
|
-
跨CLI集成系统允许您在 Codex CLI 中无缝调用不同的AI CLI工具,支持 MCP (模型上下文协议) 和斜杠命令两种方式。
|
|
411
|
-
|
|
412
|
-
### 可用方法
|
|
413
|
-
|
|
414
|
-
#### 1. MCP 工具
|
|
415
|
-
- `execute_cross_cli_call` - 执行跨CLI调用
|
|
416
|
-
- `list_supported_clis` - 列出所有支持的CLI工具
|
|
417
|
-
- `get_cross_cli_help` - 获取帮助信息
|
|
418
|
-
|
|
419
|
-
#### 2. 斜杠命令
|
|
420
|
-
```
|
|
421
|
-
/x <CLI工具> <任务描述>
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
### 支持的CLI工具
|
|
425
|
-
- `claude` - Anthropic Claude CLI
|
|
426
|
-
- `gemini` - Google Gemini CLI
|
|
427
|
-
- `qwencode` - 阿里云通义千问代码CLI
|
|
428
|
-
- `iflow` - 智能流程CLI
|
|
429
|
-
- `qoder` - Qoder CLI
|
|
430
|
-
- `codebuddy` - CodeBuddy CLI
|
|
431
|
-
- `copilot` - GitHub Copilot CLI
|
|
432
|
-
|
|
433
|
-
### 使用示例
|
|
434
|
-
```bash
|
|
435
|
-
# 使用斜杠命令
|
|
436
|
-
/x claude 帮我写一个Python函数
|
|
437
|
-
/x gemini 分析这段代码性能
|
|
438
|
-
/x qwencode 重构这个React组件
|
|
439
|
-
|
|
440
|
-
# 使用MCP工具
|
|
441
|
-
await mcp.call_tool("execute_cross_cli_call", {
|
|
442
|
-
"target_cli": "claude",
|
|
443
|
-
"task": "帮我写一个Python函数"
|
|
444
|
-
})
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
---
|
|
448
|
-
*由跨CLI集成系统提供支持*"""
|
|
449
|
-
|
|
450
|
-
def get_mcp_manifest(self) -> Dict[str, Any]:
|
|
451
|
-
"""
|
|
452
|
-
获取 MCP 服务器清单
|
|
453
|
-
|
|
454
|
-
Returns:
|
|
455
|
-
Dict[str, Any]: MCP 服务器清单
|
|
456
|
-
"""
|
|
457
|
-
return {
|
|
458
|
-
"name": self.server_name,
|
|
459
|
-
"version": self.version,
|
|
460
|
-
"description": "跨CLI调用MCP服务器,支持在不同AI CLI工具间无缝切换",
|
|
461
|
-
"tools": list(self.tools.values()),
|
|
462
|
-
"resources": [],
|
|
463
|
-
"prompts": []
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
# 全局MCP服务器实例
|
|
468
|
-
_global_mcp_server: Optional[CrossCliMCPServer] = None
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
def get_cross_cli_mcp_server() -> CrossCliMCPServer:
|
|
472
|
-
"""
|
|
473
|
-
获取跨CLI MCP服务器实例
|
|
474
|
-
|
|
475
|
-
Returns:
|
|
476
|
-
CrossCliMCPServer: MCP服务器实例
|
|
477
|
-
"""
|
|
478
|
-
global _global_mcp_server
|
|
479
|
-
if _global_mcp_server is None:
|
|
480
|
-
_global_mcp_server = CrossCliMCPServer()
|
|
481
|
-
return _global_mcp_server
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
# 便捷函数
|
|
485
|
-
async def initialize_mcp_server() -> bool:
|
|
486
|
-
"""
|
|
487
|
-
初始化MCP服务器
|
|
488
|
-
|
|
489
|
-
Returns:
|
|
490
|
-
bool: 初始化是否成功
|
|
491
|
-
"""
|
|
492
|
-
server = get_cross_cli_mcp_server()
|
|
493
|
-
return await server.initialize()
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
自然语言解析器 - 简化版本
|
|
3
|
-
专注于检测跨CLI调用意图,无复杂抽象
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import re
|
|
7
|
-
import logging
|
|
8
|
-
from typing import Dict, Any, Optional
|
|
9
|
-
from dataclasses import dataclass
|
|
10
|
-
|
|
11
|
-
logger = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@dataclass
|
|
15
|
-
class IntentResult:
|
|
16
|
-
"""意图解析结果"""
|
|
17
|
-
is_cross_cli: bool = False
|
|
18
|
-
target_cli: Optional[str] = None
|
|
19
|
-
task: str = ""
|
|
20
|
-
confidence: float = 1.0
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class NaturalLanguageParser:
|
|
24
|
-
"""简化的自然语言解析器"""
|
|
25
|
-
|
|
26
|
-
def __init__(self):
|
|
27
|
-
# 中英文跨CLI调用模式
|
|
28
|
-
self.cn_patterns = [
|
|
29
|
-
r'请用(\w+)\s*帮我?([^。!?\n]*)',
|
|
30
|
-
r'调用(\w+)\s*来([^。!?\n]*)',
|
|
31
|
-
r'用(\w+)\s*帮我?([^。!?\n]*)'
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
self.en_patterns = [
|
|
35
|
-
r'use\s+(\w+)\s+to\s+([^.\n!?]*)',
|
|
36
|
-
r'call\s+(\w+)\s+to\s+([^.\n!?]*)',
|
|
37
|
-
r'ask\s+(\w+)\s+for\s+([^.\n!?]*)'
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
def detect_cross_cli_call(self, text: str) -> bool:
|
|
41
|
-
"""检测是否为跨CLI调用"""
|
|
42
|
-
intent = self.parse_intent(text, "unknown")
|
|
43
|
-
return intent.is_cross_cli
|
|
44
|
-
|
|
45
|
-
def parse_intent(self, text: str, source_cli: str) -> IntentResult:
|
|
46
|
-
"""解析意图"""
|
|
47
|
-
text = text.strip()
|
|
48
|
-
|
|
49
|
-
# 检测中文模式
|
|
50
|
-
for pattern in self.cn_patterns:
|
|
51
|
-
match = re.search(pattern, text, re.IGNORECASE)
|
|
52
|
-
if match:
|
|
53
|
-
cli_name = match.group(1).lower()
|
|
54
|
-
task = match.group(2).strip()
|
|
55
|
-
|
|
56
|
-
# 避免自我调用
|
|
57
|
-
if cli_name != source_cli.lower():
|
|
58
|
-
return IntentResult(
|
|
59
|
-
is_cross_cli=True,
|
|
60
|
-
target_cli=cli_name,
|
|
61
|
-
task=task,
|
|
62
|
-
confidence=0.9
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
# 检测英文模式
|
|
66
|
-
for pattern in self.en_patterns:
|
|
67
|
-
match = re.search(pattern, text, re.IGNORECASE)
|
|
68
|
-
if match:
|
|
69
|
-
cli_name = match.group(1).lower()
|
|
70
|
-
task = match.group(2).strip()
|
|
71
|
-
|
|
72
|
-
# 避免自我调用
|
|
73
|
-
if cli_name != source_cli.lower():
|
|
74
|
-
return IntentResult(
|
|
75
|
-
is_cross_cli=True,
|
|
76
|
-
target_cli=cli_name,
|
|
77
|
-
task=task,
|
|
78
|
-
confidence=0.9
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
# 不是跨CLI调用
|
|
82
|
-
return IntentResult(is_cross_cli=False, task=text)
|