fix(dcp): correct storage path to match OpenCode's actual location

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)
This commit is contained in:
YeonGyu-Kim
2025-12-28 16:13:50 +09:00
parent e3be656f86
commit 7b7c14301e
8 changed files with 20 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
import { join } from "node:path"; 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( export const AGENT_USAGE_REMINDER_STORAGE = join(
OPENCODE_STORAGE, OPENCODE_STORAGE,
"agent-usage-reminder", "agent-usage-reminder",

View File

@@ -1,19 +1,8 @@
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs" import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"
import { homedir } from "node:os"
import { join } from "node:path" import { join } from "node:path"
import { xdgData } from "xdg-basedir" import { getOpenCodeStorageDir } from "../../shared/data-path"
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
}
}
const OPENCODE_STORAGE = getOpenCodeStorageDir()
const MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message") const MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message")
const PART_STORAGE = join(OPENCODE_STORAGE, "part") const PART_STORAGE = join(OPENCODE_STORAGE, "part")

View File

@@ -1,7 +1,7 @@
import { join } from "node:path"; 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( export const AGENTS_INJECTOR_STORAGE = join(
OPENCODE_STORAGE, OPENCODE_STORAGE,
"directory-agents", "directory-agents",

View File

@@ -1,7 +1,7 @@
import { join } from "node:path"; 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( export const README_INJECTOR_STORAGE = join(
OPENCODE_STORAGE, OPENCODE_STORAGE,
"directory-readme", "directory-readme",

View File

@@ -1,7 +1,7 @@
import { join } from "node:path"; 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( export const INTERACTIVE_BASH_SESSION_STORAGE = join(
OPENCODE_STORAGE, OPENCODE_STORAGE,
"interactive-bash-session", "interactive-bash-session",

View File

@@ -1,7 +1,7 @@
import { join } from "node:path"; 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 RULES_INJECTOR_STORAGE = join(OPENCODE_STORAGE, "rules-injector");
export const PROJECT_MARKERS = [ export const PROJECT_MARKERS = [

View File

@@ -1,7 +1,7 @@
import { join } from "node:path" 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 MESSAGE_STORAGE = join(OPENCODE_STORAGE, "message")
export const PART_STORAGE = join(OPENCODE_STORAGE, "part") export const PART_STORAGE = join(OPENCODE_STORAGE, "part")

View File

@@ -2,27 +2,20 @@ import * as path from "node:path"
import * as os from "node:os" import * as os from "node:os"
/** /**
* Returns the user-level data directory based on the OS. * Returns the user-level data directory.
* - Linux/macOS: XDG_DATA_HOME or ~/.local/share * Matches OpenCode's behavior via xdg-basedir:
* - Windows: %LOCALAPPDATA% * - All platforms: XDG_DATA_HOME or ~/.local/share
* *
* This follows XDG Base Directory specification on Unix systems * Note: OpenCode uses xdg-basedir which returns ~/.local/share on ALL platforms
* and Windows conventions on Windows. * including Windows, so we match that behavior exactly.
*/ */
export function getDataDir(): string { 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") return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share")
} }
/** /**
* Returns the OpenCode storage directory path. * Returns the OpenCode storage directory path.
* - Linux/macOS: ~/.local/share/opencode/storage * All platforms: ~/.local/share/opencode/storage
* - Windows: %LOCALAPPDATA%\opencode\storage
*/ */
export function getOpenCodeStorageDir(): string { export function getOpenCodeStorageDir(): string {
return path.join(getDataDir(), "opencode", "storage") return path.join(getDataDir(), "opencode", "storage")