fix(desktop): load WSL shell environment - #38252
Open
MrMushrooooom wants to merge 1 commit into
Open
Conversation
6 tasks
|
Would you be able to make this fix more generic for users whose WSL login shell is not Bash? I use zsh, and NVM initializes Node/npm from Could the sidecar detect the user’s configured login shell and load its environment instead of hardcoding Bash startup files? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the desktop WSL sidecar so it loads the user's WSL login environment before starting the OpenCode server.
When provider config uses environment interpolation such as:
{ "providers": { "company": { "options": { "apiKey": "{env:COMPANY_KEY}", "baseURL": "{env:COMPANY_BASEURL}" } } } }OpenCode launched from a WSL terminal sees variables exported by the user's shell startup files, but the desktop sidecar did not. The desktop then resolved
baseURLto an empty value and requests failed with errors such as"/chat/completions" cannot be parsed as a URL.Root cause
The desktop sidecar launched an explicit non-login shell:
Explicit WSL commands do not load the user's login startup files, unlike the shell environment used to launch the TUI. As a result, the server processes had different environments depending on which client started them.
Fix
~/.bash_profile~/.bash_login~/.profilebash -seserver script so the long-running sidecar behavior remains unchanged.Regression coverage
The new test creates a hermetic WSL-home fixture where
.profileloads.bashrc,.bashrcexportsCOMPANY_BASEURL, and a fake OpenCode executable reports the value inherited by the real generated sidecar command.Before the fix the test deterministically reports an empty value. After the fix it receives
https://company.example.Verification
bun test src/main/wsl/sidecar-shell.test.ts src/main/wsl/servers.test.ts src/renderer/wsl/connections.test.ts— 15 passedbun typecheckinpackages/desktop— passedThe recording environment is Linux rather than a Windows host, so the videos use a hermetic reproduction of the exact shell boundary and generated sidecar command. They compare the TUI-style interactive shell with the desktop sidecar before and after the change.
Before
https://github.com/anomalyco/opencode/releases/download/pr-38252-videos/wsl-env-before.mp4
After
https://github.com/anomalyco/opencode/releases/download/pr-38252-videos/wsl-env-after.mp4