stigmergy 1.0.59 → 1.0.61
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/package.json +3 -3
- package/src/enhanced-main.js +340 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stigmergy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.61",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Stigmergy CLI - Multi-Agents跨AI CLI工具协作系统",
|
|
6
6
|
"main": "src/main.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"stigmergy": "src/main.js"
|
|
8
|
+
"stigmergy": "src/enhanced-main.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node src/main.js",
|
|
@@ -78,4 +78,4 @@
|
|
|
78
78
|
"bugs": {
|
|
79
79
|
"url": "https://github.com/ptreezh/stigmergy-CLI-Multi-Agents/issues"
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stigmergy CLI - Enhanced Main Entry Point
|
|
5
|
+
* 支持自动扫描本地CLI环境并提供交互式安装选项
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
import fs from 'fs/promises';
|
|
10
|
+
import { join, dirname } from 'path';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import { homedir } from 'os';
|
|
13
|
+
import { createInterface } from 'readline';
|
|
14
|
+
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
|
|
18
|
+
// 定义支持的AI工具
|
|
19
|
+
const AI_TOOLS = [
|
|
20
|
+
{
|
|
21
|
+
name: 'claude',
|
|
22
|
+
displayName: 'Claude CLI',
|
|
23
|
+
required: true,
|
|
24
|
+
description: 'Anthropic Claude AI助手'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'gemini',
|
|
28
|
+
displayName: 'Gemini CLI',
|
|
29
|
+
required: true,
|
|
30
|
+
description: 'Google Gemini AI助手'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'qwen',
|
|
34
|
+
displayName: 'QwenCode CLI',
|
|
35
|
+
required: false,
|
|
36
|
+
description: '阿里云通义千问代码助手'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'iflow',
|
|
40
|
+
displayName: 'iFlow CLI',
|
|
41
|
+
required: false,
|
|
42
|
+
description: 'iFlow工作流自动化工具'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'qoder',
|
|
46
|
+
displayName: 'Qoder CLI',
|
|
47
|
+
required: false,
|
|
48
|
+
description: 'Qoder代码生成工具'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'codebuddy',
|
|
52
|
+
displayName: 'CodeBuddy CLI',
|
|
53
|
+
required: false,
|
|
54
|
+
description: '腾讯CodeBuddy编程助手'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'copilot',
|
|
58
|
+
displayName: 'GitHub Copilot CLI',
|
|
59
|
+
required: false,
|
|
60
|
+
description: 'GitHub Copilot命令行工具'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'ollama',
|
|
64
|
+
displayName: 'Ollama CLI',
|
|
65
|
+
required: false,
|
|
66
|
+
description: '本地AI模型运行工具'
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
class EnhancedStigmergyCLI {
|
|
71
|
+
constructor() {
|
|
72
|
+
this.configDir = join(homedir(), '.stigmergy-cli');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async checkToolAvailable(toolName) {
|
|
76
|
+
try {
|
|
77
|
+
// 使用spawn而不是spawnSync以避免阻塞
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
const child = spawn(
|
|
80
|
+
process.platform === 'win32' ? 'where' : 'which',
|
|
81
|
+
[toolName],
|
|
82
|
+
{
|
|
83
|
+
stdio: 'pipe',
|
|
84
|
+
timeout: 5000 // 5秒超时
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
let stdout = '';
|
|
89
|
+
let stderr = '';
|
|
90
|
+
|
|
91
|
+
child.stdout.on('data', (data) => {
|
|
92
|
+
stdout += data.toString();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
child.stderr.on('data', (data) => {
|
|
96
|
+
stderr += data.toString();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
child.on('close', (code) => {
|
|
100
|
+
// 检查命令是否成功执行且有输出
|
|
101
|
+
if (code === 0 && stdout.trim() !== '') {
|
|
102
|
+
resolve(true);
|
|
103
|
+
} else {
|
|
104
|
+
// 如果where/which失败,尝试直接运行命令检查版本
|
|
105
|
+
this.testCommandVersion(toolName).then(resolve).catch(() => resolve(false));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
child.on('error', () => {
|
|
110
|
+
// 如果命令不存在,尝试备用检测方法
|
|
111
|
+
this.testCommandVersion(toolName).then(resolve).catch(() => resolve(false));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async testCommandVersion(toolName) {
|
|
120
|
+
try {
|
|
121
|
+
return new Promise((resolve) => {
|
|
122
|
+
// 尝试运行常见的版本检查命令
|
|
123
|
+
const versionCommands = [
|
|
124
|
+
`${toolName} --version`,
|
|
125
|
+
`${toolName} -v`,
|
|
126
|
+
`${toolName} version`
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
let attempts = 0;
|
|
130
|
+
|
|
131
|
+
const tryNextCommand = () => {
|
|
132
|
+
if (attempts >= versionCommands.length) {
|
|
133
|
+
resolve(false);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const command = versionCommands[attempts];
|
|
138
|
+
attempts++;
|
|
139
|
+
|
|
140
|
+
const child = spawn(command, {
|
|
141
|
+
shell: true,
|
|
142
|
+
stdio: 'pipe',
|
|
143
|
+
timeout: 3000
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
let stdout = '';
|
|
147
|
+
let stderr = '';
|
|
148
|
+
|
|
149
|
+
child.stdout.on('data', (data) => {
|
|
150
|
+
stdout += data.toString();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
child.stderr.on('data', (data) => {
|
|
154
|
+
stderr += data.toString();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
child.on('close', (code) => {
|
|
158
|
+
if (code === 0 && (stdout.trim() !== '' || stderr.trim() !== '')) {
|
|
159
|
+
resolve(true);
|
|
160
|
+
} else {
|
|
161
|
+
tryNextCommand();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
child.on('error', () => {
|
|
166
|
+
tryNextCommand();
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
tryNextCommand();
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async scanLocalEnvironment() {
|
|
178
|
+
console.log('🔍 正在扫描本地AI CLI工具环境...');
|
|
179
|
+
console.log('');
|
|
180
|
+
|
|
181
|
+
const availableTools = [];
|
|
182
|
+
const missingTools = [];
|
|
183
|
+
|
|
184
|
+
// 并行检测所有工具以提高性能
|
|
185
|
+
const detectionPromises = AI_TOOLS.map(async (tool) => {
|
|
186
|
+
const isAvailable = await this.checkToolAvailable(tool.name);
|
|
187
|
+
return { tool, isAvailable };
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const results = await Promise.all(detectionPromises);
|
|
191
|
+
|
|
192
|
+
results.forEach(({ tool, isAvailable }) => {
|
|
193
|
+
if (isAvailable) {
|
|
194
|
+
availableTools.push(tool);
|
|
195
|
+
console.log(`✅ ${tool.displayName} - 已安装`);
|
|
196
|
+
} else {
|
|
197
|
+
missingTools.push(tool);
|
|
198
|
+
const status = tool.required ? '❌ (必需)' : '⚠️ (可选)';
|
|
199
|
+
console.log(`${status} ${tool.displayName} - 未安装`);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
console.log('');
|
|
204
|
+
console.log(`📊 扫描结果: ${availableTools.length} 个工具已安装, ${missingTools.length} 个工具缺失`);
|
|
205
|
+
|
|
206
|
+
// 显示一些调试信息帮助用户理解
|
|
207
|
+
if (availableTools.length === 0) {
|
|
208
|
+
console.log('💡 提示: 如果您确信已安装某些工具但未被检测到,可能是因为:');
|
|
209
|
+
console.log(' • 工具命令名称与我们检测的名称不同');
|
|
210
|
+
console.log(' • 工具未添加到系统PATH环境变量');
|
|
211
|
+
console.log(' • 工具需要特殊的方式检测版本');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { availableTools, missingTools };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async interactiveInstall(missingTools) {
|
|
218
|
+
if (missingTools.length === 0) {
|
|
219
|
+
console.log('🎉 所有工具都已安装!');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
console.log('\n🔧 可以自动安装以下缺失的工具:');
|
|
224
|
+
missingTools.forEach((tool, index) => {
|
|
225
|
+
const required = tool.required ? '(必需)' : '(可选)';
|
|
226
|
+
console.log(` ${index + 1}. ${tool.displayName} ${required} - ${tool.description}`);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const rl = createInterface({
|
|
230
|
+
input: process.stdin,
|
|
231
|
+
output: process.stdout
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return new Promise((resolve) => {
|
|
235
|
+
rl.question('\n是否要安装缺失的工具? (y/N): ', async (answer) => {
|
|
236
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
|
237
|
+
console.log('\n🚀 开始安装缺失的工具...');
|
|
238
|
+
for (const tool of missingTools) {
|
|
239
|
+
await this.installTool(tool);
|
|
240
|
+
}
|
|
241
|
+
console.log('✅ 工具安装完成!');
|
|
242
|
+
} else {
|
|
243
|
+
console.log('💡 您可以稍后手动安装这些工具。');
|
|
244
|
+
}
|
|
245
|
+
rl.close();
|
|
246
|
+
resolve();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async installTool(tool) {
|
|
252
|
+
console.log(`📥 正在安装 ${tool.displayName}...`);
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
// 这里应该实现具体的安装逻辑
|
|
256
|
+
// 例如:npm install -g @some/package
|
|
257
|
+
console.log(`⚠️ ${tool.displayName} 安装功能待实现`);
|
|
258
|
+
|
|
259
|
+
// 模拟安装过程
|
|
260
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
261
|
+
console.log(`✅ ${tool.displayName} 安装完成`);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.log(`❌ ${tool.displayName} 安装失败: ${error.message}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async deployAdapters() {
|
|
268
|
+
console.log('🔧 正在部署Stigmergy适配器到各个CLI工具...');
|
|
269
|
+
|
|
270
|
+
// 这里应该实现适配器部署逻辑
|
|
271
|
+
// 例如:将配置文件复制到各个CLI工具的配置目录
|
|
272
|
+
console.log('✅ 适配器部署完成!');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async run() {
|
|
276
|
+
const args = process.argv.slice(2);
|
|
277
|
+
const command = args[0];
|
|
278
|
+
|
|
279
|
+
switch (command) {
|
|
280
|
+
case 'scan':
|
|
281
|
+
const { missingTools } = await this.scanLocalEnvironment();
|
|
282
|
+
if (missingTools.length > 0) {
|
|
283
|
+
await this.interactiveInstall(missingTools);
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
|
|
287
|
+
case 'install':
|
|
288
|
+
console.log('📥 安装Stigmergy CLI系统...');
|
|
289
|
+
// 实现安装逻辑
|
|
290
|
+
console.log('✅ Stigmergy CLI安装完成!');
|
|
291
|
+
break;
|
|
292
|
+
|
|
293
|
+
case 'deploy':
|
|
294
|
+
await this.deployAdapters();
|
|
295
|
+
break;
|
|
296
|
+
|
|
297
|
+
case 'init':
|
|
298
|
+
console.log('🚀 初始化Stigmergy项目...');
|
|
299
|
+
await this.scanLocalEnvironment();
|
|
300
|
+
console.log('✅ 项目初始化完成!');
|
|
301
|
+
break;
|
|
302
|
+
|
|
303
|
+
default:
|
|
304
|
+
await this.showHelp();
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async showHelp() {
|
|
310
|
+
console.log(`
|
|
311
|
+
🤖 Stigmergy CLI v1.0.0 - Multi-Agents跨AI CLI工具协作系统
|
|
312
|
+
|
|
313
|
+
📚 主要功能:
|
|
314
|
+
scan - 扫描本地AI CLI工具环境并提供安装建议
|
|
315
|
+
install - 安装Stigmergy CLI系统
|
|
316
|
+
deploy - 部署适配器到各个CLI工具
|
|
317
|
+
init - 初始化项目并扫描环境
|
|
318
|
+
|
|
319
|
+
💡 使用示例:
|
|
320
|
+
stigmergy scan # 扫描环境并交互式安装缺失工具
|
|
321
|
+
stigmergy init # 初始化项目
|
|
322
|
+
stigmergy deploy # 部署适配器
|
|
323
|
+
|
|
324
|
+
🌟 特色功能:
|
|
325
|
+
• 自动扫描本地已安装的AI CLI工具
|
|
326
|
+
• 交互式选择安装缺失的工具
|
|
327
|
+
• 智能部署适配器到各个CLI工具的正确目录
|
|
328
|
+
• 支持跨AI工具协作指令生成
|
|
329
|
+
|
|
330
|
+
📖 文档: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents#readme
|
|
331
|
+
`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 运行CLI
|
|
336
|
+
const cli = new EnhancedStigmergyCLI();
|
|
337
|
+
cli.run().catch(error => {
|
|
338
|
+
console.error('❌ 程序运行出错:', error.message);
|
|
339
|
+
process.exit(1);
|
|
340
|
+
});
|