Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/core/global-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ const DEFAULT_CONFIG: GlobalConfig = {
/**
* Gets the global configuration directory path following XDG Base Directory Specification.
*
* - Unix/macOS: $XDG_CONFIG_HOME/openspec/ or ~/.config/openspec/
* - Windows: %APPDATA%/openspec/
* - All platforms: $XDG_CONFIG_HOME/openspec/ if XDG_CONFIG_HOME is set
* - Unix/macOS fallback: ~/.config/openspec/
* - Windows fallback: %APPDATA%/openspec/
*/
export function getGlobalConfigDir(): string {
// XDG_CONFIG_HOME takes precedence on all platforms when explicitly set
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
if (xdgConfigHome) {
return path.join(xdgConfigHome, GLOBAL_CONFIG_DIR_NAME);
}

const platform = os.platform();

if (platform === 'win32') {
Expand All @@ -34,12 +41,7 @@ export function getGlobalConfigDir(): string {
return path.join(os.homedir(), 'AppData', 'Roaming', GLOBAL_CONFIG_DIR_NAME);
}

// Unix/macOS: use XDG_CONFIG_HOME or fallback to ~/.config
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
if (xdgConfigHome) {
return path.join(xdgConfigHome, GLOBAL_CONFIG_DIR_NAME);
}

// Unix/macOS fallback: ~/.config
return path.join(os.homedir(), '.config', GLOBAL_CONFIG_DIR_NAME);
}

Expand Down
3 changes: 2 additions & 1 deletion test/core/global-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ describe('global-config', () => {
}
});

it('should use APPDATA on Windows', () => {
it('should use APPDATA on Windows when XDG_CONFIG_HOME is not set', () => {
// This test only makes sense conceptually - we can't change os.platform()
// But we can verify the APPDATA logic by checking the code path
if (os.platform() === 'win32') {
delete process.env.XDG_CONFIG_HOME;
const appData = process.env.APPDATA;
if (appData) {
const result = getGlobalConfigDir();
Expand Down
Loading