Skip to content

fix(setup): honor empty XDG config home for OpenCode - #2189

Closed
pcp-cmd wants to merge 1 commit into
morluto:mainfrom
pcp-cmd:fix/opencode-empty-xdg-config-home
Closed

pcp-cmd wants to merge 1 commit into
morluto:mainfrom
pcp-cmd:fix/opencode-empty-xdg-config-home

Conversation

@pcp-cmd

@pcp-cmd pcp-cmd commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2168. With an empty XDG_CONFIG_HOME, OpenCode setup previously wrote
opencode/opencode.json under the working directory and reported readiness.
Resolve the default global directory once for both writing and reading, treating
an empty XDG value as unset. Explicit OpenCode and non-empty XDG overrides retain
their existing precedence.

Problem and expected behavior

An isolated CLI run on base 5190843f8f09ac17cbf79561bd1f708c509cda78 reproduced
the misplaced registration. The empty and unset cases now both write
HOME/.config/opencode/opencode.json; a non-empty XDG root still selects
XDG_CONFIG_HOME/opencode/opencode.json. All three workspaces remain empty.
This matches the XDG specification
and OpenCode 1.18.35's xdg-basedir 5.1.0 dependency.

Change and scope

  • Share OpenCode's default global-directory resolution between the write target
    and ordered configuration read sources.
  • Extend existing compiled CLI lifecycle coverage for empty and explicit XDG
    roots, including planning, setup, doctor, idempotence and uninstall.
  • Exercise the empty-XDG global layer together with a custom directory, including
    malformed-global preflight and preservation of unrelated registrations.

Contract and boundary impact

  • Semantic owner: SupportedClients.ts, OpenCode configuration-path resolution.
  • CLI/MCP schema, provider, target-format, Evidence and generated metadata: none.
  • Installation/cleanup: setup, doctor and uninstall agree on the default global
    source; existing approval, backup, preflight and owned-registration rules apply.

Evidence and regression coverage

  • Two modified CLI regressions failed on unmodified production source at the base
    revision (16 other tests passed), then passed with the fix.
  • Independent compiled CLI reproduction ran empty, unset and explicit XDG cases
    before and after the fix with separate temporary homes and working directories.
  • Final focused run: 106 tests passed across five existing CLI/filesystem files.
  • Native OpenCode loading/MCP handshake, macOS and Windows execution are unverified.

Validation performed

Linux x64, pinned Node 24.18.0 / npm 11.16.0:

  • npm run test:focused -- tests/boundary/cli/clientProfileLifecycle.test.ts tests/boundary/cli/clientProfiles.test.ts tests/boundary/filesystem/clientLifecycle.test.ts tests/boundary/filesystem/clientConfigurationDialects.test.ts tests/boundary/filesystem/clientRegistrationStatus.test.ts — 106 passed.
  • npm run check — passed all six tasks and architecture guards; 853 lint warnings,
    zero lint errors. The first attempt found one formatting issue, corrected with oxfmt.
  • npm run verify:test-discovery — all 915 test files discovered exactly once.
  • npm pack --dry-run --json — passed; 1,431 files.
  • git diff --check and pre-commit formatting/lint hooks — passed.
  • npm run verify:package — passed, including packaged CLI/MCP, 173 tools, setup/
    uninstall, exact-version update, backups, failure recovery, symlink lifecycle,
    Skills 1.7.2 repository discovery and verified cleanup with no remaining descendants.
    The first run was stopped after its local registry forwarding repeatedly returned
    HTTP 500: Node's upstream fetch failed with EAI_AGAIN. A probe using the existing
    environment proxy returned HTTP 200. The passing run used NODE_USE_ENV_PROXY=1
    with loopback destinations excluded from the proxy (NO_PROXY, no_proxy and
    npm_config_noproxy); no repository or network-policy change was needed.

Compatibility, safety, and release

No breaking changes, metadata change or version bump. The fix does not migrate an
already misplaced registration. No analysis provider behavior changed, so no real
Hopper/Ghidra run was performed. The full deterministic suite was not run locally.
CI run 38251100446 is
action_required; its page says it is awaiting approval from a maintainer.
No jobs have executed yet, so no remote test pass is claimed.

Review checklist

  • Concrete issue and focused Conventional Commit title.
  • Current issue, discussion, timeline and related PR searches checked.
  • Observable behavior and malformed-input/preservation paths covered.
  • Existing documentation contract remains valid; no generated files committed.
  • Before/after paths and executed verification distinguished from unavailable coverage.
  • Final diff checked for secrets, unrelated changes and unsupported claims.

pcp-cmd commented Oct 13, 2026

Copy link
Copy Markdown
Author

Closing this draft as superseded by 2397137, which is present in main (checked at bb96afd). The shared xdgConfigHome() now handles empty XDG_CONFIG_HOME consistently for OpenCode's write target and global read layers, resolving #2168.

The additional CLI cases here broaden the regression matrix for empty/explicit XDG roots and empty XDG with a custom directory. Main already tests the underlying lifecycle, configuration layering, malformed-global preflight and preservation behavior separately. I found no remaining behavior difference requiring this fix.

Path-resolution checks passed for main, 2397137 and this PR (69 cases total). I did not rerun the compiled CLI suite or native OpenCode; this PR's CI has no executed jobs. This PR was not merged.

@pcp-cmd pcp-cmd closed this Oct 13, 2026
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @pcp-cmd, for catching that an empty XDG_CONFIG_HOME was being treated as a real relative path for OpenCode. Main now falls back consistently when the XDG value is empty (main).

@morluto morluto added the area: setup Setup, packaging, upgrade, install, Doctor, and client registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(setup): empty XDG_CONFIG_HOME writes OpenCode registration under the working directory

2 participants