polydev-ai 1.8.8 → 1.8.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.
package/lib/cliManager.js CHANGED
@@ -379,15 +379,15 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
379
379
  }
380
380
 
381
381
  async sendCliPrompt(providerId, prompt, mode = 'args', timeoutMs = null, model = null) {
382
- // Set provider-specific default timeouts (180s for all by default, complex prompts take time)
382
+ // Set provider-specific default timeouts (5 minutes for all by default, complex prompts take time)
383
383
  if (timeoutMs === null) {
384
- timeoutMs = 180000; // 180 seconds default for all providers
384
+ timeoutMs = 300000; // 300 seconds (5 minutes) default for all providers
385
385
  }
386
386
 
387
387
  // Ensure timeoutMs is valid (not undefined, null, Infinity, or negative)
388
- // Allow up to 300 seconds (5 minutes) for complex operations
389
- if (!timeoutMs || timeoutMs === Infinity || timeoutMs < 1 || timeoutMs > 300000) {
390
- timeoutMs = 180000 // Default to 180 seconds
388
+ // Allow up to 600 seconds (10 minutes) for very complex operations
389
+ if (!timeoutMs || timeoutMs === Infinity || timeoutMs < 1 || timeoutMs > 600000) {
390
+ timeoutMs = 300000 // Default to 5 minutes
391
391
  }
392
392
 
393
393
  const startTime = Date.now();
@@ -644,9 +644,50 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
644
644
 
645
645
  let stdout = '';
646
646
  let stderr = '';
647
+ let resolved = false;
648
+ let debounceTimer = null;
649
+
650
+ // Helper to check if output looks complete (for JSON output from claude code)
651
+ const looksComplete = () => {
652
+ const trimmed = stdout.trim();
653
+ // For JSON output, check if it's valid JSON
654
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
655
+ try {
656
+ JSON.parse(trimmed);
657
+ return true; // Valid JSON means complete
658
+ } catch {
659
+ return false;
660
+ }
661
+ }
662
+ // For text output, check if we have substantial content
663
+ return trimmed.length > 50 && trimmed.includes('\n');
664
+ };
665
+
666
+ const doResolve = () => {
667
+ if (resolved) return;
668
+ resolved = true;
669
+ if (debounceTimer) clearTimeout(debounceTimer);
670
+ if (timeoutId) clearTimeout(timeoutId);
671
+ if (!child.killed) {
672
+ try { child.kill('SIGTERM'); } catch(_) {}
673
+ }
674
+ resolve({ stdout, stderr });
675
+ };
676
+
677
+ // Schedule early return check after debounce period
678
+ const scheduleEarlyReturn = () => {
679
+ if (debounceTimer) clearTimeout(debounceTimer);
680
+ debounceTimer = setTimeout(() => {
681
+ if (!resolved && looksComplete()) {
682
+ console.log('[CLI Debug] Early return - output looks complete');
683
+ doResolve();
684
+ }
685
+ }, 2000); // Wait 2 seconds after last data for Claude Code (faster JSON parsing)
686
+ };
647
687
 
648
688
  child.stdout?.on('data', (data) => {
649
689
  stdout += data.toString();
690
+ scheduleEarlyReturn();
650
691
  });
651
692
 
652
693
  child.stderr?.on('data', (data) => {
@@ -659,6 +700,11 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
659
700
  }
660
701
 
661
702
  child.on('close', (code) => {
703
+ if (resolved) return;
704
+ resolved = true;
705
+ if (debounceTimer) clearTimeout(debounceTimer);
706
+ if (timeoutId) clearTimeout(timeoutId);
707
+
662
708
  if (process.env.POLYDEV_CLI_DEBUG) {
663
709
  console.log(`[CLI Debug] Command finished with code ${code}`);
664
710
  }
@@ -679,6 +725,10 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
679
725
  });
680
726
 
681
727
  child.on('error', (error) => {
728
+ if (resolved) return;
729
+ resolved = true;
730
+ if (debounceTimer) clearTimeout(debounceTimer);
731
+ if (timeoutId) clearTimeout(timeoutId);
682
732
  if (process.env.POLYDEV_CLI_DEBUG) {
683
733
  console.log(`[CLI Debug] Command error:`, error);
684
734
  }
@@ -686,15 +736,11 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
686
736
  });
687
737
 
688
738
  let timeoutId;
689
- const cleanup = () => {
690
- if (timeoutId) {
691
- clearTimeout(timeoutId);
692
- timeoutId = null;
693
- }
694
- };
695
739
 
696
740
  timeoutId = setTimeout(() => {
697
- cleanup();
741
+ if (resolved) return;
742
+ resolved = true;
743
+ if (debounceTimer) clearTimeout(debounceTimer);
698
744
  if (!child.killed) {
699
745
  child.kill('SIGTERM');
700
746
  // Force kill after 2 seconds if still running
@@ -707,12 +753,8 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
707
753
  reject(new Error(`Command timeout after ${timeoutMs}ms`));
708
754
  }, timeoutMs);
709
755
 
710
- child.on('close', () => {
711
- cleanup();
712
- });
713
-
714
756
  child.on('exit', () => {
715
- cleanup();
757
+ if (debounceTimer) clearTimeout(debounceTimer);
716
758
  });
717
759
  });
718
760
  }
