33ac57ba7a
Update various modules to use centralized constants from plugin-identity:
- get-local-version/formatter: Use PUBLISHED_PACKAGE_NAME
- run/session-resolver: Use PUBLISHED_PACKAGE_NAME
- background-agent/task-poller: Use PUBLISHED_PACKAGE_NAME
- mcp-oauth/provider: Use PUBLISHED_PACKAGE_NAME
- auto-update-checker/constants: Use ACCEPTED_PACKAGE_NAMES
- comment-checker/downloader: Use PUBLISHED_PACKAGE_NAME
- legacy-plugin-toast/hook: Use PLUGIN_NAME
- shared/data-path: Use CACHE_DIR_NAME
- shared/external-plugin-detector: Use ACCEPTED_PACKAGE_NAMES
- shared/logger: Use LOG_FILENAME
- tools/ast-grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/call-omo-agent/tools: Use PUBLISHED_PACKAGE_NAME
- tools/delegate-task/category-resolver: Use PUBLISHED_PACKAGE_NAME
- tools/grep/constants: Use PUBLISHED_PACKAGE_NAME
- tools/grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/lsp/lsp-client-wrapper: Use PUBLISHED_PACKAGE_NAME
🤖 Generated with assistance of OhMyOpenCode
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import * as path from "node:path"
|
|
import * as os from "node:os"
|
|
import { accessSync, constants, mkdirSync } from "node:fs"
|
|
|
|
import { CACHE_DIR_NAME } from "./plugin-identity"
|
|
|
|
function resolveWritableDirectory(preferredDir: string, fallbackSuffix: string): string {
|
|
try {
|
|
mkdirSync(preferredDir, { recursive: true })
|
|
accessSync(preferredDir, constants.W_OK)
|
|
return preferredDir
|
|
} catch {
|
|
const fallbackDir = path.join(os.tmpdir(), fallbackSuffix)
|
|
mkdirSync(fallbackDir, { recursive: true })
|
|
return fallbackDir
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the user-level data directory.
|
|
* Matches OpenCode's behavior via xdg-basedir:
|
|
* - All platforms: XDG_DATA_HOME or ~/.local/share
|
|
*
|
|
* Note: OpenCode uses xdg-basedir which returns ~/.local/share on ALL platforms
|
|
* including Windows, so we match that behavior exactly.
|
|
*/
|
|
export function getDataDir(): string {
|
|
const preferredDir = process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share")
|
|
return resolveWritableDirectory(preferredDir, "opencode-data")
|
|
}
|
|
|
|
/**
|
|
* Returns the OpenCode storage directory path.
|
|
* All platforms: ~/.local/share/opencode/storage
|
|
*/
|
|
export function getOpenCodeStorageDir(): string {
|
|
return path.join(getDataDir(), "opencode", "storage")
|
|
}
|
|
|
|
/**
|
|
* Returns the user-level cache directory.
|
|
* Matches OpenCode's behavior via xdg-basedir:
|
|
* - All platforms: XDG_CACHE_HOME or ~/.cache
|
|
*/
|
|
export function getCacheDir(): string {
|
|
const preferredDir = process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache")
|
|
return resolveWritableDirectory(preferredDir, "opencode-cache")
|
|
}
|
|
|
|
/**
|
|
* Returns the oh-my-opencode cache directory.
|
|
* All platforms: ~/.cache/oh-my-opencode
|
|
*/
|
|
export function getOmoOpenCodeCacheDir(): string {
|
|
return path.join(getCacheDir(), CACHE_DIR_NAME)
|
|
}
|
|
|
|
/**
|
|
* Returns the OpenCode cache directory (for reading OpenCode's cache).
|
|
* All platforms: ~/.cache/opencode
|
|
*/
|
|
export function getOpenCodeCacheDir(): string {
|
|
return path.join(getCacheDir(), "opencode")
|
|
}
|