-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(doctor): check config directory for plugin version detection #2282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { join } from "node:path" | |
| import { getLatestVersion } from "../../../hooks/auto-update-checker/checker" | ||
| import { extractChannel } from "../../../hooks/auto-update-checker" | ||
| import { PACKAGE_NAME } from "../constants" | ||
| import { getOpenCodeCacheDir, parseJsonc } from "../../../shared" | ||
| import { getOpenCodeConfigDir, parseJsonc } from "../../../shared" | ||
|
|
||
| interface PackageJsonShape { | ||
| version?: string | ||
|
|
@@ -26,16 +26,6 @@ function getPlatformDefaultCacheDir(platform: NodeJS.Platform = process.platform | |
| return join(homedir(), ".cache") | ||
| } | ||
|
|
||
| function resolveOpenCodeCacheDir(): string { | ||
| const xdgCacheHome = process.env.XDG_CACHE_HOME | ||
| if (xdgCacheHome) return join(xdgCacheHome, "opencode") | ||
|
|
||
| const fromShared = getOpenCodeCacheDir() | ||
| const platformDefault = join(getPlatformDefaultCacheDir(), "opencode") | ||
| if (existsSync(fromShared) || !existsSync(platformDefault)) return fromShared | ||
| return platformDefault | ||
| } | ||
|
|
||
| function readPackageJson(filePath: string): PackageJsonShape | null { | ||
| if (!existsSync(filePath)) return null | ||
|
|
||
|
|
@@ -53,8 +43,26 @@ function normalizeVersion(value: string | undefined): string | null { | |
| return match?.[0] ?? null | ||
| } | ||
|
|
||
| function resolvePluginInstallDir(): string { | ||
| const configDir = getOpenCodeConfigDir({ binary: "opencode", version: 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 | ||
|
|
||
| const xdgCacheHome = process.env.XDG_CACHE_HOME | ||
| if (xdgCacheHome) { | ||
|
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This fallback only inspects an XDG cache location when Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: On macOS, when Prompt for AI agents |
||
| const xdgDir = join(xdgCacheHome, "opencode") | ||
| if (existsSync(join(xdgDir, "node_modules", PACKAGE_NAME, "package.json"))) return xdgDir | ||
| } | ||
|
|
||
| return configDir | ||
| } | ||
|
|
||
| export function getLoadedPluginVersion(): LoadedVersionInfo { | ||
| const cacheDir = resolveOpenCodeCacheDir() | ||
| const cacheDir = resolvePluginInstallDir() | ||
| const cachePackagePath = join(cacheDir, "package.json") | ||
| const installedPackagePath = join(cacheDir, "node_modules", PACKAGE_NAME, "package.json") | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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_HOMEenvironment variable is checked AFTER the default platform cache directory. Per XDG Base Directory Specification, environment variable overrides should take precedence over defaults. The function checksgetPlatformDefaultCacheDir()beforeprocess.env.XDG_CACHE_HOME, meaning a stale installation in the default cache could be used even when the user has explicitly configuredXDG_CACHE_HOMEto a custom location.Prompt for AI agents