Skip to content

fix(hooks): read OpenCode 1.x global rules from XDG_CONFIG_HOME and config.json (#4520) - #4932

Open
feliperm17 wants to merge 1 commit into
rtk-ai:developfrom
feliperm17:fix/4520-opencode-xdg-config-json
Open

feliperm17 wants to merge 1 commit into
rtk-ai:developfrom
feliperm17:fix/4520-opencode-xdg-config-json

Conversation

@feliperm17

Copy link
Copy Markdown

Closes #4520

Summary

  • Updates global_opencode_dir() in src/hooks/permissions_opencode.rs to resolve $XDG_CONFIG_HOME/opencode when XDG_CONFIG_HOME is non-empty (without falling back to ~/.config/opencode when absent on disk, matching OpenCode 1.18.34 / xdg-basedir), covering both global JSON configs and global markdown agent rules (agents/ and agent/).
  • Separates global config loading (read_global_config) from project discovery (CONFIG_NAMES), merging config.json, opencode.json, and opencode.jsonc in order (preserving key positions on overwrite and normalizing root/agent permission string shorthands prior to merging) while keeping project discovery restricted to opencode.json(c).
  • Adds 11 unit tests in src/hooks/permissions_opencode.rs and 7 subprocess integration tests in tests/hook_config_io_test.rs covering all three required 1.x rows (XDG_CONFIG_HOME set, config.json asks, XDG_CONFIG_HOME unset/empty), global file precedence/merging, XDG markdown agents, and ignoring generic project config.json files.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test (5,442 passed, 0 failed, 8 ignored; zero clippy warnings or fmt diffs)
  • Manual testing: rtk <command> output inspected (rtk hook opencode -- ls -la verified across $XDG_CONFIG_HOME/opencode/opencode.json, config.json under both XDG and ~/.config/opencode, XDG_CONFIG_HOME unset/empty, and XDG markdown agents)

Important: All PRs must target the develop branch (not master).

See CONTRIBUTING.md for details.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes OpenCode global config discovery to follow OpenCode 1.x/xdg-basedir semantics: global_opencode_dir() now resolves $XDG_CONFIG_HOME/opencode when the env var is non-empty instead of always defaulting to ~/.config/opencode, and global config loading is split from project discovery so config.json, opencode.json, and opencode.jsonc are merged in OpenCode's precedence order (with permission shorthand normalization) while project discovery still only looks at opencode.json(c). Adds unit and sub…

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4520


Analyzed automatically by wshm · This is an automated analysis, not a human review.

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

Labels

area:hooks bug Something isn't working opencode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode 1.x: rtk misses global rules under $XDG_CONFIG_HOME/opencode and in config.json

1 participant