fix: Return to the previous prompt when one is dismissed - #607
Merged
Conversation
Dismissing a prompt ended the whole command, so escaping out of a single mistyped or misread answer, such as picking the wrong connected account, threw away every parameter gathered so far. The prompts already report a dismissal; only the flows around them treated it as fatal. Each step of a flow now catches it and returns to the step before, so a dismissal abandons an answer rather than the command. Dismissing the top level command menu still stops the CLI, since there is no step to go back to. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyVFq6gYChW9wtoDq8CHsD
The new behaviour was invisible: prompts still only advertised the keys clack knows about. Note it on the message of every prompt whose flow returns to the step before, and only those, so it never claims a way back that does not exist. Clack renders its keyboard hints from a hardcoded list that a caller cannot add to, so the note goes on the message rather than that line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyVFq6gYChW9wtoDq8CHsD
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.
Summary
Dismissing a prompt ended the whole command. Escaping out of a single mistyped or misread answer — picking the wrong connected account for
connected_account_id, say — threw away every parameter gathered so far and exited.Now a dismissal abandons that one answer and returns to the step before it, and the prompt says so:
Implementation
No new machinery. The prompts already reported a dismissal as
PromptCancelledError; the only place it was handled was the top-level catch insrc/bin/cli.ts, which ends the command. Each step of a flow now catches it and returns to the step before.Escape and ctrl-c are treated identically — neither is special-cased, and nothing inspects which key was pressed.
The hint comes from one small helper,
withBackHintinsrc/lib/util/prompt.ts, applied to the message of each prompt whose caller catches the dismissal — and only those, so it never promises a way back that does not exist. It goes on the message because clack builds its keyboard hint line from a hardcoded list:autocompletehas no option for it at all (@clack/prompts/dist/index.mjs:191-195), andshowInstructionsonselect/multiselectonly toggles the stock text on or off. Making that line itself customizable needs an upstream change to clack, worth a separate PR.Behavior
[Back]entry[Back]entryA dismissal with no step to go back to still stops the CLI with
Cancelledand exit code 1, exactly as before.Note on exiting
With ctrl-c now going back a level, leaving a deep flow in one keystroke is worth a follow-up. ctrl-d looks like it exits, but only by accident: it closes clack's readline, the prompt promise never settles, and Node bails with exit code 13 and an unsettled-promise warning, so no error handling or message runs. Verified in a pty. Happy to make that a clean exit separately — it needs care not to leave the terminal in raw mode.
Testing
src/lib/interact-for-blueprint-object.test.ts— dismissing the parameter menu leaves the command; dismissing a value prompt returns to the menu with the parameter unset; a previously supplied value survives a dismissal; the menu and value prompts carry the hint.src/lib/interact-for-command-selection.test.ts— a sub-command menu is hinted, the top-level menu is not.interact-for-custom-metadata.test.tsnow replace only the prompts, so the realPromptCancelledErrorandwithBackHintare exercised.Full suite green: 181 tests across 18 files, plus typecheck, lint, and formatting.