feat: add agent-specific rule filtering
Summary
- add allow/block agent frontmatter and filtering at generation time
- generate per-agent optional rules files and a shared AGENTS.md group optional file to keep agents in sync
- update tests and docs for new filtering behavior
Testing
- cargo test
Closes https://github.com/block/ai-rules/issues/25
@privatenumber thank you for submitting a PR for this!
I tested it out a little (there's an example folder you can play around in and run sh ai-rules.sh generate to generate the examples.
Didn't seem to work fully as expected. I tried to allow only cursor to have a rule but it ended up getting applied to AGENTS.md
We have an issue i'm not sure how to solve, several agents share AGENTS.md which is problematic if one of the rules has allowed/blocked e.g if goose has a specific rule that only applies to it, that would get added to the AGENTS.md file. I'm not sure how we can solve that, do you have any ideas?
Thanks for the feedback! I pushed an update that should address both issues:
-
Cursor-only rule appearing in
AGENTS.mdFixed. Rules now filter correctly per agent. A rule with
allowedAgents: [cursor]will only appear in Cursor's.cursor/rules/directory, not inAGENTS.md. -
AGENTS.mdshared file problemSolved by requiring rules to apply to all agents in the group. The logic:
AGENTS.mdis shared by: amp, cline, codex, copilot, goose, kilocode, roo- A rule with
allowedAgents: [goose]won't appear inAGENTS.md(since it doesn't apply to all 7 agents) - A rule with
blockedAgents: [cursor]will appear inAGENTS.md(applies to all 7)
When a rule targets a subset, a warning is emitted:
Warning: Rule 'goose-specific' applies to a subset of AGENTS.md agents; it will be excluded from AGENTS.md.
Let me know if this works for your use case or if you'd like any adjustments to the behavior.