fix(init): fix only Enter working after legacy cleanup on Windows
Summary
Fix keyboard input becoming unresponsive during openspec init on Windows after cleaning up legacy files.
In the AI tool selection prompt, arrow keys, Space, and Backspace stop responding. Only Enter continues to work.
Reproduction
Run the following commands in PowerShell:
mkdir openspec-input-repro
cd openspec-input-repro
New-Item -ItemType File ".cursor\commands\openspec-xxx.md" -Force
openspec init
Then:
- Confirm
Upgrade and clean up legacy files. - Press Enter on the animated welcome screen.
- Try using arrow keys, Space, and Backspace in the
Select AI toolsprompt.
Before this fix, only Enter responds.
Root Cause
The animated welcome screen manually managed stdin raw mode and listened for raw data events between two Inquirer prompts.
On Windows, this disrupted Inquirer's keypress handling for the following tool selection prompt.
Fix
Use an @inquirer/core prompt to wait for Enter on the welcome screen, keeping the complete interactive flow within Inquirer's input lifecycle.
The existing animated welcome screen and Ctrl+C behavior are preserved.
Cross-platform impact
This change removes the welcome screen's manual raw stdin handling and uses an @inquirer/core prompt instead, so the welcome step now follows the same input lifecycle as the subsequent Inquirer prompts.
That keeps the fix platform-neutral rather than introducing Windows-specific logic, and should reduce the chance of terminal state inconsistencies across environments.
I reproduced the regression and verified the fix on Windows. I have not manually validated the interactive flow on a real macOS terminal, but the new implementation is more consistent with Inquirer's cross-platform input handling model.
Verification
- Reproduced and verified the fix using a Windows pseudo-terminal
- Confirmed arrow keys navigate the tool list
- Confirmed Space toggles tool selections
- Confirmed Backspace removes the selections
- Confirmed Enter submits the selection
- Added a regression test for the welcome-screen input lifecycle
pnpm run buildpnpm lint- Relevant tests pass
Summary by CodeRabbit
- Tests
- Added automated test coverage for welcome screen keypress handling to verify correct interaction behavior.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ecdf23dd-30d9-496f-b2bf-52096797d153
📥 Commits
Reviewing files that changed from the base of the PR and between 1b06fddd59d8e592d5b5794a1970b22867e85b1f and 826dbb341a24e5788033bf299e989d1366e64a2b.
📒 Files selected for processing (2)
src/ui/welcome-screen.tstest/ui/welcome-screen.test.ts
📝 Walkthrough
Walkthrough
waitForEnter is refactored from manual stdin raw-mode listeners to Inquirer's keypress lifecycle. The new version exits early for non-TTY stdin, dynamically imports @inquirer/core, registers a keypress handler for Ctrl+C and Enter detection, and awaits prompt({}). Comprehensive Vitest tests validate TTY setup, mock infrastructure, and single useKeypress invocation.
Changes
Welcome Screen Enter Key Refactoring
| Layer / File(s) | Summary |
|---|---|
Inquirer-based Enter key waiting src/ui/welcome-screen.ts |
waitForEnter is refactored to use @inquirer/core's createPrompt and useKeypress hook. Early return for non-TTY stdin; keypress handler catches Ctrl+C (exit with newline) and Enter key detection. Awaits prompt({}) instead of managing raw stdin listeners. |
Welcome screen Enter key test with setup test/ui/welcome-screen.test.ts |
Vitest test suite mocks @inquirer/core to capture keypress handler and simulate Enter events. Test setup captures and restores process state (TTY flags, NO_COLOR, stdout columns). Validates single useKeypress invocation. |
🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested reviewers
- alfred-openspec
Poem
🐰 A prompt reborn, no stdin to fight,
Inquirer's keypress dances just right,
Enter awaits, no listeners loiter,
The welcome screen flows—hooray, rejoiners!
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title references fixing Enter key behavior on Windows after legacy cleanup, which directly aligns with the main change of refactoring waitForEnter from manual stdin handling to Inquirer-based prompt management to fix input issues. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.