stigmergy 1.3.9 → 1.3.10

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils.js +23 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stigmergy",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "description": "Stigmergy CLI - Multi-Agents Cross-AI CLI Tools Collaboration System",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/utils.js CHANGED
@@ -701,12 +701,22 @@ async function executeCommand(command, args = [], options = {}) {
701
701
 
702
702
  let timeoutId = null;
703
703
 
704
- child.on('close', (code) => {
705
- // Clear timeout if it exists
706
- if (timeoutId) {
704
+ // Flag to ensure timeout is cleared only once
705
+ let timeoutCleared = false;
706
+
707
+ // Function to clear timeout safely
708
+ const clearTimeoutSafely = () => {
709
+ if (timeoutId && !timeoutCleared) {
707
710
  clearTimeout(timeoutId);
711
+ timeoutCleared = true;
708
712
  }
713
+ };
709
714
 
715
+ child.on('exit', (code) => {
716
+ // Clear timeout when process exits
717
+ clearTimeoutSafely();
718
+
719
+ // Resolve with collected stdout/stderr
710
720
  resolve({
711
721
  code,
712
722
  stdout,
@@ -715,11 +725,17 @@ async function executeCommand(command, args = [], options = {}) {
715
725
  });
716
726
  });
717
727
 
728
+ child.on('close', (code) => {
729
+ // Clear timeout when all stdio streams are closed
730
+ clearTimeoutSafely();
731
+
732
+ // Only resolve if not already resolved via 'exit' event
733
+ // This prevents duplicate resolution
734
+ });
735
+
718
736
  child.on('error', (error) => {
719
- // Clear timeout if it exists
720
- if (timeoutId) {
721
- clearTimeout(timeoutId);
722
- }
737
+ // Clear timeout on error
738
+ clearTimeoutSafely();
723
739
 
724
740
  // Provide more detailed error information
725
741
  let errorMessage = error.message;