stigmergy 1.3.9 → 1.3.11

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.9",
3
+ "version": "1.3.11",
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,25 +701,51 @@ 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
+ };
714
+
715
+ child.on('exit', (code, signal) => {
716
+ // Clear timeout when process exits
717
+ clearTimeoutSafely();
709
718
 
719
+ // Resolve with collected stdout/stderr
710
720
  resolve({
711
721
  code,
722
+ signal,
712
723
  stdout,
713
724
  stderr,
714
725
  success: code === 0,
715
726
  });
716
727
  });
717
728
 
718
- child.on('error', (error) => {
719
- // Clear timeout if it exists
720
- if (timeoutId) {
721
- clearTimeout(timeoutId);
729
+ child.on('close', (code, signal) => {
730
+ // Clear timeout when all stdio streams are closed
731
+ clearTimeoutSafely();
732
+
733
+ // Only resolve if not already resolved via 'exit' event
734
+ // This prevents duplicate resolution
735
+ if (!timeoutCleared) {
736
+ resolve({
737
+ code,
738
+ signal,
739
+ stdout,
740
+ stderr,
741
+ success: code === 0,
742
+ });
722
743
  }
744
+ });
745
+
746
+ child.on('error', (error) => {
747
+ // Clear timeout on error
748
+ clearTimeoutSafely();
723
749
 
724
750
  // Provide more detailed error information
725
751
  let errorMessage = error.message;
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Simple test for basic functionality
5
+ */
6
+
7
+ // Mock the CLI tools to ensure they're available for testing
8
+ jest.doMock('../src/core/cli_tools', () => ({
9
+ CLI_TOOLS: {
10
+ claude: { name: 'Claude CLI', command: 'claude', version: 'claude --version' },
11
+ qwen: { name: 'Qwen CLI', command: 'qwen', version: 'qwen --version' },
12
+ gemini: { name: 'Gemini CLI', command: 'gemini', version: 'gemini --version' },
13
+ iflow: { name: 'iFlow CLI', command: 'iflow', version: 'iflow --version' },
14
+ codebuddy: { name: 'CodeBuddy CLI', command: 'codebuddy', version: 'codebuddy --version' },
15
+ codex: { name: 'Codex CLI', command: 'codex', version: 'codex --version' },
16
+ qodercli: { name: 'QoderCLI', command: 'qodercli', version: 'qodercli --version' },
17
+ copilot: { name: 'Copilot CLI', command: 'copilot', version: 'copilot --version' },
18
+ kode: { name: 'Kode CLI', command: 'kode', version: 'kode --version' }
19
+ },
20
+ validateCLITool: jest.fn().mockReturnValue(true)
21
+ }));
22
+
23
+ // Mock CLIHelpAnalyzer to avoid actual CLI analysis during testing
24
+ jest.doMock('../src/core/cli_help_analyzer', () => {
25
+ return jest.fn().mockImplementation(() => {
26
+ return {
27
+ setCLITools: jest.fn(),
28
+ initialize: jest.fn().mockResolvedValue(undefined),
29
+ analyzeCLI: jest.fn().mockResolvedValue({
30
+ success: true,
31
+ cliName: 'test-cli',
32
+ patterns: {
33
+ commands: [{ name: 'analyze' }, { name: 'generate' }, { name: 'explain' }],
34
+ subcommands: []
35
+ }
36
+ }),
37
+ loadPersistentConfig: jest.fn().mockResolvedValue({
38
+ failedAttempts: {},
39
+ cliPatterns: {}
40
+ }),
41
+ getCachedAnalysis: jest.fn().mockResolvedValue(null),
42
+ isCacheExpired: jest.fn().mockReturnValue(false),
43
+ generateOptimizedCall: jest.fn().mockReturnValue({
44
+ optimizedPrompt: 'test prompt'
45
+ }),
46
+ getAgentSkillCompatibilityScore: jest.fn().mockReturnValue({ score: 0.5, reasons: ['test'] }),
47
+ getEnhancedCLIPattern: jest.fn().mockResolvedValue({})
48
+ };
49
+ });
50
+ });
51
+
52
+ const SmartRouter = require('../src/core/smart_router');
53
+
54
+ async function runSimpleTest() {
55
+ console.log('Running simple test...');
56
+
57
+ try {
58
+ const router = new SmartRouter();
59
+ await router.initialize();
60
+
61
+ console.log('✓ Router initialized successfully');
62
+
63
+ // Test a simple routing case
64
+ const result = await router.smartRoute('use claude to analyze code');
65
+ console.log(`✓ Simple routing test passed: ${result.tool}`);
66
+
67
+ // Test shouldRoute functionality
68
+ const shouldRoute = router.shouldRoute('help with code');
69
+ console.log(`✓ shouldRoute test passed: ${shouldRoute}`);
70
+
71
+ console.log('All simple tests passed!');
72
+ return true;
73
+ } catch (error) {
74
+ console.error('Simple test failed:', error);
75
+ return false;
76
+ }
77
+ }
78
+
79
+ // Run the test
80
+ runSimpleTest().then(success => {
81
+ process.exit(success ? 0 : 1);
82
+ });
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Very simple test without complex mocking
5
+ */
6
+
7
+ // Simple test to check basic functionality
8
+ async function runVerySimpleTest() {
9
+ console.log('Running very simple test...');
10
+
11
+ try {
12
+ // Test basic Node.js functionality
13
+ console.log('✓ Node.js environment is working');
14
+
15
+ // Test basic string operations
16
+ const testString = 'hello world';
17
+ if (testString.toUpperCase() === 'HELLO WORLD') {
18
+ console.log('✓ String operations working');
19
+ } else {
20
+ console.log('✗ String operations failed');
21
+ return false;
22
+ }
23
+
24
+ // Test basic math
25
+ if (2 + 2 === 4) {
26
+ console.log('✓ Math operations working');
27
+ } else {
28
+ console.log('✗ Math operations failed');
29
+ return false;
30
+ }
31
+
32
+ // Test basic array operations
33
+ const arr = [1, 2, 3];
34
+ arr.push(4);
35
+ if (arr.length === 4 && arr[3] === 4) {
36
+ console.log('✓ Array operations working');
37
+ } else {
38
+ console.log('✗ Array operations failed');
39
+ return false;
40
+ }
41
+
42
+ console.log('All very simple tests passed!');
43
+ return true;
44
+ } catch (error) {
45
+ console.error('Very simple test failed:', error);
46
+ return false;
47
+ }
48
+ }
49
+
50
+ // Run the test
51
+ runVerySimpleTest().then(success => {
52
+ console.log(`Test completed with success: ${success}`);
53
+ process.exit(success ? 0 : 1);
54
+ });