@@ -888,10 +930,12 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
888
930
  let stdout = '';
889
931
  let stderr = '';
890
932
  let resolved = false;
933
+ let debounceTimer = null; // Smart debounce timer for early return
891
934
 
892
935
  const stop = (handler) => {
893
936
  if (!resolved) {
894
937
  resolved = true;
938
+ if (debounceTimer) clearTimeout(debounceTimer);
895
939
  try { child.kill('SIGTERM'); } catch (_) {}
896
940
  handler();
897
941
  }
@@ -981,18 +1025,31 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
981
1025
  // Check if we have a complete response - look for actual content
982
1026
  const flushIfComplete = () => {
983
1027
  const parsed = parseCodexOutput(stdout);
984
- // Only resolve early if we have meaningful content (at least 2 chars) and output seems done
985
- // This prevents cutting off multi-line responses
986
- if (parsed && parsed.length >= 2 && stdout.includes('\n') && !stdout.endsWith('...')) {
1028
+ // Only resolve early if we have meaningful content (at least 20 chars) and output looks complete
1029
+ // Look for signs that Codex has finished outputting (tokens used, empty lines at end, etc.)
1030
+ if (parsed && parsed.length >= 20) {
1031
+ const detectedModel = this.detectModelFromOutput('codex_cli', stdout, stderr);
987
1032
  clearTimeout(timeoutHandle);
988
- stop(() => resolve(parsed));
1033
+ if (debounceTimer) clearTimeout(debounceTimer);
1034
+ stop(() => resolve({ content: parsed, detectedModel, rawStdout: stdout.trim(), rawStderr: stderr.trim() }));
989
1035
  }
990
1036
  };
991
1037
 
1038
+ // Smart debounce: wait 3 seconds after last data received before checking for early return
1039
+ const scheduleEarlyReturn = () => {
1040
+ if (debounceTimer) clearTimeout(debounceTimer);
1041
+ debounceTimer = setTimeout(() => {
1042
+ if (!resolved) {
1043
+ console.log('[CLI Debug] Checking for early return after debounce...');
1044
+ flushIfComplete();
1045
+ }
1046
+ }, 3000); // Wait 3 seconds after last data received
1047
+ };
1048
+
992
1049
  child.stdout?.on('data', (data) => {
993
1050
  stdout += data.toString();
994
- // Don't flush too eagerly - wait a bit for more data
995
- // flushIfComplete(); // Disabled: let the process complete naturally
1051
+ // Schedule early return check after debounce period
1052
+ scheduleEarlyReturn();
996
1053
  });
997
1054
 
998
1055
  child.stderr?.on('data', (data) => {
@@ -443,19 +443,20 @@ class StdioMCPWrapper {
443
443
  console.error(`[Stdio Wrapper] Local CLI prompt sending with perspectives`);
444
444
 
445
445
  try {
446
- let { provider_id, prompt, mode = 'args', timeout_ms = 180000 } = args;
446
+ let { provider_id, prompt, mode = 'args', timeout_ms = 300000 } = args;
447
447
 
448
448
  // Ensure timeout_ms is valid (not undefined, null, Infinity, or negative)
449
- if (!timeout_ms || timeout_ms === Infinity || timeout_ms < 1 || timeout_ms > 300000) {
450
- timeout_ms = 180000; // Default to 180 seconds for CLI responses
449
+ // Default to 5 minutes (300 seconds) for complex CLI responses
450
+ if (!timeout_ms || timeout_ms === Infinity || timeout_ms < 1 || timeout_ms > 600000) {
451
+ timeout_ms = 300000; // Default to 5 minutes for CLI responses
451
452
  }
452
453
 
453
454
  if (!prompt) {
454
455
  throw new Error('prompt is required');
455
456
  }
456
457
 
457
- // Use configured timeout but cap at 5 minutes max
458
- const gracefulTimeout = Math.min(timeout_ms, 300000);
458
+ // Use configured timeout but cap at 10 minutes max for safety
459
+ const gracefulTimeout = Math.min(timeout_ms, 600000);
459
460
 
460
461
  // Fetch user's model preferences (cached, non-blocking on failure)
461
462
  let modelPreferences = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.8",
3
+ "version": "1.8.10",
4
4
  "description": "Agentic workflow assistant with CLI integration - get diverse perspectives from multiple LLMs when stuck or need enhanced reasoning",
5
5
  "keywords": [
6
6
  "mcp",
@@ -67,7 +67,7 @@
67
67
  "lucide-react": "^0.542.0",
68
68
  "marked": "^16.2.1",
69
69
  "next": "^15.5.7",
70
- "polydev-ai": "^1.8.7",
70
+ "polydev-ai": "^1.8.9",
71
71
  "posthog-js": "^1.157.2",
72
72
  "prismjs": "^1.30.0",
73
73
  "react": "^18.3.1",