@@ -91,6 +91,14 @@ type TraitsPersistence =
9191
9292const ULTRATHINK_PROMPT_PREFIX = "Ultrathink:\n" ;
9393
94+ const REASONING_SELECT_DESCRIPTOR_IDS : ReadonlySet < string > = new Set ( [
95+ "reasoningEffort" ,
96+ "reasoning" ,
97+ "effort" ,
98+ "variant" ,
99+ "thinking" ,
100+ ] ) ;
101+
94102function DefaultBadge ( ) {
95103 return (
96104 < Badge variant = "outline" size = "sm" className = "min-w-0" >
@@ -253,6 +261,97 @@ function getTraitsSectionVisibility(input: {
253261 } ;
254262}
255263
264+ function getTraitSelectChange (
265+ selected : ReturnType < typeof getSelectedTraits > ,
266+ descriptor : Extract < ProviderOptionDescriptor , { type : "select" } > ,
267+ prompt : string ,
268+ value : string ,
269+ ) {
270+ if ( ! value ) return null ;
271+ if ( descriptor . promptInjectedValues ?. includes ( value ) ) {
272+ return {
273+ prompt :
274+ prompt . trim ( ) . length === 0
275+ ? ULTRATHINK_PROMPT_PREFIX
276+ : applyClaudePromptEffortPrefix ( prompt , "ultrathink" ) ,
277+ } ;
278+ }
279+ const isPrimary = descriptor . id === selected . primarySelectDescriptor ?. id ;
280+ if ( isPrimary && selected . ultrathinkInBodyText ) return null ;
281+ return {
282+ prompt :
283+ isPrimary && selected . ultrathinkPromptControlled
284+ ? prompt . replace ( / ^ U l t r a t h i n k : \s * / i, "" )
285+ : prompt ,
286+ modelOptions : buildProviderOptionSelectionsFromDescriptors (
287+ replaceDescriptorCurrentValue ( selected . descriptors , descriptor . id , value ) ,
288+ ) ,
289+ } ;
290+ }
291+
292+ /**
293+ * `modelOptions` must already carry the composer's implicit defaults (see
294+ * `withImplicitFastModeDefault`) so the persisted selection matches what the
295+ * picker would write.
296+ */
297+ export function getReasoningTraitStep ( input : {
298+ provider : ProviderDriverKind ;
299+ instanceId : ProviderInstanceId ;
300+ model : string ;
301+ models : ReadonlyArray < ServerProviderModel > ;
302+ modelOptions : ProviderOptions | undefined ;
303+ reportedModelSelection : ModelSelection | null | undefined ;
304+ prompt : string ;
305+ planModeEnabled : boolean ;
306+ direction : 1 | - 1 ;
307+ } ) {
308+ const selected = getSelectedTraits (
309+ input . provider ,
310+ input . models ,
311+ input . model ,
312+ input . prompt ,
313+ input . modelOptions ,
314+ true ,
315+ input . planModeEnabled ,
316+ ) ;
317+ if ( selected . modelIsUnavailable || selected . ultrathinkInBodyText ) return null ;
318+ const descriptor = selected . selectDescriptors . find ( ( entry ) =>
319+ REASONING_SELECT_DESCRIPTOR_IDS . has ( entry . id ) ,
320+ ) ;
321+ if ( ! descriptor || descriptor . options . length < 2 ) return null ;
322+ const isPrimary = descriptor . id === selected . primarySelectDescriptor ?. id ;
323+ const current =
324+ isPrimary && selected . ultrathinkPromptControlled
325+ ? "ultrathink"
326+ : getDescriptorStringValue (
327+ descriptor ,
328+ { instanceId : input . instanceId , model : input . model , options : input . modelOptions ?? [ ] } ,
329+ input . reportedModelSelection ,
330+ ) ;
331+ const ordered = input . direction > 0 ? descriptor . options : descriptor . options . toReversed ( ) ;
332+ // A reported value outside the catalog, such as OpenCode's "default", steps
333+ // from the catalog default, or from the end when there is none.
334+ const position =
335+ [ current , getDescriptorStringValue ( descriptor ) ]
336+ . map ( ( value ) => ordered . findIndex ( ( option ) => option . id === value ) )
337+ . find ( ( index ) => index >= 0 ) ?? - 1 ;
338+ for ( const option of [
339+ ...ordered . slice ( position + 1 ) ,
340+ ...ordered . slice ( 0 , Math . max ( position , 0 ) ) ,
341+ ] ) {
342+ const change = getTraitSelectChange ( selected , descriptor , input . prompt , option . id ) ;
343+ if ( ! change ) return null ;
344+ if ( "modelOptions" in change ) {
345+ return change . modelOptions
346+ ? { prompt : change . prompt , modelOptions : change . modelOptions }
347+ : null ;
348+ }
349+ // A slash command refuses the Ultrathink prefix, so skip that level.
350+ if ( change . prompt . startsWith ( ULTRATHINK_PROMPT_PREFIX ) ) return change ;
351+ }
352+ return null ;
353+ }
354+
256355export function shouldRenderTraitsControls ( input : {
257356 provider : ProviderDriverKind ;
258357 models : ReadonlyArray < ServerProviderModel > ;
@@ -311,6 +410,15 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
311410 persistSticky : true ,
312411 } ) ;
313412 } ;
413+ const selected = getTraitsSectionVisibility ( {
414+ provider,
415+ models,
416+ model,
417+ prompt,
418+ modelOptions,
419+ allowPromptInjectedEffort,
420+ planModeEnabled,
421+ } ) ;
314422 const {
315423 descriptors,
316424 selectDescriptors,
@@ -320,15 +428,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
320428 ultrathinkInBodyText,
321429 hasAnyControls,
322430 modelIsUnavailable,
323- } = getTraitsSectionVisibility ( {
324- provider,
325- models,
326- model,
327- prompt,
328- modelOptions,
329- allowPromptInjectedEffort,
330- planModeEnabled,
331- } ) ;
431+ } = selected ;
332432 const updateDescriptors = ( nextDescriptors : ReadonlyArray < ProviderOptionDescriptor > ) => {
333433 updateModelOptions ( buildProviderOptionSelectionsFromDescriptors ( nextDescriptors ) ) ;
334434 } ;
@@ -337,21 +437,10 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
337437 descriptor : Extract < ProviderOptionDescriptor , { type : "select" } > ,
338438 value : string ,
339439 ) => {
340- if ( ! value ) return ;
341- if ( descriptor . promptInjectedValues ?. includes ( value ) ) {
342- const nextPrompt =
343- prompt . trim ( ) . length === 0
344- ? ULTRATHINK_PROMPT_PREFIX
345- : applyClaudePromptEffortPrefix ( prompt , "ultrathink" ) ;
346- onPromptChange ( nextPrompt ) ;
347- return ;
348- }
349- if ( ultrathinkInBodyText && descriptor . id === primarySelectDescriptor ?. id ) return ;
350- if ( ultrathinkPromptControlled && descriptor . id === primarySelectDescriptor ?. id ) {
351- const stripped = prompt . replace ( / ^ U l t r a t h i n k : \s * / i, "" ) ;
352- onPromptChange ( stripped ) ;
353- }
354- updateDescriptors ( replaceDescriptorCurrentValue ( descriptors , descriptor . id , value ) ) ;
440+ const change = getTraitSelectChange ( selected , descriptor , prompt , value ) ;
441+ if ( ! change ) return ;
442+ if ( change . prompt !== prompt ) onPromptChange ( change . prompt ) ;
443+ if ( "modelOptions" in change ) updateModelOptions ( change . modelOptions ) ;
355444 } ;
356445
357446 if ( ! hasAnyControls ) {
@@ -534,7 +623,7 @@ export function buildTraitsTriggerDisplay(input: {
534623 if (
535624 reasoningLabelIndex === - 1 &&
536625 descriptor . type === "select" &&
537- [ "reasoningEffort" , "reasoning" , "effort" , "variant" , "thinking" ] . includes ( descriptor . id )
626+ REASONING_SELECT_DESCRIPTOR_IDS . has ( descriptor . id )
538627 ) {
539628 reasoningLabelIndex = labels . length ;
540629 }
0 commit comments