2025-12-13 01:18:39 +09:00
|
|
|
import * as path from "node:path"
|
|
|
|
|
import * as os from "node:os"
|
2026-01-02 14:28:44 +09:00
|
|
|
import * as fs from "node:fs"
|
2025-12-13 01:18:39 +09:00
|
|
|
|
|
|
|
|
export const PACKAGE_NAME = "oh-my-opencode"
|
|
|
|
|
export const NPM_REGISTRY_URL = `https://registry.npmjs.org/-/package/${PACKAGE_NAME}/dist-tags`
|
|
|
|
|
export const NPM_FETCH_TIMEOUT = 5000
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OpenCode plugin cache directory
|
|
|
|
|
* - Linux/macOS: ~/.cache/opencode/
|
|
|
|
|
* - Windows: %LOCALAPPDATA%/opencode/
|
|
|
|
|
*/
|
|
|
|
|
function getCacheDir(): string {
|
|
|
|
|
if (process.platform === "win32") {
|
|
|
|
|
return path.join(process.env.LOCALAPPDATA ?? os.homedir(), "opencode")
|
|
|
|
|
}
|
|
|
|
|
return path.join(os.homedir(), ".cache", "opencode")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CACHE_DIR = getCacheDir()
|
|
|
|
|
export const VERSION_FILE = path.join(CACHE_DIR, "version")
|
|
|
|
|
export const INSTALLED_PACKAGE_JSON = path.join(
|
|
|
|
|
CACHE_DIR,
|
|
|
|
|
"node_modules",
|
|
|
|
|
PACKAGE_NAME,
|
|
|
|
|
"package.json"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OpenCode config file locations (priority order)
|
2026-01-02 14:28:44 +09:00
|
|
|
* On Windows, checks ~/.config first (cross-platform), then %APPDATA% (fallback)
|
|
|
|
|
* This matches shared/config-path.ts behavior for consistency
|
2025-12-13 01:18:39 +09:00
|
|
|
*/
|
|
|
|
|
function getUserConfigDir(): string {
|
|
|
|
|
if (process.platform === "win32") {
|
2026-01-02 14:28:44 +09:00
|
|
|
const crossPlatformDir = path.join(os.homedir(), ".config")
|
|
|
|
|
const appdataDir = process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming")
|
|
|
|
|
|
|
|
|
|
// Check cross-platform path first (~/.config)
|
|
|
|
|
const crossPlatformConfig = path.join(crossPlatformDir, "opencode", "opencode.json")
|
|
|
|
|
const crossPlatformConfigJsonc = path.join(crossPlatformDir, "opencode", "opencode.jsonc")
|
|
|
|
|
|
|
|
|
|
if (fs.existsSync(crossPlatformConfig) || fs.existsSync(crossPlatformConfigJsonc)) {
|
|
|
|
|
return crossPlatformDir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fall back to %APPDATA%
|
|
|
|
|
return appdataDir
|
2025-12-13 01:18:39 +09:00
|
|
|
}
|
|
|
|
|
return process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config")
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 14:28:44 +09:00
|
|
|
/**
|
|
|
|
|
* Get the Windows-specific APPDATA directory (for fallback checks)
|
|
|
|
|
*/
|
|
|
|
|
export function getWindowsAppdataDir(): string | null {
|
|
|
|
|
if (process.platform !== "win32") return null
|
|
|
|
|
return process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming")
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-13 01:18:39 +09:00
|
|
|
export const USER_CONFIG_DIR = getUserConfigDir()
|
|
|
|
|
export const USER_OPENCODE_CONFIG = path.join(USER_CONFIG_DIR, "opencode", "opencode.json")
|
2025-12-15 08:39:21 +09:00
|
|
|
export const USER_OPENCODE_CONFIG_JSONC = path.join(USER_CONFIG_DIR, "opencode", "opencode.jsonc")
|