Skip to content

Commit de9de84

Browse files
authored
dev(agents): Configure context-aware Cursor rules with file matching (#105426)
Adds .cursor/rules/*.mdc files to automatically load domain-specific AGENTS.md files based on the file being edited: * Backend Python files → loads src/AGENTS.md * Test files → loads tests/AGENTS.md * Frontend files → loads static/AGENTS.md * All files → always loads root AGENTS.md Benefits: * Token efficient: Only loads relevant context for current task * Better AI responses: Gets targeted guidance (backend vs frontend vs testing patterns) * Prevents context overload: No need to load all guides simultaneously Also includes documentation in root AGENTS.md and .cursor/rules/README.md explaining the setup.
1 parent 455cb11 commit de9de84

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed

.cursor/rules/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Cursor Rules Configuration
2+
3+
This directory contains `.mdc` (Markdown with Cursor directives) files that configure context-aware loading of AGENTS.md files in Cursor's AI assistant.
4+
5+
## How It Works
6+
7+
When you edit a file, Cursor automatically loads the relevant AGENTS.md based on glob patterns:
8+
9+
| File Type | Loaded Guide | Glob Pattern |
10+
| -------------- | ------------------ | --------------------------------------- |
11+
| Backend Python | `src/AGENTS.md` | `src/**/*.py` (excluding tests) |
12+
| Test files | `tests/AGENTS.md` | `tests/**/*.py`, `src/**/tests/**/*.py` |
13+
| Frontend | `static/AGENTS.md` | `static/**/*.{ts,tsx,js,jsx,css,scss}` |
14+
| All files | `AGENTS.md` | Always loaded |
15+
16+
## Files
17+
18+
- **`general.mdc`** - Always loads root `AGENTS.md` for general Sentry context
19+
- **`backend.mdc`** - Loads backend patterns for Python files in `src/`
20+
- **`tests.mdc`** - Loads testing patterns for test files
21+
- **`frontend.mdc`** - Loads frontend patterns for TypeScript/JavaScript/CSS files
22+
23+
## Benefits
24+
25+
- **Token efficient**: Only relevant context is loaded
26+
- **Better AI responses**: Targeted guidance for the current task
27+
- **Maintainable**: Content lives in AGENTS.md files, rules just reference them
28+
29+
## Adding New Rules
30+
31+
To add a new context-specific rule:
32+
33+
1. Create a new `.mdc` file in this directory
34+
2. Add YAML frontmatter with `globs:` or `alwaysApply:`
35+
3. Reference the appropriate AGENTS.md file with `@file:`
36+
37+
Example:
38+
39+
```markdown
40+
---
41+
globs:
42+
- 'migrations/**/*.py'
43+
---
44+
45+
@file:migrations/AGENTS.md
46+
```
47+
48+
## Documentation
49+
50+
For more information, see:
51+
52+
- [Cursor Context Rules Documentation](https://docs.cursor.com/en/context/rules)
53+
- Root `AGENTS.md` - "Context-Aware Loading" section

.cursor/rules/backend.mdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
globs:
3+
- 'src/**/*.py'
4+
- '!src/**/tests/**'
5+
---
6+
7+
@file:src/AGENTS.md

.cursor/rules/frontend.mdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
globs:
3+
- 'static/**/*.{ts,tsx,js,jsx}'
4+
- 'static/**/*.{css,scss}'
5+
---
6+
7+
@file:static/AGENTS.md

.cursor/rules/general.mdc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
@file:AGENTS.md

.cursor/rules/tests.mdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
globs:
3+
- 'tests/**/*.py'
4+
- 'src/**/tests/**/*.py'
5+
---
6+
7+
@file:tests/AGENTS.md

AGENTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ sentry/
3434
> - **Backend testing patterns**: `tests/AGENTS.md`
3535
> - **Frontend patterns**: `static/AGENTS.md`
3636
37+
### Context-Aware Loading
38+
39+
Cursor is configured to automatically load relevant AGENTS.md files based on the file being edited (via `.cursor/rules/*.mdc`). This provides context-specific guidance without token bloat:
40+
41+
- Editing `src/**/*.py` → Loads `src/AGENTS.md` (backend patterns)
42+
- Editing `tests/**/*.py` → Loads `tests/AGENTS.md` (testing patterns)
43+
- Editing `static/**/*.{ts,tsx,js,jsx}` → Loads `static/AGENTS.md` (frontend patterns)
44+
- Always loads this file (`AGENTS.md`) for general Sentry context
45+
46+
**Note**: These `.mdc` files only _reference_ AGENTS.md files—they don't duplicate content. All actual guidance should be added to the appropriate AGENTS.md file, not to Cursor rules.
47+
3748
## Backend
3849

3950
For backend development patterns, commands, security guidelines, and architecture, see `src/AGENTS.md`.

0 commit comments

Comments
 (0)