fix: Prefill every parameter editor with the value it has - #625
Merged
Conversation
Interactive mode shows the value each parameter was given, but opening one to change it starts from nothing: a text prompt opens blank, a list opens with nothing selected, a confirm opens on true whatever the value is, and an object parameter is edited on an empty params object, so its value is dropped the moment it is looked at. Every editor now opens on the value the parameter has, whether it came from an argument, from the JSON piped in, or from an earlier trip through the menu. Params are passed through as given, so a value need not match the format its parameter documents: one that does not fit the editor is left out of it and the editor opens as it does for an unset parameter. A resource picker opens on the resource already chosen, unless the list does not offer it — clack answers with no value at all for a selection with no choice behind it, which would blank the parameter. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BFLnh3eSDcivDPtu8r1bBy
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.
Closes the same hole as #624, and the rest of it: opening a parameter to change it should never start from a blank.
The problem
Interactive mode already lists every parameter with the value it was given — from
--flags, from the JSON piped in, or from an earlier trip through the menu. But every editor behind that list opens from nothing:--search 'foo bar',--limit 25,--sort-direction desc, …promptText)promptNumber)promptSelect)promptAutocompleteMultiselect)promptConfirm)true, even when the value isfalseinteractForBlueprintObject)params: {}— the value is dropped as soon as it is looked atinteractForResource)The object row is the data-loss one #624 found, and it is worth restating:
interactForBlueprintObjectopens the sub-editor onparams: {}, so leaving with[Back]or dismissing returns those empty params, the parent menu assigns them over what was given, and the request body goes out with{}. That is 30 request parameters in the current schema,/acs/users/create --access-scheduleand/access_grants/create --user-identityamong them. The list and metadata editors were already seeded (args.params[paramToEdit] || []/|| {}); the object editor was the one that was not.All of it contradicts the README (
--interactive"is prefilled with whatever you passed as arguments") and this function's own comment that dismissing a prompt returns to the menu "with the parameter left as it was".What changed
src/lib/prompt.ts—initialValueon the text, number and select options,initialValueson a newPromptMultiselectOptions, each passed to the clack prompt that already supports it. Undefined is stripped rather than passed through, since clack's option types plusexactOptionalPropertyTypesreject an explicitundefined.offeredValue/offeredValues— a value is only handed to a list prompt when the list offers it. This one is load-bearing rather than defensive: clack's autocomplete answersundefinedfor a selection with no choice behind it, so--device-id dev_deletedwould have blanked the parameter on the way through the picker. Verified against the real prompt, not assumed:src/lib/interactions/blueprint-object.ts— each branch opens its editor on the current value, viatoText/toNumber/toBoolean/toTextList/toRecord. Params are passed through as given, so a value need not match the format its parameter documents — the JSON piped in is arbitrary, and a schema can change under a script. A value the editor cannot start from is left out of it, opening the editor exactly as it does for an unset parameter. That also fixesinteractForArraybeing handed a bare string and spreading it into characters.resource,device,access-code,connected-account,user-identity,acs-*) — take the resource already chosen and open on it.interactForAcsSystemnow takes an options object, so itsmessageandinitialValuecannot be confused for one another.interactForCustomMetadata— the one prompt that both adds and edits a key opens on that key's current value.src/lib/memory-prompt.ts— records what each question was seeded with, so a test can assert on what the user would see.Nothing is taken away:
Unset,Set to nulland[Leave Empty]all still clear a value, and dismissing an editor still returns to the menu with the parameter as it was.Verification
npm test,npm run typecheck,npm run lint— 311 tests passing (286 before), clean type-check and lint.25 tests added across
test/interactions/blueprint-object.test.ts,test/interactions/custom-metadata.test.tsandsrc/lib/prompt.test.ts. 13 of them fail on this tree without the source change; the "opens empty" cases stay green both ways, holding the unchanged behavior in place:The clack behavior this rests on was also checked directly against the real prompts rather than inferred from the types — a prefilled text prompt renders its value and returns it edited (
"foo bar"+" baz"→"foo bar baz"), and a list opens on the value given.Generated by Claude Code