Skip to content

fix: standardize user-level config directories via btw_user_dirs()#182

Merged
gadenbuie merged 9 commits intomainfrom
fix/standardize-user-install-locations
Mar 19, 2026
Merged

fix: standardize user-level config directories via btw_user_dirs()#182
gadenbuie merged 9 commits intomainfrom
fix/standardize-user-install-locations

Conversation

@gadenbuie
Copy link
Collaborator

Summary

Introduces btw_user_dirs() in R/utils.R as a single source of truth for all user-level btw configuration locations. Previously, skills, agents, and btw.md discovery each hardcoded different and inconsistent sets of paths — and skills used tools::R_user_dir("btw", "config"), the wrong which argument (shipped in v1.2.0).

btw_user_dirs() returns paths in decreasing priority order: ~/.btw, ~/.config/btw, tools::R_user_dir("btw"). All three subsystems now use it:

  • Skills discovery (btw_skills_directories()): uses rev(btw_user_dirs()) to build the increasing-priority dir list; retains tools::R_user_dir("btw", "config")/skills as a legacy read-only fallback for installs from btw <= 1.2.0
  • Skills install (resolve_user_skill_dir()): picks the first non-empty existing candidate from btw_user_dirs(), defaulting to ~/.btw/skills
  • Agents discovery (find_user_agent_files()): gains tools::R_user_dir("btw") lookup
  • btw.md discovery (path_find_user()): gains ~/.btw/btw.md and tools::R_user_dir("btw")/btw.md lookups

Also includes: a btw CLI fix for standard packages not loading (datasets, stats, methods), and AGENTS.md updates documenting btw_user_dirs() as the canonical helper to use for any future user-level config work.

Verification

# See all user-level directories btw searches
btw:::btw_user_dirs()
#> [1] "~/.btw"
#> [2] "~/.config/btw"
#> [3] "~/Library/Application Support/org.R-project.R/R/btw"  # macOS

# Install a skill to user scope — lands in ~/.btw/skills by default
btw_skill_install_github("owner/repo", scope = "user")

Introduces `btw_user_dirs()` as a single source of truth for all
user-level btw config locations, returning paths in decreasing priority
order (~/.btw, ~/.config/btw, tools::R_user_dir("btw")).

Previously, skills, agents, and btw.md each hardcoded their own
inconsistent sets of user-level paths. Skills used
`tools::R_user_dir("btw", "config")` (wrong `which` argument, shipped
in v1.2.0), agents used ~/.btw and ~/.config/btw, and btw.md used the
home dir and ~/.config/btw.

Now all three subsystems use `btw_user_dirs()`:
- `path_find_user()`: gains ~/.btw and tools::R_user_dir("btw") lookups
- `find_user_agent_files()`: gains tools::R_user_dir("btw") lookup
- `btw_skills_directories()`: uses rev(btw_user_dirs()) for correct
  increasing-priority insertion; retains tools::R_user_dir("btw","config")
  as a legacy read-only fallback for skills installed with btw <= 1.2.0
- `resolve_skill_scope("user")`: new resolve_user_skill_dir() picks the
  first non-empty existing candidate from btw_user_dirs(), defaulting
  to ~/.btw/skills
@gadenbuie gadenbuie marked this pull request as ready for review March 18, 2026 16:07
btw_skills_directories() builds its list in increasing priority order
(last = highest). find_skill() was iterating in that same order and
returning on first match, meaning it returned the *lowest*-priority
version — the opposite of btw_skills_list()'s last-wins semantics.

Fix by iterating rev(skill_dirs) in both the fast and slow paths so
find_skill() and btw_skills_list() agree on which version wins.

Also adds tests for find_skill() priority resolution and
resolve_user_skill_dir() selection semantics.
@gadenbuie gadenbuie merged commit eeca3d1 into main Mar 19, 2026
9 checks passed
@gadenbuie gadenbuie deleted the fix/standardize-user-install-locations branch March 19, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant