agents-templated 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/.claude/rules/ai-integration.mdc +60 -0
- package/templates/.claude/rules/core.mdc +180 -0
- package/templates/.claude/rules/database.mdc +291 -0
- package/templates/.claude/rules/frontend.mdc +224 -0
- package/templates/.claude/rules/guardrails.mdc +105 -0
- package/templates/.claude/rules/hardening.mdc +58 -0
- package/templates/.claude/rules/intent-routing.mdc +59 -0
- package/templates/.claude/rules/planning.mdc +75 -0
- package/templates/.claude/rules/security.mdc +286 -0
- package/templates/.claude/rules/style.mdc +306 -0
- package/templates/.claude/rules/system-workflow.mdc +69 -0
- package/templates/.claude/rules/testing.mdc +308 -0
- package/templates/.claude/rules/workflows.mdc +61 -0
- package/templates/CLAUDE.md +27 -27
- package/templates/agents/rules/ai-integration.mdc +10 -2
- package/templates/agents/rules/core.mdc +8 -1
- package/templates/agents/rules/database.mdc +10 -2
- package/templates/agents/rules/frontend.mdc +10 -2
- package/templates/agents/rules/guardrails.mdc +10 -2
- package/templates/agents/rules/hardening.mdc +10 -2
- package/templates/agents/rules/intent-routing.mdc +10 -2
- package/templates/agents/rules/planning.mdc +10 -2
- package/templates/agents/rules/security.mdc +11 -2
- package/templates/agents/rules/style.mdc +10 -2
- package/templates/agents/rules/system-workflow.mdc +10 -2
- package/templates/agents/rules/testing.mdc +9 -1
- package/templates/agents/rules/workflows.mdc +10 -2
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Security Rules & Best Practices"
|
|
3
|
+
description: "Apply when implementing authentication, authorization, API validation, secrets management, or protecting against OWASP Top 10 vulnerabilities"
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
version: "3.0.0"
|
|
6
|
+
tags: ["security", "auth", "validation", "secrets", "owasp"]
|
|
7
|
+
triggers:
|
|
8
|
+
- "User adds login/authentication to project"
|
|
9
|
+
- "Building API endpoints or handling user input"
|
|
10
|
+
- "Storing passwords, tokens, or sensitive data"
|
|
11
|
+
- "Validating form inputs or API requests"
|
|
12
|
+
- "Protecting against injection, XSS, CSRF"
|
|
13
|
+
- "Adding authorization/permissions to endpoints"
|
|
14
|
+
- "Integrating third-party APIs or external services"
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Security Rules & Best Practices
|
|
18
|
+
|
|
19
|
+
You are an expert security-focused developer implementing security-first development regardless of technology stack.
|
|
20
|
+
|
|
21
|
+
## Core Security Principles
|
|
22
|
+
|
|
23
|
+
- **Defense in Depth**: Implement multiple layers of security controls
|
|
24
|
+
- **Least Privilege**: Grant minimum necessary permissions for each role/service
|
|
25
|
+
- **Input Validation**: Validate all inputs at boundaries with appropriate schema validation
|
|
26
|
+
- **Output Encoding**: Encode all outputs to prevent injection attacks
|
|
27
|
+
- **Secure by Default**: Choose secure configurations over convenience
|
|
28
|
+
- **Fail Securely**: Default to denial, require explicit allow
|
|
29
|
+
|
|
30
|
+
## Authentication & Authorization Patterns
|
|
31
|
+
|
|
32
|
+
### Session Management Best Practices
|
|
33
|
+
|
|
34
|
+
Implement secure session handling regardless of framework:
|
|
35
|
+
- **Session storage**: Use secure cookies (HttpOnly, Secure, SameSite) or JWT tokens
|
|
36
|
+
- **Token expiration**: Implement appropriate timeout for token validity
|
|
37
|
+
- **Refresh tokens**: Separate long-lived and short-lived tokens
|
|
38
|
+
- **Session invalidation**: Properly terminate sessions on logout
|
|
39
|
+
- **CSRF protection**: Verify request origin for state-changing operations
|
|
40
|
+
|
|
41
|
+
### Authentication Patterns (Language-Agnostic)
|
|
42
|
+
|
|
43
|
+
Authentication Flow:
|
|
44
|
+
1. User provides credentials (username/password)
|
|
45
|
+
2. Validate credentials against hashed password in database
|
|
46
|
+
3. Create session or JWT token with user identity
|
|
47
|
+
4. Return session/token to client with secure flags
|
|
48
|
+
5. Client includes token/session in subsequent requests
|
|
49
|
+
6. Server validates token/session on each request
|
|
50
|
+
7. Extract user identity from verified token/session
|
|
51
|
+
|
|
52
|
+
**Key Requirements:**
|
|
53
|
+
- Hash passwords with strong algorithms (bcrypt, scrypt, argon2)
|
|
54
|
+
- Salt rounds: 12+ for bcrypt
|
|
55
|
+
- Never store plaintext passwords
|
|
56
|
+
- Implement rate limiting on authentication endpoints
|
|
57
|
+
- Log authentication attempts (failures especially)
|
|
58
|
+
- Provide clear error messages that don't leak user information
|
|
59
|
+
|
|
60
|
+
### Authorization Patterns (Language-Agnostic)
|
|
61
|
+
|
|
62
|
+
Authorization Flow:
|
|
63
|
+
1. Extract user identity from authenticated session/token
|
|
64
|
+
2. For each protected operation:
|
|
65
|
+
a. Check if user is authenticated
|
|
66
|
+
b. Retrieve user's roles/permissions from database
|
|
67
|
+
c. Verify required permissions for operation
|
|
68
|
+
d. Allow or deny based on permission check
|
|
69
|
+
3. Log authorization checks (especially failures)
|
|
70
|
+
4. Return appropriate error for denied access
|
|
71
|
+
|
|
72
|
+
**Role-Based Access Control (RBAC):**
|
|
73
|
+
- Define roles with clear permissions (admin, moderator, user, guest)
|
|
74
|
+
- Assign roles to users (can be multiple)
|
|
75
|
+
- Check user's roles before allowing sensitive operations
|
|
76
|
+
- Implement at API boundaries and critical business logic
|
|
77
|
+
- Audit role changes and permission checks
|
|
78
|
+
|
|
79
|
+
## Input Validation & Sanitization
|
|
80
|
+
|
|
81
|
+
### Validation Strategy (Technology-Agnostic)
|
|
82
|
+
|
|
83
|
+
Validate all user inputs at API boundaries:
|
|
84
|
+
|
|
85
|
+
Validation Process:
|
|
86
|
+
1. Define schema/rules for each input
|
|
87
|
+
- Data type (string, number, boolean, date, etc.)
|
|
88
|
+
- Length constraints (min/max)
|
|
89
|
+
- Format requirements (regex patterns)
|
|
90
|
+
- Allowed values (whitelist)
|
|
91
|
+
- Required fields
|
|
92
|
+
|
|
93
|
+
2. Validate incoming data against schema
|
|
94
|
+
- Reject invalid data with clear error messages
|
|
95
|
+
- Never modify user input, reject or accept
|
|
96
|
+
|
|
97
|
+
3. Transform/normalize data if needed
|
|
98
|
+
- Trim whitespace
|
|
99
|
+
- Convert to lowercase/uppercase as appropriate
|
|
100
|
+
- Parse dates to consistent format
|
|
101
|
+
|
|
102
|
+
4. Return validation result
|
|
103
|
+
- Success with validated data
|
|
104
|
+
- Failure with specific field errors
|
|
105
|
+
|
|
106
|
+
**Common Validation Rules:**
|
|
107
|
+
- Email: Valid format using standardized validation, convert to lowercase
|
|
108
|
+
- Password: Minimum 8 characters, complexity requirements (uppercase, lowercase, number, special)
|
|
109
|
+
- Names: 2-100 characters, alphanumeric with spaces allowed
|
|
110
|
+
- URLs: Valid URL format for whitelist only
|
|
111
|
+
- Phone: Valid format for your region
|
|
112
|
+
- User IDs: UUID v4 format or similar non-sequential identifiers
|
|
113
|
+
|
|
114
|
+
### Special Input Handling
|
|
115
|
+
|
|
116
|
+
**File Uploads:**
|
|
117
|
+
- Validate file content type (MIME type check from file content, not extension)
|
|
118
|
+
- Enforce size limits (max upload size)
|
|
119
|
+
- Scan for malware when possible
|
|
120
|
+
- Store outside web root
|
|
121
|
+
- No execute permission on upload directory
|
|
122
|
+
- Serve with inline=false to force download
|
|
123
|
+
|
|
124
|
+
**API Parameters:**
|
|
125
|
+
- Validate query parameters with same rules as request body
|
|
126
|
+
- Whitelist allowed parameters per endpoint
|
|
127
|
+
- Validate pagination limits (max 100-1000 items)
|
|
128
|
+
- Validate sort fields against whitelist
|
|
129
|
+
|
|
130
|
+
**Database Queries:**
|
|
131
|
+
- Use ORM/parameterized queries only (never string concatenation)
|
|
132
|
+
- Filter results to authenticated user's data
|
|
133
|
+
- Limit results with pagination
|
|
134
|
+
- Monitor for suspicious query patterns
|
|
135
|
+
|
|
136
|
+
## Rate Limiting & DoS Protection
|
|
137
|
+
|
|
138
|
+
### Rate Limiting Strategy
|
|
139
|
+
|
|
140
|
+
Implement rate limiting on sensitive endpoints:
|
|
141
|
+
|
|
142
|
+
Rate Limiting Levels:
|
|
143
|
+
- Authentication endpoints: 5 attempts per 15 minutes per IP
|
|
144
|
+
- API endpoints: 100-1000 requests per hour per user/IP
|
|
145
|
+
- Public endpoints: 1000+ requests per hour per IP
|
|
146
|
+
- Critical operations: 1 attempt per minute per user
|
|
147
|
+
|
|
148
|
+
**Implementation approach:**
|
|
149
|
+
- Use Redis or similar for distributed rate limiting
|
|
150
|
+
- Track by IP address, user ID, or API key depending on endpoint
|
|
151
|
+
- Return 429 (Too Many Requests) when limit exceeded
|
|
152
|
+
- Include retry-after header in response
|
|
153
|
+
- Log rate limit violations
|
|
154
|
+
|
|
155
|
+
## OWASP Top 10 Protection
|
|
156
|
+
|
|
157
|
+
### A01: Broken Access Control
|
|
158
|
+
- Implement authentication on all protected endpoints
|
|
159
|
+
- Check authorization for current user before returning data
|
|
160
|
+
- Use role-based access control with clear permission model
|
|
161
|
+
- Validate user can only access their own data
|
|
162
|
+
- Log authorization failures for security monitoring
|
|
163
|
+
|
|
164
|
+
### A02: Cryptographic Failures
|
|
165
|
+
- Hash passwords with strong algorithms (bcrypt, scrypt, argon2)
|
|
166
|
+
- Use HTTPS in production for all communications
|
|
167
|
+
- Store secrets in environment variables, never in code
|
|
168
|
+
- Use secure cookie flags (HttpOnly, Secure, SameSite)
|
|
169
|
+
- Encrypt sensitive data at rest when appropriate
|
|
170
|
+
|
|
171
|
+
### A03: Injection
|
|
172
|
+
- Use ORM/parameterized queries only (no string concatenation)
|
|
173
|
+
- Validate all inputs with schema/whitelist approach
|
|
174
|
+
- Encode output data in appropriate context (HTML, URL, etc.)
|
|
175
|
+
- Implement Content Security Policy headers
|
|
176
|
+
- Use prepared statements for database queries
|
|
177
|
+
|
|
178
|
+
### A04: Insecure Design
|
|
179
|
+
- Implement authentication and authorization from start
|
|
180
|
+
- Rate limit authentication endpoints
|
|
181
|
+
- Validate input at every API boundary
|
|
182
|
+
- Design with fail-secure defaults
|
|
183
|
+
- Implement comprehensive error handling
|
|
184
|
+
|
|
185
|
+
### A05: Security Misconfiguration
|
|
186
|
+
- Run only necessary services/features
|
|
187
|
+
- Implement all security headers (CSP, X-Frame-Options, HSTS, etc.)
|
|
188
|
+
- Update frameworks and dependencies regularly
|
|
189
|
+
- Remove default accounts and credentials
|
|
190
|
+
- Validate environment variables at startup
|
|
191
|
+
|
|
192
|
+
### A06: Vulnerable Components
|
|
193
|
+
- Keep dependencies updated with security patches
|
|
194
|
+
- Use lock files (package-lock.json, requirements.txt, etc.)
|
|
195
|
+
- Regularly scan dependencies for vulnerabilities
|
|
196
|
+
- Remove unused dependencies
|
|
197
|
+
- Only use supported versions of frameworks
|
|
198
|
+
|
|
199
|
+
### A07: Authentication Failure
|
|
200
|
+
- Implement strong password requirements
|
|
201
|
+
- Use rate limiting on authentication endpoints
|
|
202
|
+
- Hash passwords securely (bcrypt, scrypt, argon2)
|
|
203
|
+
- Implement session timeouts
|
|
204
|
+
- Log authentication attempts
|
|
205
|
+
|
|
206
|
+
### A08: Data Integrity Failures
|
|
207
|
+
- Validate all input data with schema validation
|
|
208
|
+
- Implement proper error handling
|
|
209
|
+
- Log integrity violation attempts
|
|
210
|
+
- Use strong checksums/hashes for critical data
|
|
211
|
+
- Implement database constraints
|
|
212
|
+
|
|
213
|
+
### A09: Logging and Monitoring Failure
|
|
214
|
+
- Log authentication and authorization events
|
|
215
|
+
- Log sensitive operations and data access
|
|
216
|
+
- Monitor for suspicious patterns
|
|
217
|
+
- Keep logs secure and don't expose sensitive info
|
|
218
|
+
- Alert on security-relevant events
|
|
219
|
+
|
|
220
|
+
### A10: SSRF (Server-Side Request Forgery)
|
|
221
|
+
- Validate and whitelist URLs that application accesses
|
|
222
|
+
- Implement network-level restrictions
|
|
223
|
+
- Disable unused URL schemes
|
|
224
|
+
- Implement timeouts on external requests
|
|
225
|
+
- Log and monitor external API calls
|
|
226
|
+
|
|
227
|
+
## Environment & Secrets Management
|
|
228
|
+
|
|
229
|
+
### Environment Variables
|
|
230
|
+
|
|
231
|
+
Environment Variable Validation Pattern:
|
|
232
|
+
1. Define all required variables with types
|
|
233
|
+
2. Load from .env file or environment not from code
|
|
234
|
+
3. Validate all variables exist at startup
|
|
235
|
+
4. Validate all variables are correct type/format
|
|
236
|
+
5. Provide clear error if validation fails
|
|
237
|
+
6. Never log or expose environment variables
|
|
238
|
+
|
|
239
|
+
**Sensitive Variables:**
|
|
240
|
+
- Database credentials (URL, passwords)
|
|
241
|
+
- API keys and secrets
|
|
242
|
+
- Encryption keys
|
|
243
|
+
- Authentication secrets (session secret, JWT secret)
|
|
244
|
+
- Third-party service credentials
|
|
245
|
+
|
|
246
|
+
No sensitive variables should ever be:
|
|
247
|
+
- Committed to version control
|
|
248
|
+
- Logged (even in debug logs)
|
|
249
|
+
- Exposed in error messages
|
|
250
|
+
- Included in client-side code
|
|
251
|
+
- Transmitted in URLs
|
|
252
|
+
|
|
253
|
+
## Application Hardening & Obfuscation
|
|
254
|
+
|
|
255
|
+
- Treat obfuscation as **defense in depth**, not a replacement for authentication, authorization, secrets hygiene, or validation.
|
|
256
|
+
- Apply hardening selectively by risk profile, especially for distributed clients (mobile/desktop/browser) and high-value IP logic.
|
|
257
|
+
- Integrate hardening into build/release flow and require post-hardening functional regression and performance checks.
|
|
258
|
+
- Protect symbol/mapping/debug artifacts with restricted access and secure retention policies.
|
|
259
|
+
- Require reproducible builds and a clear rollback path for hardened releases.
|
|
260
|
+
|
|
261
|
+
## Security Checklist
|
|
262
|
+
|
|
263
|
+
Before deploying to production:
|
|
264
|
+
|
|
265
|
+
- [ ] All inputs validated with schema validation
|
|
266
|
+
- [ ] Password hashing implemented with strong algorithm
|
|
267
|
+
- [ ] Rate limiting on authentication endpoints
|
|
268
|
+
- [ ] HTTPS enforced in production
|
|
269
|
+
- [ ] Security headers configured
|
|
270
|
+
- [ ] Environment variables validated at startup
|
|
271
|
+
- [ ] No sensitive data in logs
|
|
272
|
+
- [ ] Database queries use ORM (no raw SQL)
|
|
273
|
+
- [ ] Authorization checks on protected endpoints
|
|
274
|
+
- [ ] Error messages don't leak sensitive information
|
|
275
|
+
- [ ] External API calls use HTTPS
|
|
276
|
+
- [ ] Dependencies scanned for vulnerabilities
|
|
277
|
+
- [ ] Unused dependencies removed
|
|
278
|
+
- [ ] Dead code removed
|
|
279
|
+
- [ ] Secrets never committed to version control
|
|
280
|
+
- [ ] Session/token timeouts configured
|
|
281
|
+
- [ ] CSRF protection implemented (if applicable)
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
Remember: **Security must be built in from the beginning, not added as an afterthought.**
|
|
286
|
+
Every feature should consider security implications, and every developer should understand these principles.
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Code Style and Standards"
|
|
3
|
+
description: "Apply when organizing code, naming variables, formatting, or improving code clarity and maintainability"
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
version: "3.0.0"
|
|
6
|
+
tags: ["style", "formatting", "naming", "quality"]
|
|
7
|
+
globs:
|
|
8
|
+
- "**/*"
|
|
9
|
+
triggers:
|
|
10
|
+
- "Writing or reviewing code"
|
|
11
|
+
- "Setting up code formatting rules"
|
|
12
|
+
- "Naming variables, functions, or files"
|
|
13
|
+
- "Organizing module structure"
|
|
14
|
+
- "Refactoring or improving readability"
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Code Style and Standards
|
|
18
|
+
|
|
19
|
+
Language and framework-agnostic standards for clean, maintainable code.
|
|
20
|
+
|
|
21
|
+
## General Code Quality
|
|
22
|
+
|
|
23
|
+
### Core Principles
|
|
24
|
+
|
|
25
|
+
- **Readability**: Code should be easy to understand without extensive comments
|
|
26
|
+
- **Consistency**: Follow the same patterns throughout the codebase
|
|
27
|
+
- **Simplicity**: Prefer simple solutions to complex ones
|
|
28
|
+
- **SOLID principles**: Single responsibility, Open/closed, Liskov, Interface segregation, Dependency inversion
|
|
29
|
+
- **DRY**: Don't Repeat Yourself - extract common patterns
|
|
30
|
+
|
|
31
|
+
### Code Review Standards
|
|
32
|
+
|
|
33
|
+
Code should:
|
|
34
|
+
- Do one thing well
|
|
35
|
+
- Be testable
|
|
36
|
+
- Have no dead code
|
|
37
|
+
- Follow established patterns
|
|
38
|
+
- Include appropriate comments
|
|
39
|
+
- Have meaningful names
|
|
40
|
+
- Handle errors appropriately
|
|
41
|
+
- Consider security implications
|
|
42
|
+
- Consider performance implications
|
|
43
|
+
|
|
44
|
+
## Naming Conventions
|
|
45
|
+
|
|
46
|
+
### File Naming
|
|
47
|
+
|
|
48
|
+
Choose from established conventions:
|
|
49
|
+
|
|
50
|
+
**Option 1: kebab-case (Recommended)**
|
|
51
|
+
- File names: `user-profile.ts`, `navigation-bar.tsx`, `date-utils.js`
|
|
52
|
+
- Matches URLs and file systems
|
|
53
|
+
- Language-agnostic
|
|
54
|
+
- Easy to type and read
|
|
55
|
+
|
|
56
|
+
**Option 2: snake_case**
|
|
57
|
+
- File names: `user_profile.py`, `date_utils.go`
|
|
58
|
+
- Common in Python, Go, and Ruby
|
|
59
|
+
- Matches language conventions
|
|
60
|
+
|
|
61
|
+
**Option 3: PascalCase**
|
|
62
|
+
- File names: `UserProfile.tsx`, `DateUtils.ts`
|
|
63
|
+
- Common in C# and some JavaScript frameworks
|
|
64
|
+
- Use consistently if chosen
|
|
65
|
+
|
|
66
|
+
**Consistency rule**: Pick ONE and use it throughout the entire project.
|
|
67
|
+
|
|
68
|
+
### Code Naming
|
|
69
|
+
|
|
70
|
+
Consistent naming patterns:
|
|
71
|
+
|
|
72
|
+
**Variables and Functions**
|
|
73
|
+
- Use camelCase: `getUserData`, `isLoading`, `handleSubmit`
|
|
74
|
+
- Use English words (even in non-English projects)
|
|
75
|
+
- Be descriptive: `user` is worse than `currentUser`
|
|
76
|
+
- Avoid abbreviations: `getDesc` vs `getDescription`
|
|
77
|
+
- Prefix booleans with is/has: `isActive`, `hasPermission`
|
|
78
|
+
|
|
79
|
+
**Constants**
|
|
80
|
+
- Use UPPER_SNAKE_CASE: `MAX_RETRIES`, `API_BASE_URL`
|
|
81
|
+
- Immutable values that don't change
|
|
82
|
+
- Global configuration values
|
|
83
|
+
- Magic numbers should become constants
|
|
84
|
+
|
|
85
|
+
**Classes/Types/Interfaces**
|
|
86
|
+
- Use PascalCase: `UserProfile`, `ApiResponse`, `DatabaseConfig`
|
|
87
|
+
- Descriptive and specific names
|
|
88
|
+
- Avoid generic names like `Data`, `Info`, `Object`
|
|
89
|
+
|
|
90
|
+
**Enums**
|
|
91
|
+
- Type name PascalCase: `UserStatus`
|
|
92
|
+
- Values UPPER_SNAKE_CASE: `ACTIVE`, `INACTIVE`
|
|
93
|
+
- Example: `UserStatus.ACTIVE`, `Theme.DARK_MODE`
|
|
94
|
+
|
|
95
|
+
### Examples
|
|
96
|
+
|
|
97
|
+
Good naming:
|
|
98
|
+
```
|
|
99
|
+
getUserById()
|
|
100
|
+
isValidEmail()
|
|
101
|
+
parseJsonResponse()
|
|
102
|
+
calculateProposedDiscount()
|
|
103
|
+
MAXIMUM_RETRY_ATTEMPTS
|
|
104
|
+
ValidationError
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Bad naming:
|
|
108
|
+
```
|
|
109
|
+
get()
|
|
110
|
+
foo(), bar(), x
|
|
111
|
+
process()
|
|
112
|
+
u1, u2, s
|
|
113
|
+
var1, var2
|
|
114
|
+
handleIt()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Formatting
|
|
118
|
+
|
|
119
|
+
### Consistent Formatting
|
|
120
|
+
|
|
121
|
+
Use automated tools:
|
|
122
|
+
- **Prettier**: JavaScript/TypeScript/CSS/YAML
|
|
123
|
+
- **Black**: Python
|
|
124
|
+
- **gofmt**: Go
|
|
125
|
+
- **rustfmt**: Rust
|
|
126
|
+
- **clang-format**: C/C++
|
|
127
|
+
- Your language's standard formatter
|
|
128
|
+
|
|
129
|
+
Benefits:
|
|
130
|
+
- No debates about formatting
|
|
131
|
+
- Quick review of actual changes
|
|
132
|
+
- Consistent codebase
|
|
133
|
+
|
|
134
|
+
### Line Length
|
|
135
|
+
|
|
136
|
+
- Target: 80-120 characters
|
|
137
|
+
- Maximum: 120-140 characters
|
|
138
|
+
- Avoid scrolling horizontally
|
|
139
|
+
|
|
140
|
+
### Indentation
|
|
141
|
+
|
|
142
|
+
Choose ONE and use consistently:
|
|
143
|
+
- **2 spaces**: JavaScript, YAML, some Python
|
|
144
|
+
- **4 spaces**: Python, Java, most languages
|
|
145
|
+
- **Tabs**: If configured, consistently
|
|
146
|
+
|
|
147
|
+
### Comments & Documentation
|
|
148
|
+
|
|
149
|
+
Good comments explain:
|
|
150
|
+
- **Why**: The reason for this code
|
|
151
|
+
- **Complex logic**: How it works if not obvious
|
|
152
|
+
- **Edge cases**: Special handling and why
|
|
153
|
+
- **Warnings**: Performance implications or gotchas
|
|
154
|
+
|
|
155
|
+
Bad comments:
|
|
156
|
+
```
|
|
157
|
+
// Increment x
|
|
158
|
+
x = x + 1
|
|
159
|
+
|
|
160
|
+
// Loop through users
|
|
161
|
+
for (user in users) { ... }
|
|
162
|
+
|
|
163
|
+
// This is a variable
|
|
164
|
+
let name = getUserName()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Good comments:
|
|
168
|
+
```
|
|
169
|
+
// Increment retry counter before exponential backoff
|
|
170
|
+
retryCount = retryCount + 1
|
|
171
|
+
|
|
172
|
+
// Process users in batches to prevent memory overload
|
|
173
|
+
for (batch in users.batches()) { ... }
|
|
174
|
+
|
|
175
|
+
// Fetch fresh name from API to avoid stale cache
|
|
176
|
+
let name = getUserName()
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Comments vs Code
|
|
180
|
+
|
|
181
|
+
Let code speak for itself:
|
|
182
|
+
|
|
183
|
+
Instead of:
|
|
184
|
+
```
|
|
185
|
+
// Get user age
|
|
186
|
+
int age = currentYear - birthYear
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Write:
|
|
190
|
+
```
|
|
191
|
+
int age = calculateAge(currentYear, birthYear)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Code Organization
|
|
195
|
+
|
|
196
|
+
### Module Organization
|
|
197
|
+
|
|
198
|
+
Order within files:
|
|
199
|
+
1. **Imports/Dependencies** - at top
|
|
200
|
+
2. **Constants** - module-level constants
|
|
201
|
+
3. **Types/Interfaces** - type definitions
|
|
202
|
+
4. **Functions/Classes** - main code (public first, private after)
|
|
203
|
+
5. **Exports** - explicit exports at end
|
|
204
|
+
|
|
205
|
+
### Function Organization
|
|
206
|
+
|
|
207
|
+
Function structure:
|
|
208
|
+
1. **Parameters** - at top
|
|
209
|
+
2. **Early returns** - validate inputs early
|
|
210
|
+
3. **Logic** - main implementation
|
|
211
|
+
4. **Return** - return result
|
|
212
|
+
|
|
213
|
+
### Class/Object Organization
|
|
214
|
+
|
|
215
|
+
Class structure:
|
|
216
|
+
1. **Constructor/initializer**
|
|
217
|
+
2. **Public methods**
|
|
218
|
+
3. **Private methods**
|
|
219
|
+
4. **Getters/setters**
|
|
220
|
+
5. **Static methods** (if applicable)
|
|
221
|
+
|
|
222
|
+
## Type Definitions
|
|
223
|
+
|
|
224
|
+
### Clear Type Contracts
|
|
225
|
+
|
|
226
|
+
Document what your types expect:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
Define data structures clearly:
|
|
230
|
+
- What fields are required
|
|
231
|
+
- What data types
|
|
232
|
+
- What values are valid
|
|
233
|
+
- Any constraints or rules
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Avoid Magic Values
|
|
237
|
+
|
|
238
|
+
Instead of magic numbers/strings:
|
|
239
|
+
```
|
|
240
|
+
if (status === 1) { ... }
|
|
241
|
+
if (timeout === 60000) { ... }
|
|
242
|
+
|
|
243
|
+
const ACTIVE_STATUS = 1
|
|
244
|
+
const DEFAULT_TIMEOUT_MS = 60000
|
|
245
|
+
if (status === ACTIVE_STATUS) { ... }
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Error Handling
|
|
249
|
+
|
|
250
|
+
### Clear Error Messages
|
|
251
|
+
|
|
252
|
+
Error messages should:
|
|
253
|
+
- Describe what went wrong
|
|
254
|
+
- Explain why (if not obvious)
|
|
255
|
+
- Suggest how to fix
|
|
256
|
+
- Use user-friendly language
|
|
257
|
+
|
|
258
|
+
Good error messages:
|
|
259
|
+
- "Email format is invalid. Please enter a valid email address."
|
|
260
|
+
- "Password must be at least 8 characters."
|
|
261
|
+
- "User with this email already exists."
|
|
262
|
+
|
|
263
|
+
Bad error messages:
|
|
264
|
+
- "Error"
|
|
265
|
+
- "Invalid input"
|
|
266
|
+
- "Stack trace here..."
|
|
267
|
+
|
|
268
|
+
### Error Handling Pattern
|
|
269
|
+
|
|
270
|
+
Proper error handling:
|
|
271
|
+
1. Catch/handle errors explicitly
|
|
272
|
+
2. Log error with context
|
|
273
|
+
3. Return appropriate error response
|
|
274
|
+
4. Never expose sensitive data
|
|
275
|
+
5. Include error code for client handling
|
|
276
|
+
|
|
277
|
+
## Security in Code
|
|
278
|
+
|
|
279
|
+
### Dangerous Patterns to Avoid
|
|
280
|
+
|
|
281
|
+
Never:
|
|
282
|
+
- Store secrets in code
|
|
283
|
+
- Log sensitive data
|
|
284
|
+
- Dynamic SQL/query construction
|
|
285
|
+
- Eval user input
|
|
286
|
+
- Hardcoded API keys
|
|
287
|
+
- Return sensitive data in errors
|
|
288
|
+
- Skip input validation
|
|
289
|
+
|
|
290
|
+
Always:
|
|
291
|
+
- Validate all inputs
|
|
292
|
+
- Use parameterized queries
|
|
293
|
+
- Hash sensitive data
|
|
294
|
+
- Use environment variables for secrets
|
|
295
|
+
- Log security events
|
|
296
|
+
- Encode output appropriately
|
|
297
|
+
|
|
298
|
+
## Performance Considerations
|
|
299
|
+
|
|
300
|
+
### Avoid N+1 Queries
|
|
301
|
+
|
|
302
|
+
Good:
|
|
303
|
+
```
|
|
304
|
+
Get all users once with their posts
|
|
305
|
+
Result: 1 query
|
|
306
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "System Workflow Orchestration"
|
|
3
|
+
description: "Apply when planning work phases, defining acceptance criteria, or establishing delivery gates and rollback strategies"
|
|
4
|
+
version: "1.0.0"
|
|
5
|
+
tags: ["workflow", "gates", "delivery", "governance"]
|
|
6
|
+
triggers:
|
|
7
|
+
- "Starting a new feature or major change"
|
|
8
|
+
- "Planning implementation phases"
|
|
9
|
+
- "Defining acceptance criteria"
|
|
10
|
+
- "Establishing rollback procedures"
|
|
11
|
+
- "Preparing for release or deployment"
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Purpose
|
|
15
|
+
|
|
16
|
+
Define a repeatable lifecycle so all work is traceable, verifiable, and releasable.
|
|
17
|
+
|
|
18
|
+
## Workflow Phases
|
|
19
|
+
|
|
20
|
+
1. Discover
|
|
21
|
+
2. Plan
|
|
22
|
+
3. Implement
|
|
23
|
+
4. Verify
|
|
24
|
+
5. Release
|
|
25
|
+
|
|
26
|
+
## Phase Requirements
|
|
27
|
+
|
|
28
|
+
### 1) Discover
|
|
29
|
+
- Capture objective, scope boundaries, constraints, and risk profile.
|
|
30
|
+
- Produce: context summary + assumptions.
|
|
31
|
+
|
|
32
|
+
### 2) Plan
|
|
33
|
+
- Break work into atomic units and dependency order.
|
|
34
|
+
- Define acceptance criteria and rollback considerations.
|
|
35
|
+
- Produce: execution plan with checkpoints.
|
|
36
|
+
|
|
37
|
+
### 3) Implement
|
|
38
|
+
- Apply smallest safe changes within declared scope.
|
|
39
|
+
- Keep changes deterministic and reversible when possible.
|
|
40
|
+
- Produce: change summary and affected files.
|
|
41
|
+
|
|
42
|
+
### 4) Verify
|
|
43
|
+
- Run relevant tests/checks (targeted first, broad second).
|
|
44
|
+
- Confirm security and regression impact.
|
|
45
|
+
- Produce: validation evidence.
|
|
46
|
+
|
|
47
|
+
### 5) Release
|
|
48
|
+
- Check gates: tests, security posture, migration safety, rollback readiness.
|
|
49
|
+
- Produce: release decision + rollout/rollback steps.
|
|
50
|
+
|
|
51
|
+
## Required Delivery Artifacts
|
|
52
|
+
|
|
53
|
+
- Objective and scope
|
|
54
|
+
- Acceptance criteria
|
|
55
|
+
- Risk register
|
|
56
|
+
- Validation evidence
|
|
57
|
+
- Rollback strategy (for non-trivial changes)
|
|
58
|
+
|
|
59
|
+
## Gate Rules
|
|
60
|
+
|
|
61
|
+
- Fail any critical gate -> `status: blocked`.
|
|
62
|
+
- Missing rollback for risky changes -> blocked.
|
|
63
|
+
- Missing validation evidence -> blocked.
|
|
64
|
+
|
|
65
|
+
## Rollback Requirements
|
|
66
|
+
|
|
67
|
+
- Identify rollback trigger conditions.
|
|
68
|
+
- Provide explicit rollback steps.
|
|
69
|
+
- Keep backups/version references for destructive changes.
|