From a8719f0a8ee0becbb8528894b3dc78ee316ec4e1 Mon Sep 17 00:00:00 2001 From: cyan <79063400+cyanff@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:47:42 -0400 Subject: [PATCH] Match Opencode Config Resolution Behavior (#949) * fix(config): match opencode config resolution behavior * fix(config): use primary opencode config file --------- Co-authored-by: Bohdan Triapitsyn --- packages/vscode/src/opencodeConfig.ts | 21 ++++++++++++++++++--- packages/web/server/lib/opencode/shared.js | 21 ++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/vscode/src/opencodeConfig.ts b/packages/vscode/src/opencodeConfig.ts index 16c8b8b7..0eeb5266 100644 --- a/packages/vscode/src/opencodeConfig.ts +++ b/packages/vscode/src/opencodeConfig.ts @@ -7,7 +7,7 @@ import { parse as parseJsonc } from 'jsonc-parser'; const OPENCODE_CONFIG_DIR = path.join(os.homedir(), '.config', 'opencode'); const AGENT_DIR = path.join(OPENCODE_CONFIG_DIR, 'agents'); const COMMAND_DIR = path.join(OPENCODE_CONFIG_DIR, 'commands'); -const CONFIG_FILE = path.join(OPENCODE_CONFIG_DIR, 'opencode.json'); +const CONFIG_FILE = path.join(OPENCODE_CONFIG_DIR, 'config.json'); const CUSTOM_CONFIG_FILE = process.env.OPENCODE_CONFIG ? path.resolve(process.env.OPENCODE_CONFIG) : null; @@ -321,11 +321,25 @@ const getProjectConfigPath = (workingDirectory?: string): string | null => { }; const getConfigPaths = (workingDirectory?: string) => ({ - userPath: CONFIG_FILE, + userPaths: [ + path.join(OPENCODE_CONFIG_DIR, 'config.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.jsonc'), + ], projectPath: getProjectConfigPath(workingDirectory), customPath: CUSTOM_CONFIG_FILE }); +const getPrimaryUserConfigPath = (userPaths: string[]): string => { + for (const userPath of userPaths) { + if (fs.existsSync(userPath)) { + return userPath; + } + } + + return CONFIG_FILE; +}; + const readConfigFile = (filePath?: string | null): Record => { if (!filePath || !fs.existsSync(filePath)) return {}; const content = fs.readFileSync(filePath, 'utf8'); @@ -355,7 +369,8 @@ const mergeConfigs = (base: Record, override: Record { - const { userPath, projectPath, customPath } = getConfigPaths(workingDirectory); + const { userPaths, projectPath, customPath } = getConfigPaths(workingDirectory); + const userPath = getPrimaryUserConfigPath(userPaths); const userConfig = readConfigFile(userPath); const projectConfig = readConfigFile(projectPath); const customConfig = readConfigFile(customPath); diff --git a/packages/web/server/lib/opencode/shared.js b/packages/web/server/lib/opencode/shared.js index 6efe84e6..164615a0 100644 --- a/packages/web/server/lib/opencode/shared.js +++ b/packages/web/server/lib/opencode/shared.js @@ -10,7 +10,7 @@ const OPENCODE_CONFIG_DIR = path.join(os.homedir(), '.config', 'opencode'); const AGENT_DIR = path.join(OPENCODE_CONFIG_DIR, 'agents'); const COMMAND_DIR = path.join(OPENCODE_CONFIG_DIR, 'commands'); const SKILL_DIR = path.join(OPENCODE_CONFIG_DIR, 'skills'); -const CONFIG_FILE = path.join(OPENCODE_CONFIG_DIR, 'opencode.json'); +const CONFIG_FILE = path.join(OPENCODE_CONFIG_DIR, 'config.json'); const CUSTOM_CONFIG_FILE = process.env.OPENCODE_CONFIG ? path.resolve(process.env.OPENCODE_CONFIG) : null; @@ -115,12 +115,26 @@ function getProjectConfigPath(workingDirectory) { function getConfigPaths(workingDirectory) { return { - userPath: CONFIG_FILE, + userPaths: [ + path.join(OPENCODE_CONFIG_DIR, 'config.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.jsonc'), + ], projectPath: getProjectConfigPath(workingDirectory), customPath: CUSTOM_CONFIG_FILE }; } +function getPrimaryUserConfigPath(userPaths) { + for (const userPath of userPaths) { + if (fs.existsSync(userPath)) { + return userPath; + } + } + + return CONFIG_FILE; +} + function readConfigFile(filePath) { if (!filePath || !fs.existsSync(filePath)) { return {}; @@ -163,7 +177,8 @@ function mergeConfigs(base, override) { } function readConfigLayers(workingDirectory) { - const { userPath, projectPath, customPath } = getConfigPaths(workingDirectory); + const { userPaths, projectPath, customPath } = getConfigPaths(workingDirectory); + const userPath = getPrimaryUserConfigPath(userPaths); const userConfig = readConfigFile(userPath); const projectConfig = readConfigFile(projectPath); const customConfig = readConfigFile(customPath);