Skip to content

feat(tui): undo a just-sent prompt with double escape - #52538

Closed
moritzWa wants to merge 3 commits into
anomalyco:devfrom
moritzWa:feat/tui-quick-undo-escape
Closed

moritzWa wants to merge 3 commits into
anomalyco:devfrom
moritzWa:feat/tui-quick-undo-escape

Conversation

@moritzWa

@moritzWa moritzWa commented Oct 1, 2026 •

Copy link
Copy Markdown

Demo

quick undo demo

Double Esc before the reply starts: the turn stops, the message is reverted, and the text comes back in the input. It is then edited and resent. (mp4)

Issue for this PR

Closes #52537

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Claude Code-style "oops, unsend": pressing Esc twice after submitting a prompt, before the reply has shown any text or tool output, aborts the turn, reverts that exact message, and puts its text and attachments back in the input. The first Esc shows "esc again to undo" instead of "esc again to interrupt" when this applies. Once the reply is visible (or if you've already started typing a new draft), Esc behaves exactly as before.

I started with a fixed 2s window like #36538, but time to first token is often 3-10s and people press Esc twice slower than that, so the window kept missing. Keying it on "has the reply shown anything yet" matches what you actually want to undo.

How it works:

  • On submit, the TUI now generates the message ID client-side (session.prompt already accepts messageID) and remembers it with the prompt.
  • On the second Esc, if no assistant message replying to it has a non-empty text part or a tool part yet, the prompt is restored immediately, then session.abort and session.revert run on that message ID. Abort can take a few seconds to settle, so restoring first keeps it from feeling ignored. That's the same revert flow /undo uses, so /redo still works.
  • The tracker lives at module scope so it also works for the first message of a new session, which is submitted from the home route's prompt and then navigates to the session route's prompt. It checks the session ID before reverting.

This revives #36538 (closed by stale-PR cleanup), plus the first-message fix and the don't-clobber-a-new-draft guard.

How did you verify your code works?

  • bun test src/component/prompt/quick-undo.test.ts (5 tests) and bun run typecheck in packages/tui
  • Built a local binary and drove it in tmux:
    • first message in a new session, Esc Esc after ~1s: "1 message reverted", text back in the input
    • follow-up message in an existing session: same
    • Esc, then Esc 2.5s later, before any output: reverted, hint showed "esc again to undo"
    • Esc Esc after the reply started streaming text: normal interrupt, hint showed "esc again to interrupt"

Screenshots / recordings

Behavioral only. After Esc Esc right after sending, the transcript shows "1 message reverted · ctrl+x r or /redo to restore" and the prompt contains the original text.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
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.

[FEATURE]: Double Esc right after sending should undo the message and restore it to the input

2 participants