Skip to content

Extract opencode_xdg.ts helper module #560

Description

@jeonghun-jj-lee

Problem

Four call sites across the extension hardcode ~/.config/opencode/ and ~/.local/share/opencode/ as literal path.join(os.homedir(), ".config", "opencode", ...) / path.join(os.homedir(), ".local", "share", "opencode", ...) strings. They break under non-standard XDG_CONFIG_HOME / XDG_DATA_HOME and bypass configurable settings.

This slice extracts the shared resolution logic into a single module that all consumers import.

Scope

Create packages/extension/src/opencode_xdg.ts exporting two functions:

  • opencodeConfigDir(): string — returns $XDG_CONFIG_HOME/opencode (or ~/.config/opencode when unset)
  • opencodeDataDir(): string — returns $XDG_DATA_HOME/opencode (or ~/.local/share/opencode when unset)

Pure utility — no VS Code API dependencies, no side effects.

Acceptance Criteria

  • opencodeConfigDir() returns path.join(process.env.XDG_CONFIG_HOME, "opencode") when XDG_CONFIG_HOME is set; otherwise path.join(os.homedir(), ".config", "opencode").
  • opencodeDataDir() returns path.join(process.env.XDG_DATA_HOME, "opencode") when XDG_DATA_HOME is set; otherwise path.join(os.homedir(), ".local", "share", "opencode").
  • Both functions are exported and importable by other extension modules.
  • Unit tests cover: default (env unset), env set to custom path, env set to empty string (treated as unset).

Testing Decisions

Create packages/extension/test/opencode_xdg.test.ts:

  • Mock process.env.XDG_CONFIG_HOME / XDG_DATA_HOME and os.homedir().
  • Three cases per function: unset → default, set → custom, empty string → default.

Key Decisions

Decision Rationale
No VS Code API dependency Keeps the module testable without vscode mock; consumers layer settings on top
Empty-string env treated as unset XDG spec: unset or empty means default
path.join (not template literals) Cross-platform safety (though macOS is the primary target)

Constraints & Invariants

  • This module MUST NOT read VS Code settings (amicode.configDir, amicode.sessionDatabase) — those are consumer-side overrides, not base resolution.
  • No filesystem side effects (no mkdirp, no writes).
  • Consumers that need the VS Code setting override apply it themselves on top of these helpers.

Source

Part of #556

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

afkImplementable without human interactionarea:node

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions