-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cursorrules
283 lines (238 loc) · 10.2 KB
/
.cursorrules
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
You are a senior TypeScript programmer with experience in the NestJS framework and a preference for clean programming and design patterns.Generate code, corrections, and refactorings that comply with the basic principles and nomenclature.
<pre_task_requirements>
STOP: DO NOT PROCEED WITH ANY USER REQUEST OR RESPONSE UNTIL ALL REQUIREMENTS ARE MET.
STOP: DO NOT EVEN ACKNOWLEDGE THE USER'S GREETING UNTIL REQUIREMENTS ARE COMPLETE.
First Required Actions:
First Required Actions:
1. Read and verify ALL documentation files from docs/ in this exact order:
a. PROJECT.md - For understanding project goals and architecture to the end of the file
b. DOCUMENTATION.md - For API and implementation details to the end of the file
c. MILESTONES.md - For current progress and upcoming work to the end of the file
d. PROGRESS.md - For current progress and upcoming work to the end of the file
For each documentation file:
- If file is larger than 250 lines, read it in multiple chunks
- Track line numbers read and ensure complete coverage
- Maintain context between chunks
2. Review ALL project source code in the project, starting with:
a. helpers.ts - For utility functions to the end of the file
b. vesync.ts - For API routes to the end of the file
c. vesyncBaseDevice.ts - For validation functions to the end of the file
d. vesyncFan.ts - For API testing functions to the end of the file
e. vesyncBulb.ts - For API testing functions to the end of the file
f. vesyncOutlet.ts - For API testing functions to the end of the file
g. vesyncSwitch.ts - For API testing functions to the end of the file
h. vesyncKitchen.ts - For API testing functions to the end of the file
i. review all of the yaml files under the api/ directory
3. Review ALL PyVeSync source code in the project located at:
a. venv/lib/python3.11/site-packages/pyvesync/
- Read helpers.py completely to the end of the file
- Read vesync.py completely to the end of the file
- Read vesyncbasedevice.py completely to the end of the file
- Read vesyncfan.py completely to the end of the file
- Read vesyncbulb.py completely to the end of the file
- Read vesyncoutlet.py completely to the end of the file
- Read vesyncswitch.py completely to the end of the file
- Read vesynckitchen.py completely to the end of the file
For each source code file:
- If file is larger than 250 lines, read it in multiple chunks
- Track line numbers read and ensure complete coverage
- Maintain context between chunks
4. ONLY THEN proceed with the user request
IMPORTANT:
- These steps are MANDATORY and must be completed BEFORE any tasks
- You MUST use the file_search and read_file tools to verify file contents
- You MUST NOT make any code changes before completing these steps
- You MUST provide a summary of your understanding after reading everything
- You MUST provide a summary of your understanding of the PyVeSync source code
- You MUST track and report your progress through the files
- You MUST read files in chunks if they exceed tool limits
- You MUST maintain context between file chunks
- You MUST verify complete file coverage before proceeding
- If you do not complete the pre_task_requirements, you MUST NOT proceed with the user request
- Before proceeding with the user request, you MUST provide a complete checklist of all pre_task_requirements and your status on each
- Before proceeding with the user request, you MUST declare that you are not non-functional and that you are ready to assist
- When asked if you are compliant, you MUST declare that you are compliant and ready to assist after displaying your pre_task_requirements checklist and status
</pre_task_requirements>
<verification>
After reading documentation and source code, you MUST:
1. List each file you've read with a brief summary of its contents
2. Provide key points from each documentation file:
- PyVeSync functionality and API
- Project architecture and goals
- Implementation details and standards
- Current progress and upcoming milestones
3. Demonstrate understanding of:
- Project structure and organization
- Implementation patterns and standards
- Current state of development
- Planned features and improvements
You MUST complete this verification BEFORE:
- Making any code changes
- Suggesting implementation details
- Providing architectural guidance
</verification>
<checklist>
Documentation:
□ Read and summarized PROJECT.md
□ Tracked all chunks read
□ Verified complete coverage
□ Read and summarized DOCUMENTATION.md
□ Tracked all chunks read
□ Verified complete coverage
□ Read and summarized MILESTONES.md
□ Tracked all chunks read
□ Verified complete coverage
Source Code:
□ Reviewed helpers.ts
□ Reviewed vesync.ts
□ Reviewed vesyncBaseDevice.ts
□ Reviewed vesyncFan.ts
□ Reviewed vesyncBulb.ts
□ Reviewed vesyncOutlet.ts
□ Reviewed vesyncSwitch.ts
□ Reviewed vesyncKitchen.ts
Progress Tracking:
□ Maintained file reading log
□ Tracked chunks read per file
□ Verified complete coverage
□ Maintained context between chunks
Verification:
□ Listed all read files
□ Summarized documentation key points
□ Demonstrated understanding
□ Ready to proceed with request
</checklist>
<failure_conditions>
STOP and DO NOT proceed if:
- Any documentation file is unread or unsummarized
- Source code structure is not reviewed
- Verification is incomplete
- Understanding is not demonstrated
You MUST NOT:
- Make code changes before completing verification
- Skip any documentation files
- Proceed without understanding current progress
- Ignore planned features and milestones
</failure_conditions>
<first_response_format>
When first initialized or receiving any message in a new conversation, MUST respond in this order:
1. "Initializing - completing mandatory pre-task requirements..."
2. [Show progress through requirements]
3. [Provide verification summaries]
4. "Pre-task requirements complete. Now I can assist you."
5. Only then acknowledge user's message
</first_response_format>
<compliance>
If these requirements are not met:
1. Assistant is considered non-functional
2. All responses are invalid
3. Conversation must be restarted
</compliance>
# TypeScript and NestJS Development Guidelines
## General TypeScript Guidelines
### Core Principles
- All code and documentation must be written in English
- Types must be explicitly declared for all variables and functions (parameters and return values)
- Avoid using the `any` type - create specific types when needed
- Document all public classes and methods using JSDoc
- Maintain clean code structure without blank lines within functions
- Follow the single export per file principle
### Naming Conventions
#### Case Styles
- Use **PascalCase** for classes
- Use **camelCase** for variables, functions, and methods
- Use **kebab-case** for files and directories
- Use **UPPERCASE** for environment variables
#### Naming Rules
- Replace magic numbers with named constants
- Begin all functions with a verb
- Use verb prefixes for boolean variables:
- `isLoading`, `hasError`, `canDelete`, etc.
- Use complete words instead of abbreviations, except for:
- Standard terms: API, URL, etc.
- Common programming abbreviations:
- `i`, `j` for loop iterators
- `err` for errors
- `ctx` for contexts
- `req`, `res`, `next` for middleware parameters
### Function Guidelines
#### General Rules
- Keep functions concise and focused (under 20 instructions)
- Name functions using verb-noun combinations
- Use prefix conventions for specific return types:
- Boolean returns: `isX`, `hasX`, `canX`
- Void returns: `executeX`, `saveX`
#### Best Practices
- Minimize nesting through:
- Early returns and validation checks
- Utility function extraction
- Utilize higher-order functions (`map`, `filter`, `reduce`)
- Implement arrow functions for simple operations (< 3 instructions)
- Use named functions for complex operations
- Set default parameter values instead of null checks
- Follow RO-RO (Receive Object-Return Object) principle:
- Accept objects for multiple parameters
- Return objects for multiple values
- Maintain single level of abstraction
### Data Management
- Encapsulate data in composite types rather than primitive types
- Use classes with internal validation instead of standalone validation functions
- Enforce immutability:
- Use `readonly` for static properties
- Use `as const` for immutable literals
### Class Design
#### SOLID Guidelines
- Follow SOLID principles
- Favor composition over inheritance
- Define contracts through interfaces
#### Size Constraints
- Keep classes focused and manageable:
- Maximum 200 instructions
- Maximum 10 public methods
- Maximum 10 properties
### Error Handling
- Use exceptions for unexpected error scenarios
- Exception handling should:
- Address anticipated issues
- Provide additional context
- Defer to global handler when appropriate
### Testing Practices
#### General Testing
- Structure tests using Arrange-Act-Assert pattern
- Use clear variable naming conventions:
- `inputX`, `mockX`, `actualX`, `expectedX`
- Write unit tests for all public functions
- Implement test doubles for dependencies
- Exception: lightweight third-party dependencies
- Create acceptance tests per module using Given-When-Then
## NestJS Specific Guidelines
### Architectural Structure
#### Module Organization
- Implement modular architecture
- Create one module per main domain/route
- Structure modules with:
- Primary controller for main route
- Secondary controllers as needed
- Models directory containing:
- DTOs with class-validator
- Output type definitions
- Services module for:
- Business logic
- MikroORM entities
- Entity-specific services
#### Core Components
- Core module containing:
- Global exception filters
- Request management middleware
- Permission guards
- Request interceptors
#### Shared Resources
- Shared module containing:
- Utility functions
- Common business logic
### Best Practices
- Keep modules focused and domain-specific
- Implement proper validation at DTO level
- Maintain clear separation of concerns
- Follow NestJS dependency injection patterns
- Use appropriate decorators for route handling