Skip to content

fix(doctor): check config directory for plugin version detection#2282

Open
MoerAI wants to merge 1 commit intocode-yeongyu:devfrom
MoerAI:fix/doctor-version-config-dir
Open

fix(doctor): check config directory for plugin version detection#2282
MoerAI wants to merge 1 commit intocode-yeongyu:devfrom
MoerAI:fix/doctor-version-config-dir

Conversation

@MoerAI
Copy link
Contributor

@MoerAI MoerAI commented Mar 4, 2026

Summary

  • Fix doctor showing oh-my-opencode unknown when plugin is installed in config directory
  • The version detection was only checking ~/.cache/opencode/ but the plugin is typically installed in ~/.config/opencode/
  • Now checks config directory first (getOpenCodeConfigDir), then falls back to platform cache directory and XDG cache
  • Also fixes broken import of removed getOpenCodeCacheDir function

Fixes #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.

  • Bug Fixes
    • Detect plugin from config dir via getOpenCodeConfigDir, then fall back to platform cache and XDG cache.
    • Replace removed getOpenCodeCacheDir import and add resolvePluginInstallDir to centralize lookup.

Written for commit d53da2a. Summary will update on new commits.

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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +55 to +56
const xdgCacheHome = process.env.XDG_CACHE_HOME
if (xdgCacheHome) {

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

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_HOME is 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/opencode may never be checked when XDG_CACHE_HOME is 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) {
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

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

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>
Fix with Cubic

const configInstalled = join(configDir, "node_modules", PACKAGE_NAME, "package.json")
if (existsSync(configInstalled)) return configDir

const cacheDir = join(getPlatformDefaultCacheDir(), "opencode")
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

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

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>
Fix with Cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: doctor shows 'oh-my-opencode unknown' when plugin installed in config directory

1 participant