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.
Files changed (94) hide show
  1. package/LICENSE +19 -0
  2. package/README.de.md +301 -0
  3. package/README.en.md +301 -0
  4. package/README.es.md +301 -0
  5. package/README.fr.md +301 -0
  6. package/README.ja.md +301 -0
  7. package/README.ko.md +301 -0
  8. package/README.md +301 -0
  9. package/README.ru.md +301 -0
  10. package/README.zh.md +301 -0
  11. package/package.json +82 -0
  12. package/src/adapters/claude/__init__.py +13 -0
  13. package/src/adapters/claude/claude_skills_integration.py +609 -0
  14. package/src/adapters/claude/hook_adapter.py +663 -0
  15. package/src/adapters/claude/install_claude_integration.py +265 -0
  16. package/src/adapters/claude/skills_hook_adapter.py +841 -0
  17. package/src/adapters/claude/standalone_claude_adapter.py +384 -0
  18. package/src/adapters/cline/__init__.py +20 -0
  19. package/src/adapters/cline/config.py +108 -0
  20. package/src/adapters/cline/install_cline_integration.py +617 -0
  21. package/src/adapters/cline/mcp_server.py +713 -0
  22. package/src/adapters/cline/standalone_cline_adapter.py +459 -0
  23. package/src/adapters/codebuddy/__init__.py +13 -0
  24. package/src/adapters/codebuddy/buddy_adapter.py +1125 -0
  25. package/src/adapters/codebuddy/install_codebuddy_integration.py +279 -0
  26. package/src/adapters/codebuddy/skills_hook_adapter.py +672 -0
  27. package/src/adapters/codebuddy/skills_integration.py +395 -0
  28. package/src/adapters/codebuddy/standalone_codebuddy_adapter.py +403 -0
  29. package/src/adapters/codex/__init__.py +11 -0
  30. package/src/adapters/codex/base.py +46 -0
  31. package/src/adapters/codex/install_codex_integration.py +311 -0
  32. package/src/adapters/codex/mcp_server.py +493 -0
  33. package/src/adapters/codex/natural_language_parser.py +82 -0
  34. package/src/adapters/codex/slash_command_adapter.py +326 -0
  35. package/src/adapters/codex/standalone_codex_adapter.py +362 -0
  36. package/src/adapters/copilot/__init__.py +13 -0
  37. package/src/adapters/copilot/install_copilot_integration.py +564 -0
  38. package/src/adapters/copilot/mcp_adapter.py +772 -0
  39. package/src/adapters/copilot/mcp_server.py +168 -0
  40. package/src/adapters/copilot/standalone_copilot_adapter.py +114 -0
  41. package/src/adapters/gemini/__init__.py +13 -0
  42. package/src/adapters/gemini/extension_adapter.py +690 -0
  43. package/src/adapters/gemini/install_gemini_integration.py +257 -0
  44. package/src/adapters/gemini/standalone_gemini_adapter.py +366 -0
  45. package/src/adapters/iflow/__init__.py +7 -0
  46. package/src/adapters/iflow/hook_adapter.py +1038 -0
  47. package/src/adapters/iflow/hook_installer.py +536 -0
  48. package/src/adapters/iflow/install_iflow_integration.py +271 -0
  49. package/src/adapters/iflow/official_hook_adapter.py +1272 -0
  50. package/src/adapters/iflow/standalone_iflow_adapter.py +48 -0
  51. package/src/adapters/iflow/workflow_adapter.py +793 -0
  52. package/src/adapters/qoder/hook_installer.py +732 -0
  53. package/src/adapters/qoder/install_qoder_integration.py +265 -0
  54. package/src/adapters/qoder/notification_hook_adapter.py +863 -0
  55. package/src/adapters/qoder/standalone_qoder_adapter.py +48 -0
  56. package/src/adapters/qwen/__init__.py +17 -0
  57. package/src/adapters/qwencode/__init__.py +13 -0
  58. package/src/adapters/qwencode/inheritance_adapter.py +818 -0
  59. package/src/adapters/qwencode/install_qwencode_integration.py +276 -0
  60. package/src/adapters/qwencode/standalone_qwencode_adapter.py +399 -0
  61. package/src/atomic_collaboration_handler.py +461 -0
  62. package/src/cli_collaboration_agent.py +697 -0
  63. package/src/collaboration/hooks.py +315 -0
  64. package/src/core/__init__.py +21 -0
  65. package/src/core/ai_environment_scanner.py +331 -0
  66. package/src/core/base_adapter.py +220 -0
  67. package/src/core/cli_hook_integration.py +406 -0
  68. package/src/core/cross_cli_executor.py +713 -0
  69. package/src/core/cross_cli_mapping.py +1163 -0
  70. package/src/core/cross_platform_encoding.py +365 -0
  71. package/src/core/cross_platform_safe_cli.py +894 -0
  72. package/src/core/direct_cli_executor.py +805 -0
  73. package/src/core/direct_cli_hook_system.py +958 -0
  74. package/src/core/enhanced_init_processor.py +427 -0
  75. package/src/core/graceful_cli_executor.py +912 -0
  76. package/src/core/md_enhancer.py +342 -0
  77. package/src/core/md_generator.py +619 -0
  78. package/src/core/models.py +218 -0
  79. package/src/core/parser.py +108 -0
  80. package/src/core/real_cli_hook_system.py +852 -0
  81. package/src/core/real_cross_cli_system.py +925 -0
  82. package/src/core/verified_cross_cli_system.py +961 -0
  83. package/src/deploy.js +737 -0
  84. package/src/enhanced_deploy.js +303 -0
  85. package/src/enhanced_universal_cli_setup.py +930 -0
  86. package/src/kimi_wrapper.py +104 -0
  87. package/src/main.js +1309 -0
  88. package/src/shell_integration.py +398 -0
  89. package/src/simple-main.js +315 -0
  90. package/src/smart_router_creator.py +323 -0
  91. package/src/universal_cli_setup.py +1289 -0
  92. package/src/utils/__init__.py +12 -0
  93. package/src/utils/cli_detector.py +445 -0
  94. package/src/utils/file_utils.py +246 -0
