UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

59 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForExit = waitForExit; const SILENCE_TIMEOUT_MS = 10000; // 10 seconds /** * Waits for PTY process to exit, either naturally or after 10 seconds of no output. * Returns the exit code of the process. */ function waitForExit(ptyProcess) { return new Promise((resolve) => { let exitCode = -1; let silenceTimer = null; // Function to reset the silence timer const resetSilenceTimer = () => { if (silenceTimer) { clearTimeout(silenceTimer); } silenceTimer = setTimeout(() => { // Exit after silence timeout - return 0 for intentional kill cleanup(); resolve(0); }, SILENCE_TIMEOUT_MS); }; // Cleanup function const cleanup = () => { if (silenceTimer) { clearTimeout(silenceTimer); silenceTimer = null; } // Restore stdin to normal mode if (process.stdin.isTTY && process.stdin.setRawMode) { process.stdin.setRawMode(false); } // Kill the process if it's still running if (ptyProcess.pid) { try { ptyProcess.kill(); } catch (_a) { // Process might already be dead } } }; // Handle PTY output ptyProcess.onData((data) => { process.stdout.write(data); resetSilenceTimer(); }); // Handle PTY exit ptyProcess.onExit(({ exitCode: code }) => { exitCode = code || 0; cleanup(); resolve(exitCode); }); // Start the initial silence timer resetSilenceTimer(); }); } //# sourceMappingURL=waitForExit.js.map