feat: @file expansion in rules files + CLAUDE.md fallback#348
Open
breedx wants to merge 2 commits into
Open
Conversation
added 2 commits
May 20, 2026 16:55
- Add _expand_at_references(): expands @path lines one level deep from the directory containing the rules file - Add _read_rules_file(): wraps read + expansion - Update load_puppy_rules() to use _read_rules_file() throughout - Add CLAUDE.md fallback when no AGENTS.md exists in project - Add _CLAUDE_FALLBACK_FILES constant for CLAUDE.md / claude.md - Add tests: TestExpandAtReferences + TestClaudeMdFallback
- Add _resolve_at_ref(): rejects absolute paths, .. traversal, and symlinks that escape base_dir using Path.resolve() + relative_to() - Tighten _AT_REF_RE to require @ref on its own line (no trailing text) - Add TestResolveAtRef: absolute path, traversal, symlink escape, valid path, and expansion output tests (7 new cases) - 30/30 tests passing, zero ruff warnings
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.
What
@pathreference expansion toload_puppy_rules()— any line consisting solely of@pathin a rules file is replaced with the contents of that file, resolved relative to the rules file's directoryCLAUDE.md/claude.mdin the project root when noAGENTS.mdexists anywhereWhy
Allows
AGENTS.md(orCLAUDE.md) to compose rules from multiple files via@references, rather than requiring all rules to be inlined. Useful for referencing external philosophy/rule sets without duplicating content into a single flat file.Security
Path expansion is constrained to the directory containing the rules file:
@/etc/hostname) are rejected@../../.env) is rejected@tokenso the agent can see what failedChanges
code_puppy/agents/_builder.py: add_AT_REF_RE,_resolve_at_ref(),_expand_at_references(),_read_rules_file(), updateload_puppy_rules()tests/agents/test_builder_load_puppy_rules.py: addTestExpandAtReferences(7 tests),TestResolveAtRef(7 tests),TestClaudeMdFallback(6 tests)Tests