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")
|
|
|
|
|
}
|