ai-rules icon indicating copy to clipboard operation
ai-rules copied to clipboard

feat: add agent-specific rule filtering

Open privatenumber opened this issue 10 months ago • 2 comments

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 avatar Jan 23 '26 14:01 privatenumber

@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?

jonandersen avatar Jan 23 '26 18:01 jonandersen

Thanks for the feedback! I pushed an update that should address both issues:

  1. Cursor-only rule appearing in AGENTS.md

    Fixed. Rules now filter correctly per agent. A rule with allowedAgents: [cursor] will only appear in Cursor's .cursor/rules/ directory, not in AGENTS.md.

  2. AGENTS.md shared file problem

    Solved by requiring rules to apply to all agents in the group. The logic:

    • AGENTS.md is shared by: amp, cline, codex, copilot, goose, kilocode, roo
    • A rule with allowedAgents: [goose] won't appear in AGENTS.md (since it doesn't apply to all 7 agents)
    • A rule with blockedAgents: [cursor] will appear in AGENTS.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.

privatenumber avatar Jan 26 '26 17:01 privatenumber