| 185 | /* ---------- Path + config helpers ------------------------------------ */ |
| 186 | |
| 187 | function userDataDir(): string { |
| 188 | // Test/automation hook: point the CLI and MCP server at an explicit |
| 189 | // config directory instead of the per-OS Electron location. |
| 190 | const override = process.env.ZENNOTES_CONFIG_DIR?.trim() |
| 191 | if (override) return path.resolve(override) |
| 192 | |
| 193 | // Mirror Electron's `app.getPath('userData')` for product name "ZenNotes". |
| 194 | const home = os.homedir() |
| 195 | switch (process.platform) { |
| 196 | case 'darwin': |
| 197 | return path.join(home, 'Library', 'Application Support', 'ZenNotes') |
| 198 | case 'win32': |
| 199 | return path.join(process.env.APPDATA || path.join(home, 'AppData', 'Roaming'), 'ZenNotes') |
| 200 | default: |
| 201 | return path.join(process.env.XDG_CONFIG_HOME || path.join(home, '.config'), 'ZenNotes') |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | async function readConfigFile(): Promise<Record<string, unknown> | null> { |
| 206 | const configPath = path.join(userDataDir(), 'zennotes.config.json') |