| 392 | }) |
| 393 | |
| 394 | async function resolveConfigPath(baseDir: string, global = false) { |
| 395 | // Check for existing config files (prefer .jsonc over .json, check .opencode/ subdirectory too) |
| 396 | const candidates = [path.join(baseDir, "opencode.json"), path.join(baseDir, "opencode.jsonc")] |
| 397 | |
| 398 | if (!global) { |
| 399 | candidates.push(path.join(baseDir, ".opencode", "opencode.json"), path.join(baseDir, ".opencode", "opencode.jsonc")) |
| 400 | } |
| 401 | |
| 402 | for (const candidate of candidates) { |
| 403 | if (await Filesystem.exists(candidate)) { |
| 404 | return candidate |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // Default to opencode.json if none exist |
| 409 | return candidates[0] |
| 410 | } |
| 411 | |
| 412 | async function addMcpToConfig(name: string, mcpConfig: ConfigMCPV1.Info, configPath: string) { |
| 413 | let text = "{}" |