@@ -10,6 +10,7 @@ import {
1010import { homedir } from "node:os" ;
1111import { dirname , join , resolve } from "node:path" ;
1212import { fileURLToPath } from "node:url" ;
13+ import type { ProjectLocation } from "@/shared/contracts" ;
1314import { toWslUncPath } from "@/shared/wsl" ;
1415import type { AgentEnvContext } from "../../base" ;
1516import { resolveWslHomeDirectory } from "../../base" ;
@@ -233,11 +234,10 @@ export function installOpenCodePlugin(
233234 }
234235
235236 // Best-effort: scrub the dead `file://...` entry older lightcode versions
236- // wrote into opencode.json, and merge the browser MCP entry in one
237- // read/write cycle. Failure here doesn't block install — the plugin is
238- // already loadable via auto-discovery.
237+ // wrote into opencode.json. Browser MCP is synced at OpenCode launch time so
238+ // it can honor the user's provider setting.
239239 const nativeConfigPath = join ( resolveOpenCodeNativeConfigDir ( ) , OPENCODE_CONFIG_FILE_NAME ) ;
240- updateOpenCodeConfigFile ( nativeConfigPath , buildOpenCodeBrowserMcp ( { kind : "windows" } ) ) ;
240+ updateOpenCodeConfigFile ( nativeConfigPath , undefined ) ;
241241
242242 console . log (
243243 `[supervisor] OpenCode hook plugin staged v${ manifest . version } at ${ pluginDir } ` +
@@ -286,11 +286,12 @@ function installOpenCodePluginWsl(
286286 } ;
287287 }
288288
289- // Same scrub on the WSL-side opencode.json — in one read/write cycle.
289+ // Same scrub on the WSL-side opencode.json. Browser MCP is synced at launch
290+ // time so it can honor the user's provider setting.
290291 const cfgDir = resolveOpenCodeWslConfigDir ( distro ) ;
291292 if ( cfgDir ) {
292293 const wslConfigPath = `${ cfgDir . uncDir } \\${ OPENCODE_CONFIG_FILE_NAME } ` ;
293- updateOpenCodeConfigFile ( wslConfigPath , buildOpenCodeBrowserMcp ( { kind : "wsl" , distro } ) ) ;
294+ updateOpenCodeConfigFile ( wslConfigPath , undefined ) ;
294295 }
295296
296297 console . log (
@@ -469,6 +470,26 @@ function updateOpenCodeConfigFile(configPath: string, servers: BrowserMcpServers
469470 }
470471}
471472
473+ export function syncOpenCodeBrowserMcpConfigFile (
474+ location : ProjectLocation ,
475+ enabled : boolean ,
476+ ) : void {
477+ if ( location . kind === "wsl" ) {
478+ const cfgDir = resolveOpenCodeWslConfigDir ( location . distro ) ;
479+ if ( ! cfgDir ) return ;
480+ updateOpenCodeConfigFile (
481+ `${ cfgDir . uncDir } \\${ OPENCODE_CONFIG_FILE_NAME } ` ,
482+ enabled ? buildOpenCodeBrowserMcp ( location ) : undefined ,
483+ ) ;
484+ return ;
485+ }
486+
487+ updateOpenCodeConfigFile (
488+ join ( resolveOpenCodeNativeConfigDir ( ) , OPENCODE_CONFIG_FILE_NAME ) ,
489+ enabled ? buildOpenCodeBrowserMcp ( location ) : undefined ,
490+ ) ;
491+ }
492+
472493/**
473494 * Removes the dropped plugin file from OpenCode's plugins/ directory and any
474495 * legacy drops, plus scrubs the lightcode entry from opencode.json. Staging
0 commit comments