stigmergy 1.2.0 → 1.2.8

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 (130) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +31 -211
  3. package/STIGMERGY.md +70 -61
  4. package/docs/MULTI_USER_WIKI_COLLABORATION_SYSTEM.md +523 -0
  5. package/docs/PROJECT_CONSTITUTION.md +433 -433
  6. package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
  7. package/docs/PROMPT_BASED_SKILLS_SYSTEM_DESIGN.md +458 -0
  8. package/docs/SKILL_IMPLEMENTATION_CONSTRAINTS_AND_ALIGNMENT.md +423 -0
  9. package/docs/TECHNICAL_FEASIBILITY_ANALYSIS.md +308 -0
  10. package/examples/calculator-example.js +72 -72
  11. package/examples/cline_usage_examples.md +364 -364
  12. package/examples/encryption-example.js +67 -67
  13. package/examples/json-parser-example.js +120 -120
  14. package/examples/json-validation-example.js +64 -64
  15. package/examples/multilingual-hook-demo.js +125 -0
  16. package/examples/rest-client-example.js +52 -52
  17. package/examples/rest_client_example.js +54 -54
  18. package/package.json +38 -20
  19. package/scripts/build.js +74 -74
  20. package/scripts/dependency-analyzer.js +101 -0
  21. package/scripts/generate-cli-docs.js +64 -0
  22. package/scripts/post-deployment-config.js +296 -296
  23. package/scripts/postuninstall.js +46 -0
  24. package/scripts/preinstall-check.js +173 -173
  25. package/scripts/preuninstall.js +75 -0
  26. package/scripts/publish.js +58 -268
  27. package/scripts/run-layered-tests.js +247 -0
  28. package/scripts/safe-install.js +139 -139
  29. package/scripts/simple-publish.js +57 -59
  30. package/src/adapters/claude/install_claude_integration.js +292 -0
  31. package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
  32. package/src/adapters/codex/install_codex_integration.js +395 -0
  33. package/src/adapters/copilot/install_copilot_integration.js +716 -0
  34. package/src/adapters/gemini/install_gemini_integration.js +304 -0
  35. package/src/adapters/iflow/install_iflow_integration.js +304 -0
  36. package/src/adapters/qoder/install_qoder_integration.js +1090 -0
  37. package/src/adapters/qwen/install_qwen_integration.js +285 -0
  38. package/src/cli/router.js +562 -39
  39. package/src/core/cache_cleaner.js +82 -59
  40. package/src/core/cli_help_analyzer.js +297 -291
  41. package/src/core/cli_parameter_handler.js +5 -0
  42. package/src/core/cli_tools.js +6 -6
  43. package/src/core/coordination/index.js +2 -2
  44. package/src/core/coordination/nodejs/AdapterManager.js +30 -17
  45. package/src/core/coordination/nodejs/CLCommunication.js +28 -20
  46. package/src/core/coordination/nodejs/CLIIntegrationManager.js +72 -36
  47. package/src/core/coordination/nodejs/HealthChecker.js +13 -14
  48. package/src/core/coordination/nodejs/HookDeploymentManager.js +325 -63
  49. package/src/core/coordination/nodejs/StatisticsCollector.js +6 -6
  50. package/src/core/coordination/nodejs/index.js +29 -11
  51. package/src/core/coordination/nodejs/utils/Logger.js +1 -1
  52. package/src/core/enhanced_installer.js +92 -69
  53. package/src/core/enhanced_uninstaller.js +73 -53
  54. package/src/core/installer.js +815 -294
  55. package/src/core/multilingual/language-pattern-manager.js +172 -0
  56. package/src/core/smart_router.js +141 -26
  57. package/src/core/upgrade_manager.js +91 -46
  58. package/src/data_structures.js +1 -1
  59. package/src/deploy.js +2 -2
  60. package/src/index.js +3 -3
  61. package/src/test/cli-availability-checker.js +194 -0
  62. package/src/test/test-environment.js +289 -0
  63. package/src/utils/helpers.js +2 -2
  64. package/src/utils.js +7 -1
  65. package/test/multilingual/hook-deployment.test.js +91 -0
  66. package/test/multilingual/language-pattern-manager.test.js +140 -0
  67. package/test/multilingual/system-test.js +85 -0
  68. package/test/cache-cleaner-implemented.test.js +0 -328
  69. package/test/cache-cleaner.test.js +0 -390
  70. package/test/calculator.test.js +0 -215
  71. package/test/collision-test.js +0 -26
  72. package/test/comprehensive-enhanced-features.test.js +0 -252
  73. package/test/comprehensive-execution-test.js +0 -428
  74. package/test/conflict-prevention-test.js +0 -95
  75. package/test/cross-cli-detection-test.js +0 -33
  76. package/test/csv-processing-test.js +0 -36
  77. package/test/deploy-hooks-test.js +0 -250
  78. package/test/e2e/claude-cli-test.js +0 -128
  79. package/test/e2e/collaboration-test.js +0 -75
  80. package/test/e2e/comprehensive-test.js +0 -431
  81. package/test/e2e/error-handling-test.js +0 -90
  82. package/test/e2e/individual-tool-test.js +0 -143
  83. package/test/e2e/other-cli-test.js +0 -130
  84. package/test/e2e/qoder-cli-test.js +0 -128
  85. package/test/e2e/run-e2e-tests.js +0 -73
  86. package/test/e2e/test-data.js +0 -88
  87. package/test/e2e/test-utils.js +0 -222
  88. package/test/encryption-simple-test.js +0 -110
  89. package/test/encryption.test.js +0 -129
  90. package/test/enhanced-main-alignment.test.js +0 -298
  91. package/test/enhanced-uninstaller-implemented.test.js +0 -271
  92. package/test/enhanced-uninstaller.test.js +0 -284
  93. package/test/error-handling-test.js +0 -341
  94. package/test/fibonacci.test.js +0 -178
  95. package/test/final-deploy-test.js +0 -221
  96. package/test/final-install-test.js +0 -226
  97. package/test/hash-table-demo.js +0 -33
  98. package/test/hash-table-test.js +0 -26
  99. package/test/hash_table_test.js +0 -114
  100. package/test/hook-system-integration-test.js +0 -307
  101. package/test/iflow-integration-test.js +0 -292
  102. package/test/improved-install-test.js +0 -362
  103. package/test/install-command-test.js +0 -370
  104. package/test/json-parser-test.js +0 -161
  105. package/test/json-validation-test.js +0 -164
  106. package/test/natural-language-skills-test.js +0 -320
  107. package/test/nl-integration-test.js +0 -179
  108. package/test/parameter-parsing-test.js +0 -143
  109. package/test/plugin-deployment-test.js +0 -316
  110. package/test/postinstall-test.js +0 -269
  111. package/test/python-plugins-test.js +0 -259
  112. package/test/real-test.js +0 -435
  113. package/test/remaining-adapters-test.js +0 -256
  114. package/test/rest-client-test.js +0 -56
  115. package/test/rest_client.test.js +0 -85
  116. package/test/safe-installation-cleaner.test.js +0 -343
  117. package/test/simple-iflow-hook-test.js +0 -137
  118. package/test/stigmergy-upgrade-test.js +0 -243
  119. package/test/system-compatibility-test.js +0 -467
  120. package/test/tdd-deploy-fix-test.js +0 -324
  121. package/test/tdd-fixes-test.js +0 -211
  122. package/test/third-party-skills-test.js +0 -321
  123. package/test/tool-selection-integration-test.js +0 -158
  124. package/test/unit/calculator-full.test.js +0 -191
  125. package/test/unit/calculator-simple.test.js +0 -96
  126. package/test/unit/calculator.test.js +0 -97
  127. package/test/unit/cli-scanner.test.js +0 -291
  128. package/test/unit/cli_parameter_handler.test.js +0 -116
  129. package/test/unit/cross-cli-executor.test.js +0 -399
  130. package/test/weather-processor.test.js +0 -104
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Claude CLI Integration Installer - JavaScript Version
5
+ * Sets up basic integration for Claude CLI with cross-CLI collaboration capabilities
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ // Claude CLI config paths
13
+ const CLAUDE_CONFIG_DIR = path.join(os.homedir(), '.claude');
14
+ const CLAUDE_CONFIG_FILE = path.join(CLAUDE_CONFIG_DIR, 'config.json');
15
+ const CLAUDE_HOOKS_FILE = path.join(CLAUDE_CONFIG_DIR, 'hooks.json');
16
+
17
+ class ClaudeInstaller {
18
+ constructor() {
19
+ this.toolName = 'claude';
20
+ this.configDir = CLAUDE_CONFIG_DIR;
21
+ this.configFile = CLAUDE_CONFIG_FILE;
22
+ this.hooksFile = CLAUDE_HOOKS_FILE;
23
+ }
24
+
25
+ async createConfigDirectory() {
26
+ await fs.mkdir(this.configDir, { recursive: true });
27
+ console.log(`[OK] Created Claude config directory: ${this.configDir}`);
28
+ }
29
+
30
+ async installConfig() {
31
+ // Read existing config
32
+ let existingConfig = {};
33
+ try {
34
+ const content = await fs.readFile(this.configFile, 'utf-8');
35
+ existingConfig = JSON.parse(content);
36
+ } catch (e) {
37
+ console.log(`Warning: Failed to read existing config: ${e.message}`);
38
+ existingConfig = {};
39
+ }
40
+
41
+ // Define cross-CLI integration config
42
+ const crossCliConfig = {
43
+ cross_cli_enabled: true,
44
+ supported_clis: ['claude', 'gemini', 'qwen', 'iflow', 'qodercli', 'codebuddy', 'copilot', 'codex'],
45
+ auto_detect: true,
46
+ timeout: 30,
47
+ collaboration_mode: 'active',
48
+ claude_skills_integration: true,
49
+ claude_hooks_enabled: true
50
+ };
51
+
52
+ // Merge configs
53
+ const mergedConfig = { ...existingConfig, ...crossCliConfig };
54
+
55
+ // Write config file
56
+ await fs.writeFile(this.configFile, JSON.stringify(mergedConfig, null, 2));
57
+ console.log(`[OK] Claude config installed: ${this.configFile}`);
58
+ return true;
59
+ }
60
+
61
+ async installHooks() {
62
+ // Read existing hooks config
63
+ let existingHooks = {};
64
+ try {
65
+ const content = await fs.readFile(this.hooksFile, 'utf-8');
66
+ existingHooks = JSON.parse(content);
67
+ } catch (e) {
68
+ console.log(`Warning: Failed to read existing hooks config: ${e.message}`);
69
+ existingHooks = {};
70
+ }
71
+
72
+ // Define cross-CLI integration hooks
73
+ const crossCliHooks = {
74
+ cross_cli_adapter: {
75
+ enabled: true,
76
+ supported_tools: ['claude', 'gemini', 'qwen', 'iflow', 'qodercli', 'codebuddy', 'copilot', 'codex'],
77
+ trigger_patterns: [
78
+ 'use\\s+(\\w+)\\s+to\\s+(.+)$',
79
+ 'call\\s+(\\w+)\\s+(.+)$',
80
+ 'ask\\s+(\\w+)\\s+(.+)$',
81
+ 'stigmergy\\s+(\\w+)\\s+(.+)$'
82
+ ]
83
+ },
84
+ claude_skills: {
85
+ enabled: true,
86
+ auto_register: true,
87
+ cross_cli_aware: true
88
+ }
89
+ };
90
+
91
+ // Merge hooks configs
92
+ const mergedHooks = { ...existingHooks, ...crossCliHooks };
93
+
94
+ // Write hooks config file
95
+ await fs.writeFile(this.hooksFile, JSON.stringify(mergedHooks, null, 2));
96
+ console.log(`[OK] Claude hooks installed: ${this.hooksFile}`);
97
+ return true;
98
+ }
99
+
100
+ async copyAdapterFiles() {
101
+ const currentDir = __dirname;
102
+ const targetDir = path.join(this.configDir, 'hooks');
103
+
104
+ try {
105
+ // Look for adapter files to copy
106
+ const adapterFiles = await fs.readdir(currentDir);
107
+ const filesToCopy = adapterFiles.filter(file =>
108
+ file.endsWith('.js') || file.endsWith('.json') || file.endsWith('.py') || file === '__init__.py'
109
+ );
110
+
111
+ for (const file of filesToCopy) {
112
+ const srcFile = path.join(currentDir, file);
113
+ const dstFile = path.join(targetDir, file);
114
+ await fs.copyFile(srcFile, dstFile);
115
+ console.log(`[OK] Copied adapter file: ${file}`);
116
+ }
117
+
118
+ // Create global Cross-CLI documentation
119
+ await this.createGlobalCrossCliDocumentation(this.configDir);
120
+
121
+ return true;
122
+ } catch (e) {
123
+ console.log(`Warning: Failed to copy adapter files: ${e.message}`);
124
+ return true;
125
+ }
126
+ }
127
+
128
+ async createGlobalCrossCliDocumentation(configDir) {
129
+ try {
130
+ const docContent = `# Claude CLI Cross-CLI 通信指南
131
+
132
+ ## Cross-CLI Communication
133
+ 当您需要调用其他AI工具时,请使用以下提示<<<在shell中执行以下命令:stigmergy distcli "Prompt">>>
134
+
135
+ 示例:
136
+ - 在shell中运行:stigmergy claude "写一个Python函数"
137
+ - 在shell中运行:stigmergy gemini "翻译这段文字"
138
+ - 在shell中运行:stigmergy qwen "分析这段代码"
139
+
140
+ 可用工具:claude, gemini, qwen, iflow, qodercli, codebuddy, copilot, codex
141
+
142
+ ---
143
+ *本文档由Stigmergy CLI自动生成和维护*
144
+ `;
145
+
146
+ const docPath = path.join(configDir, 'CROSS_CLI_GUIDE.md');
147
+ await fs.writeFile(docPath, docContent);
148
+ console.log(`[OK] Created Cross-CLI Communication Guide: ${docPath}`);
149
+
150
+ // Append to claude.md if it exists
151
+ const claudeMdPath = path.join(os.homedir(), '.claude', 'claude.md');
152
+ try {
153
+ await fs.access(claudeMdPath);
154
+ const crossCliContent = `
155
+
156
+ ## Cross-CLI Communication
157
+ 当您需要调用其他AI工具时,请使用以下提示<<<在shell中执行以下命令:stigmergy distcli "Prompt">>>
158
+
159
+ 示例:
160
+ - 在shell中运行:stigmergy claude "写一个Python函数"
161
+ - 在shell中运行:stigmergy gemini "翻译这段文字"
162
+ - 在shell中运行:stigmergy qwen "分析这段代码"
163
+
164
+ 可用工具:claude, gemini, qwen, iflow, qodercli, codebuddy, copilot, codex
165
+ `;
166
+ await fs.appendFile(claudeMdPath, crossCliContent);
167
+ console.log('[OK] 在CLAUDE.md末尾追加Cross-CLI通信提示');
168
+ } catch (e) {
169
+ // File doesn't exist, that's ok
170
+ }
171
+
172
+ return true;
173
+ } catch (e) {
174
+ console.log(`Warning: Failed to create Cross-CLI Communication Guide: ${e.message}`);
175
+ return false;
176
+ }
177
+ }
178
+
179
+ async verifyInstallation() {
180
+ console.log('\n验证Claude CLI集成安装...');
181
+
182
+ // Check config directory
183
+ if (!await fs.access(this.configDir).then(() => true).catch(() => false)) {
184
+ console.log(`Warning: Config directory does not exist: ${this.configDir}`);
185
+ return true;
186
+ }
187
+
188
+ // Check config file content
189
+ try {
190
+ const content = await fs.readFile(this.configFile, 'utf-8');
191
+ const config = JSON.parse(content);
192
+
193
+ if (config.cross_cli_enabled) {
194
+ console.log('[OK] Cross-CLI integration enabled');
195
+ } else {
196
+ console.log('Note: Cross-CLI integration not enabled');
197
+ }
198
+
199
+ console.log('[OK] Claude config file verified');
200
+ return true;
201
+ } catch (e) {
202
+ console.log(`Warning: Failed to verify config file: ${e.message}`);
203
+ return true;
204
+ }
205
+ }
206
+
207
+ async uninstallIntegration() {
208
+ try {
209
+ // Remove cross-CLI config from config file
210
+ if (await fs.access(this.configFile).then(() => true).catch(() => false)) {
211
+ const content = await fs.readFile(this.configFile, 'utf-8');
212
+ const config = JSON.parse(content);
213
+
214
+ // Remove cross-CLI settings
215
+ delete config.cross_cli_enabled;
216
+ delete config.supported_clis;
217
+ delete config.auto_detect;
218
+ delete config.collaboration_mode;
219
+ delete config.claude_skills_integration;
220
+ delete config.claude_hooks_enabled;
221
+
222
+ // Save updated config
223
+ await fs.writeFile(this.configFile, JSON.stringify(config, null, 2));
224
+ console.log('[OK] Removed cross-CLI settings from Claude config');
225
+ }
226
+
227
+ // Remove hooks config file
228
+ if (await fs.access(this.hooksFile).then(() => true).catch(() => false)) {
229
+ await fs.unlink(this.hooksFile);
230
+ console.log('[OK] Removed Claude hooks config file');
231
+ }
232
+
233
+ console.log('[OK] Claude CLI cross-CLI integration uninstalled');
234
+ return true;
235
+ } catch (e) {
236
+ console.log(`Error: Uninstall failed: ${e.message}`);
237
+ return false;
238
+ }
239
+ }
240
+
241
+ async install() {
242
+ console.log('Claude CLI Integration Installer');
243
+ console.log('==========================================');
244
+
245
+ // Execute installation
246
+ console.log('Step 1. 创建配置目录...');
247
+ await this.createConfigDirectory();
248
+
249
+ console.log('\nStep 2. 安装配置...');
250
+ const configSuccess = await this.installConfig();
251
+
252
+ console.log('\nStep 3. 安装钩子...');
253
+ const hooksSuccess = await this.installHooks();
254
+
255
+ console.log('\nStep 4. 复制适配器文件...');
256
+ const adapterSuccess = await this.copyAdapterFiles();
257
+
258
+ console.log('\nStep 5. 验证安装...');
259
+ const verificationSuccess = await this.verifyInstallation();
260
+
261
+ const overallSuccess = configSuccess && hooksSuccess && adapterSuccess && verificationSuccess;
262
+ if (overallSuccess) {
263
+ console.log('\n[SUCCESS] Claude CLI integration installed successfully!');
264
+ } else {
265
+ console.log('\n[WARNING] Installation completed with warnings');
266
+ }
267
+
268
+ return overallSuccess;
269
+ }
270
+ }
271
+
272
+ // Main execution
273
+ if (require.main === module) {
274
+ const installer = new ClaudeInstaller();
275
+
276
+ const args = process.argv.slice(2);
277
+ const command = args[0];
278
+
279
+ switch (command) {
280
+ case '--verify':
281
+ installer.verifyInstallation().then(success => process.exit(success ? 0 : 1));
282
+ break;
283
+ case '--uninstall':
284
+ installer.uninstallIntegration().then(success => process.exit(success ? 0 : 1));
285
+ break;
286
+ default:
287
+ installer.install().then(success => process.exit(success ? 0 : 1));
288
+ break;
289
+ }
290
+ }
291
+
292
+ module.exports = ClaudeInstaller;
@@ -0,0 +1,349 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CodeBuddy CLI Skills集成安装脚本
5
+ * 为CodeBuddy CLI安装跨CLI协作感知能力
6
+ *
7
+ * 使用方法:
8
+ * node install_codebuddy_integration.js [--verify|--uninstall]
9
+ */
10
+
11
+ const fs = require('fs').promises;
12
+ const path = require('path');
13
+ const os = require('os');
14
+
15
+ // CodeBuddy CLI配置路径
16
+ const CODEBUDDY_CONFIG_DIR = path.join(os.homedir(), '.codebuddy');
17
+ const CODEBUDDY_CONFIG_FILE = path.join(CODEBUDDY_CONFIG_DIR, 'buddy_config.json');
18
+
19
+ class CodeBuddyIntegrationInstaller {
20
+ constructor() {
21
+ this.startTime = Date.now();
22
+ }
23
+
24
+ /**
25
+ * 创建CodeBuddy配置目录
26
+ */
27
+ async createCodeBuddyConfigDirectory() {
28
+ try {
29
+ await fs.mkdir(CODEBUDDY_CONFIG_DIR, { recursive: true });
30
+ console.log(`[OK] 创建CodeBuddy配置目录: ${CODEBUDDY_CONFIG_DIR}`);
31
+ return true;
32
+ } catch (error) {
33
+ console.log(`[ERROR] 创建CodeBuddy配置目录失败: ${error.message}`);
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * 安装CodeBuddy Skills配置
40
+ */
41
+ async installCodeBuddySkills() {
42
+ try {
43
+ // 读取现有buddy_config配置
44
+ let existingConfig = {};
45
+ try {
46
+ const data = await fs.readFile(CODEBUDDY_CONFIG_FILE, 'utf8');
47
+ existingConfig = JSON.parse(data);
48
+ } catch (error) {
49
+ console.log(`[WARN] 读取现有buddy_config配置失败: ${error.message}`);
50
+ existingConfig = {};
51
+ }
52
+
53
+ // 定义跨CLI协作的Skills配置
54
+ const crossCliSkills = {
55
+ cross_cli_skill: {
56
+ name: 'CrossCLICoordinationSkill',
57
+ description: 'Cross-CLI工具协调技能',
58
+ module: 'src.adapters.codebuddy.skills_hook_adapter',
59
+ class: 'CodeBuddySkillsHookAdapter',
60
+ enabled: true,
61
+ priority: 100,
62
+ triggers: [
63
+ 'on_skill_activation',
64
+ 'on_user_command'
65
+ ],
66
+ config: {
67
+ cross_cli_enabled: true,
68
+ supported_clis: ['claude', 'gemini', 'qwen', 'iflow', 'qoder', 'copilot'],
69
+ auto_route: true,
70
+ timeout: 30,
71
+ collaboration_mode: 'active'
72
+ }
73
+ }
74
+ };
75
+
76
+ // 合并配置(保留现有skills,添加协作功能)
77
+ const mergedConfig = { ...existingConfig };
78
+ if (!mergedConfig.skills) {
79
+ mergedConfig.skills = [];
80
+ }
81
+
82
+ // 检查是否已存在跨CLI协调技能
83
+ const existingSkillNames = mergedConfig.skills.map(skill => skill.name);
84
+ const crossCliSkillName = 'CrossCLICoordinationSkill';
85
+
86
+ if (!existingSkillNames.includes(crossCliSkillName)) {
87
+ mergedConfig.skills.push(crossCliSkills.cross_cli_skill);
88
+ }
89
+
90
+ // 写入配置文件
91
+ await fs.writeFile(CODEBUDDY_CONFIG_FILE, JSON.stringify(mergedConfig, null, 2), 'utf8');
92
+
93
+ console.log(`[OK] CodeBuddy配置已安装: ${CODEBUDDY_CONFIG_FILE}`);
94
+ console.log('已安装的Skills:');
95
+ mergedConfig.skills.forEach(skill => {
96
+ const status = skill.enabled ? '[OK]' : '[DISABLED]';
97
+ console.log(` - ${skill.name}: ${status}`);
98
+ });
99
+
100
+ return true;
101
+ } catch (error) {
102
+ console.log(`[ERROR] 安装CodeBuddy配置失败: ${error.message}`);
103
+ return false;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * 复制适配器文件到CodeBuddy配置目录
109
+ */
110
+ async copyAdapterFile() {
111
+ try {
112
+ // 创建适配器目录
113
+ await fs.mkdir(CODEBUDDY_CONFIG_DIR, { recursive: true });
114
+
115
+ // 获取当前脚本目录
116
+ const currentDir = __dirname;
117
+
118
+ // 复制适配器文件
119
+ const adapterFiles = [
120
+ 'skills_hook_adapter.js',
121
+ 'standalone_codebuddy_adapter.js'
122
+ ];
123
+
124
+ for (const fileName of adapterFiles) {
125
+ const srcFile = path.join(currentDir, fileName);
126
+ const dstFile = path.join(CODEBUDDY_CONFIG_DIR, fileName);
127
+
128
+ try {
129
+ await fs.access(srcFile);
130
+ await fs.copyFile(srcFile, dstFile);
131
+ console.log(`[OK] 复制适配器文件: ${fileName}`);
132
+ } catch (error) {
133
+ console.log(`[WARN] 适配器文件不存在: ${fileName}`);
134
+ // 不强制要求适配器文件
135
+ }
136
+ }
137
+
138
+ return true;
139
+ } catch (error) {
140
+ console.log(`[ERROR] 复制适配器文件失败: ${error.message}`);
141
+ return false;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * 验证安装是否成功
147
+ */
148
+ async verifyInstallation() {
149
+ console.log('\n验证CodeBuddy CLI集成安装...');
150
+
151
+ try {
152
+ // 检查配置文件
153
+ await fs.access(CODEBUDDY_CONFIG_FILE);
154
+
155
+ // 检查配置文件内容
156
+ const data = await fs.readFile(CODEBUDDY_CONFIG_FILE, 'utf8');
157
+ const config = JSON.parse(data);
158
+
159
+ // 检查是否存在跨CLI技能
160
+ const skills = config.skills || [];
161
+ const crossCliSkillFound = skills.some(skill => skill.name === 'CrossCLICoordinationSkill');
162
+
163
+ if (crossCliSkillFound) {
164
+ console.log('[OK] 跨CLI协调技能已安装');
165
+ } else {
166
+ console.log('[WARN] 未找到跨CLI协调技能');
167
+ }
168
+
169
+ console.log('[OK] CodeBuddy配置文件验证通过');
170
+ return true;
171
+ } catch (error) {
172
+ console.log(`[ERROR] 配置文件验证失败: ${error.message}`);
173
+ return false;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * 卸载CodeBuddy集成
179
+ */
180
+ async uninstallIntegration() {
181
+ try {
182
+ // 从配置文件中移除跨CLI技能
183
+ try {
184
+ const data = await fs.readFile(CODEBUDDY_CONFIG_FILE, 'utf8');
185
+ const config = JSON.parse(data);
186
+
187
+ // 移除跨CLI技能
188
+ let skills = config.skills || [];
189
+ skills = skills.filter(skill => skill.name !== 'CrossCLICoordinationSkill');
190
+ config.skills = skills;
191
+
192
+ // 保存更新后的配置
193
+ await fs.writeFile(CODEBUDDY_CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
194
+
195
+ console.log('[OK] 已从CodeBuddy配置中移除跨CLI协调技能');
196
+ } catch (error) {
197
+ console.log(`[WARN] 处理配置文件失败: ${error.message}`);
198
+ }
199
+
200
+ // 删除适配器文件
201
+ const adapterFiles = [
202
+ 'skills_hook_adapter.js',
203
+ 'standalone_codebuddy_adapter.js'
204
+ ];
205
+
206
+ for (const fileName of adapterFiles) {
207
+ const adapterFile = path.join(CODEBUDDY_CONFIG_DIR, fileName);
208
+ try {
209
+ await fs.unlink(adapterFile);
210
+ console.log(`[OK] 已删除适配器文件: ${fileName}`);
211
+ } catch (error) {
212
+ // 文件可能不存在,忽略错误
213
+ }
214
+ }
215
+
216
+ console.log('[OK] CodeBuddy CLI跨CLI集成已卸载');
217
+ return true;
218
+ } catch (error) {
219
+ console.log(`[ERROR] 卸载失败: ${error.message}`);
220
+ return false;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * 创建全局Cross-CLI通信文档
226
+ */
227
+ async createGlobalCrossCliDocumentation() {
228
+ try {
229
+ const docContent = `# CodeBuddy CLI 跨CLI通信指南
230
+
231
+ ## Cross-CLI Communication
232
+ 当您需要调用其他AI工具时,请使用以下提示<<<在shell中执行以下命令:stigmergy <工具名> <任务描述>>>>
233
+
234
+ 示例:
235
+ - 在shell中运行:stigmergy claude "写一个Python函数"
236
+ - 在shell中运行:stigmergy gemini "翻译这段文字"
237
+ - 在shell中运行:stigmergy qwen "分析这段代码"
238
+
239
+ 可用工具:claude, gemini, qwen, iflow, qodercli, codebuddy, copilot, codex
240
+
241
+ ---
242
+ *本文档由Stigmergy CLI自动生成和维护*
243
+ `;
244
+
245
+ const docPath = path.join(CODEBUDDY_CONFIG_DIR, 'CROSS_CLI_GUIDE.md');
246
+ await fs.writeFile(docPath, docContent, 'utf8');
247
+ console.log(`[OK] 创建Cross-CLI通信指南: ${docPath}`);
248
+
249
+ // 如果存在codebuddy.md文件,则在末尾追加Cross-CLI通信提示
250
+ const codebuddyMdPath = path.join(os.homedir(), '.codebuddy', 'codebuddy.md');
251
+ try {
252
+ await fs.access(codebuddyMdPath);
253
+
254
+ const crossCliContent = `
255
+
256
+ ## Cross-CLI Communication
257
+ 当您需要调用其他AI工具时,请使用以下提示<<<在shell中执行以下命令:stigmergy <工具名> <任务描述>>>>
258
+
259
+ 示例:
260
+ - 在shell中运行:stigmergy claude "写一个Python函数"
261
+ - 在shell中运行:stigmergy gemini "翻译这段文字"
262
+ - 在shell中运行:stigmergy qwen "分析这段代码"
263
+
264
+ 可用工具:claude, gemini, qwen, iflow, qodercli, codebuddy, copilot, codex
265
+ `;
266
+ await fs.appendFile(codebuddyMdPath, crossCliContent, 'utf8');
267
+ console.log('[OK] 在CODEBUDDY.md末尾追加Cross-CLI通信提示');
268
+ } catch (error) {
269
+ // 文件可能不存在,忽略
270
+ }
271
+
272
+ return true;
273
+ } catch (error) {
274
+ console.log(`[WARN] 创建Cross-CLI通信指南失败: ${error.message}`);
275
+ return false;
276
+ }
277
+ }
278
+
279
+ /**
280
+ * 主安装流程
281
+ */
282
+ async install() {
283
+ console.log('CodeBuddy CLI跨CLI集成安装程序');
284
+ console.log('='.repeat(50));
285
+
286
+ // 步骤1. 创建配置目录
287
+ console.log('\n步骤1. 创建配置目录...');
288
+ const configDirSuccess = await this.createCodeBuddyConfigDirectory();
289
+
290
+ // 步骤2. 安装Skills配置
291
+ console.log('\n步骤2. 安装Skills配置...');
292
+ const skillsSuccess = await this.installCodeBuddySkills();
293
+
294
+ // 步骤3. 复制适配器文件
295
+ console.log('\n步骤3. 复制适配器文件...');
296
+ const adapterSuccess = await this.copyAdapterFile();
297
+
298
+ // 步骤4. 创建Cross-CLI通信指南
299
+ console.log('\n步骤4. 创建Cross-CLI通信指南...');
300
+ const guideSuccess = await this.createGlobalCrossCliDocumentation();
301
+
302
+ // 步骤5. 验证安装
303
+ console.log('\n步骤5. 验证安装...');
304
+ const verificationSuccess = await this.verifyInstallation();
305
+
306
+ const overallSuccess = configDirSuccess && skillsSuccess && adapterSuccess && guideSuccess && verificationSuccess;
307
+
308
+ const duration = Date.now() - this.startTime;
309
+ console.log(`\n[INFO] 安装耗时: ${duration}ms`);
310
+
311
+ if (overallSuccess) {
312
+ console.log('\n[SUCCESS] CodeBuddy CLI跨CLI集成安装成功!');
313
+ } else {
314
+ console.log('\n[WARNING] 安装过程中出现警告,请检查上述输出');
315
+ }
316
+
317
+ return overallSuccess;
318
+ }
319
+ }
320
+
321
+ // 主函数
322
+ async function main() {
323
+ const args = process.argv.slice(2);
324
+ const verify = args.includes('--verify');
325
+ const uninstall = args.includes('--uninstall');
326
+
327
+ const installer = new CodeBuddyIntegrationInstaller();
328
+
329
+ if (uninstall) {
330
+ return await installer.uninstallIntegration();
331
+ } else if (verify) {
332
+ return await installer.verifyInstallation();
333
+ } else {
334
+ return await installer.install();
335
+ }
336
+ }
337
+
338
+ // 导出模块
339
+ module.exports = CodeBuddyIntegrationInstaller;
340
+
341
+ // 如果直接运行此脚本
342
+ if (require.main === module) {
343
+ main().then(success => {
344
+ process.exit(success ? 0 : 1);
345
+ }).catch(error => {
346
+ console.error('[FATAL]', error.message);
347
+ process.exit(1);
348
+ });
349
+ }