stigmergy 1.0.84 → 1.0.86
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/docs/NATIVE_INTEGRATION_GUIDE.md +1191 -0
- package/docs/PROJECT_CONSTITUTION.md +434 -0
- package/docs/PROJECT_REQUIREMENTS.md +329 -0
- package/docs/PROJECT_STRUCTURE.md +304 -0
- package/docs/PROJECT_STRUCTURE_CURRENT.md +81 -0
- package/docs/UNIFIED_TECHNICAL_ARCHITECTURE.md +967 -0
- package/examples/cline_usage_examples.md +365 -0
- package/package.json +4 -2
- package/src/main_english.js +70 -82
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# AI CLI Universal Integration System
|
|
2
|
+
## Requirements Specification (Unified and Clarified Version)
|
|
3
|
+
|
|
4
|
+
**Project ID:** AI-CLI-UNIFIED-001
|
|
5
|
+
**Version:** 2.0
|
|
6
|
+
**Date:** 2025-01-22
|
|
7
|
+
**Status:** Final
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 📋 Executive Summary
|
|
12
|
+
|
|
13
|
+
### Project Vision
|
|
14
|
+
实现一个综合性的AI CLI工具生态系统,支持**跨CLI直接调用**和**间接协作**双重功能,让用户能够在任意一个AI CLI环境中无缝调用其他AI CLI工具,同时支持基于项目背景的智能工具协作。
|
|
15
|
+
|
|
16
|
+
### Problem Statement
|
|
17
|
+
AI CLI工具用户面临两个核心问题:
|
|
18
|
+
1. **工具孤岛** - 用户被限制在单一CLI工具的能力范围内,无法调用其他工具的独特功能
|
|
19
|
+
2. **协作缺失** - 多个AI工具缺乏有效的协作机制,无法基于项目背景实现智能协同工作
|
|
20
|
+
|
|
21
|
+
### Solution Overview
|
|
22
|
+
开发一个双重功能的统一集成系统:
|
|
23
|
+
1. **跨CLI直接调用系统** - 用户在任何CLI中自然语言调用其他CLI工具
|
|
24
|
+
2. **间接协作系统** - 基于PROJECT_SPEC.json的AI工具自主协作机制
|
|
25
|
+
所有集成严格使用各CLI的原生机制,不使用包装器方案。
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🎯 Core Requirements
|
|
30
|
+
|
|
31
|
+
### 1. Functional Requirements
|
|
32
|
+
|
|
33
|
+
## 🎯 Core Requirements
|
|
34
|
+
|
|
35
|
+
### 1. 跨CLI直接调用系统 (Cross-CLI Direct Calling System)
|
|
36
|
+
|
|
37
|
+
#### FR-001: 跨CLI调用能力
|
|
38
|
+
- **优先级:** 最高
|
|
39
|
+
- **描述:** 用户必须在任何支持的AI CLI工具中能够自然语言调用其他AI CLI工具
|
|
40
|
+
- **验收标准:**
|
|
41
|
+
- 用户可以在Claude CLI中输入"请用gemini帮我分析这个文件"
|
|
42
|
+
- 用户可以在QwenCodeCLI中输入"调用claude审查这段代码"
|
|
43
|
+
- 系统自动检测目标CLI并执行请求
|
|
44
|
+
- 结果在源CLI中正确显示并标注来源
|
|
45
|
+
|
|
46
|
+
#### FR-002: 自然语言协作协议
|
|
47
|
+
- **优先级:** 最高
|
|
48
|
+
- **描述:** 支持直观的自然语言调用协议,无需学习特定语法
|
|
49
|
+
- **支持协议:**
|
|
50
|
+
- "请用{CLI名} + 任务描述"
|
|
51
|
+
- "调用{CLI名} + 任务描述"
|
|
52
|
+
- "用{CLI名}来 + 任务描述"
|
|
53
|
+
- "让{CLI名}帮我 + 任务描述"
|
|
54
|
+
- "use {CLI名} + 任务描述"
|
|
55
|
+
|
|
56
|
+
#### FR-003: 透明集成
|
|
57
|
+
- **优先级:** 最高
|
|
58
|
+
- **描述:** 集成不能改变现有CLI工具的启动和使用方式
|
|
59
|
+
- **约束条件:**
|
|
60
|
+
- 用户仍使用原有命令启动CLI工具
|
|
61
|
+
- 正常CLI功能保持不变
|
|
62
|
+
- 跨CLI功能是增强功能,不替换原有功能
|
|
63
|
+
|
|
64
|
+
#### FR-004: 目标CLI工具清单
|
|
65
|
+
- **优先级:** 高
|
|
66
|
+
- **描述:** 系统必须支持集成指定的7个AI CLI工具
|
|
67
|
+
- **目标CLI工具 (按优先级排序):**
|
|
68
|
+
1. **Claude CLI** (最高优先级) - Hook系统集成
|
|
69
|
+
2. **QwenCodeCLI** - Python类继承集成
|
|
70
|
+
3. **iFlowCLI** - 工作流脚本集成
|
|
71
|
+
4. **QoderCLI** - 环境变量钩子集成
|
|
72
|
+
5. **GeminiCLI** - Python模块配置集成
|
|
73
|
+
6. **CodeBuddyCLI** - 插件系统集成
|
|
74
|
+
7. **Codex CLI** - 配置注入集成
|
|
75
|
+
|
|
76
|
+
#### FR-005: 原生机制集成
|
|
77
|
+
- **优先级:** 最高
|
|
78
|
+
- **描述:** 每个CLI工具必须使用其最适合的原生集成机制
|
|
79
|
+
- **集成方案映射:**
|
|
80
|
+
- **Claude CLI**: Hook System (UserPromptSubmit hook) - 完全原生
|
|
81
|
+
- **QwenCodeCLI**: Python Class Inheritance - 继承原生类
|
|
82
|
+
- **GeminiCLI**: Python Module + Configuration - 模块集成
|
|
83
|
+
- **iFlowCLI**: Workflow Scripts - 工作流脚本钩子
|
|
84
|
+
- **QoderCLI**: Environment Variable Hooks - 环境变量响应
|
|
85
|
+
- **CodeBuddyCLI**: Plugin System - 原生插件接口
|
|
86
|
+
- **Codex CLI**: Configuration Injection - 配置预处理
|
|
87
|
+
|
|
88
|
+
### 2. 间接协作系统 (Indirect Collaboration System)
|
|
89
|
+
|
|
90
|
+
#### FR-006: 基于文档的协作机制
|
|
91
|
+
- **优先级:** 高
|
|
92
|
+
- **描述:** 基于PROJECT_SPEC.json实现AI工具间的间接协作
|
|
93
|
+
- **验收标准:**
|
|
94
|
+
- 多个AI工具能够读取和更新PROJECT_SPEC.json
|
|
95
|
+
- 工具能够基于项目状态自主认领任务
|
|
96
|
+
- 支持协作历史记录和状态追踪
|
|
97
|
+
|
|
98
|
+
#### FR-007: 智能体协作协议
|
|
99
|
+
- **优先级:** 高
|
|
100
|
+
- **描述:** 支持AI工具间的自然语言协作协议
|
|
101
|
+
- **协作协议:**
|
|
102
|
+
- "让<工具名>帮我<任务描述>"
|
|
103
|
+
- "用<工具名>来<任务描述>"
|
|
104
|
+
- "请<工具名><任务描述>"
|
|
105
|
+
- "调用<工具名>来<任务描述>"
|
|
106
|
+
|
|
107
|
+
#### FR-008: 原子状态管理
|
|
108
|
+
- **优先级:** 最高
|
|
109
|
+
- **描述:** 确保并发访问PROJECT_SPEC.json的原子性和一致性
|
|
110
|
+
- **技术要求:**
|
|
111
|
+
- 跨平台文件锁机制
|
|
112
|
+
- 原子读写操作
|
|
113
|
+
- 冲突检测和解决
|
|
114
|
+
- 状态变更追踪
|
|
115
|
+
|
|
116
|
+
### 3. 通用功能要求 (General Functional Requirements)
|
|
117
|
+
|
|
118
|
+
#### FR-009: 智能CLI选择
|
|
119
|
+
- **优先级:** 中
|
|
120
|
+
- **描述:** 当未明确指定目标CLI时,系统应自动选择最适合的CLI工具
|
|
121
|
+
- **选择标准:**
|
|
122
|
+
- 任务类型与CLI优势匹配
|
|
123
|
+
- 工具可用性检查
|
|
124
|
+
- 历史性能表现
|
|
125
|
+
- 用户偏好设置
|
|
126
|
+
|
|
127
|
+
#### FR-010: 错误处理和降级
|
|
128
|
+
- **优先级:** 高
|
|
129
|
+
- **描述:** 系统必须优雅处理失败并提供降级机制
|
|
130
|
+
- **要求:**
|
|
131
|
+
- 目标CLI不可用时提供替代建议
|
|
132
|
+
- 跨CLI调用失败时降级到源CLI处理
|
|
133
|
+
- 清晰的错误信息和恢复建议
|
|
134
|
+
|
|
135
|
+
#### FR-011: 结果格式化
|
|
136
|
+
- **优先级:** 中
|
|
137
|
+
- **描述:** 跨CLI调用结果必须适合源CLI上下文的格式化显示
|
|
138
|
+
- **要求:**
|
|
139
|
+
- 所有CLI集成的一致格式化
|
|
140
|
+
- 结果来源的清晰标注
|
|
141
|
+
- 执行时间信息
|
|
142
|
+
- 上下文感知的响应格式
|
|
143
|
+
|
|
144
|
+
#### FR-012: 任务状态生命周期
|
|
145
|
+
- **优先级:** 高
|
|
146
|
+
- **描述:** 必须实现完整的任务状态生命周期管理
|
|
147
|
+
- **任务状态:**
|
|
148
|
+
- `pending` - 待认领
|
|
149
|
+
- `in_progress` - 进行中
|
|
150
|
+
- `completed` - 已完成
|
|
151
|
+
- `failed` - 失败
|
|
152
|
+
- `blocked` - 被阻塞
|
|
153
|
+
|
|
154
|
+
### 4. 非功能性要求 (Non-Functional Requirements)
|
|
155
|
+
|
|
156
|
+
#### NFR-001: 性能要求
|
|
157
|
+
- **响应时间:** 跨CLI调用应在30秒内完成
|
|
158
|
+
- **系统开销:** 集成应对正常CLI操作增加最小开销(<100ms)
|
|
159
|
+
- **并发支持:** 支持多个同时进行的跨CLI调用
|
|
160
|
+
- **协作响应:** 协作状态变更响应时间<1秒
|
|
161
|
+
|
|
162
|
+
#### NFR-002: 兼容性要求
|
|
163
|
+
- **Python版本:** 支持Python 3.8+
|
|
164
|
+
- **操作系统:** 支持Linux, macOS, Windows
|
|
165
|
+
- **CLI版本:** 支持所有目标CLI工具的当前稳定版本
|
|
166
|
+
|
|
167
|
+
#### NFR-003: 可靠性要求
|
|
168
|
+
- **可用性:** 跨CLI功能99%正常运行时间
|
|
169
|
+
- **错误率:** 因系统问题导致的跨CLI调用失败率<1%
|
|
170
|
+
- **恢复能力:** 从瞬时故障中自动恢复
|
|
171
|
+
- **数据一致性:** 协作状态数据完整性>99.99%
|
|
172
|
+
|
|
173
|
+
#### NFR-004: 安全性要求
|
|
174
|
+
- **API密钥管理:** 安全处理API密钥和凭证
|
|
175
|
+
- **命令验证:** 验证和清理跨CLI命令
|
|
176
|
+
- **访问控制:** 尊重现有CLI权限系统
|
|
177
|
+
- **数据保护:** 本地存储,不传输项目数据
|
|
178
|
+
|
|
179
|
+
#### NFR-005: 可维护性要求
|
|
180
|
+
- **代码质量:** 遵循PEP 8标准
|
|
181
|
+
- **文档完整性:** 完整的API和集成文档
|
|
182
|
+
- **测试覆盖率:** 关键组件90%+代码覆盖率
|
|
183
|
+
- **模块化设计:** 每个CLI适配器独立实现
|
|
184
|
+
|
|
185
|
+
#### NFR-006: 可扩展性要求
|
|
186
|
+
- **新CLI支持:** 易于添加新CLI工具的框架
|
|
187
|
+
- **插件架构:** 支持第三方扩展
|
|
188
|
+
- **配置系统:** 灵活的配置管理
|
|
189
|
+
- **版本兼容:** 向后兼容多个CLI版本
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 🚫 明确约束条件和负面要求 (绝对不可妥协)
|
|
196
|
+
|
|
197
|
+
### NC-001: 绝对不依赖VS Code
|
|
198
|
+
- **约束条件:** 解决方案绝对不能依赖VS Code或任何特定IDE
|
|
199
|
+
- **理由:** 用户要求纯命令行解决方案
|
|
200
|
+
- **影响:** 所有功能必须在终端环境中工作
|
|
201
|
+
|
|
202
|
+
### NC-002: 绝对不使用包装器作为主要方案
|
|
203
|
+
- **约束条件:** 绝对不能依赖shell包装器脚本作为主要集成方法
|
|
204
|
+
- **理由:** 用户偏好内部插件/钩子集成,而非外部包装器
|
|
205
|
+
- **影响:** 必须使用各CLI的原生扩展机制
|
|
206
|
+
|
|
207
|
+
### NC-003: 绝对不改变CLI启动方式
|
|
208
|
+
- **约束条件:** 绝对不能改变用户启动和配置CLI工具的方式
|
|
209
|
+
- **理由:** 用户希望透明集成,不中断工作流程
|
|
210
|
+
- **影响:** 集成必须是增量的、非侵入性的
|
|
211
|
+
|
|
212
|
+
### NC-004: 绝对不引入新的主要命令
|
|
213
|
+
- **约束条件:** 绝对不能为CLI工具引入新的主要命令名称
|
|
214
|
+
- **理由:** 用户希望使用现有CLI命令的增强功能
|
|
215
|
+
- **影响:** 跨CLI功能必须集成到现有命令流中
|
|
216
|
+
|
|
217
|
+
### NC-005: 绝对不依赖外部服务
|
|
218
|
+
- **约束条件:** 核心功能绝对不能依赖外部服务(除目标CLI工具外)
|
|
219
|
+
- **理由:** 确保离线能力和减少外部依赖
|
|
220
|
+
- **影响:** 所有跨CLI协调必须在本地发生
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 📊 Acceptance Criteria
|
|
225
|
+
|
|
226
|
+
### AC-001: Installation Success
|
|
227
|
+
- [ ] User can install system with single command
|
|
228
|
+
- [ ] Installation detects available CLI tools automatically
|
|
229
|
+
- [ ] Integration works immediately after installation without additional configuration
|
|
230
|
+
|
|
231
|
+
### AC-002: Basic Cross-CLI Functionality
|
|
232
|
+
- [ ] User can call Claude from Gemini CLI
|
|
233
|
+
- [ ] User can call Gemini from Claude CLI
|
|
234
|
+
- [ ] Results are correctly formatted and attributed
|
|
235
|
+
|
|
236
|
+
### AC-003: Advanced Cross-CLI Features
|
|
237
|
+
- [ ] System handles multiple cross-CLI calls in single request
|
|
238
|
+
- [ ] Intelligent CLI selection works when target not specified
|
|
239
|
+
- [ ] Error handling and fallback mechanisms function correctly
|
|
240
|
+
|
|
241
|
+
### AC-004: Performance and Reliability
|
|
242
|
+
- [ ] Cross-CLI calls complete within performance requirements
|
|
243
|
+
- [ ] System gracefully handles CLI tool unavailability
|
|
244
|
+
- [ ] Normal CLI operations not impacted by integration
|
|
245
|
+
|
|
246
|
+
### AC-005: User Experience
|
|
247
|
+
- [ ] Learning curve is minimal for existing CLI users
|
|
248
|
+
- [ ] Error messages are clear and actionable
|
|
249
|
+
- [ ] Documentation is comprehensive and accessible
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 🔄 Success Metrics
|
|
254
|
+
|
|
255
|
+
### Technical Metrics
|
|
256
|
+
- **Integration Success Rate:** >95% of cross-CLI calls complete successfully
|
|
257
|
+
- **Performance Overhead:** <100ms additional latency for cross-CLI detection
|
|
258
|
+
- **Compatibility:** Support for current stable versions of all 8 CLI tools
|
|
259
|
+
- **Test Coverage:** >90% code coverage for critical integration components
|
|
260
|
+
|
|
261
|
+
### User Experience Metrics
|
|
262
|
+
- **Adoption Rate:** >80% of beta testers continue to use after 1 month
|
|
263
|
+
- **Task Completion Rate:** >90% of cross-CLI tasks completed successfully
|
|
264
|
+
- **User Satisfaction:** >4.5/5 rating on user feedback surveys
|
|
265
|
+
- **Support Requests:** <5% of users require support for basic functionality
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## 🚧 Risk Assessment
|
|
270
|
+
|
|
271
|
+
### High-Risk Items
|
|
272
|
+
1. **CLI Tool Compatibility:** Risk of breaking changes in target CLI tools
|
|
273
|
+
2. **Integration Complexity:** Different integration mechanisms per CLI tool
|
|
274
|
+
3. **Performance Impact:** Potential overhead on CLI operations
|
|
275
|
+
|
|
276
|
+
### Mitigation Strategies
|
|
277
|
+
1. **Version Compatibility:** Maintain compatibility matrix and automated testing
|
|
278
|
+
2. **Modular Architecture:** Isolate each CLI adapter to limit blast radius
|
|
279
|
+
3. **Performance Monitoring:** Continuous monitoring of integration overhead
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 📅 Implementation Phases
|
|
284
|
+
|
|
285
|
+
### Phase 1: Core Infrastructure (Weeks 1-4)
|
|
286
|
+
- [ ] Develop base adapter framework
|
|
287
|
+
- [ ] Implement CLI detection and discovery
|
|
288
|
+
- [ ] Create natural language parsing engine
|
|
289
|
+
- [ ] Build cross-CLI execution engine
|
|
290
|
+
|
|
291
|
+
### Phase 2: Primary CLI Integration (Weeks 5-8)
|
|
292
|
+
- [ ] Implement Claude CLI hook integration
|
|
293
|
+
- [ ] Implement Aider CLI plugin integration
|
|
294
|
+
- [ ] Implement Gemini CLI module integration
|
|
295
|
+
- [ ] Test three-tool cross-CLI functionality
|
|
296
|
+
|
|
297
|
+
### Phase 3: Extended CLI Support (Weeks 9-12)
|
|
298
|
+
- [ ] Implement remaining 5 CLI tool integrations
|
|
299
|
+
- [ ] Add intelligent CLI selection
|
|
300
|
+
- [ ] Implement comprehensive error handling
|
|
301
|
+
- [ ] Performance optimization
|
|
302
|
+
|
|
303
|
+
### Phase 4: Polish and Launch (Weeks 13-16)
|
|
304
|
+
- [ ] Complete documentation
|
|
305
|
+
- [ ] Security audit and hardening
|
|
306
|
+
- [ ] User acceptance testing
|
|
307
|
+
- [ ] Production deployment
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## 📝 Version History
|
|
312
|
+
|
|
313
|
+
| Version | Date | Changes | Author |
|
|
314
|
+
|---------|------|---------|--------|
|
|
315
|
+
| 1.0 | 2025-01-22 | Initial requirements specification | AI System |
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## 📚 References
|
|
320
|
+
|
|
321
|
+
1. Claude Code Documentation - Hook system and plugin architecture
|
|
322
|
+
2. Aider CLI Documentation - Plugin system and command registry
|
|
323
|
+
3. Gemini CLI Documentation - Configuration and module system
|
|
324
|
+
4. spec.kit Standards - Requirements specification format
|
|
325
|
+
5. User Requirements Analysis - Cross-CLI calling needs and constraints
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
*This document follows spec.kit standards for requirements specification and will be updated as the project evolves.*
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# AI CLI Universal Integration System
|
|
2
|
+
## Project Structure (项目结构)
|
|
3
|
+
|
|
4
|
+
**Project ID:** AI-CLI-UNIFIED-001
|
|
5
|
+
**Structure Version:** 1.0
|
|
6
|
+
**Date:** 2025-01-22
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📁 目录结构
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
smart-cli-router/
|
|
14
|
+
├── 📄 核心文档
|
|
15
|
+
│ ├── README.md # 项目介绍和快速开始
|
|
16
|
+
│ ├── PROJECT_REQUIREMENTS.md # 统一需求规范
|
|
17
|
+
│ ├── PROJECT_CONSTITUTION.md # 项目宪法(约束条件)
|
|
18
|
+
│ ├── UNIFIED_TECHNICAL_ARCHITECTURE.md # 统一技术架构
|
|
19
|
+
│ ├── NATIVE_INTEGRATION_GUIDE.md # 原生集成实现指南
|
|
20
|
+
│ ├── PROJECT_STRUCTURE.md # 项目结构说明(本文件)
|
|
21
|
+
│ ├── CONTRIBUTING.md # 贡献指南
|
|
22
|
+
│ ├── LICENSE # 开源许可证
|
|
23
|
+
│ └── requirements.txt # Python依赖
|
|
24
|
+
│
|
|
25
|
+
├── 🔧 核心代码 (src/)
|
|
26
|
+
│ ├── core/ # 核心框架
|
|
27
|
+
│ │ ├── __init__.py
|
|
28
|
+
│ │ ├── base_adapter.py # 适配器基类
|
|
29
|
+
│ │ ├── factory.py # 适配器工厂
|
|
30
|
+
│ │ ├── parser.py # 自然语言解析器
|
|
31
|
+
│ │ ├── router.py # 意图路由器
|
|
32
|
+
│ │ └── collaboration.py # 协作协调器
|
|
33
|
+
│ │
|
|
34
|
+
│ ├── adapters/ # CLI适配器实现
|
|
35
|
+
│ │ ├── claude/ # Claude CLI适配器
|
|
36
|
+
│ │ │ ├── __init__.py
|
|
37
|
+
│ │ │ ├── hook_adapter.py # Hook系统适配器
|
|
38
|
+
│ │ │ └── config.json # Claude CLI配置
|
|
39
|
+
│ │ │
|
|
40
|
+
│ │ ├── qwencode/ # QwenCodeCLI适配器
|
|
41
|
+
│ │ │ ├── __init__.py
|
|
42
|
+
│ │ │ ├── class_adapter.py # 类继承适配器
|
|
43
|
+
│ │ │ └── config.json # QwenCodeCLI配置
|
|
44
|
+
│ │ │
|
|
45
|
+
│ │ ├── gemini/ # Gemini CLI适配器
|
|
46
|
+
│ │ │ ├── __init__.py
|
|
47
|
+
│ │ │ ├── module_adapter.py # 模块扩展适配器
|
|
48
|
+
│ │ │ └── config.json # Gemini CLI配置
|
|
49
|
+
│ │ │
|
|
50
|
+
│ │ ├── iflow/ # iFlowCLI适配器
|
|
51
|
+
│ │ │ ├── __init__.py
|
|
52
|
+
│ │ │ ├── workflow_adapter.py # 工作流脚本适配器
|
|
53
|
+
│ │ │ ├── workflow.yml # iFlowCLI工作流
|
|
54
|
+
│ │ │ └── config.json # iFlowCLI配置
|
|
55
|
+
│ │ │
|
|
56
|
+
│ │ ├── qoder/ # QoderCLI适配器
|
|
57
|
+
│ │ │ ├── __init__.py
|
|
58
|
+
│ │ │ ├── plugin_adapter.py # Plugin系统适配器
|
|
59
|
+
│ │ │ └── config.json # QoderCLI配置
|
|
60
|
+
│ │ │
|
|
61
|
+
│ │ ├── codebuddy/ # CodeBuddyCLI适配器
|
|
62
|
+
│ │ │ ├── __init__.py
|
|
63
|
+
│ │ │ ├── buddy_adapter.py # Buddy系统适配器
|
|
64
|
+
│ │ │ └── config.json # CodeBuddyCLI配置
|
|
65
|
+
│ │ │
|
|
66
|
+
│ │ └── codex/ # Codex CLI适配器
|
|
67
|
+
│ │ ├── __init__.py
|
|
68
|
+
│ │ ├── extension_adapter.py # Extension系统适配器
|
|
69
|
+
│ │ └── config.json # Codex CLI配置
|
|
70
|
+
│ │
|
|
71
|
+
│ └── utils/ # 工具模块
|
|
72
|
+
│ ├── __init__.py
|
|
73
|
+
│ ├── logger.py # 日志工具
|
|
74
|
+
│ ├── config.py # 配置管理
|
|
75
|
+
│ ├── atomic_state.py # 原子状态管理
|
|
76
|
+
│ └── protocols.py # 协议定义
|
|
77
|
+
│
|
|
78
|
+
├── 🧪 测试代码 (tests/)
|
|
79
|
+
│ ├── unit/ # 单元测试
|
|
80
|
+
│ │ ├── __init__.py
|
|
81
|
+
│ │ ├── test_core/ # 核心框架测试
|
|
82
|
+
│ │ │ ├── test_base_adapter.py
|
|
83
|
+
│ │ │ ├── test_factory.py
|
|
84
|
+
│ │ │ ├── test_parser.py
|
|
85
|
+
│ │ │ └── test_router.py
|
|
86
|
+
│ │ │
|
|
87
|
+
│ │ └── adapters/ # 适配器单元测试
|
|
88
|
+
│ │ ├── test_claude_adapter.py
|
|
89
|
+
│ │ ├── test_qwencode_adapter.py
|
|
90
|
+
│ │ ├── test_gemini_adapter.py
|
|
91
|
+
│ │ ├── test_iflow_adapter.py
|
|
92
|
+
│ │ ├── test_qoder_adapter.py
|
|
93
|
+
│ │ ├── test_codebuddy_adapter.py
|
|
94
|
+
│ │ └── test_codex_adapter.py
|
|
95
|
+
│ │
|
|
96
|
+
│ ├── integration/ # 集成测试
|
|
97
|
+
│ │ ├── __init__.py
|
|
98
|
+
│ │ ├── test_cross_cli_calls.py # 跨CLI调用测试
|
|
99
|
+
│ │ ├── test_collaboration.py # 间接协作测试
|
|
100
|
+
│ │ └── adapters/ # 适配器集成测试
|
|
101
|
+
│ │ ├── test_claude_integration.py
|
|
102
|
+
│ │ ├── test_qwencode_integration.py
|
|
103
|
+
│ │ └── ...
|
|
104
|
+
│ │
|
|
105
|
+
│ ├── fixtures/ # 测试数据
|
|
106
|
+
│ │ ├── sample_requests.json
|
|
107
|
+
│ │ ├── mock_responses.json
|
|
108
|
+
│ │ └── test_configs/
|
|
109
|
+
│ │
|
|
110
|
+
│ └── conftest.py # pytest配置
|
|
111
|
+
│
|
|
112
|
+
├── 📚 文档 (docs/)
|
|
113
|
+
│ ├── api/ # API文档
|
|
114
|
+
│ │ ├── core.md # 核心API
|
|
115
|
+
│ │ └── adapters.md # 适配器API
|
|
116
|
+
│ │
|
|
117
|
+
│ ├── user_guide/ # 用户指南
|
|
118
|
+
│ │ ├── installation.md # 安装指南
|
|
119
|
+
│ │ ├── usage.md # 使用指南
|
|
120
|
+
│ │ └── troubleshooting.md # 故障排除
|
|
121
|
+
│ │
|
|
122
|
+
│ └── developer_guide/ # 开发者指南
|
|
123
|
+
│ ├── contributing.md # 贡献指南
|
|
124
|
+
│ ├── testing.md # 测试指南
|
|
125
|
+
│ └── architecture.md # 架构说明
|
|
126
|
+
│
|
|
127
|
+
├── 🚀 部署和配置
|
|
128
|
+
│ ├── install_unix.sh # Unix安装脚本
|
|
129
|
+
│ ├── install_windows.bat # Windows安装脚本
|
|
130
|
+
│ ├── config.json # 全局配置文件
|
|
131
|
+
│ ├── pyproject.toml # Python项目配置
|
|
132
|
+
│ └── setup.py # 安装脚本
|
|
133
|
+
│
|
|
134
|
+
├── 🌐 网站 (website/)
|
|
135
|
+
│ ├── index.html # 主页
|
|
136
|
+
│ ├── css/ # 样式文件
|
|
137
|
+
│ ├── js/ # JavaScript文件
|
|
138
|
+
│ └── docs/ # 网站文档
|
|
139
|
+
│
|
|
140
|
+
├── 🗄️ 存档 (archive/)
|
|
141
|
+
│ ├── obsolete_files/ # 过时文件存档
|
|
142
|
+
│ └── old_versions/ # 旧版本存档
|
|
143
|
+
│
|
|
144
|
+
├── 📋 项目管理
|
|
145
|
+
│ ├── PROJECT_SPEC.json # 项目规范
|
|
146
|
+
│ └── .gitignore # Git忽略文件
|
|
147
|
+
│
|
|
148
|
+
└── 🔒 配置和缓存
|
|
149
|
+
├── .git/ # Git仓库
|
|
150
|
+
├── .claude/ # Claude配置
|
|
151
|
+
└── __pycache__/ # Python缓存
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 🎯 目录设计原则
|
|
157
|
+
|
|
158
|
+
### 1. **CLI专用目录结构**
|
|
159
|
+
每个CLI工具都有独立的适配器目录:
|
|
160
|
+
- **独立的适配器实现** - 避免代码耦合
|
|
161
|
+
- **专用配置文件** - 每个CLI的特定配置
|
|
162
|
+
- **独立测试** - 针对性的单元测试和集成测试
|
|
163
|
+
|
|
164
|
+
### 2. **TDD驱动结构**
|
|
165
|
+
测试先行,代码后实现:
|
|
166
|
+
- **单元测试** - 每个组件的独立测试
|
|
167
|
+
- **集成测试** - 跨组件功能测试
|
|
168
|
+
- **测试数据** - 标准化的测试数据集
|
|
169
|
+
|
|
170
|
+
### 3. **模块化设计**
|
|
171
|
+
清晰的模块划分:
|
|
172
|
+
- **core/** - 核心框架和通用功能
|
|
173
|
+
- **adapters/** - CLI特定的适配器实现
|
|
174
|
+
- **utils/** - 通用工具和辅助功能
|
|
175
|
+
|
|
176
|
+
### 4. **文档分层**
|
|
177
|
+
面向不同用户的文档:
|
|
178
|
+
- **用户文档** - 安装、使用、故障排除
|
|
179
|
+
- **开发者文档** - API、架构、贡献指南
|
|
180
|
+
- **技术文档** - 详细的技术规范
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 📦 开发工作流
|
|
185
|
+
|
|
186
|
+
### TDD开发流程
|
|
187
|
+
1. **编写测试** - 在`tests/`中创建测试用例
|
|
188
|
+
2. **运行测试** - 测试应该失败(RED)
|
|
189
|
+
3. **实现代码** - 在`src/`中编写最小可行代码
|
|
190
|
+
4. **运行测试** - 测试应该通过(GREEN)
|
|
191
|
+
5. **重构优化** - 改进代码质量,保持测试通过(REFACTOR)
|
|
192
|
+
|
|
193
|
+
### CLI适配器开发流程
|
|
194
|
+
1. **创建适配器目录** - `src/adapters/{cli_name}/`
|
|
195
|
+
2. **编写适配器测试** - `tests/unit/adapters/test_{cli_name}_adapter.py`
|
|
196
|
+
3. **实现适配器类** - `src/adapters/{cli_name}/{type}_adapter.py`
|
|
197
|
+
4. **创建配置文件** - `src/adapters/{cli_name}/config.json`
|
|
198
|
+
5. **编写集成测试** - `tests/integration/adapters/test_{cli_name}_integration.py`
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 🔧 核心组件说明
|
|
203
|
+
|
|
204
|
+
### 1. **BaseAdapter** (`src/core/base_adapter.py`)
|
|
205
|
+
所有CLI适配器的基类,定义统一接口:
|
|
206
|
+
```python
|
|
207
|
+
class BaseCrossCLIAdapter(ABC):
|
|
208
|
+
@abstractmethod
|
|
209
|
+
async def execute_task(self, task: str, context: dict) -> str
|
|
210
|
+
@abstractmethod
|
|
211
|
+
def is_available(self) -> bool
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 2. **AdapterFactory** (`src/core/factory.py`)
|
|
215
|
+
适配器工厂,负责创建和管理适配器实例:
|
|
216
|
+
```python
|
|
217
|
+
class CrossCliAdapterFactory:
|
|
218
|
+
def get_adapter(self, cli_name: str) -> BaseCrossCLIAdapter
|
|
219
|
+
def list_available_adapters(self) -> Dict[str, bool]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 3. **NaturalLanguageParser** (`src/core/parser.py`)
|
|
223
|
+
自然语言解析器,识别跨CLI调用意图:
|
|
224
|
+
```python
|
|
225
|
+
class NaturalLanguageParser:
|
|
226
|
+
def parse_intent(self, user_input: str) -> IntentResult
|
|
227
|
+
def detect_cross_cli_call(self, text: str) -> bool
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 4. **IntentRouter** (`src/core/router.py`)
|
|
231
|
+
意图路由器,根据解析结果路由到相应处理器:
|
|
232
|
+
```python
|
|
233
|
+
class IntentRouter:
|
|
234
|
+
def route_request(self, intent: IntentResult) -> RequestTarget
|
|
235
|
+
def select_adapter(self, target_cli: str) -> BaseCrossCLIAdapter
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 📋 开发优先级
|
|
241
|
+
|
|
242
|
+
基于原生集成可行性,开发优先级为:
|
|
243
|
+
|
|
244
|
+
### Phase 1: 高可行性CLI (Weeks 1-4)
|
|
245
|
+
1. **Claude CLI** - 官方Hook系统,文档完善
|
|
246
|
+
2. **QwenCodeCLI** - Python类继承,原生支持
|
|
247
|
+
3. **Gemini CLI** - 官方Extension接口
|
|
248
|
+
|
|
249
|
+
### Phase 2: 标准CLI (Weeks 5-8)
|
|
250
|
+
4. **CodeBuddyCLI** - 官方Buddy系统
|
|
251
|
+
5. **QoderCLI** - 官方Plugin架构
|
|
252
|
+
6. **Codex CLI** - 官方Extension系统
|
|
253
|
+
|
|
254
|
+
### Phase 3: 创新CLI (Weeks 9-12)
|
|
255
|
+
7. **iFlowCLI** - 官方Python工作流节点
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## 🧪 测试策略
|
|
260
|
+
|
|
261
|
+
### 测试金字塔
|
|
262
|
+
```
|
|
263
|
+
E2E Tests (5%)
|
|
264
|
+
用户场景测试
|
|
265
|
+
Integration Tests (25%)
|
|
266
|
+
适配器集成测试
|
|
267
|
+
跨CLI调用测试
|
|
268
|
+
Unit Tests (70%)
|
|
269
|
+
核心组件测试
|
|
270
|
+
适配器单元测试
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 测试覆盖率目标
|
|
274
|
+
- **核心框架**: 95%+ 覆盖率
|
|
275
|
+
- **适配器代码**: 90%+ 覆盖率
|
|
276
|
+
- **工具模块**: 85%+ 覆盖率
|
|
277
|
+
|
|
278
|
+
### 测试环境
|
|
279
|
+
- **本地测试**: 单元测试和基础集成测试
|
|
280
|
+
- **CI/CD测试**: 全量测试套件
|
|
281
|
+
- **端到端测试**: 真实CLI环境测试
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 🚀 部署结构
|
|
286
|
+
|
|
287
|
+
### 包结构
|
|
288
|
+
```
|
|
289
|
+
ai_cli_unified/
|
|
290
|
+
├── __init__.py
|
|
291
|
+
├── core/
|
|
292
|
+
├── adapters/
|
|
293
|
+
├── utils/
|
|
294
|
+
└── __main__.py
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### 配置管理
|
|
298
|
+
- **全局配置**: `~/.config/ai-cli-unified/config.yml`
|
|
299
|
+
- **CLI特定配置**: `~/.config/{cli}/config.yml`
|
|
300
|
+
- **用户配置**: `~/.ai-cli-unified/config.json`
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
*本项目结构设计遵循TDD原则、模块化设计和CLI专用化策略,确保代码的可维护性、可测试性和可扩展性。*
|