Repository navigation
Project context search stops at the home directory - #234
Merged
Merged
Conversation
path_find_in_project() now returns NULL when the upward search reaches the home directory (fs::path_home() or fs::path_home_r()), without checking home itself. This keeps ~/AGENTS.md and ~/CLAUDE.md from being treated as project context when the working directory is under ~ but outside a project, and stops ~/btw.md from being read twice (as project file and user-level config). Also skip the user-level file in read_btw_file() when path_btw resolves to the same file, and check *.Rproj project roots in the directory being searched rather than the session working directory. Fixes #225
- Share a path_normalize_for_compare() helper between path_is_home() and path_same() so Windows case-folding is consistent - Rewrite the project-roots-below-home test so the root-marker stop is actually exercised and the searched directory is created first Finding 1 (home-as-project detection) is intentional per #225: home skips all project detection; home-level files are handled only by the user-level lookup.
Move AGENTS.md below home and above the .git marker so the NULL result can only come from the marker stop, not the home-directory stop, and assert the same file is found from the same directory before the marker exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #225
Summary
path_find_in_project()walked up from the working directory until it found a project root marker (DESCRIPTION,.git,.vscode,.here, or an*.Rprojfile) or the filesystem root. The home directory wasn't a stopping point, so when the working directory was under~but outside a project, the walk reached home and treated~/AGENTS.md,~/CLAUDE.md, or~/btw.mdas project files — and~/btw.mdinstructions were then read twice: once as the project file, once as the user-level config.This PR makes the home directory a hard stop for the upward search:
path_find_in_project()returnsNULLas soon as the walk reaches the home directory — eitherfs::path_home()orfs::path_home_r(), which differ on Windows — without ever checking the home directory itself. Home-level files are handled only by the user-level lookup (path_find_user()); supporting~/AGENTS.mdthere is tracked in the companion issue.~/.gitor a~/DESCRIPTIONdoes not make home a project.read_btw_file()no longer duplicates instructions whenpath_btwis set explicitly to the same file as the user-level config, e.g.btw_client(path_btw = "~/.btw/btw.md").*.Rprojroot check: it listed the session's working directory instead of the directory being searched, so a stray*.Rprojin the session cwd could falsely mark unrelated directories as project roots, and roots marked only by an*.Rprojfile could be walked past.New internal helpers
path_is_home()andpath_same()sharepath_normalize_for_compare()for consistent path comparison, including Windows case-folding.Verification
With a
~/AGENTS.mdpresent and the working directory under~but outside a project,find_btw_context_file()previously returned~/AGENTS.mdas the project context file; it now returnsNULL, and~/btw.mdinstructions appear once in the system prompt instead of twice. The repro from the issue (using a temporary HOME):New tests cover the home stop, project roots below home, the Windows split home roots, the
*.Rprojfixes, and thepath_btwdedup guard; the full test suite passes.