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,564 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Copilot CLI 跨CLI集成安装脚本
|
|
4
|
-
|
|
5
|
-
自动安装和配置Copilot CLI的跨CLI集成功能
|
|
6
|
-
包括MCP服务器注册、自定义代理创建和权限配置
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
import os
|
|
10
|
-
import json
|
|
11
|
-
import sys
|
|
12
|
-
import logging
|
|
13
|
-
import shutil
|
|
14
|
-
import argparse
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
from typing import Dict, Any, Optional
|
|
17
|
-
from datetime import datetime
|
|
18
|
-
|
|
19
|
-
# 设置日志
|
|
20
|
-
logging.basicConfig(
|
|
21
|
-
level=logging.INFO,
|
|
22
|
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
23
|
-
)
|
|
24
|
-
logger = logging.getLogger(__name__)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class CopilotIntegrationInstaller:
|
|
28
|
-
"""Copilot CLI集成安装器"""
|
|
29
|
-
|
|
30
|
-
def __init__(self, config_path: Optional[str] = None):
|
|
31
|
-
"""
|
|
32
|
-
初始化安装器
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
config_path: 配置文件路径,如果为None则使用默认路径
|
|
36
|
-
"""
|
|
37
|
-
self.script_dir = Path(__file__).parent
|
|
38
|
-
self.project_root = self.script_dir.parent.parent.parent
|
|
39
|
-
|
|
40
|
-
if config_path:
|
|
41
|
-
self.config_path = Path(config_path)
|
|
42
|
-
else:
|
|
43
|
-
# 在npx环境下,可能需要搜索配置文件的多个位置
|
|
44
|
-
possible_paths = [
|
|
45
|
-
self.script_dir / "config.json", # 标准位置 - 应该是最可能的路径
|
|
46
|
-
self.script_dir.parent / "copilot" / "config.json", # 在adapters/copilot/下
|
|
47
|
-
Path(__file__).parent / "config.json", # 使用脚本所在目录 - 也是标准位置
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
# 检查环境变量以获取项目根目录
|
|
51
|
-
project_root_env = os.environ.get('STIGMERGY_PROJECT_ROOT', '')
|
|
52
|
-
if project_root_env:
|
|
53
|
-
# 添加环境变量指定的路径到搜索列表
|
|
54
|
-
env_config_path = Path(project_root_env) / "src" / "adapters" / "copilot" / "config.json"
|
|
55
|
-
possible_paths.append(env_config_path)
|
|
56
|
-
|
|
57
|
-
for config_path_option in possible_paths:
|
|
58
|
-
if config_path_option.exists():
|
|
59
|
-
self.config_path = config_path_option
|
|
60
|
-
logger.info(f"使用配置文件: {config_path_option}")
|
|
61
|
-
break
|
|
62
|
-
else:
|
|
63
|
-
# 如果所有选项都失败,使用默认位置并动态创建配置
|
|
64
|
-
self.config_path = self.script_dir / "config.json"
|
|
65
|
-
|
|
66
|
-
# 创建默认配置内容
|
|
67
|
-
default_config = {
|
|
68
|
-
"name": "copilot",
|
|
69
|
-
"displayName": "GitHub Copilot CLI",
|
|
70
|
-
"version": "1.0.0",
|
|
71
|
-
"integration_type": "mcp_server",
|
|
72
|
-
"config_file": "~/.config/copilot/config.json",
|
|
73
|
-
"global_doc": "copilot.md",
|
|
74
|
-
"description": "GitHub Copilot CLI MCP服务器集成适配器",
|
|
75
|
-
"mcp_config": {
|
|
76
|
-
"server_name": "stigmergy-copilot-integration",
|
|
77
|
-
"command": "python",
|
|
78
|
-
"args": [
|
|
79
|
-
"src/adapters/copilot/mcp_server.py"
|
|
80
|
-
],
|
|
81
|
-
"environment": {
|
|
82
|
-
"PYTHONPATH": ".",
|
|
83
|
-
"STIGMERGY_CONFIG_PATH": "~/.stigmergy",
|
|
84
|
-
"COPILOT_ADAPTER_MODE": "cross_cli"
|
|
85
|
-
},
|
|
86
|
-
"health_check_interval": 30,
|
|
87
|
-
"timeout": 60
|
|
88
|
-
},
|
|
89
|
-
"custom_agents": {
|
|
90
|
-
"cross_cli_caller": {
|
|
91
|
-
"name": "CrossCLICaller",
|
|
92
|
-
"description": "跨CLI工具调用代理",
|
|
93
|
-
"version": "1.0.0",
|
|
94
|
-
"tools": [
|
|
95
|
-
"cross_cli_execute",
|
|
96
|
-
"get_available_clis",
|
|
97
|
-
"check_cli_status"
|
|
98
|
-
],
|
|
99
|
-
"permissions": [
|
|
100
|
-
"execute_external_cli",
|
|
101
|
-
"read_config",
|
|
102
|
-
"write_logs"
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"supported_cli_tools": [
|
|
107
|
-
"claude",
|
|
108
|
-
"gemini",
|
|
109
|
-
"qwencode",
|
|
110
|
-
"iflow",
|
|
111
|
-
"qoder",
|
|
112
|
-
"codebuddy",
|
|
113
|
-
"codex"
|
|
114
|
-
],
|
|
115
|
-
"permissions": {
|
|
116
|
-
"execute_external_cli": {
|
|
117
|
-
"description": "执行外部CLI工具",
|
|
118
|
-
"level": "high",
|
|
119
|
-
"requires_approval": False
|
|
120
|
-
},
|
|
121
|
-
"read_config": {
|
|
122
|
-
"description": "读取CLI配置文件",
|
|
123
|
-
"level": "medium",
|
|
124
|
-
"requires_approval": False
|
|
125
|
-
},
|
|
126
|
-
"write_logs": {
|
|
127
|
-
"description": "写入日志文件",
|
|
128
|
-
"level": "low",
|
|
129
|
-
"requires_approval": False
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
"adapter": {
|
|
133
|
-
"name": "Copilot MCP Integration Adapter",
|
|
134
|
-
"version": "1.0.0",
|
|
135
|
-
"type": "mcp_server",
|
|
136
|
-
"module_path": "src.adapters.copilot.mcp_adapter",
|
|
137
|
-
"class_name": "CopilotMCPIntegrationAdapter",
|
|
138
|
-
"features": [
|
|
139
|
-
"cross_cli_detection",
|
|
140
|
-
"command_routing",
|
|
141
|
-
"result_formatting",
|
|
142
|
-
"collaboration_tracking"
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
# 创建配置文件
|
|
148
|
-
try:
|
|
149
|
-
self.script_dir.mkdir(parents=True, exist_ok=True)
|
|
150
|
-
with open(self.config_path, 'w', encoding='utf-8') as f:
|
|
151
|
-
import json
|
|
152
|
-
json.dump(default_config, f, indent=2, ensure_ascii=False)
|
|
153
|
-
logger.info(f"[OK] 已创建默认配置文件: {self.config_path}")
|
|
154
|
-
except Exception as e:
|
|
155
|
-
logger.error(f"❌ 创建默认配置文件失败: {e}")
|
|
156
|
-
raise
|
|
157
|
-
|
|
158
|
-
logger.info(f"使用动态创建的配置文件: {self.config_path}")
|
|
159
|
-
|
|
160
|
-
self.config = self._load_config()
|
|
161
|
-
|
|
162
|
-
# Copilot相关路径
|
|
163
|
-
self.home_dir = Path.home()
|
|
164
|
-
self.copilot_dir = self.home_dir / ".copilot"
|
|
165
|
-
self.mcp_config_file = self.copilot_dir / "mcp-config.json"
|
|
166
|
-
self.custom_agents_dir = self.copilot_dir / "agents"
|
|
167
|
-
|
|
168
|
-
# 项目路径
|
|
169
|
-
self.src_dir = self.project_root / "src"
|
|
170
|
-
|
|
171
|
-
def _load_config(self) -> Dict[str, Any]:
|
|
172
|
-
"""加载配置文件"""
|
|
173
|
-
try:
|
|
174
|
-
with open(self.config_path, 'r', encoding='utf-8') as f:
|
|
175
|
-
return json.load(f)
|
|
176
|
-
except Exception as e:
|
|
177
|
-
logger.error(f"加载配置文件失败: {e}")
|
|
178
|
-
sys.exit(1)
|
|
179
|
-
|
|
180
|
-
def install(self, force: bool = False) -> bool:
|
|
181
|
-
"""
|
|
182
|
-
执行完整安装流程
|
|
183
|
-
|
|
184
|
-
Args:
|
|
185
|
-
force: 是否强制覆盖现有配置
|
|
186
|
-
|
|
187
|
-
Returns:
|
|
188
|
-
bool: 安装是否成功
|
|
189
|
-
"""
|
|
190
|
-
try:
|
|
191
|
-
logger.info("开始安装Copilot CLI跨CLI集成...")
|
|
192
|
-
|
|
193
|
-
# 1. 检查环境
|
|
194
|
-
if not self._check_environment():
|
|
195
|
-
return False
|
|
196
|
-
|
|
197
|
-
# 2. 创建配置目录
|
|
198
|
-
if not self._create_directories():
|
|
199
|
-
return False
|
|
200
|
-
|
|
201
|
-
# 3. 安装MCP服务器配置
|
|
202
|
-
if not self._install_mcp_server(force):
|
|
203
|
-
return False
|
|
204
|
-
|
|
205
|
-
# 4. 创建自定义代理
|
|
206
|
-
if not self._create_custom_agents(force):
|
|
207
|
-
return False
|
|
208
|
-
|
|
209
|
-
# 5. 设置权限配置
|
|
210
|
-
if not self._setup_permissions():
|
|
211
|
-
return False
|
|
212
|
-
|
|
213
|
-
# 6. 验证安装
|
|
214
|
-
if not self._verify_installation():
|
|
215
|
-
return False
|
|
216
|
-
|
|
217
|
-
logger.info("[OK] Copilot CLI跨CLI集成安装成功!")
|
|
218
|
-
self._print_usage_instructions()
|
|
219
|
-
return True
|
|
220
|
-
|
|
221
|
-
except Exception as e:
|
|
222
|
-
logger.error(f"安装失败: {e}")
|
|
223
|
-
return False
|
|
224
|
-
|
|
225
|
-
def _check_environment(self) -> bool:
|
|
226
|
-
"""检查安装环境"""
|
|
227
|
-
logger.info("检查安装环境...")
|
|
228
|
-
|
|
229
|
-
# 检查Python版本
|
|
230
|
-
if sys.version_info < (3, 8):
|
|
231
|
-
logger.error("需要Python 3.8或更高版本")
|
|
232
|
-
return False
|
|
233
|
-
|
|
234
|
-
# 检查Copilot CLI是否安装
|
|
235
|
-
copilot_path = shutil.which("copilot")
|
|
236
|
-
if not copilot_path:
|
|
237
|
-
logger.warning("⚠️ 未找到copilot命令,请确保已安装GitHub Copilot CLI")
|
|
238
|
-
logger.info("安装方法: npm install -g @github/copilot")
|
|
239
|
-
|
|
240
|
-
# 询问是否继续
|
|
241
|
-
response = input("是否继续安装?(y/N): ").strip().lower()
|
|
242
|
-
if response not in ['y', 'yes']:
|
|
243
|
-
return False
|
|
244
|
-
|
|
245
|
-
# 检查项目结构
|
|
246
|
-
if not self.src_dir.exists():
|
|
247
|
-
logger.error(f"项目源码目录不存在: {self.src_dir}")
|
|
248
|
-
return False
|
|
249
|
-
|
|
250
|
-
# 检查适配器文件
|
|
251
|
-
adapter_file = self.script_dir / "mcp_adapter.py"
|
|
252
|
-
if not adapter_file.exists():
|
|
253
|
-
logger.error(f"适配器文件不存在: {adapter_file}")
|
|
254
|
-
return False
|
|
255
|
-
|
|
256
|
-
logger.info("[OK] 环境检查通过")
|
|
257
|
-
return True
|
|
258
|
-
|
|
259
|
-
def _create_directories(self) -> bool:
|
|
260
|
-
"""创建必要的目录"""
|
|
261
|
-
logger.info("创建配置目录...")
|
|
262
|
-
|
|
263
|
-
directories = [
|
|
264
|
-
self.copilot_dir,
|
|
265
|
-
self.custom_agents_dir,
|
|
266
|
-
self.copilot_dir / "logs",
|
|
267
|
-
self.copilot_dir / "sessions"
|
|
268
|
-
]
|
|
269
|
-
|
|
270
|
-
for directory in directories:
|
|
271
|
-
try:
|
|
272
|
-
directory.mkdir(parents=True, exist_ok=True)
|
|
273
|
-
logger.debug(f"创建目录: {directory}")
|
|
274
|
-
except Exception as e:
|
|
275
|
-
logger.error(f"创建目录失败 {directory}: {e}")
|
|
276
|
-
return False
|
|
277
|
-
|
|
278
|
-
logger.info("[OK] 目录创建完成")
|
|
279
|
-
return True
|
|
280
|
-
|
|
281
|
-
def _install_mcp_server(self, force: bool = False) -> bool:
|
|
282
|
-
"""安装MCP服务器配置"""
|
|
283
|
-
logger.info("安装MCP服务器配置...")
|
|
284
|
-
|
|
285
|
-
try:
|
|
286
|
-
# 读取现有MCP配置
|
|
287
|
-
mcp_config = self._load_existing_mcp_config()
|
|
288
|
-
|
|
289
|
-
# 添加我们的MCP服务器
|
|
290
|
-
mcp_servers = mcp_config.get('mcpServers', {})
|
|
291
|
-
server_name = self.config['mcp_config']['server_name']
|
|
292
|
-
|
|
293
|
-
if server_name in mcp_servers and not force:
|
|
294
|
-
logger.warning(f"MCP服务器 '{server_name}' 已存在")
|
|
295
|
-
response = input("是否覆盖?(y/N): ").strip().lower()
|
|
296
|
-
if response not in ['y', 'yes']:
|
|
297
|
-
return True
|
|
298
|
-
|
|
299
|
-
# 构建MCP服务器配置
|
|
300
|
-
mcp_server_config = {
|
|
301
|
-
"command": self.config['mcp_config']['command'],
|
|
302
|
-
"args": self.config['mcp_config']['args'],
|
|
303
|
-
"env": self.config['mcp_config']['environment']
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
# 添加Python路径到环境变量
|
|
307
|
-
python_path = str(self.project_root)
|
|
308
|
-
if 'PYTHONPATH' in mcp_server_config['env']:
|
|
309
|
-
mcp_server_config['env']['PYTHONPATH'] = f"{python_path}:{mcp_server_config['env']['PYTHONPATH']}"
|
|
310
|
-
else:
|
|
311
|
-
mcp_server_config['env']['PYTHONPATH'] = python_path
|
|
312
|
-
|
|
313
|
-
mcp_servers[server_name] = mcp_server_config
|
|
314
|
-
mcp_config['mcpServers'] = mcp_servers
|
|
315
|
-
|
|
316
|
-
# 保存配置
|
|
317
|
-
with open(self.mcp_config_file, 'w', encoding='utf-8') as f:
|
|
318
|
-
json.dump(mcp_config, f, indent=2, ensure_ascii=False)
|
|
319
|
-
|
|
320
|
-
logger.info(f"[OK] MCP服务器配置已保存到: {self.mcp_config_file}")
|
|
321
|
-
return True
|
|
322
|
-
|
|
323
|
-
except Exception as e:
|
|
324
|
-
logger.error(f"安装MCP服务器失败: {e}")
|
|
325
|
-
return False
|
|
326
|
-
|
|
327
|
-
def _load_existing_mcp_config(self) -> Dict[str, Any]:
|
|
328
|
-
"""加载现有MCP配置"""
|
|
329
|
-
if self.mcp_config_file.exists():
|
|
330
|
-
try:
|
|
331
|
-
with open(self.mcp_config_file, 'r', encoding='utf-8') as f:
|
|
332
|
-
return json.load(f)
|
|
333
|
-
except Exception as e:
|
|
334
|
-
logger.warning(f"读取现有MCP配置失败: {e}")
|
|
335
|
-
|
|
336
|
-
# 返回默认配置
|
|
337
|
-
return {
|
|
338
|
-
"mcpServers": {}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
def _create_custom_agents(self, force: bool = False) -> bool:
|
|
342
|
-
"""创建自定义代理"""
|
|
343
|
-
logger.info("创建自定义代理...")
|
|
344
|
-
|
|
345
|
-
try:
|
|
346
|
-
for agent_name, agent_config in self.config['custom_agents'].items():
|
|
347
|
-
agent_file = self.custom_agents_dir / f"{agent_name}.json"
|
|
348
|
-
|
|
349
|
-
if agent_file.exists() and not force:
|
|
350
|
-
logger.warning(f"代理 '{agent_name}' 已存在")
|
|
351
|
-
response = input("是否覆盖?(y/N): ").strip().lower()
|
|
352
|
-
if response not in ['y', 'yes']:
|
|
353
|
-
continue
|
|
354
|
-
|
|
355
|
-
# 创建代理配置
|
|
356
|
-
agent_data = {
|
|
357
|
-
"name": agent_config['name'],
|
|
358
|
-
"description": agent_config['description'],
|
|
359
|
-
"version": agent_config['version'],
|
|
360
|
-
"instructions": self._get_agent_instructions(agent_name),
|
|
361
|
-
"tools": agent_config['tools'],
|
|
362
|
-
"permissions": agent_config['permissions']
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
with open(agent_file, 'w', encoding='utf-8') as f:
|
|
366
|
-
json.dump(agent_data, f, indent=2, ensure_ascii=False)
|
|
367
|
-
|
|
368
|
-
logger.info(f"创建代理: {agent_name}")
|
|
369
|
-
|
|
370
|
-
logger.info("[OK] 自定义代理创建完成")
|
|
371
|
-
return True
|
|
372
|
-
|
|
373
|
-
except Exception as e:
|
|
374
|
-
logger.error(f"创建自定义代理失败: {e}")
|
|
375
|
-
return False
|
|
376
|
-
|
|
377
|
-
def _get_agent_instructions(self, agent_name: str) -> str:
|
|
378
|
-
"""获取代理指令"""
|
|
379
|
-
instructions = {
|
|
380
|
-
"cross_cli_caller": """You are a cross-CLI integration agent that helps users collaborate between different AI CLI tools.
|
|
381
|
-
|
|
382
|
-
When you detect a request to use another CLI tool (like Claude, Gemini, QwenCode, iFlow, etc.):
|
|
383
|
-
1. Parse the target CLI and task from the user's request
|
|
384
|
-
2. Execute the task using the appropriate CLI tool
|
|
385
|
-
3. Return the results in a clear, structured format
|
|
386
|
-
|
|
387
|
-
Support both Chinese and English collaboration patterns:
|
|
388
|
-
- "请用{CLI}帮我{task}" -> Use {CLI} to help with {task}
|
|
389
|
-
- "调用{CLI}来{task}" -> Call {CLI} to {task}
|
|
390
|
-
- "use {CLI} to {task}" -> Execute {task} with {CLI}
|
|
391
|
-
- "call {CLI} to {task}" -> Call {CLI} to execute {task}
|
|
392
|
-
|
|
393
|
-
Available tools:
|
|
394
|
-
- cross_cli_execute: Execute tasks on other CLI tools
|
|
395
|
-
- get_available_clis: Get list of available CLI tools
|
|
396
|
-
- check_cli_status: Check status of a specific CLI tool
|
|
397
|
-
|
|
398
|
-
Always maintain the original intent and context of the user's request.
|
|
399
|
-
Provide clear, structured results with execution details."""
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return instructions.get(agent_name, "Cross-CLI integration agent")
|
|
403
|
-
|
|
404
|
-
def _setup_permissions(self) -> bool:
|
|
405
|
-
"""设置权限配置"""
|
|
406
|
-
logger.info("设置权限配置...")
|
|
407
|
-
|
|
408
|
-
try:
|
|
409
|
-
permissions_config_file = self.copilot_dir / "permissions.json"
|
|
410
|
-
|
|
411
|
-
permissions_config = {
|
|
412
|
-
"version": "1.0",
|
|
413
|
-
"permissions": self.config['permissions'],
|
|
414
|
-
"created_at": datetime.now().isoformat(),
|
|
415
|
-
"adapter_version": self.config['adapter']['version']
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
with open(permissions_config_file, 'w', encoding='utf-8') as f:
|
|
419
|
-
json.dump(permissions_config, f, indent=2, ensure_ascii=False)
|
|
420
|
-
|
|
421
|
-
logger.info("[OK] 权限配置设置完成")
|
|
422
|
-
return True
|
|
423
|
-
|
|
424
|
-
except Exception as e:
|
|
425
|
-
logger.error(f"设置权限配置失败: {e}")
|
|
426
|
-
return False
|
|
427
|
-
|
|
428
|
-
def _verify_installation(self) -> bool:
|
|
429
|
-
"""验证安装"""
|
|
430
|
-
logger.info("验证安装...")
|
|
431
|
-
|
|
432
|
-
# 检查MCP配置文件
|
|
433
|
-
if not self.mcp_config_file.exists():
|
|
434
|
-
logger.error("MCP配置文件不存在")
|
|
435
|
-
return False
|
|
436
|
-
|
|
437
|
-
# 检查自定义代理
|
|
438
|
-
for agent_name in self.config['custom_agents'].keys():
|
|
439
|
-
agent_file = self.custom_agents_dir / f"{agent_name}.json"
|
|
440
|
-
if not agent_file.exists():
|
|
441
|
-
logger.error(f"代理文件不存在: {agent_file}")
|
|
442
|
-
return False
|
|
443
|
-
|
|
444
|
-
# 验证MCP配置格式
|
|
445
|
-
try:
|
|
446
|
-
with open(self.mcp_config_file, 'r', encoding='utf-8') as f:
|
|
447
|
-
mcp_config = json.load(f)
|
|
448
|
-
|
|
449
|
-
server_name = self.config['mcp_config']['server_name']
|
|
450
|
-
if server_name not in mcp_config.get('mcpServers', {}):
|
|
451
|
-
logger.error(f"MCP服务器配置未找到: {server_name}")
|
|
452
|
-
return False
|
|
453
|
-
|
|
454
|
-
except Exception as e:
|
|
455
|
-
logger.error(f"验证MCP配置失败: {e}")
|
|
456
|
-
return False
|
|
457
|
-
|
|
458
|
-
logger.info("[OK] 安装验证通过")
|
|
459
|
-
return True
|
|
460
|
-
|
|
461
|
-
def _print_usage_instructions(self):
|
|
462
|
-
"""打印使用说明"""
|
|
463
|
-
print("\n" + "="*60)
|
|
464
|
-
print("🎉 Copilot CLI跨CLI集成安装完成!")
|
|
465
|
-
print("="*60)
|
|
466
|
-
print("\n[INFO] 使用说明:")
|
|
467
|
-
print("1. 启动Copilot CLI:")
|
|
468
|
-
print(" copilot")
|
|
469
|
-
print("\n2. 跨CLI调用示例:")
|
|
470
|
-
print(" 中文: '请用claude帮我写一个Python脚本'")
|
|
471
|
-
print(" 英文: 'use gemini to analyze this code'")
|
|
472
|
-
print("\n3. 可用的代理:")
|
|
473
|
-
for agent_name in self.config['custom_agents'].keys():
|
|
474
|
-
print(f" - {agent_name}")
|
|
475
|
-
print("\n4. 支持的CLI工具:")
|
|
476
|
-
for cli_tool in self.config['supported_cli_tools']:
|
|
477
|
-
print(f" - {cli_tool}")
|
|
478
|
-
print("\n📁 配置文件位置:")
|
|
479
|
-
print(f" MCP配置: {self.mcp_config_file}")
|
|
480
|
-
print(f" 自定义代理: {self.custom_agents_dir}")
|
|
481
|
-
print("\n📚 更多信息请参考项目文档")
|
|
482
|
-
print("="*60)
|
|
483
|
-
|
|
484
|
-
def uninstall(self) -> bool:
|
|
485
|
-
"""卸载集成"""
|
|
486
|
-
logger.info("卸载Copilot CLI跨CLI集成...")
|
|
487
|
-
|
|
488
|
-
try:
|
|
489
|
-
# 1. 移除MCP服务器配置
|
|
490
|
-
if self.mcp_config_file.exists():
|
|
491
|
-
mcp_config = self._load_existing_mcp_config()
|
|
492
|
-
server_name = self.config['mcp_config']['server_name']
|
|
493
|
-
|
|
494
|
-
if server_name in mcp_config.get('mcpServers', {}):
|
|
495
|
-
del mcp_config['mcpServers'][server_name]
|
|
496
|
-
|
|
497
|
-
with open(self.mcp_config_file, 'w', encoding='utf-8') as f:
|
|
498
|
-
json.dump(mcp_config, f, indent=2, ensure_ascii=False)
|
|
499
|
-
|
|
500
|
-
logger.info(f"移除MCP服务器配置: {server_name}")
|
|
501
|
-
|
|
502
|
-
# 2. 移除自定义代理
|
|
503
|
-
for agent_name in self.config['custom_agents'].keys():
|
|
504
|
-
agent_file = self.custom_agents_dir / f"{agent_name}.json"
|
|
505
|
-
if agent_file.exists():
|
|
506
|
-
agent_file.unlink()
|
|
507
|
-
logger.info(f"移除代理: {agent_name}")
|
|
508
|
-
|
|
509
|
-
# 3. 询问是否移除配置目录
|
|
510
|
-
if self.copilot_dir.exists():
|
|
511
|
-
response = input(f"是否删除配置目录 {self.copilot_dir}?(y/N): ").strip().lower()
|
|
512
|
-
if response in ['y', 'yes']:
|
|
513
|
-
shutil.rmtree(self.copilot_dir)
|
|
514
|
-
logger.info("删除配置目录")
|
|
515
|
-
|
|
516
|
-
logger.info("[OK] 卸载完成")
|
|
517
|
-
return True
|
|
518
|
-
|
|
519
|
-
except Exception as e:
|
|
520
|
-
logger.error(f"卸载失败: {e}")
|
|
521
|
-
return False
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
def main():
|
|
525
|
-
"""主函数"""
|
|
526
|
-
parser = argparse.ArgumentParser(description="Copilot CLI跨CLI集成安装程序")
|
|
527
|
-
parser.add_argument(
|
|
528
|
-
"--config",
|
|
529
|
-
help="配置文件路径",
|
|
530
|
-
default=None
|
|
531
|
-
)
|
|
532
|
-
parser.add_argument(
|
|
533
|
-
"--force",
|
|
534
|
-
action="store_true",
|
|
535
|
-
help="强制覆盖现有配置"
|
|
536
|
-
)
|
|
537
|
-
parser.add_argument(
|
|
538
|
-
"--uninstall",
|
|
539
|
-
action="store_true",
|
|
540
|
-
help="卸载集成"
|
|
541
|
-
)
|
|
542
|
-
parser.add_argument(
|
|
543
|
-
"--verbose", "-v",
|
|
544
|
-
action="store_true",
|
|
545
|
-
help="详细输出"
|
|
546
|
-
)
|
|
547
|
-
|
|
548
|
-
args = parser.parse_args()
|
|
549
|
-
|
|
550
|
-
if args.verbose:
|
|
551
|
-
logging.getLogger().setLevel(logging.DEBUG)
|
|
552
|
-
|
|
553
|
-
installer = CopilotIntegrationInstaller(args.config)
|
|
554
|
-
|
|
555
|
-
if args.uninstall:
|
|
556
|
-
success = installer.uninstall()
|
|
557
|
-
else:
|
|
558
|
-
success = installer.install(args.force)
|
|
559
|
-
|
|
560
|
-
sys.exit(0 if success else 1)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if __name__ == "__main__":
|
|
564
|
-
main()
|