stigmergy 1.0.98 → 1.1.0
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.md +17 -0
- package/bin/stigmergy +1 -1
- package/bin/stigmergy.cmd +1 -1
- package/docs/NATIVE_INTEGRATION_GUIDE.md +1155 -1190
- package/docs/PROJECT_STRUCTURE.md +283 -303
- package/package.json +10 -7
- package/src/cli/router.js +460 -0
- package/src/core/cli_help_analyzer.js +3 -3
- package/src/core/coordination/index.js +16 -0
- package/src/core/coordination/nodejs/AdapterManager.js +89 -0
- package/src/core/coordination/nodejs/CLCommunication.js +59 -0
- package/src/core/coordination/nodejs/CLIIntegrationManager.js +236 -0
- package/src/core/coordination/nodejs/HealthChecker.js +77 -0
- package/src/core/coordination/nodejs/HookDeploymentManager.js +256 -0
- package/src/core/coordination/nodejs/StatisticsCollector.js +71 -0
- package/src/core/coordination/nodejs/index.js +72 -0
- package/src/core/coordination/nodejs/utils/Logger.js +29 -0
- package/src/core/installer.js +374 -0
- package/src/core/smart_router.js +3 -3
- package/src/data_structures.js +3 -3
- package/src/deploy.js +1 -2
- package/src/index.js +25 -4
- package/src/main.js +1067 -830
- package/src/utils/helpers.js +35 -0
- package/src/utils.js +1 -2
- package/test/cross-cli-detection-test.js +33 -0
- package/test/python-plugins-test.js +259 -0
- package/test/remaining-adapters-test.js +256 -0
- package/test/system-compatibility-test.js +466 -446
- package/test/tool-selection-integration-test.js +157 -156
- package/src/main_english.js +0 -1421
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const inquirer = require('inquirer');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
const fs = require('fs/promises');
|
|
8
|
+
const fsSync = require('fs');
|
|
9
|
+
|
|
10
|
+
// Import our custom modules
|
|
11
|
+
const SmartRouter = require('../core/smart_router');
|
|
12
|
+
const CLIHelpAnalyzer = require('../core/cli_help_analyzer');
|
|
13
|
+
const { CLI_TOOLS } = require('../core/cli_tools');
|
|
14
|
+
const { errorHandler } = require('../core/error_handler');
|
|
15
|
+
const { executeCommand, executeJSFile } = require('../utils');
|
|
16
|
+
const { UserAuthenticator } = require('../auth');
|
|
17
|
+
const MemoryManager = require('../core/memory_manager');
|
|
18
|
+
const StigmergyInstaller = require('../core/installer');
|
|
19
|
+
const { maxOfTwo, isAuthenticated } = require('../utils/helpers');
|
|
20
|
+
|
|
21
|
+
// Set up global error handlers using our error handler module
|
|
22
|
+
const { setupGlobalErrorHandlers } = require('../core/error_handler');
|
|
23
|
+
setupGlobalErrorHandlers();
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
|
|
28
|
+
// Debug mode
|
|
29
|
+
if (process.env.DEBUG === 'true') {
|
|
30
|
+
console.log('[DEBUG] Main function called with args:', process.argv);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Create instances
|
|
34
|
+
const memory = new MemoryManager();
|
|
35
|
+
const installer = new StigmergyInstaller();
|
|
36
|
+
|
|
37
|
+
// Handle help command early
|
|
38
|
+
if (
|
|
39
|
+
args.length === 0 ||
|
|
40
|
+
args.includes('-h') ||
|
|
41
|
+
args.includes('--help') ||
|
|
42
|
+
args.includes('help')
|
|
43
|
+
) {
|
|
44
|
+
console.log('Stigmergy CLI - Multi-Agents Cross-AI CLI Tools Collaboration System');
|
|
45
|
+
console.log('=====================================================================');
|
|
46
|
+
console.log('');
|
|
47
|
+
console.log('Usage: stigmergy <command> [options]');
|
|
48
|
+
console.log('');
|
|
49
|
+
console.log('Commands:');
|
|
50
|
+
console.log(' help, --help Show this help message');
|
|
51
|
+
console.log(' version, --version Show version information');
|
|
52
|
+
console.log(' status Check CLI tools status');
|
|
53
|
+
console.log(' scan Scan for available AI CLI tools');
|
|
54
|
+
console.log(' install Auto-install missing CLI tools');
|
|
55
|
+
console.log(
|
|
56
|
+
' deploy Deploy hooks and integration to installed tools',
|
|
57
|
+
);
|
|
58
|
+
console.log(' setup Complete setup and configuration');
|
|
59
|
+
console.log(
|
|
60
|
+
' init Initialize Stigmergy configuration (alias for setup)',
|
|
61
|
+
);
|
|
62
|
+
console.log(' call "<prompt>" Execute prompt with auto-routed AI CLI');
|
|
63
|
+
console.log(' errors Display error report and statistics');
|
|
64
|
+
console.log('');
|
|
65
|
+
console.log('[WORKFLOW] Automated Workflow:');
|
|
66
|
+
console.log(' 1. npm install -g stigmergy # Install Stigmergy');
|
|
67
|
+
console.log(
|
|
68
|
+
' 2. stigmergy install # Auto-scan & install CLI tools',
|
|
69
|
+
);
|
|
70
|
+
console.log(' 3. stigmergy setup # Deploy hooks & config');
|
|
71
|
+
console.log(' 4. stigmergy call "<prompt>" # Start collaborating');
|
|
72
|
+
console.log('');
|
|
73
|
+
console.log(
|
|
74
|
+
'For more information, visit: https://github.com/ptreezh/stigmergy-CLI-Multi-Agents',
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const command = args[0];
|
|
80
|
+
|
|
81
|
+
switch (command) {
|
|
82
|
+
case 'version':
|
|
83
|
+
case '--version': {
|
|
84
|
+
// Use the version from configuration instead of hardcoding
|
|
85
|
+
const config = {
|
|
86
|
+
version: '1.0.94',
|
|
87
|
+
initialized: true,
|
|
88
|
+
createdAt: new Date().toISOString(),
|
|
89
|
+
lastUpdated: new Date().toISOString(),
|
|
90
|
+
defaultCLI: 'claude',
|
|
91
|
+
enableCrossCLI: true,
|
|
92
|
+
enableMemory: true,
|
|
93
|
+
};
|
|
94
|
+
console.log(`Stigmergy CLI v${config.version}`);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
case 'errors':
|
|
99
|
+
try {
|
|
100
|
+
console.log('[ERRORS] Generating Stigmergy CLI error report...\n');
|
|
101
|
+
await errorHandler.printErrorReport();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(
|
|
104
|
+
'[ERROR] Failed to generate error report:',
|
|
105
|
+
error.message,
|
|
106
|
+
);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'init':
|
|
112
|
+
// Alias for setup command
|
|
113
|
+
console.log('[INIT] Initializing Stigmergy CLI...');
|
|
114
|
+
// Fall through to setup case
|
|
115
|
+
|
|
116
|
+
case 'setup':
|
|
117
|
+
try {
|
|
118
|
+
console.log('[SETUP] Starting complete Stigmergy setup...\n');
|
|
119
|
+
|
|
120
|
+
// Step 1: Download required assets
|
|
121
|
+
await installer.downloadRequiredAssets();
|
|
122
|
+
|
|
123
|
+
// Step 2: Scan for CLI tools
|
|
124
|
+
const { available: setupAvailable, missing: setupMissing } =
|
|
125
|
+
await installer.scanCLI();
|
|
126
|
+
const setupOptions = await installer.showInstallOptions(setupMissing);
|
|
127
|
+
|
|
128
|
+
// Step 3: Install missing CLI tools if user chooses
|
|
129
|
+
if (setupOptions.length > 0) {
|
|
130
|
+
const selectedTools = await installer.getUserSelection(
|
|
131
|
+
setupOptions,
|
|
132
|
+
setupMissing,
|
|
133
|
+
);
|
|
134
|
+
if (selectedTools.length > 0) {
|
|
135
|
+
console.log(
|
|
136
|
+
'\n[INFO] Installing selected tools (this may take several minutes for tools that download binaries)...',
|
|
137
|
+
);
|
|
138
|
+
await installer.installTools(selectedTools, setupMissing);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
console.log('\n[INFO] All required tools are already installed!');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Step 4: Deploy hooks to available CLI tools
|
|
145
|
+
await installer.deployHooks(setupAvailable);
|
|
146
|
+
|
|
147
|
+
// Step 5: Deploy project documentation
|
|
148
|
+
await installer.deployProjectDocumentation();
|
|
149
|
+
|
|
150
|
+
// Step 6: Initialize configuration
|
|
151
|
+
await installer.initializeConfig();
|
|
152
|
+
|
|
153
|
+
// Step 7: Show usage instructions
|
|
154
|
+
installer.showUsageInstructions();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
await errorHandler.logError(error, 'ERROR', 'main.setup');
|
|
157
|
+
console.log(`[ERROR] Setup failed: ${error.message}`);
|
|
158
|
+
console.log('\n[TROUBLESHOOTING] To manually complete setup:');
|
|
159
|
+
console.log('1. Run: stigmergy deploy # Deploy hooks manually');
|
|
160
|
+
console.log('2. Run: stigmergy setup # Try setup again');
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
|
|
165
|
+
case 'status':
|
|
166
|
+
try {
|
|
167
|
+
const { available, missing } = await installer.scanCLI();
|
|
168
|
+
console.log('\n[STATUS] AI CLI Tools Status Report');
|
|
169
|
+
console.log('=====================================');
|
|
170
|
+
|
|
171
|
+
if (Object.keys(available).length > 0) {
|
|
172
|
+
console.log('\n✅ Available Tools:');
|
|
173
|
+
for (const [toolName, toolInfo] of Object.entries(available)) {
|
|
174
|
+
console.log(` - ${toolInfo.name} (${toolName})`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (Object.keys(missing).length > 0) {
|
|
179
|
+
console.log('\n❌ Missing Tools:');
|
|
180
|
+
for (const [toolName, toolInfo] of Object.entries(missing)) {
|
|
181
|
+
console.log(` - ${toolInfo.name} (${toolName})`);
|
|
182
|
+
console.log(` Install command: ${toolInfo.install}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(
|
|
187
|
+
`\n[SUMMARY] ${Object.keys(available).length} available, ${Object.keys(missing).length} missing`,
|
|
188
|
+
);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
await errorHandler.logError(error, 'ERROR', 'main.status');
|
|
191
|
+
console.log(`[ERROR] Failed to get status: ${error.message}`);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
|
|
196
|
+
case 'scan':
|
|
197
|
+
try {
|
|
198
|
+
await installer.scanCLI();
|
|
199
|
+
} catch (error) {
|
|
200
|
+
await errorHandler.logError(error, 'ERROR', 'main.scan');
|
|
201
|
+
console.log(`[ERROR] Failed to scan CLI tools: ${error.message}`);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
case 'install':
|
|
207
|
+
try {
|
|
208
|
+
console.log('[INSTALL] Starting AI CLI tools installation...');
|
|
209
|
+
const { missing: missingTools } = await installer.scanCLI();
|
|
210
|
+
const options = await installer.showInstallOptions(missingTools);
|
|
211
|
+
|
|
212
|
+
if (options.length > 0) {
|
|
213
|
+
const selectedTools = await installer.getUserSelection(
|
|
214
|
+
options,
|
|
215
|
+
missingTools,
|
|
216
|
+
);
|
|
217
|
+
if (selectedTools.length > 0) {
|
|
218
|
+
console.log(
|
|
219
|
+
'\n[INFO] Installing selected tools (this may take several minutes for tools that download binaries)...',
|
|
220
|
+
);
|
|
221
|
+
await installer.installTools(selectedTools, missingTools);
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
console.log('\n[INFO] All required tools are already installed!');
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
await errorHandler.logError(error, 'ERROR', 'main.install');
|
|
228
|
+
console.log(`[ERROR] Installation failed: ${error.message}`);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
|
|
233
|
+
case 'deploy':
|
|
234
|
+
try {
|
|
235
|
+
const { available: deployedTools } = await installer.scanCLI();
|
|
236
|
+
await installer.deployHooks(deployedTools);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
await errorHandler.logError(error, 'ERROR', 'main.deploy');
|
|
239
|
+
console.log(`[ERROR] Deployment failed: ${error.message}`);
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
case 'call': {
|
|
246
|
+
if (args.length < 2) {
|
|
247
|
+
console.log('[ERROR] Please provide a prompt');
|
|
248
|
+
console.log('Usage: stigmergy call "<your prompt>"');
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Extract prompt from quotes or join remaining args
|
|
253
|
+
let prompt = '';
|
|
254
|
+
if (args[1].startsWith('"') && args[args.length - 1].endsWith('"')) {
|
|
255
|
+
// Quoted prompt
|
|
256
|
+
prompt = args.slice(1).join(' ').slice(1, -1);
|
|
257
|
+
} else {
|
|
258
|
+
// Unquoted prompt
|
|
259
|
+
prompt = args.slice(1).join(' ');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
console.log(`[ROUTE] Analyzing prompt: ${prompt}`);
|
|
264
|
+
|
|
265
|
+
// Route to appropriate AI CLI tool
|
|
266
|
+
const route = await router.routePrompt(prompt);
|
|
267
|
+
console.log(`[ROUTE] Selected tool: ${route.tool}`);
|
|
268
|
+
|
|
269
|
+
// Prepare tool arguments
|
|
270
|
+
const toolArgs = router.prepareToolArguments(route, prompt);
|
|
271
|
+
const toolPath = route.tool;
|
|
272
|
+
|
|
273
|
+
console.log(`[EXEC] Running: ${toolPath} ${toolArgs.join(' ')}`);
|
|
274
|
+
|
|
275
|
+
// Execute the AI CLI tool
|
|
276
|
+
const startTime = Date.now();
|
|
277
|
+
try {
|
|
278
|
+
const result = await executeCommand(toolPath, toolArgs);
|
|
279
|
+
|
|
280
|
+
if (result.success) {
|
|
281
|
+
console.log('[RESULT] Success!');
|
|
282
|
+
console.log(result.output);
|
|
283
|
+
|
|
284
|
+
// Save to memory
|
|
285
|
+
await memory.addInteraction(route.tool, prompt, result.output);
|
|
286
|
+
|
|
287
|
+
// Exit with the same code as the executed command
|
|
288
|
+
process.exit(result.code || 0);
|
|
289
|
+
}
|
|
290
|
+
} catch (executionError) {
|
|
291
|
+
const cliError = await errorHandler.handleCLIError(
|
|
292
|
+
route.tool,
|
|
293
|
+
executionError.error || executionError,
|
|
294
|
+
toolArgs.join(' '),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// Provide clear ANSI English error message
|
|
298
|
+
console.log('==================================================');
|
|
299
|
+
console.log('ERROR: Failed to execute AI CLI tool');
|
|
300
|
+
console.log('==================================================');
|
|
301
|
+
console.log(`Tool: ${route.tool}`);
|
|
302
|
+
console.log(`Error: ${cliError.message}`);
|
|
303
|
+
if (executionError.stderr) {
|
|
304
|
+
console.log(`Stderr: ${executionError.stderr}`);
|
|
305
|
+
}
|
|
306
|
+
console.log('');
|
|
307
|
+
console.log('Possible solutions:');
|
|
308
|
+
console.log('1. Check if the AI CLI tool is properly installed');
|
|
309
|
+
console.log('2. Verify the tool is in your system PATH');
|
|
310
|
+
console.log('3. Try reinstalling the tool with: stigmergy install');
|
|
311
|
+
console.log('4. Run stigmergy status to check tool availability');
|
|
312
|
+
console.log('');
|
|
313
|
+
console.log('For manual execution, you can run:');
|
|
314
|
+
console.log(`${toolPath} ${toolArgs.join(' ')}`);
|
|
315
|
+
console.log('==================================================');
|
|
316
|
+
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
const cliError = await errorHandler.handleCLIError(
|
|
321
|
+
route.tool,
|
|
322
|
+
error,
|
|
323
|
+
prompt,
|
|
324
|
+
);
|
|
325
|
+
console.log(
|
|
326
|
+
`[ERROR] Failed to execute ${route.tool}:`,
|
|
327
|
+
cliError.message,
|
|
328
|
+
);
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
case 'auto-install':
|
|
335
|
+
// Auto-install mode for npm postinstall - NON-INTERACTIVE
|
|
336
|
+
console.log('[AUTO-INSTALL] Stigmergy CLI automated setup');
|
|
337
|
+
console.log('='.repeat(60));
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
// Step 1: Download required assets
|
|
341
|
+
try {
|
|
342
|
+
console.log('[STEP] Downloading required assets...');
|
|
343
|
+
await installer.downloadRequiredAssets();
|
|
344
|
+
console.log('[OK] Assets downloaded successfully');
|
|
345
|
+
} catch (error) {
|
|
346
|
+
console.log(`[WARN] Failed to download assets: ${error.message}`);
|
|
347
|
+
console.log('[INFO] Continuing with installation...');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Step 2: Scan for CLI tools
|
|
351
|
+
let autoAvailable = {},
|
|
352
|
+
autoMissing = {};
|
|
353
|
+
try {
|
|
354
|
+
console.log('[STEP] Scanning for CLI tools...');
|
|
355
|
+
const scanResult = await installer.scanCLI();
|
|
356
|
+
autoAvailable = scanResult.available;
|
|
357
|
+
autoMissing = scanResult.missing;
|
|
358
|
+
console.log('[OK] CLI tools scanned successfully');
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.log(`[WARN] Failed to scan CLI tools: ${error.message}`);
|
|
361
|
+
console.log('[INFO] Continuing with installation...');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Step 3: Show summary to user after installation
|
|
365
|
+
try {
|
|
366
|
+
if (Object.keys(autoMissing).length > 0) {
|
|
367
|
+
console.log(
|
|
368
|
+
'\n[INFO] Found ' +
|
|
369
|
+
Object.keys(autoMissing).length +
|
|
370
|
+
' missing AI CLI tools:',
|
|
371
|
+
);
|
|
372
|
+
for (const [toolName, toolInfo] of Object.entries(autoMissing)) {
|
|
373
|
+
console.log(` - ${toolInfo.name} (${toolName})`);
|
|
374
|
+
}
|
|
375
|
+
console.log(
|
|
376
|
+
'\n[INFO] Auto-install mode detected. Skipping automatic installation of missing tools.',
|
|
377
|
+
);
|
|
378
|
+
console.log(
|
|
379
|
+
'[INFO] For full functionality, please run "stigmergy install" after installation completes.',
|
|
380
|
+
);
|
|
381
|
+
} else {
|
|
382
|
+
console.log(
|
|
383
|
+
'\n[INFO] All AI CLI tools are already installed! No additional tools required.',
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
} catch (error) {
|
|
387
|
+
console.log(`[WARN] Failed to show tool summary: ${error.message}`);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Step 4: Deploy hooks to available CLI tools
|
|
391
|
+
try {
|
|
392
|
+
console.log('[STEP] Deploying hooks to available CLI tools...');
|
|
393
|
+
await installer.deployHooks(autoAvailable);
|
|
394
|
+
console.log('[OK] Hooks deployed successfully');
|
|
395
|
+
} catch (error) {
|
|
396
|
+
console.log(`[ERROR] Failed to deploy hooks: ${error.message}`);
|
|
397
|
+
console.log(
|
|
398
|
+
'[INFO] You can manually deploy hooks later by running: stigmergy deploy',
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Step 5: Deploy project documentation
|
|
403
|
+
try {
|
|
404
|
+
console.log('[STEP] Deploying project documentation...');
|
|
405
|
+
await installer.deployProjectDocumentation();
|
|
406
|
+
console.log('[OK] Documentation deployed successfully');
|
|
407
|
+
} catch (error) {
|
|
408
|
+
console.log(
|
|
409
|
+
`[WARN] Failed to deploy documentation: ${error.message}`,
|
|
410
|
+
);
|
|
411
|
+
console.log('[INFO] Continuing with installation...');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Step 6: Initialize configuration
|
|
415
|
+
try {
|
|
416
|
+
console.log('[STEP] Initializing configuration...');
|
|
417
|
+
await installer.initializeConfig();
|
|
418
|
+
console.log('[OK] Configuration initialized successfully');
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.log(
|
|
421
|
+
`[ERROR] Failed to initialize configuration: ${error.message}`,
|
|
422
|
+
);
|
|
423
|
+
console.log(
|
|
424
|
+
'[INFO] You can manually initialize configuration later by running: stigmergy setup',
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Step 7: Show final message to guide users
|
|
429
|
+
console.log('\n[SUCCESS] Stigmergy CLI installed successfully!');
|
|
430
|
+
console.log(
|
|
431
|
+
'[USAGE] Run "stigmergy setup" to complete full configuration and install missing AI CLI tools.',
|
|
432
|
+
);
|
|
433
|
+
console.log(
|
|
434
|
+
'[USAGE] Run "stigmergy install" to install only missing AI CLI tools.',
|
|
435
|
+
);
|
|
436
|
+
console.log(
|
|
437
|
+
'[USAGE] Run "stigmergy --help" to see all available commands.',
|
|
438
|
+
);
|
|
439
|
+
} catch (fatalError) {
|
|
440
|
+
await errorHandler.logError(fatalError, 'ERROR', 'main.auto-install');
|
|
441
|
+
console.error(
|
|
442
|
+
'[FATAL] Auto-install process failed:',
|
|
443
|
+
fatalError.message,
|
|
444
|
+
);
|
|
445
|
+
console.log('\n[TROUBLESHOOTING] To manually complete installation:');
|
|
446
|
+
console.log('1. Run: stigmergy setup # Complete setup');
|
|
447
|
+
console.log('2. Run: stigmergy install # Install missing tools');
|
|
448
|
+
console.log('3. Run: stigmergy deploy # Deploy hooks manually');
|
|
449
|
+
process.exit(1);
|
|
450
|
+
}
|
|
451
|
+
break;
|
|
452
|
+
|
|
453
|
+
default:
|
|
454
|
+
console.log(`[ERROR] Unknown command: ${command}`);
|
|
455
|
+
console.log('[INFO] Run "stigmergy --help" for usage information');
|
|
456
|
+
process.exit(1);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
module.exports = main;
|
|
@@ -4,7 +4,7 @@ const fs = require('fs/promises');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
6
|
const { CLI_TOOLS } = require('./cli_tools');
|
|
7
|
-
const { errorHandler
|
|
7
|
+
const { errorHandler } = require('./error_handler');
|
|
8
8
|
|
|
9
9
|
class CLIHelpAnalyzer {
|
|
10
10
|
constructor() {
|
|
@@ -89,7 +89,7 @@ class CLIHelpAnalyzer {
|
|
|
89
89
|
async analyzeAllCLI() {
|
|
90
90
|
const results = {};
|
|
91
91
|
|
|
92
|
-
for (const [cliName,
|
|
92
|
+
for (const [cliName, _] of Object.entries(this.cliTools)) {
|
|
93
93
|
try {
|
|
94
94
|
if (process.env.DEBUG === 'true') {
|
|
95
95
|
console.log(`Analyzing ${cliName}...`);
|
|
@@ -671,4 +671,4 @@ class CLIHelpAnalyzer {
|
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
-
module.exports = CLIHelpAnalyzer;
|
|
674
|
+
module.exports = CLIHelpAnalyzer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Update main coordination layer to include Node.js components
|
|
2
|
+
// src/core/coordination/index.js
|
|
3
|
+
|
|
4
|
+
// Existing content would be here...
|
|
5
|
+
|
|
6
|
+
// Add Node.js coordination layer exports
|
|
7
|
+
const NodeJsCoordinationLayer = require('./nodejs');
|
|
8
|
+
const HookDeploymentManager = require('./nodejs/HookDeploymentManager');
|
|
9
|
+
const CLIIntegrationManager = require('./nodejs/CLIIntegrationManager');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
// Existing exports...
|
|
13
|
+
NodeJsCoordinationLayer,
|
|
14
|
+
HookDeploymentManager,
|
|
15
|
+
CLIIntegrationManager
|
|
16
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/core/coordination/nodejs/AdapterManager.js
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
|
|
6
|
+
class AdapterManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.adapters = new Map();
|
|
9
|
+
this.discoveryPaths = [
|
|
10
|
+
path.join(__dirname, '..', '..', '..', 'adapters'),
|
|
11
|
+
path.join(os.homedir(), '.stigmergy', 'adapters')
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async initialize() {
|
|
16
|
+
console.log('[ADAPTER_MANAGER] Initializing adapter manager...');
|
|
17
|
+
await this.discoverAdapters();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async discoverAdapters() {
|
|
21
|
+
console.log('[ADAPTER_MANAGER] Discovering adapters...');
|
|
22
|
+
|
|
23
|
+
for (const basePath of this.discoveryPaths) {
|
|
24
|
+
if (fs.existsSync(basePath)) {
|
|
25
|
+
try {
|
|
26
|
+
const adapterDirs = fs.readdirSync(basePath, { withFileTypes: true })
|
|
27
|
+
.filter(dirent => dirent.isDirectory())
|
|
28
|
+
.map(dirent => dirent.name);
|
|
29
|
+
|
|
30
|
+
console.log(`[ADAPTER_MANAGER] Found ${adapterDirs.length} adapter directories in ${basePath}`);
|
|
31
|
+
|
|
32
|
+
for (const dir of adapterDirs) {
|
|
33
|
+
await this.loadAdapter(dir, basePath);
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(`[ADAPTER_MANAGER] Failed to read adapter directory ${basePath}:`, error.message);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`[ADAPTER_MANAGER] Adapter path does not exist: ${basePath}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async loadAdapter(adapterName, basePath) {
|
|
45
|
+
const adapterPath = path.join(basePath, adapterName, 'index.js');
|
|
46
|
+
|
|
47
|
+
if (fs.existsSync(adapterPath)) {
|
|
48
|
+
try {
|
|
49
|
+
// Create a simple adapter wrapper for Node.js
|
|
50
|
+
const adapter = {
|
|
51
|
+
name: adapterName,
|
|
52
|
+
path: adapterPath,
|
|
53
|
+
available: true,
|
|
54
|
+
version: '1.0.0-nodejs',
|
|
55
|
+
isAvailable: async () => true,
|
|
56
|
+
executeTask: async (task, context) => {
|
|
57
|
+
// Simple task execution simulation
|
|
58
|
+
return `[${adapterName.toUpperCase()} NODE.JS ADAPTER] Executed: ${task}`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
this.adapters.set(adapterName, adapter);
|
|
63
|
+
console.log(`[ADAPTER_MANAGER] Loaded Node.js adapter: ${adapterName}`);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.warn(`[ADAPTER_MANAGER] Failed to load adapter from ${adapterPath}:`, error.message);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
console.log(`[ADAPTER_MANAGER] Adapter index.js not found for: ${adapterName}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getAdapter(cliName) {
|
|
73
|
+
return this.adapters.get(cliName.toLowerCase());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async listAdapters() {
|
|
77
|
+
const adapterList = [];
|
|
78
|
+
for (const [name, adapter] of this.adapters) {
|
|
79
|
+
adapterList.push({
|
|
80
|
+
name,
|
|
81
|
+
available: await adapter.isAvailable(),
|
|
82
|
+
version: adapter.version || 'unknown'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return adapterList;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = AdapterManager;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/core/coordination/nodejs/CLCommunication.js
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
class CLCommunication {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.executionTimeout = 30000; // 30 seconds
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async initialize() {
|
|
11
|
+
console.log('[CL_COMMUNICATION] Initializing cross-CLI communication...');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async executeTask(sourceCLI, targetCLI, task, context) {
|
|
15
|
+
console.log(`[CL_COMMUNICATION] Executing task from ${sourceCLI} to ${targetCLI}: ${task}`);
|
|
16
|
+
|
|
17
|
+
const targetAdapter = this.getAdapter(targetCLI);
|
|
18
|
+
if (!targetAdapter) {
|
|
19
|
+
throw new Error(`Adapter for ${targetCLI} not found`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// For Node.js implementation, we simulate cross-CLI communication
|
|
23
|
+
// In a real implementation, this would interface with actual CLI tools
|
|
24
|
+
try {
|
|
25
|
+
// Simulate CLI execution with a delay
|
|
26
|
+
const result = await this.simulateCLIExecution(targetCLI, task, context);
|
|
27
|
+
return result;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(`[CL_COMMUNICATION] Failed to execute task for ${targetCLI}:`, error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getAdapter(cliName) {
|
|
35
|
+
// In a real implementation, this would integrate with the adapter manager
|
|
36
|
+
// For now, we return a mock adapter
|
|
37
|
+
return {
|
|
38
|
+
name: cliName,
|
|
39
|
+
executeTask: async (task, context) => {
|
|
40
|
+
return `[${cliName.toUpperCase()} NODE.JS SIMULATION] Executed: ${task}`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async simulateCLIExecution(cliName, task, context) {
|
|
46
|
+
// Simulate CLI execution with a promise that resolves after a short delay
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
resolve(`[${cliName.toUpperCase()} NODE.JS EXECUTION] Completed task: ${task}`);
|
|
50
|
+
}, Math.random() * 1000); // Random delay between 0-1000ms
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
generateTaskId() {
|
|
55
|
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = CLCommunication;
|