Skip to content

fix(cli): double-Esc cancels current prompt, not history (#784) #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Pruthvik-P
Copy link

Closes #784

What

This change makes “Esc Esc” only cancel the in-flight generation, instead of wiping out the entire chat history.

  • Introduced escCount in TextBuffer to track consecutive Escape presses.
  • Added an optional onCancelCurrent callback that consumers (e.g. the CLI session) can hook to abort only the current generation.
  • Modified handleInput so:
    1. First Esc increments escCount and returns false (no re-render).
    2. Second consecutive Esc resets escCount, invokes onCancelCurrent, and returns true to trigger a re-render.
    3. Any other key resets escCount to zero.
  • Added Jest unit tests in text-buffer.test.ts covering:
    • Single Esc does not cancel and does not re-render.
    • Double Esc calls onCancelCurrent exactly once and requests a re-render.
    • Non-Esc keys between Esc presses reset the counter.

How to test

  1. Run the TypeScript tests:
    npm test  # or `yarn test`

Copy link

github-actions bot commented May 2, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Pruthvik-P
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request May 2, 2025
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.

esc esc to "cancel" completely wipes chat history
1 participant