Skip to content

Fix: interactive mode exits after first prompt#23

Open
Mostafa-M-Hussein wants to merge 1 commit into
holasoymalva:mainfrom
Mostafa-M-Hussein:fix/interactive-readline-exit
Open

Fix: interactive mode exits after first prompt#23
Mostafa-M-Hussein wants to merge 1 commit into
holasoymalva:mainfrom
Mostafa-M-Hussein:fix/interactive-readline-exit

Conversation

@Mostafa-M-Hussein
Copy link
Copy Markdown

Problem

In interactive mode the CLI quits immediately after the first response is printed. The deepseek-cli > prompt never comes back. The chat <prompt> subcommand is not affected.

Repro

  1. export DEEPSEEK_API_KEY=...
  2. deepseek-cli
  3. type a prompt, press Enter
  4. response prints, then process exits with Goodbye! 👋

Tested on Node 22, 24, 25.

Cause

In src/commands/interactive.ts the 'line' handler starts an ora spinner inside the await:

const spinner = ora('Thinking...').start();
const response = await api.complete(trimmed);
spinner.stop();

ora hooks process.stdin to manage cursor visibility. On Node 22+ the way it releases stdin on .stop() leaves the stream paused/detached, and readline reads EOF on the next tick. That fires rl.on('close'), which calls process.exit(0). So the very first start/stop cycle is enough to kill the session.

Fix

Pause readline while the spinner is running, resume in finally. Three lines, no behavior change otherwise.

rl.pause();
const spinner = ora('Thinking...').start();
try {
  ...
} finally {
  rl.resume();
}

Verified

  • npm run build clean
  • interactive mode now keeps the prompt across many prompts, exit and Ctrl+C still work
  • single-shot chat command unchanged

ora's spinner detaches stdin when it stops, which causes readline to
receive EOF and fire 'close' on the next tick. The 'close' handler
calls process.exit(0), so the session dies right after the first
response prints.

Pause readline while the spinner is running and resume it in finally
so the stdin stream stays attached to readline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant