From f02dfbd4cbee8cf2bf02367ca67bd65363a28c85 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Sat, 5 Sep 2026 14:43:57 +0300 Subject: [PATCH] fix(web): tidy the XDG config root resolution The web server read XDG_CONFIG_HOME through a redundant typeof guard on a value that is already string|undefined, which tripped the anti-slop lint on its own new line and diverged from the VS Code helper. Both now read the same way. The VS Code provider test also still hard-coded ~/.config/opencode, so it silently stopped asserting whenever XDG_CONFIG_HOME was set; it now uses the shared constant, like the web test already does. --- packages/vscode/src/opencodeConfig.providers.test.ts | 9 +++++---- packages/web/server/lib/opencode/shared.js | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/vscode/src/opencodeConfig.providers.test.ts b/packages/vscode/src/opencodeConfig.providers.test.ts index 4e616a19..c4dfc4a1 100644 --- a/packages/vscode/src/opencodeConfig.providers.test.ts +++ b/packages/vscode/src/opencodeConfig.providers.test.ts @@ -10,6 +10,7 @@ import { upsertProviderConfig, validateCustomProviderConfig, } from './opencodeConfig'; +import { OPENCODE_CONFIG_DIR } from './opencodeConfigPaths'; let projectDir: string; @@ -377,8 +378,8 @@ describe('custom provider config persistence (VS Code parity)', () => { assert.equal(sources.custom.exists, false); for (const userPath of [ - path.join(os.homedir(), '.config', 'opencode', 'opencode.json'), - path.join(os.homedir(), '.config', 'opencode', 'config.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.json'), + path.join(OPENCODE_CONFIG_DIR, 'config.json'), ]) { if (!fs.existsSync(userPath)) continue; const userConfig = readJson(userPath); @@ -416,8 +417,8 @@ describe('custom provider config persistence (VS Code parity)', () => { assert.equal(sources.project.exists, false); for (const userPath of [ - path.join(os.homedir(), '.config', 'opencode', 'opencode.json'), - path.join(os.homedir(), '.config', 'opencode', 'config.json'), + path.join(OPENCODE_CONFIG_DIR, 'opencode.json'), + path.join(OPENCODE_CONFIG_DIR, 'config.json'), ]) { if (!fs.existsSync(userPath)) continue; const userConfig = readJson(userPath); diff --git a/packages/web/server/lib/opencode/shared.js b/packages/web/server/lib/opencode/shared.js index d154cc29..73d66cc8 100644 --- a/packages/web/server/lib/opencode/shared.js +++ b/packages/web/server/lib/opencode/shared.js @@ -6,10 +6,10 @@ import { parse as parseJsonc, printParseErrorCode } from 'jsonc-parser'; // ============== PATH CONSTANTS ============== -const XDG_CONFIG_HOME = typeof process.env.XDG_CONFIG_HOME === 'string' && process.env.XDG_CONFIG_HOME.trim() - ? process.env.XDG_CONFIG_HOME.trim() - : path.join(os.homedir(), '.config'); -const OPENCODE_CONFIG_DIR = path.join(XDG_CONFIG_HOME, 'opencode'); +const OPENCODE_CONFIG_DIR = path.join( + process.env.XDG_CONFIG_HOME?.trim() || 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');