* Return the path to OpenCode's SQLite database. * * Resolution order: * 1. $XDG_DATA_HOME/opencode/opencode.db — explicit override always wins * 2. ~/Library/Application Support/opencode/opencode.db — macOS native path * (checked only when the file actually exists, so Linux is never pe
()
| 39 | * 3. ~/.local/share/opencode/opencode.db — XDG default for Linux + macOS |
| 40 | */ |
| 41 | function getDbPath(): string { |
| 42 | if (process.env['XDG_DATA_HOME']) { |
| 43 | return join(process.env['XDG_DATA_HOME'], 'opencode', 'opencode.db'); |
| 44 | } |
| 45 | |
| 46 | if (process.platform === 'darwin') { |
| 47 | const macPath = join( |
| 48 | homedir(), |
| 49 | 'Library', |
| 50 | 'Application Support', |
| 51 | 'opencode', |
| 52 | 'opencode.db', |
| 53 | ); |
| 54 | if (existsSync(macPath)) return macPath; |
| 55 | } |
| 56 | |
| 57 | return join(homedir(), '.local', 'share', 'opencode', 'opencode.db'); |
| 58 | } |
| 59 | |
| 60 | function tryOpenDb(): SQLiteDatabase | null { |
| 61 | const dbPath = getDbPath(); |
no outgoing calls
no test coverage detected