@@ -1696,15 +1696,20 @@ export class ClineProvider
16961696 * @param targetTask The task whose in-memory mode should be updated. Defaults to the
16971697 * current task. Pass null to apply only global mode/profile effects for a pending child.
16981698 */
1699- public async handleModeSwitch ( newMode : Mode , targetTask : Task | null | undefined = this . getCurrentTask ( ) ) {
1699+ public async handleModeSwitch (
1700+ newMode : Mode ,
1701+ targetTask : Task | null | undefined = this . getCurrentTask ( ) ,
1702+ options : { preparePendingTask ?: boolean } = { } ,
1703+ ) {
17001704 return this . enqueueProviderProfileMutation ( ( signal ) =>
1701- this . handleModeSwitchUnlocked ( newMode , targetTask , signal ) ,
1705+ this . handleModeSwitchUnlocked ( newMode , targetTask , options , signal ) ,
17021706 )
17031707 }
17041708
17051709 private async handleModeSwitchUnlocked (
17061710 newMode : Mode ,
17071711 targetTask : Task | null | undefined ,
1712+ options : { preparePendingTask ?: boolean } ,
17081713 signal ?: AbortSignal ,
17091714 ) : Promise < void > {
17101715 const task = targetTask
@@ -1744,7 +1749,7 @@ export class ClineProvider
17441749 // If workspace lock is on, keep the current API config — don't load mode-specific config
17451750 const lockApiConfigAcrossModes = this . context . workspaceState . get ( "lockApiConfigAcrossModes" , false )
17461751 if ( lockApiConfigAcrossModes ) {
1747- if ( targetTask !== null ) {
1752+ if ( targetTask !== null && ! options . preparePendingTask ) {
17481753 await this . postStateToWebview ( )
17491754 }
17501755 return
@@ -1778,7 +1783,15 @@ export class ClineProvider
17781783 if ( hasActualSettings ) {
17791784 await this . activateProviderProfileUnlocked (
17801785 { name : profile . name } ,
1781- targetTask === null ? { skipCurrentTaskRebuild : true } : undefined ,
1786+ targetTask === null
1787+ ? { skipCurrentTaskRebuild : true }
1788+ : options . preparePendingTask
1789+ ? {
1790+ skipCurrentTaskRebuild : true ,
1791+ applyProviderSettingsToContext : true ,
1792+ suppressStatePost : true ,
1793+ }
1794+ : undefined ,
17821795 signal ,
17831796 )
17841797 } else {
@@ -1800,7 +1813,7 @@ export class ClineProvider
18001813 }
18011814 }
18021815
1803- if ( targetTask !== null ) {
1816+ if ( targetTask !== null && ! options . preparePendingTask ) {
18041817 await this . postStateToWebview ( )
18051818 }
18061819 }
@@ -1978,6 +1991,8 @@ export class ClineProvider
19781991 persistModeConfig ?: boolean
19791992 persistTaskHistory ?: boolean
19801993 skipCurrentTaskRebuild ?: boolean
1994+ applyProviderSettingsToContext ?: boolean
1995+ suppressStatePost ?: boolean
19811996 } ,
19821997 ) {
19831998 return this . enqueueProviderProfileMutation ( ( signal ) =>
@@ -1991,6 +2006,8 @@ export class ClineProvider
19912006 persistModeConfig ?: boolean
19922007 persistTaskHistory ?: boolean
19932008 skipCurrentTaskRebuild ?: boolean
2009+ applyProviderSettingsToContext ?: boolean
2010+ suppressStatePost ?: boolean
19942011 } ,
19952012 signal ?: AbortSignal ,
19962013 ) : Promise < void > {
@@ -2001,8 +2018,10 @@ export class ClineProvider
20012018 const persistModeConfig = options ?. persistModeConfig ?? true
20022019 const persistTaskHistory = options ?. persistTaskHistory ?? true
20032020 const skipCurrentTaskRebuild = options ?. skipCurrentTaskRebuild ?? false
2021+ const applyProviderSettingsToContext = options ?. applyProviderSettingsToContext ?? ! skipCurrentTaskRebuild
2022+ const suppressStatePost = options ?. suppressStatePost ?? false
20042023
2005- if ( ! skipCurrentTaskRebuild ) {
2024+ if ( applyProviderSettingsToContext ) {
20062025 // See `upsertProviderProfile` for a description of what this is doing.
20072026 await Promise . all ( [
20082027 this . contextProxy . setValue ( "listApiConfigMeta" , await this . providerSettingsManager . listConfig ( ) ) ,
@@ -2026,7 +2045,7 @@ export class ClineProvider
20262045 await this . persistStickyProviderProfileToCurrentTask ( name , { skipCurrentTaskRebuild } )
20272046 }
20282047
2029- if ( ! skipCurrentTaskRebuild ) {
2048+ if ( ! skipCurrentTaskRebuild && ! suppressStatePost ) {
20302049 await this . postStateToWebview ( )
20312050 }
20322051
@@ -3885,7 +3904,7 @@ export class ClineProvider
38853904 // The mode switch must happen before createTask() because the Task constructor
38863905 // initializes its mode from provider.getState() during initializeTaskMode().
38873906 try {
3888- await this . handleModeSwitch ( mode as any )
3907+ await this . handleModeSwitch ( mode as any , undefined , { preparePendingTask : true } )
38893908 } catch ( e ) {
38903909 this . log (
38913910 `[delegateParentAndOpenChild] handleModeSwitch failed for mode '${ mode } ': ${
0 commit comments