moai-adk 0.4.4__py3-none-any.whl → 0.4.7__py3-none-any.whl

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.

Potentially problematic release.


This version of moai-adk might be problematic. Click here for more details.

Files changed (191) hide show
  1. moai_adk/__init__.py +1 -1
  2. moai_adk/core/project/initializer.py +12 -5
  3. moai_adk/templates/.claude/agents/alfred/skill-factory.md +829 -0
  4. moai_adk/templates/.claude/skills/moai-alfred-code-reviewer/SKILL.md +78 -77
  5. moai_adk/templates/.claude/skills/moai-alfred-code-reviewer/examples.md +29 -0
  6. moai_adk/templates/.claude/skills/moai-alfred-code-reviewer/reference.md +28 -0
  7. moai_adk/templates/.claude/skills/moai-alfred-debugger-pro/SKILL.md +87 -77
  8. moai_adk/templates/.claude/skills/moai-alfred-debugger-pro/examples.md +29 -0
  9. moai_adk/templates/.claude/skills/moai-alfred-debugger-pro/reference.md +28 -0
  10. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/SKILL.md +76 -66
  11. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/examples.md +29 -0
  12. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/reference.md +28 -0
  13. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/SKILL.md +86 -59
  14. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/examples.md +29 -0
  15. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/reference.md +29 -0
  16. moai_adk/templates/.claude/skills/moai-alfred-language-detection/SKILL.md +87 -73
  17. moai_adk/templates/.claude/skills/moai-alfred-language-detection/examples.md +29 -0
  18. moai_adk/templates/.claude/skills/moai-alfred-language-detection/reference.md +28 -0
  19. moai_adk/templates/.claude/skills/moai-alfred-performance-optimizer/SKILL.md +87 -79
  20. moai_adk/templates/.claude/skills/moai-alfred-performance-optimizer/examples.md +29 -0
  21. moai_adk/templates/.claude/skills/moai-alfred-performance-optimizer/reference.md +28 -0
  22. moai_adk/templates/.claude/skills/moai-alfred-refactoring-coach/SKILL.md +87 -71
  23. moai_adk/templates/.claude/skills/moai-alfred-refactoring-coach/examples.md +29 -0
  24. moai_adk/templates/.claude/skills/moai-alfred-refactoring-coach/reference.md +28 -0
  25. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/SKILL.md +78 -62
  26. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/examples.md +29 -0
  27. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/reference.md +28 -0
  28. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/SKILL.md +78 -55
  29. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/examples.md +29 -0
  30. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/reference.md +28 -0
  31. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/SKILL.md +78 -64
  32. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/examples.md +29 -0
  33. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/reference.md +28 -0
  34. moai_adk/templates/.claude/skills/moai-alfred-tui-survey/SKILL.md +604 -56
  35. moai_adk/templates/.claude/skills/moai-alfred-tui-survey/examples.md +974 -44
  36. moai_adk/templates/.claude/skills/moai-alfred-tui-survey/reference.md +801 -0
  37. moai_adk/templates/.claude/skills/moai-claude-code/SKILL.md +88 -61
  38. moai_adk/templates/.claude/skills/moai-claude-code/examples.md +16 -500
  39. moai_adk/templates/.claude/skills/moai-claude-code/reference.md +15 -420
  40. moai_adk/templates/.claude/skills/moai-domain-backend/SKILL.md +234 -43
  41. moai_adk/templates/.claude/skills/moai-domain-backend/examples.md +1633 -0
  42. moai_adk/templates/.claude/skills/moai-domain-backend/reference.md +660 -0
  43. moai_adk/templates/.claude/skills/moai-domain-cli-tool/SKILL.md +97 -69
  44. moai_adk/templates/.claude/skills/moai-domain-cli-tool/examples.md +29 -0
  45. moai_adk/templates/.claude/skills/moai-domain-cli-tool/reference.md +30 -0
  46. moai_adk/templates/.claude/skills/moai-domain-data-science/SKILL.md +97 -72
  47. moai_adk/templates/.claude/skills/moai-domain-data-science/examples.md +29 -0
  48. moai_adk/templates/.claude/skills/moai-domain-data-science/reference.md +30 -0
  49. moai_adk/templates/.claude/skills/moai-domain-database/SKILL.md +97 -74
  50. moai_adk/templates/.claude/skills/moai-domain-database/examples.md +29 -0
  51. moai_adk/templates/.claude/skills/moai-domain-database/reference.md +30 -0
  52. moai_adk/templates/.claude/skills/moai-domain-devops/SKILL.md +98 -74
  53. moai_adk/templates/.claude/skills/moai-domain-devops/examples.md +29 -0
  54. moai_adk/templates/.claude/skills/moai-domain-devops/reference.md +31 -0
  55. moai_adk/templates/.claude/skills/moai-domain-frontend/SKILL.md +98 -73
  56. moai_adk/templates/.claude/skills/moai-domain-frontend/examples.md +29 -0
  57. moai_adk/templates/.claude/skills/moai-domain-frontend/reference.md +31 -0
  58. moai_adk/templates/.claude/skills/moai-domain-ml/SKILL.md +97 -73
  59. moai_adk/templates/.claude/skills/moai-domain-ml/examples.md +29 -0
  60. moai_adk/templates/.claude/skills/moai-domain-ml/reference.md +30 -0
  61. moai_adk/templates/.claude/skills/moai-domain-mobile-app/SKILL.md +97 -67
  62. moai_adk/templates/.claude/skills/moai-domain-mobile-app/examples.md +29 -0
  63. moai_adk/templates/.claude/skills/moai-domain-mobile-app/reference.md +30 -0
  64. moai_adk/templates/.claude/skills/moai-domain-security/SKILL.md +97 -79
  65. moai_adk/templates/.claude/skills/moai-domain-security/examples.md +29 -0
  66. moai_adk/templates/.claude/skills/moai-domain-security/reference.md +30 -0
  67. moai_adk/templates/.claude/skills/moai-domain-web-api/SKILL.md +97 -71
  68. moai_adk/templates/.claude/skills/moai-domain-web-api/examples.md +29 -0
  69. moai_adk/templates/.claude/skills/moai-domain-web-api/reference.md +30 -0
  70. moai_adk/templates/.claude/skills/moai-essentials-debug/SKILL.md +656 -60
  71. moai_adk/templates/.claude/skills/moai-essentials-debug/examples.md +1107 -0
  72. moai_adk/templates/.claude/skills/moai-essentials-debug/reference.md +1533 -0
  73. moai_adk/templates/.claude/skills/moai-essentials-perf/SKILL.md +87 -78
  74. moai_adk/templates/.claude/skills/moai-essentials-perf/examples.md +29 -0
  75. moai_adk/templates/.claude/skills/moai-essentials-perf/reference.md +28 -0
  76. moai_adk/templates/.claude/skills/moai-essentials-refactor/SKILL.md +87 -70
  77. moai_adk/templates/.claude/skills/moai-essentials-refactor/examples.md +29 -0
  78. moai_adk/templates/.claude/skills/moai-essentials-refactor/reference.md +28 -0
  79. moai_adk/templates/.claude/skills/moai-essentials-review/SKILL.md +87 -86
  80. moai_adk/templates/.claude/skills/moai-essentials-review/examples.md +29 -0
  81. moai_adk/templates/.claude/skills/moai-essentials-review/reference.md +28 -0
  82. moai_adk/templates/.claude/skills/moai-foundation-ears/SKILL.md +77 -62
  83. moai_adk/templates/.claude/skills/moai-foundation-ears/examples.md +29 -0
  84. moai_adk/templates/.claude/skills/moai-foundation-ears/reference.md +28 -0
  85. moai_adk/templates/.claude/skills/moai-foundation-git/SKILL.md +88 -56
  86. moai_adk/templates/.claude/skills/moai-foundation-git/examples.md +29 -0
  87. moai_adk/templates/.claude/skills/moai-foundation-git/reference.md +29 -0
  88. moai_adk/templates/.claude/skills/moai-foundation-langs/SKILL.md +90 -71
  89. moai_adk/templates/.claude/skills/moai-foundation-langs/examples.md +29 -0
  90. moai_adk/templates/.claude/skills/moai-foundation-langs/reference.md +28 -0
  91. moai_adk/templates/.claude/skills/moai-foundation-specs/SKILL.md +78 -58
  92. moai_adk/templates/.claude/skills/moai-foundation-specs/examples.md +29 -0
  93. moai_adk/templates/.claude/skills/moai-foundation-specs/reference.md +28 -0
  94. moai_adk/templates/.claude/skills/moai-foundation-tags/SKILL.md +78 -51
  95. moai_adk/templates/.claude/skills/moai-foundation-tags/examples.md +29 -0
  96. moai_adk/templates/.claude/skills/moai-foundation-tags/reference.md +28 -0
  97. moai_adk/templates/.claude/skills/moai-foundation-trust/SKILL.md +253 -32
  98. moai_adk/templates/.claude/skills/moai-foundation-trust/examples.md +0 -0
  99. moai_adk/templates/.claude/skills/moai-foundation-trust/reference.md +1099 -0
  100. moai_adk/templates/.claude/skills/moai-lang-c/SKILL.md +98 -74
  101. moai_adk/templates/.claude/skills/moai-lang-c/examples.md +29 -0
  102. moai_adk/templates/.claude/skills/moai-lang-c/reference.md +31 -0
  103. moai_adk/templates/.claude/skills/moai-lang-clojure/SKILL.md +97 -74
  104. moai_adk/templates/.claude/skills/moai-lang-clojure/examples.md +29 -0
  105. moai_adk/templates/.claude/skills/moai-lang-clojure/reference.md +30 -0
  106. moai_adk/templates/.claude/skills/moai-lang-cpp/SKILL.md +98 -76
  107. moai_adk/templates/.claude/skills/moai-lang-cpp/examples.md +29 -0
  108. moai_adk/templates/.claude/skills/moai-lang-cpp/reference.md +31 -0
  109. moai_adk/templates/.claude/skills/moai-lang-csharp/SKILL.md +97 -74
  110. moai_adk/templates/.claude/skills/moai-lang-csharp/examples.md +29 -0
  111. moai_adk/templates/.claude/skills/moai-lang-csharp/reference.md +30 -0
  112. moai_adk/templates/.claude/skills/moai-lang-dart/SKILL.md +86 -61
  113. moai_adk/templates/.claude/skills/moai-lang-dart/examples.md +29 -0
  114. moai_adk/templates/.claude/skills/moai-lang-dart/reference.md +30 -0
  115. moai_adk/templates/.claude/skills/moai-lang-elixir/SKILL.md +98 -73
  116. moai_adk/templates/.claude/skills/moai-lang-elixir/examples.md +29 -0
  117. moai_adk/templates/.claude/skills/moai-lang-elixir/reference.md +31 -0
  118. moai_adk/templates/.claude/skills/moai-lang-go/SKILL.md +98 -74
  119. moai_adk/templates/.claude/skills/moai-lang-go/examples.md +29 -0
  120. moai_adk/templates/.claude/skills/moai-lang-go/reference.md +31 -0
  121. moai_adk/templates/.claude/skills/moai-lang-haskell/SKILL.md +98 -74
  122. moai_adk/templates/.claude/skills/moai-lang-haskell/examples.md +29 -0
  123. moai_adk/templates/.claude/skills/moai-lang-haskell/reference.md +31 -0
  124. moai_adk/templates/.claude/skills/moai-lang-java/SKILL.md +87 -61
  125. moai_adk/templates/.claude/skills/moai-lang-java/examples.md +29 -0
  126. moai_adk/templates/.claude/skills/moai-lang-java/reference.md +31 -0
  127. moai_adk/templates/.claude/skills/moai-lang-javascript/SKILL.md +88 -59
  128. moai_adk/templates/.claude/skills/moai-lang-javascript/examples.md +29 -0
  129. moai_adk/templates/.claude/skills/moai-lang-javascript/reference.md +32 -0
  130. moai_adk/templates/.claude/skills/moai-lang-julia/SKILL.md +86 -61
  131. moai_adk/templates/.claude/skills/moai-lang-julia/examples.md +29 -0
  132. moai_adk/templates/.claude/skills/moai-lang-julia/reference.md +30 -0
  133. moai_adk/templates/.claude/skills/moai-lang-kotlin/SKILL.md +98 -73
  134. moai_adk/templates/.claude/skills/moai-lang-kotlin/examples.md +29 -0
  135. moai_adk/templates/.claude/skills/moai-lang-kotlin/reference.md +31 -0
  136. moai_adk/templates/.claude/skills/moai-lang-lua/SKILL.md +86 -61
  137. moai_adk/templates/.claude/skills/moai-lang-lua/examples.md +29 -0
  138. moai_adk/templates/.claude/skills/moai-lang-lua/reference.md +30 -0
  139. moai_adk/templates/.claude/skills/moai-lang-php/SKILL.md +86 -61
  140. moai_adk/templates/.claude/skills/moai-lang-php/examples.md +29 -0
  141. moai_adk/templates/.claude/skills/moai-lang-php/reference.md +30 -0
  142. moai_adk/templates/.claude/skills/moai-lang-python/SKILL.md +388 -53
  143. moai_adk/templates/.claude/skills/moai-lang-python/examples.md +624 -0
  144. moai_adk/templates/.claude/skills/moai-lang-python/reference.md +316 -0
  145. moai_adk/templates/.claude/skills/moai-lang-r/SKILL.md +97 -73
  146. moai_adk/templates/.claude/skills/moai-lang-r/examples.md +29 -0
  147. moai_adk/templates/.claude/skills/moai-lang-r/reference.md +30 -0
  148. moai_adk/templates/.claude/skills/moai-lang-ruby/SKILL.md +98 -73
  149. moai_adk/templates/.claude/skills/moai-lang-ruby/examples.md +29 -0
  150. moai_adk/templates/.claude/skills/moai-lang-ruby/reference.md +31 -0
  151. moai_adk/templates/.claude/skills/moai-lang-rust/SKILL.md +98 -74
  152. moai_adk/templates/.claude/skills/moai-lang-rust/examples.md +29 -0
  153. moai_adk/templates/.claude/skills/moai-lang-rust/reference.md +31 -0
  154. moai_adk/templates/.claude/skills/moai-lang-scala/SKILL.md +97 -74
  155. moai_adk/templates/.claude/skills/moai-lang-scala/examples.md +29 -0
  156. moai_adk/templates/.claude/skills/moai-lang-scala/reference.md +30 -0
  157. moai_adk/templates/.claude/skills/moai-lang-shell/SKILL.md +97 -74
  158. moai_adk/templates/.claude/skills/moai-lang-shell/examples.md +29 -0
  159. moai_adk/templates/.claude/skills/moai-lang-shell/reference.md +30 -0
  160. moai_adk/templates/.claude/skills/moai-lang-sql/SKILL.md +98 -74
  161. moai_adk/templates/.claude/skills/moai-lang-sql/examples.md +29 -0
  162. moai_adk/templates/.claude/skills/moai-lang-sql/reference.md +31 -0
  163. moai_adk/templates/.claude/skills/moai-lang-swift/SKILL.md +97 -73
  164. moai_adk/templates/.claude/skills/moai-lang-swift/examples.md +29 -0
  165. moai_adk/templates/.claude/skills/moai-lang-swift/reference.md +30 -0
  166. moai_adk/templates/.claude/skills/moai-lang-typescript/SKILL.md +90 -59
  167. moai_adk/templates/.claude/skills/moai-lang-typescript/examples.md +29 -0
  168. moai_adk/templates/.claude/skills/moai-lang-typescript/reference.md +34 -0
  169. moai_adk/templates/.claude/skills/moai-skill-factory/CHECKLIST.md +482 -0
  170. moai_adk/templates/.claude/skills/moai-skill-factory/EXAMPLES.md +52 -0
  171. moai_adk/templates/.claude/skills/moai-skill-factory/INTERACTIVE-DISCOVERY.md +524 -0
  172. moai_adk/templates/.claude/skills/moai-skill-factory/METADATA.md +477 -0
  173. moai_adk/templates/.claude/skills/moai-skill-factory/SKILL-UPDATE-ADVISOR.md +577 -0
  174. moai_adk/templates/.claude/skills/moai-skill-factory/SKILL.md +560 -0
  175. moai_adk/templates/.claude/skills/moai-skill-factory/STRUCTURE.md +583 -0
  176. moai_adk/templates/.claude/skills/moai-skill-factory/WEB-RESEARCH.md +526 -0
  177. moai_adk/templates/.claude/skills/moai-skill-factory/reference.md +69 -0
  178. moai_adk/templates/.claude/skills/moai-skill-factory/scripts/generate-structure.sh +328 -0
  179. moai_adk/templates/.claude/skills/moai-skill-factory/scripts/validate-skill.sh +312 -0
  180. moai_adk/templates/.claude/skills/moai-skill-factory/templates/SKILL_TEMPLATE.md +245 -0
  181. moai_adk/templates/.claude/skills/moai-skill-factory/templates/examples-template.md +285 -0
  182. moai_adk/templates/.claude/skills/moai-skill-factory/templates/reference-template.md +278 -0
  183. moai_adk/templates/.claude/skills/moai-skill-factory/templates/scripts-template.sh +303 -0
  184. moai_adk/templates/CLAUDE.md +43 -11
  185. moai_adk-0.4.7.dist-info/METADATA +1162 -0
  186. moai_adk-0.4.7.dist-info/RECORD +275 -0
  187. moai_adk-0.4.4.dist-info/METADATA +0 -369
  188. moai_adk-0.4.4.dist-info/RECORD +0 -152
  189. {moai_adk-0.4.4.dist-info → moai_adk-0.4.7.dist-info}/WHEEL +0 -0
  190. {moai_adk-0.4.4.dist-info → moai_adk-0.4.7.dist-info}/entry_points.txt +0 -0
  191. {moai_adk-0.4.4.dist-info → moai_adk-0.4.7.dist-info}/licenses/LICENSE +0 -0
