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
package/src/simple-main.js
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Stigmergy CLI - 简化版核心功能
|
|
4
|
-
* 专注于实际的部署和使用需求
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { existsSync, exists, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
8
|
-
import { join, dirname } from 'path';
|
|
9
|
-
import { homedir } from 'os';
|
|
10
|
-
|
|
11
|
-
class SimpleStigmergyCLI {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.configDir = join(homedir(), '.stigmergy-cli');
|
|
14
|
-
this.projectConfigDir = '.stigmergy-project';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
log(message, type = 'info') {
|
|
18
|
-
const timestamp = new Date().toISOString();
|
|
19
|
-
const prefix = {
|
|
20
|
-
'info': '📦 ',
|
|
21
|
-
'success': '✅ ',
|
|
22
|
-
'error': '❌ ',
|
|
23
|
-
'warning': '⚠️ '
|
|
24
|
-
}[type] || '📦 ';
|
|
25
|
-
|
|
26
|
-
console.log(`${timestamp} ${prefix}${message}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
scanEnvironment() {
|
|
30
|
-
this.log('扫描AI环境...', 'info');
|
|
31
|
-
|
|
32
|
-
const cliTools = [
|
|
33
|
-
{ name: 'claude', displayName: 'Claude CLI', doc: 'claude.md' },
|
|
34
|
-
{ name: 'gemini', displayName: 'Gemini CLI', doc: 'gemini.md' },
|
|
35
|
-
{ name: 'qwen', displayName: 'QwenCode CLI', doc: 'qwen.md' },
|
|
36
|
-
{ name: 'iflow', displayName: 'iFlow CLI', doc: 'iflow.md' },
|
|
37
|
-
{ name: 'qoder', displayName: 'Qoder CLI', doc: 'qoder.md' },
|
|
38
|
-
{ name: 'codebuddy', displayName: 'CodeBuddy CLI', doc: 'codebuddy.md' },
|
|
39
|
-
{ name: 'copilot', displayName: 'Copilot CLI', doc: 'copilot.md' },
|
|
40
|
-
{ name: 'codex', displayName: 'Codex CLI', doc: 'codex.md' }
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const available = [];
|
|
44
|
-
for (const tool of cliTools) {
|
|
45
|
-
if (existsSync(join(process.cwd(), `${tool.doc}`))) {
|
|
46
|
-
available.push(tool);
|
|
47
|
-
this.log(`发现 ${tool.displayName} (${tool.doc})`, 'success');
|
|
48
|
-
} else {
|
|
49
|
-
this.log(`未发现 ${tool.displayName}`, 'warning');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (available.length > 0) {
|
|
54
|
-
this.log(`发现 ${available.length} 个AI CLI工具`, 'success');
|
|
55
|
-
|
|
56
|
-
// 生成简单的协作指南
|
|
57
|
-
const collaborationGuide = this.generateCollaborationGuide(available);
|
|
58
|
-
|
|
59
|
-
// 保存全局配置
|
|
60
|
-
const globalConfig = {
|
|
61
|
-
cliTools: available,
|
|
62
|
-
lastUpdate: new Date().toISOString(),
|
|
63
|
-
version: '1.0.0'
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
if (!existsSync(this.configDir)) {
|
|
67
|
-
mkdirSync(this.configDir, { recursive: true });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
writeFileSync(
|
|
71
|
-
join(this.configDir, 'global-config.json'),
|
|
72
|
-
JSON.stringify(globalConfig, null, 2)
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// 生成项目配置
|
|
76
|
-
this.initProject(process.cwd(), available);
|
|
77
|
-
|
|
78
|
-
this.log('协作指南已生成', 'success');
|
|
79
|
-
return true;
|
|
80
|
-
} else {
|
|
81
|
-
this.log('未发现任何AI CLI工具', 'error');
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
generateCollaborationGuide(available) {
|
|
87
|
-
let guide = '\n## 🤝 AI工具协作指南\n\n';
|
|
88
|
-
|
|
89
|
-
for (const tool of available) {
|
|
90
|
-
const otherTools = available.filter(t => t.name !== tool.name);
|
|
91
|
-
|
|
92
|
-
guide += `### 使用 ${tool.displayName}\n\n`;
|
|
93
|
-
guide += `在${tool.displayName}中,您可以调用以下工具:\n\n`;
|
|
94
|
-
|
|
95
|
-
for (const other of otherTools.slice(0, 3)) {
|
|
96
|
-
guide += `- 请用${other.name}帮我${this.getRandomTask()}\n`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
guide += '\n示例:\n';
|
|
100
|
-
guide += `\`\`\`请用${otherTools[0]?.name || 'qwen'}帮我生成一个Python函数\`\`\`\n\n`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return guide;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getRandomTask() {
|
|
107
|
-
const tasks = [
|
|
108
|
-
'生成用户认证模块',
|
|
109
|
-
'分析代码性能问题',
|
|
110
|
-
'创建数据库迁移脚本',
|
|
111
|
-
'实现API端点',
|
|
112
|
-
'优化SQL查询',
|
|
113
|
-
'生成测试用例',
|
|
114
|
-
'审查代码架构',
|
|
115
|
-
'重构遗留代码',
|
|
116
|
-
'设计系统架构文档',
|
|
117
|
-
'处理CSV数据并生成可视化图表',
|
|
118
|
-
'分析关键业务指标',
|
|
119
|
-
'实现缓存策略',
|
|
120
|
-
'优化应用启动时间'
|
|
121
|
-
];
|
|
122
|
-
return tasks[Math.floor(Math.random() * tasks.length)];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
initProject(projectPath, availableTools) {
|
|
126
|
-
this.log(`初始化Stigmergy项目: ${projectPath}`, 'info');
|
|
127
|
-
|
|
128
|
-
// 创建项目配置目录
|
|
129
|
-
const configDir = join(projectPath, this.projectConfigDir);
|
|
130
|
-
if (!existsSync(configDir)) {
|
|
131
|
-
mkdirSync(configDir, { recursive: true });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 生成项目配置
|
|
135
|
-
const projectConfig = {
|
|
136
|
-
projectType: 'stigmergy-initialized',
|
|
137
|
-
createdAt: new Date().toISOString(),
|
|
138
|
-
cliTools: availableTools,
|
|
139
|
-
version: '1.0.0'
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
writeFileSync(
|
|
143
|
-
join(configDir, 'stigmergy-config.json'),
|
|
144
|
-
JSON.stringify(projectConfig, null, 2)
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
// 为每个可用工具生成简单的协作文档
|
|
148
|
-
for (const tool of availableTools) {
|
|
149
|
-
const docContent = this.generateToolDoc(tool, availableTools);
|
|
150
|
-
writeFileSync(join(projectPath, `${tool.name}.md`), docContent);
|
|
151
|
-
this.log(`生成 ${tool.name}.md`, 'success');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 生成主要协作文档
|
|
155
|
-
const mainDoc = this.generateMainDoc(availableTools);
|
|
156
|
-
writeFileSync(join(projectPath, 'README.md'), mainDoc);
|
|
157
|
-
|
|
158
|
-
this.log(`项目初始化完成!发现 ${availableTools.length} 个AI CLI工具`, 'success');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
generateToolDoc(tool, availableTools) {
|
|
162
|
-
const otherTools = available.filter(t => t.name !== tool.name);
|
|
163
|
-
|
|
164
|
-
return `# ${tool.displayName} 协作指南
|
|
165
|
-
|
|
166
|
-
> 🚀 **Stigmergy协作增强** - 让您的${tool.displayName}能够与其他AI CLI工具智能协作
|
|
167
|
-
|
|
168
|
-
## 📋 工具信息
|
|
169
|
-
|
|
170
|
-
- **名称**: ${tool.displayName}
|
|
171
|
-
- **配置文件**: ${tool.name}.json
|
|
172
|
-
- **文档文件**: ${tool.doc}
|
|
173
|
-
|
|
174
|
-
## 🤝 协作功能
|
|
175
|
-
|
|
176
|
-
### 中文协作指令
|
|
177
|
-
|
|
178
|
-
在${tool.displayName}中,您可以使用以下格式调用其他AI工具:
|
|
179
|
-
|
|
180
|
-
\`\`\`请用{工具名}帮我{任务}\`\`\`
|
|
181
|
-
|
|
182
|
-
### 示例
|
|
183
|
-
|
|
184
|
-
\`\`\`请用qwen帮我生成一个Python函数\`\`\`
|
|
185
|
-
|
|
186
|
-
## 🔧 可用的协作工具
|
|
187
|
-
|
|
188
|
-
根据当前AI环境,您可以在${tool.displayName}中调用以下工具:
|
|
189
|
-
|
|
190
|
-
${otherTools.map(t => `- ${t.displayName} (${t.doc})`).join('\n')}
|
|
191
|
-
|
|
192
|
-
## 💡 最佳实践
|
|
193
|
-
|
|
194
|
-
### 1. 任务分解策略
|
|
195
|
-
复杂任务可以分解为多个子任务,分配给不同的AI工具
|
|
196
|
-
|
|
197
|
-
### 2. 协作工作流示例
|
|
198
|
-
1. 使用Claude进行架构设计
|
|
199
|
-
2. 使用QwenCode实现核心功能
|
|
200
|
-
3. 使用Gemini进行性能优化
|
|
201
|
-
|
|
202
|
-
### 3. 错误处理和恢复
|
|
203
|
-
如果某个工具调用失败,可以尝试使用其他工具完成相同任务
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
**生成时间**: ${new Date().toLocaleString('zh-CN')}
|
|
208
|
-
**项目路径**: ${process.cwd()}
|
|
209
|
-
**Stigmergy版本**: 1.0.0
|
|
210
|
-
|
|
211
|
-
> 🎉 **通过Stigmergy协作,让每个AI工具都能发挥最大价值!** 🚀
|
|
212
|
-
`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
generateMainDoc(availableTools) {
|
|
216
|
-
let doc = `# Stigmergy CLI - Multi-Agents跨AI CLI工具协作系统
|
|
217
|
-
|
|
218
|
-
> 🚀 **真正的Stigmergy协作** - 让各个AI CLI工具智能协作,创造更大的价值!
|
|
219
|
-
|
|
220
|
-
## 📋 发现的AI工具
|
|
221
|
-
|
|
222
|
-
当前项目已检测到以下可用的AI CLI工具:
|
|
223
|
-
|
|
224
|
-
${available.map(tool => `- **${tool.displayName}** (${tool.name})`).join('\n')}
|
|
225
|
-
|
|
226
|
-
## 🎯 使用方法
|
|
227
|
-
|
|
228
|
-
### 1. 项目初始化
|
|
229
|
-
|
|
230
|
-
\`\`\`
|
|
231
|
-
stigmergy-cli init
|
|
232
|
-
\`\`\`
|
|
233
|
-
|
|
234
|
-
### 2. 跨AI工具协作
|
|
235
|
-
|
|
236
|
-
在任意AI工具中,您可以使用以下协作指令:
|
|
237
|
-
|
|
238
|
-
### 中文协作指令
|
|
239
|
-
\`\`\`请用{工具名}帮我{任务}\`\`\`
|
|
240
|
-
|
|
241
|
-
### 示例
|
|
242
|
-
\`\`\`请用qwen帮我生成一个Python函数\`\`\`
|
|
243
|
-
|
|
244
|
-
## 🔧 管理命令
|
|
245
|
-
|
|
246
|
-
\`\`\`
|
|
247
|
-
stigmergy-cli status # 检查系统和工具状态
|
|
248
|
-
\`\`\`
|
|
249
|
-
|
|
250
|
-
## 📚 项目配置
|
|
251
|
-
|
|
252
|
-
- **全局配置**: \`~/.stigmergy-cli/global-config.json\`
|
|
253
|
-
- **项目配置**: \`.stigmergy-project/stigmergy-config.json\`
|
|
254
|
-
|
|
255
|
-
---
|
|
256
|
-
|
|
257
|
-
**生成时间**: ${new Date().toLocaleString('zh-CN')}
|
|
258
|
-
|
|
259
|
-
> 🎉 **让AI工具通过Stigmergy机制实现真正的智能协作!** 🚀
|
|
260
|
-
|
|
261
|
-
## 🔮 技术支持
|
|
262
|
-
|
|
263
|
-
- **GitHub**: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents
|
|
264
|
-
- **文档**: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents/blob/main/README.md
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
|
-
**Stigmergy CLI v1.0.0** - 简化版,专注于核心协作功能
|
|
269
|
-
`;
|
|
270
|
-
|
|
271
|
-
return doc;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// 简化的命令处理
|
|
276
|
-
async function main() {
|
|
277
|
-
const args = process.argv.slice(2);
|
|
278
|
-
const command = args[0];
|
|
279
|
-
|
|
280
|
-
const cli = new SimpleStigmergyCLI();
|
|
281
|
-
|
|
282
|
-
switch (command) {
|
|
283
|
-
case 'init':
|
|
284
|
-
await cli.scanEnvironment();
|
|
285
|
-
break;
|
|
286
|
-
case 'status':
|
|
287
|
-
console.log('🔍 检查Stigmergy CLI状态...');
|
|
288
|
-
console.log('📁 全局配置:', cli.configDir);
|
|
289
|
-
console.log('📁 项目配置:', cli.projectConfigDir);
|
|
290
|
-
break;
|
|
291
|
-
case 'help':
|
|
292
|
-
default:
|
|
293
|
-
console.log(`
|
|
294
|
-
🤖 Stigmergy CLI v1.0.0 - 简化版
|
|
295
|
-
|
|
296
|
-
📚 可用命令:
|
|
297
|
-
init - 初始化项目(扫描AI环境并生成协作文档)
|
|
298
|
-
status - 检查状态
|
|
299
|
-
help - 显示帮助信息
|
|
300
|
-
|
|
301
|
-
💡 使用方法:
|
|
302
|
-
stigmergy-cli init # 初始化当前项目
|
|
303
|
-
|
|
304
|
-
🔗 项目地址: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents
|
|
305
|
-
🔧 配置目录: ~/.stigmergy-cli
|
|
306
|
-
|
|
307
|
-
> 🎉 简化版 - 专注于核心协作功能,立即可用!
|
|
308
|
-
`);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
314
|
-
main();
|
|
315
|
-
}
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
智能路由器创建器 - 简化版
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import os
|
|
8
|
-
import sys
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def create_smart_router(cli_name, output_format="cmd"):
|
|
12
|
-
"""创建智能路由器"""
|
|
13
|
-
|
|
14
|
-
# 基础配置
|
|
15
|
-
tools = {
|
|
16
|
-
"claude": {"cmd": "claude.cmd", "keywords": ["claude", "anthropic"], "priority": 1},
|
|
17
|
-
"gemini": {"cmd": "gemini.cmd", "keywords": ["gemini", "google", "谷歌"], "priority": 2},
|
|
18
|
-
"kimi": {"cmd": "kimi_wrapper", "keywords": ["kimi", "月之暗面"], "priority": 3, "wrapper": True},
|
|
19
|
-
"qwen": {"cmd": "qwen.cmd", "keywords": ["qwen", "通义", "阿里"], "priority": 4},
|
|
20
|
-
"ollama": {"cmd": "ollama", "keywords": ["ollama", "本地", "离线"], "priority": 5},
|
|
21
|
-
"codebuddy": {"cmd": "codebuddy", "keywords": ["codebuddy", "代码助手", "编程"], "priority": 6},
|
|
22
|
-
"qodercli": {"cmd": "qodercli", "keywords": ["qodercli", "代码生成", "编程"], "priority": 7},
|
|
23
|
-
"iflow": {"cmd": "iflow", "keywords": ["iflow", "智能", "助手", "心流"], "priority": 8}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
route_keywords = ["用", "帮我", "请", "智能", "ai", "写", "生成", "解释", "分析", "翻译", "代码", "文章"]
|
|
27
|
-
default_tool = "claude"
|
|
28
|
-
|
|
29
|
-
if output_format == "cmd":
|
|
30
|
-
return _create_cmd_router(cli_name, tools)
|
|
31
|
-
elif output_format == "powershell":
|
|
32
|
-
return _create_powershell_router(cli_name, tools)
|
|
33
|
-
elif output_format == "python":
|
|
34
|
-
return _create_python_router(cli_name, tools)
|
|
35
|
-
else:
|
|
36
|
-
raise ValueError(f"不支持的格式: {output_format}")
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def _create_cmd_router(cli_name, tools):
|
|
40
|
-
"""创建CMD路由器"""
|
|
41
|
-
content = f'''@echo off
|
|
42
|
-
setlocal enabledelayedexpansion
|
|
43
|
-
|
|
44
|
-
:: 智能{cli_name}路由器
|
|
45
|
-
|
|
46
|
-
set "USER_INPUT=%*"
|
|
47
|
-
|
|
48
|
-
if "%USER_INPUT%"=="" (
|
|
49
|
-
echo 🎯 智能{cli_name}路由器
|
|
50
|
-
echo 💡 用法: smart_{cli_name}.bat '用kimi写代码'
|
|
51
|
-
exit /b
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
:: 检测路由关键词
|
|
55
|
-
echo %USER_INPUT% | findstr /i "用 帮我 请 智能 ai 写 生成 解释 分析 翻译 代码 文章" >nul
|
|
56
|
-
if !errorlevel! equ 0 (
|
|
57
|
-
{cli_name} %USER_INPUT%
|
|
58
|
-
exit /b
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
'''
|
|
62
|
-
|
|
63
|
-
# 按优先级生成路由逻辑
|
|
64
|
-
router_content = ""
|
|
65
|
-
for tool_name, tool_info in sorted(tools.items(), key=lambda x: x[1]["priority"]):
|
|
66
|
-
keywords = tool_info["keywords"]
|
|
67
|
-
command = tool_info["cmd"]
|
|
68
|
-
|
|
69
|
-
for keyword in keywords:
|
|
70
|
-
content = f'''echo %USER_INPUT% | findstr /i "{keyword}" >nul
|
|
71
|
-
if !errorlevel! equ 0 (
|
|
72
|
-
echo 🚀 智能路由到: {tool_name}
|
|
73
|
-
set "CLEAN_INPUT=!USER_INPUT!"
|
|
74
|
-
'''
|
|
75
|
-
|
|
76
|
-
# 清理输入
|
|
77
|
-
for clean_word in ["用", "帮我", "请", "写", "生成", "解释", "分析", "翻译", "代码", "文章"]:
|
|
78
|
-
content += f''' set "CLEAN_INPUT=!CLEAN_INPUT:{clean_word}=!"
|
|
79
|
-
'''
|
|
80
|
-
|
|
81
|
-
content += f''' '''
|
|
82
|
-
|
|
83
|
-
if tool_info.get("wrapper"):
|
|
84
|
-
content += ''' python kimi_wrapper.py "!CLEAN_INPUT!"'''
|
|
85
|
-
else:
|
|
86
|
-
content += f''' {command} "!CLEAN_INPUT!"'''
|
|
87
|
-
|
|
88
|
-
content += '''
|
|
89
|
-
exit /b
|
|
90
|
-
)
|
|
91
|
-
'''
|
|
92
|
-
|
|
93
|
-
router_content += content
|
|
94
|
-
|
|
95
|
-
return content + router_content
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _create_powershell_router(cli_name, tools):
|
|
99
|
-
"""创建PowerShell路由器"""
|
|
100
|
-
content = f'''# 智能{cli_name}路由器 - PowerShell版本
|
|
101
|
-
|
|
102
|
-
param(
|
|
103
|
-
[string]$UserInput = ""
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
function SmartRoute {{
|
|
107
|
-
param([string]$Input)
|
|
108
|
-
$routeKeywords = @("用", "帮我", "请", "智能", "ai", "写", "生成", "解释", "analysis", "translate", "code", "article")
|
|
109
|
-
|
|
110
|
-
foreach ($keyword in $routeKeywords) {{
|
|
111
|
-
if ($Input -like "*$keyword*") {{
|
|
112
|
-
return $true
|
|
113
|
-
}}
|
|
114
|
-
}}
|
|
115
|
-
|
|
116
|
-
return $false
|
|
117
|
-
}}
|
|
118
|
-
|
|
119
|
-
function Route-ToTool {{
|
|
120
|
-
param([string]$Input)
|
|
121
|
-
'''
|
|
122
|
-
|
|
123
|
-
for tool_name, tool_info in sorted(tools.items(), key=lambda x: x[1]["priority"]):
|
|
124
|
-
keywords = tool_info["keywords"]
|
|
125
|
-
command = tool_info["cmd"]
|
|
126
|
-
|
|
127
|
-
content += f''' if ($Input -like "*{keywords[0]}*") {{
|
|
128
|
-
Write-Host "🚀 智能路由到: {tool_name}"
|
|
129
|
-
$cleanInput = $Input
|
|
130
|
-
'''
|
|
131
|
-
|
|
132
|
-
for keyword in keywords:
|
|
133
|
-
content += f''' $cleanInput = $cleanInput -replace "{keyword}", ""'''
|
|
134
|
-
|
|
135
|
-
content += f''' $cleanInput = $cleanInput -replace "^用", "" -replace "^帮我", "" -replace "^请", "" -replace "^写", "" -replace "^生成", "" -replace "^解释", "" -replace "^分析", "" -replace "^翻译", "" -replace "^代码", "" -replace "^文章", ""
|
|
136
|
-
'''
|
|
137
|
-
|
|
138
|
-
if tool_info.get("wrapper"):
|
|
139
|
-
content += ''' python kimi_wrapper.py $cleanInput.Trim()'''
|
|
140
|
-
else:
|
|
141
|
-
content += f''' {command} $cleanInput.Trim()'''
|
|
142
|
-
|
|
143
|
-
content += '''
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
'''
|
|
147
|
-
|
|
148
|
-
# 默认路由
|
|
149
|
-
default_tool = "claude"
|
|
150
|
-
if default_tool in tools:
|
|
151
|
-
command = tools[default_tool]["cmd"]
|
|
152
|
-
content += f''' # 默认路由到{tools[default_tool]["description"]}
|
|
153
|
-
$cleanInput = $Input
|
|
154
|
-
$cleanInput = $cleanInput -replace "^用", "" -replace "^帮我", "" -replace "^请", "" -replace "^写", "" -replace "^生成", "" -replace "^解释", "" -replace "^分析", "" -replace "^翻译", "" -replace "^代码", "" -replace "^文章", ""
|
|
155
|
-
{command} $cleanInput.Trim()
|
|
156
|
-
'''
|
|
157
|
-
else:
|
|
158
|
-
content += f''' # 执行原始{cli_name}
|
|
159
|
-
{cli_name} $Input'''
|
|
160
|
-
|
|
161
|
-
content += '''
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
# 主逻辑
|
|
165
|
-
if (-not $UserInput) {{
|
|
166
|
-
Write-Host "🎯 智能{cli_name}路由器 - PowerShell版本"
|
|
167
|
-
Write-Host "💡 用法: .\smart_{cli_name}.ps1 '用kimi写代码'"
|
|
168
|
-
exit
|
|
169
|
-
}}
|
|
170
|
-
|
|
171
|
-
if (SmartRoute $UserInput) {{
|
|
172
|
-
Route-ToTool $UserInput
|
|
173
|
-
}} else {{
|
|
174
|
-
{cli_name} $UserInput
|
|
175
|
-
}}
|
|
176
|
-
'''
|
|
177
|
-
|
|
178
|
-
return content
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def _create_python_router(cli_name, tools):
|
|
182
|
-
"""创建Python路由器"""
|
|
183
|
-
content = f'''#!/usr/bin/env python3
|
|
184
|
-
# -*- coding: utf-8 -*-
|
|
185
|
-
"""
|
|
186
|
-
智能{cli_name}路由器 - Python版本
|
|
187
|
-
"""
|
|
188
|
-
|
|
189
|
-
import sys
|
|
190
|
-
import subprocess
|
|
191
|
-
import re
|
|
192
|
-
|
|
193
|
-
class SmartRouter:
|
|
194
|
-
def __init__(self):
|
|
195
|
-
self.cli_name = "{cli_name}"
|
|
196
|
-
self.tools = {repr(tools)}
|
|
197
|
-
self.route_keywords = ["用", "帮我", "请", "智能", "ai", "写", "生成", "解释", "分析", "翻译", "代码", "文章"]
|
|
198
|
-
self.default_tool = "claude"
|
|
199
|
-
|
|
200
|
-
def should_route(self, user_input):
|
|
201
|
-
return any(keyword.lower() in user_input.lower() for keyword in self.route_keywords)
|
|
202
|
-
|
|
203
|
-
def smart_route(self, user_input):
|
|
204
|
-
user_input = user_input.strip()
|
|
205
|
-
|
|
206
|
-
for tool_name, tool_info in self.tools.items():
|
|
207
|
-
for keyword in tool_info["keywords"]:
|
|
208
|
-
if keyword.lower() in user_input.lower():
|
|
209
|
-
clean_input = user_input.replace(keyword, "", 1).strip()
|
|
210
|
-
clean_input = re.sub(r'^(用|帮我|请|麻烦|给我|帮我写|帮我生成)\\s*', '', clean_input, flags=re.IGNORECASE).strip()
|
|
211
|
-
return tool_name, [clean_input] if clean_input else []
|
|
212
|
-
|
|
213
|
-
clean_input = re.sub(r'^(用|帮我|请|麻烦|给我|帮我写|帮我生成)\\s*', '', user_input, flags=re.IGNORECASE).strip()
|
|
214
|
-
return self.default_tool, [clean_input] if clean_input else []
|
|
215
|
-
|
|
216
|
-
def execute_tool(self, tool_name, args):
|
|
217
|
-
if tool_name not in self.tools:
|
|
218
|
-
return 1, "", f"未知工具: {{tool_name}}"
|
|
219
|
-
|
|
220
|
-
tool_info = self.tools[tool_name]
|
|
221
|
-
command = tool_info["cmd"]
|
|
222
|
-
|
|
223
|
-
if tool_info.get("wrapper"):
|
|
224
|
-
cmd = ["python", "kimi_wrapper.py"] + args
|
|
225
|
-
else:
|
|
226
|
-
cmd = [command] + args
|
|
227
|
-
|
|
228
|
-
try:
|
|
229
|
-
result = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', timeout=60)
|
|
230
|
-
return result.returncode, result.stdout, result.stderr
|
|
231
|
-
except Exception as e:
|
|
232
|
-
return -1, "", f"执行失败: {{e}}"
|
|
233
|
-
|
|
234
|
-
def execute_original_cli(self, args):
|
|
235
|
-
try:
|
|
236
|
-
cmd = ["{cli_name}"] + args
|
|
237
|
-
result = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8')
|
|
238
|
-
return result.returncode, result.stdout, result.stderr
|
|
239
|
-
except Exception as e:
|
|
240
|
-
return -1, "", f"原始CLI执行失败: {{e}}"
|
|
241
|
-
|
|
242
|
-
def main():
|
|
243
|
-
router = SmartRouter()
|
|
244
|
-
|
|
245
|
-
if len(sys.argv) < 2:
|
|
246
|
-
print("🎯 智能{cli_name}路由器 - Python版本")
|
|
247
|
-
print("💡 用法: python smart_{cli_name}.py '用kimi写代码'")
|
|
248
|
-
return
|
|
249
|
-
|
|
250
|
-
user_input = ' '.join(sys.argv[1:])
|
|
251
|
-
|
|
252
|
-
if router.should_route(user_input):
|
|
253
|
-
tool_name, args = router.smart_route(user_input)
|
|
254
|
-
if tool_name and tool_name != router.cli_name:
|
|
255
|
-
print(f"🚀 智能路由到: {{tool_name}}")
|
|
256
|
-
returncode, stdout, stderr = router.execute_tool(tool_name, args)
|
|
257
|
-
if stdout:
|
|
258
|
-
print(stdout)
|
|
259
|
-
if stderr:
|
|
260
|
-
print(stderr, file=sys.stderr)
|
|
261
|
-
sys.exit(returncode)
|
|
262
|
-
|
|
263
|
-
# 执行原始CLI
|
|
264
|
-
returncode, stdout, stderr = router.execute_original_cli(sys.argv[1:])
|
|
265
|
-
if stdout:
|
|
266
|
-
print(stdout)
|
|
267
|
-
if stderr:
|
|
268
|
-
print(stderr, file=sys.stderr)
|
|
269
|
-
sys.exit(returncode)
|
|
270
|
-
|
|
271
|
-
if __name__ == "__main__":
|
|
272
|
-
main()
|
|
273
|
-
'''
|
|
274
|
-
|
|
275
|
-
return content
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
def main():
|
|
279
|
-
import argparse
|
|
280
|
-
|
|
281
|
-
parser = argparse.ArgumentParser(description="智能路由器创建器")
|
|
282
|
-
parser.add_argument("--cli", help="指定CLI名称")
|
|
283
|
-
parser.add_argument("--format", choices=["cmd", "powershell", "python"], default="cmd", help="输出格式")
|
|
284
|
-
parser.add_argument("--all", help="为所有工具创建路由器")
|
|
285
|
-
|
|
286
|
-
args = parser.parse_args()
|
|
287
|
-
|
|
288
|
-
if args.all:
|
|
289
|
-
tools = ["claude", "gemini", "kimi", "qwen", "ollama", "codebuddy", "qodercli", "iflow"]
|
|
290
|
-
for tool in tools:
|
|
291
|
-
try:
|
|
292
|
-
content = create_smart_router(tool, args.format)
|
|
293
|
-
filename = f"smart_{tool}.bat"
|
|
294
|
-
with open(filename, 'w', encoding='utf-8') as f:
|
|
295
|
-
f.write(content)
|
|
296
|
-
print(f"✅ 创建: {filename}")
|
|
297
|
-
except Exception as e:
|
|
298
|
-
print(f"❌ 创建 {tool} 失败: {e}")
|
|
299
|
-
return
|
|
300
|
-
|
|
301
|
-
if args.cli:
|
|
302
|
-
try:
|
|
303
|
-
content = create_smart_router(args.cli, args.format)
|
|
304
|
-
filename = f"smart_{args.cli}.{args.format}"
|
|
305
|
-
with open(filename, 'w', encoding='utf-8') as f:
|
|
306
|
-
f.write(content)
|
|
307
|
-
print(f"✅ 智能路由器已创建: {filename}")
|
|
308
|
-
print(f"📝 使用: {filename} '用kimi写代码'")
|
|
309
|
-
except Exception as e:
|
|
310
|
-
print(f"❌ 创建失败: {e}")
|
|
311
|
-
|
|
312
|
-
else:
|
|
313
|
-
print("🎯 智能路由器创建器")
|
|
314
|
-
print("\n使用方法:")
|
|
315
|
-
print(" python smart_router_creator.py --cli mytool cmd")
|
|
316
|
-
print(" python smart_router_creator.py --cli mytool powershell")
|
|
317
|
-
print(" python smart_router_creator.py --all")
|
|
318
|
-
print("\n支持的CLI工具:")
|
|
319
|
-
print(" claude, gemini, kimi, qwen, ollama, codebuddy, qodercli, iflow")
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if __name__ == "__main__":
|
|
323
|
-
main()
|