@buivietphi/skill-mobile-mt 2.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.
@@ -0,0 +1,705 @@
1
+ # Prompt Engineering — Intelligent Prompt Generation
2
+
3
+ > Learned from Anthropic, Cline, Roo Code, and Claude Code.
4
+ > How to generate prompts that AI agents execute correctly.
5
+
6
+ ---
7
+
8
+ ## Core Principles
9
+
10
+ ### 1. XML Tag Structure (Anthropic Best Practice)
11
+
12
+ **Why:** Clear structure prevents misinterpretation.
13
+
14
+ ```xml
15
+ <task>
16
+ <role>Senior React Native developer with 10+ years experience</role>
17
+
18
+ <context>
19
+ Project: E-commerce mobile app
20
+ Stack: React Native 0.73 + TypeScript + Redux Toolkit
21
+ Current: Product listing works
22
+ Need: Add cart functionality
23
+ </context>
24
+
25
+ <instructions>
26
+ 1. Clone pattern from ProductList screen
27
+ 2. Create cart slice with Redux Toolkit
28
+ 3. Add items to cart with optimistic updates
29
+ 4. Handle API errors with rollback
30
+ </instructions>
31
+
32
+ <constraints>
33
+ - Must work offline (cache in Redux Persist)
34
+ - Follow existing ProductList pattern
35
+ - Use existing Button/Card components
36
+ - NO new dependencies without approval
37
+ </constraints>
38
+
39
+ <examples>
40
+ <example>
41
+ <input>Add product to cart</input>
42
+ <output>
43
+ dispatch(addToCart(product));
44
+ // Optimistic update → API call → rollback on error
45
+ </output>
46
+ </example>
47
+ </examples>
48
+
49
+ <output_format>
50
+ 1. List files to create/modify
51
+ 2. Show code changes with before/after
52
+ 3. Specify test cases
53
+ 4. List manual verification steps
54
+ </output_format>
55
+ </task>
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Auto-Think Templates (Enhanced)
61
+
62
+ ### Fix / Debug
63
+
64
+ ```xml
65
+ <think>
66
+ BUG: [description]
67
+ FILE: [path]
68
+
69
+ <source_verification>
70
+ ⚠️ BEFORE analyzing — verify I have real data:
71
+ - [ ] Read the actual file (not guessing from error message)
72
+ - [ ] Verified function/class names exist (grep)
73
+ - [ ] Checked package versions in package.json/pubspec.yaml
74
+ - [ ] Identified data types from actual code (not assumed)
75
+ </source_verification>
76
+
77
+ <context_needed>
78
+ - Read [file] to understand current implementation
79
+ - Grep for similar patterns: grep "[pattern]" src/
80
+ - Check imports and dependencies
81
+ </context_needed>
82
+
83
+ <root_cause>
84
+ [Analyze AFTER loading context - don't guess]
85
+ - What code is executed?
86
+ - What values are passed?
87
+ - What conditions are checked?
88
+ SOURCE: [file:line where the bug is — cite exact location]
89
+ </root_cause>
90
+
91
+ <fix>
92
+ [Specific change with code snippet]
93
+
94
+ WHY IT WORKS:
95
+ [Explain the fix based on root cause]
96
+ SOURCE: [where this fix pattern comes from — project code / skill file / official docs]
97
+ </fix>
98
+
99
+ <side_effects>
100
+ - Files that import this: [list after grep]
101
+ - Tests affected: [list]
102
+ - Platform-specific: iOS [impact] / Android [impact]
103
+ </side_effects>
104
+
105
+ <test>
106
+ 1. Unit test: [specific test case]
107
+ 2. Manual: [steps to reproduce bug → verify fix]
108
+ 3. Regression: [what could this break]
109
+ </test>
110
+
111
+ <cleanup>
112
+ - Remove debug logs
113
+ - Update comments
114
+ - Check for unused imports
115
+ </cleanup>
116
+ </think>
117
+ ```
118
+
119
+ **Example:**
120
+ ```xml
121
+ <think>
122
+ BUG: App crashes when tapping product with no images
123
+
124
+ <context_needed>
125
+ - Read src/screens/ProductDetail.tsx
126
+ - Grep for image rendering: grep "Image source" src/
127
+ - Check Product type definition
128
+ </context_needed>
129
+
130
+ <root_cause>
131
+ Line 42: <Image source={{uri: product.images[0]}} />
132
+ Problem: product.images is undefined when API returns no images
133
+ TypeScript allows this because images is Product['images']?
134
+ </root_cause>
135
+
136
+ <fix>
137
+ {product.images?.length > 0 ? (
138
+ <Image source={{uri: product.images[0]}} />
139
+ ) : (
140
+ <Image source={require('@assets/placeholder.png')} />
141
+ )}
142
+
143
+ WHY IT WORKS:
144
+ Optional chaining prevents undefined access.
145
+ Fallback image provides default visual.
146
+ </fix>
147
+
148
+ <side_effects>
149
+ - ProductCard.tsx also renders images → apply same fix
150
+ - No tests affected (this is a UI safety check)
151
+ - Works same on both platforms
152
+ </side_effects>
153
+
154
+ <test>
155
+ 1. Unit: Mock product with images: undefined
156
+ 2. Manual: Find product without images in staging API
157
+ 3. Regression: Verify products WITH images still render
158
+ </test>
159
+
160
+ <cleanup>
161
+ - No debug code added
162
+ - Add comment: // Handle products without images
163
+ </cleanup>
164
+ </think>
165
+ ```
166
+
167
+ ---
168
+
169
+ ### Build / Create (Multi-Phase)
170
+
171
+ **Phase 1: Discovery**
172
+ ```xml
173
+ <think>
174
+ <discovery>
175
+ FEATURE: [description]
176
+ PLATFORM: [React Native / Flutter / iOS / Android]
177
+
178
+ <source_verification>
179
+ ⚠️ GROUNDING CHECK:
180
+ - [ ] Scanned actual project structure (not assumed)
181
+ - [ ] Found real reference feature (not imagined)
182
+ - [ ] Will read reference files before cloning pattern
183
+ - [ ] Will verify all imports/packages exist before using
184
+ </source_verification>
185
+
186
+ STEP 1: SCAN PROJECT
187
+ - List screens: ls src/screens/
188
+ - Find similar features: grep -r "useState" src/screens/
189
+ - Identify pattern: feature-based or layer-based?
190
+
191
+ STEP 2: FIND REFERENCE
192
+ - Most similar feature: [name]
193
+ - Location: [path]
194
+ - Files in reference:
195
+ * Screen component
196
+ * Service/API layer
197
+ * State management (slice/store/bloc)
198
+ * Types/interfaces
199
+ * Tests
200
+
201
+ STEP 3: READ REFERENCE FILES
202
+ [List files to read - will load in next step]
203
+ </discovery>
204
+ </think>
205
+ ```
206
+
207
+ **Phase 2: Analysis**
208
+ ```xml
209
+ <think>
210
+ <analysis>
211
+ REFERENCE ANALYZED: src/features/product/
212
+
213
+ PATTERNS DETECTED:
214
+ - State: Redux Toolkit slice
215
+ - API: Axios with interceptor
216
+ - Data: API response → map to domain entity
217
+ - UI: Functional component + hooks
218
+ - Navigation: React Navigation v6
219
+ - Naming: camelCase for files, PascalCase for components
220
+
221
+ DATA FLOW:
222
+ ProductScreen
223
+ → useSelector(state.product.items)
224
+ → dispatch(fetchProducts())
225
+ → productSlice.ts (createAsyncThunk)
226
+ → productService.ts (axios.get)
227
+ → API response
228
+ → map to Product entity
229
+ → update Redux state
230
+ → re-render with new data
231
+
232
+ ERROR HANDLING:
233
+ - API errors: catch in thunk → set error state
234
+ - UI errors: ErrorBoundary wraps screen
235
+ - Network: Show offline banner
236
+
237
+ STATES: loading / success / error / empty
238
+ </analysis>
239
+ </think>
240
+ ```
241
+
242
+ **Phase 3: Clone Mapping**
243
+ ```xml
244
+ <think>
245
+ <clone_map>
246
+ REFERENCE → NEW FEATURE
247
+
248
+ product/ProductScreen.tsx → cart/CartScreen.tsx
249
+ product/useProducts.ts → cart/useCart.ts
250
+ product/productService.ts → cart/cartService.ts
251
+ product/productSlice.ts → cart/cartSlice.ts
252
+ product/product.types.ts → cart/cart.types.ts
253
+ product/ProductCard.tsx → cart/CartItem.tsx
254
+ product/ProductScreen.test.tsx → cart/CartScreen.test.tsx
255
+
256
+ MODIFICATIONS:
257
+ 1. Update API endpoints:
258
+ - GET /products → GET /cart
259
+ - POST /cart/add → add item to cart
260
+
261
+ 2. Adjust state shape:
262
+ - items: Product[] → items: CartItem[]
263
+ - Add: quantities, totals, discounts
264
+
265
+ 3. UI changes:
266
+ - ProductCard shows image + price
267
+ - CartItem shows image + price + quantity + remove button
268
+
269
+ 4. Navigation:
270
+ - ProductScreen → ProductDetail
271
+ - CartScreen → Checkout
272
+ </clone_map>
273
+ </think>
274
+ ```
275
+
276
+ **Phase 4: Implementation Plan**
277
+ ```xml
278
+ <think>
279
+ <implementation>
280
+ INCREMENTAL APPROACH (test after each step):
281
+
282
+ ITERATION 1: Type Definitions
283
+ - Create cart/cart.types.ts
284
+ - Define CartItem, Cart interfaces
285
+ - Export types
286
+ ✅ TEST: TypeScript compilation succeeds
287
+
288
+ ITERATION 2: API Service
289
+ - Create cart/cartService.ts
290
+ - Implement getCart(), addToCart(), removeFromCart()
291
+ - Use same axios instance as productService
292
+ ✅ TEST: Unit tests pass for API calls
293
+
294
+ ITERATION 3: Redux Slice
295
+ - Create cart/cartSlice.ts
296
+ - createAsyncThunk for async operations
297
+ - Add reducers for optimistic updates
298
+ ✅ TEST: Redux tests pass
299
+
300
+ ITERATION 4: Custom Hook
301
+ - Create cart/useCart.ts
302
+ - Wrap useSelector + useDispatch
303
+ - Export cart operations
304
+ ✅ TEST: Hook tests pass
305
+
306
+ ITERATION 5: UI Components
307
+ - Create cart/CartItem.tsx (clone ProductCard)
308
+ - Create cart/CartScreen.tsx (clone ProductScreen)
309
+ - Wire up with useCart hook
310
+ ✅ TEST: Component renders without errors
311
+
312
+ ITERATION 6: Navigation
313
+ - Add CartScreen to navigator
314
+ - Add "View Cart" button to header
315
+ - Test navigation flow
316
+ ✅ TEST: Navigation works on both platforms
317
+
318
+ DEPENDENCIES:
319
+ - No new packages needed (reuse existing stack)
320
+ </implementation>
321
+ </think>
322
+ ```
323
+
324
+ ---
325
+
326
+ ### Review / Audit
327
+
328
+ ```xml
329
+ <think>
330
+ <review>
331
+ SCOPE: [files/feature to review]
332
+
333
+ SCAN ORDER (by severity):
334
+ 1. 🔴 CRITICAL: Crash risks
335
+ - Force unwraps (! / !!)
336
+ - Array access without bounds check
337
+ - Unhandled null from API
338
+
339
+ 2. 🔴 CRITICAL: Security
340
+ - Hardcoded secrets
341
+ - Tokens in AsyncStorage (use SecureStore)
342
+ - SQL injection / XSS vulnerabilities
343
+
344
+ 3. 🟠 HIGH: Memory leaks
345
+ - useEffect without cleanup
346
+ - Listeners not removed
347
+ - Timers not cleared
348
+
349
+ 4. 🟡 MEDIUM: Performance
350
+ - Inline functions in render
351
+ - Missing React.memo
352
+ - ScrollView for long lists (use FlatList)
353
+
354
+ 5. 🟡 MEDIUM: Code quality
355
+ - Missing types (any)
356
+ - Duplicate code
357
+ - Magic numbers/strings
358
+
359
+ OUTPUT FORMAT:
360
+ file:line — severity — issue — fix
361
+ </review>
362
+ </think>
363
+ ```
364
+
365
+ ---
366
+
367
+ ### Refactor
368
+
369
+ ```xml
370
+ <think>
371
+ <refactor>
372
+ TARGET: [what to improve]
373
+
374
+ CONSTRAINTS:
375
+ ✅ NO behavior changes
376
+ ✅ NO new dependencies
377
+ ✅ Match existing conventions
378
+ ✅ All tests must still pass
379
+
380
+ STEP 1: IMPACT ANALYSIS
381
+ - Files affected: grep -r "[pattern]" src/
382
+ - Dependencies: [what imports this]
383
+ - Tests: find . -name "*.test.*" | grep [pattern]
384
+
385
+ STEP 2: REFACTOR PLAN
386
+ Priority 1 (Core Logic):
387
+ - [file]: [specific change]
388
+
389
+ Priority 2 (Dependents):
390
+ - [file]: [update imports/usage]
391
+
392
+ Priority 3 (Tests):
393
+ - [file]: [update test cases]
394
+
395
+ STEP 3: EXECUTION
396
+ [Execute Priority 1 → run tests → proceed to Priority 2]
397
+
398
+ STEP 4: VERIFICATION
399
+ ✅ All tests pass
400
+ ✅ TypeScript compiles
401
+ ✅ No new lint errors
402
+ ✅ Git diff review (no unintended changes)
403
+ </refactor>
404
+ </think>
405
+ ```
406
+
407
+ ---
408
+
409
+ ## Mobile-Specific Patterns
410
+
411
+ ### Platform-Specific Implementation
412
+
413
+ ```xml
414
+ <think>
415
+ <mobile_implementation>
416
+ FEATURE: [description]
417
+ PLATFORM: React Native
418
+
419
+ CROSS-PLATFORM STRATEGY:
420
+ 1. Identify platform differences:
421
+ iOS: [specific behaviors]
422
+ Android: [specific behaviors]
423
+
424
+ 2. Choose approach:
425
+ [ ] Shared component with Platform.select
426
+ [ ] Separate .ios.tsx and .android.tsx files
427
+ [ ] Native module (requires native code)
428
+
429
+ EXAMPLE:
430
+ // Shared component approach
431
+ import { Platform } from 'react-native';
432
+
433
+ export const DatePicker = () => {
434
+ const Picker = Platform.select({
435
+ ios: () => require('./DatePicker.ios').default,
436
+ android: () => require('./DatePicker.android').default,
437
+ })();
438
+
439
+ return <Picker />;
440
+ };
441
+
442
+ TESTING:
443
+ - Jest: Test shared logic
444
+ - Platform-specific: Manual on both devices
445
+ - Edge cases: Different OS versions, screen sizes
446
+
447
+ CONSIDERATIONS:
448
+ - iOS: Use native UIDatePicker
449
+ - Android: Use native DatePickerDialog
450
+ - Permissions: Different request flows
451
+ - UI: Respect platform design guidelines
452
+ </mobile_implementation>
453
+ </think>
454
+ ```
455
+
456
+ ---
457
+
458
+ ### Performance Optimization
459
+
460
+ ```xml
461
+ <think>
462
+ <optimization>
463
+ COMPONENT: [name]
464
+
465
+ STEP 1: PROFILE
466
+ - Tool: React DevTools Profiler
467
+ - Metric: Render time, re-render count
468
+ - Current: [value] ms per render
469
+
470
+ STEP 2: ANALYZE
471
+ Root causes:
472
+ - [ ] Expensive computation in render
473
+ - [ ] Inline functions causing re-renders
474
+ - [ ] Missing memoization
475
+ - [ ] Large list without virtualization
476
+
477
+ STEP 3: OPTIMIZE (priority order)
478
+ 1. [ ] React.memo for pure components
479
+ 2. [ ] useMemo for expensive computations
480
+ 3. [ ] useCallback for stable callbacks
481
+ 4. [ ] FlatList with getItemLayout
482
+ 5. [ ] Image optimization (resize, cache)
483
+
484
+ STEP 4: MEASURE
485
+ - Before: [ms] per render
486
+ - After: [ms] per render
487
+ - Improvement: [%]
488
+
489
+ TRADE-OFFS:
490
+ - Code complexity: [increased/decreased]
491
+ - Bundle size: [KB change]
492
+ - Maintainability: [impact]
493
+
494
+ DECISION: [proceed / revert / iterate]
495
+ </optimization>
496
+ </think>
497
+ ```
498
+
499
+ ---
500
+
501
+ ## Context Management
502
+
503
+ ### Progressive Loading (Don't load everything upfront)
504
+
505
+ ```
506
+ Level 1: Always Loaded
507
+ └── SKILL.md (project overview, tech stack)
508
+
509
+ Level 2: Task-Triggered
510
+ └── Identify reference pattern (don't read yet)
511
+
512
+ Level 3: File-Specific
513
+ └── Read ONLY files needed for current task
514
+
515
+ Level 4: Deep Dive
516
+ └── Load detailed docs if stuck
517
+
518
+ Level 5: Expert
519
+ └── Invoke specialized subagent
520
+
521
+ ⛔ DON'T jump to Level 5 immediately.
522
+ ✅ DO progress through levels as complexity requires.
523
+ ```
524
+
525
+ **Example:**
526
+ ```xml
527
+ <progressive_context>
528
+ User: "Add dark mode"
529
+
530
+ Level 1: Check SKILL.md
531
+ → React Native + TypeScript project
532
+ → Styled with StyleSheet
533
+
534
+ Level 2: Find pattern
535
+ → grep "theme" src/ --files-with-matches
536
+ → Found: src/theme/theme.ts
537
+
538
+ Level 3: Read reference
539
+ → Read src/theme/theme.ts
540
+ → Understand current theme structure
541
+
542
+ Level 4: Implement
543
+ → Clone pattern
544
+ → Add dark mode values
545
+ → No need for Level 5 (straightforward task)
546
+ </progressive_context>
547
+ ```
548
+
549
+ ---
550
+
551
+ ### Just-In-Time File Reading
552
+
553
+ ```xml
554
+ <jit_reading>
555
+ ❌ BAD: Read all files upfront
556
+ Read src/screens/HomeScreen.tsx
557
+ Read src/screens/ProductScreen.tsx
558
+ Read src/screens/CartScreen.tsx
559
+ Read src/screens/ProfileScreen.tsx
560
+ [Load 50+ files → context bloat]
561
+
562
+ ✅ GOOD: Search → Read only relevant
563
+ grep "useAuth" src/screens/ --files-with-matches
564
+ → Found: ProfileScreen.tsx
565
+
566
+ Read src/screens/ProfileScreen.tsx
567
+ [Load 1 file → use ~500 tokens instead of 25,000]
568
+ </jit_reading>
569
+ ```
570
+
571
+ ---
572
+
573
+ ### Reference Pattern System
574
+
575
+ ```markdown
576
+ BEFORE reading docs, check if a REFERENCE exists:
577
+
578
+ List Screen → src/screens/ProductList/
579
+ Form Screen → src/screens/UserProfile/EditProfile
580
+ API Integration → src/services/productService.ts
581
+ Redux Slice → src/store/slices/productSlice.ts
582
+ Navigation → src/navigation/RootNavigator.tsx
583
+
584
+ Clone the reference pattern → modify → test.
585
+ Faster than reading documentation.
586
+ ```
587
+
588
+ ---
589
+
590
+ ## Multi-AI Format
591
+
592
+ | AI | Think Format | Notes |
593
+ |----|-------------|-------|
594
+ | Claude | `<think>...</think>` | XML tags preferred |
595
+ | Gemini | `## Thinking:` block | Markdown headings |
596
+ | Kimi | `【思考】` or markdown | Supports Chinese |
597
+ | Cursor | Inline in Composer | Visible to user |
598
+ | Copilot | `// PLAN:` comments | Code comments |
599
+ | Windsurf | Inline reasoning | Similar to Cursor |
600
+
601
+ ---
602
+
603
+ ## Anti-Patterns (Don't Do This)
604
+
605
+ ```
606
+ ❌ Vague instructions
607
+ "Make this better"
608
+ "Optimize the app"
609
+ "Fix all bugs"
610
+
611
+ ✅ Specific instructions
612
+ "Reduce ProductList render time from 300ms to <100ms"
613
+ "Fix crash when product.images is undefined"
614
+ "Add pagination to ProductList with 20 items per page"
615
+
616
+ ❌ Over-loading context
617
+ Read all 50 component files upfront
618
+
619
+ ✅ Lazy loading
620
+ Grep → identify → read only relevant files
621
+
622
+ ❌ Skipping verification
623
+ Write code → mark as done
624
+
625
+ ✅ Quality gate
626
+ Write → test → verify → then mark done
627
+
628
+ ❌ Guessing root cause
629
+ "Probably a race condition"
630
+
631
+ ✅ Reading code first
632
+ Read file → analyze flow → identify cause → fix
633
+
634
+ ❌ Generic prompts
635
+ "Create login screen"
636
+
637
+ ✅ Contextual prompts
638
+ "Create login screen following pattern in src/screens/ProductScreen
639
+ using Redux slice from src/store/slices/authSlice
640
+ with email/password fields + remember me checkbox"
641
+
642
+ ❌ Hallucinated answers (AI "intuition")
643
+ "Use react-native-awesome-picker for this" ← package may not exist
644
+ "Call the fetchUserData() method" ← function may not exist
645
+ "This API returns { data: [...] }" ← response shape may be wrong
646
+
647
+ ✅ Grounded answers (verified from source)
648
+ Read package.json → verify package exists → then suggest usage
649
+ Grep "fetchUser" src/ → find actual function → then reference it
650
+ Read API service file → check actual response shape → then use it
651
+ ```
652
+
653
+ ---
654
+
655
+ ## Quick Reference
656
+
657
+ ### Good Prompt Checklist
658
+
659
+ ```
660
+ ✅ Role defined (Senior React Native developer)
661
+ ✅ Context provided (tech stack, current state)
662
+ ✅ Task is specific (what to build, not "make better")
663
+ ✅ Constraints listed (platform, dependencies, patterns)
664
+ ✅ Reference pattern identified (clone from X)
665
+ ✅ Success criteria clear (passes tests + renders)
666
+ ✅ Output format specified (code + tests + verification)
667
+ ```
668
+
669
+ ### Before Writing Code
670
+
671
+ ```
672
+ 1. 🔍 READ existing code (don't guess patterns)
673
+ 2. 🗺️ IDENTIFY reference to clone
674
+ 3. 📋 PLAN files to create/modify
675
+ 4. 🧪 DEFINE how to test/verify
676
+ 5. ⚠️ CHECK side effects (what else could break)
677
+ 6. 💻 WRITE code incrementally (test each step)
678
+ 7. ✅ VERIFY all quality gates pass
679
+ ```
680
+
681
+ ### When Stuck
682
+
683
+ ```
684
+ Instead of: "I don't know how to do this"
685
+ Do this: grep -r "similar pattern" src/
686
+ Read reference files
687
+ Clone and modify
688
+
689
+ Instead of: Load all documentation
690
+ Do this: Start with SKILL.md overview
691
+ Find reference pattern
692
+ Read only needed files
693
+ Load docs only if stuck
694
+
695
+ Instead of: Try random fixes
696
+ Do this: Read code → understand flow
697
+ Analyze root cause
698
+ Apply targeted fix
699
+ Verify with tests
700
+ ```
701
+
702
+ ---
703
+
704
+ > **Golden Rule:** Think like a senior developer joining a new team.
705
+ > Read their code. Follow their patterns. Ask when unclear. Test before shipping.