Skip to content

fix(desktop): resolve WSL OpenCode from PATH - #44514

Closed
zjm54321 wants to merge 2 commits into
anomalyco:devfrom
zjm54321:wsl-path-fix
Closed

zjm54321 wants to merge 2 commits into
anomalyco:devfrom
zjm54321:wsl-path-fix

Conversation

@zjm54321

Copy link
Copy Markdown

Issue for this PR

Closes #38309

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The WSL setup only recognized $HOME/.opencode/bin/opencode, so installations from global npm, Nix, or Home Manager appeared missing even when opencode was available. Resolve opencode from the distro PATH first, then retain the existing fixed path as a fallback.

How did you verify your code works?

  • bun test src/main/wsl/runtime.test.ts from packages/desktop (2 passed)
  • bun typecheck from packages/desktop
  • pre-push repository typecheck (30/30 tasks)
  • verified the command resolves /etc/profiles/per-user/ming/bin/opencode on NixOS WSL

Screenshots / recordings

N/A (no UI change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI lite review requested due to automatic review settings August 23, 2026 19:38
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #44512: fix(desktop): use PATH for WSL probe

This appears to be a closely related PR addressing the same issue. Both PRs aim to resolve OpenCode from PATH in WSL environments. PR #44512 is focused on WSL probe detection using PATH, while PR #44514 (current) resolves the WSL OpenCode executable from PATH with a fallback. These are likely addressing related or overlapping aspects of the same issue (#38309).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes WSL OpenCode detection in the Desktop app by resolving the opencode executable from the distro’s PATH (supporting global npm/Nix/Home Manager installs) while keeping the legacy $HOME/.opencode/bin/opencode path as a fallback, addressing the “OpenCode not installed” false-negative in WSL.

Changes:

  • Update WSL runtime probing to resolve opencode via command -v opencode before falling back to $HOME/.opencode/bin/opencode.
  • Add unit tests validating PATH-first resolution and the fallback behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/desktop/src/main/wsl/runtime.ts Updates resolveWslOpencode to prefer resolving from distro PATH before using the fixed home-bin fallback.
packages/desktop/src/main/wsl/runtime.test.ts Adds tests to validate PATH-first resolution and fallback behavior for WSL OpenCode path discovery.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +42 to +45
"sh",
"-c",
'command -v opencode || { [ -x "$HOME/.opencode/bin/opencode" ] && printf "%s\\n" "$HOME/.opencode/bin/opencode"; }',
],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated in d38b26e. The test now asserts the filtered PATH script passed to WSL.

[
"sh",
"-c",
'command -v opencode || { [ -x "$HOME/.opencode/bin/opencode" ] && printf "%s\\n" "$HOME/.opencode/bin/opencode"; }',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in d38b26e: resolveWslOpencode now removes /mnt/* entries before command -v, matching the sidecar PATH policy.

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference, author can ignore or act on any point.

Overall: right fix direction — the old probe only accepted the fixed install path, so distro-managed installs were invisible, and stripping Windows interop entries before command -v correctly avoids resolving a Windows shim. A few notes:

  1. packages/desktop/src/main/wsl/runtime.ts:315 — the filter relies on awk -v RS=: treating RS as a regex (multi-character). That works on gawk and modern mawk, but busybox awk (Alpine, minimal images used as WSL distros) has historically been inconsistent here, and this runs before any opencode binary exists to guarantee anything about the environment. A pure-sh filter sidesteps the dialect question entirely, e.g. building the filtered PATH with case in an IFS=: loop, or tr ':' '\n' | grep -v ... | paste -sd :.

  2. Same line — /mnt/ hardcodes the default WSL automount root. Users who set a custom automountRoot (or disable appendWindowsPath but keep tools under another mountpoint) will either still get interop pollution (custom root ≠ /mnt) or lose legitimate distro-side entries installed under a /mnt path. Matching the interop entries more precisely (e.g. drive-letter roots like /mnt/?/:) or reading the automount setting would make this robust; worth at least a comment documenting the assumption.

  3. Minor: with both installs present, the PATH binary now silently wins over the managed ~/.opencode/bin/opencode — if the desktop app assumes its own managed version, logging which path was resolved (once, at probe time) will save future debugging.

Tests pin the exact argv and both resolution outcomes — good, though asserting on a substring (command -v opencode) instead of the full command string would make intentional edits less churn-y.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop 1.18.4 + WSL2 Ubuntu: shows 'OpenCode not installed' after install; version check fails

3 participants