stigmergy 1.0.60 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stigmergy",
3
- "version": "1.0.60",
3
+ "version": "1.0.61",
4
4
  "type": "module",
5
5
  "description": "Stigmergy CLI - Multi-Agents跨AI CLI工具协作系统",
6
6
  "main": "src/main.js",
@@ -74,11 +74,101 @@ class EnhancedStigmergyCLI {
74
74
 
75
75
  async checkToolAvailable(toolName) {
76
76
  try {
77
- const result = spawnSync(process.platform === 'win32' ? 'where' : 'which', [toolName], {
78
- stdio: 'pipe',
79
- encoding: 'utf-8'
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();
80
171
  });
81
- return result.status === 0 && result.stdout.trim() !== '';
82
172
  } catch (error) {
83
173
  return false;
84
174
  }
@@ -91,8 +181,15 @@ class EnhancedStigmergyCLI {
91
181
  const availableTools = [];
92
182
  const missingTools = [];
93
183
 
94
- for (const tool of AI_TOOLS) {
184
+ // 并行检测所有工具以提高性能
185
+ const detectionPromises = AI_TOOLS.map(async (tool) => {
95
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 }) => {
96
193
  if (isAvailable) {
97
194
  availableTools.push(tool);
98
195
  console.log(`✅ ${tool.displayName} - 已安装`);
@@ -101,11 +198,19 @@ class EnhancedStigmergyCLI {
101
198
  const status = tool.required ? '❌ (必需)' : '⚠️ (可选)';
102
199
  console.log(`${status} ${tool.displayName} - 未安装`);
103
200
  }
104
- }
201
+ });
105
202
 
106
203
  console.log('');
107
204
  console.log(`📊 扫描结果: ${availableTools.length} 个工具已安装, ${missingTools.length} 个工具缺失`);
108
205
 
206
+ // 显示一些调试信息帮助用户理解
207
+ if (availableTools.length === 0) {
208
+ console.log('💡 提示: 如果您确信已安装某些工具但未被检测到,可能是因为:');
209
+ console.log(' • 工具命令名称与我们检测的名称不同');
210
+ console.log(' • 工具未添加到系统PATH环境变量');
211
+ console.log(' • 工具需要特殊的方式检测版本');
212
+ }
213
+
109
214
  return { availableTools, missingTools };
110
215
  }
111
216