fix(rules): Resolve relative @ includes against source file directory#3116
fix(rules): Resolve relative @ includes against source file directory#3116toniher wants to merge 7 commits into
Conversation
Add logic to both claude and cli parsers to resolve relative @include paths against the directory of the source file rather than the current working directory. This allows includes to work correctly when the source file is located outside the cwd. Includes absolute paths (starting with / or ~) and cases where source_dir cannot be determined are left unchanged. Add corresponding test cases for both parsers.
There was a problem hiding this comment.
against the directory of the source file rather than the current working directory
Looking at the code, is this actually the case? It reads like it tries the source file dir and then tries the cwd? Otherwise, this is potentially a breaking change for users.
|
But absolutely solid addition to the plugin and one that I should have in from the start. We should also update the configuration page for rules to clarify how the file resolution works. |
The relative @include resolution logic has been moved to the Claude parser and abstracted into a reusable `files.exists()` utility function. The CLI parser no longer needs this functionality, so remove the unused code and its associated test file.
Update the comment to more precisely describe the path resolution logic, clarifying that non-absolute paths (those without leading / or ~) are resolved against the source file's directory.
The rules file now documents that an INSTRUCTIONS.md file in the same directory is automatically included in the chat buffer context, without requiring a './' prefix.
|
This should be addressed! More clarity and a bit of documentation. |
|
Super thank you. And apologies for being slow, I've been travelling so only got chance to look at this now. Regarding my post above:
Is this actually the case? It reads like it tries the source file dir and then tries the cwd? Otherwise, this is potentially a breaking change for users. |
Yeah, it simply checks if there is '/' or '~' prepended (absolute path). If a file is in |
|
A potential breaking change could be that a global CLAUDE.md ( Should it load from the current directory or find it a The outcome t is explicit in the context load, but I can write it down in the documentation. |
The rules documentation now provides more comprehensive details about how @INSTRUCTIONS.md files are located and included. Added clarification that the file is looked up in both the rules directory and project working directory, with special note for global Claude Rules files. Included information about warning behavior when files cannot be found.
|
That's entirely logical and what I think user's would expect from rules files. Defo worth documenting this |
What would you add more apart from this: 828adc4 ? |
Description
Add logic to both claude and cli parsers to resolve relative @ include paths against the directory of the source file rather than the current working directory. This allows includes to work correctly when the source file is located outside the
cwd. Includes absolute paths (starting with / or ~) and cases where source_dir cannot be determined are left unchanged. Add corresponding test cases for both parsers.Coming from discussion here: #2688 (reply in thread)
AI Usage
Claude Code with Sonnet 4.7
Prompt:
...
Checklist
make allto ensure docs are generated, tests pass and StyLua has formatted the code