fix(doctor): check config directory for plugin version detection#2282
fix(doctor): check config directory for plugin version detection#2282MoerAI wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
The version detection was only checking the cache directory for the installed plugin, but the plugin is typically installed in the config directory (~/.config/opencode/). Now checks config directory first, then falls back to cache directory, fixing 'unknown' version display. Fixes code-yeongyu#2240
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d53da2af1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const xdgCacheHome = process.env.XDG_CACHE_HOME | ||
| if (xdgCacheHome) { |
There was a problem hiding this comment.
Check XDG default cache path even when env var is unset
This fallback only inspects an XDG cache location when XDG_CACHE_HOME is explicitly set, so on systems where OpenCode data is still under the default XDG path (~/.cache/opencode) the doctor check can miss an existing install and report loadedVersion as unknown. That is a regression from the previous resolver, which always considered the default XDG path via getOpenCodeCacheDir(), and it causes update/reinstall guidance to point at the wrong directory for affected users.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
2 issues found across 1 file
Confidence score: 3/5
- There is a concrete behavior risk in
src/cli/doctor/checks/system-loaded-version.ts:XDG_CACHE_HOMEis evaluated after platform defaults, which can ignore an explicit user override and violate expected XDG precedence. - A second path-resolution issue on macOS means
~/.cache/opencodemay never be checked whenXDG_CACHE_HOMEis unset, which can cause incorrect or missed results in the doctor check. - Given the medium severities (6/10 and 5/10) and high confidence on the top issue, this looks mergeable with caution but carries real user-impact risk in cache-location detection.
- Pay close attention to
src/cli/doctor/checks/system-loaded-version.ts- cache directory precedence/order and macOS fallback path handling need verification.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/cli/doctor/checks/system-loaded-version.ts">
<violation number="1" location="src/cli/doctor/checks/system-loaded-version.ts:51">
P2: Priority inversion: `XDG_CACHE_HOME` environment variable is checked AFTER the default platform cache directory. Per XDG Base Directory Specification, environment variable overrides should take precedence over defaults. The function checks `getPlatformDefaultCacheDir()` before `process.env.XDG_CACHE_HOME`, meaning a stale installation in the default cache could be used even when the user has explicitly configured `XDG_CACHE_HOME` to a custom location.</violation>
<violation number="2" location="src/cli/doctor/checks/system-loaded-version.ts:56">
P2: On macOS, when `XDG_CACHE_HOME` is not explicitly set, the default XDG cache path (`~/.cache/opencode`) is never checked. `getPlatformDefaultCacheDir()` returns `~/Library/Caches` on macOS, and the XDG branch at line 56 is only entered when the env var is explicitly set. This means macOS users who have the plugin installed at `~/.cache/opencode` (the XDG default) will get `unknown` version. Consider also checking `join(homedir(), '.cache', 'opencode')` as a fallback when `XDG_CACHE_HOME` is unset, to cover the default XDG path on non-Linux platforms.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| if (existsSync(cacheInstalled)) return cacheDir | ||
|
|
||
| const xdgCacheHome = process.env.XDG_CACHE_HOME | ||
| if (xdgCacheHome) { |
There was a problem hiding this comment.
P2: On macOS, when XDG_CACHE_HOME is not explicitly set, the default XDG cache path (~/.cache/opencode) is never checked. getPlatformDefaultCacheDir() returns ~/Library/Caches on macOS, and the XDG branch at line 56 is only entered when the env var is explicitly set. This means macOS users who have the plugin installed at ~/.cache/opencode (the XDG default) will get unknown version. Consider also checking join(homedir(), '.cache', 'opencode') as a fallback when XDG_CACHE_HOME is unset, to cover the default XDG path on non-Linux platforms.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli/doctor/checks/system-loaded-version.ts, line 56:
<comment>On macOS, when `XDG_CACHE_HOME` is not explicitly set, the default XDG cache path (`~/.cache/opencode`) is never checked. `getPlatformDefaultCacheDir()` returns `~/Library/Caches` on macOS, and the XDG branch at line 56 is only entered when the env var is explicitly set. This means macOS users who have the plugin installed at `~/.cache/opencode` (the XDG default) will get `unknown` version. Consider also checking `join(homedir(), '.cache', 'opencode')` as a fallback when `XDG_CACHE_HOME` is unset, to cover the default XDG path on non-Linux platforms.</comment>
<file context>
@@ -53,8 +43,26 @@ function normalizeVersion(value: string | undefined): string | null {
+ if (existsSync(cacheInstalled)) return cacheDir
+
+ const xdgCacheHome = process.env.XDG_CACHE_HOME
+ if (xdgCacheHome) {
+ const xdgDir = join(xdgCacheHome, "opencode")
+ if (existsSync(join(xdgDir, "node_modules", PACKAGE_NAME, "package.json"))) return xdgDir
</file context>
| const configInstalled = join(configDir, "node_modules", PACKAGE_NAME, "package.json") | ||
| if (existsSync(configInstalled)) return configDir | ||
|
|
||
| const cacheDir = join(getPlatformDefaultCacheDir(), "opencode") |
There was a problem hiding this comment.
P2: Priority inversion: XDG_CACHE_HOME environment variable is checked AFTER the default platform cache directory. Per XDG Base Directory Specification, environment variable overrides should take precedence over defaults. The function checks getPlatformDefaultCacheDir() before process.env.XDG_CACHE_HOME, meaning a stale installation in the default cache could be used even when the user has explicitly configured XDG_CACHE_HOME to a custom location.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli/doctor/checks/system-loaded-version.ts, line 51:
<comment>Priority inversion: `XDG_CACHE_HOME` environment variable is checked AFTER the default platform cache directory. Per XDG Base Directory Specification, environment variable overrides should take precedence over defaults. The function checks `getPlatformDefaultCacheDir()` before `process.env.XDG_CACHE_HOME`, meaning a stale installation in the default cache could be used even when the user has explicitly configured `XDG_CACHE_HOME` to a custom location.</comment>
<file context>
@@ -53,8 +43,26 @@ function normalizeVersion(value: string | undefined): string | null {
+ const configInstalled = join(configDir, "node_modules", PACKAGE_NAME, "package.json")
+ if (existsSync(configInstalled)) return configDir
+
+ const cacheDir = join(getPlatformDefaultCacheDir(), "opencode")
+ const cacheInstalled = join(cacheDir, "node_modules", PACKAGE_NAME, "package.json")
+ if (existsSync(cacheInstalled)) return cacheDir
</file context>
Summary
doctorshowingoh-my-opencode unknownwhen plugin is installed in config directory~/.cache/opencode/but the plugin is typically installed in~/.config/opencode/getOpenCodeConfigDir), then falls back to platform cache directory and XDG cachegetOpenCodeCacheDirfunctionFixes #2240
Summary by cubic
Fixes doctor plugin version detection by checking the config directory first, so the loaded version no longer shows “oh-my-opencode unknown” when installed in ~/.config/opencode. Fixes #2240.
Written for commit d53da2a. Summary will update on new commits.