polydev-ai 1.8.9 → 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 +75 -18
- package/package.json +1 -1
package/lib/cliManager.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
985
|
-
//
|
|
986
|
-
if (parsed && parsed.length >=
|
|
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
|
-
|
|
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
|
-
//
|
|
995
|
-
|
|
1051
|
+
// Schedule early return check after debounce period
|
|
1052
|
+
scheduleEarlyReturn();
|
|
996
1053
|
});
|
|
997
1054
|
|
|
998
1055
|
child.stderr?.on('data', (data) => {
|
package/package.json
CHANGED