@@ -1,62 +1,992 @@
1
- # Alfred TUI Survey Examples
1
+ # TUI Survey Examples - Real-World Scenarios
2
2
 
3
- ## Single-select template
3
+ This document provides complete, production-ready examples of TUI surveys across common MoAI-ADK workflows.
4
+
5
+ _Last updated: 2025-10-22_
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Competition Completion Page](#example-1-competition-completion-page)
12
+ 2. [State Management Library Selection](#example-2-state-management-library-selection)
13
+ 3. [Auth System Refactor](#example-3-auth-system-refactor)
14
+ 4. [Feature Approval Workflow](#example-4-feature-approval-workflow)
15
+ 5. [API Design Decision](#example-5-api-design-decision)
16
+ 6. [Database Migration Strategy](#example-6-database-migration-strategy)
17
+ 7. [Testing Framework Selection](#example-7-testing-framework-selection)
18
+ 8. [Performance Optimization](#example-8-performance-optimization)
19
+
20
+ ---
21
+
22
+ ## Example 1: Competition Completion Page
23
+
24
+ ### Context
25
+
26
+ **User Request**: "Competition is over. Add a completion page."
27
+
28
+ **Current State**:
29
+ - Existing `/end` page (authentication required, shows results)
30
+ - No public completion page exists
31
+ - Need to communicate competition closure to all visitors
32
+
33
+ ### Phase 1: Codebase Analysis
34
+
35
+ ```typescript
36
+ // Alfred analyzes existing code
37
+ const endPageAnalysis = await Read("/app/end/page.tsx");
38
+
39
+ // Analysis results:
40
+ // - Next.js App Router
41
+ // - Requires authentication
42
+ // - Shows competition results
43
+ // - No environment-based gating
44
+ ```
45
+
46
+ ### Phase 2: Interactive Survey
47
+
48
+ **Question 1: Implementation Approach**
49
+
50
+ ```typescript
51
+ AskUserQuestion({
52
+ questions: [
53
+ {
54
+ question: "How should the completion page be implemented?",
55
+ header: "Approach",
56
+ multiSelect: false,
57
+ options: [
58
+ {
59
+ label: "Create new public page (/competition-closed)",
60
+ description: "Unguarded route visible to all visitors, no authentication required. Clean separation from existing /end page."
61
+ },
62
+ {
63
+ label: "Modify existing /end page with conditional logic",
64
+ description: "Add competition status check, redirect to completion message if inactive. Reuses existing route structure."
65
+ },
66
+ {
67
+ label: "Use environment-based gating",
68
+ description: "Set NEXT_PUBLIC_COMPETITION_CLOSED=true, redirect all traffic. Runtime configuration."
69
+ }
70
+ ]
71
+ }
72
+ ]
73
+ })
74
+ ```
75
+
76
+ **User Selection**: "Create new public page (/competition-closed)"
77
+
78
+ **Question 2: User Behavior**
79
+
80
+ ```typescript
81
+ AskUserQuestion({
82
+ questions: [
83
+ {
84
+ question: "For logged-in participants accessing the new page, what should they see?",
85
+ header: "UX",
86
+ multiSelect: false,
87
+ options: [
88
+ {
89
+ label: "Show submission history",
90
+ description: "Redirect authenticated users to /end page, display full results and timeline."
91
+ },
92
+ {
93
+ label: "Show simple completion message only",
94
+ description: "Display 'Competition concluded' notice without historical data. Consistent experience for all users."
95
+ },
96
+ {
97
+ label: "Custom behavior based on user role",
98
+ description: "Different experience per role (admin/participants/visitors)."
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ })
104
+ ```
105
+
106
+ **User Selection**: "Show simple completion message only"
107
+
108
+ ### Phase 3: Review & Confirmation
109
+
110
+ ```
111
+ Summary:
112
+ ✓ Implementation: New public page (/competition-closed)
113
+ ✓ User experience: Simple completion message for all users
114
+
115
+ Ready to proceed?
116
+ ```
117
+
118
+ **User Selection**: "Approve and execute"
119
+
120
+ ### Phase 4: Execution
121
+
122
+ ```typescript
123
+ // /app/competition-closed/page.tsx
124
+ export const metadata = {
125
+ title: "Competition Closed",
126
+ description: "This competition has concluded"
127
+ };
128
+
129
+ export default function CompetitionClosedPage() {
130
+ return (
131
+ <div className="flex min-h-screen items-center justify-center">
132
+ <div className="max-w-md text-center">
133
+ <h1 className="text-3xl font-bold">Competition Concluded</h1>
134
+ <p className="mt-4 text-muted-foreground">
135
+ Thank you for your interest. This competition has ended.
136
+ </p>
137
+ <p className="mt-2 text-sm">
138
+ Check back soon for future opportunities!
139
+ </p>
140
+ </div>
141
+ </div>
142
+ );
143
+ }
144
+ ```
145
+
146
+ ### Outcome
147
+
148
+ ✅ Clean implementation matching user specifications
149
+ ✅ No guessing or ambiguity
150
+ ✅ Direct execution based on confirmed choices
151
+ ✅ Simple public route with consistent UX
152
+
153
+ ---
154
+
155
+ ## Example 2: State Management Library Selection
156
+
157
+ ### Context
158
+
159
+ **User Request**: "Add state management to the application."
160
+
161
+ **Current State**:
162
+ - React 18.x application
163
+ - No existing state management library
164
+ - Component prop drilling in 12+ files
165
+ - Need centralized state for user auth, theme, settings
166
+
167
+ ### Phase 1: Codebase Analysis
168
+
169
+ ```typescript
170
+ const analysis = {
171
+ framework: "React 18.3.1",
172
+ propDrillingDepth: 4,
173
+ stateComplexity: "Medium",
174
+ teamPreference: null
175
+ };
176
+ ```
177
+
178
+ ### Phase 2: Interactive Survey
179
+
180
+ **Question 1: Library Selection**
181
+
182
+ ```typescript
183
+ AskUserQuestion({
184
+ questions: [
185
+ {
186
+ question: "Which state management library should be used?",
187
+ header: "Library",
188
+ multiSelect: false,
189
+ options: [
190
+ {
191
+ label: "Redux Toolkit (v2.x)",
192
+ description: "Industry standard with extensive ecosystem. DevTools support, middleware. PRO: Battle-tested. CON: More boilerplate."
193
+ },
194
+ {
195
+ label: "Zustand (v5.x)",
196
+ description: "Modern, minimalist state management. Simple API with hooks. PRO: Minimal boilerplate. CON: Fewer resources."
197
+ },
198
+ {
199
+ label: "Jotai (v2.x)",
200
+ description: "Atomic state management. Fine-grained reactivity. PRO: Granular updates. CON: Paradigm shift."
201
+ },
202
+ {
203
+ label: "Context API + useReducer (built-in)",
204
+ description: "React's built-in solution. PRO: Zero dependencies. CON: Performance concerns."
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ })
210
+ ```
211
+
212
+ **User Selection**: "Zustand (v5.x)"
213
+
214
+ **Question 2: Store Structure**
215
+
216
+ ```typescript
217
+ AskUserQuestion({
218
+ questions: [
219
+ {
220
+ question: "How should the Zustand store be structured?",
221
+ header: "Structure",
222
+ multiSelect: false,
223
+ options: [
224
+ {
225
+ label: "Single global store",
226
+ description: "All state in one store. Simple to reason about."
227
+ },
228
+ {
229
+ label: "Multiple domain stores",
230
+ description: "Separate stores per domain (useAuthStore, useThemeStore, useSettingsStore). Clear separation."
231
+ },
232
+ {
233
+ label: "Hybrid (global + domain-specific)",
234
+ description: "Core state in global store, specialized logic in domain stores."
235
+ }
236
+ ]
237
+ }
238
+ ]
239
+ })
240
+ ```
241
+
242
+ **User Selection**: "Multiple domain stores"
243
+
244
+ **Question 3: Persistence**
245
+
246
+ ```typescript
247
+ AskUserQuestion({
248
+ questions: [
249
+ {
250
+ question: "Which state should be persisted to localStorage?",
251
+ header: "Persistence",
252
+ multiSelect: true,
253
+ options: [
254
+ {
255
+ label: "Authentication state",
256
+ description: "Persist user session, tokens. Resume logged-in state."
257
+ },
258
+ {
259
+ label: "Theme preferences",
260
+ description: "Persist dark/light mode selection."
261
+ },
262
+ {
263
+ label: "User settings",
264
+ description: "Persist app configuration (language, notifications)."
265
+ },
266
+ {
267
+ label: "None (session-only)",
268
+ description: "Don't persist any state."
269
+ }
270
+ ]
271
+ }
272
+ ]
273
+ })
274
+ ```
275
+
276
+ **User Selections**: ["Theme preferences", "User settings"]
277
+
278
+ ### Phase 3: Execution
279
+
280
+ ```typescript
281
+ // stores/theme.ts
282
+ import { create } from 'zustand';
283
+ import { persist } from 'zustand/middleware';
284
+
285
+ interface ThemeState {
286
+ theme: 'light' | 'dark';
287
+ setTheme: (theme: 'light' | 'dark') => void;
288
+ toggleTheme: () => void;
289
+ }
290
+
291
+ export const useThemeStore = create<ThemeState>()(
292
+ persist(
293
+ (set) => ({
294
+ theme: 'light',
295
+ setTheme: (theme) => set({ theme }),
296
+ toggleTheme: () => set((state) => ({
297
+ theme: state.theme === 'light' ? 'dark' : 'light'
298
+ }))
299
+ }),
300
+ {
301
+ name: 'theme-storage'
302
+ }
303
+ )
304
+ );
305
+
306
+ // stores/settings.ts
307
+ interface SettingsState {
308
+ language: string;
309
+ notifications: boolean;
310
+ setLanguage: (language: string) => void;
311
+ toggleNotifications: () => void;
312
+ }
313
+
314
+ export const useSettingsStore = create<SettingsState>()(
315
+ persist(
316
+ (set) => ({
317
+ language: 'en',
318
+ notifications: true,
319
+ setLanguage: (language) => set({ language }),
320
+ toggleNotifications: () => set((state) => ({
321
+ notifications: !state.notifications
322
+ }))
323
+ }),
324
+ {
325
+ name: 'settings-storage'
326
+ }
327
+ )
328
+ );
329
+
330
+ // stores/auth.ts (no persistence)
331
+ interface AuthState {
332
+ user: User | null;
333
+ isAuthenticated: boolean;
334
+ login: (user: User) => void;
335
+ logout: () => void;
336
+ }
337
+
338
+ export const useAuthStore = create<AuthState>((set) => ({
339
+ user: null,
340
+ isAuthenticated: false,
341
+ login: (user) => set({ user, isAuthenticated: true }),
342
+ logout: () => set({ user: null, isAuthenticated: false })
343
+ }));
344
+ ```
345
+
346
+ ### Outcome
347
+
348
+ ✅ Zustand v5.x with minimal boilerplate
349
+ ✅ Three domain-specific stores
350
+ ✅ Selective persistence (theme + settings, not auth)
351
+ ✅ Type-safe TypeScript implementation
352
+ ✅ Exact match to user specifications
353
+
354
+ ---
355
+
356
+ ## Example 3: Auth System Refactor
357
+
358
+ ### Context
359
+
360
+ **User Request**: "Refactor the auth system to use JWT instead of sessions."
361
+
362
+ **Current State**:
363
+ - Session-based authentication (Express + Redis)
364
+ - 20+ routes depend on session middleware
365
+ - ~500 active users in production
366
+ - No JWT infrastructure exists
367
+
368
+ ### Risk Assessment
369
+
370
+ ```typescript
371
+ const riskAnalysis = {
372
+ activeUsers: 500,
373
+ dependentRoutes: 23,
374
+ currentUptime: "99.2%",
375
+ rollbackComplexity: "High",
376
+ estimatedDowntime: "2-4 hours (big bang) or 0 minutes (incremental)"
377
+ };
378
+ ```
379
+
380
+ ### Interactive Survey
381
+
382
+ **Question 1: Migration Strategy**
383
+
384
+ ```typescript
385
+ AskUserQuestion({
386
+ questions: [
387
+ {
388
+ question: "What migration strategy should be used for the auth refactor?",
389
+ header: "Strategy",
390
+ multiSelect: false,
391
+ options: [
392
+ {
393
+ label: "Big bang migration (full rewrite)",
394
+ description: "Complete replacement in one deployment. Timeline: 2-3 weeks. Risk: High (downtime, all users logged out)."
395
+ },
396
+ {
397
+ label: "Incremental migration with feature flags",
398
+ description: "Gradual rollout per route. Timeline: 4-6 weeks. Risk: Medium (code duplication)."
399
+ },
400
+ {
401
+ label: "Parallel run with adapter pattern",
402
+ description: "Support both methods simultaneously. Timeline: 6-8 weeks. Risk: Low (safe rollback, zero downtime)."
403
+ }
404
+ ]
405
+ }
406
+ ]
407
+ })
408
+ ```
409
+
410
+ **User Selection**: "Parallel run with adapter pattern"
411
+
412
+ **Question 2: JWT Configuration**
413
+
414
+ ```typescript
415
+ AskUserQuestion({
416
+ questions: [
417
+ {
418
+ question: "How should JWT tokens be configured?",
419
+ header: "JWT Config",
420
+ multiSelect: false,
421
+ options: [
422
+ {
423
+ label: "Short-lived access tokens only (15 min)",
424
+ description: "Single token type. Simple but requires frequent logins."
425
+ },
426
+ {
427
+ label: "Access + refresh tokens (15 min + 7 days)",
428
+ description: "Access token for requests, refresh for renewal. Standard approach, better UX."
429
+ },
430
+ {
431
+ label: "Long-lived access tokens (24 hours)",
432
+ description: "Extended lifespan, no refresh tokens. Simplified but less secure."
433
+ }
434
+ ]
435
+ }
436
+ ]
437
+ })
438
+ ```
439
+
440
+ **User Selection**: "Access + refresh tokens (15 min + 7 days)"
441
+
442
+ **Question 3: Rollout Plan**
443
+
444
+ ```typescript
445
+ AskUserQuestion({
446
+ questions: [
447
+ {
448
+ question: "What rollout percentage should be used for JWT migration?",
449
+ header: "Rollout",
450
+ multiSelect: false,
451
+ options: [
452
+ {
453
+ label: "Canary (5% → 25% → 50% → 100%)",
454
+ description: "Gradual rollout over 4 weeks with monitoring. Safest approach."
455
+ },
456
+ {
457
+ label: "Blue-Green (0% → 100%)",
458
+ description: "Full cutover after parallel testing. Faster but higher risk."
459
+ },
460
+ {
461
+ label: "Opt-in beta (users choose)",
462
+ description: "Users voluntarily test JWT auth. Slowest but zero forced risk."
463
+ }
464
+ ]
465
+ }
466
+ ]
467
+ })
468
+ ```
469
+
470
+ **User Selection**: "Canary (5% → 25% → 50% → 100%)"
471
+
472
+ ### Execution
473
+
474
+ ```typescript
475
+ // lib/auth/adapter.ts
476
+ export class AuthAdapter {
477
+ private sessionAuth: SessionAuthHandler;
478
+ private jwtAuth: JWTAuthHandler;
479
+ private rolloutPercentage: number;
480
+
481
+ async authenticate(req: Request): Promise<User | null> {
482
+ const useJWT = this.shouldUseJWT(req);
483
+
484
+ if (useJWT) {
485
+ return this.jwtAuth.authenticate(req);
486
+ } else {
487
+ return this.sessionAuth.authenticate(req);
488
+ }
489
+ }
490
+
491
+ private shouldUseJWT(req: Request): boolean {
492
+ // Sticky session: once JWT, always JWT
493
+ if (req.cookies.auth_method === 'jwt') return true;
494
+
495
+ // Gradual rollout based on user ID hash
496
+ const userId = req.session?.userId;
497
+ if (!userId) return false;
498
+
499
+ const hash = hashUserId(userId);
500
+ return (hash % 100) < this.rolloutPercentage;
501
+ }
502
+ }
503
+
504
+ // Rollout schedule (via environment variable)
505
+ // Week 1-2: ROLLOUT_PERCENTAGE=5
506
+ // Week 3-4: ROLLOUT_PERCENTAGE=25
507
+ // Week 5-6: ROLLOUT_PERCENTAGE=50
508
+ // Week 7-8: ROLLOUT_PERCENTAGE=100
509
+ ```
510
+
511
+ ### Outcome
512
+
513
+ ✅ Parallel auth system with adapter pattern
514
+ ✅ Zero downtime migration over 6-8 weeks
515
+ ✅ Safe rollback at any stage
516
+ ✅ Canary deployment with monitoring
517
+ ✅ Access (15 min) + refresh (7 days) tokens
518
+ ✅ Matches confirmed risk tolerance
519
+
520
+ ---
521
+
522
+ ## Example 4: Feature Approval Workflow
523
+
524
+ ### Context
525
+
526
+ **User Request**: "Clean up unused files from the last refactor."
527
+
528
+ **Current State**:
529
+ - 50 files not referenced in codebase (last modified >6 months ago)
530
+ - Files include: deprecated components, old test fixtures, legacy utils
531
+ - Risk: some files may be dynamically imported or used in scripts
532
+
533
+ ### Phase 1: Analysis & Backup
534
+
535
+ ```typescript
536
+ const unusedFiles = [
537
+ "/src/components/deprecated/OldButton.tsx",
538
+ "/src/utils/legacy/formatter.ts",
539
+ // ... 48 more files
540
+ ];
541
+
542
+ // Create backup
543
+ await Bash("git checkout -b backup/pre-cleanup-2025-10-22");
544
+ await Bash("tar -czf .moai-backups/pre-cleanup-$(date +%Y%m%d).tar.gz src/");
545
+ ```
546
+
547
+ ### Phase 2: Approval Survey
4
548
 
5
549
  ```typescript
6
550
  AskUserQuestion({
7
- questions: [{
8
- header: "Decision point: Deployment Strategy",
9
- question: "How should we roll out the new release?",
10
- options: [
11
- {
12
- label: "Canary release",
13
- description: "Gradually roll out to a small user segment; monitor metrics first."
14
- },
15
- {
16
- label: "Blue/Green",
17
- description: "Keep the current version live while preparing the new stack in parallel."
18
- },
19
- {
20
- label: "Full deploy",
21
- description: "Immediate production rollout after smoke tests succeed."
22
- }
23
- ],
24
- multiSelect: false
25
- }]
551
+ questions: [
552
+ {
553
+ question: "50 unused files identified. Review and approve deletion?",
554
+ header: "Cleanup",
555
+ multiSelect: false,
556
+ options: [
557
+ {
558
+ label: "Show file list first",
559
+ description: "Display all 50 files before deciding. Manual review of each path."
560
+ },
561
+ {
562
+ label: "Approve and execute cleanup",
563
+ description: "Delete all 50 files immediately. Backup created. Reversible via Git."
564
+ },
565
+ {
566
+ label: "Approve deletion for specific directories only",
567
+ description: "Select directories to clean. Partial cleanup with directory-level control."
568
+ },
569
+ {
570
+ label: "Cancel operation",
571
+ description: "Abort cleanup, keep all files."
572
+ }
573
+ ]
574
+ }
575
+ ]
26
576
  })
27
577
  ```
28
578
 
29
- ## Multi-select variation
579
+ **User Selection**: "Show file list first"
580
+
581
+ ### Phase 3: Detailed Review
30
582
 
31
583
  ```typescript
584
+ const filesByCategory = {
585
+ "Deprecated Components (15 files)": [
586
+ "/src/components/deprecated/OldButton.tsx",
587
+ "/src/components/deprecated/LegacyModal.tsx",
588
+ // ... 13 more
589
+ ],
590
+ "Legacy Utilities (20 files)": [
591
+ "/src/utils/legacy/formatter.ts",
592
+ "/src/utils/legacy/validator.ts",
593
+ // ... 18 more
594
+ ],
595
+ "Old Test Fixtures (15 files)": [
596
+ "/tests/fixtures/old-data.json",
597
+ "/tests/fixtures/deprecated-mock.ts",
598
+ // ... 13 more
599
+ ]
600
+ };
601
+
602
+ // Follow-up survey
32
603
  AskUserQuestion({
33
- questions: [{
34
- header: "Select diagnostics to run",
35
- question: "Which checks should run before proceeding?",
36
- options: [
37
- { label: "Unit tests", description: "Fast verification for core modules." },
38
- { label: "Integration tests", description: "Service-level interactions and DB calls." },
39
- { label: "Security scan", description: "Dependency vulnerability audit." }
40
- ],
41
- multiSelect: true
42
- }]
604
+ questions: [
605
+ {
606
+ question: "Which categories should be cleaned up?",
607
+ header: "Categories",
608
+ multiSelect: true,
609
+ options: [
610
+ {
611
+ label: "Deprecated Components (15 files)",
612
+ description: "Remove old UI components no longer used."
613
+ },
614
+ {
615
+ label: "Legacy Utilities (20 files)",
616
+ description: "Remove utility functions replaced by modern alternatives."
617
+ },
618
+ {
619
+ label: "Old Test Fixtures (15 files)",
620
+ description: "Remove outdated test data and mocks."
621
+ }
622
+ ]
623
+ }
624
+ ]
43
625
  })
44
626
  ```
45
627
 
46
- ## Follow-up prompt for deeper detail
628
+ **User Selections**: ["Deprecated Components (15 files)", "Old Test Fixtures (15 files)"]
629
+
630
+ ### Phase 4: Execution
631
+
632
+ ```typescript
633
+ const filesToDelete = [
634
+ ...filesByCategory["Deprecated Components (15 files)"],
635
+ ...filesByCategory["Old Test Fixtures (15 files)"]
636
+ ];
637
+
638
+ for (const file of filesToDelete) {
639
+ await Bash(`rm ${file}`);
640
+ }
641
+
642
+ await Bash(`git add -A && git commit -m "chore: remove deprecated components and test fixtures
643
+
644
+ - Deleted 15 deprecated component files
645
+ - Deleted 15 old test fixture files
646
+ - Preserved 20 legacy utility files for gradual migration
647
+ - Backup available at .moai-backups/pre-cleanup-2025-10-22.tar.gz
648
+
649
+ Refs: cleanup-2025-10-22"`);
650
+ ```
651
+
652
+ ### Outcome
653
+
654
+ ✅ 30 files deleted (selective cleanup)
655
+ ✅ 20 files preserved (user decision)
656
+ ✅ Complete backup and Git branch for rollback
657
+ ✅ User had full control and visibility
658
+ ✅ Explicit approval before destructive operation
659
+
660
+ ---
661
+
662
+ ## Example 5: API Design Decision
663
+
664
+ ### Context
665
+
666
+ **User Request**: "Add pagination to the /api/posts endpoint."
667
+
668
+ **Current State**:
669
+ - Endpoint returns all posts (currently 200, growing to 1000+)
670
+ - No pagination implemented
671
+ - Frontend expects array of posts
672
+
673
+ ### Interactive Survey
47
674
 
48
675
  ```typescript
49
- if (selection.includes("Integration tests")) {
50
- AskUserQuestion({
51
- questions: [{
52
- header: "Integration test scope",
53
- question: "Which environment should host integration tests?",
676
+ AskUserQuestion({
677
+ questions: [
678
+ {
679
+ question: "Which pagination strategy should be used?",
680
+ header: "Pagination",
681
+ multiSelect: false,
682
+ options: [
683
+ {
684
+ label: "Offset-based (?page=1&limit=20)",
685
+ description: "Traditional page numbers. Simple, familiar. CON: Performance degrades with large offsets."
686
+ },
687
+ {
688
+ label: "Cursor-based (?cursor=abc123&limit=20)",
689
+ description: "Use cursor (e.g., last post ID). Better performance, consistent results. CON: No random page access."
690
+ },
691
+ {
692
+ label: "Hybrid (offset + cursor fallback)",
693
+ description: "Offset for first 100 pages, cursor thereafter. Balances UX and performance. CON: Complex."
694
+ }
695
+ ]
696
+ },
697
+ {
698
+ question: "Should the API return pagination metadata?",
699
+ header: "Metadata",
700
+ multiSelect: true,
54
701
  options: [
55
- { label: "Staging", description: "Use the shared staging cluster." },
56
- { label: "Ephemeral env", description: "Provision a one-off test environment." }
57
- ],
58
- multiSelect: false
59
- }]
60
- })
702
+ {
703
+ label: "Total count",
704
+ description: "Include total number of posts. Allows 'Page X of Y'. Warning: COUNT(*) slow on large tables."
705
+ },
706
+ {
707
+ label: "Has next/previous flags",
708
+ description: "Boolean flags indicating more data. Efficient, no COUNT() needed."
709
+ },
710
+ {
711
+ label: "Next/previous page URLs",
712
+ description: "Full URLs (HATEOAS). Self-documenting but larger response."
713
+ }
714
+ ]
715
+ }
716
+ ]
717
+ })
718
+ ```
719
+
720
+ **User Selections**:
721
+ - Pagination: "Cursor-based (?cursor=abc123&limit=20)"
722
+ - Metadata: ["Has next/previous flags", "Next/previous page URLs"]
723
+
724
+ ### Execution
725
+
726
+ ```typescript
727
+ // GET /api/posts?cursor=abc123&limit=20
728
+ {
729
+ "data": [...],
730
+ "pagination": {
731
+ "hasNext": true,
732
+ "hasPrevious": true,
733
+ "nextUrl": "/api/posts?cursor=def456&limit=20",
734
+ "previousUrl": "/api/posts?cursor=xyz789&limit=20"
735
+ }
61
736
  }
62
737
  ```
738
+
739
+ ---
740
+
741
+ ## Example 6: Database Migration Strategy
742
+
743
+ ### Context
744
+
745
+ **User Request**: "Add full-text search to the posts table."
746
+
747
+ **Current State**:
748
+ - PostgreSQL 15.x database
749
+ - 500k rows in posts table
750
+ - Production database (24/7 availability required)
751
+
752
+ ### Interactive Survey
753
+
754
+ ```typescript
755
+ AskUserQuestion({
756
+ questions: [
757
+ {
758
+ question: "Which full-text search implementation should be used?",
759
+ header: "Search",
760
+ multiSelect: false,
761
+ options: [
762
+ {
763
+ label: "PostgreSQL GIN index with tsvector",
764
+ description: "Native Postgres full-text search. PRO: No external dependencies. CON: Less flexible than dedicated engines."
765
+ },
766
+ {
767
+ label: "PostgreSQL pg_trgm (trigram) index",
768
+ description: "Fuzzy matching with trigrams. PRO: Typo-tolerant. CON: Higher storage overhead."
769
+ },
770
+ {
771
+ label: "External search engine (Elasticsearch/Meilisearch)",
772
+ description: "Dedicated search service. PRO: Advanced features. CON: Operational overhead, data sync."
773
+ }
774
+ ]
775
+ },
776
+ {
777
+ question: "How should the index be created on production?",
778
+ header: "Migration",
779
+ multiSelect: false,
780
+ options: [
781
+ {
782
+ label: "Online with CONCURRENTLY (zero downtime)",
783
+ description: "CREATE INDEX CONCURRENTLY allows reads/writes during creation. Duration: ~2-4 hours. Risk: Low."
784
+ },
785
+ {
786
+ label: "Offline during maintenance window",
787
+ description: "Scheduled downtime. Duration: ~30-60 minutes. Risk: Medium (unavailable)."
788
+ },
789
+ {
790
+ label: "Blue-green deployment with replica",
791
+ description: "Create index on replica, promote to primary. Duration: ~1 hour prep + instant cutover. Risk: Low but complex."
792
+ }
793
+ ]
794
+ }
795
+ ]
796
+ })
797
+ ```
798
+
799
+ **User Selections**:
800
+ - Implementation: "PostgreSQL GIN index with tsvector"
801
+ - Migration: "Online with CONCURRENTLY (zero downtime)"
802
+
803
+ ### Execution
804
+
805
+ ```sql
806
+ -- Migration: add_fulltext_search_to_posts.sql
807
+
808
+ -- Step 1: Add tsvector column
809
+ ALTER TABLE posts
810
+ ADD COLUMN search_vector tsvector;
811
+
812
+ -- Step 2: Populate search_vector (batched)
813
+ UPDATE posts
814
+ SET search_vector = to_tsvector('english', title || ' ' || content)
815
+ WHERE id BETWEEN 1 AND 100000;
816
+
817
+ -- Step 3: Create GIN index (CONCURRENTLY = zero downtime)
818
+ CREATE INDEX CONCURRENTLY idx_posts_search_vector
819
+ ON posts USING GIN(search_vector);
820
+
821
+ -- Step 4: Add trigger to keep search_vector updated
822
+ CREATE TRIGGER posts_search_vector_update
823
+ BEFORE INSERT OR UPDATE ON posts
824
+ FOR EACH ROW EXECUTE FUNCTION
825
+ tsvector_update_trigger(search_vector, 'pg_catalog.english', title, content);
826
+ ```
827
+
828
+ ---
829
+
830
+ ## Example 7: Testing Framework Selection
831
+
832
+ ### Context
833
+
834
+ **User Request**: "Set up testing for the React application."
835
+
836
+ **Current State**:
837
+ - React 18.x + TypeScript
838
+ - No tests exist yet
839
+ - Need unit tests, component tests, and E2E tests
840
+
841
+ ### Interactive Survey
842
+
843
+ ```typescript
844
+ AskUserQuestion({
845
+ questions: [
846
+ {
847
+ question: "Which unit/component testing framework should be used?",
848
+ header: "Test FW",
849
+ multiSelect: false,
850
+ options: [
851
+ {
852
+ label: "Vitest + React Testing Library",
853
+ description: "Modern, fast test runner with native ESM. PRO: Fastest execution. CON: Newer ecosystem."
854
+ },
855
+ {
856
+ label: "Jest + React Testing Library",
857
+ description: "Industry standard. PRO: Mature, many resources. CON: Slower, ESM issues."
858
+ },
859
+ {
860
+ label: "Vitest + Playwright component testing",
861
+ description: "Hybrid with real browser testing. PRO: True browser environment. CON: Slower, complex setup."
862
+ }
863
+ ]
864
+ },
865
+ {
866
+ question: "Which E2E testing tool should be used?",
867
+ header: "E2E Tool",
868
+ multiSelect: false,
869
+ options: [
870
+ {
871
+ label: "Playwright",
872
+ description: "Modern E2E framework. PRO: Fast, reliable, trace viewer. CON: Node-only API."
873
+ },
874
+ {
875
+ label: "Cypress",
876
+ description: "Popular E2E tool. PRO: Great docs, visual testing. CON: Slower than Playwright."
877
+ },
878
+ {
879
+ label: "None (unit/component tests only)",
880
+ description: "Skip E2E initially. PRO: Faster setup. CON: No full user flow coverage."
881
+ }
882
+ ]
883
+ }
884
+ ]
885
+ })
886
+ ```
887
+
888
+ **User Selections**:
889
+ - Unit/Component: "Vitest + React Testing Library"
890
+ - E2E: "Playwright"
891
+
892
+ ---
893
+
894
+ ## Example 8: Performance Optimization
895
+
896
+ ### Context
897
+
898
+ **User Request**: "The dashboard is loading slowly."
899
+
900
+ **Current State**:
901
+ - Dashboard loads in 4-5 seconds
902
+ - Multiple data fetches on mount
903
+ - Large bundle size (500KB)
904
+ - No profiling data yet
905
+
906
+ ### Interactive Survey
907
+
908
+ ```typescript
909
+ AskUserQuestion({
910
+ questions: [
911
+ {
912
+ question: "What is the primary optimization goal?",
913
+ header: "Goal",
914
+ multiSelect: false,
915
+ options: [
916
+ {
917
+ label: "Reduce initial load time",
918
+ description: "Focus on bundle size, code splitting, lazy loading. Target: <2s to interactive."
919
+ },
920
+ {
921
+ label: "Reduce time to first data",
922
+ description: "Optimize API requests, implement caching, parallel fetches. Target: <1s to first content."
923
+ },
924
+ {
925
+ label: "Improve perceived performance",
926
+ description: "Add loading states, skeleton screens, progressive rendering. Target: instant visual feedback."
927
+ }
928
+ ]
929
+ },
930
+ {
931
+ question: "Which optimization techniques should be applied?",
932
+ header: "Techniques",
933
+ multiSelect: true,
934
+ options: [
935
+ {
936
+ label: "Code splitting + lazy loading",
937
+ description: "Split dashboard into chunks, load on demand. Impact: -200KB initial bundle."
938
+ },
939
+ {
940
+ label: "Data fetching optimization",
941
+ description: "Parallel requests, caching, React Query. Impact: -2s load time."
942
+ },
943
+ {
944
+ label: "Image optimization",
945
+ description: "WebP format, responsive images, lazy loading. Impact: -100KB assets."
946
+ },
947
+ {
948
+ label: "Memo/useMemo for expensive renders",
949
+ description: "Prevent unnecessary re-renders. Impact: smoother interactions."
950
+ }
951
+ ]
952
+ }
953
+ ]
954
+ })
955
+ ```
956
+
957
+ **User Selections**:
958
+ - Goal: "Reduce initial load time"
959
+ - Techniques: ["Code splitting + lazy loading", "Data fetching optimization"]
960
+
961
+ ---
962
+
963
+ ## Best Practices Summary
964
+
965
+ ### Effective TUI Surveys:
966
+
967
+ 1. **Analyze first**: Examine codebase context before presenting options
968
+ 2. **Limit options**: 2-4 choices per question (avoid decision fatigue)
969
+ 3. **Show trade-offs**: PRO/CON, effort, risk for each option
970
+ 4. **Allow "Other"**: Provide escape hatch for custom input
971
+ 5. **Review before execution**: Summary step with "Go back" option
972
+ 6. **Context is key**: Include current state, constraints, implications
973
+
974
+ ### Common Patterns:
975
+
976
+ - **Architectural decisions**: Present 3 approaches with trade-offs
977
+ - **Technical choices**: Show maturity, ecosystem, pros/cons
978
+ - **Migration strategies**: Include timeline, risk, rollback plan
979
+ - **Approval workflows**: Show impact, backup plan, reversibility
980
+
981
+ ### Integration with MoAI Workflow:
982
+
983
+ - **Plan phase**: Scope clarification, EARS pattern selection
984
+ - **Run phase**: Library selection, implementation approach
985
+ - **Sync phase**: Documentation format, merge strategy
986
+
987
+ ---
988
+
989
+ **Examples Count**: 8 complete scenarios
990
+ **Total Lines**: 850+
991
+ **Coverage**: Architecture, libraries, refactoring, approvals, API design, databases, testing, performance
992
+ **Last Updated**: 2025-10-22