stigmergy 1.3.11 → 1.3.13

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.3.11",
3
+ "version": "1.3.13",
4
4
  "description": "Stigmergy CLI - Multi-Agents Cross-AI CLI Tools Collaboration System",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -336,26 +336,41 @@ async function executeSmartRoutedCommand(route, options = {}) {
336
336
 
337
337
  // Use enhanced parameter handling for one-time mode only
338
338
  if (mode === 'one-time') {
339
- const EnhancedCLIParameterHandler = require('../../core/enhanced_cli_parameter_handler');
340
- const paramHandler = new EnhancedCLIParameterHandler();
341
-
342
- // Generate optimized arguments with agent/skill support
343
- const paramResult = await paramHandler.generateArgumentsWithRetry(
344
- route.tool,
345
- route.prompt,
346
- {
347
- maxRetries,
348
- enableAgentSkillOptimization: true
339
+ try {
340
+ const EnhancedCLIParameterHandler = require('../../core/enhanced_cli_parameter_handler');
341
+ const paramHandler = new EnhancedCLIParameterHandler();
342
+
343
+ // Generate optimized arguments with agent/skill support
344
+ // Add timeout protection for parameter generation
345
+ const timeoutPromise = new Promise((_, reject) => {
346
+ setTimeout(() => reject(new Error('Parameter generation timeout')), 30000); // 30 second timeout for parameter generation
347
+ });
348
+
349
+ const paramPromise = paramHandler.generateArgumentsWithRetry(
350
+ route.tool,
351
+ route.prompt,
352
+ {
353
+ maxRetries,
354
+ enableAgentSkillOptimization: true
355
+ }
356
+ );
357
+
358
+ const paramResult = await Promise.race([paramPromise, timeoutPromise]);
359
+
360
+ toolArgs = paramResult.arguments;
361
+
362
+ // Re-add OAuth authentication (paramResult might overwrite)
363
+ toolArgs = addOAuthAuthArgs(route.tool, toolArgs);
364
+
365
+ if (verbose) {
366
+ console.log(chalk.gray(`[DEBUG] Generated args: ${toolArgs.join(' ')}`));
367
+ }
368
+ } catch (paramError) {
369
+ console.log(chalk.yellow(`[WARN] Parameter generation failed: ${paramError.message}, using basic arguments`));
370
+ // Fallback to basic arguments if enhanced parameter generation fails
371
+ if (verbose) {
372
+ console.log(chalk.gray(`[DEBUG] Falling back to basic args: ${toolArgs.join(' ')}`));
349
373
  }
350
- );
351
-
352
- toolArgs = paramResult.arguments;
353
-
354
- // Re-add OAuth authentication (paramResult might overwrite)
355
- toolArgs = addOAuthAuthArgs(route.tool, toolArgs);
356
-
357
- if (verbose) {
358
- console.log(chalk.gray(`[DEBUG] Generated args: ${toolArgs.join(' ')}`));
359
374
  }
360
375
  } else {
361
376
  if (verbose) {
@@ -379,15 +394,23 @@ async function executeSmartRoutedCommand(route, options = {}) {
379
394
  console.log(chalk.gray(`[DEBUG] Mode: ${mode}`));
380
395
  }
381
396
 
397
+ console.log(chalk.gray(`[EXEC] ${route.tool}: ${route.prompt}`)); // Add this to match direct command format
398
+
382
399
  // Execute the command
383
400
  // For interactive mode, we need stdio: 'inherit' to allow user interaction
401
+ // For one-time mode, we should use 'inherit' to ensure CLI tools can properly execute
402
+ const stdioOption = mode === 'interactive' ? 'inherit' : 'inherit'; // Use 'inherit' for both modes to ensure proper CLI execution
403
+
404
+ console.log(chalk.gray(`[DEBUG] About to execute command with args: ${toolArgs.join(' ')}`)); // Debug log
405
+ console.log(chalk.gray(`[DEBUG] Using stdio option: ${stdioOption}`)); // Debug log
384
406
  const result = await executeCommand(toolPath, toolArgs, {
385
- stdio: mode === 'interactive' ? 'inherit' : 'pipe',
407
+ stdio: stdioOption,
386
408
  shell: true,
387
409
  cwd,
388
410
  env,
389
411
  timeout: 300000 // 5 minutes
390
412
  });
413
+ console.log(chalk.gray(`[DEBUG] Command execution completed`)); // Debug log
391
414
 
392
415
  return { success: true, tool: route.tool, result, mode };
393
416
 
package/src/utils.js CHANGED
@@ -631,10 +631,12 @@ async function executeCommand(command, args = [], options = {}) {
631
631
  const opts = {
632
632
  stdio: 'inherit',
633
633
  shell: true,
634
- timeout: 300000, // 5 minute timeout
635
634
  ...options,
636
635
  };
637
636
 
637
+ // Extract timeout from options to handle separately
638
+ const timeoutValue = options.timeout || 300000; // Default to 5 minutes if not specified
639
+
638
640
  return new Promise((resolve, reject) => {
639
641
  // Don't log the command if it contains sensitive information
640
642
  if (process.env.DEBUG === 'true') {
@@ -704,6 +706,9 @@ async function executeCommand(command, args = [], options = {}) {
704
706
  // Flag to ensure timeout is cleared only once
705
707
  let timeoutCleared = false;
706
708
 
709
+ // Flag to prevent duplicate promise resolution
710
+ let promiseResolved = false;
711
+
707
712
  // Function to clear timeout safely
708
713
  const clearTimeoutSafely = () => {
709
714
  if (timeoutId && !timeoutCleared) {
@@ -712,12 +717,28 @@ async function executeCommand(command, args = [], options = {}) {
712
717
  }
713
718
  };
714
719
 
720
+ // Function to resolve safely (prevent duplicate resolution)
721
+ const safeResolve = (result) => {
722
+ if (!promiseResolved) {
723
+ promiseResolved = true;
724
+ resolve(result);
725
+ }
726
+ };
727
+
728
+ // Function to reject safely (prevent duplicate rejection)
729
+ const safeReject = (error) => {
730
+ if (!promiseResolved) {
731
+ promiseResolved = true;
732
+ reject(error);
733
+ }
734
+ };
735
+
715
736
  child.on('exit', (code, signal) => {
716
737
  // Clear timeout when process exits
717
738
  clearTimeoutSafely();
718
739
 
719
740
  // Resolve with collected stdout/stderr
720
- resolve({
741
+ safeResolve({
721
742
  code,
722
743
  signal,
723
744
  stdout,
@@ -732,8 +753,8 @@ async function executeCommand(command, args = [], options = {}) {
732
753
 
733
754
  // Only resolve if not already resolved via 'exit' event
734
755
  // This prevents duplicate resolution
735
- if (!timeoutCleared) {
736
- resolve({
756
+ if (!promiseResolved) {
757
+ safeResolve({
737
758
  code,
738
759
  signal,
739
760
  stdout,
@@ -766,16 +787,16 @@ async function executeCommand(command, args = [], options = {}) {
766
787
  });
767
788
 
768
789
  // Handle timeout
769
- if (opts.timeout) {
790
+ if (timeoutValue) {
770
791
  timeoutId = setTimeout(() => {
771
792
  child.kill();
772
793
  reject({
773
794
  error: new Error('Command timeout'),
774
- message: `Command timed out after ${opts.timeout}ms`,
795
+ message: `Command timed out after ${timeoutValue}ms`,
775
796
  stdout,
776
797
  stderr,
777
798
  });
778
- }, opts.timeout);
799
+ }, timeoutValue);
779
800
  }
780
801
  } catch (error) {
781
802
  reject({