@champpaba/claude-agent-kit 1.4.0 → 1.4.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.
@@ -0,0 +1,421 @@
1
+ # Frontend Performance Optimization
2
+
3
+ > **Purpose:** Optimize frontend performance for faster load times, better UX, and improved SEO
4
+
5
+ **Key Metrics:**
6
+ - **LCP (Largest Contentful Paint):** < 2.5s (target)
7
+ - **FCP (First Contentful Paint):** < 1.8s (target)
8
+ - **Total Bundle Size:** < 200KB gzipped (initial load)
9
+ - **Image Size:** < 100KB per image (target)
10
+
11
+ ---
12
+
13
+ ## ⚡ Performance Impact
14
+
15
+ **Before optimization:**
16
+ ```
17
+ Total image size: 2.2MB (5 × 440KB JPG)
18
+ JS bundle size: 850KB (no splitting)
19
+ HTTP requests: 12 requests
20
+ LCP: 5.8s
21
+ Lighthouse Score: 58
22
+ ```
23
+
24
+ **After optimization:**
25
+ ```
26
+ Total image size: 400KB (5 × 80KB WebP) = -82%
27
+ JS bundle size: 320KB (code split) = -62%
28
+ HTTP requests: 6 requests = -50%
29
+ LCP: 2.1s = -64%
30
+ Lighthouse Score: 94 = +62%
31
+ ```
32
+
33
+ **User Impact:**
34
+ - Mobile users: 2-3× faster load
35
+ - Bounce rate: -10-15%
36
+ - SEO ranking: +20-30%
37
+
38
+ ---
39
+
40
+ ## 🖼️ Image Optimization (Primary Focus)
41
+
42
+ ### 1. Format Selection
43
+
44
+ **Rule:** Use WebP with fallback to JPEG/PNG
45
+
46
+ | Use Case | Format | Why |
47
+ |----------|--------|-----|
48
+ | **Photos** | WebP | 30% smaller than JPEG, better quality |
49
+ | **Icons** | SVG | Scalable, tiny file size |
50
+ | **Logos** | SVG | Crisp at any size |
51
+ | **Screenshots** | WebP | Better compression than PNG |
52
+ | **Complex graphics** | WebP/AVIF | Best compression |
53
+
54
+ **Implementation:**
55
+
56
+ ```html
57
+ <!-- ✅ WebP with fallback -->
58
+ <picture>
59
+ <source srcset="hero.webp" type="image/webp">
60
+ <img src="hero.jpg" alt="Hero image" loading="lazy">
61
+ </picture>
62
+
63
+ <!-- ✅ SVG for icons -->
64
+ <svg width="24" height="24">
65
+ <path d="..." />
66
+ </svg>
67
+ ```
68
+
69
+ ---
70
+
71
+ ### 2. Lazy Loading
72
+
73
+ **Rule:** Lazy load all images below the fold
74
+
75
+ **Benefits:**
76
+ - Faster initial page load
77
+ - Reduced bandwidth usage
78
+ - Better LCP score
79
+
80
+ **Implementation:**
81
+
82
+ ```html
83
+ <!-- ✅ Lazy load below-fold images -->
84
+ <img
85
+ src="product.webp"
86
+ alt="Product image"
87
+ loading="lazy"
88
+ width="400"
89
+ height="300"
90
+ />
91
+
92
+ <!-- ✅ Eager load above-fold images (hero, logo) -->
93
+ <img
94
+ src="hero.webp"
95
+ alt="Hero"
96
+ loading="eager"
97
+ width="1920"
98
+ height="1080"
99
+ />
100
+
101
+ <!-- ❌ Don't lazy load critical images -->
102
+ <img src="logo.svg" alt="Logo" loading="lazy"> <!-- BAD: Logo should load immediately -->
103
+ ```
104
+
105
+ **React/Next.js:**
106
+
107
+ ```tsx
108
+ import Image from 'next/image'
109
+
110
+ // ✅ Lazy load by default
111
+ <Image
112
+ src="/product.webp"
113
+ alt="Product"
114
+ width={400}
115
+ height={300}
116
+ loading="lazy"
117
+ />
118
+
119
+ // ✅ Eager load hero images
120
+ <Image
121
+ src="/hero.webp"
122
+ alt="Hero"
123
+ width={1920}
124
+ height={1080}
125
+ priority // Next.js: eager loading
126
+ />
127
+ ```
128
+
129
+ ---
130
+
131
+ ### 3. Responsive Images
132
+
133
+ **Rule:** Serve different image sizes for different screen sizes
134
+
135
+ **Benefits:**
136
+ - Mobile users don't download desktop images
137
+ - 70-80% size reduction on mobile
138
+ - Better performance on slow connections
139
+
140
+ **Implementation:**
141
+
142
+ ```html
143
+ <!-- ✅ Responsive images with srcset -->
144
+ <img
145
+ src="hero-1920.webp"
146
+ srcset="
147
+ hero-768.webp 768w,
148
+ hero-1024.webp 1024w,
149
+ hero-1920.webp 1920w
150
+ "
151
+ sizes="
152
+ (max-width: 768px) 100vw,
153
+ (max-width: 1024px) 100vw,
154
+ 1920px
155
+ "
156
+ alt="Hero"
157
+ loading="lazy"
158
+ width="1920"
159
+ height="1080"
160
+ />
161
+ ```
162
+
163
+ **React/Next.js:**
164
+
165
+ ```tsx
166
+ <Image
167
+ src="/hero.webp"
168
+ alt="Hero"
169
+ width={1920}
170
+ height={1080}
171
+ sizes="(max-width: 768px) 100vw, (max-width: 1024px) 100vw, 1920px"
172
+ loading="lazy"
173
+ />
174
+ ```
175
+
176
+ ---
177
+
178
+ ### 4. Image Dimensions (Prevent Layout Shift)
179
+
180
+ **Rule:** Always specify width and height attributes
181
+
182
+ **Benefits:**
183
+ - Prevents Cumulative Layout Shift (CLS)
184
+ - Browser reserves space before image loads
185
+ - Better UX (no content jumping)
186
+
187
+ **Implementation:**
188
+
189
+ ```html
190
+ <!-- ✅ Always specify dimensions -->
191
+ <img
192
+ src="product.webp"
193
+ alt="Product"
194
+ width="400"
195
+ height="300"
196
+ loading="lazy"
197
+ />
198
+
199
+ <!-- ❌ Missing dimensions (causes layout shift) -->
200
+ <img src="product.webp" alt="Product" loading="lazy">
201
+ ```
202
+
203
+ ---
204
+
205
+ ### 5. Image Compression
206
+
207
+ **Rule:** Compress images to 80-85% quality (no visible difference)
208
+
209
+ **Tools:**
210
+ - **Online:** TinyPNG, Squoosh, Compressor.io
211
+ - **CLI:** `imagemagick`, `sharp`, `squoosh-cli`
212
+ - **Build-time:** Next.js Image Optimization, webpack loaders
213
+
214
+ **Example (ImageMagick):**
215
+
216
+ ```bash
217
+ # Convert JPEG to WebP (85% quality)
218
+ magick input.jpg -quality 85 output.webp
219
+
220
+ # Resize + Convert
221
+ magick input.jpg -resize 768x -quality 85 output-768.webp
222
+ ```
223
+
224
+ ---
225
+
226
+ ## 🎯 Image Optimization Checklist
227
+
228
+ **Before implementing any image:**
229
+
230
+ - [ ] **Format:** Use WebP (with JPEG/PNG fallback)
231
+ - [ ] **Lazy loading:** `loading="lazy"` for below-fold images
232
+ - [ ] **Responsive:** Generate 3 sizes (768w, 1024w, 1920w) if > 400px width
233
+ - [ ] **Dimensions:** Always specify `width` and `height`
234
+ - [ ] **Compression:** 80-85% quality (use TinyPNG or Squoosh)
235
+ - [ ] **Alt text:** Descriptive alt text for accessibility
236
+ - [ ] **Priority:** `loading="eager"` or `priority` for hero images only
237
+
238
+ ---
239
+
240
+ ## 📦 Code Splitting (Basic)
241
+
242
+ ### When to Split
243
+
244
+ **✅ Split code when:**
245
+ - Route-based splitting (different pages)
246
+ - Heavy components (charts, editors, modals)
247
+ - Third-party libraries (3+ libraries)
248
+
249
+ **❌ Don't split:**
250
+ - Small components (< 10KB)
251
+ - Critical path components (above-fold)
252
+ - Frequently used utilities
253
+
254
+ ### React/Next.js Examples
255
+
256
+ ```tsx
257
+ // ✅ Lazy load heavy components
258
+ import dynamic from 'next/dynamic'
259
+
260
+ const HeavyChart = dynamic(() => import('./HeavyChart'), {
261
+ loading: () => <div>Loading chart...</div>,
262
+ ssr: false // Client-side only
263
+ })
264
+
265
+ // ✅ Route-based splitting (automatic in Next.js)
266
+ // pages/dashboard.tsx - loaded only when /dashboard is accessed
267
+ ```
268
+
269
+ ```tsx
270
+ // React (without Next.js)
271
+ import { lazy, Suspense } from 'react'
272
+
273
+ const Dashboard = lazy(() => import('./Dashboard'))
274
+
275
+ function App() {
276
+ return (
277
+ <Suspense fallback={<div>Loading...</div>}>
278
+ <Dashboard />
279
+ </Suspense>
280
+ )
281
+ }
282
+ ```
283
+
284
+ ---
285
+
286
+ ## 📊 Performance Budget
287
+
288
+ **Define limits to prevent performance regression:**
289
+
290
+ | Metric | Target | Max | Action if exceeded |
291
+ |--------|--------|-----|-------------------|
292
+ | **LCP** | < 2.5s | 4s | Optimize images, reduce bundle |
293
+ | **FCP** | < 1.8s | 3s | Inline critical CSS, defer JS |
294
+ | **Total Bundle (initial)** | < 200KB | 500KB | Code splitting, tree shaking |
295
+ | **Image Size (each)** | < 100KB | 200KB | Compress, use WebP |
296
+ | **HTTP Requests** | < 10 | 20 | Combine assets, use sprites |
297
+
298
+ **Check during code review:**
299
+ ```bash
300
+ # Check bundle size
301
+ npm run build
302
+
303
+ # Check Lighthouse score
304
+ lighthouse https://your-site.com --view
305
+ ```
306
+
307
+ ---
308
+
309
+ ## ⚡ Quick Wins (Immediate Impact)
310
+
311
+ ### 1. Convert Images to WebP
312
+ ```bash
313
+ # Batch convert all JPEGs to WebP
314
+ for file in *.jpg; do
315
+ magick "$file" -quality 85 "${file%.jpg}.webp"
316
+ done
317
+ ```
318
+
319
+ **Impact:** -30% file size, +0.5s LCP improvement
320
+
321
+ ---
322
+
323
+ ### 2. Add Lazy Loading to Images
324
+ ```tsx
325
+ // Find all images and add loading="lazy"
326
+ <img src="..." alt="..." loading="lazy" />
327
+ ```
328
+
329
+ **Impact:** -2s initial load time, +20 Lighthouse score
330
+
331
+ ---
332
+
333
+ ### 3. Specify Image Dimensions
334
+ ```tsx
335
+ // Add width/height to prevent layout shift
336
+ <img src="..." alt="..." width={400} height={300} />
337
+ ```
338
+
339
+ **Impact:** CLS score 0.1 → 0.01 (90% improvement)
340
+
341
+ ---
342
+
343
+ ## 🚨 Common Mistakes
344
+
345
+ ### ❌ Mistake 1: Lazy load hero images
346
+
347
+ ```tsx
348
+ // ❌ BAD: Hero image lazy loaded (appears late)
349
+ <img src="hero.webp" alt="Hero" loading="lazy" />
350
+
351
+ // ✅ GOOD: Hero image eager loaded
352
+ <img src="hero.webp" alt="Hero" loading="eager" />
353
+ ```
354
+
355
+ ---
356
+
357
+ ### ❌ Mistake 2: No image dimensions
358
+
359
+ ```tsx
360
+ // ❌ BAD: No dimensions (causes layout shift)
361
+ <img src="product.webp" alt="Product" />
362
+
363
+ // ✅ GOOD: Dimensions specified
364
+ <img src="product.webp" alt="Product" width={400} height={300} />
365
+ ```
366
+
367
+ ---
368
+
369
+ ### ❌ Mistake 3: Using PNG for photos
370
+
371
+ ```tsx
372
+ // ❌ BAD: PNG for photo (2.2MB)
373
+ <img src="photo.png" alt="Photo" />
374
+
375
+ // ✅ GOOD: WebP for photo (300KB)
376
+ <picture>
377
+ <source srcset="photo.webp" type="image/webp">
378
+ <img src="photo.jpg" alt="Photo" />
379
+ </picture>
380
+ ```
381
+
382
+ ---
383
+
384
+ ### ❌ Mistake 4: No responsive images
385
+
386
+ ```tsx
387
+ // ❌ BAD: Mobile downloads 1920px image
388
+ <img src="hero-1920.webp" alt="Hero" />
389
+
390
+ // ✅ GOOD: Responsive images (mobile gets 768px)
391
+ <img
392
+ src="hero-1920.webp"
393
+ srcset="hero-768.webp 768w, hero-1024.webp 1024w, hero-1920.webp 1920w"
394
+ sizes="(max-width: 768px) 100vw, 1920px"
395
+ alt="Hero"
396
+ />
397
+ ```
398
+
399
+ ---
400
+
401
+ ## 📚 Additional Resources
402
+
403
+ **Official Docs:**
404
+ - [Web.dev: Optimize LCP](https://web.dev/optimize-lcp/)
405
+ - [MDN: Lazy loading](https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading)
406
+ - [Next.js: Image Optimization](https://nextjs.org/docs/basic-features/image-optimization)
407
+
408
+ **Tools:**
409
+ - **Lighthouse:** Chrome DevTools > Lighthouse tab
410
+ - **WebPageTest:** https://www.webpagetest.org/
411
+ - **Squoosh:** https://squoosh.app/ (image compression)
412
+ - **TinyPNG:** https://tinypng.com/ (batch compression)
413
+
414
+ **Source:**
415
+ - FreeCodeCamp Performance Handbook
416
+ - Chrome DevTools Performance Guide
417
+ - Web.dev Performance Best Practices
418
+
419
+ ---
420
+
421
+ **💡 Remember:** 80% of performance gains come from image optimization. Start there!
@@ -84,6 +84,49 @@ const LAYOUT_TOKENS = {
84
84
  }
85
85
  ```
86
86
 
87
+ #### Animation Properties (🆕 v1.4.0 - MANDATORY)
88
+ ```typescript
89
+ const ANIMATION_TOKENS = {
90
+ // Hover state
91
+ hover: {
92
+ properties: ['transform', 'box-shadow'], // GPU-accelerated only
93
+ values: ['scale(1.05)', 'shadow-lg'],
94
+ duration: '150ms', // From STYLE_TOKENS.json
95
+ easing: 'ease-in-out',
96
+ classes: 'hover:scale-105 hover:shadow-lg transition-all duration-150'
97
+ },
98
+
99
+ // Focus state (inputs)
100
+ focus: {
101
+ properties: ['box-shadow', 'border-color'],
102
+ values: ['ring-2 ring-primary', 'border-primary'],
103
+ duration: '200ms',
104
+ easing: 'ease-in-out',
105
+ classes: 'focus:ring-2 focus:ring-primary focus:border-primary transition-all duration-200'
106
+ },
107
+
108
+ // Active state (press feedback)
109
+ active: {
110
+ properties: ['transform'],
111
+ values: ['scale(0.95)'],
112
+ duration: '100ms',
113
+ easing: 'ease-in-out',
114
+ classes: 'active:scale-95'
115
+ },
116
+
117
+ // Rationale
118
+ description: 'Button scale + shadow pattern (consistency with other buttons)'
119
+ }
120
+ ```
121
+
122
+ **Critical Rules:**
123
+ 1. ✅ Extract animation from reference component (same as colors, spacing)
124
+ 2. ✅ Use durations from STYLE_TOKENS.json (150ms, 300ms, 500ms)
125
+ 3. ✅ Use GPU-accelerated properties (transform, opacity) - NOT width, height, top, left
126
+ 4. ✅ Same component type = same animation pattern (buttons scale, cards elevate shadow)
127
+ 5. ❌ NO random durations (200ms, 250ms) - only 150/300/500ms
128
+ 6. ❌ NO inconsistent patterns (button A scales, button B changes color)
129
+
87
130
  ---
88
131
 
89
132
  ### Step 3: Apply Tokens to New Component
@@ -263,11 +306,15 @@ transition: 'transition-colors'
263
306
  **Before committing any UI component:**
264
307
 
265
308
  - [ ] Found similar reference component in codebase
266
- - [ ] Extracted all design tokens (icon, spacing, colors, states)
267
- - [ ] Applied tokens exactly (no guessing)
309
+ - [ ] Extracted all design tokens (icon, spacing, colors, states, **animations**)
310
+ - [ ] Extracted animation tokens (hover, focus, active, durations)
311
+ - [ ] Verified durations match STYLE_TOKENS.json (150/300/500ms)
312
+ - [ ] Verified animation properties are GPU-accelerated (transform, opacity)
313
+ - [ ] Applied tokens exactly (no guessing, no random values)
268
314
  - [ ] Tested visual appearance in browser
269
315
  - [ ] Compared computed CSS values with DevTools
270
316
  - [ ] Tested all states (normal, hover, focus, error, disabled)
317
+ - [ ] Tested animation smoothness (60fps, no jank)
271
318
  - [ ] Documented reference component in JSDoc
272
319
  - [ ] Visually indistinguishable from reference component
273
320
 
@@ -44,7 +44,7 @@ Provides resilient agent execution that:
44
44
 
45
45
  **Main Claude should follow this flow in `/cdev` command:**
46
46
 
47
- ### Step 1: Build Prompt
47
+ ### Step 1: Build Prompt with Approval Context
48
48
 
49
49
  ```markdown
50
50
  Include in prompt:
@@ -52,33 +52,58 @@ Include in prompt:
52
52
  - Phase-specific instructions
53
53
  - TDD requirements (if phase.tdd_required)
54
54
  - Validation checkpoint reminder
55
+ - Approval context (if user approved workflow) ← NEW!
55
56
  ```
56
57
 
58
+ **Approval Context Format:**
59
+
60
+ ```
61
+ [AUTO-PROCEED: YES]
62
+ User has approved this workflow. After completing pre-work validation,
63
+ proceed immediately to implementation without asking for confirmation.
64
+ ```
65
+
66
+ **When to include:**
67
+ - ✅ User ran `/cdev` command → Auto-approve (implicit approval for all phases)
68
+ - ✅ User said "continue", "proceed", "yes", "ลุยเลย" → Auto-approve
69
+ - ❌ Agent previously failed → Skip (need explicit approval)
70
+ - ❌ Manual intervention mode → Skip (user wants control)
71
+
57
72
  ### Step 2: Execute with Retry Loop
58
73
 
59
74
  ```
60
75
  attempt = 0
61
76
  max_retries = 2
77
+ auto_proceed = userApprovalGranted() // Check if user approved workflow
62
78
 
63
79
  while (attempt <= max_retries):
64
80
 
65
81
  1. Invoke agent:
66
- Task(agent=agentType, model='haiku', prompt=buildPrompt())
67
-
68
- 2. Validate pre-work (see validation-framework.md):
82
+ Task(agent=agentType, model='haiku', prompt=buildPrompt(auto_proceed))
83
+
84
+ 2. Handle agent questions (NEW!):
85
+ If agent asks "Should I proceed?" or "Continue?":
86
+ - If auto_proceed === true:
87
+ → Answer agent: "YES, proceed immediately"
88
+ → Continue waiting for implementation result
89
+ - Else:
90
+ → Ask user: "Agent ready. Proceed? (yes/no)"
91
+ → Wait for user response
92
+
93
+ 3. Validate pre-work (see validation-framework.md):
69
94
  - Check for required checklist items
70
95
  - If missing → reject and retry
71
96
 
72
- 3. Validate output quality:
97
+ 4. Validate output quality:
73
98
  - Check for completion markers (✅, Done, Complete)
74
99
  - Check for code blocks (if code agent)
75
100
  - Check for test results (if test agent)
76
101
  - If incomplete → send feedback and retry
77
102
 
78
- 4. If validation passed:
103
+ 5. If validation passed:
79
104
  → SUCCESS! Return result
80
105
 
81
- 5. If validation failed:
106
+ 6. If validation failed:
82
107
  - If attempt < max_retries:
83
108
  → Send feedback, increment attempt, retry
84
109
  - Else:
@@ -242,17 +267,51 @@ Please provide complete output including:
242
267
  ```markdown
243
268
  Step 4: Invoke Agent with Retry
244
269
 
245
- 1. Build prompt (include validation requirements)
246
- 2. Execute retry loop (max 2 retries):
270
+ 1. Check user approval status:
271
+ - User ran /cdev auto_proceed = true
272
+ - User said "continue" → auto_proceed = true
273
+ - Otherwise → auto_proceed = false
274
+
275
+ 2. Build prompt (include validation requirements + approval context)
276
+
277
+ 3. Execute retry loop (max 2 retries):
247
278
  - Invoke agent
279
+ - Handle agent questions (auto-answer if approved)
248
280
  - Validate pre-work
249
281
  - Validate output quality
250
282
  - If failed → retry or escalate
251
- 3. Handle result:
283
+
284
+ 4. Handle result:
252
285
  - Success → update flags.json, move to next phase
253
286
  - Failed → escalate to user (retry/skip/abort)
254
287
  ```
255
288
 
256
289
  ---
257
290
 
291
+ ## 🎯 Auto-Proceed Decision Tree
292
+
293
+ ```
294
+ User Action → auto_proceed?
295
+ ─────────────────────────────
296
+ /cdev → YES (implicit approval for all phases)
297
+ "continue" → YES (explicit approval)
298
+ "proceed" → YES (explicit approval)
299
+ "yes" → YES (explicit approval)
300
+ "ลุยเลย" → YES (explicit approval)
301
+ /cdev retry → NO (need confirmation after failure)
302
+ Manual mode → NO (user wants control)
303
+ ```
304
+
305
+ **When auto_proceed = YES:**
306
+ - Agent asks "Proceed?" → Main Claude answers "YES" immediately
307
+ - No double-confirmation with user
308
+ - Faster workflow execution
309
+
310
+ **When auto_proceed = NO:**
311
+ - Agent asks "Proceed?" → Main Claude asks user
312
+ - Manual confirmation at each step
313
+ - Slower but more controlled
314
+
315
+ ---
316
+
258
317
  This retry & escalation framework makes agent execution **robust and reliable**.