fix(tui): auto-undo interrupted prompt when turn has no output#553
Open
MicroGery wants to merge 3 commits into
Open
fix(tui): auto-undo interrupted prompt when turn has no output#553MicroGery wants to merge 3 commits into
MicroGery wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 7e375ed The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9897231f7b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
When the user interrupts a turn (Esc or Ctrl-C) before the model has produced any substantial content, automatically withdraw the prompt from the transcript and restore its text to the editor. A semantic guard scans the current turn: if an assistant message with non-empty text or any tool_call already exists, the cancel only stops the stream and leaves the prompt in place (unchanged behavior). Esc and Ctrl-C share the same semantics -- both are user-initiated interrupts, so the decision rests solely on the guard, not on which key was pressed. Extracts the transcript-cleanup logic from handleUndoCommand into a reusable applyUndoToTranscriptState so the auto-undo path can share it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9897231 to
61f9e0c
Compare
- Fix semantic guard: check for any assistant entry (not non-empty content), since content is flushed into the entry object in place and may still be empty at guard evaluation time - Add four unit tests covering the auto-undo scenarios: no-output cancel withdraws prompt and refills editor; streamed text and tool_call prevent auto-undo; completed turns are not affected - Add changeset for @moonshot-ai/kimi-code (minor bump) - Update en/zh interaction guide and keyboard reference to document the new Esc/Ctrl-C behaviour Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61f9e0c to
2728e69
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolve part of #481
Problem
When the user interrupts a turn (Esc or Ctrl-C) before the model has produced any substantial content, the prompt is now automatically withdrawn from the transcript and its text is restored to the editor.
Previously, interrupting during the model's "thinking" phase only cancelled the stream — the prompt stayed in the context. The user would then type a new prompt, and the model would see both the abandoned one and the new one stitched together. This addresses that case from #481.

What changed
A semantic guard scans the current turn before undoing:
Esc and Ctrl-C share identical semantics here — both are user-initiated interrupts, so the decision rests solely on the guard, not on which key was pressed.
The transcript-cleanup logic was extracted from
handleUndoCommandinto a reusableapplyUndoToTranscriptState, shared by the new auto-undo path.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.