Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ export class ClineProvider
includeDiagnosticMessages: includeDiagnosticMessages ?? true,
maxDiagnosticMessages: maxDiagnosticMessages ?? 50,
includeTaskHistoryInEnhance: includeTaskHistoryInEnhance ?? true,
remoteControlEnabled: remoteControlEnabled ?? false,
remoteControlEnabled,
}
}

Expand Down Expand Up @@ -1970,6 +1970,17 @@ export class ClineProvider
)
}

let remoteControlEnabled: boolean = false

try {
const cloudSettings = CloudService.instance.getUserSettings()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check - what happens if CloudService is not initialized yet? The code uses optional chaining but doesn't verify that CloudService.instance exists.

Consider adding a hasInstance() check before accessing the instance.

remoteControlEnabled = cloudSettings?.settings?.extensionBridgeEnabled ?? false
} catch (error) {
console.error(
`[getState] failed to get remote control setting from cloud: ${error instanceof Error ? error.message : String(error)}`,
)
}

// Return the same structure as before
return {
apiConfiguration: providerSettings,
Expand Down Expand Up @@ -2080,8 +2091,8 @@ export class ClineProvider
maxDiagnosticMessages: stateValues.maxDiagnosticMessages ?? 50,
// Add includeTaskHistoryInEnhance setting
includeTaskHistoryInEnhance: stateValues.includeTaskHistoryInEnhance ?? true,
// Add remoteControlEnabled setting
remoteControlEnabled: stateValues.remoteControlEnabled ?? false,
// Add remoteControlEnabled setting - get from cloud settings
remoteControlEnabled,
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,15 @@ export const webviewMessageHandler = async (
await provider.postStateToWebview()
break
case "remoteControlEnabled":
await updateGlobalState("remoteControlEnabled", message.bool ?? false)
// Update cloud settings instead of local globalState
try {
await CloudService.instance.updateUserSettings({
extensionBridgeEnabled: message.bool ?? false,
})
} catch (error) {
provider.log(`Failed to update cloud settings for remote control: ${error}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is only logged but doesn't provide user feedback. Should we show an error message to the user when cloud settings fail to update?

Consider adding a user-facing error notification.

// Don't fall back to local storage - cloud settings are the source of truth
}
await provider.handleRemoteControlToggle(message.bool ?? false)
await provider.postStateToWebview()
break
Expand Down
44 changes: 42 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,43 @@ export async function activate(context: vscode.ExtensionContext) {
// Initialize Roo Code Cloud service.
const postStateListener = () => ClineProvider.getVisibleInstance()?.postStateToWebview()
authStateChangedHandler = postStateListener
settingsUpdatedHandler = postStateListener

// Enhanced settings updated handler that also updates ExtensionBridgeService
settingsUpdatedHandler = async () => {
// Update ExtensionBridgeService when settings change
const userInfo = CloudService.instance.getUserInfo()
if (userInfo && CloudService.instance.cloudAPI) {
try {
const config = await CloudService.instance.cloudAPI.bridgeConfig()

const isCloudAgent =
typeof process.env.ROO_CODE_CLOUD_TOKEN === "string" && process.env.ROO_CODE_CLOUD_TOKEN.length > 0

const remoteControlEnabled = isCloudAgent
? true
: (CloudService.instance.getUserSettings()?.settings?.extensionBridgeEnabled ?? false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The error handling here only logs the error but doesn't provide any fallback value for remoteControlEnabled. If getUserSettings() returns null/undefined, the remote control state could be out of sync.

Consider ensuring the fallback value is always applied.


cloudLogger(`[CloudService] Settings updated - remoteControlEnabled = ${remoteControlEnabled}`)

ExtensionBridgeService.handleRemoteControlState(
userInfo,
remoteControlEnabled,
{
...config,
provider,
sessionId: vscode.env.sessionId,
},
cloudLogger,
)
} catch (error) {
cloudLogger(
`[CloudService] Failed to update ExtensionBridgeService on settings change: ${error instanceof Error ? error.message : String(error)}`,
)
}
}

postStateListener()
}

userInfoHandler = async ({ userInfo }: { userInfo: CloudUserInfo }) => {
postStateListener()
Expand All @@ -147,9 +183,13 @@ export async function activate(context: vscode.ExtensionContext) {

cloudLogger(`[CloudService] isCloudAgent = ${isCloudAgent}, socketBridgeUrl = ${config.socketBridgeUrl}`)

const remoteControlEnabled = isCloudAgent
? true
: (CloudService.instance.getUserSettings()?.settings?.extensionBridgeEnabled ?? false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic for determining remoteControlEnabled is duplicated from lines 144-146. Could we extract this into a helper function to avoid duplication?

For example:

function getRemoteControlEnabled(isCloudAgent: boolean): boolean {
    return isCloudAgent ? true : (CloudService.instance.getUserSettings()?.settings?.extensionBridgeEnabled ?? false);
}


ExtensionBridgeService.handleRemoteControlState(
userInfo,
isCloudAgent ? true : contextProxy.getValue("remoteControlEnabled"),
remoteControlEnabled,
{
...config,
provider,
Expand Down
Loading