fix(cli): clean up stdin after sessions command readline interface closes

The sessions command uses readline.createInterface() to prompt for session
selection, but was not cleaning up stdin listeners after rl.close().
This left stdin in a corrupted state with lingering readline listeners,
causing duplicate terminal I/O and making the CLI unusable when the TUI
subsequently initialized.

Add proper stdin cleanup after rl.close() to match the pattern used after
onboarding, removing data/keypress listeners, resetting raw mode, and
pausing stdin for a clean state handoff to the TUI.

Closes #3718
This commit is contained in:
H. Sinan Alioglu 2026-04-08 16:27:43 +02:00
parent e3d69ed01a
commit 27675a5224

View file

@ -281,6 +281,14 @@ if (cliFlags.messages[0] === 'sessions') {
})
rl.close()
// Clean up stdin state left by readline.createInterface().
// Without this, downstream TUI initialization gets corrupted listeners and exhibits
// duplicate terminal I/O. Match the pattern used after onboarding cleanup.
process.stdin.removeAllListeners('data')
process.stdin.removeAllListeners('keypress')
if (process.stdin.setRawMode) process.stdin.setRawMode(false)
process.stdin.pause()
const choice = parseInt(answer, 10)
if (isNaN(choice) || choice < 1 || choice > toShow.length) {
process.stderr.write(chalk.dim('Cancelled.\n'))