2025-12-25 17:04:16 +09:00
|
|
|
import * as path from "node:path"
|
|
|
|
|
import * as os from "node:os"
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-28 16:13:50 +09:00
|
|
|
* Returns the user-level data directory.
|
|
|
|
|
* Matches OpenCode's behavior via xdg-basedir:
|
|
|
|
|
* - All platforms: XDG_DATA_HOME or ~/.local/share
|
2025-12-25 17:04:16 +09:00
|
|
|
*
|
2025-12-28 16:13:50 +09:00
|
|
|
* Note: OpenCode uses xdg-basedir which returns ~/.local/share on ALL platforms
|
|
|
|
|
* including Windows, so we match that behavior exactly.
|
2025-12-25 17:04:16 +09:00
|
|
|
*/
|
|
|
|
|
export function getDataDir(): string {
|
|
|
|
|
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the OpenCode storage directory path.
|
2025-12-28 16:13:50 +09:00
|
|
|
* All platforms: ~/.local/share/opencode/storage
|
2025-12-25 17:04:16 +09:00
|
|
|
*/
|
|
|
|
|
export function getOpenCodeStorageDir(): string {
|
|
|
|
|
return path.join(getDataDir(), "opencode", "storage")
|
|
|
|
|
}
|
2026-01-26 11:53:41 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user-level cache directory.
|
|
|
|
|
* Matches OpenCode's behavior via xdg-basedir:
|
|
|
|
|
* - All platforms: XDG_CACHE_HOME or ~/.cache
|
|
|
|
|
*/
|
|
|
|
|
export function getCacheDir(): string {
|
|
|
|
|
return process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the oh-my-opencode cache directory.
|
|
|
|
|
* All platforms: ~/.cache/oh-my-opencode
|
|
|
|
|
*/
|
|
|
|
|
export function getOmoOpenCodeCacheDir(): string {
|
|
|
|
|
return path.join(getCacheDir(), "oh-my-opencode")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the OpenCode cache directory (for reading OpenCode's cache).
|
|
|
|
|
* All platforms: ~/.cache/opencode
|
|
|
|
|
*/
|
|
|
|
|
export function getOpenCodeCacheDir(): string {
|
|
|
|
|
return path.join(getCacheDir(), "opencode")
|
|
|
|
|
}
|