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/enhanced-main.js
DELETED
|
@@ -1,626 +0,0 @@
|
|
|
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
|
-
// 处理 --help 参数和全局help
|
|
280
|
-
if (!command || command === '--help' || command === '-h') {
|
|
281
|
-
await this.showHelp();
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
switch (command) {
|
|
286
|
-
case 'scan':
|
|
287
|
-
if (args[1] === '--help' || args[1] === '-h') {
|
|
288
|
-
console.log('scan - 扫描本地AI CLI工具环境并提供安装建议');
|
|
289
|
-
console.log('用法: stigmergy scan');
|
|
290
|
-
console.log('描述: 自动检测系统中已安装的AI CLI工具,提供安装建议');
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
const { missingTools } = await this.scanLocalEnvironment();
|
|
294
|
-
if (missingTools.length > 0) {
|
|
295
|
-
await this.interactiveInstall(missingTools);
|
|
296
|
-
}
|
|
297
|
-
break;
|
|
298
|
-
|
|
299
|
-
case 'install':
|
|
300
|
-
if (args[1] === '--help' || args[1] === '-h') {
|
|
301
|
-
console.log('install - 安装Stigmergy CLI系统');
|
|
302
|
-
console.log('用法: stigmergy install');
|
|
303
|
-
console.log('描述: 全局安装Stigmergy CLI到系统中');
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
console.log('📥 安装Stigmergy CLI系统...');
|
|
307
|
-
await this.installStigmergyGlobally();
|
|
308
|
-
break;
|
|
309
|
-
|
|
310
|
-
case 'deploy':
|
|
311
|
-
if (args[1] === '--help' || args[1] === '-h') {
|
|
312
|
-
console.log('deploy - 部署适配器到各个CLI工具');
|
|
313
|
-
console.log('用法: stigmergy deploy');
|
|
314
|
-
console.log('描述: 部署Stigmergy适配器到各个AI CLI工具的配置目录');
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
await this.deployAdapters();
|
|
318
|
-
break;
|
|
319
|
-
|
|
320
|
-
case 'init':
|
|
321
|
-
const projectPath = args[1] || process.cwd();
|
|
322
|
-
await this.initProject(projectPath);
|
|
323
|
-
break;
|
|
324
|
-
|
|
325
|
-
case 'status':
|
|
326
|
-
await this.checkStatus();
|
|
327
|
-
break;
|
|
328
|
-
|
|
329
|
-
case 'validate':
|
|
330
|
-
const scope = args[1] || 'project';
|
|
331
|
-
await this.validateConfiguration(scope);
|
|
332
|
-
break;
|
|
333
|
-
|
|
334
|
-
case 'check-project':
|
|
335
|
-
const checkPath = args[1] || process.cwd();
|
|
336
|
-
await this.checkProject(checkPath);
|
|
337
|
-
break;
|
|
338
|
-
|
|
339
|
-
case 'clean':
|
|
340
|
-
await this.cleanCache();
|
|
341
|
-
break;
|
|
342
|
-
|
|
343
|
-
default:
|
|
344
|
-
await this.showHelp();
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 全局安装方法
|
|
350
|
-
async installStigmergyGlobally() {
|
|
351
|
-
try {
|
|
352
|
-
const { spawn } = await import('child_process');
|
|
353
|
-
|
|
354
|
-
await new Promise((resolve, reject) => {
|
|
355
|
-
const installProcess = spawn('npm', ['install', '-g', '.'], {
|
|
356
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
357
|
-
shell: true,
|
|
358
|
-
cwd: process.cwd()
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
let output = '';
|
|
362
|
-
installProcess.stdout.on('data', (data) => {
|
|
363
|
-
output += data.toString();
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
installProcess.stderr.on('data', (data) => {
|
|
367
|
-
const stderr = data.toString();
|
|
368
|
-
if (!stderr.includes('WARN')) {
|
|
369
|
-
output += stderr;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
installProcess.on('close', (code) => {
|
|
374
|
-
if (code === 0) {
|
|
375
|
-
console.log('✅ Stigmergy CLI 全局安装完成!');
|
|
376
|
-
console.log('现在可以在任何目录运行: stigmergy <command>');
|
|
377
|
-
resolve();
|
|
378
|
-
} else {
|
|
379
|
-
console.error('❌ 全局安装失败');
|
|
380
|
-
reject(new Error('Installation failed'));
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
} catch (error) {
|
|
385
|
-
console.error('❌ 全局安装出错:', error.message);
|
|
386
|
-
throw error;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// 项目初始化方法
|
|
391
|
-
async initProject(projectPath) {
|
|
392
|
-
try {
|
|
393
|
-
console.log(`🚀 初始化Stigmergy项目: ${projectPath}`);
|
|
394
|
-
|
|
395
|
-
// 创建项目配置目录
|
|
396
|
-
const configDir = join(projectPath, '.stigmergy-project');
|
|
397
|
-
await fs.mkdir(configDir, { recursive: true });
|
|
398
|
-
|
|
399
|
-
// 扫描环境
|
|
400
|
-
await this.scanLocalEnvironment();
|
|
401
|
-
|
|
402
|
-
// 生成项目配置
|
|
403
|
-
const config = {
|
|
404
|
-
projectType: 'initialized',
|
|
405
|
-
createdAt: new Date().toISOString(),
|
|
406
|
-
adapters: AI_TOOLS.map(tool => ({
|
|
407
|
-
name: tool.name,
|
|
408
|
-
version: '1.0.0',
|
|
409
|
-
integrationType: 'cli',
|
|
410
|
-
status: 'available'
|
|
411
|
-
}))
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
const configPath = join(configDir, 'stigmergy-config.json');
|
|
415
|
-
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
416
|
-
|
|
417
|
-
console.log('✅ 项目初始化完成!');
|
|
418
|
-
console.log(`📁 配置文件: ${configPath}`);
|
|
419
|
-
|
|
420
|
-
} catch (error) {
|
|
421
|
-
console.error('❌ 项目初始化失败:', error.message);
|
|
422
|
-
throw error;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// 状态检查方法
|
|
427
|
-
async checkStatus() {
|
|
428
|
-
try {
|
|
429
|
-
console.log('🔍 检查Stigmergy CLI状态...');
|
|
430
|
-
|
|
431
|
-
// 检查全局配置
|
|
432
|
-
const globalConfigPath = join(homedir(), '.stigmergy-cli', 'global-config.json');
|
|
433
|
-
let globalConfig = null;
|
|
434
|
-
try {
|
|
435
|
-
const globalConfigData = await fs.readFile(globalConfigPath, 'utf8');
|
|
436
|
-
globalConfig = JSON.parse(globalConfigData);
|
|
437
|
-
} catch (e) {
|
|
438
|
-
console.log('⚠️ 全局配置不存在');
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
console.log('\n📊 全局配置:');
|
|
442
|
-
if (globalConfig) {
|
|
443
|
-
console.log(` 仓库: ${globalConfig.repository || 'undefined'}`);
|
|
444
|
-
console.log(` 版本: ${globalConfig.version || '1.0.0'}`);
|
|
445
|
-
console.log(` 最后更新: ${globalConfig.lastUpdated || 'undefined'}`);
|
|
446
|
-
} else {
|
|
447
|
-
console.log(' 状态: 未配置');
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// 检查项目配置
|
|
451
|
-
const projectConfigPath = join(process.cwd(), '.stigmergy-project', 'stigmergy-config.json');
|
|
452
|
-
let projectConfig = null;
|
|
453
|
-
try {
|
|
454
|
-
const projectConfigData = await fs.readFile(projectConfigPath, 'utf8');
|
|
455
|
-
projectConfig = JSON.parse(projectConfigData);
|
|
456
|
-
} catch (e) {
|
|
457
|
-
console.log('⚠️ 项目配置不存在');
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
console.log('\n📁 项目配置:');
|
|
461
|
-
if (projectConfig) {
|
|
462
|
-
console.log(` 类型: ${projectConfig.projectType || 'unknown'}`);
|
|
463
|
-
console.log(` 创建时间: ${projectConfig.createdAt || 'unknown'}`);
|
|
464
|
-
if (projectConfig.adapters) {
|
|
465
|
-
const availableTools = projectConfig.adapters
|
|
466
|
-
.filter(a => a.status === 'available')
|
|
467
|
-
.map(a => a.name)
|
|
468
|
-
.join(', ');
|
|
469
|
-
console.log(` 可用工具: ${availableTools}`);
|
|
470
|
-
}
|
|
471
|
-
} else {
|
|
472
|
-
console.log(' 状态: 未初始化');
|
|
473
|
-
console.log(' 💡 提示: 运行 stigmergy init 初始化项目');
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
} catch (error) {
|
|
477
|
-
console.error('❌ 状态检查失败:', error.message);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// 配置验证方法
|
|
482
|
-
async validateConfiguration(scope = 'project') {
|
|
483
|
-
try {
|
|
484
|
-
console.log(`🔍 验证 ${scope} 配置...`);
|
|
485
|
-
|
|
486
|
-
if (scope === 'project') {
|
|
487
|
-
const projectConfigPath = join(process.cwd(), '.stigmergy-project', 'stigmergy-config.json');
|
|
488
|
-
try {
|
|
489
|
-
const configData = await fs.readFile(projectConfigPath, 'utf8');
|
|
490
|
-
const config = JSON.parse(configData);
|
|
491
|
-
|
|
492
|
-
console.log('✅ 项目配置验证通过');
|
|
493
|
-
console.log(`📊 项目类型: ${config.projectType}`);
|
|
494
|
-
console.log(`📅 创建时间: ${config.createdAt}`);
|
|
495
|
-
|
|
496
|
-
if (config.adapters) {
|
|
497
|
-
console.log(`🔧 适配器数量: ${config.adapters.length}`);
|
|
498
|
-
}
|
|
499
|
-
} catch (error) {
|
|
500
|
-
console.log('⚠️ 项目配置验证失败或不存在');
|
|
501
|
-
console.log('💡 提示: 使用 stigmergy init 初始化项目配置');
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
} else if (scope === 'global') {
|
|
505
|
-
const globalConfigPath = join(homedir(), '.stigmergy-cli', 'global-config.json');
|
|
506
|
-
try {
|
|
507
|
-
const configData = await fs.readFile(globalConfigPath, 'utf8');
|
|
508
|
-
JSON.parse(configData);
|
|
509
|
-
console.log('✅ 全局配置验证通过');
|
|
510
|
-
} catch (error) {
|
|
511
|
-
console.log('⚠️ 全局配置验证失败或不存在');
|
|
512
|
-
console.log('💡 提示: 使用 stigmergy deploy 部署全局配置');
|
|
513
|
-
return false;
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
console.log('⚠️ 未知的验证范围,使用 "project" 或 "global"');
|
|
517
|
-
return false;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return true;
|
|
521
|
-
} catch (error) {
|
|
522
|
-
console.error('❌ 配置验证出错:', error.message);
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// 项目检查方法
|
|
528
|
-
async checkProject(projectPath = process.cwd()) {
|
|
529
|
-
try {
|
|
530
|
-
console.log(`🔍 检查项目配置: ${projectPath}`);
|
|
531
|
-
|
|
532
|
-
const configPath = join(projectPath, '.stigmergy-project', 'stigmergy-config.json');
|
|
533
|
-
try {
|
|
534
|
-
const configData = await fs.readFile(configPath, 'utf8');
|
|
535
|
-
const config = JSON.parse(configData);
|
|
536
|
-
|
|
537
|
-
console.log('✅ 项目配置有效');
|
|
538
|
-
console.log(`📊 项目类型: ${config.projectType}`);
|
|
539
|
-
console.log(`📅 创建时间: ${config.createdAt}`);
|
|
540
|
-
|
|
541
|
-
if (config.adapters) {
|
|
542
|
-
console.log('\n🤖 可用适配器:');
|
|
543
|
-
config.adapters.forEach(adapter => {
|
|
544
|
-
const status = adapter.status === 'available' ? '✅' : '❌';
|
|
545
|
-
console.log(` ${status} ${adapter.name} v${adapter.version} (${adapter.integrationType})`);
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
} catch (error) {
|
|
550
|
-
console.log('❌ 项目配置无效或不存在');
|
|
551
|
-
console.log('💡 提示: 运行 stigmergy init 初始化项目');
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
} catch (error) {
|
|
555
|
-
console.error('❌ 项目检查失败:', error.message);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// 缓存清理方法
|
|
560
|
-
async cleanCache() {
|
|
561
|
-
try {
|
|
562
|
-
console.log('🧹 清理缓存和临时文件...');
|
|
563
|
-
|
|
564
|
-
// 清理可能的缓存目录
|
|
565
|
-
const cacheDirs = [
|
|
566
|
-
join(homedir(), '.stigmergy-cli', 'cache'),
|
|
567
|
-
join(process.cwd(), '.stigmergy-project', 'cache'),
|
|
568
|
-
join(process.cwd(), 'node_modules', '.cache')
|
|
569
|
-
];
|
|
570
|
-
|
|
571
|
-
let cleanedCount = 0;
|
|
572
|
-
for (const cacheDir of cacheDirs) {
|
|
573
|
-
try {
|
|
574
|
-
await fs.access(cacheDir);
|
|
575
|
-
await fs.rm(cacheDir, { recursive: true, force: true });
|
|
576
|
-
console.log(`✅ 已清理: ${cacheDir}`);
|
|
577
|
-
cleanedCount++;
|
|
578
|
-
} catch (e) {
|
|
579
|
-
// 目录不存在,跳过
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
if (cleanedCount === 0) {
|
|
584
|
-
console.log('✅ 没有发现需要清理的缓存文件');
|
|
585
|
-
} else {
|
|
586
|
-
console.log(`✅ 已清理 ${cleanedCount} 个缓存目录`);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
} catch (error) {
|
|
590
|
-
console.error('❌ 缓存清理失败:', error.message);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
async showHelp() {
|
|
595
|
-
console.log(`
|
|
596
|
-
🤖 Stigmergy CLI v1.0.0 - Multi-Agents跨AI CLI工具协作系统
|
|
597
|
-
|
|
598
|
-
📚 可用命令:
|
|
599
|
-
init [path] - 初始化项目(默认当前目录)
|
|
600
|
-
scan - 扫描环境AI CLI工具状态
|
|
601
|
-
deploy - 部署适配器到本地配置
|
|
602
|
-
status - 检查系统和适配器状态
|
|
603
|
-
validate [scope] - 验证配置 (project/global)
|
|
604
|
-
check-project [path] - 检查项目配置
|
|
605
|
-
clean [options] - 清理缓存和临时文件
|
|
606
|
-
install - 安装所有AI CLI工具适配器
|
|
607
|
-
|
|
608
|
-
💡 快速开始:
|
|
609
|
-
stigmergy init # 初始化当前项目
|
|
610
|
-
stigmergy deploy # 一键部署
|
|
611
|
-
stigmergy status # 查看状态
|
|
612
|
-
|
|
613
|
-
🚀 快速部署:
|
|
614
|
-
npx -y git+https://github.com/ptreezh/stigmergy-CLI-Multi-Agents.git#main quick-deploy
|
|
615
|
-
|
|
616
|
-
📖 文档: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents#readme
|
|
617
|
-
`);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// 运行CLI
|
|
622
|
-
const cli = new EnhancedStigmergyCLI();
|
|
623
|
-
cli.run().catch(error => {
|
|
624
|
-
console.error('❌ 程序运行出错:', error.message);
|
|
625
|
-
process.exit(1);
|
|
626
|
-
});
|