fix(opencode): honor the user's own opencode config - #387
Conversation
ucode exported XDG_CONFIG_HOME to send opencode to its own directory. That removed all of ~/.config/opencode from opencode's load path. Thus the user's permission rules, MCP servers, disabled_providers, global skills, agents, commands, plugins, tui.json and global AGENTS.md had no effect in a ucode session. Name ucode's file with OPENCODE_CONFIG in place of the redirect. OPENCODE_CONFIG is a config layer above the user's global config, and opencode merges the layers. Objects merge one key at a time and the later scalar wins. Thus ucode keeps control of `model` and `provider`, and the user keeps everything else. ucode still writes to its own file only. The config file path does not change, so MCP servers that `ucode mcp add` registered survive the upgrade.
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenCode agent integration so ucode opencode no longer hides the developer’s existing OpenCode config under ~/.config/opencode/. Instead of redirecting XDG_CONFIG_HOME, ucode now points OpenCode at ucode’s generated config via OPENCODE_CONFIG, allowing OpenCode to merge configs as intended while keeping ucode’s config written under ~/.ucode/.
Changes:
- Stop exporting
XDG_CONFIG_HOMEfor OpenCode; setOPENCODE_CONFIGto ucode’s generated config file instead. - Update e2e/unit tests to avoid reading the developer’s real
~/.config/opencodeby settingXDG_CONFIG_HOMEto a test-only empty location. - Document the OpenCode managed file path as a layering config in the README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/ucode/agents/opencode.py |
Switch runtime env construction from XDG_CONFIG_HOME redirection to OPENCODE_CONFIG layering. |
tests/test_agent_opencode.py |
Adjust unit tests to assert OPENCODE_CONFIG is used and XDG_CONFIG_HOME is not overridden. |
tests/test_e2e.py |
Update OpenCode e2e launches to keep tests hermetic now that XDG_CONFIG_HOME isn’t redirected by ucode. |
tests/test_e2e_user_agent.py |
Update OpenCode user-agent e2e test env to use OPENCODE_CONFIG plus an empty XDG_CONFIG_HOME. |
README.md |
Update managed-local-files table to reflect OpenCode’s config layering behavior and ucode-managed path. |
Suppressed comments (1)
tests/test_e2e.py:872
- Same hermeticity concern here: XDG_CONFIG_HOME is pointed at tmp_path/empty-xdg but the directory isn’t created, which can allow fallbacks to the developer’s real config depending on opencode’s lookup behavior.
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "empty-xdg"))
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The single test asserted only that build_runtime_env adds no XDG_CONFIG_HOME when the variable is absent. A reintroduced redirect that overwrites a value the user already set would have passed. Split the case in two so the pass-through is asserted with a sentinel.
|
@lilly-luo Do you have time to review this? Or are there adjustments I need to do in my PRs before you can take a look at them? 😊 |
Fixes #391.
Before this,
ucode opencodeignored your~/.config/opencode/. Now it honors it.The one-line cause
ucode set
XDG_CONFIG_HOMEto its own folder. That is the variable OpenCode uses to find your config folder — change it and your config is gone. The fix names ucode's file withOPENCODE_CONFIGinstead, which OpenCode adds as one more layer rather than replacing the folder.How OpenCode combines the layers
OpenCode reads several config sources in priority order and merges them.
OPENCODE_CONFIGsits just above your global config, so:modelwins.mcpservers and ucode's server all survive.disabled_providersstays whole.Result: ucode keeps
modelandprovider; the user keeps permissions, MCP servers,disabled_providers, skills,AGENTS.md, everything else. ucode still writes only its own file, and the path is unchanged, soucode mcp addservers survive.Verification
opencode debug configbefore the change shows only ucode's keys; after the change it shows the user'spermission,disabled_providersand MCP servers merged with ucode'smodel,providerand MCP server. A launcheducode opencode runstill reaches the gateway and returns a normal reply.Tests
uv run --frozen pytest: 1937 passed, 41 skipped.ruff check .: clean. New regression testtest_leaves_xdg_config_home_alone.