diff --git a/src/hooks/comment-checker/cli.ts b/src/hooks/comment-checker/cli.ts index ee6d382..2b938c2 100644 --- a/src/hooks/comment-checker/cli.ts +++ b/src/hooks/comment-checker/cli.ts @@ -23,6 +23,19 @@ function getBinaryName(): string { function findCommentCheckerPathSync(): string | null { const binaryName = getBinaryName() + // Check cached binary first (safest path - no module resolution needed) + const cachedPath = getCachedBinaryPath() + if (cachedPath) { + debugLog("found binary in cache:", cachedPath) + return cachedPath + } + + // Guard against undefined import.meta.url (can happen on Windows during plugin loading) + if (!import.meta.url) { + debugLog("import.meta.url is undefined, skipping package resolution") + return null + } + try { const require = createRequire(import.meta.url) const cliPkgPath = require.resolve("@code-yeongyu/comment-checker/package.json") @@ -33,14 +46,8 @@ function findCommentCheckerPathSync(): string | null { debugLog("found binary in main package:", binaryPath) return binaryPath } - } catch { - debugLog("main package not installed") - } - - const cachedPath = getCachedBinaryPath() - if (cachedPath) { - debugLog("found binary in cache:", cachedPath) - return cachedPath + } catch (err) { + debugLog("main package not installed or resolution failed:", err) } debugLog("no binary found in known locations") diff --git a/src/hooks/comment-checker/downloader.ts b/src/hooks/comment-checker/downloader.ts index 81646a4..c260c4e 100644 --- a/src/hooks/comment-checker/downloader.ts +++ b/src/hooks/comment-checker/downloader.ts @@ -32,9 +32,16 @@ const PLATFORM_MAP: Record = { /** * Get the cache directory for oh-my-opencode binaries. - * Follows XDG Base Directory Specification. + * On Windows: Uses %LOCALAPPDATA% or %APPDATA% (Windows conventions) + * On Unix: Follows XDG Base Directory Specification */ export function getCacheDir(): string { + if (process.platform === "win32") { + const localAppData = process.env.LOCALAPPDATA || process.env.APPDATA + const base = localAppData || join(homedir(), "AppData", "Local") + return join(base, "oh-my-opencode", "bin") + } + const xdgCache = process.env.XDG_CACHE_HOME const base = xdgCache || join(homedir(), ".cache") return join(base, "oh-my-opencode", "bin")