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,619 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MD Document Generator - MD文档生成器
|
|
3
|
+
为新项目生成包含协作感知的完整MD文档
|
|
4
|
+
"""
|
|
5
|
+
import asyncio
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from typing import Dict, List, Optional
|
|
9
|
+
|
|
10
|
+
from .models import (
|
|
11
|
+
CLIInfo, AIEnvironmentInfo, GeneratedDocument, CLI_CONFIG_MAPPING
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MDDocumentGenerator:
|
|
19
|
+
"""MD文档生成器 - 为新项目生成完整MD文档"""
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
self.template_cache = {}
|
|
23
|
+
|
|
24
|
+
async def generate_complete_md(self,
|
|
25
|
+
cli_name: str,
|
|
26
|
+
cli_info: CLIInfo,
|
|
27
|
+
ai_environment: AIEnvironmentInfo,
|
|
28
|
+
current_cli: str) -> str:
|
|
29
|
+
"""为新项目生成完整的MD文档"""
|
|
30
|
+
try:
|
|
31
|
+
logger.info(f"为CLI工具 {cli_name} 生成完整MD文档")
|
|
32
|
+
|
|
33
|
+
# 生成基础文档结构
|
|
34
|
+
md_content = f"""# {cli_info.display_name} 项目配置
|
|
35
|
+
|
|
36
|
+
> 🆕 新项目初始化
|
|
37
|
+
> 📅 生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
38
|
+
> 🔧 由 {current_cli.upper()} 工具初始化
|
|
39
|
+
|
|
40
|
+
## 📋 项目概览
|
|
41
|
+
|
|
42
|
+
本项目已启用 **AI CLI Router 跨工具协作系统**,支持多个AI CLI工具的无缝协作。
|
|
43
|
+
|
|
44
|
+
### 🎯 主要特性
|
|
45
|
+
|
|
46
|
+
- ✅ **跨工具协作**: 支持多个AI CLI工具的协作开发
|
|
47
|
+
- ✅ **智能路由**: 自动识别和路由跨AI工具调用
|
|
48
|
+
- ✅ **配置管理**: 统一的AI环境配置管理
|
|
49
|
+
- ✅ **上下文保持**: 跨工具的上下文信息保持
|
|
50
|
+
- ✅ **错误恢复**: 智能的错误处理和恢复机制
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
# 添加CLI工具基本信息
|
|
55
|
+
md_content += await self._generate_cli_info_section(cli_info)
|
|
56
|
+
|
|
57
|
+
# 添加协作环境章节
|
|
58
|
+
collaboration_content = await self._generate_collaboration_section(cli_name, ai_environment, current_cli)
|
|
59
|
+
md_content += collaboration_content
|
|
60
|
+
|
|
61
|
+
# 添加项目特定配置
|
|
62
|
+
project_specific_content = await self._generate_project_specific_section(cli_name, ai_environment)
|
|
63
|
+
md_content += project_specific_content
|
|
64
|
+
|
|
65
|
+
# 添加快速开始指南
|
|
66
|
+
quick_start_content = await self._generate_quick_start_section(cli_name, ai_environment)
|
|
67
|
+
md_content += quick_start_content
|
|
68
|
+
|
|
69
|
+
# 添加配置参考
|
|
70
|
+
config_reference = await self._generate_config_reference_section(cli_name, ai_environment)
|
|
71
|
+
md_content += config_reference
|
|
72
|
+
|
|
73
|
+
# 添加故障排除指南
|
|
74
|
+
troubleshooting_content = await self._generate_troubleshooting_section(cli_name, ai_environment)
|
|
75
|
+
md_content += troubleshooting_content
|
|
76
|
+
|
|
77
|
+
logger.info(f"成功生成 {cli_name}.md 文档,包含完整的协作感知")
|
|
78
|
+
return md_content
|
|
79
|
+
|
|
80
|
+
except Exception as e:
|
|
81
|
+
logger.error(f"生成MD文档失败: {e}")
|
|
82
|
+
raise
|
|
83
|
+
|
|
84
|
+
async def _generate_cli_info_section(self, cli_info: CLIInfo) -> str:
|
|
85
|
+
"""生成CLI工具信息章节"""
|
|
86
|
+
return f"""
|
|
87
|
+
## 🤖 当前CLI工具信息
|
|
88
|
+
|
|
89
|
+
**{cli_info.display_name}** v{cli_info.version}
|
|
90
|
+
|
|
91
|
+
### 📊 基本信息
|
|
92
|
+
- **集成类型**: {self._get_integration_type_display(cli_info.integration_type)}
|
|
93
|
+
- **配置文件**: `{cli_info.config_file}`
|
|
94
|
+
- **状态**: {self._get_status_display(cli_info.status)}
|
|
95
|
+
- **全局记忆文档**: `{cli_info.global_doc}`
|
|
96
|
+
|
|
97
|
+
### ⚡ 核心能力
|
|
98
|
+
{self._format_capabilities(cli_info.capabilities)}
|
|
99
|
+
|
|
100
|
+
### 🔧 技术规格
|
|
101
|
+
- **协议支持**: 跨CLI协作协议、中英文自然语言处理
|
|
102
|
+
- **错误处理**: 优雅降级、自动重试、错误隔离
|
|
103
|
+
- **性能优化**: 异步执行、并发处理、智能缓存
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
async def _generate_collaboration_section(self,
|
|
107
|
+
cli_name: str,
|
|
108
|
+
ai_environment: AIEnvironmentInfo,
|
|
109
|
+
current_cli: str) -> str:
|
|
110
|
+
"""生成协作环境章节"""
|
|
111
|
+
current_cli_info = ai_environment.available_clis.get(cli_name)
|
|
112
|
+
peer_clis = ai_environment.collaboration_guide.available_peers
|
|
113
|
+
|
|
114
|
+
collaboration_section = f"""
|
|
115
|
+
|
|
116
|
+
## 🤝 AI工具协作环境
|
|
117
|
+
|
|
118
|
+
### 🎯 本项目AI工具生态系统
|
|
119
|
+
|
|
120
|
+
**当前激活工具**: **{current_cli_info.display_name}** v{current_cli_info.version}
|
|
121
|
+
|
|
122
|
+
**🔄 可协作工具生态系统**:
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
# 添加协作工具列表
|
|
126
|
+
for peer_name, peer_info in peer_clis.items():
|
|
127
|
+
status_emoji = "✅" if peer_info.status.value == "available" else "❌"
|
|
128
|
+
capabilities_text = ", ".join(peer_info.capabilities[:2])
|
|
129
|
+
if len(peer_info.capabilities) > 2:
|
|
130
|
+
capabilities_text += f" 等{len(peer_info.capabilities)}项"
|
|
131
|
+
|
|
132
|
+
collaboration_section += f"""
|
|
133
|
+
- **{peer_info.display_name}** v{peer_info.version}
|
|
134
|
+
- {status_emoji} 状态: {self._get_status_display(peer_info.status)}
|
|
135
|
+
- 🛠️ 类型: {self._get_integration_type_display(peer_info.integration_type)}
|
|
136
|
+
- ⚡ 能力: {capabilities_text}
|
|
137
|
+
- 📁 配置: `{peer_info.config_file}`
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
# 添加协作协议
|
|
141
|
+
collaboration_section += f"""
|
|
142
|
+
|
|
143
|
+
### 📝 跨AI协作协议
|
|
144
|
+
|
|
145
|
+
**中文协作指令模式**:
|
|
146
|
+
"""
|
|
147
|
+
chinese_protocols = ai_environment.collaboration_guide.protocols.get("chinese", [])[:6]
|
|
148
|
+
for protocol in chinese_protocols:
|
|
149
|
+
examples = self._generate_protocol_examples(protocol, list(peer_clis.keys())[:2])
|
|
150
|
+
collaboration_section += f"- `{protocol}`\n"
|
|
151
|
+
for example in examples[:2]: # 每个协议最多2个示例
|
|
152
|
+
collaboration_section += f" - 示例: `{example}`\n"
|
|
153
|
+
|
|
154
|
+
collaboration_section += """
|
|
155
|
+
**英文协作指令模式**:
|
|
156
|
+
"""
|
|
157
|
+
english_protocols = ai_environment.collaboration_guide.protocols.get("english", [])[:6]
|
|
158
|
+
for protocol in english_protocols:
|
|
159
|
+
examples = self._generate_protocol_examples(protocol, list(peer_clis.keys())[:2])
|
|
160
|
+
collaboration_section += f"- `{protocol}`\n"
|
|
161
|
+
for example in examples[:2]: # 每个协议最多2个示例
|
|
162
|
+
collaboration_section += f" - 示例: `{example}`\n"
|
|
163
|
+
|
|
164
|
+
# 添加协作场景
|
|
165
|
+
collaboration_section += f"""
|
|
166
|
+
|
|
167
|
+
### 🎨 典型协作场景
|
|
168
|
+
|
|
169
|
+
#### 1. 代码开发协作流程
|
|
170
|
+
```bash
|
|
171
|
+
# 开发新功能
|
|
172
|
+
> 请用qwen帮我实现用户认证模块
|
|
173
|
+
> 调用gemini分析安全漏洞
|
|
174
|
+
> 用claude审查代码架构
|
|
175
|
+
> 让iflow创建测试工作流
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### 2. 问题解决协作
|
|
179
|
+
```bash
|
|
180
|
+
# 解决复杂技术问题
|
|
181
|
+
> 用claude分析这个性能问题
|
|
182
|
+
> 调用gemini提供优化方案
|
|
183
|
+
> 请用qwen实现性能优化
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### 3. 项目维护协作
|
|
187
|
+
```bash
|
|
188
|
+
# 项目维护和更新
|
|
189
|
+
> 用iflow创建维护工作流
|
|
190
|
+
> 请用qwen重构老旧代码
|
|
191
|
+
> 调用gemini进行性能分析
|
|
192
|
+
> 让claude生成技术文档
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### 4. 数据处理协作
|
|
196
|
+
```bash
|
|
197
|
+
# 数据分析和处理
|
|
198
|
+
> 请用qwen处理这个数据集
|
|
199
|
+
> 用gemini进行统计分析
|
|
200
|
+
> 调用claude生成可视化报告
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 🎯 协作最佳实践
|
|
204
|
+
|
|
205
|
+
1. **上下文传递**: 在跨工具调用时保持充分的上下文信息
|
|
206
|
+
2. **任务分解**: 将复杂任务分解为不同工具的专长领域
|
|
207
|
+
3. **结果验证**: 使用不同工具交叉验证重要结果
|
|
208
|
+
4. **版本管理**: 为重要的协作结果建立版本控制
|
|
209
|
+
5. **错误处理**: 优雅处理跨工具调用中的错误情况
|
|
210
|
+
|
|
211
|
+
### 🔄 工具切换策略
|
|
212
|
+
|
|
213
|
+
| 任务类型 | 推荐工具 | 备用工具 |
|
|
214
|
+
|---------|---------|---------|
|
|
215
|
+
| 代码生成 | QwenCode | Claude |
|
|
216
|
+
| 性能优化 | Gemini | Claude |
|
|
217
|
+
| 架构设计 | Claude | Gemini |
|
|
218
|
+
| 工作流自动化 | iFlow | Claude |
|
|
219
|
+
| 代码审查 | Claude | Gemini |
|
|
220
|
+
| 数据分析 | Gemini | QwenCode |
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
return collaboration_section
|
|
224
|
+
|
|
225
|
+
async def _generate_project_specific_section(self,
|
|
226
|
+
cli_name: str,
|
|
227
|
+
ai_environment: AIEnvironmentInfo) -> str:
|
|
228
|
+
"""生成项目特定配置章节"""
|
|
229
|
+
|
|
230
|
+
return f"""
|
|
231
|
+
|
|
232
|
+
## ⚙️ 项目特定配置
|
|
233
|
+
|
|
234
|
+
### 📁 项目结构
|
|
235
|
+
|
|
236
|
+
建议的项目目录结构:
|
|
237
|
+
```
|
|
238
|
+
project-root/
|
|
239
|
+
├── {cli_name}.md # 当前工具的项目配置 (本文件)
|
|
240
|
+
├── claude.md # Claude CLI配置
|
|
241
|
+
├── gemini.md # Gemini CLI配置
|
|
242
|
+
├── qwen.md # QwenCode CLI配置
|
|
243
|
+
├── iflow.md # iFlow CLI配置
|
|
244
|
+
├── .ai-cli-project/ # AI项目配置目录
|
|
245
|
+
│ ├── project-config.json # 项目级AI配置
|
|
246
|
+
│ ├── collaboration-log.json # 协作历史记录
|
|
247
|
+
│ └── tool-preferences.json # 工具使用偏好
|
|
248
|
+
├── src/ # 源代码目录
|
|
249
|
+
├── tests/ # 测试目录
|
|
250
|
+
└── docs/ # 文档目录
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 🔧 AI配置管理
|
|
254
|
+
|
|
255
|
+
#### 全局配置
|
|
256
|
+
- **位置**: `~/.ai-cli-unified/global-config.json`
|
|
257
|
+
- **作用**: 存储所有AI CLI工具的全局配置
|
|
258
|
+
- **更新方式**: 通过 `ai-cli-router scan` 命令
|
|
259
|
+
|
|
260
|
+
#### 项目配置
|
|
261
|
+
- **位置**: `.ai-cli-project/project-config.json`
|
|
262
|
+
- **作用**: 项目特定的AI工具配置和偏好
|
|
263
|
+
- **更新方式**: 通过各CLI工具的配置功能
|
|
264
|
+
|
|
265
|
+
### 📊 协作统计
|
|
266
|
+
|
|
267
|
+
项目AI工具使用情况将自动记录在 `.ai-cli-project/collaboration-log.json` 中,包括:
|
|
268
|
+
- 跨工具调用次数
|
|
269
|
+
- 协作成功率
|
|
270
|
+
- 常用协作模式
|
|
271
|
+
- 性能指标统计
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
async def _generate_quick_start_section(self,
|
|
275
|
+
cli_name: str,
|
|
276
|
+
ai_environment: AIEnvironmentInfo) -> str:
|
|
277
|
+
"""生成快速开始指南"""
|
|
278
|
+
peer_clis = list(ai_environment.collaboration_guide.available_peers.keys())
|
|
279
|
+
|
|
280
|
+
quick_start = f"""
|
|
281
|
+
|
|
282
|
+
## 🚀 快速开始
|
|
283
|
+
|
|
284
|
+
### 1. 立即开始协作
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# 检查可用AI工具
|
|
288
|
+
> /init
|
|
289
|
+
|
|
290
|
+
# 开始跨工具协作
|
|
291
|
+
> 请用{peer_clis[0] if peer_clis else 'qwen'}帮我生成一个Python函数
|
|
292
|
+
> 调用{peer_clis[1] if len(peer_clis) > 1 else 'claude'}审查这段代码
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### 2. 常用协作模式
|
|
296
|
+
|
|
297
|
+
#### 🔗 代码生成 → 审查 → 优化
|
|
298
|
+
```bash
|
|
299
|
+
> 请用qwen生成用户认证代码
|
|
300
|
+
> 调用gemini分析性能
|
|
301
|
+
> 用claude审查架构设计
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### 🔄 问题分析 → 解决方案 → 实现
|
|
305
|
+
```bash
|
|
306
|
+
> 用claude分析这个bug
|
|
307
|
+
> 调用gemini提供解决方案
|
|
308
|
+
> 请用qwen实现修复代码
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### 📊 数据处理 → 分析 → 报告
|
|
312
|
+
```bash
|
|
313
|
+
> 请用qwen处理CSV数据
|
|
314
|
+
> 用gemini统计分析结果
|
|
315
|
+
> 调用claude生成分析报告
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 3. 工具特定功能
|
|
319
|
+
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
# 添加工具特定的快速开始内容
|
|
323
|
+
tool_specific_content = await self._generate_tool_specific_quick_start(cli_name, peer_clis)
|
|
324
|
+
quick_start += tool_specific_content
|
|
325
|
+
|
|
326
|
+
return quick_start
|
|
327
|
+
|
|
328
|
+
async def _generate_tool_specific_quick_start(self, cli_name: str, peer_clis: List[str]) -> str:
|
|
329
|
+
"""生成工具特定的快速开始内容"""
|
|
330
|
+
|
|
331
|
+
tool_guides = {
|
|
332
|
+
"claude": """
|
|
333
|
+
#### Claude CLI 特有功能
|
|
334
|
+
- **智能分析**: 深度语义理解和智能分析
|
|
335
|
+
- **学习优化**: 持续学习和性能优化
|
|
336
|
+
- **错误恢复**: 智能错误分析和自动恢复
|
|
337
|
+
|
|
338
|
+
推荐协作模式:
|
|
339
|
+
```bash
|
|
340
|
+
> 用claude分析这个需求的复杂性
|
|
341
|
+
> 请用qwen基于分析结果生成代码
|
|
342
|
+
> 调用gemini优化生成的代码性能
|
|
343
|
+
```
|
|
344
|
+
""",
|
|
345
|
+
"gemini": """
|
|
346
|
+
#### Gemini CLI 特有功能
|
|
347
|
+
- **智能匹配**: 高级模式匹配和任务识别
|
|
348
|
+
- **多处理器**: 支持多种Extension处理器
|
|
349
|
+
- **数据分析**: 强大的数据处理和分析能力
|
|
350
|
+
|
|
351
|
+
推荐协作模式:
|
|
352
|
+
```bash
|
|
353
|
+
> 用gemini分析这个数据集的模式
|
|
354
|
+
> 请用qwen生成数据可视化代码
|
|
355
|
+
> 调用claude生成分析报告
|
|
356
|
+
```
|
|
357
|
+
""",
|
|
358
|
+
"qwen": """
|
|
359
|
+
#### QwenCode CLI 特有功能
|
|
360
|
+
- **代码生成**: 高质量代码生成和重构
|
|
361
|
+
- **插件系统**: 丰富的插件和扩展能力
|
|
362
|
+
- **代码审查**: 智能代码质量检查
|
|
363
|
+
|
|
364
|
+
推荐协作模式:
|
|
365
|
+
```bash
|
|
366
|
+
> 请用qwen生成完整的CRUD API
|
|
367
|
+
> 调用gemini分析API性能
|
|
368
|
+
> 用claude审查代码架构
|
|
369
|
+
```
|
|
370
|
+
""",
|
|
371
|
+
"iflow": """
|
|
372
|
+
#### iFlow CLI 特有功能
|
|
373
|
+
- **工作流引擎**: 强大的工作流编排能力
|
|
374
|
+
- **流水线处理**: 自动化流水线管理
|
|
375
|
+
- **任务队列**: 高效的任务调度和执行
|
|
376
|
+
|
|
377
|
+
推荐协作模式:
|
|
378
|
+
```bash
|
|
379
|
+
> 用iflow创建CI/CD工作流
|
|
380
|
+
> 请用qwen生成部署脚本
|
|
381
|
+
> 调用gemini优化工作流性能
|
|
382
|
+
```
|
|
383
|
+
"""
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return tool_guides.get(cli_name, f"""
|
|
387
|
+
#### {cli_name.upper()} CLI
|
|
388
|
+
使用 {cli_name.upper()} CLI 开始你的AI协作之旅。查看工具文档了解更多功能。
|
|
389
|
+
""")
|
|
390
|
+
|
|
391
|
+
async def _generate_config_reference_section(self,
|
|
392
|
+
cli_name: str,
|
|
393
|
+
ai_environment: AIEnvironmentInfo) -> str:
|
|
394
|
+
"""生成配置参考章节"""
|
|
395
|
+
|
|
396
|
+
return f"""
|
|
397
|
+
|
|
398
|
+
## 📚 配置参考
|
|
399
|
+
|
|
400
|
+
### 🔧 环境变量
|
|
401
|
+
|
|
402
|
+
| 变量名 | 描述 | 默认值 |
|
|
403
|
+
|--------|------|--------|
|
|
404
|
+
| AI_CLI_ROUTER_ENABLED | 启用AI CLI Router | true |
|
|
405
|
+
| AI_CLI_LOG_LEVEL | 日志级别 | INFO |
|
|
406
|
+
| AI_CLI_TIMEOUT | 超时时间(秒) | 30 |
|
|
407
|
+
| AI_CLI_RETRY_COUNT | 重试次数 | 3 |
|
|
408
|
+
|
|
409
|
+
### 📁 配置文件路径
|
|
410
|
+
|
|
411
|
+
- **全局配置**: `~/.ai-cli-unified/global-config.json`
|
|
412
|
+
- **项目配置**: `.ai-cli-project/project-config.json`
|
|
413
|
+
- **工具配置**: `~/.config/{cli_name}/config.yml`
|
|
414
|
+
- **日志文件**: `~/.config/{cli_name}/logs/`
|
|
415
|
+
|
|
416
|
+
### 🎯 协作配置选项
|
|
417
|
+
|
|
418
|
+
```json
|
|
419
|
+
{{
|
|
420
|
+
"collaboration": {{
|
|
421
|
+
"enabled": true,
|
|
422
|
+
"auto_detect": true,
|
|
423
|
+
"timeout": 30,
|
|
424
|
+
"retry_count": 3,
|
|
425
|
+
"preferred_tools": ["claude", "qwen", "gemini"],
|
|
426
|
+
"fallback_strategy": "sequential"
|
|
427
|
+
}},
|
|
428
|
+
"protocols": {{
|
|
429
|
+
"chinese": true,
|
|
430
|
+
"english": true,
|
|
431
|
+
"mixed_language": true
|
|
432
|
+
}}
|
|
433
|
+
}}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### 🔌 插件配置
|
|
437
|
+
|
|
438
|
+
支持的插件类型:
|
|
439
|
+
- **Hook插件**: 用于事件驱动的扩展
|
|
440
|
+
- **Extension插件**: 用于功能增强
|
|
441
|
+
- **Workflow插件**: 用于工作流集成
|
|
442
|
+
"""
|
|
443
|
+
|
|
444
|
+
async def _generate_troubleshooting_section(self,
|
|
445
|
+
cli_name: str,
|
|
446
|
+
ai_environment: AIEnvironmentInfo) -> str:
|
|
447
|
+
"""生成故障排除指南"""
|
|
448
|
+
|
|
449
|
+
return f"""
|
|
450
|
+
|
|
451
|
+
## 🔧 故障排除
|
|
452
|
+
|
|
453
|
+
### ❌ 常见问题
|
|
454
|
+
|
|
455
|
+
#### 1. 跨工具调用失败
|
|
456
|
+
**症状**: 跨AI工具调用时出现错误或超时
|
|
457
|
+
|
|
458
|
+
**解决方案**:
|
|
459
|
+
- 检查目标CLI工具是否正确安装
|
|
460
|
+
- 验证配置文件是否存在且格式正确
|
|
461
|
+
- 检查网络连接状态
|
|
462
|
+
- 查看各工具的日志文件
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
# 检查工具状态
|
|
466
|
+
> ai-cli-router status
|
|
467
|
+
|
|
468
|
+
# 重新扫描环境
|
|
469
|
+
> ai-cli-router scan
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
#### 2. 协作协议识别失败
|
|
473
|
+
**症状**: 无法识别跨AI工具调用意图
|
|
474
|
+
|
|
475
|
+
**解决方案**:
|
|
476
|
+
- 确保使用标准协作协议格式
|
|
477
|
+
- 检查协议中的CLI工具名称是否正确
|
|
478
|
+
- 使用完整的任务描述
|
|
479
|
+
- 避免使用模糊的指令
|
|
480
|
+
|
|
481
|
+
#### 3. 配置文件冲突
|
|
482
|
+
**症状**: 配置文件格式错误或内容冲突
|
|
483
|
+
|
|
484
|
+
**解决方案**:
|
|
485
|
+
- 备份现有配置文件
|
|
486
|
+
- 使用 `ai-cli-router init` 重新生成配置
|
|
487
|
+
- 手动检查配置文件格式
|
|
488
|
+
- 查看配置验证日志
|
|
489
|
+
|
|
490
|
+
#### 4. 性能问题
|
|
491
|
+
**症状**: 跨工具调用响应缓慢
|
|
492
|
+
|
|
493
|
+
**解决方案**:
|
|
494
|
+
- 检查系统资源使用情况
|
|
495
|
+
- 调整超时和重试设置
|
|
496
|
+
- 使用并行处理模式
|
|
497
|
+
- 优化任务描述的清晰度
|
|
498
|
+
|
|
499
|
+
### 🔍 调试工具
|
|
500
|
+
|
|
501
|
+
#### 日志查看
|
|
502
|
+
```bash
|
|
503
|
+
# 查看全局日志
|
|
504
|
+
tail -f ~/.ai-cli-unified/logs/router.log
|
|
505
|
+
|
|
506
|
+
# 查看工具特定日志
|
|
507
|
+
tail -f ~/.config/{cli_name}/logs/collaboration.log
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### 状态检查
|
|
511
|
+
```bash
|
|
512
|
+
# 检查所有工具状态
|
|
513
|
+
ai-cli-router status --verbose
|
|
514
|
+
|
|
515
|
+
# 检查项目配置
|
|
516
|
+
ai-cli-router check-project
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### 配置验证
|
|
520
|
+
```bash
|
|
521
|
+
# 验证全局配置
|
|
522
|
+
ai-cli-router validate --global
|
|
523
|
+
|
|
524
|
+
# 验证项目配置
|
|
525
|
+
ai-cli-router validate --project
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### 📞 获取帮助
|
|
529
|
+
|
|
530
|
+
如果遇到无法解决的问题:
|
|
531
|
+
|
|
532
|
+
1. **查看文档**: 访问项目的完整文档
|
|
533
|
+
2. **社区支持**: 在社区论坛寻求帮助
|
|
534
|
+
3. **问题报告**: 在GitHub上提交issue
|
|
535
|
+
4. **日志分析**: 提供详细的错误日志
|
|
536
|
+
|
|
537
|
+
### 🔄 重置和恢复
|
|
538
|
+
|
|
539
|
+
```bash
|
|
540
|
+
# 重置项目配置
|
|
541
|
+
ai-cli-router reset --project
|
|
542
|
+
|
|
543
|
+
# 重置全局配置
|
|
544
|
+
ai-cli-router reset --global
|
|
545
|
+
|
|
546
|
+
# 完全重置
|
|
547
|
+
ai-cli-router reset --all
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
---
|
|
551
|
+
|
|
552
|
+
*💡 提示: 定期更新AI CLI Router以获得最新功能和修复*
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
def _get_integration_type_display(self, integration_type) -> str:
|
|
556
|
+
"""获取集成类型的显示名称"""
|
|
557
|
+
type_names = {
|
|
558
|
+
"hook_system": "钩子系统",
|
|
559
|
+
"extension_system": "扩展系统",
|
|
560
|
+
"class_inheritance": "类继承",
|
|
561
|
+
"workflow_pipeline": "工作流流水线",
|
|
562
|
+
"notification_hook": "通知钩子",
|
|
563
|
+
"mcp_server": "MCP服务器",
|
|
564
|
+
"slash_command": "斜杠命令"
|
|
565
|
+
}
|
|
566
|
+
return type_names.get(integration_type.value, integration_type.value)
|
|
567
|
+
|
|
568
|
+
def _get_status_display(self, status) -> str:
|
|
569
|
+
"""获取状态的显示名称"""
|
|
570
|
+
status_names = {
|
|
571
|
+
"available": "✅ 可用",
|
|
572
|
+
"unavailable": "❌ 不可用",
|
|
573
|
+
"version_incompatible": "⚠️ 版本不兼容",
|
|
574
|
+
"config_missing": "⚠️ 配置缺失"
|
|
575
|
+
}
|
|
576
|
+
return status_names.get(status.value, status.value)
|
|
577
|
+
|
|
578
|
+
def _format_capabilities(self, capabilities: List[str]) -> str:
|
|
579
|
+
"""格式化能力列表"""
|
|
580
|
+
if not capabilities:
|
|
581
|
+
return "- 基础AI助手功能"
|
|
582
|
+
|
|
583
|
+
formatted = []
|
|
584
|
+
for capability in capabilities:
|
|
585
|
+
formatted.append(f"- {capability}")
|
|
586
|
+
|
|
587
|
+
return "\n".join(formatted)
|
|
588
|
+
|
|
589
|
+
def _generate_protocol_examples(self, protocol: str, peer_clis: List[str]) -> List[str]:
|
|
590
|
+
"""生成协议示例"""
|
|
591
|
+
if not peer_clis:
|
|
592
|
+
return [protocol.replace('{cli}', '工具名').replace('{task}', '任务')]
|
|
593
|
+
|
|
594
|
+
examples = []
|
|
595
|
+
for peer_cli in peer_clis[:3]: # 最多3个示例
|
|
596
|
+
example_tasks = {
|
|
597
|
+
"qwen": ["生成代码", "重构函数", "编写测试"],
|
|
598
|
+
"gemini": ["分析性能", "优化查询", "数据可视化"],
|
|
599
|
+
"claude": ["架构设计", "代码审查", "需求分析"],
|
|
600
|
+
"iflow": ["创建工作流", "自动化部署", "流程优化"]
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
tasks = example_tasks.get(peer_cli, ["执行任务"])
|
|
604
|
+
for task in tasks[:2]: # 每个工具最多2个任务
|
|
605
|
+
example = protocol.replace('{cli}', peer_cli).replace('{task}', task)
|
|
606
|
+
examples.append(example)
|
|
607
|
+
|
|
608
|
+
return examples
|
|
609
|
+
|
|
610
|
+
def _extract_sections(self, content: str) -> int:
|
|
611
|
+
"""提取文档中的章节数量"""
|
|
612
|
+
sections = []
|
|
613
|
+
lines = content.split('\n')
|
|
614
|
+
|
|
615
|
+
for line in lines:
|
|
616
|
+
if line.strip().startswith('#'):
|
|
617
|
+
sections.append(line.strip())
|
|
618
|
+
|
|
619
|
+
return len(sections)
|