()
| 55 | } |
| 56 | |
| 57 | export function detectConfigPaths(): ConfigPaths { |
| 58 | const configDir = getOpenCodeConfigDir(); |
| 59 | |
| 60 | let opencodeConfig: string; |
| 61 | let opencodeConfigFormat: "json" | "jsonc" | "none"; |
| 62 | let tuiConfig: string; |
| 63 | let tuiConfigFormat: "json" | "jsonc" | "none"; |
| 64 | |
| 65 | const jsoncPath = join(configDir, "opencode.jsonc"); |
| 66 | const jsonPath = join(configDir, "opencode.json"); |
| 67 | if (existsSync(jsoncPath)) { |
| 68 | opencodeConfig = jsoncPath; |
| 69 | opencodeConfigFormat = "jsonc"; |
| 70 | } else if (existsSync(jsonPath)) { |
| 71 | opencodeConfig = jsonPath; |
| 72 | opencodeConfigFormat = "json"; |
| 73 | } else { |
| 74 | opencodeConfig = jsonPath; |
| 75 | opencodeConfigFormat = "none"; |
| 76 | } |
| 77 | |
| 78 | const tuiJsoncPath = join(configDir, "tui.jsonc"); |
| 79 | const tuiJsonPath = join(configDir, "tui.json"); |
| 80 | if (existsSync(tuiJsoncPath)) { |
| 81 | // OpenCode merges tui.json + tui.jsonc with tui.jsonc winning, so an |
| 82 | // existing tui.jsonc is the higher-precedence user file — write into it. |
| 83 | tuiConfig = tuiJsoncPath; |
| 84 | tuiConfigFormat = "jsonc"; |
| 85 | } else if (existsSync(tuiJsonPath)) { |
| 86 | tuiConfig = tuiJsonPath; |
| 87 | tuiConfigFormat = "json"; |
| 88 | } else { |
| 89 | // Fresh install: create tui.jsonc (not tui.json) so the user can add |
| 90 | // comments later and we don't leave a second, lower-precedence file |
| 91 | // alongside a tui.jsonc they create afterward (#176). |
| 92 | tuiConfig = tuiJsoncPath; |
| 93 | tuiConfigFormat = "none"; |
| 94 | } |
| 95 | |
| 96 | return { |
| 97 | configDir, |
| 98 | opencodeConfig, |
| 99 | opencodeConfigFormat, |
| 100 | magicContextConfig: resolveCortexKitUserConfigPath(), |
| 101 | omoConfig: findOmoConfig(configDir), |
| 102 | tuiConfig, |
| 103 | tuiConfigFormat, |
| 104 | }; |
| 105 | } |
| 106 | |
| 107 | // ============================================================================ |
| 108 | // Pi paths |
no test coverage detected