Skip to content

feat: @file expansion in rules files + CLAUDE.md fallback#348

Open
breedx wants to merge 2 commits into
mpfaffenberger:mainfrom
breedx:feature/upstream-at-file-expansion
Open

feat: @file expansion in rules files + CLAUDE.md fallback#348
breedx wants to merge 2 commits into
mpfaffenberger:mainfrom
breedx:feature/upstream-at-file-expansion

Conversation

@breedx
Copy link
Copy Markdown
Contributor

@breedx breedx commented May 20, 2026

What

  • Adds @path reference expansion to load_puppy_rules() — any line consisting solely of @path in a rules file is replaced with the contents of that file, resolved relative to the rules file's directory
  • Expansion is one level deep only — refs inside included files are left as-is
  • Falls back to CLAUDE.md / claude.md in the project root when no AGENTS.md exists anywhere

Why

Allows AGENTS.md (or CLAUDE.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:

  • Absolute paths (e.g. @/etc/hostname) are rejected
  • Parent traversal (e.g. @../../.env) is rejected
  • Symlinks that resolve outside the base directory are rejected
  • Unknown/unsafe refs are left as their original @token so the agent can see what failed

Changes

  • code_puppy/agents/_builder.py: add _AT_REF_RE, _resolve_at_ref(), _expand_at_references(), _read_rules_file(), update load_puppy_rules()
  • tests/agents/test_builder_load_puppy_rules.py: add TestExpandAtReferences (7 tests), TestResolveAtRef (7 tests), TestClaudeMdFallback (6 tests)

Tests

  • 30/30 targeted tests passing
  • 572/572 agent tests passing
  • Zero ruff warnings

brian 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
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