-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cursorrules
More file actions
289 lines (218 loc) · 6.56 KB
/
.cursorrules
File metadata and controls
289 lines (218 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Cortex - Strategic AI Orchestrator
## Project Overview
Cortex is an intelligent AI orchestration system that provides:
- **Project Intelligence** - Scans git repos for activity and status
- **Strategic Recommendations** - AI-powered suggestions for next actions
- **Learning System** - Adapts based on feedback and outcomes
- **Context Intelligence** - Predicts relevant context for work
- **Daily Briefings** - Automated status reports and priorities
**Purpose**: Help developers stay organized and focused on high-priority work
**Intelligence**: Learns from feedback to improve recommendations over time
---
## Technology Stack
### Core
- **Python 3.9+** - Programming language
- **FastAPI** - API framework (optional)
- **Anthropic SDK** - Claude API integration
- **APScheduler** - Task scheduling
### Libraries
- **structlog** - Structured logging
- **rich** - Terminal UI formatting
- **python-dotenv** - Environment configuration
- **pytz** - Timezone handling
---
## Architecture
### Components
1. **AI Intelligence** (`ai_intelligence.py`)
- ProjectScanner: Find and analyze git repos
- ProjectActivity: Track commits, changes, blockers
2. **Recommendation Engine** (`recommendation_engine.py`)
- Generate strategic recommendations
- Prioritize based on urgency and impact
- Apply learning-based confidence adjustments
3. **Context Intelligence** (`context_intelligence.py`)
- Predict relevant context for tasks
- Search knowledge base
- Find related documentation
4. **Bridge** (`bridge.py`)
- Universal interface for AI agents
- Context retrieval
- Strategy injection
5. **CLI** (`cli.py`)
- Command-line interface
- User interaction and output formatting
---
## Development Guidelines
### Code Style
#### Dataclasses for Models
```python
from dataclasses import dataclass, field
from typing import List, Optional
from datetime import datetime
@dataclass
class ProjectActivity:
"""Project activity data from git analysis."""
name: str
path: Path
status: str
commits_7d: int
commits_30d: int
blockers: List[str] = field(default_factory=list)
last_commit_date: Optional[datetime] = None
```
#### Type Hints Required
```python
def analyze_project(self, repo_path: Path) -> ProjectActivity:
"""Analyze a single project."""
# Implementation
pass
```
### Logging
#### Structured Logging
```python
from app.utils.logger import logger
logger.info("Scanning projects", root_dir=str(self.root_dir))
logger.error("Failed to analyze project", project=project.name, error=str(e))
logger.warning("Project has blockers", project=project.name, count=len(blockers))
```
### Git Operations
#### Subprocess Pattern
```python
import subprocess
def get_git_output(self, repo_path: Path, command: List[str]) -> str:
"""Run git command and return output."""
try:
result = subprocess.run(
['git'] + command,
cwd=repo_path,
capture_output=True,
text=True,
timeout=2
)
return result.stdout.strip()
except (subprocess.TimeoutExpired, subprocess.SubprocessError):
return ""
```
### Recommendation Generation
#### Engine Pattern
```python
def generate_recommendations(
self,
project_activity: List[ProjectActivity],
goals: Optional[List[Goal]] = None,
limit: int = 5
) -> List[Recommendation]:
"""Generate prioritized recommendations."""
recommendations = []
# 1. Blocker resolution (highest priority)
recommendations.extend(self._generate_blocker_recommendations(project_activity))
# 2. Goal progress
if goals:
recommendations.extend(self._generate_goal_recommendations(goals, project_activity))
# Sort by priority score
recommendations.sort(key=lambda r: self._priority_score(r), reverse=True)
return recommendations[:limit]
```
---
## Key Patterns
### Project Scanning
```python
from ai_intelligence import ProjectScanner
scanner = ProjectScanner("/Users/jesse.kemp/Dev")
projects = scanner.find_projects()
analyzed = [scanner.analyze_project(p) for p in projects]
# Filter active projects
active = [p for p in analyzed if p.status == "active"]
```
### Recommendation Engine
```python
from recommendation_engine import RecommendationEngine
engine = RecommendationEngine()
recommendations = engine.generate_recommendations(
project_activity=analyzed,
limit=5
)
for rec in recommendations:
print(f"{rec.priority}: {rec.title}")
print(f" {rec.rationale}")
```
### Context Intelligence
```python
from context_intelligence import ContextIntelligence
intel = ContextIntelligence()
predictions = intel.predict_context(
current_project="cortex",
current_task="Add new feature",
limit=5
)
for pred in predictions:
print(f"{pred.title} ({pred.confidence:.0%})")
```
### Bridge Integration
```python
from bridge import CortexBridge
bridge = CortexBridge()
# Get context
context = bridge.get_context("fastapi patterns", limit=3)
# Inject recommendation
bridge.inject_recommendation(
title="Implement caching",
rationale="Improve API performance",
priority="high"
)
```
---
## CLI Commands
### Available Commands
```bash
# Get next action
cortex next
# Show current state
cortex status
# System health check
cortex health
# Generate daily briefing
cortex briefing
# Log feedback
cortex feedback --outcome success
```
---
## Configuration
### Environment Variables
```bash
# Optional: Anthropic API key for enhanced features
ANTHROPIC_API_KEY=sk-ant-...
# Project root directory
CORTEX_ROOT=/Users/jesse.kemp/Dev
```
---
## Code Quality Checklist
- [ ] Type hints on all public functions
- [ ] Docstrings with Args, Returns, Raises
- [ ] Dataclasses for structured data
- [ ] Structured logging (not print statements)
- [ ] Git operations with timeout
- [ ] Error handling for subprocess calls
- [ ] Path operations use Path objects
- [ ] Recommendations have confidence scores
- [ ] Priority scores calculated consistently
---
## Technology-Specific Rules
See `.cursor/rules/`:
### 📘 fastapi-cortex.mdc
- API endpoint patterns
- Request/response models
- Error handling
- Integration with scanner and engine
---
## Important Notes
✅ **Dataclasses**: Use for all structured data
✅ **Type Hints**: Required on all functions
✅ **Logging**: Use structlog, not print
✅ **Git**: Timeout all subprocess calls
✅ **Paths**: Use Path objects, not strings
✅ **Recommendations**: Include rationale and confidence
✅ **Priority**: Calculate priority scores consistently
✅ **Learning**: Track outcomes for improvement
---
*For detailed patterns, see files in `.cursor/rules/`*