Skip to content

Commit bc34db1

Browse files
committed
feat(core): add toggleable sticky modes setting
1 parent f06567d commit bc34db1

File tree

7 files changed

+43
-22
lines changed

7 files changed

+43
-22
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -781,36 +781,44 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
781781

782782
await this.updateGlobalState("mode", newMode)
783783

784-
// Load the saved API config for the new mode if it exists
785-
const savedConfigId = await this.providerSettingsManager.getModeConfigId(newMode)
786-
const listApiConfig = await this.providerSettingsManager.listConfig()
784+
const stickyModesEnabled = this.getGlobalState("stickyModesEnabled") ?? true
787785

788-
// Update listApiConfigMeta first to ensure UI has latest data
789-
await this.updateGlobalState("listApiConfigMeta", listApiConfig)
786+
if (stickyModesEnabled) {
787+
// Load the saved API config for the new mode if it exists
788+
const savedConfigId = await this.providerSettingsManager.getModeConfigId(newMode)
789+
const listApiConfig = await this.providerSettingsManager.listConfig()
790790

791-
// If this mode has a saved config, use it
792-
if (savedConfigId) {
793-
const config = listApiConfig?.find((c) => c.id === savedConfigId)
791+
// Update listApiConfigMeta first to ensure UI has latest data
792+
await this.updateGlobalState("listApiConfigMeta", listApiConfig)
794793

795-
if (config?.name) {
796-
const apiConfig = await this.providerSettingsManager.loadConfig(config.name)
794+
// If this mode has a saved config, use it
795+
if (savedConfigId) {
796+
const config = listApiConfig?.find((c) => c.id === savedConfigId)
797797

798-
await Promise.all([
799-
this.updateGlobalState("currentApiConfigName", config.name),
800-
this.updateApiConfiguration(apiConfig),
801-
])
802-
}
803-
} else {
804-
// If no saved config for this mode, save current config as default
805-
const currentApiConfigName = this.getGlobalState("currentApiConfigName")
798+
if (config?.name) {
799+
const apiConfig = await this.providerSettingsManager.loadConfig(config.name)
800+
801+
await Promise.all([
802+
this.updateGlobalState("currentApiConfigName", config.name),
803+
this.updateApiConfiguration(apiConfig),
804+
])
805+
}
806+
} else {
807+
// If no saved config for this mode, save current config as default
808+
const currentApiConfigName = this.getGlobalState("currentApiConfigName")
806809

807-
if (currentApiConfigName) {
808-
const config = listApiConfig?.find((c) => c.name === currentApiConfigName)
810+
if (currentApiConfigName) {
811+
const config = listApiConfig?.find((c) => c.name === currentApiConfigName)
809812

810-
if (config?.id) {
811-
await this.providerSettingsManager.setModeConfig(newMode, config.id)
813+
if (config?.id) {
814+
await this.providerSettingsManager.setModeConfig(newMode, config.id)
815+
}
812816
}
813817
}
818+
} else {
819+
// If sticky modes are disabled, ensure we don't accidentally load a stale config
820+
const listApiConfig = await this.providerSettingsManager.listConfig()
821+
await this.updateGlobalState("listApiConfigMeta", listApiConfig)
814822
}
815823

816824
await this.postStateToWebview()
@@ -1226,6 +1234,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12261234
showRooIgnoredFiles,
12271235
language,
12281236
maxReadFileLine,
1237+
stickyModesEnabled,
12291238
} = await this.getState()
12301239

12311240
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1310,6 +1319,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13101319
maxReadFileLine: maxReadFileLine ?? 500,
13111320
settingsImportedAt: this.settingsImportedAt,
13121321
hasSystemPromptOverride,
1322+
stickyModesEnabled: stickyModesEnabled ?? true,
13131323
}
13141324
}
13151325

@@ -1397,6 +1407,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13971407
telemetrySetting: stateValues.telemetrySetting || "unset",
13981408
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
13991409
maxReadFileLine: stateValues.maxReadFileLine ?? 500,
1410+
stickyModesEnabled: stateValues.stickyModesEnabled ?? true,
14001411
}
14011412
}
14021413

src/core/webview/webviewMessageHandler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,10 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
939939
await updateGlobalState("showRooIgnoredFiles", message.bool ?? true)
940940
await provider.postStateToWebview()
941941
break
942+
case "stickyModesEnabled":
943+
await updateGlobalState("stickyModesEnabled", message.bool ?? true)
944+
await provider.postStateToWebview()
945+
break
942946
case "maxReadFileLine":
943947
await updateGlobalState("maxReadFileLine", message.value)
944948
await provider.postStateToWebview()

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ type GlobalSettings = {
354354
}
355355
| undefined
356356
enhancementApiConfigId?: string | undefined
357+
stickyModesEnabled?: boolean | undefined
357358
}
358359

359360
type ClineMessage = {

src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ type GlobalSettings = {
357357
}
358358
| undefined
359359
enhancementApiConfigId?: string | undefined
360+
stickyModesEnabled?: boolean | undefined
360361
}
361362

362363
export type { GlobalSettings }

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ export const globalSettingsSchema = z.object({
565565
customModePrompts: customModePromptsSchema.optional(),
566566
customSupportPrompts: customSupportPromptsSchema.optional(),
567567
enhancementApiConfigId: z.string().optional(),
568+
stickyModesEnabled: z.boolean().optional(),
568569
})
569570

570571
export type GlobalSettings = z.infer<typeof globalSettingsSchema>
@@ -641,6 +642,7 @@ const globalSettingsRecord: GlobalSettingsRecord = {
641642
customSupportPrompts: undefined,
642643
enhancementApiConfigId: undefined,
643644
cachedChromeHostUrl: undefined,
645+
stickyModesEnabled: undefined,
644646
}
645647

646648
export const GLOBAL_SETTINGS_KEYS = Object.keys(globalSettingsRecord) as Keys<GlobalSettings>[]

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export type ExtensionState = Pick<
171171
| "customModePrompts"
172172
| "customSupportPrompts"
173173
| "enhancementApiConfigId"
174+
| "stickyModesEnabled"
174175
> & {
175176
version: string
176177
clineMessages: ClineMessage[]

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface WebviewMessage {
125125
| "maxReadFileLine"
126126
| "searchFiles"
127127
| "toggleApiConfigPin"
128+
| "stickyModesEnabled"
128129
text?: string
129130
disabled?: boolean
130131
askResponse?: ClineAskResponse

0 commit comments

Comments
 (0)