Recursively look up cursor rules in any .cursor directory

We have a large codebase which many teams contribute to. Rather than putting all of the cursor rules in a single .cursor directory in the root of the project, we’d like to be able to put the rules in individual sub-directories.

This would work better for organization, and makes it easier to have different teams own the code reviews for different rules - typically the way we do ownership is per-directory.

The idea is that if you add a file, cursor will look for .cursor directories anywhere on the path between the project root and that file.

For example ideally it would be able to find all of these:

.cursor/rules
service-a/.cursor/rules
service-b/.cursor/rules

Then if I edit a file like service-b/example.txt it would use the rules from service-b/.cursor/rules as well as ./cursor/rules but not from service-a/cursor/rules.

That way each team can maintain separate rules for how to write unit tests or code style, and those rules can be kept just in the directory for their service.

This is similar to how .gitignore works - you can put it in any directory and it is applied just to that directory and below.

Unfortunately, just opening service-a as the project root is not a solution that works for us - we need to open the entire root.