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 <artmore@protonmail.com>
This commit is contained in:
cyan
2026-04-21 22:47:42 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent d4a4f43a83
commit a8719f0a8e
2 changed files with 36 additions and 6 deletions
+18 -3
View File
@@ -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);