package/src/deploy.js ADDED
@@ -0,0 +1,737 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Stigmergy CLI - 项目构建和发布部署脚本
5
+ * =================================================================
6
+ * 这是项目的主部署脚本,用于:
7
+ * 1. 扫描系统中的CLI工具状态
8
+ * 2. 询问用户是否安装未安装的CLI工具和集成
9
+ * 3. 构建项目
10
+ * 4. 发布到NPM
11
+ * 5. 显示使用说明
12
+ *
13
+ * 与 deployment/ 目录下的工具配置脚本不同:
14
+ * - deployment/deploy.js: 用于配置用户系统中已安装的AI工具
15
+ * - deployment/deploy-with-install.js: 增强版工具配置脚本,支持自动安装缺失的工具
16
+ *
17
+ * 使用方法:
18
+ * npm run deploy
19
+ * =================================================================
20
+ */
21
+
22
+ import { spawn } from 'child_process';
23
+ import { readFile } from 'fs/promises';
24
+ import { accessSync, existsSync } from 'fs';
25
+ import { join, dirname } from 'path';
26
+ import { createInterface } from 'readline';
27
+ import { fileURLToPath } from 'url';
28
+
29
+ const __filename = fileURLToPath(import.meta.url);
30
+ const __dirname = dirname(__filename);
31
+
32
+ // CLI工具配置
33
+ const CLI_TOOLS = [
34
+ {
35
+ name: 'claude',
36
+ displayName: 'Claude CLI',
37
+ description: 'Anthropic Claude CLI工具',
38
+ required: true
39
+ },
40
+ {
41
+ name: 'gemini',
42
+ displayName: 'Gemini CLI',
43
+ description: 'Google Gemini CLI工具',
44
+ required: true
45
+ },
46
+ {
47
+ name: 'qwen',
48
+ displayName: 'QwenCode CLI',
49
+ description: '阿里云QwenCode CLI工具',
50
+ required: false
51
+ },
52
+ {
53
+ name: 'iflow',
54
+ displayName: 'iFlow CLI',
55
+ description: 'iFlow工作流CLI工具',
56
+ required: false
57
+ },
58
+ {
59
+ name: 'qoder',
60
+ displayName: 'Qoder CLI',
61
+ description: 'Qoder代码生成CLI工具',
62
+ required: false
63
+ },
64
+ {
65
+ name: 'codebuddy',
66
+ displayName: 'CodeBuddy CLI',
67
+ description: 'CodeBuddy编程助手CLI工具',
68
+ required: false
69
+ },
70
+ {
71
+ name: 'copilot',
72
+ displayName: 'GitHub Copilot CLI',
73
+ description: 'GitHub Copilot CLI工具',
74
+ required: false
75
+ },
76
+ {
77
+ name: 'codex',
78
+ displayName: 'Codex CLI',
79
+ description: 'Codex代码分析CLI工具',
80
+ required: false
81
+ },
82
+ {
83
+ name: 'cline',
84
+ displayName: 'Cline CLI',
85
+ description: 'Cline自主编码代理CLI工具 (仅支持macOS/Linux)',
86
+ required: false
87
+ }
88
+ ];
89
+
90
+ // 颜色输出
91
+ const colors = {
92
+ reset: '\x1b[0m',
93
+ red: '\x1b[31m',
94
+ green: '\x1b[32m',
95
+ yellow: '\x1b[33m',
96
+ blue: '\x1b[34m',
97
+ magenta: '\x1b[35m',
98
+ cyan: '\x1b[36m'
99
+ };
100
+
101
+ function colorLog(color, message) {
102
+ console.log(`${colors[color]}${message}${colors.reset}`);
103
+ }
104
+
105
+ // 交互式询问
106
+ async function askQuestion(question, defaultValue = null) {
107
+ const rl = createInterface({
108
+ input: process.stdin,
109
+ output: process.stdout
110
+ });
111
+
112
+ return new Promise((resolve) => {
113
+ const questionText = defaultValue ?
114
+ `${colors.cyan}${question} (${colors.yellow}${defaultValue}${colors.cyan}): ${colors.reset}` :
115
+ `${colors.cyan}${question}: ${colors.reset}`;
116
+
117
+ rl.question(questionText, (answer) => {
118
+ rl.close();
119
+ resolve(answer.trim() || defaultValue);
120
+ });
121
+ });
122
+ }
123
+
124
+ // 询问是否(Y/n)
125
+ async function askYesNo(question, defaultYes = true) {
126
+ const suffix = defaultYes ? ' (Y/n): ' : ' (y/N): ';
127
+ const answer = await askQuestion(question + suffix, defaultYes ? 'Y' : 'N');
128
+ return answer.toLowerCase().startsWith('y') || answer.toLowerCase() === '';
129
+ }
130
+
131
+ // 执行命令
132
+ function executeCommand(command, args, options = {}) {
133
+ return new Promise((resolve, reject) => {
134
+ const child = spawn(command, args, {
135
+ stdio: ['pipe', 'pipe', 'pipe'],
136
+ shell: true,
137
+ ...options
138
+ });
139
+
140
+ let stdout = '';
141
+ let stderr = '';
142
+
143
+ child.stdout?.on('data', (data) => {
144
+ stdout += data.toString();
145
+ });
146
+
147
+ child.stderr?.on('data', (data) => {
148
+ stderr += data.toString();
149
+ });
150
+
151
+ child.on('close', (code) => {
152
+ resolve({ code, stdout, stderr });
153
+ });
154
+
155
+ child.on('error', (error) => {
156
+ reject(error);
157
+ });
158
+ });
159
+ }
160
+
161
+ // CLI工具安装配置(真实的安装命令)
162
+ const CLI_INSTALL_CONFIGS = {
163
+ 'claude': {
164
+ name: 'Claude CLI',
165
+ displayName: 'Claude CLI',
166
+ description: 'Anthropic Claude CLI工具',
167
+ required: true,
168
+ installCommand: 'npm install -g @anthropic-ai/claude-code',
169
+ website: 'https://claude.ai/cli',
170
+ docs: 'https://docs.anthropic.com/claude-cli'
171
+ },
172
+ 'gemini': {
173
+ name: 'Gemini CLI',
174
+ displayName: 'Gemini CLI',
175
+ description: 'Google Gemini CLI工具',
176
+ required: true,
177
+ installCommand: 'npm install -g @google/gemini-cli',
178
+ website: 'https://ai.google.dev/cli',
179
+ docs: 'https://ai.google.dev/cli/docs'
180
+ },
181
+ 'qwen': {
182
+ name: 'QwenCode CLI',
183
+ displayName: 'QwenCode CLI',
184
+ description: '阿里云QwenCode CLI工具',
185
+ required: false,
186
+ installCommand: 'npm install -g @qwen-code/qwen-code@latest',
187
+ website: 'https://qwen.aliyun.com',
188
+ docs: 'https://help.aliyun.com/zh/developer-tools/qwen'
189
+ },
190
+ 'qoder': {
191
+ name: 'Qoder CLI',
192
+ displayName: 'Qoder CLI',
193
+ description: 'Qoder代码生成CLI工具',
194
+ required: false,
195
+ installCommand: 'npm install -g @qoder-ai/qodercli',
196
+ website: 'https://qoder.ai',
197
+ docs: 'https://qoder.ai/docs/cli'
198
+ },
199
+ 'iflow': {
200
+ name: 'iFlow CLI',
201
+ displayName: 'iFlow CLI',
202
+ description: 'iFlow工作流CLI工具',
203
+ required: false,
204
+ installCommand: 'npm install -g @iflow-ai/iflow-cli@latest',
205
+ website: 'https://iflow.ai',
206
+ docs: 'https://iflow.ai/docs/cli'
207
+ },
208
+ 'codebuddy': {
209
+ name: 'CodeBuddy CLI',
210
+ displayName: 'CodeBuddy CLI',
211
+ description: 'CodeBuddy编程助手CLI工具',
212
+ required: false,
213
+ installCommand: 'npm install -g @tencent-ai/codebuddy-code',
214
+ website: 'https://codebuddy.ai',
215
+ docs: 'https://codebuddy.ai/docs/cli'
216
+ },
217
+ 'copilot': {
218
+ name: 'GitHub Copilot CLI',
219
+ displayName: 'GitHub Copilot CLI',
220
+ description: 'GitHub Copilot CLI工具',
221
+ required: false,
222
+ installCommand: 'npm install -g @github/copilot',
223
+ website: 'https://github.com/features/copilot',
224
+ docs: 'https://docs.github.com/en/copilot/cli-overview'
225
+ },
226
+ 'codex': {
227
+ name: 'OpenAI Codex CLI',
228
+ displayName: 'Codex CLI',
229
+ description: 'OpenAI Codex代码分析CLI工具',
230
+ required: false,
231
+ installCommand: 'npm i -g @openai/codex --registry=https://registry.npmmirror.com',
232
+ website: 'https://platform.openai.com',
233
+ docs: 'https://platform.openai.com/docs/cli'
234
+ },
235
+ 'cline': {
236
+ name: 'Cline CLI',
237
+ displayName: 'Cline CLI',
238
+ description: 'Cline自主编码代理CLI工具 (仅支持macOS/Linux)',
239
+ required: false,
240
+ installCommand: 'npm install -g cline',
241
+ website: 'https://cline.bot',
242
+ docs: 'https://docs.cline.bot'
243
+ }
244
+ };
245
+
246
+ // 检查CLI工具是否可用
247
+ async function checkCLIAvailability(cliName) {
248
+ try {
249
+ const installConfig = CLI_INSTALL_CONFIGS[cliName];
250
+ if (!installConfig) {
251
+ return false;
252
+ }
253
+
254
+ // 平台检查 - Cline CLI仅支持macOS和Linux
255
+ if (cliName === 'cline') {
256
+ const os = process.platform;
257
+ if (os === 'win32') {
258
+ console.log('⚠️ Cline CLI不支持Windows平台');
259
+ return false;
260
+ }
261
+ }
262
+
263
+ // 尝试常见的CLI命令名称
264
+ const possibleCommands = [cliName, `${cliName}.cmd`, `${cliName}.py`, `${cliName}.sh`];
265
+
266
+ for (const cmd of possibleCommands) {
267
+ try {
268
+ // 在Unix-like系统上使用which命令
269
+ const whichCmd = process.platform === 'win32' ? 'where' : 'which';
270
+ const result = await executeCommand(whichCmd, [cmd]);
271
+ if (result.code === 0) {
272
+ return true;
273
+ }
274
+ } catch (error) {
275
+ // 继续尝试下一个命令
276
+ }
277
+ }
278
+
279
+ // GitHub Copilot 检查集成状态(不再需要特殊处理,使用通用检查)
280
+ if (cliName === 'copilot') {
281
+ try {
282
+ const result = await executeCommand('gh', ['extensions', 'list']);
283
+ if (result.stdout.includes('gh-copilot')) {
284
+ return true;
285
+ }
286
+ } catch (error) {
287
+ // 继续尝试通用检查
288
+ }
289
+ }
290
+
291
+ // 通用检查:尝试执行CLI命令
292
+ try {
293
+ const result = await executeCommand(cliName, ['--version', '--help'], {
294
+ shell: true,
295
+ timeout: 5000
296
+ });
297
+ return result.code === 0;
298
+ } catch (error) {
299
+ return false;
300
+ }
301
+ } catch (error) {
302
+ return false;
303
+ }
304
+ }
305
+
306
+ // 提供CLI工具安装指导
307
+ function showCLInstallationGuide(cliName) {
308
+ const cliInfo = CLI_TOOLS_INFO[cliName];
309
+ if (!cliInfo) {
310
+ return;
311
+ }
312
+
313
+ console.log('');
314
+ colorLog('yellow', `📖 ${cliInfo.officialName} 安装指南:`);
315
+ console.log('');
316
+ console.log(colors.cyan + `📚 官方文档: ${cliInfo.installDocs}`);
317
+ console.log(colors.cyan + `🌐 官方网站: ${cliInfo.website}`);
318
+ console.log('');
319
+
320
+ console.log(colors.yellow + '🔧 推荐安装方法:');
321
+ cliInfo.installMethods.forEach((method, index) => {
322
+ console.log(colors.white + ` ${index + 1}. ${method}`);
323
+ });
324
+
325
+ console.log('');
326
+ console.log(colors.blue + '💡 提示:');
327
+ console.log(colors.white + ' - 请按照官方文档进行安装');
328
+ console.log(colors.white + ' - 安装完成后,重新运行部署脚本');
329
+ console.log(colors.white + ' - 如果遇到问题,请查看官方文档获取帮助');
330
+ }
331
+
332
+ // 询问用户是否已安装CLI工具
333
+ async function askUserToInstallCLIMannualy(unavailableCLIs) {
334
+ if (unavailableCLIs.length === 0) {
335
+ return;
336
+ }
337
+
338
+ console.log('');
339
+ colorLog('yellow', '🔴 检测到以下CLI工具未安装:');
340
+
341
+ for (const cliInfo of unavailableCLIs) {
342
+ const required = cliInfo.required ? '(必需)' : '(可选)';
343
+ console.log(colors.red + ` ❌ ${cliInfo.displayName} ${required}`);
344
+ }
345
+
346
+ console.log('');
347
+ const shouldContinue = await askYesNo(
348
+ '是否要查看这些CLI工具的安装指南?',
349
+ true
350
+ );
351
+
352
+ if (shouldContinue) {
353
+ for (const cliInfo of unavailableCLIs) {
354
+ showCLInstallationGuide(cliInfo.name);
355
+ console.log('');
356
+
357
+ const pauseForUser = await askYesNo(
358
+ `已查看 ${cliInfo.displayName} 安装指南,是否继续下一个?`,
359
+ true
360
+ );
361
+ }
362
+ }
363
+ }
364
+
365
+ // 检查CLI集成是否已安装
366
+ async function checkCLIIntegration(cliName) {
367
+ try {
368
+ const installScript = join(__dirname, 'adapters', cliName, `install_${cliName}_integration.py`);
369
+
370
+ // 检查安装脚本是否存在
371
+ try {
372
+ await accessSync(installScript);
373
+ } catch (error) {
374
+ return { installed: false, reason: 'Install script not found' };
375
+ }
376
+
377
+ // 执行验证
378
+ const result = await executeCommand('python', [installScript, '--verify'], {
379
+ cwd: __dirname
380
+ });
381
+
382
+ return {
383
+ installed: result.code === 0,
384
+ reason: result.code === 0 ? 'Verified' : result.stderr
385
+ };
386
+ } catch (error) {
387
+ return { installed: false, reason: error.message };
388
+ }
389
+ }
390
+
391
+ // 安装单个CLI工具集成
392
+ async function installCLIIntegration(cliName, cliInfo) {
393
+ colorLog('cyan', `🔧 正在安装 ${cliInfo.displayName} 集成...`);
394
+
395
+ try {
396
+ const installScript = join(__dirname, 'adapters', cliName, `install_${cliName}_integration.py`);
397
+
398
+ // 检查安装脚本是否存在
399
+ try {
400
+ await accessSync(installScript);
401
+ } catch (error) {
402
+ colorLog('yellow', `⚠️ ${cliInfo.displayName} 安装脚本不存在,跳过`);
403
+ return { success: false, reason: 'Install script not found' };
404
+ }
405
+
406
+ // 执行安装
407
+ const result = await executeCommand('python', [installScript, '--install'], {
408
+ cwd: __dirname
409
+ });
410
+
411
+ if (result.code === 0) {
412
+ colorLog('green', `✅ ${cliInfo.displayName} 集成安装成功`);
413
+ return { success: true };
414
+ } else {
415
+ colorLog('red', `❌ ${cliInfo.displayName} 集成安装失败`);
416
+ if (result.stderr) {
417
+ console.log(colors.red + result.stderr + colors.reset);
418
+ }
419
+ return { success: false, reason: result.stderr };
420
+ }
421
+
422
+ } catch (error) {
423
+ colorLog('red', `❌ ${cliInfo.displayName} 安装过程出错: ${error.message}`);
424
+ return { success: false, reason: error.message };
425
+ }
426
+ }
427
+
428
+ // 扫描系统状态
429
+ async function scanSystemStatus() {
430
+ colorLog('magenta', '🔍 扫描系统CLI工具状态...');
431
+ console.log('');
432
+
433
+ const results = [];
434
+
435
+ for (const cliInfo of CLI_TOOLS) {
436
+ const isAvailable = await checkCLIAvailability(cliInfo.name);
437
+ const integrationStatus = await checkCLIIntegration(cliInfo.name);
438
+
439
+ results.push({
440
+ ...cliInfo,
441
+ available: isAvailable,
442
+ integration: integrationStatus
443
+ });
444
+
445
+ const statusIcon = isAvailable ? '🟢' : '🔴';
446
+ const integrationIcon = integrationStatus.installed ? '✅' : '❌';
447
+
448
+ console.log(` ${statusIcon} ${integrationIcon} ${cliInfo.displayName.padEnd(20)} | CLI: ${isAvailable ? '可用' : '未安装'} | 集成: ${integrationStatus.installed ? '已安装' : '未安装'}`);
449
+ }
450
+
451
+ return results;
452
+ }
453
+
454
+ // 智能询问用户是否安装未安装的CLI工具和集成
455
+ async function askUserToInstall(results) {
456
+ const unavailableCLIs = results.filter(cli => !cli.available);
457
+ const uninstalledIntegrations = results.filter(cli => !cli.integration.installed);
458
+
459
+ if (unavailableCLIs.length === 0 && uninstalledIntegrations.length === 0) {
460
+ colorLog('green', '\n🎉 所有CLI工具和集成都已安装!');
461
+ return { installCLIs: [], installIntegrations: [] };
462
+ }
463
+
464
+ console.log('');
465
+ colorLog('yellow', '📋 检测到以下未安装的工具:');
466
+
467
+ let needInstallCLIs = [];
468
+ let needInstallIntegrations = [];
469
+
470
+ // 显示未安装的CLI工具
471
+ if (unavailableCLIs.length > 0) {
472
+ console.log('\n🔴 未安装的CLI工具:');
473
+ unavailableCLIs.forEach(cli => {
474
+ const required = cli.required ? '(必需)' : '(可选)';
475
+ console.log(` - ${cli.displayName} ${required} - ${cli.description}`);
476
+ });
477
+
478
+ console.log('');
479
+ const shouldInstallCLIs = await askYesNo(
480
+ `是否要尝试自动安装 ${unavailableCLIs.length} 个CLI工具?`,
481
+ true
482
+ );
483
+
484
+ if (shouldInstallCLIs) {
485
+ needInstallCLIs = unavailableCLIs;
486
+ }
487
+ }
488
+
489
+ // 显示未安装的集成
490
+ if (uninstalledIntegrations.length > 0) {
491
+ console.log('\n❌ 未安装的CLI集成:');
492
+ uninstalledIntegrations.forEach(cli => {
493
+ const required = cli.required ? '(必需)' : '(可选)';
494
+ console.log(` - ${cli.displayName} 集成 ${required}`);
495
+ });
496
+
497
+ console.log('');
498
+ const shouldInstallIntegrations = await askYesNo(
499
+ `是否要自动安装 ${uninstalledIntegrations.length} 个CLI集成?`,
500
+ true
501
+ );
502
+
503
+ if (shouldInstallIntegrations) {
504
+ needInstallIntegrations = uninstalledIntegrations;
505
+ }
506
+ }
507
+
508
+ return {
509
+ installCLIs: needInstallCLIs,
510
+ installIntegrations: needInstallIntegrations
511
+ };
512
+ }
513
+
514
+ // 安装单个CLI工具
515
+ async function installCLITool(cliName, cliInfo) {
516
+ colorLog('cyan', `🔧 正在安装 ${cliInfo.displayName}...`);
517
+
518
+ try {
519
+ const installConfig = CLI_INSTALL_CONFIGS[cliName];
520
+ if (!installConfig) {
521
+ colorLog('yellow', `⚠️ ${cliInfo.displayName} 安装配置不存在,跳过`);
522
+ return { success: false, reason: 'Install config not found' };
523
+ }
524
+
525
+ // 执行安装命令
526
+ const result = await executeCommand(installConfig.installCommand, [], {
527
+ shell: true
528
+ });
529
+
530
+ if (result.code === 0) {
531
+ colorLog('green', `✅ ${cliInfo.displayName} 安装成功`);
532
+ return { success: true };
533
+ } else {
534
+ colorLog('red', `❌ ${cliInfo.displayName} 安装失败`);
535
+ if (result.stderr) {
536
+ console.log(colors.red + result.stderr + colors.reset);
537
+ }
538
+ return { success: false, reason: result.stderr };
539
+ }
540
+
541
+ } catch (error) {
542
+ colorLog('red', `❌ ${cliInfo.displayName} 安装过程出错: ${error.message}`);
543
+ return { success: false, reason: error.message };
544
+ }
545
+ }
546
+
547
+ // 批量安装CLI工具
548
+ async function installSelectedCLIs(selectedCLIs) {
549
+ if (selectedCLIs.length === 0) {
550
+ return { successCount: 0, totalCount: 0 };
551
+ }
552
+
553
+ colorLog('blue', `🚀 开始自动安装 ${selectedCLIs.length} 个CLI工具...`);
554
+ console.log('');
555
+
556
+ let successCount = 0;
557
+ let totalCount = selectedCLIs.length;
558
+
559
+ for (const cliInfo of selectedCLIs) {
560
+ const result = await installCLITool(cliInfo.name, cliInfo);
561
+
562
+ if (result.success) {
563
+ successCount++;
564
+ }
565
+ }
566
+
567
+ console.log('');
568
+ colorLog('green', `✅ CLI工具安装完成: ${successCount}/${totalCount} 个成功`);
569
+
570
+ return { successCount, totalCount };
571
+ }
572
+
573
+ // 批量安装CLI集成
574
+ async function installSelectedIntegrations(selectedIntegrations) {
575
+ if (selectedIntegrations.length === 0) {
576
+ return { successCount: 0, totalCount: 0 };
577
+ }
578
+
579
+ colorLog('blue', `🚀 开始自动安装 ${selectedIntegrations.length} 个CLI集成...`);
580
+ console.log('');
581
+
582
+ let successCount = 0;
583
+ let totalCount = selectedIntegrations.length;
584
+
585
+ for (const cliInfo of selectedIntegrations) {
586
+ const result = await installCLIIntegration(cliInfo.name, cliInfo);
587
+
588
+ if (result.success) {
589
+ successCount++;
590
+ }
591
+ }
592
+
593
+ console.log('');
594
+ colorLog('green', `✅ 集成安装完成: ${successCount}/${totalCount} 个成功`);
595
+
596
+ return { successCount, totalCount };
597
+ }
598
+
599
+ // 构建项目
600
+ async function buildProject() {
601
+ colorLog('blue', '\n📦 构建项目...');
602
+
603
+ try {
604
+ const result = await executeCommand('npm', ['run', 'build'], {
605
+ cwd: __dirname
606
+ });
607
+
608
+ if (result.code === 0) {
609
+ colorLog('green', '✅ 项目构建成功');
610
+ return true;
611
+ } else {
612
+ colorLog('red', `❌ 项目构建失败: ${result.stderr}`);
613
+ return false;
614
+ }
615
+ } catch (error) {
616
+ colorLog('red', `❌ 构建过程出错: ${error.message}`);
617
+ return false;
618
+ }
619
+ }
620
+
621
+ // 发布到NPM
622
+ async function publishToNPM() {
623
+ colorLog('blue', '\n🚀 发布到 NPM...');
624
+
625
+ try {
626
+ const result = await executeCommand('npm', ['publish', '--access', 'public'], {
627
+ cwd: __dirname
628
+ });
629
+
630
+ if (result.code === 0) {
631
+ colorLog('green', '✅ NPM 发布成功');
632
+ return true;
633
+ } else {
634
+ colorLog('red', `❌ NPM 发布失败: ${result.stderr}`);
635
+ return false;
636
+ }
637
+ } catch (error) {
638
+ colorLog('red', `❌ 发布过程出错: ${error.message}`);
639
+ return false;
640
+ }
641
+ }
642
+
643
+ // 显示部署后使用说明
644
+ function showUsageInstructions() {
645
+ console.log('');
646
+ colorLog('magenta', '🎉 Stigmergy CLI 部署成功!');
647
+ console.log('');
648
+ colorLog('cyan', '📦 现在任何人都可以使用以下命令:');
649
+ console.log('');
650
+ console.log(colors.yellow + ' # 基本命令');
651
+ console.log(colors.cyan + ' npx stigmergy-cli init # 初始化项目');
652
+ console.log(colors.cyan + ' npx stigmergy-cli status # 查看状态');
653
+ console.log(colors.cyan + ' npx stigmergy-cli scan # 扫描环境');
654
+ console.log('');
655
+ console.log(colors.yellow + ' # 部署命令');
656
+ console.log(colors.cyan + ' npx stigmergy-cli deploy # 智能部署');
657
+ console.log(colors.cyan + ' npm run deploy-all # 全量部署');
658
+ console.log('');
659
+ console.log(colors.yellow + ' # 协作示例');
660
+ console.log(colors.cyan + ' # 在任何支持的CLI中直接调用其他工具');
661
+ console.log(colors.cyan + ' "请用gemini帮我翻译这段代码"');
662
+ console.log(colors.cyan + ' "调用qwen分析这个需求"');
663
+ console.log(colors.cyan + ' "用iflow创建工作流"');
664
+ console.log('');
665
+ colorLog('cyan', '🎯 真正的跨CLI协作,让每个AI工具都能发挥最大价值!');
666
+ console.log('');
667
+ colorLog('cyan', '📚 更多信息: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents');
668
+ }
669
+
670
+ // 主部署函数
671
+ async function deploy(options = {}) {
672
+ const {
673
+ buildOnly = false,
674
+ publishOnly = false,
675
+ scanOnly = false
676
+ } = options;
677
+
678
+ colorLog('magenta', '🚀 Stigmergy CLI - 智能部署系统');
679
+ colorLog('cyan', '=====================================');
680
+ console.log('');
681
+
682
+ try {
683
+ // 1. 扫描系统状态
684
+ const results = await scanSystemStatus();
685
+
686
+ if (scanOnly) {
687
+ return;
688
+ }
689
+
690
+ // 2. 询问用户是否要安装未安装的CLI工具和集成
691
+ const { installCLIs, installIntegrations } = await askUserToInstall(results);
692
+
693
+ // 3. 先安装CLI工具
694
+ if (installCLIs.length > 0) {
695
+ await installSelectedCLIs(installCLIs);
696
+ }
697
+
698
+ // 4. 再安装CLI集成
699
+ if (installIntegrations.length > 0) {
700
+ await installSelectedIntegrations(installIntegrations);
701
+ }
702
+
703
+ // 5. 构建项目
704
+ if (buildOnly || publishOnly || !buildOnly && !publishOnly) {
705
+ const buildSuccess = await buildProject();
706
+ if (!buildSuccess && publishOnly) {
707
+ throw new Error('构建失败,无法发布');
708
+ }
709
+ }
710
+
711
+ // 6. 发布到NPM
712
+ if (publishOnly || !buildOnly && !publishOnly) {
713
+ const publishSuccess = await publishToNPM();
714
+ if (publishSuccess) {
715
+ showUsageInstructions();
716
+ }
717
+ } else {
718
+ console.log('');
719
+ colorLog('green', '✅ 部署完成!');
720
+ colorLog('cyan', '使用以下命令测试:');
721
+ console.log(colors.cyan + ' node src/main.js status');
722
+ console.log(colors.cyan + ' npx stigmergy-cli status (发布后)');
723
+ }
724
+
725
+ } catch (error) {
726
+ colorLog('red', `❌ 部署失败: ${error.message}`);
727
+ process.exit(1);
728
+ }
729
+ }
730
+
731
+ // 运行部署
732
+ if (import.meta.url === `file://${process.argv[1]}`) {
733
+ deploy().catch(error => {
734
+ console.error('部署失败:', error.message);
735
+ process.exit(1);
736
+ });
737
+ }