antigravity-init 1.0.0
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/.agent/agents/architect.md +211 -0
- package/.agent/agents/build-error-resolver.md +532 -0
- package/.agent/agents/code-reviewer.md +104 -0
- package/.agent/agents/doc-updater.md +452 -0
- package/.agent/agents/e2e-runner.md +708 -0
- package/.agent/agents/planner.md +119 -0
- package/.agent/agents/refactor-cleaner.md +306 -0
- package/.agent/agents/security-reviewer.md +545 -0
- package/.agent/agents/tdd-guide.md +280 -0
- package/.agent/rules/agents.md +49 -0
- package/.agent/rules/coding-style.md +70 -0
- package/.agent/rules/git-workflow.md +45 -0
- package/.agent/rules/hooks.md +46 -0
- package/.agent/rules/patterns.md +55 -0
- package/.agent/rules/performance.md +47 -0
- package/.agent/rules/security.md +36 -0
- package/.agent/rules/testing.md +30 -0
- package/.agent/skills/backend-patterns/SKILL.md +582 -0
- package/.agent/skills/brainstorming/SKILL.md +54 -0
- package/.agent/skills/coding-standards/SKILL.md +520 -0
- package/.agent/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/.agent/skills/executing-plans/SKILL.md +76 -0
- package/.agent/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/.agent/skills/frontend-patterns/SKILL.md +631 -0
- package/.agent/skills/receiving-code-review/SKILL.md +213 -0
- package/.agent/skills/requesting-code-review/SKILL.md +105 -0
- package/.agent/skills/requesting-code-review/code-reviewer.md +48 -0
- package/.agent/skills/security-review/SKILL.md +494 -0
- package/.agent/skills/subagent-driven-development/SKILL.md +240 -0
- package/.agent/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/.agent/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/.agent/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/.agent/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/.agent/skills/systematic-debugging/SKILL.md +296 -0
- package/.agent/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/.agent/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/.agent/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/.agent/skills/systematic-debugging/find-polluter.sh +63 -0
- package/.agent/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/.agent/skills/systematic-debugging/test-academic.md +14 -0
- package/.agent/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/.agent/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/.agent/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/.agent/skills/test-driven-development/SKILL.md +371 -0
- package/.agent/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +292 -0
- package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-314.pyc +0 -0
- package/.agent/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-314.pyc +0 -0
- package/.agent/skills/ui-ux-pro-max/scripts/__pycache__/search.cpython-314.pyc +0 -0
- package/.agent/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agent/skills/ui-ux-pro-max/scripts/search.py +106 -0
- package/.agent/skills/using-git-worktrees/SKILL.md +217 -0
- package/.agent/skills/using-superpowers/SKILL.md +87 -0
- package/.agent/skills/verification-before-completion/SKILL.md +139 -0
- package/.agent/skills/writing-plans/SKILL.md +116 -0
- package/.agent/skills/writing-skills/SKILL.md +655 -0
- package/.agent/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/.agent/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/.agent/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/.agent/skills/writing-skills/persuasion-principles.md +187 -0
- package/.agent/skills/writing-skills/render-graphs.js +168 -0
- package/.agent/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/.agent/workflows/brainstorm.md +5 -0
- package/.agent/workflows/build-fix.md +212 -0
- package/.agent/workflows/code-review.md +169 -0
- package/.agent/workflows/execute-plan.md +5 -0
- package/.agent/workflows/tdd-workflow.md +166 -0
- package/.agent/workflows/ui-ux-pro-max.md +292 -0
- package/.agent/workflows/write-plan.md +5 -0
- package/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/bin/cli.js +53 -0
- package/package.json +30 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-standards
|
|
3
|
+
description: Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Coding Standards & Best Practices
|
|
7
|
+
|
|
8
|
+
Universal coding standards applicable across all projects.
|
|
9
|
+
|
|
10
|
+
## Code Quality Principles
|
|
11
|
+
|
|
12
|
+
### 1. Readability First
|
|
13
|
+
- Code is read more than written
|
|
14
|
+
- Clear variable and function names
|
|
15
|
+
- Self-documenting code preferred over comments
|
|
16
|
+
- Consistent formatting
|
|
17
|
+
|
|
18
|
+
### 2. KISS (Keep It Simple, Stupid)
|
|
19
|
+
- Simplest solution that works
|
|
20
|
+
- Avoid over-engineering
|
|
21
|
+
- No premature optimization
|
|
22
|
+
- Easy to understand > clever code
|
|
23
|
+
|
|
24
|
+
### 3. DRY (Don't Repeat Yourself)
|
|
25
|
+
- Extract common logic into functions
|
|
26
|
+
- Create reusable components
|
|
27
|
+
- Share utilities across modules
|
|
28
|
+
- Avoid copy-paste programming
|
|
29
|
+
|
|
30
|
+
### 4. YAGNI (You Aren't Gonna Need It)
|
|
31
|
+
- Don't build features before they're needed
|
|
32
|
+
- Avoid speculative generality
|
|
33
|
+
- Add complexity only when required
|
|
34
|
+
- Start simple, refactor when needed
|
|
35
|
+
|
|
36
|
+
## TypeScript/JavaScript Standards
|
|
37
|
+
|
|
38
|
+
### Variable Naming
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// ✅ GOOD: Descriptive names
|
|
42
|
+
const marketSearchQuery = 'election'
|
|
43
|
+
const isUserAuthenticated = true
|
|
44
|
+
const totalRevenue = 1000
|
|
45
|
+
|
|
46
|
+
// ❌ BAD: Unclear names
|
|
47
|
+
const q = 'election'
|
|
48
|
+
const flag = true
|
|
49
|
+
const x = 1000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Function Naming
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// ✅ GOOD: Verb-noun pattern
|
|
56
|
+
async function fetchMarketData(marketId: string) { }
|
|
57
|
+
function calculateSimilarity(a: number[], b: number[]) { }
|
|
58
|
+
function isValidEmail(email: string): boolean { }
|
|
59
|
+
|
|
60
|
+
// ❌ BAD: Unclear or noun-only
|
|
61
|
+
async function market(id: string) { }
|
|
62
|
+
function similarity(a, b) { }
|
|
63
|
+
function email(e) { }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Immutability Pattern (CRITICAL)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// ✅ ALWAYS use spread operator
|
|
70
|
+
const updatedUser = {
|
|
71
|
+
...user,
|
|
72
|
+
name: 'New Name'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const updatedArray = [...items, newItem]
|
|
76
|
+
|
|
77
|
+
// ❌ NEVER mutate directly
|
|
78
|
+
user.name = 'New Name' // BAD
|
|
79
|
+
items.push(newItem) // BAD
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Error Handling
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// ✅ GOOD: Comprehensive error handling
|
|
86
|
+
async function fetchData(url: string) {
|
|
87
|
+
try {
|
|
88
|
+
const response = await fetch(url)
|
|
89
|
+
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return await response.json()
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('Fetch failed:', error)
|
|
97
|
+
throw new Error('Failed to fetch data')
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ❌ BAD: No error handling
|
|
102
|
+
async function fetchData(url) {
|
|
103
|
+
const response = await fetch(url)
|
|
104
|
+
return response.json()
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Async/Await Best Practices
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// ✅ GOOD: Parallel execution when possible
|
|
112
|
+
const [users, markets, stats] = await Promise.all([
|
|
113
|
+
fetchUsers(),
|
|
114
|
+
fetchMarkets(),
|
|
115
|
+
fetchStats()
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
// ❌ BAD: Sequential when unnecessary
|
|
119
|
+
const users = await fetchUsers()
|
|
120
|
+
const markets = await fetchMarkets()
|
|
121
|
+
const stats = await fetchStats()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Type Safety
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// ✅ GOOD: Proper types
|
|
128
|
+
interface Market {
|
|
129
|
+
id: string
|
|
130
|
+
name: string
|
|
131
|
+
status: 'active' | 'resolved' | 'closed'
|
|
132
|
+
created_at: Date
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getMarket(id: string): Promise<Market> {
|
|
136
|
+
// Implementation
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ❌ BAD: Using 'any'
|
|
140
|
+
function getMarket(id: any): Promise<any> {
|
|
141
|
+
// Implementation
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## React Best Practices
|
|
146
|
+
|
|
147
|
+
### Component Structure
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// ✅ GOOD: Functional component with types
|
|
151
|
+
interface ButtonProps {
|
|
152
|
+
children: React.ReactNode
|
|
153
|
+
onClick: () => void
|
|
154
|
+
disabled?: boolean
|
|
155
|
+
variant?: 'primary' | 'secondary'
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function Button({
|
|
159
|
+
children,
|
|
160
|
+
onClick,
|
|
161
|
+
disabled = false,
|
|
162
|
+
variant = 'primary'
|
|
163
|
+
}: ButtonProps) {
|
|
164
|
+
return (
|
|
165
|
+
<button
|
|
166
|
+
onClick={onClick}
|
|
167
|
+
disabled={disabled}
|
|
168
|
+
className={`btn btn-${variant}`}
|
|
169
|
+
>
|
|
170
|
+
{children}
|
|
171
|
+
</button>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ❌ BAD: No types, unclear structure
|
|
176
|
+
export function Button(props) {
|
|
177
|
+
return <button onClick={props.onClick}>{props.children}</button>
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Custom Hooks
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// ✅ GOOD: Reusable custom hook
|
|
185
|
+
export function useDebounce<T>(value: T, delay: number): T {
|
|
186
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value)
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
const handler = setTimeout(() => {
|
|
190
|
+
setDebouncedValue(value)
|
|
191
|
+
}, delay)
|
|
192
|
+
|
|
193
|
+
return () => clearTimeout(handler)
|
|
194
|
+
}, [value, delay])
|
|
195
|
+
|
|
196
|
+
return debouncedValue
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Usage
|
|
200
|
+
const debouncedQuery = useDebounce(searchQuery, 500)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### State Management
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// ✅ GOOD: Proper state updates
|
|
207
|
+
const [count, setCount] = useState(0)
|
|
208
|
+
|
|
209
|
+
// Functional update for state based on previous state
|
|
210
|
+
setCount(prev => prev + 1)
|
|
211
|
+
|
|
212
|
+
// ❌ BAD: Direct state reference
|
|
213
|
+
setCount(count + 1) // Can be stale in async scenarios
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Conditional Rendering
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// ✅ GOOD: Clear conditional rendering
|
|
220
|
+
{isLoading && <Spinner />}
|
|
221
|
+
{error && <ErrorMessage error={error} />}
|
|
222
|
+
{data && <DataDisplay data={data} />}
|
|
223
|
+
|
|
224
|
+
// ❌ BAD: Ternary hell
|
|
225
|
+
{isLoading ? <Spinner /> : error ? <ErrorMessage error={error} /> : data ? <DataDisplay data={data} /> : null}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## API Design Standards
|
|
229
|
+
|
|
230
|
+
### REST API Conventions
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
GET /api/markets # List all markets
|
|
234
|
+
GET /api/markets/:id # Get specific market
|
|
235
|
+
POST /api/markets # Create new market
|
|
236
|
+
PUT /api/markets/:id # Update market (full)
|
|
237
|
+
PATCH /api/markets/:id # Update market (partial)
|
|
238
|
+
DELETE /api/markets/:id # Delete market
|
|
239
|
+
|
|
240
|
+
# Query parameters for filtering
|
|
241
|
+
GET /api/markets?status=active&limit=10&offset=0
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Response Format
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// ✅ GOOD: Consistent response structure
|
|
248
|
+
interface ApiResponse<T> {
|
|
249
|
+
success: boolean
|
|
250
|
+
data?: T
|
|
251
|
+
error?: string
|
|
252
|
+
meta?: {
|
|
253
|
+
total: number
|
|
254
|
+
page: number
|
|
255
|
+
limit: number
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Success response
|
|
260
|
+
return NextResponse.json({
|
|
261
|
+
success: true,
|
|
262
|
+
data: markets,
|
|
263
|
+
meta: { total: 100, page: 1, limit: 10 }
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
// Error response
|
|
267
|
+
return NextResponse.json({
|
|
268
|
+
success: false,
|
|
269
|
+
error: 'Invalid request'
|
|
270
|
+
}, { status: 400 })
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Input Validation
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { z } from 'zod'
|
|
277
|
+
|
|
278
|
+
// ✅ GOOD: Schema validation
|
|
279
|
+
const CreateMarketSchema = z.object({
|
|
280
|
+
name: z.string().min(1).max(200),
|
|
281
|
+
description: z.string().min(1).max(2000),
|
|
282
|
+
endDate: z.string().datetime(),
|
|
283
|
+
categories: z.array(z.string()).min(1)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
export async function POST(request: Request) {
|
|
287
|
+
const body = await request.json()
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
const validated = CreateMarketSchema.parse(body)
|
|
291
|
+
// Proceed with validated data
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (error instanceof z.ZodError) {
|
|
294
|
+
return NextResponse.json({
|
|
295
|
+
success: false,
|
|
296
|
+
error: 'Validation failed',
|
|
297
|
+
details: error.errors
|
|
298
|
+
}, { status: 400 })
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## File Organization
|
|
305
|
+
|
|
306
|
+
### Project Structure
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
src/
|
|
310
|
+
├── app/ # Next.js App Router
|
|
311
|
+
│ ├── api/ # API routes
|
|
312
|
+
│ ├── markets/ # Market pages
|
|
313
|
+
│ └── (auth)/ # Auth pages (route groups)
|
|
314
|
+
├── components/ # React components
|
|
315
|
+
│ ├── ui/ # Generic UI components
|
|
316
|
+
│ ├── forms/ # Form components
|
|
317
|
+
│ └── layouts/ # Layout components
|
|
318
|
+
├── hooks/ # Custom React hooks
|
|
319
|
+
├── lib/ # Utilities and configs
|
|
320
|
+
│ ├── api/ # API clients
|
|
321
|
+
│ ├── utils/ # Helper functions
|
|
322
|
+
│ └── constants/ # Constants
|
|
323
|
+
├── types/ # TypeScript types
|
|
324
|
+
└── styles/ # Global styles
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### File Naming
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
components/Button.tsx # PascalCase for components
|
|
331
|
+
hooks/useAuth.ts # camelCase with 'use' prefix
|
|
332
|
+
lib/formatDate.ts # camelCase for utilities
|
|
333
|
+
types/market.types.ts # camelCase with .types suffix
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Comments & Documentation
|
|
337
|
+
|
|
338
|
+
### When to Comment
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// ✅ GOOD: Explain WHY, not WHAT
|
|
342
|
+
// Use exponential backoff to avoid overwhelming the API during outages
|
|
343
|
+
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000)
|
|
344
|
+
|
|
345
|
+
// Deliberately using mutation here for performance with large arrays
|
|
346
|
+
items.push(newItem)
|
|
347
|
+
|
|
348
|
+
// ❌ BAD: Stating the obvious
|
|
349
|
+
// Increment counter by 1
|
|
350
|
+
count++
|
|
351
|
+
|
|
352
|
+
// Set name to user's name
|
|
353
|
+
name = user.name
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### JSDoc for Public APIs
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
/**
|
|
360
|
+
* Searches markets using semantic similarity.
|
|
361
|
+
*
|
|
362
|
+
* @param query - Natural language search query
|
|
363
|
+
* @param limit - Maximum number of results (default: 10)
|
|
364
|
+
* @returns Array of markets sorted by similarity score
|
|
365
|
+
* @throws {Error} If OpenAI API fails or Redis unavailable
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const results = await searchMarkets('election', 5)
|
|
370
|
+
* console.log(results[0].name) // "Trump vs Biden"
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
export async function searchMarkets(
|
|
374
|
+
query: string,
|
|
375
|
+
limit: number = 10
|
|
376
|
+
): Promise<Market[]> {
|
|
377
|
+
// Implementation
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Performance Best Practices
|
|
382
|
+
|
|
383
|
+
### Memoization
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import { useMemo, useCallback } from 'react'
|
|
387
|
+
|
|
388
|
+
// ✅ GOOD: Memoize expensive computations
|
|
389
|
+
const sortedMarkets = useMemo(() => {
|
|
390
|
+
return markets.sort((a, b) => b.volume - a.volume)
|
|
391
|
+
}, [markets])
|
|
392
|
+
|
|
393
|
+
// ✅ GOOD: Memoize callbacks
|
|
394
|
+
const handleSearch = useCallback((query: string) => {
|
|
395
|
+
setSearchQuery(query)
|
|
396
|
+
}, [])
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Lazy Loading
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import { lazy, Suspense } from 'react'
|
|
403
|
+
|
|
404
|
+
// ✅ GOOD: Lazy load heavy components
|
|
405
|
+
const HeavyChart = lazy(() => import('./HeavyChart'))
|
|
406
|
+
|
|
407
|
+
export function Dashboard() {
|
|
408
|
+
return (
|
|
409
|
+
<Suspense fallback={<Spinner />}>
|
|
410
|
+
<HeavyChart />
|
|
411
|
+
</Suspense>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Database Queries
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
// ✅ GOOD: Select only needed columns
|
|
420
|
+
const { data } = await supabase
|
|
421
|
+
.from('markets')
|
|
422
|
+
.select('id, name, status')
|
|
423
|
+
.limit(10)
|
|
424
|
+
|
|
425
|
+
// ❌ BAD: Select everything
|
|
426
|
+
const { data } = await supabase
|
|
427
|
+
.from('markets')
|
|
428
|
+
.select('*')
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Testing Standards
|
|
432
|
+
|
|
433
|
+
### Test Structure (AAA Pattern)
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
test('calculates similarity correctly', () => {
|
|
437
|
+
// Arrange
|
|
438
|
+
const vector1 = [1, 0, 0]
|
|
439
|
+
const vector2 = [0, 1, 0]
|
|
440
|
+
|
|
441
|
+
// Act
|
|
442
|
+
const similarity = calculateCosineSimilarity(vector1, vector2)
|
|
443
|
+
|
|
444
|
+
// Assert
|
|
445
|
+
expect(similarity).toBe(0)
|
|
446
|
+
})
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Test Naming
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
// ✅ GOOD: Descriptive test names
|
|
453
|
+
test('returns empty array when no markets match query', () => { })
|
|
454
|
+
test('throws error when OpenAI API key is missing', () => { })
|
|
455
|
+
test('falls back to substring search when Redis unavailable', () => { })
|
|
456
|
+
|
|
457
|
+
// ❌ BAD: Vague test names
|
|
458
|
+
test('works', () => { })
|
|
459
|
+
test('test search', () => { })
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Code Smell Detection
|
|
463
|
+
|
|
464
|
+
Watch for these anti-patterns:
|
|
465
|
+
|
|
466
|
+
### 1. Long Functions
|
|
467
|
+
```typescript
|
|
468
|
+
// ❌ BAD: Function > 50 lines
|
|
469
|
+
function processMarketData() {
|
|
470
|
+
// 100 lines of code
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ✅ GOOD: Split into smaller functions
|
|
474
|
+
function processMarketData() {
|
|
475
|
+
const validated = validateData()
|
|
476
|
+
const transformed = transformData(validated)
|
|
477
|
+
return saveData(transformed)
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### 2. Deep Nesting
|
|
482
|
+
```typescript
|
|
483
|
+
// ❌ BAD: 5+ levels of nesting
|
|
484
|
+
if (user) {
|
|
485
|
+
if (user.isAdmin) {
|
|
486
|
+
if (market) {
|
|
487
|
+
if (market.isActive) {
|
|
488
|
+
if (hasPermission) {
|
|
489
|
+
// Do something
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// ✅ GOOD: Early returns
|
|
497
|
+
if (!user) return
|
|
498
|
+
if (!user.isAdmin) return
|
|
499
|
+
if (!market) return
|
|
500
|
+
if (!market.isActive) return
|
|
501
|
+
if (!hasPermission) return
|
|
502
|
+
|
|
503
|
+
// Do something
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### 3. Magic Numbers
|
|
507
|
+
```typescript
|
|
508
|
+
// ❌ BAD: Unexplained numbers
|
|
509
|
+
if (retryCount > 3) { }
|
|
510
|
+
setTimeout(callback, 500)
|
|
511
|
+
|
|
512
|
+
// ✅ GOOD: Named constants
|
|
513
|
+
const MAX_RETRIES = 3
|
|
514
|
+
const DEBOUNCE_DELAY_MS = 500
|
|
515
|
+
|
|
516
|
+
if (retryCount > MAX_RETRIES) { }
|
|
517
|
+
setTimeout(callback, DEBOUNCE_DELAY_MS)
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
**Remember**: Code quality is not negotiable. Clear, maintainable code enables rapid development and confident refactoring.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dispatching-parallel-agents
|
|
3
|
+
description: Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Dispatching Parallel Agents
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
When you have multiple unrelated failures (different test files, different subsystems, different bugs), investigating them sequentially wastes time. Each investigation is independent and can happen in parallel.
|
|
11
|
+
|
|
12
|
+
**Core principle:** Dispatch one agent per independent problem domain. Let them work concurrently.
|
|
13
|
+
|
|
14
|
+
## When to Use
|
|
15
|
+
|
|
16
|
+
```dot
|
|
17
|
+
digraph when_to_use {
|
|
18
|
+
"Multiple failures?" [shape=diamond];
|
|
19
|
+
"Are they independent?" [shape=diamond];
|
|
20
|
+
"Single agent investigates all" [shape=box];
|
|
21
|
+
"One agent per problem domain" [shape=box];
|
|
22
|
+
"Can they work in parallel?" [shape=diamond];
|
|
23
|
+
"Sequential agents" [shape=box];
|
|
24
|
+
"Parallel dispatch" [shape=box];
|
|
25
|
+
|
|
26
|
+
"Multiple failures?" -> "Are they independent?" [label="yes"];
|
|
27
|
+
"Are they independent?" -> "Single agent investigates all" [label="no - related"];
|
|
28
|
+
"Are they independent?" -> "Can they work in parallel?" [label="yes"];
|
|
29
|
+
"Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
|
|
30
|
+
"Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Use when:**
|
|
35
|
+
- 3+ test files failing with different root causes
|
|
36
|
+
- Multiple subsystems broken independently
|
|
37
|
+
- Each problem can be understood without context from others
|
|
38
|
+
- No shared state between investigations
|
|
39
|
+
|
|
40
|
+
**Don't use when:**
|
|
41
|
+
- Failures are related (fix one might fix others)
|
|
42
|
+
- Need to understand full system state
|
|
43
|
+
- Agents would interfere with each other
|
|
44
|
+
|
|
45
|
+
## The Pattern
|
|
46
|
+
|
|
47
|
+
### 1. Identify Independent Domains
|
|
48
|
+
|
|
49
|
+
Group failures by what's broken:
|
|
50
|
+
- File A tests: Tool approval flow
|
|
51
|
+
- File B tests: Batch completion behavior
|
|
52
|
+
- File C tests: Abort functionality
|
|
53
|
+
|
|
54
|
+
Each domain is independent - fixing tool approval doesn't affect abort tests.
|
|
55
|
+
|
|
56
|
+
### 2. Create Focused Agent Tasks
|
|
57
|
+
|
|
58
|
+
Each agent gets:
|
|
59
|
+
- **Specific scope:** One test file or subsystem
|
|
60
|
+
- **Clear goal:** Make these tests pass
|
|
61
|
+
- **Constraints:** Don't change other code
|
|
62
|
+
- **Expected output:** Summary of what you found and fixed
|
|
63
|
+
|
|
64
|
+
### 3. Dispatch in Parallel
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// In Claude Code / AI environment
|
|
68
|
+
Task("Fix agent-tool-abort.test.ts failures")
|
|
69
|
+
Task("Fix batch-completion-behavior.test.ts failures")
|
|
70
|
+
Task("Fix tool-approval-race-conditions.test.ts failures")
|
|
71
|
+
// All three run concurrently
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. Review and Integrate
|
|
75
|
+
|
|
76
|
+
When agents return:
|
|
77
|
+
- Read each summary
|
|
78
|
+
- Verify fixes don't conflict
|
|
79
|
+
- Run full test suite
|
|
80
|
+
- Integrate all changes
|
|
81
|
+
|
|
82
|
+
## Agent Prompt Structure
|
|
83
|
+
|
|
84
|
+
Good agent prompts are:
|
|
85
|
+
1. **Focused** - One clear problem domain
|
|
86
|
+
2. **Self-contained** - All context needed to understand the problem
|
|
87
|
+
3. **Specific about output** - What should the agent return?
|
|
88
|
+
|
|
89
|
+
```markdown
|
|
90
|
+
Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
|
|
91
|
+
|
|
92
|
+
1. "should abort tool with partial output capture" - expects 'interrupted at' in message
|
|
93
|
+
2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
|
|
94
|
+
3. "should properly track pendingToolCount" - expects 3 results but gets 0
|
|
95
|
+
|
|
96
|
+
These are timing/race condition issues. Your task:
|
|
97
|
+
|
|
98
|
+
1. Read the test file and understand what each test verifies
|
|
99
|
+
2. Identify root cause - timing issues or actual bugs?
|
|
100
|
+
3. Fix by:
|
|
101
|
+
- Replacing arbitrary timeouts with event-based waiting
|
|
102
|
+
- Fixing bugs in abort implementation if found
|
|
103
|
+
- Adjusting test expectations if testing changed behavior
|
|
104
|
+
|
|
105
|
+
Do NOT just increase timeouts - find the real issue.
|
|
106
|
+
|
|
107
|
+
Return: Summary of what you found and what you fixed.
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Common Mistakes
|
|
111
|
+
|
|
112
|
+
**❌ Too broad:** "Fix all the tests" - agent gets lost
|
|
113
|
+
**✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope
|
|
114
|
+
|
|
115
|
+
**❌ No context:** "Fix the race condition" - agent doesn't know where
|
|
116
|
+
**✅ Context:** Paste the error messages and test names
|
|
117
|
+
|
|
118
|
+
**❌ No constraints:** Agent might refactor everything
|
|
119
|
+
**✅ Constraints:** "Do NOT change production code" or "Fix tests only"
|
|
120
|
+
|
|
121
|
+
**❌ Vague output:** "Fix it" - you don't know what changed
|
|
122
|
+
**✅ Specific:** "Return summary of root cause and changes"
|
|
123
|
+
|
|
124
|
+
## When NOT to Use
|
|
125
|
+
|
|
126
|
+
**Related failures:** Fixing one might fix others - investigate together first
|
|
127
|
+
**Need full context:** Understanding requires seeing entire system
|
|
128
|
+
**Exploratory debugging:** You don't know what's broken yet
|
|
129
|
+
**Shared state:** Agents would interfere (editing same files, using same resources)
|
|
130
|
+
|
|
131
|
+
## Real Example from Session
|
|
132
|
+
|
|
133
|
+
**Scenario:** 6 test failures across 3 files after major refactoring
|
|
134
|
+
|
|
135
|
+
**Failures:**
|
|
136
|
+
- agent-tool-abort.test.ts: 3 failures (timing issues)
|
|
137
|
+
- batch-completion-behavior.test.ts: 2 failures (tools not executing)
|
|
138
|
+
- tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
|
|
139
|
+
|
|
140
|
+
**Decision:** Independent domains - abort logic separate from batch completion separate from race conditions
|
|
141
|
+
|
|
142
|
+
**Dispatch:**
|
|
143
|
+
```
|
|
144
|
+
Agent 1 → Fix agent-tool-abort.test.ts
|
|
145
|
+
Agent 2 → Fix batch-completion-behavior.test.ts
|
|
146
|
+
Agent 3 → Fix tool-approval-race-conditions.test.ts
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Results:**
|
|
150
|
+
- Agent 1: Replaced timeouts with event-based waiting
|
|
151
|
+
- Agent 2: Fixed event structure bug (threadId in wrong place)
|
|
152
|
+
- Agent 3: Added wait for async tool execution to complete
|
|
153
|
+
|
|
154
|
+
**Integration:** All fixes independent, no conflicts, full suite green
|
|
155
|
+
|
|
156
|
+
**Time saved:** 3 problems solved in parallel vs sequentially
|
|
157
|
+
|
|
158
|
+
## Key Benefits
|
|
159
|
+
|
|
160
|
+
1. **Parallelization** - Multiple investigations happen simultaneously
|
|
161
|
+
2. **Focus** - Each agent has narrow scope, less context to track
|
|
162
|
+
3. **Independence** - Agents don't interfere with each other
|
|
163
|
+
4. **Speed** - 3 problems solved in time of 1
|
|
164
|
+
|
|
165
|
+
## Verification
|
|
166
|
+
|
|
167
|
+
After agents return:
|
|
168
|
+
1. **Review each summary** - Understand what changed
|
|
169
|
+
2. **Check for conflicts** - Did agents edit same code?
|
|
170
|
+
3. **Run full suite** - Verify all fixes work together
|
|
171
|
+
4. **Spot check** - Agents can make systematic errors
|
|
172
|
+
|
|
173
|
+
## Real-World Impact
|
|
174
|
+
|
|
175
|
+
From debugging session (2025-10-03):
|
|
176
|
+
- 6 failures across 3 files
|
|
177
|
+
- 3 agents dispatched in parallel
|
|
178
|
+
- All investigations completed concurrently
|
|
179
|
+
- All fixes integrated successfully
|
|
180
|
+
- Zero conflicts between agent changes
|