stigmergy 1.0.57
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/LICENSE +19 -0
- package/README.de.md +301 -0
- package/README.en.md +301 -0
- package/README.es.md +301 -0
- package/README.fr.md +301 -0
- package/README.ja.md +301 -0
- package/README.ko.md +301 -0
- package/README.md +301 -0
- package/README.ru.md +301 -0
- package/README.zh.md +301 -0
- package/package.json +82 -0
- package/src/adapters/claude/__init__.py +13 -0
- package/src/adapters/claude/claude_skills_integration.py +609 -0
- package/src/adapters/claude/hook_adapter.py +663 -0
- package/src/adapters/claude/install_claude_integration.py +265 -0
- package/src/adapters/claude/skills_hook_adapter.py +841 -0
- package/src/adapters/claude/standalone_claude_adapter.py +384 -0
- package/src/adapters/cline/__init__.py +20 -0
- package/src/adapters/cline/config.py +108 -0
- package/src/adapters/cline/install_cline_integration.py +617 -0
- package/src/adapters/cline/mcp_server.py +713 -0
- package/src/adapters/cline/standalone_cline_adapter.py +459 -0
- package/src/adapters/codebuddy/__init__.py +13 -0
- package/src/adapters/codebuddy/buddy_adapter.py +1125 -0
- package/src/adapters/codebuddy/install_codebuddy_integration.py +279 -0
- package/src/adapters/codebuddy/skills_hook_adapter.py +672 -0
- package/src/adapters/codebuddy/skills_integration.py +395 -0
- package/src/adapters/codebuddy/standalone_codebuddy_adapter.py +403 -0
- package/src/adapters/codex/__init__.py +11 -0
- package/src/adapters/codex/base.py +46 -0
- package/src/adapters/codex/install_codex_integration.py +311 -0
- package/src/adapters/codex/mcp_server.py +493 -0
- package/src/adapters/codex/natural_language_parser.py +82 -0
- package/src/adapters/codex/slash_command_adapter.py +326 -0
- package/src/adapters/codex/standalone_codex_adapter.py +362 -0
- package/src/adapters/copilot/__init__.py +13 -0
- package/src/adapters/copilot/install_copilot_integration.py +564 -0
- package/src/adapters/copilot/mcp_adapter.py +772 -0
- package/src/adapters/copilot/mcp_server.py +168 -0
- package/src/adapters/copilot/standalone_copilot_adapter.py +114 -0
- package/src/adapters/gemini/__init__.py +13 -0
- package/src/adapters/gemini/extension_adapter.py +690 -0
- package/src/adapters/gemini/install_gemini_integration.py +257 -0
- package/src/adapters/gemini/standalone_gemini_adapter.py +366 -0
- package/src/adapters/iflow/__init__.py +7 -0
- package/src/adapters/iflow/hook_adapter.py +1038 -0
- package/src/adapters/iflow/hook_installer.py +536 -0
- package/src/adapters/iflow/install_iflow_integration.py +271 -0
- package/src/adapters/iflow/official_hook_adapter.py +1272 -0
- package/src/adapters/iflow/standalone_iflow_adapter.py +48 -0
- package/src/adapters/iflow/workflow_adapter.py +793 -0
- package/src/adapters/qoder/hook_installer.py +732 -0
- package/src/adapters/qoder/install_qoder_integration.py +265 -0
- package/src/adapters/qoder/notification_hook_adapter.py +863 -0
- package/src/adapters/qoder/standalone_qoder_adapter.py +48 -0
- package/src/adapters/qwen/__init__.py +17 -0
- package/src/adapters/qwencode/__init__.py +13 -0
- package/src/adapters/qwencode/inheritance_adapter.py +818 -0
- package/src/adapters/qwencode/install_qwencode_integration.py +276 -0
- package/src/adapters/qwencode/standalone_qwencode_adapter.py +399 -0
- package/src/atomic_collaboration_handler.py +461 -0
- package/src/cli_collaboration_agent.py +697 -0
- package/src/collaboration/hooks.py +315 -0
- package/src/core/__init__.py +21 -0
- package/src/core/ai_environment_scanner.py +331 -0
- package/src/core/base_adapter.py +220 -0
- package/src/core/cli_hook_integration.py +406 -0
- package/src/core/cross_cli_executor.py +713 -0
- package/src/core/cross_cli_mapping.py +1163 -0
- package/src/core/cross_platform_encoding.py +365 -0
- package/src/core/cross_platform_safe_cli.py +894 -0
- package/src/core/direct_cli_executor.py +805 -0
- package/src/core/direct_cli_hook_system.py +958 -0
- package/src/core/enhanced_init_processor.py +427 -0
- package/src/core/graceful_cli_executor.py +912 -0
- package/src/core/md_enhancer.py +342 -0
- package/src/core/md_generator.py +619 -0
- package/src/core/models.py +218 -0
- package/src/core/parser.py +108 -0
- package/src/core/real_cli_hook_system.py +852 -0
- package/src/core/real_cross_cli_system.py +925 -0
- package/src/core/verified_cross_cli_system.py +961 -0
- package/src/deploy.js +737 -0
- package/src/enhanced_deploy.js +303 -0
- package/src/enhanced_universal_cli_setup.py +930 -0
- package/src/kimi_wrapper.py +104 -0
- package/src/main.js +1309 -0
- package/src/shell_integration.py +398 -0
- package/src/simple-main.js +315 -0
- package/src/smart_router_creator.py +323 -0
- package/src/universal_cli_setup.py +1289 -0
- package/src/utils/__init__.py +12 -0
- package/src/utils/cli_detector.py +445 -0
- package/src/utils/file_utils.py +246 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"""
|
|
2
|
+
独立 Claude CLI 适配器 - 完全无抽象层
|
|
3
|
+
|
|
4
|
+
基于 Claude CLI 官方 Hook 系统的原生集成:
|
|
5
|
+
- 使用 Claude CLI 官方 Hook 机制
|
|
6
|
+
- 无任何抽象基类或 Factory 系统
|
|
7
|
+
- 不改变 CLI 启动和使用方式
|
|
8
|
+
- 纯粹的原生扩展实现
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import json
|
|
13
|
+
import logging
|
|
14
|
+
import asyncio
|
|
15
|
+
import re
|
|
16
|
+
from typing import Dict, Any, Optional, List
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ClaudeHookContext:
|
|
23
|
+
"""Claude CLI Hook 上下文 - 独立实现"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, prompt: str = "", metadata: Optional[Dict] = None):
|
|
26
|
+
self.prompt = prompt
|
|
27
|
+
self.metadata = metadata or {}
|
|
28
|
+
self.session_id = self.metadata.get('session_id', 'unknown')
|
|
29
|
+
self.user_id = self.metadata.get('user_id', 'unknown')
|
|
30
|
+
self.timestamp = datetime.now()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class StandaloneClaudeAdapter:
|
|
34
|
+
"""
|
|
35
|
+
独立的 Claude CLI Hook 适配器
|
|
36
|
+
|
|
37
|
+
直接基于 Claude CLI 官方 Hook 系统,无任何抽象层:
|
|
38
|
+
- user_prompt_submit Hook
|
|
39
|
+
- tool_use_pre/post Hooks
|
|
40
|
+
- response_generated Hook
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self):
|
|
44
|
+
"""初始化 - 纯实现,无抽象"""
|
|
45
|
+
self.cli_name = "claude"
|
|
46
|
+
self.version = "1.0.0"
|
|
47
|
+
|
|
48
|
+
# Hook 配置
|
|
49
|
+
self.hooks_config_file = os.path.expanduser("~/.config/claude/hooks.json")
|
|
50
|
+
self.hooks_registered = False
|
|
51
|
+
|
|
52
|
+
# 统计信息
|
|
53
|
+
self.execution_count = 0
|
|
54
|
+
self.error_count = 0
|
|
55
|
+
self.hook_calls_count = 0
|
|
56
|
+
self.cross_cli_calls_count = 0
|
|
57
|
+
self.processed_requests: List[Dict[str, Any]] = []
|
|
58
|
+
self.last_execution: Optional[datetime] = None
|
|
59
|
+
|
|
60
|
+
# Hook 处理器
|
|
61
|
+
self.hook_handlers = {
|
|
62
|
+
'user_prompt_submit': self.on_user_prompt_submit,
|
|
63
|
+
'tool_use_pre': self.on_tool_use_pre,
|
|
64
|
+
'tool_use_post': self.on_tool_use_post,
|
|
65
|
+
'response_generated': self.on_response_generated,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# 直接跨CLI处理器 - 无Factory
|
|
69
|
+
self._cli_handlers = {}
|
|
70
|
+
self._init_cli_handlers()
|
|
71
|
+
|
|
72
|
+
# 配置
|
|
73
|
+
self.config = self._load_config()
|
|
74
|
+
|
|
75
|
+
logger.info("独立 Claude CLI Hook 适配器初始化完成")
|
|
76
|
+
|
|
77
|
+
def _load_config(self) -> Dict[str, Any]:
|
|
78
|
+
"""加载配置"""
|
|
79
|
+
config_file = os.path.join(os.path.dirname(__file__), "config.json")
|
|
80
|
+
try:
|
|
81
|
+
with open(config_file, 'r', encoding='utf-8') as f:
|
|
82
|
+
return json.load(f)
|
|
83
|
+
except Exception as e:
|
|
84
|
+
logger.warning(f"配置加载失败: {e}")
|
|
85
|
+
return {"hooks": [], "integration_settings": {"enable_cross_cli": True}}
|
|
86
|
+
|
|
87
|
+
def _init_cli_handlers(self):
|
|
88
|
+
"""初始化跨CLI处理器 - 直接导入,无Factory"""
|
|
89
|
+
try:
|
|
90
|
+
# 可以直接添加其他CLI处理器
|
|
91
|
+
# from ..codex.standalone_codex_adapter import get_standalone_codex_adapter
|
|
92
|
+
# self._cli_handlers['codex'] = get_standalone_codex_adapter()
|
|
93
|
+
logger.info("跨CLI处理器初始化完成")
|
|
94
|
+
except Exception as e:
|
|
95
|
+
logger.warning(f"跨CLI处理器初始化失败: {e}")
|
|
96
|
+
|
|
97
|
+
def is_available(self) -> bool:
|
|
98
|
+
"""检查是否可用 - 直接检查 Claude CLI"""
|
|
99
|
+
try:
|
|
100
|
+
# 检查Claude CLI是否可用
|
|
101
|
+
import subprocess
|
|
102
|
+
result = subprocess.run(['claude', '--version'], capture_output=True, text=True, timeout=10)
|
|
103
|
+
return result.returncode == 0
|
|
104
|
+
except Exception:
|
|
105
|
+
return False
|
|
106
|
+
|
|
107
|
+
async def execute_task(self, task: str, context: Dict[str, Any] = None) -> str:
|
|
108
|
+
"""
|
|
109
|
+
执行任务 - 纯实现,无抽象层
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
task: 任务内容
|
|
113
|
+
context: 执行上下文
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
str: 执行结果
|
|
117
|
+
"""
|
|
118
|
+
if context is None:
|
|
119
|
+
context = {}
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
self.execution_count += 1
|
|
123
|
+
self.last_execution = datetime.now()
|
|
124
|
+
|
|
125
|
+
# 创建 Hook 上下文
|
|
126
|
+
hook_context = ClaudeHookContext(
|
|
127
|
+
prompt=task,
|
|
128
|
+
metadata=context.get('metadata', {})
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# 通过 Hook 系统处理
|
|
132
|
+
result = await self.on_user_prompt_submit(hook_context)
|
|
133
|
+
|
|
134
|
+
# 如果 Hook 没有处理,则本地处理
|
|
135
|
+
if result is None:
|
|
136
|
+
# 检测跨CLI调用
|
|
137
|
+
cross_cli_intent = self._detect_cross_cli_intent(task)
|
|
138
|
+
if cross_cli_intent:
|
|
139
|
+
return await self._handle_cross_cli_call(cross_cli_intent, context)
|
|
140
|
+
|
|
141
|
+
# 本地 Claude 处理
|
|
142
|
+
result = f"[Claude CLI 本地处理] {task}"
|
|
143
|
+
|
|
144
|
+
return result
|
|
145
|
+
|
|
146
|
+
except Exception as e:
|
|
147
|
+
self.error_count += 1
|
|
148
|
+
logger.error(f"任务执行失败: {task}, 错误: {e}")
|
|
149
|
+
return f"[错误] {task} 执行失败: {str(e)}"
|
|
150
|
+
|
|
151
|
+
def _detect_cross_cli_intent(self, text: str) -> Optional[str]:
|
|
152
|
+
"""检测跨CLI调用意图 - 简单实现,无抽象"""
|
|
153
|
+
# 中文模式
|
|
154
|
+
cn_patterns = [
|
|
155
|
+
r'请用(\w+)\s*帮我?([^。!?\n]*)',
|
|
156
|
+
r'调用(\w+)\s*来([^。!?\n]*)',
|
|
157
|
+
r'用(\w+)\s*帮我?([^。!?\n]*)'
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
for pattern in cn_patterns:
|
|
161
|
+
match = re.search(pattern, text, re.IGNORECASE)
|
|
162
|
+
if match:
|
|
163
|
+
cli_name = match.group(1).lower()
|
|
164
|
+
task = match.group(2).strip()
|
|
165
|
+
if cli_name != self.cli_name: # 避免自我调用
|
|
166
|
+
return f"{cli_name} {task}"
|
|
167
|
+
|
|
168
|
+
# 英文模式
|
|
169
|
+
en_patterns = [
|
|
170
|
+
r'use\s+(\w+)\s+to\s+([^.\n!?]*)',
|
|
171
|
+
r'call\s+(\w+)\s+to\s+([^.\n!?]*)',
|
|
172
|
+
r'ask\s+(\w+)\s+for\s+([^.\n!?]*)'
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
for pattern in en_patterns:
|
|
176
|
+
match = re.search(pattern, text, re.IGNORECASE)
|
|
177
|
+
if match:
|
|
178
|
+
cli_name = match.group(1).lower()
|
|
179
|
+
task = match.group(2).strip()
|
|
180
|
+
if cli_name != self.cli_name: # 避免自我调用
|
|
181
|
+
return f"{cli_name} {task}"
|
|
182
|
+
|
|
183
|
+
return None
|
|
184
|
+
|
|
185
|
+
async def _handle_cross_cli_call(self, command: str, context: Dict[str, Any]) -> str:
|
|
186
|
+
"""处理跨CLI调用 - 直接实现,无抽象层"""
|
|
187
|
+
if ' ' not in command:
|
|
188
|
+
return "跨CLI命令格式错误,请使用: <CLI> <任务>"
|
|
189
|
+
|
|
190
|
+
cli_name, task = command.split(' ', 1)
|
|
191
|
+
cli_name = cli_name.lower()
|
|
192
|
+
|
|
193
|
+
try:
|
|
194
|
+
self.cross_cli_calls_count += 1
|
|
195
|
+
|
|
196
|
+
# 直接调用目标CLI - 无抽象层
|
|
197
|
+
if cli_name in self._cli_handlers:
|
|
198
|
+
handler = self._cli_handlers[cli_name]
|
|
199
|
+
if hasattr(handler, 'execute_task'):
|
|
200
|
+
result = await handler.execute_task(task, {'source_cli': 'claude'})
|
|
201
|
+
return self._format_cross_cli_result(cli_name, task, result)
|
|
202
|
+
|
|
203
|
+
# 模拟跨CLI调用结果
|
|
204
|
+
result = f"[{cli_name.upper()} CLI 处理结果] {task}"
|
|
205
|
+
return self._format_cross_cli_result(cli_name, task, result)
|
|
206
|
+
|
|
207
|
+
except Exception as e:
|
|
208
|
+
logger.error(f"跨CLI调用失败: {cli_name}, {e}")
|
|
209
|
+
return f"跨CLI调用失败: {cli_name} - {str(e)}"
|
|
210
|
+
|
|
211
|
+
def _format_cross_cli_result(self, target_cli: str, task: str, result: str) -> str:
|
|
212
|
+
"""格式化跨CLI调用结果"""
|
|
213
|
+
return f"""## 🔗 跨CLI调用结果
|
|
214
|
+
|
|
215
|
+
**源工具**: Claude CLI (Hook 系统)
|
|
216
|
+
**目标工具**: {target_cli.upper()}
|
|
217
|
+
**任务**: {task}
|
|
218
|
+
**执行时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
{result}
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
*Claude Hook 系统原生集成 - 无抽象层*"""
|
|
227
|
+
|
|
228
|
+
# Hook 处理方法 - 基于 Claude CLI 官方 Hook 机制
|
|
229
|
+
async def on_user_prompt_submit(self, context: ClaudeHookContext) -> Optional[str]:
|
|
230
|
+
"""
|
|
231
|
+
用户提示提交 Hook - 核心跨CLI检测点
|
|
232
|
+
|
|
233
|
+
这是基于 Claude CLI 官方 Hook 系统的原生实现。
|
|
234
|
+
"""
|
|
235
|
+
try:
|
|
236
|
+
self.hook_calls_count += 1
|
|
237
|
+
user_input = context.prompt
|
|
238
|
+
|
|
239
|
+
# 记录请求
|
|
240
|
+
self.processed_requests.append({
|
|
241
|
+
'hook_type': 'user_prompt_submit',
|
|
242
|
+
'prompt': user_input,
|
|
243
|
+
'metadata': context.metadata,
|
|
244
|
+
'timestamp': datetime.now().isoformat()
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
# 检测跨CLI调用
|
|
248
|
+
cross_cli_intent = self._detect_cross_cli_intent(user_input)
|
|
249
|
+
if cross_cli_intent:
|
|
250
|
+
return await self._handle_cross_cli_call(cross_cli_intent, context.metadata)
|
|
251
|
+
|
|
252
|
+
# 不是跨CLI调用,让 Claude 正常处理
|
|
253
|
+
return None
|
|
254
|
+
|
|
255
|
+
except Exception as e:
|
|
256
|
+
logger.error(f"用户提示 Hook 处理失败: {e}")
|
|
257
|
+
self.error_count += 1
|
|
258
|
+
return None # 错误时让 Claude 继续正常处理
|
|
259
|
+
|
|
260
|
+
async def on_tool_use_pre(self, context: ClaudeHookContext) -> Optional[str]:
|
|
261
|
+
"""工具使用前 Hook"""
|
|
262
|
+
# 预处理工具调用
|
|
263
|
+
return None
|
|
264
|
+
|
|
265
|
+
async def on_tool_use_post(self, context: ClaudeHookContext) -> Optional[str]:
|
|
266
|
+
"""工具使用后 Hook"""
|
|
267
|
+
# 后处理工具调用结果
|
|
268
|
+
return None
|
|
269
|
+
|
|
270
|
+
async def on_response_generated(self, context: ClaudeHookContext) -> Optional[str]:
|
|
271
|
+
"""响应生成后 Hook"""
|
|
272
|
+
# 后处理 Claude 响应
|
|
273
|
+
return None
|
|
274
|
+
|
|
275
|
+
async def initialize(self) -> bool:
|
|
276
|
+
"""初始化适配器"""
|
|
277
|
+
try:
|
|
278
|
+
# 检查 Claude CLI 环境
|
|
279
|
+
if not self.is_available():
|
|
280
|
+
logger.warning("Claude CLI 不可用")
|
|
281
|
+
return False
|
|
282
|
+
|
|
283
|
+
# 注册 Hook 到 Claude CLI
|
|
284
|
+
await self._register_hooks()
|
|
285
|
+
|
|
286
|
+
# 创建配置目录
|
|
287
|
+
os.makedirs(os.path.dirname(self.hooks_config_file), exist_ok=True)
|
|
288
|
+
|
|
289
|
+
self.hooks_registered = True
|
|
290
|
+
logger.info("Claude Hook 适配器初始化成功 - 独立模式")
|
|
291
|
+
return True
|
|
292
|
+
|
|
293
|
+
except Exception as e:
|
|
294
|
+
logger.error(f"适配器初始化失败: {e}")
|
|
295
|
+
return False
|
|
296
|
+
|
|
297
|
+
async def _register_hooks(self) -> bool:
|
|
298
|
+
"""注册 Hook 到 Claude CLI"""
|
|
299
|
+
try:
|
|
300
|
+
# 读取现有 hooks 配置
|
|
301
|
+
hooks_config = self._load_hooks_config()
|
|
302
|
+
|
|
303
|
+
# 添加跨CLI Hook
|
|
304
|
+
cross_cli_hook = {
|
|
305
|
+
"name": "cross-cli-hooks",
|
|
306
|
+
"version": "1.0.0",
|
|
307
|
+
"description": "跨CLI调用集成Hook系统",
|
|
308
|
+
"author": "Smart CLI Router",
|
|
309
|
+
"module": "src.adapters.claude.standalone_claude_adapter",
|
|
310
|
+
"class": "StandaloneClaudeAdapter",
|
|
311
|
+
"enabled": True,
|
|
312
|
+
"priority": 100,
|
|
313
|
+
"hooks": list(self.hook_handlers.keys())
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
# 检查是否已存在
|
|
317
|
+
existing_hooks = hooks_config.get('hooks', [])
|
|
318
|
+
hook_exists = any(hook['name'] == cross_cli_hook['name'] for hook in existing_hooks)
|
|
319
|
+
|
|
320
|
+
if not hook_exists:
|
|
321
|
+
existing_hooks.append(cross_cli_hook)
|
|
322
|
+
hooks_config['hooks'] = existing_hooks
|
|
323
|
+
await self._save_hooks_config(hooks_config)
|
|
324
|
+
logger.info(f"注册 Hook: {cross_cli_hook['name']}")
|
|
325
|
+
else:
|
|
326
|
+
logger.info("Hook 已存在,跳过注册")
|
|
327
|
+
|
|
328
|
+
return True
|
|
329
|
+
|
|
330
|
+
except Exception as e:
|
|
331
|
+
logger.error(f"Hook 注册失败: {e}")
|
|
332
|
+
return False
|
|
333
|
+
|
|
334
|
+
def _load_hooks_config(self) -> Dict[str, Any]:
|
|
335
|
+
"""加载 Hooks 配置"""
|
|
336
|
+
if os.path.exists(self.hooks_config_file):
|
|
337
|
+
try:
|
|
338
|
+
with open(self.hooks_config_file, 'r', encoding='utf-8') as f:
|
|
339
|
+
return json.load(f)
|
|
340
|
+
except Exception as e:
|
|
341
|
+
logger.warning(f"加载 Hook 配置失败: {e}")
|
|
342
|
+
|
|
343
|
+
return {"version": "1.0", "hooks": []}
|
|
344
|
+
|
|
345
|
+
async def _save_hooks_config(self, config: Dict[str, Any]) -> bool:
|
|
346
|
+
"""保存 Hooks 配置"""
|
|
347
|
+
try:
|
|
348
|
+
with open(self.hooks_config_file, 'w', encoding='utf-8') as f:
|
|
349
|
+
json.dump(config, f, indent=2, ensure_ascii=False)
|
|
350
|
+
return True
|
|
351
|
+
except Exception as e:
|
|
352
|
+
logger.error(f"保存 Hook 配置失败: {e}")
|
|
353
|
+
return False
|
|
354
|
+
|
|
355
|
+
def get_statistics(self) -> Dict[str, Any]:
|
|
356
|
+
"""获取统计信息 - 直接实现"""
|
|
357
|
+
success_rate = ((self.execution_count - self.error_count) / self.execution_count) if self.execution_count > 0 else 1.0
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
'cli_name': self.cli_name,
|
|
361
|
+
'version': self.version,
|
|
362
|
+
'hooks_registered': self.hooks_registered,
|
|
363
|
+
'execution_count': self.execution_count,
|
|
364
|
+
'hook_calls_count': self.hook_calls_count,
|
|
365
|
+
'cross_cli_calls_count': self.cross_cli_calls_count,
|
|
366
|
+
'error_count': self.error_count,
|
|
367
|
+
'success_rate': success_rate,
|
|
368
|
+
'last_execution': self.last_execution.isoformat() if self.last_execution else None,
|
|
369
|
+
'design': 'standalone_hook_native',
|
|
370
|
+
'no_abstraction': True,
|
|
371
|
+
'hooks_config_file': self.hooks_config_file
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
# 便捷函数 - 无抽象层
|
|
376
|
+
def get_standalone_claude_adapter() -> StandaloneClaudeAdapter:
|
|
377
|
+
"""获取独立的 Claude CLI 适配器实例"""
|
|
378
|
+
return StandaloneClaudeAdapter()
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
# 保持向后兼容的函数名
|
|
382
|
+
def get_claude_hook_adapter() -> StandaloneClaudeAdapter:
|
|
383
|
+
"""获取 Claude Hook 适配器实例(向后兼容)"""
|
|
384
|
+
return get_standalone_claude_adapter()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Cline CLI Adapter for Stigmergy System
|
|
3
|
+
|
|
4
|
+
This module provides integration with Cline CLI through MCP (Model Context Protocol)
|
|
5
|
+
support, enabling cross-CLI collaboration and tool extension capabilities.
|
|
6
|
+
|
|
7
|
+
Key Features:
|
|
8
|
+
- MCP server integration for tool management
|
|
9
|
+
- Cross-CLI task delegation
|
|
10
|
+
- Context preservation across sessions
|
|
11
|
+
- Real-time collaboration with other CLI tools
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .standalone_cline_adapter import StandaloneClineAdapter
|
|
15
|
+
from .config import CLINE_CONFIG
|
|
16
|
+
|
|
17
|
+
__version__ = "1.0.0"
|
|
18
|
+
__author__ = "Stigmergy CLI Multi-Agents System"
|
|
19
|
+
|
|
20
|
+
__all__ = ["StandaloneClineAdapter", "CLINE_CONFIG"]
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Cline CLI Configuration Module
|
|
3
|
+
|
|
4
|
+
Defines configuration constants and utilities for Cline CLI integration
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Dict, Any, List
|
|
10
|
+
|
|
11
|
+
# Cline CLI Configuration
|
|
12
|
+
CLINE_CONFIG = {
|
|
13
|
+
"name": "cline",
|
|
14
|
+
"display_name": "Cline CLI",
|
|
15
|
+
"version": "1.0.0",
|
|
16
|
+
"mcp_protocol_version": "2024-11-05",
|
|
17
|
+
|
|
18
|
+
# Installation and execution
|
|
19
|
+
"npm_package": "cline",
|
|
20
|
+
"install_command": "npm install -g cline",
|
|
21
|
+
"execution_command": "cline",
|
|
22
|
+
"npx_command": "npx -y cline",
|
|
23
|
+
|
|
24
|
+
# Configuration files
|
|
25
|
+
"mcp_settings_file": "cline_mcp_settings.json",
|
|
26
|
+
"config_directory": ".cline",
|
|
27
|
+
"mcp_server_directory": "~/Documents/Cline/MCP",
|
|
28
|
+
|
|
29
|
+
# MCP Protocol settings
|
|
30
|
+
"mcp_transport_mechanisms": ["stdio", "http"],
|
|
31
|
+
"mcp_default_timeout": 60, # seconds
|
|
32
|
+
"mcp_max_retries": 3,
|
|
33
|
+
|
|
34
|
+
# Cross-CLI patterns
|
|
35
|
+
"intent_patterns": {
|
|
36
|
+
"chinese": [
|
|
37
|
+
r"请用cline\s*帮我?([^。!?\n]*)",
|
|
38
|
+
r"调用cline\s*来([^。!?\n]*)",
|
|
39
|
+
r"用cline\s*帮我?([^。!?\n]*)"
|
|
40
|
+
],
|
|
41
|
+
"english": [
|
|
42
|
+
r"use\s+cline\s+to\s+([^.\n!?]*)",
|
|
43
|
+
r"call\s+cline\s+to\s+([^.\n!?]*)",
|
|
44
|
+
r"ask\s+cline\s+for\s+([^.\n!?]*)"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
# Tool capabilities
|
|
49
|
+
"supported_tools": [
|
|
50
|
+
"file_operations",
|
|
51
|
+
"terminal_execution",
|
|
52
|
+
"browser_automation",
|
|
53
|
+
"tool_creation",
|
|
54
|
+
"context_management",
|
|
55
|
+
"mcp_server_management"
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
# API providers supported by Cline
|
|
59
|
+
"supported_providers": [
|
|
60
|
+
"anthropic",
|
|
61
|
+
"openai",
|
|
62
|
+
"google",
|
|
63
|
+
"openrouter",
|
|
64
|
+
"aws_bedrock",
|
|
65
|
+
"azure",
|
|
66
|
+
"gcp_vertex",
|
|
67
|
+
"cerebras",
|
|
68
|
+
"groq",
|
|
69
|
+
"local_ollama",
|
|
70
|
+
"lm_studio"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def get_cline_config_path() -> Path:
|
|
75
|
+
"""Get Cline configuration directory path"""
|
|
76
|
+
home = Path.home()
|
|
77
|
+
return home / ".config" / "cline"
|
|
78
|
+
|
|
79
|
+
def get_mcp_settings_path() -> Path:
|
|
80
|
+
"""Get MCP settings file path"""
|
|
81
|
+
return get_cline_config_path() / CLINE_CONFIG["mcp_settings_file"]
|
|
82
|
+
|
|
83
|
+
def get_mcp_server_directory() -> Path:
|
|
84
|
+
"""Get MCP server directory path"""
|
|
85
|
+
home = Path.home()
|
|
86
|
+
return home / "Documents" / "Cline" / "MCP"
|
|
87
|
+
|
|
88
|
+
def create_default_mcp_settings() -> Dict[str, Any]:
|
|
89
|
+
"""Create default MCP settings for Cline integration"""
|
|
90
|
+
return {
|
|
91
|
+
"mcpServers": {
|
|
92
|
+
"stigmergy": {
|
|
93
|
+
"command": "python",
|
|
94
|
+
"args": ["-m", "src.adapters.cline.mcp_server"],
|
|
95
|
+
"env": {
|
|
96
|
+
"STIGMERGY_PROJECT_ROOT": os.getcwd(),
|
|
97
|
+
"STIGMERGY_COLLABORATION_MODE": "enabled"
|
|
98
|
+
},
|
|
99
|
+
"disabled": False,
|
|
100
|
+
"autoStart": True
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"globalSettings": {
|
|
104
|
+
"timeout": CLINE_CONFIG["mcp_default_timeout"],
|
|
105
|
+
"maxRetries": CLINE_CONFIG["mcp_max_retries"],
|
|
106
|
+
"transport": "stdio"
|
|
107
|
+
}
|
|
108
|
+
}
|