opencode-agile-agent 1.0.1 → 1.0.2
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/README.md +61 -71
- package/bin/cli.js +344 -434
- package/bin/sync-templates.js +45 -0
- package/bin/validate-templates.js +44 -6
- package/package.json +2 -1
- package/templates/.opencode/ARCHITECTURE.md +82 -368
- package/templates/.opencode/README.md +110 -391
- package/templates/.opencode/agents/api-designer.md +45 -312
- package/templates/.opencode/agents/backend-specialist.md +46 -214
- package/templates/.opencode/agents/code-archaeologist.md +45 -260
- package/templates/.opencode/agents/context-gatherer.md +51 -0
- package/templates/.opencode/agents/database-architect.md +45 -212
- package/templates/.opencode/agents/debugger.md +45 -302
- package/templates/.opencode/agents/developer.md +45 -523
- package/templates/.opencode/agents/devops-engineer.md +45 -253
- package/templates/.opencode/agents/documentation-writer.md +45 -247
- package/templates/.opencode/agents/explorer-agent.md +49 -233
- package/templates/.opencode/agents/feature-lead.md +62 -302
- package/templates/.opencode/agents/frontend-specialist.md +46 -186
- package/templates/.opencode/agents/game-developer.md +45 -391
- package/templates/.opencode/agents/mobile-developer.md +45 -264
- package/templates/.opencode/agents/orchestrator.md +48 -463
- package/templates/.opencode/agents/penetration-tester.md +44 -254
- package/templates/.opencode/agents/performance-optimizer.md +45 -292
- package/templates/.opencode/agents/pr-reviewer.md +45 -468
- package/templates/.opencode/agents/product-manager.md +46 -225
- package/templates/.opencode/agents/project-planner.md +45 -248
- package/templates/.opencode/agents/qa-automation-engineer.md +45 -275
- package/templates/.opencode/agents/security-auditor.md +44 -258
- package/templates/.opencode/agents/seo-specialist.md +45 -266
- package/templates/.opencode/agents/system-analyst.md +48 -428
- package/templates/.opencode/agents/test-engineer.md +45 -229
- package/templates/.opencode/archive/README.md +24 -0
- package/templates/.opencode/commands/brainstorm.md +10 -0
- package/templates/.opencode/commands/create.md +11 -0
- package/templates/.opencode/commands/debug.md +10 -0
- package/templates/.opencode/commands/plan.md +9 -0
- package/templates/.opencode/commands/review.md +11 -0
- package/templates/.opencode/commands/status.md +9 -0
- package/templates/.opencode/commands/test.md +10 -0
- package/templates/.opencode/skills/api-patterns/SKILL.md +25 -149
- package/templates/.opencode/skills/brainstorming/SKILL.md +26 -242
- package/templates/.opencode/skills/clean-code/SKILL.md +27 -339
- package/templates/.opencode/skills/code-philosophy/SKILL.md +27 -499
- package/templates/.opencode/skills/context-archive/SKILL.md +47 -0
- package/templates/.opencode/skills/context-gathering/SKILL.md +51 -0
- package/templates/.opencode/skills/frontend-design/SKILL.md +26 -224
- package/templates/.opencode/skills/intelligent-routing/SKILL.md +25 -182
- package/templates/.opencode/skills/parallel-agents/SKILL.md +25 -261
- package/templates/.opencode/skills/plan-writing/SKILL.md +28 -238
- package/templates/.opencode/skills/redteam-validation/SKILL.md +33 -0
- package/templates/.opencode/skills/security-gate/SKILL.md +33 -0
- package/templates/.opencode/skills/systematic-debugging/SKILL.md +25 -197
- package/templates/.opencode/skills/testing-patterns/SKILL.md +25 -238
- package/templates/AGENTS.template.md +300 -426
- package/templates/.opencode/agents/product-owner.md +0 -264
- package/templates/.opencode/workflows/brainstorm.md +0 -110
- package/templates/.opencode/workflows/create.md +0 -108
- package/templates/.opencode/workflows/debug.md +0 -128
- package/templates/.opencode/workflows/deploy.md +0 -160
- package/templates/.opencode/workflows/enhance.md +0 -253
- package/templates/.opencode/workflows/orchestrate.md +0 -130
- package/templates/.opencode/workflows/plan.md +0 -163
- package/templates/.opencode/workflows/review.md +0 -135
- package/templates/.opencode/workflows/status.md +0 -102
- package/templates/.opencode/workflows/test.md +0 -146
|
@@ -1,255 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: brainstorming
|
|
3
|
-
description:
|
|
4
|
-
version: 1.0.0
|
|
3
|
+
description: Explore fuzzy requests with Socratic questions, tradeoffs, and a recommended direction.
|
|
5
4
|
---
|
|
6
5
|
|
|
7
6
|
# Brainstorming
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
## Philosophy
|
|
9
|
+
Questions shape the solution. Discovery should narrow the space before anyone commits to a path.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Use When
|
|
12
|
+
- The request is ambiguous or the scope is not settled.
|
|
13
|
+
- There are multiple valid approaches and a default choice is needed.
|
|
14
|
+
- You need to surface assumptions before planning or coding.
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
## Core Moves
|
|
17
|
+
- Ask to uncover the problem, audience, constraints, and success criteria.
|
|
18
|
+
- Separate options from decisions.
|
|
19
|
+
- Reflect back what you heard before moving forward.
|
|
20
|
+
- Keep the conversation moving; avoid endless exploration.
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
## Default Moves
|
|
23
|
+
- Ask 3-5 targeted questions, not a full interview.
|
|
24
|
+
- Compare 2-3 options and recommend one default.
|
|
25
|
+
- Record the open questions that remain.
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Who has this problem?
|
|
20
|
-
- Why does it matter?
|
|
27
|
+
## Anti-Patterns
|
|
28
|
+
- Leading questions, yes/no traps, hidden assumptions, and jumping to architecture too early.
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
## Variation
|
|
31
|
+
- Use 3-question mode for simple requests.
|
|
32
|
+
- Use 5-whys for bugs and root-cause conversations.
|
|
33
|
+
- Use a tradeoff matrix when the decision is architectural.
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- What's the definition of done?
|
|
30
|
-
- What would failure look like?
|
|
35
|
+
## Output
|
|
36
|
+
- Return a crisp problem statement, a small set of options, a recommendation, and unresolved questions.
|
|
31
37
|
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
### 5 Whys
|
|
35
|
-
|
|
36
|
-
Dig deeper into root causes:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
Problem: Users aren't completing checkout
|
|
40
|
-
|
|
41
|
-
Why? → Form is too long
|
|
42
|
-
Why? → We're asking for too much information
|
|
43
|
-
Why? → We want complete user profiles
|
|
44
|
-
Why? → Marketing wants demographic data
|
|
45
|
-
Why? → To improve targeting
|
|
46
|
-
|
|
47
|
-
Root cause: Marketing needs vs. UX needs conflict
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### SCAMPER
|
|
51
|
-
|
|
52
|
-
Explore alternatives:
|
|
53
|
-
|
|
54
|
-
| Question | Prompt |
|
|
55
|
-
|----------|--------|
|
|
56
|
-
| **S**ubstitute | What can be replaced? |
|
|
57
|
-
| **C**ombine | What can be merged? |
|
|
58
|
-
| **A**dapt | What can be adjusted? |
|
|
59
|
-
| **M**odify | What can be changed? |
|
|
60
|
-
| **P**ut to other use | What else can it do? |
|
|
61
|
-
| **E**liminate | What can be removed? |
|
|
62
|
-
| **R**everse | What can be inverted? |
|
|
63
|
-
|
|
64
|
-
### Six Thinking Hats
|
|
65
|
-
|
|
66
|
-
Explore from different perspectives:
|
|
67
|
-
|
|
68
|
-
| Hat | Focus |
|
|
69
|
-
|-----|-------|
|
|
70
|
-
| **White** | Facts and data |
|
|
71
|
-
| **Red** | Emotions and feelings |
|
|
72
|
-
| **Black** | Risks and problems |
|
|
73
|
-
| **Yellow** | Benefits and value |
|
|
74
|
-
| **Green** | Creativity and alternatives |
|
|
75
|
-
| **Blue** | Process and control |
|
|
76
|
-
|
|
77
|
-
## Discovery Process
|
|
78
|
-
|
|
79
|
-
### Phase 1: Understand the Request
|
|
80
|
-
|
|
81
|
-
```markdown
|
|
82
|
-
Initial request: "Build a dashboard"
|
|
83
|
-
|
|
84
|
-
Questions to ask:
|
|
85
|
-
- Who will use this dashboard?
|
|
86
|
-
- What decisions will they make from it?
|
|
87
|
-
- What data do they need?
|
|
88
|
-
- How often will they use it?
|
|
89
|
-
- What devices will they use?
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Phase 2: Explore Options
|
|
93
|
-
|
|
94
|
-
```markdown
|
|
95
|
-
Options for dashboard:
|
|
96
|
-
1. Real-time monitoring dashboard
|
|
97
|
-
2. Analytics dashboard with charts
|
|
98
|
-
3. Task management dashboard
|
|
99
|
-
4. Executive summary dashboard
|
|
100
|
-
|
|
101
|
-
Trade-offs:
|
|
102
|
-
- Real-time vs. historical data
|
|
103
|
-
- Simple vs. detailed
|
|
104
|
-
- Mobile vs. desktop priority
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Phase 3: Define Scope
|
|
108
|
-
|
|
109
|
-
```markdown
|
|
110
|
-
In Scope:
|
|
111
|
-
- [Feature 1]
|
|
112
|
-
- [Feature 2]
|
|
113
|
-
|
|
114
|
-
Out of Scope:
|
|
115
|
-
- [Feature X]
|
|
116
|
-
- [Feature Y]
|
|
117
|
-
|
|
118
|
-
MVP:
|
|
119
|
-
- [Minimum viable feature set]
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Phase 4: Validate Understanding
|
|
123
|
-
|
|
124
|
-
```markdown
|
|
125
|
-
"So what I'm hearing is:
|
|
126
|
-
- You need [X]
|
|
127
|
-
- For [audience]
|
|
128
|
-
- To solve [problem]
|
|
129
|
-
- With [constraints]
|
|
130
|
-
|
|
131
|
-
Is that correct?"
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Question Templates
|
|
135
|
-
|
|
136
|
-
### For New Features
|
|
137
|
-
|
|
138
|
-
```markdown
|
|
139
|
-
1. What problem does this solve?
|
|
140
|
-
2. Who is the target user?
|
|
141
|
-
3. How are they solving this today?
|
|
142
|
-
4. What would make this feature a success?
|
|
143
|
-
5. What are the must-haves vs. nice-to-haves?
|
|
144
|
-
6. What's the timeline?
|
|
145
|
-
7. Are there any technical constraints?
|
|
146
|
-
8. Are there any design preferences?
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### For Bug Fixes
|
|
150
|
-
|
|
151
|
-
```markdown
|
|
152
|
-
1. What's the expected behavior?
|
|
153
|
-
2. What's the actual behavior?
|
|
154
|
-
3. When did this start happening?
|
|
155
|
-
4. Can you reproduce it reliably?
|
|
156
|
-
5. What steps reproduce it?
|
|
157
|
-
6. What have you tried to fix it?
|
|
158
|
-
7. Who is affected by this?
|
|
159
|
-
8. How urgent is this?
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### For Performance Issues
|
|
163
|
-
|
|
164
|
-
```markdown
|
|
165
|
-
1. What's slow?
|
|
166
|
-
2. How slow is it? (measure)
|
|
167
|
-
3. When is it slow?
|
|
168
|
-
4. Has it always been slow?
|
|
169
|
-
5. What changed recently?
|
|
170
|
-
6. What's the target performance?
|
|
171
|
-
7. What metrics matter most?
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### For Architecture Decisions
|
|
175
|
-
|
|
176
|
-
```markdown
|
|
177
|
-
1. What are we trying to achieve?
|
|
178
|
-
2. What are the constraints?
|
|
179
|
-
3. What are the options?
|
|
180
|
-
4. What are the trade-offs of each?
|
|
181
|
-
5. What's the impact of each option?
|
|
182
|
-
6. How reversible is this decision?
|
|
183
|
-
7. What's the cost of waiting?
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Facilitation Techniques
|
|
187
|
-
|
|
188
|
-
### Dot Voting
|
|
189
|
-
|
|
190
|
-
```markdown
|
|
191
|
-
Options:
|
|
192
|
-
- Option A •••• (4 votes)
|
|
193
|
-
- Option B •• (2 votes)
|
|
194
|
-
- Option C ••• (3 votes)
|
|
195
|
-
|
|
196
|
-
→ Proceed with Option A
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Impact/Effort Matrix
|
|
200
|
-
|
|
201
|
-
```
|
|
202
|
-
High Impact
|
|
203
|
-
│
|
|
204
|
-
Quick Wins │ Major Projects
|
|
205
|
-
──────────────┼──────────────
|
|
206
|
-
Fill-ins │ Money Pits
|
|
207
|
-
│
|
|
208
|
-
Low Impact
|
|
209
|
-
Low Effort High Effort
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Affinity Mapping
|
|
213
|
-
|
|
214
|
-
```markdown
|
|
215
|
-
Group related ideas:
|
|
216
|
-
|
|
217
|
-
[Performance] [Security] [UX]
|
|
218
|
-
- Load time - Auth - Navigation
|
|
219
|
-
- Caching - Encryption - Responsive
|
|
220
|
-
- CDN - Validation - Accessibility
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Anti-Patterns to Avoid
|
|
224
|
-
|
|
225
|
-
### Leading Questions
|
|
226
|
-
|
|
227
|
-
```
|
|
228
|
-
❌ "Don't you think we should use React?"
|
|
229
|
-
✅ "What frontend framework are you considering?"
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Yes/No Questions
|
|
233
|
-
|
|
234
|
-
```
|
|
235
|
-
❌ "Do you need authentication?"
|
|
236
|
-
✅ "Tell me about your authentication requirements."
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### Assumptions
|
|
240
|
-
|
|
241
|
-
```
|
|
242
|
-
❌ "I assume you want dark mode."
|
|
243
|
-
✅ "Do you have preferences for the visual theme?"
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Solutionizing
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
❌ "We should build it with microservices."
|
|
250
|
-
✅ "What are your scalability requirements?"
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
---
|
|
254
|
-
|
|
255
|
-
**Good questions lead to better solutions.**
|
|
38
|
+
## Remember
|
|
39
|
+
Good questions make later specs smaller and clearer.
|
|
@@ -1,351 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clean-code
|
|
3
|
-
description:
|
|
4
|
-
version: 1.0.0
|
|
3
|
+
description: Apply global coding standards for readable, maintainable, defensive code.
|
|
5
4
|
---
|
|
6
5
|
|
|
7
|
-
# Clean Code
|
|
6
|
+
# Clean Code
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
## Philosophy
|
|
9
|
+
Code should read like intent, not a puzzle. Clarity beats cleverness.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Use When
|
|
12
|
+
- You are writing or reviewing code in any language.
|
|
13
|
+
- The implementation needs readability, safety, or structure improvements.
|
|
14
|
+
- You want a universal standard before more specific domain skills apply.
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
## Core Moves
|
|
17
|
+
- Use guard clauses to handle unhappy paths early.
|
|
18
|
+
- Validate and transform at the boundary, then trust the result inside.
|
|
19
|
+
- Prefer pure functions unless mutation is clearly owned and contained.
|
|
20
|
+
- Fail loud on impossible states instead of hiding them.
|
|
21
|
+
- Use names that explain intent without extra comments.
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
## Default Moves
|
|
24
|
+
- Return early instead of nesting deeply.
|
|
25
|
+
- Keep side effects explicit and local.
|
|
26
|
+
- Choose the simplest code that makes the path obvious.
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function process(user) {
|
|
20
|
-
if (user) {
|
|
21
|
-
if (user.isActive) {
|
|
22
|
-
if (user.hasPermission) {
|
|
23
|
-
return doSomething(user);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
28
|
+
## Anti-Patterns
|
|
29
|
+
- Nested conditionals, scattered validation, silent fallback, clever one-liners, and vague names.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!user.isActive) return null;
|
|
34
|
-
if (!user.hasPermission) return null;
|
|
35
|
-
|
|
36
|
-
return doSomething(user);
|
|
37
|
-
}
|
|
38
|
-
```
|
|
31
|
+
## Variation
|
|
32
|
+
- Be stricter at boundaries and more compact in tiny helpers.
|
|
33
|
+
- Allow controlled mutation in owned state, but keep transforms pure.
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
## Output
|
|
36
|
+
- Return the smallest set of fixes that makes the code easier to read and harder to misuse.
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// ❌ Checking everywhere
|
|
46
|
-
function updateEmail(email) {
|
|
47
|
-
if (!isValidEmail(email)) throw new Error('Invalid');
|
|
48
|
-
// ... logic
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function saveUser(user) {
|
|
52
|
-
if (!isValidEmail(user.email)) throw new Error('Invalid');
|
|
53
|
-
// ... logic
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ✅ Parse once, trust everywhere
|
|
57
|
-
type Email = string & { readonly __brand: unique symbol };
|
|
58
|
-
|
|
59
|
-
function parseEmail(input: string): Email | Error {
|
|
60
|
-
if (!emailRegex.test(input)) {
|
|
61
|
-
return new Error('Invalid email');
|
|
62
|
-
}
|
|
63
|
-
return input as Email;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Now Email is guaranteed valid
|
|
67
|
-
function updateEmail(email: Email) {
|
|
68
|
-
// No validation needed - Email type guarantees validity
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### 3. Pure Functions
|
|
73
|
-
|
|
74
|
-
Functions should be predictable. Same input → same output. No side effects.
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
// ❌ Impure - depends on external state
|
|
78
|
-
let total = 0;
|
|
79
|
-
function addToTotal(amount) {
|
|
80
|
-
total += amount;
|
|
81
|
-
return total;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ✅ Pure - predictable
|
|
85
|
-
function addToTotal(currentTotal: number, amount: number): number {
|
|
86
|
-
return currentTotal + amount;
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### 4. Fail Loud
|
|
91
|
-
|
|
92
|
-
Invalid states should throw errors, not silently continue.
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
// ❌ Silent failure
|
|
96
|
-
function getConfig(key) {
|
|
97
|
-
return config[key] || null; // Hides the problem
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ✅ Fail loud
|
|
101
|
-
function getConfig(key: keyof Config): ConfigValue {
|
|
102
|
-
const value = config[key];
|
|
103
|
-
if (value === undefined) {
|
|
104
|
-
throw new Error(`Missing required config: ${key}`);
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### 5. Readability First
|
|
111
|
-
|
|
112
|
-
Code reads like a sentence. Names are documentation.
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
// ❌ Unclear
|
|
116
|
-
const d = new Date();
|
|
117
|
-
const x = users.filter(u => u.a).map(u => u.n);
|
|
118
|
-
|
|
119
|
-
// ✅ Readable
|
|
120
|
-
const now = new Date();
|
|
121
|
-
const activeUserNames = users
|
|
122
|
-
.filter(user => user.isActive)
|
|
123
|
-
.map(user => user.name);
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Naming Conventions
|
|
127
|
-
|
|
128
|
-
### Variables
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
// Use descriptive names
|
|
132
|
-
const users = [...]; // Good
|
|
133
|
-
const userList = [...]; // Redundant
|
|
134
|
-
const data = [...]; // Too vague
|
|
135
|
-
|
|
136
|
-
// Boolean names should read naturally
|
|
137
|
-
const isActive = true;
|
|
138
|
-
const hasPermission = false;
|
|
139
|
-
const canEdit = true;
|
|
140
|
-
|
|
141
|
-
// Avoid negatives in names
|
|
142
|
-
const isNotActive = false; // Confusing: !isNotActive
|
|
143
|
-
const isDisabled = false; // Better: !isDisabled
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Functions
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
// Functions should describe actions
|
|
150
|
-
function getUser() { } // Good
|
|
151
|
-
function userData() { } // Is it a getter or setter?
|
|
152
|
-
|
|
153
|
-
// Boolean functions should be questions
|
|
154
|
-
function isValid() { } // Good
|
|
155
|
-
function validate() { } // Sounds like it throws
|
|
156
|
-
|
|
157
|
-
// Event handlers should describe what happens
|
|
158
|
-
function handleSubmit() { } // Good
|
|
159
|
-
function onClick() { } // Too generic
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Classes
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
// Classes should be nouns
|
|
166
|
-
class User { } // Good
|
|
167
|
-
class UserManager { } // Good
|
|
168
|
-
class CreateUser { } // Sounds like a function
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Function Guidelines
|
|
172
|
-
|
|
173
|
-
### Single Responsibility
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
// ❌ Does too many things
|
|
177
|
-
function processOrder(order) {
|
|
178
|
-
validateOrder(order);
|
|
179
|
-
calculateTotal(order);
|
|
180
|
-
chargePayment(order);
|
|
181
|
-
sendConfirmation(order);
|
|
182
|
-
updateInventory(order);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ✅ One thing, well
|
|
186
|
-
function processOrder(order: Order): ProcessResult {
|
|
187
|
-
return pipe(
|
|
188
|
-
validateOrder,
|
|
189
|
-
calculateTotal,
|
|
190
|
-
chargePayment,
|
|
191
|
-
sendConfirmation,
|
|
192
|
-
updateInventory
|
|
193
|
-
)(order);
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Small Functions
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
// ❌ 100+ line function
|
|
201
|
-
function doEverything() {
|
|
202
|
-
// 100 lines of code
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// ✅ Small, focused functions
|
|
206
|
-
function validateInput(input: Input): ValidationResult {
|
|
207
|
-
// 5-10 lines
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function processData(data: Data): ProcessedData {
|
|
211
|
-
// 5-10 lines
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Avoid Side Effects
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
// ❌ Modifies input
|
|
219
|
-
function addItem(cart, item) {
|
|
220
|
-
cart.items.push(item);
|
|
221
|
-
return cart;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// ✅ Returns new value
|
|
225
|
-
function addItem(cart: Cart, item: Item): Cart {
|
|
226
|
-
return {
|
|
227
|
-
...cart,
|
|
228
|
-
items: [...cart.items, item]
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## Code Organization
|
|
234
|
-
|
|
235
|
-
### File Structure
|
|
236
|
-
|
|
237
|
-
```
|
|
238
|
-
src/
|
|
239
|
-
├── components/ # UI components
|
|
240
|
-
├── hooks/ # Custom hooks
|
|
241
|
-
├── services/ # Business logic
|
|
242
|
-
├── utils/ # Pure utilities
|
|
243
|
-
├── types/ # TypeScript types
|
|
244
|
-
└── constants/ # Constants
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
### Import Order
|
|
248
|
-
|
|
249
|
-
```typescript
|
|
250
|
-
// 1. External dependencies
|
|
251
|
-
import { useState, useEffect } from 'react';
|
|
252
|
-
import { z } from 'zod';
|
|
253
|
-
|
|
254
|
-
// 2. Internal modules
|
|
255
|
-
import { UserService } from '@/services/user';
|
|
256
|
-
import { Button } from '@/components/ui';
|
|
257
|
-
|
|
258
|
-
// 3. Types
|
|
259
|
-
import type { User } from '@/types';
|
|
260
|
-
|
|
261
|
-
// 4. Constants
|
|
262
|
-
import { MAX_RETRIES } from './constants';
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## Comments
|
|
266
|
-
|
|
267
|
-
### When to Comment
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
// ✅ Explain WHY, not WHAT
|
|
271
|
-
// Using exponential backoff to avoid overwhelming the server
|
|
272
|
-
const delay = Math.pow(2, retryCount) * 1000;
|
|
273
|
-
|
|
274
|
-
// ✅ Document complex algorithms
|
|
275
|
-
// Using Fisher-Yates shuffle for unbiased randomization
|
|
276
|
-
function shuffle(array) { ... }
|
|
277
|
-
|
|
278
|
-
// ✅ Add TODOs with context
|
|
279
|
-
// TODO(#123): Remove after migrating to new API
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### When NOT to Comment
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
// ❌ Explains the obvious
|
|
286
|
-
// Loop through users
|
|
287
|
-
for (const user of users) { }
|
|
288
|
-
|
|
289
|
-
// ❌ Outdated comment
|
|
290
|
-
// This function does X (but it actually does Y now)
|
|
291
|
-
|
|
292
|
-
// ❌ Commented-out code
|
|
293
|
-
// function oldFunction() { ... }
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Error Handling
|
|
297
|
-
|
|
298
|
-
### Use Specific Errors
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
// ❌ Generic error
|
|
302
|
-
throw new Error('Something went wrong');
|
|
303
|
-
|
|
304
|
-
// ✅ Specific error
|
|
305
|
-
throw new ValidationError('Email is invalid', { field: 'email' });
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
### Handle Errors at Boundaries
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
// ❌ Silent catch
|
|
312
|
-
try {
|
|
313
|
-
doSomething();
|
|
314
|
-
} catch (e) {
|
|
315
|
-
// Do nothing
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// ✅ Log and handle
|
|
319
|
-
try {
|
|
320
|
-
doSomething();
|
|
321
|
-
} catch (error) {
|
|
322
|
-
logger.error('Failed to do something', { error });
|
|
323
|
-
throw new ServiceError('Operation failed', { cause: error });
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
## Testing Principles
|
|
328
|
-
|
|
329
|
-
### Test Behavior, Not Implementation
|
|
330
|
-
|
|
331
|
-
```typescript
|
|
332
|
-
// ❌ Tests implementation
|
|
333
|
-
expect(component.state.count).toBe(1);
|
|
334
|
-
|
|
335
|
-
// ✅ Tests behavior
|
|
336
|
-
expect(screen.getByText('Count: 1')).toBeInTheDocument();
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### Use Descriptive Test Names
|
|
340
|
-
|
|
341
|
-
```typescript
|
|
342
|
-
// ❌ Vague
|
|
343
|
-
test('user', () => { ... });
|
|
344
|
-
|
|
345
|
-
// ✅ Descriptive
|
|
346
|
-
test('should create user with valid email', () => { ... });
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
---
|
|
350
|
-
|
|
351
|
-
**These principles apply to all code, regardless of language or domain.**
|
|
38
|
+
## Remember
|
|
39
|
+
Readable code is a feature, not a luxury.
|