From 7b7c14301e9ec47a2894fb5a662fcbc97aff2950 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 28 Dec 2025 16:13:50 +0900 Subject: [PATCH] fix(dcp): correct storage path to match OpenCode's actual location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DCP was failing to find session messages because it was looking in ~/.config/opencode/sessions instead of ~/.local/share/opencode/storage. Unified all hooks to use getOpenCodeStorageDir() for cross-platform consistency. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/hooks/agent-usage-reminder/constants.ts | 4 ++-- src/hooks/anthropic-auto-compact/storage.ts | 15 ++------------- .../directory-agents-injector/constants.ts | 4 ++-- .../directory-readme-injector/constants.ts | 4 ++-- .../interactive-bash-session/constants.ts | 4 ++-- src/hooks/rules-injector/constants.ts | 4 ++-- src/hooks/session-recovery/constants.ts | 4 ++-- src/shared/data-path.ts | 19 ++++++------------- 8 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/hooks/agent-usage-reminder/constants.ts b/src/hooks/agent-usage-reminder/constants.ts index 5ef7ba6..26e6c87 100644 --- a/src/hooks/agent-usage-reminder/constants.ts +++ b/src/hooks/agent-usage-reminder/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path"; -import { xdgData } from "xdg-basedir"; +import { getOpenCodeStorageDir } from "../../shared/data-path"; -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage"); +export const OPENCODE_STORAGE = getOpenCodeStorageDir(); export const AGENT_USAGE_REMINDER_STORAGE = join( OPENCODE_STORAGE, "agent-usage-reminder", diff --git a/src/hooks/anthropic-auto-compact/storage.ts b/src/hooks/anthropic-auto-compact/storage.ts index ddc0b80..750f77d 100644 --- a/src/hooks/anthropic-auto-compact/storage.ts +++ b/src/hooks/anthropic-auto-compact/storage.ts @@ -1,19 +1,8 @@ import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs" -import { homedir } from "node:os" import { join } from "node:path" -import { xdgData } from "xdg-basedir" - -let OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage") - -// Fix for macOS where xdg-basedir points to ~/Library/Application Support -// but OpenCode (cli) uses ~/.local/share -if (process.platform === "darwin" && !existsSync(OPENCODE_STORAGE)) { - const localShare = join(homedir(), ".local", "share", "opencode", "storage") - if (existsSync(localShare)) { - OPENCODE_STORAGE = localShare - } -} +import { getOpenCodeStorageDir } from "../../shared/data-path" +const OPENCODE_STORAGE = getOpenCodeStorageDir() const MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message") const PART_STORAGE = join(OPENCODE_STORAGE, "part") diff --git a/src/hooks/directory-agents-injector/constants.ts b/src/hooks/directory-agents-injector/constants.ts index 5208e85..3dc2e19 100644 --- a/src/hooks/directory-agents-injector/constants.ts +++ b/src/hooks/directory-agents-injector/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path"; -import { xdgData } from "xdg-basedir"; +import { getOpenCodeStorageDir } from "../../shared/data-path"; -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage"); +export const OPENCODE_STORAGE = getOpenCodeStorageDir(); export const AGENTS_INJECTOR_STORAGE = join( OPENCODE_STORAGE, "directory-agents", diff --git a/src/hooks/directory-readme-injector/constants.ts b/src/hooks/directory-readme-injector/constants.ts index 90c4b81..f5d9f49 100644 --- a/src/hooks/directory-readme-injector/constants.ts +++ b/src/hooks/directory-readme-injector/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path"; -import { xdgData } from "xdg-basedir"; +import { getOpenCodeStorageDir } from "../../shared/data-path"; -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage"); +export const OPENCODE_STORAGE = getOpenCodeStorageDir(); export const README_INJECTOR_STORAGE = join( OPENCODE_STORAGE, "directory-readme", diff --git a/src/hooks/interactive-bash-session/constants.ts b/src/hooks/interactive-bash-session/constants.ts index a43f058..9b2ce38 100644 --- a/src/hooks/interactive-bash-session/constants.ts +++ b/src/hooks/interactive-bash-session/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path"; -import { xdgData } from "xdg-basedir"; +import { getOpenCodeStorageDir } from "../../shared/data-path"; -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage"); +export const OPENCODE_STORAGE = getOpenCodeStorageDir(); export const INTERACTIVE_BASH_SESSION_STORAGE = join( OPENCODE_STORAGE, "interactive-bash-session", diff --git a/src/hooks/rules-injector/constants.ts b/src/hooks/rules-injector/constants.ts index 1e2ebb3..12e0467 100644 --- a/src/hooks/rules-injector/constants.ts +++ b/src/hooks/rules-injector/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path"; -import { xdgData } from "xdg-basedir"; +import { getOpenCodeStorageDir } from "../../shared/data-path"; -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage"); +export const OPENCODE_STORAGE = getOpenCodeStorageDir(); export const RULES_INJECTOR_STORAGE = join(OPENCODE_STORAGE, "rules-injector"); export const PROJECT_MARKERS = [ diff --git a/src/hooks/session-recovery/constants.ts b/src/hooks/session-recovery/constants.ts index 02c2d80..a45b802 100644 --- a/src/hooks/session-recovery/constants.ts +++ b/src/hooks/session-recovery/constants.ts @@ -1,7 +1,7 @@ import { join } from "node:path" -import { xdgData } from "xdg-basedir" +import { getOpenCodeStorageDir } from "../../shared/data-path" -export const OPENCODE_STORAGE = join(xdgData ?? "", "opencode", "storage") +export const OPENCODE_STORAGE = getOpenCodeStorageDir() export const MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message") export const PART_STORAGE = join(OPENCODE_STORAGE, "part") diff --git a/src/shared/data-path.ts b/src/shared/data-path.ts index 3f2b576..3e1cdee 100644 --- a/src/shared/data-path.ts +++ b/src/shared/data-path.ts @@ -2,27 +2,20 @@ import * as path from "node:path" import * as os from "node:os" /** - * Returns the user-level data directory based on the OS. - * - Linux/macOS: XDG_DATA_HOME or ~/.local/share - * - Windows: %LOCALAPPDATA% + * Returns the user-level data directory. + * Matches OpenCode's behavior via xdg-basedir: + * - All platforms: XDG_DATA_HOME or ~/.local/share * - * This follows XDG Base Directory specification on Unix systems - * and Windows conventions on Windows. + * Note: OpenCode uses xdg-basedir which returns ~/.local/share on ALL platforms + * including Windows, so we match that behavior exactly. */ export function getDataDir(): string { - if (process.platform === "win32") { - // Windows: Use %LOCALAPPDATA% (e.g., C:\Users\Username\AppData\Local) - return process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local") - } - - // Unix: Use XDG_DATA_HOME or fallback to ~/.local/share return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share") } /** * Returns the OpenCode storage directory path. - * - Linux/macOS: ~/.local/share/opencode/storage - * - Windows: %LOCALAPPDATA%\opencode\storage + * All platforms: ~/.local/share/opencode/storage */ export function getOpenCodeStorageDir(): string { return path.join(getDataDir(), "opencode", "storage")