@anhth2/spec-driven-dev-plugin 0.6.0 → 0.8.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.
Files changed (86) hide show
  1. package/bin/index.js +285 -11
  2. package/commands/debug.md +233 -11
  3. package/commands/debug.tmpl +170 -6
  4. package/commands/define-product.md +68 -6
  5. package/commands/define-product.tmpl +5 -1
  6. package/commands/fix-bug.md +111 -11
  7. package/commands/fix-bug.tmpl +48 -6
  8. package/commands/generate-bdd.md +86 -9
  9. package/commands/generate-bdd.tmpl +23 -4
  10. package/commands/generate-code.md +146 -19
  11. package/commands/generate-code.tmpl +83 -14
  12. package/commands/generate-design-spec.md +754 -0
  13. package/commands/generate-design-spec.tmpl +399 -0
  14. package/commands/generate-prd.md +91 -7
  15. package/commands/generate-prd.tmpl +28 -2
  16. package/commands/generate-spec-manifest.md +519 -0
  17. package/commands/generate-spec-manifest.tmpl +164 -0
  18. package/commands/generate-tech-docs.md +122 -9
  19. package/commands/generate-tech-docs.tmpl +59 -4
  20. package/commands/generate-tests.md +491 -37
  21. package/commands/generate-tests.tmpl +428 -32
  22. package/commands/refine-prd.md +76 -8
  23. package/commands/refine-prd.tmpl +13 -3
  24. package/commands/review-code.md +94 -6
  25. package/commands/review-code.tmpl +31 -1
  26. package/commands/review-context.md +118 -12
  27. package/commands/review-context.tmpl +55 -7
  28. package/commands/review-tech-docs.md +76 -9
  29. package/commands/review-tech-docs.tmpl +13 -4
  30. package/commands/run-tests.md +196 -18
  31. package/commands/run-tests.tmpl +133 -13
  32. package/commands/setup-ai-first.md +192 -6
  33. package/commands/setup-ai-first.tmpl +136 -5
  34. package/commands/smoke-test.md +228 -22
  35. package/commands/smoke-test.tmpl +165 -17
  36. package/commands/validate-traces.md +77 -8
  37. package/commands/validate-traces.tmpl +14 -3
  38. package/core/FRAMEWORK_VERSION +1 -1
  39. package/core/commands/debug.md +233 -11
  40. package/core/commands/define-product.md +68 -6
  41. package/core/commands/fix-bug.md +111 -11
  42. package/core/commands/generate-bdd.md +86 -9
  43. package/core/commands/generate-code.md +146 -19
  44. package/core/commands/generate-design-spec.md +754 -0
  45. package/core/commands/generate-prd.md +91 -7
  46. package/core/commands/generate-spec-manifest.md +519 -0
  47. package/core/commands/generate-tech-docs.md +122 -9
  48. package/core/commands/generate-tests.md +491 -37
  49. package/core/commands/refine-prd.md +76 -8
  50. package/core/commands/review-code.md +94 -6
  51. package/core/commands/review-context.md +118 -12
  52. package/core/commands/review-tech-docs.md +76 -9
  53. package/core/commands/run-tests.md +196 -18
  54. package/core/commands/setup-ai-first.md +192 -6
  55. package/core/commands/smoke-test.md +228 -22
  56. package/core/commands/validate-traces.md +77 -8
  57. package/core/skills/code/SKILL.md +68 -8
  58. package/core/skills/debug/SKILL.md +72 -10
  59. package/core/skills/design-spec/SKILL.md +450 -0
  60. package/core/skills/discovery/SKILL.md +62 -4
  61. package/core/skills/prd/SKILL.md +12 -8
  62. package/core/skills/setup-ai-first/SKILL.md +5 -3
  63. package/core/skills/spec/SKILL.md +11 -7
  64. package/core/skills/test/SKILL.md +130 -12
  65. package/core/steps/context-loader.md +57 -1
  66. package/core/steps/gate.md +1 -1
  67. package/core/steps/report-footer.md +5 -3
  68. package/core/steps/spawn-agent.md +3 -1
  69. package/core/templates/design-spec.template.md +209 -0
  70. package/core/templates/project-context.yaml +29 -0
  71. package/package.json +1 -1
  72. package/skills/code/SKILL.md +68 -8
  73. package/skills/debug/SKILL.md +72 -10
  74. package/skills/design-spec/SKILL.md +450 -0
  75. package/skills/design-spec/SKILL.tmpl +95 -0
  76. package/skills/discovery/SKILL.md +62 -4
  77. package/skills/prd/SKILL.md +12 -8
  78. package/skills/setup-ai-first/SKILL.md +5 -3
  79. package/skills/spec/SKILL.md +11 -7
  80. package/skills/test/SKILL.md +130 -12
  81. package/steps/context-loader.md +57 -1
  82. package/steps/gate.md +1 -1
  83. package/steps/report-footer.md +5 -3
  84. package/steps/spawn-agent.md +3 -1
  85. package/templates/design-spec.template.md +209 -0
  86. package/templates/project-context.yaml +29 -0
@@ -0,0 +1,754 @@
1
+ # /generate-design-spec — Generate Design Specification (FE / App)
2
+
3
+ ## Gate
4
+ # Gate — Universal Entry Procedure
5
+
6
+ Every command must execute this gate before proceeding with its specific logic.
7
+
8
+ ## Step 0 — Sub-Agent Mode Check
9
+
10
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
11
+
12
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
13
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
14
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
15
+ - Set target file = `payload.target_file`
16
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
17
+ - Set UC scope = `payload.uc_id` (process only this UC)
18
+ - Set line range = `payload.uc_section` (read only that PRD section)
19
+ - Proceed directly to the command-specific logic.
20
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
21
+
22
+ ## Step 0-B — Model Check
23
+
24
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
25
+
26
+ Complex generation and review commands require strong reasoning.
27
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
28
+
29
+ Display and wait for response:
30
+
31
+ ```
32
+ ⚙️ MODEL CHECK
33
+ ──────────────────────────────────────────────────────────────────
34
+ Recommended : claude-opus-4 (or latest Opus model)
35
+ Why needed : Spec analysis, architecture review, code generation
36
+ require deep reasoning. Smaller models miss edge cases.
37
+
38
+ To switch in Claude Code:
39
+ • Settings → Model → select "claude-opus"
40
+ • or: /model → choose claude-opus
41
+
42
+ Running on claude-opus?
43
+ Y — yes, on claude-opus → proceed
44
+ S — skip check (I accept lower quality risk with current model)
45
+ ──────────────────────────────────────────────────────────────────
46
+ ```
47
+
48
+ - "Y" → proceed to Step 1.
49
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
50
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
51
+
52
+ ## Step 1 — Resolve Target File
53
+
54
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
55
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
56
+ 3. If `$ARGUMENTS` is empty or no match found:
57
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
58
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
59
+ - Wait for user selection before continuing.
60
+
61
+ ## Step 2 — Execute Context Loader
62
+
63
+ Load all project context by following the procedure in `steps/context-loader.md`.
64
+ Store all loaded context in memory for use throughout this command session.
65
+
66
+ ## Step 3 — CHECKPOINT
67
+
68
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
69
+
70
+ ```
71
+ CHECKPOINT
72
+ -----------
73
+ Target : {resolved file path}
74
+ Project : {project.name from project-context.yaml}
75
+ Tech stack : {language} / {framework}
76
+ Module : {module if set, else "not configured"}
77
+ Domains : {comma-separated domain list}
78
+
79
+ Proceed? (Y/N)
80
+ ```
81
+
82
+ Wait for explicit "Y" or "N" from the user before continuing.
83
+ - "Y" → proceed to the command-specific steps below.
84
+ - "N" → stop and ask what the user wants to change.
85
+
86
+
87
+ *Note: For this command, the target file is a Business PRD in `{paths.prd_dir}/`. Resolve from `$ARGUMENTS` or list the directory and ask. Only FE and mobile PRDs are supported — BE PRDs will be rejected at the Platform Check step.*
88
+
89
+ ## Context
90
+ # Context Loader — Load All Project Context
91
+
92
+ Execute these steps in order. Store everything in memory for the duration of the command session.
93
+
94
+ **Priority guide (anti-lost-in-middle):**
95
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
96
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
97
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
98
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
99
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
100
+
101
+ ---
102
+
103
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
104
+
105
+ Read `.agent/project-context.yaml`. Extract and store:
106
+
107
+ **Tech Stack:**
108
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
109
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
110
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
111
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
112
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
113
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
114
+
115
+ **Conventions:**
116
+ - `conventions.build_command` → how to compile/build
117
+ - `conventions.test_command` → how to run tests
118
+ - `conventions.service_run` → how to start the service
119
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
120
+
121
+ **Domains:**
122
+ - `domains` → list of active business domains
123
+
124
+ **Paths (if present):**
125
+ - `paths.specs_dir` → BDD specs root
126
+ - `paths.prd_dir` → PRD documents root
127
+ - `paths.refinement_dir` → findings/review output dir
128
+ - `paths.product_definitions_dir` → product definitions root
129
+ - `paths.domain_knowledge_dir` → domain knowledge root
130
+ - `paths.business_dictionary` → path to business-dictionary.md
131
+ - `paths.core_entities` → path to core-entities.md
132
+ - `paths.tech_docs_dir` → technical documentation root
133
+ - `paths.trace_dir` → trace state directory
134
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
135
+
136
+ If `paths` section is absent, use these defaults:
137
+ - `specs_dir` = `specs/bdd`
138
+ - `prd_dir` = `specs/prd`
139
+ - `refinement_dir` = `.agent/review`
140
+ - `product_definitions_dir` = `specs/product-definition`
141
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
142
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
143
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
144
+ - `tech_docs_dir` = `specs/tech-docs`
145
+ - `trace_dir` = `.trace`
146
+ - `design_spec_dir` = `specs/design-spec`
147
+
148
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
149
+
150
+ ---
151
+
152
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
153
+
154
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
155
+
156
+ If `services` section is present:
157
+
158
+ **1. Detect active domain** (in priority order):
159
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
160
+ - Extract from target file path: segment immediately after `prd_dir` base path
161
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
162
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
163
+
164
+ **2. Route to service** — if active domain matches a key in `services`:
165
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
166
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
167
+ - Store `active_service` = `services.{domain}.path`
168
+ - Store `active_service_module` = `services.{domain}.module`
169
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
170
+
171
+ **3. Fallback** — if domain not detected or no matching service key:
172
+ - Keep default paths from Step 1
173
+ - Set `active_service = unresolved`
174
+
175
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
176
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
177
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
178
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
179
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
180
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
181
+
182
+ ---
183
+
184
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
185
+
186
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
187
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
188
+ If the file does not exist → skip silently.
189
+
190
+ ---
191
+
192
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
193
+
194
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
195
+
196
+ Read `CLAUDE.md`. Extract and store:
197
+
198
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
199
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
200
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
201
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
202
+ - **§7 Git Conventions** → branch naming pattern, commit message format
203
+
204
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
205
+
206
+ ---
207
+
208
+ ## Step 4 — [SAFETY] Load Data Protection Rules
209
+
210
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
211
+
212
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
213
+
214
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
215
+
216
+ ---
217
+
218
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
219
+
220
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
221
+
222
+ If it exists, read it and extract:
223
+ - **Canonical Terms** → complete list of approved terms and their definitions
224
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
225
+ - **Status / Enum Registry** → allowed enum values per entity
226
+
227
+ Store the banned terms list for **active enforcement** throughout the command session:
228
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
229
+ - Replace banned terms with their canonical equivalents automatically
230
+
231
+ If the file does not exist → skip silently. Do not warn or block.
232
+
233
+ ---
234
+
235
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
236
+
237
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
238
+ Default path: `specs/domain-knowledge/core-entities.md`.
239
+
240
+ If it exists, read it and store:
241
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
242
+ - **Field name registry** → canonical field names to use in generated code and documents
243
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
244
+
245
+ **How to use this catalog:**
246
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
247
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
248
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
249
+
250
+ If the file does not exist → skip silently.
251
+
252
+ ---
253
+
254
+ ## Step 6.5 — [PLATFORM] Derive active_module and platform_type
255
+
256
+ Using `tech_stack.module` loaded in Step 1, derive and store two variables for use by all downstream commands:
257
+
258
+ ```
259
+ active_module = tech_stack.module (e.g. "java-spring", "react", "flutter")
260
+ ```
261
+
262
+ | `platform_type` | Modules |
263
+ |---|---|
264
+ | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
265
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
266
+ | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
267
+
268
+ If `tech_stack.module` is blank or not recognized → set `platform_type = "unknown"` and flag as ⚠️ in the Step 7 recap.
269
+
270
+ These two variables (`active_module`, `platform_type`) are the canonical source for all branching logic in commands that need platform-specific behavior (generate-tests, debug, fix-bug, smoke-test).
271
+
272
+ ---
273
+
274
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
275
+
276
+ After loading all context, synthesize and output a compact summary block.
277
+ This recap ensures the most critical facts are stated at the END of context loading
278
+ (recency effect — freshest in working memory when the task begins).
279
+
280
+ Output exactly this block:
281
+ ```
282
+ [CTX LOADED]
283
+ Stack : {language} / {framework} / {database}
284
+ Platform : {active_module} ({platform_type})
285
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
286
+ Ticket : {ticket_prefix}-
287
+ Dict : {loaded — N canonical terms, M banned terms | missing}
288
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
289
+ Service : {active_service} ({active_service_module}) | single-service
290
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
291
+ ```
292
+
293
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
294
+
295
+ ---
296
+
297
+ ## Context Load Complete
298
+
299
+ After completing all steps, you have loaded:
300
+ - Project identity, tech stack, module conventions
301
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
302
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
303
+ - Data protection rules (sensitive file patterns to never access)
304
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
305
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
306
+ - All configured paths
307
+
308
+ Proceed to the next step of the calling command.
309
+
310
+
311
+ *Additional context for this command: Read the full target PRD. Extract: **TICKET-ID**, **domain**, **feature name**, **Service** and **Module** from PRD metadata (rows `| **Service** |` and `| **Module** |`), User Flow (Section 4a), and Wireframe screen names (Section 4b).*
312
+
313
+ *Service extraction rules (same as /generate-prd):*
314
+ - *If PRD metadata has `| **Service** |` → use as `active_service` and `| **Module** |` as `active_module`.*
315
+ - *If absent AND `services` defined in `project-context.yaml` → ask: "Which service is this Design Spec for?" (list FE/App services only, wait for selection).*
316
+ - *If single-service project → `active_service = "default"`, `active_module = tech_stack.module`.*
317
+
318
+ ---
319
+
320
+ ## Platform Check
321
+
322
+ Using `active_module` and `platform_type` derived from context loading:
323
+
324
+ 1. If `platform_type = "backend"` → **STOP**. Output:
325
+ ```
326
+ ❌ Design Spec is only for FE and mobile platforms.
327
+ For BE services, API contracts belong in the Business PRD (Use Case → Business Logic section).
328
+ ```
329
+
330
+ 2. If `platform_type = "web-frontend"` → set `active_platform = "web"`.
331
+
332
+ 3. If `platform_type = "mobile"`:
333
+ - `flutter` or `react-native` → set `active_platform = "app"`
334
+ - `ios-swiftui` → set `active_platform = "app-ios"`
335
+ - `android-compose` → set `active_platform = "app-android"`
336
+
337
+ 4. If `platform_type = "unknown"` → ask: "Which platform is this Design Spec for?"
338
+ ```
339
+ Options:
340
+ 1 — web (React / Next.js / Vue / Angular)
341
+ 2 — app (Flutter / React Native)
342
+ 3 — app-ios (iOS SwiftUI)
343
+ 4 — app-android (Android Compose)
344
+ ```
345
+ Wait for selection. Map choice to `active_platform` and infer `active_module` if possible.
346
+
347
+ ---
348
+
349
+ ## Figma Check
350
+
351
+ Ask:
352
+
353
+ ```
354
+ Do you have a Figma link for this feature? (paste URL or press Enter to skip)
355
+ ```
356
+
357
+ - If URL provided → store as `figma_url`.
358
+ - If skipped → `figma_url = "TBD"`. Add AI Assumption: "Figma link not provided — all screen descriptions are text-based. Link must be added and verified before Design Spec sign-off."
359
+
360
+ ---
361
+
362
+ ## Screen Discovery
363
+
364
+ From the PRD's Section 4 (User Flow + Wireframe), extract all screen / page / modal names mentioned.
365
+
366
+ Present the list and ask PO to confirm:
367
+
368
+ ```
369
+ Screens detected from PRD:
370
+ 1. {Screen name 1}
371
+ 2. {Screen name 2}
372
+ ...
373
+
374
+ Are these all the screens for the {active_platform} platform?
375
+ Add any missing, remove any that don't apply, or confirm with Y.
376
+ ```
377
+
378
+ Wait for confirmation. Store the confirmed list as `screen_list`.
379
+
380
+ ---
381
+
382
+ ## CHECKPOINT
383
+
384
+ ```
385
+ CHECKPOINT — Design Spec
386
+ -------------------------
387
+ Target PRD : {prd-file-path}
388
+ Platform : {active_platform}
389
+ Module : {active_module}
390
+ Service : {active_service}
391
+ Domain : {domain}
392
+ Screens : {N} — {comma-separated screen_list}
393
+ Figma : {figma_url}
394
+ Output path : {paths.design_spec_dir}/{domain}/{TICKET-ID}-design-spec-{active_platform}-{slug}.md
395
+
396
+ Generate? (Y/N)
397
+ ```
398
+
399
+ Wait for explicit Y before proceeding.
400
+
401
+ ---
402
+
403
+ ## Generation Rules
404
+
405
+ Apply these rules consistently when generating all sections:
406
+
407
+ **Component mapping (C.M — mandatory):**
408
+ - For each component referenced, check `figma-components/{active_module}.md` (loaded in context).
409
+ - ✅ Matched → use the exact `Code Component` and `Import Path` from the catalog.
410
+ - ⚠️ Matched but `[TODO]` → mark the component cell as `[TODO — implementation pending]`.
411
+ - ❌ Not in catalog → mark as `[NEW — confirm with designer before generating code]`.
412
+ - Never invent component names or import paths.
413
+
414
+ **Platform-adaptive sections:**
415
+ - Section 3 (Interaction Patterns) and Section 4 (Platform Considerations) adapt to `active_platform`:
416
+ - `web` → include responsive breakpoints, hover/focus states, keyboard navigation, accessibility.
417
+ - `app` / `app-ios` / `app-android` → include gestures, safe area, minimum touch targets, navigation pattern, deep links, permissions, offline behavior.
418
+ - Only generate the section relevant to `active_platform`. Omit the other platform's section entirely.
419
+
420
+ **Screen states (mandatory per screen):**
421
+ - Every screen must document at minimum: `default`, `loading`, `error`.
422
+ - Add `empty` when the screen can display zero-data state.
423
+ - Add `success` when a completed action produces a distinct confirmation state.
424
+ - If a state does not apply → mark `N/A` with a short reason.
425
+
426
+ ---
427
+
428
+ ## Generate
429
+
430
+ Write `{paths.design_spec_dir}/{domain}/{TICKET-ID}-design-spec-{active_platform}-{slug}.md`:
431
+
432
+ ````markdown
433
+ # {TICKET-ID} {Feature Name} — Design Spec [{active_platform}]
434
+
435
+ ---
436
+
437
+ ## Metadata
438
+
439
+ | Field | Value |
440
+ |--------------------|---------------------------------------------------------------|
441
+ | **Spec ID** | {TICKET-ID}-DS-{active_platform} |
442
+ | **Version** | 1.0 |
443
+ | **Status** | draft |
444
+ | **Platform** | {active_platform} |
445
+ | **Module** | {active_module} |
446
+ | **Service** | {active_service} |
447
+ | **Domain** | {domain} |
448
+ | **Business PRD** | [{TICKET-ID}]({relative-path-to-prd.md}) |
449
+ | **Figma** | {figma_url} |
450
+ | **Author** | {PO name or "AI-assisted"} |
451
+ | **Created** | {YYYY-MM-DD} |
452
+ | **Updated** | {YYYY-MM-DD} |
453
+
454
+ ---
455
+
456
+ # 1. Screen Inventory
457
+
458
+ | # | Screen Name | Entry Point | Figma Frame | Notes |
459
+ |---|-------------|-------------|-------------|-------|
460
+ | 1 | {Screen 1} | {how user arrives — e.g., tap CTA on Home} | [Frame]({figma_url}#screen1) | |
461
+ | 2 | {Screen 2} | {entry point} | [Frame]({figma_url}#screen2) | |
462
+
463
+ ---
464
+
465
+ # 2. Screen Specs
466
+
467
+ <!--
468
+ Repeat this block for every screen in the Screen Inventory.
469
+ Each screen must have: Layout, Component Inventory, Screen States, Actions & Navigation.
470
+ -->
471
+
472
+ ## Screen 1: {Screen Name}
473
+
474
+ **Figma**: [{Frame name}]({figma_frame_url})
475
+
476
+ ### Layout
477
+
478
+ {Describe the layout: grid columns, max-width container, section order, padding, key spacing values.
479
+ Reference design tokens where applicable (e.g., `spacing.md = 16px`, `color.surface`).}
480
+
481
+ ### Component Inventory
482
+
483
+ | Component (Figma) | Code Component | Import Path | States | Notes |
484
+ |---------------------|-----------------|------------------------|---------------------------------|--------------------|
485
+ | {Figma/Button/Primary} | Button | @/components/ui/Button | default, loading, disabled | |
486
+ | {Figma/Input/Text} | TextInput | @/components/ui/Input | default, focus, error, disabled | |
487
+ | {Figma/Card/Order} | OrderCard | @/features/{domain}/components/OrderCard | default, skeleton | |
488
+
489
+ ### Screen States
490
+
491
+ | State | Trigger | UI Behavior |
492
+ |-----------|-------------------------------------|--------------------------------------------------------------|
493
+ | default | Screen loaded, data available | {Describe full rendered appearance} |
494
+ | loading | API call in flight | {Skeleton layout / spinner position — reference component} |
495
+ | error | API failure or validation error | {Toast / inline message / error screen — exact copy TBD} |
496
+ | empty | API returns empty list / no data | {Empty state illustration + CTA text — e.g., "No orders yet. Start shopping →"} |
497
+ | success | Action completed (if applicable) | {Confirmation message / navigation / state change} |
498
+
499
+ ### Actions & Navigation
500
+
501
+ | Action | Trigger | Result |
502
+ |-----------------|--------------------------------|-------------------------------------------------|
503
+ | {Action name} | Tap/click {element name} | Navigate to {Screen N} / Open {Modal name} |
504
+ | {Action name} | Swipe left on {list item} | Show delete confirmation |
505
+ | {Back / Cancel} | Back gesture / Cancel button | Return to {previous screen} without saving |
506
+
507
+ ---
508
+
509
+ <!-- Repeat ## Screen N block for each additional screen -->
510
+
511
+ ---
512
+
513
+ # 3. Interaction Patterns
514
+
515
+ <!--
516
+ Web platform: include sections A + B. Remove section C.
517
+ App platform: include section C. Remove sections A + B.
518
+ -->
519
+
520
+ <!-- ═══════════════════════════ WEB ONLY ═══════════════════════════ -->
521
+
522
+ ## A. Responsive Behavior *(web only)*
523
+
524
+ | Breakpoint | Width | Layout Changes |
525
+ |------------|------------|----------------------------------------------------|
526
+ | Mobile | < 768px | {Single column, bottom navigation bar, CTA full-width} |
527
+ | Tablet | 768–1279px | {2-column grid, sidebar collapsed, tab navigation} |
528
+ | Desktop | ≥ 1280px | {Full layout, sidebar visible, max-width 1440px} |
529
+
530
+ ## B. Hover / Focus / Keyboard *(web only)*
531
+
532
+ | Element | Hover state | Focus state | Keyboard shortcut |
533
+ |----------------|-------------------------------|---------------------------------|-------------------|
534
+ | Primary button | Background → {color.hover} | Outline 2px {color.focus} | Enter / Space |
535
+ | Text input | Border → {color.border.hover} | Border → {color.primary}, label floats | Tab to focus |
536
+ | Dropdown | Background highlight | Same as hover + ring | Arrow keys to navigate |
537
+
538
+ <!-- ═══════════════════════════ APP ONLY ═══════════════════════════ -->
539
+
540
+ ## C. Gestures & Navigation *(app only)*
541
+
542
+ | Gesture | Screen / Element | Behavior |
543
+ |-------------------|---------------------------|-------------------------------------------------------|
544
+ | Back gesture (iOS swipe-right / Android back) | All screens | {Return to previous screen / Show "Discard changes?" dialog} |
545
+ | Pull-to-refresh | {Screen names} | Refresh data, spinner at top |
546
+ | Swipe left on row | {List item name} | Reveal {Delete / Archive} action |
547
+ | Long press | {Element name} | {Context menu / selection mode} |
548
+ | Pinch / zoom | {Image viewer} | Scale image, double-tap to reset |
549
+
550
+ ### Navigation Pattern *(app only)*
551
+
552
+ ```
553
+ {Draw the navigation stack for this feature, e.g.:
554
+ BottomTab(Home) → FeatureListPage → FeatureDetailPage → EditPage
555
+ BottomTab(Home) → FeatureListPage ↘ (modal) CreatePage
556
+ }
557
+ ```
558
+
559
+ Entry: {how the user enters this feature — tab / deeplink / push from another screen}
560
+ Exit: {how the user leaves — back stack / tab switch / deeplink out}
561
+
562
+ ### Platform Conventions *(app only)*
563
+
564
+ | Aspect | iOS behavior | Android behavior |
565
+ |--------------------------|-----------------------------------------|-----------------------------------------|
566
+ | Navigation bar | {Back button top-left, title centered} | {Up arrow top-left, title left-aligned} |
567
+ | Sheet / bottom modal | {UISheetPresentation, grabber visible} | {BottomSheet, drag handle} |
568
+ | Alert / confirm dialog | {UIAlertController, actions right-aligned} | {Material AlertDialog, actions left-aligned} |
569
+ | Loading indicator | {UIActivityIndicatorView, center} | {CircularProgressIndicator} |
570
+ | Toast / snackbar | {Custom toast, bottom center} | {Material Snackbar, bottom} |
571
+
572
+ ---
573
+
574
+ # 4. Platform Considerations
575
+
576
+ <!--
577
+ Web: include section A. App: include section B. Remove the non-applicable section.
578
+ -->
579
+
580
+ <!-- ═══════════════════════════ WEB ONLY ═══════════════════════════ -->
581
+
582
+ ## A. Accessibility *(web only)*
583
+
584
+ - [ ] All interactive elements reachable via Tab key — no keyboard traps
585
+ - [ ] Focus trap inside modal dialogs (Tab cycles within modal only)
586
+ - [ ] Icon-only buttons have `aria-label` describing the action
587
+ - [ ] Dynamic content updates (loading → loaded) announce via `aria-live`
588
+ - [ ] Color contrast meets WCAG AA: text ≥ 4.5:1, large text ≥ 3:1
589
+ - [ ] Form inputs have visible labels (not placeholder-only)
590
+ - [ ] Error messages linked to inputs via `aria-describedby`
591
+
592
+ <!-- ═══════════════════════════ APP ONLY ═══════════════════════════ -->
593
+
594
+ ## B. Device & OS *(app only)*
595
+
596
+ - [ ] Safe area insets applied on all screens — top (status bar) and bottom (home indicator)
597
+ - [ ] Minimum touch target: 44×44pt (iOS) / 48×48dp (Android)
598
+ - [ ] Tested on small screen: 375pt wide (iPhone SE) / 360dp wide (common Android)
599
+ - [ ] Deep link entry: `{scheme}://{host}/{path}` → lands on {screen name} with {param} pre-filled
600
+ - [ ] Permission gates: {list permissions needed — Camera / Location / Notification}
601
+ - {Permission}: requested on {screen name} with rationale copy: "{copy TBD}"
602
+ - [ ] Offline / no-network behavior:
603
+ - {Screen name}: show cached data + offline banner
604
+ - {Action name}: disable button, show tooltip "Requires connection"
605
+ - [ ] Dark mode: all screens tested in dark mode — no hardcoded colors
606
+
607
+ ---
608
+
609
+ # 5. AC-UI — Design Acceptance Criteria
610
+
611
+ > Reviewed and signed off by **PO + Designer** together before BDD generation.
612
+ > These complement (not replace) the business-level AC in the [Business PRD]({prd-path}).
613
+
614
+ | ID | Acceptance Criterion | Verified by |
615
+ |--------|--------------------------------------------------------------------------------|-----------------|
616
+ | AC-UI1 | All screens match approved Figma frames within design-system tolerances | Designer |
617
+ | AC-UI2 | Loading skeleton/spinner appears within 200ms of initiating any API call | QA |
618
+ | AC-UI3 | All error messages are visible, descriptive, and include a recovery action | PO |
619
+ | AC-UI4 | Empty states include an illustration and a clear call-to-action | PO + Designer |
620
+ | AC-UI5 | {Platform-specific — e.g., web: "All screens pass WCAG AA contrast check"} | QA |
621
+ | AC-UI6 | {Platform-specific — e.g., app: "Back gesture on all screens returns to correct previous screen"} | QA |
622
+ | AC-UI7 | {Feature-specific UI criterion from Business PRD wireframe section} | PO |
623
+
624
+ ---
625
+
626
+ # Appendix
627
+
628
+ ## Figma Summary
629
+
630
+ | Screen | Figma Frame | Designer Status |
631
+ |-----------------|-------------------------------|------------------------|
632
+ | {Screen 1} | [Link]({figma_frame_url}) | ✅ Ready / ⏳ WIP / ❌ Missing |
633
+ | {Screen 2} | [Link]({figma_frame_url}) | ✅ Ready / ⏳ WIP / ❌ Missing |
634
+
635
+ ## Design Tokens Referenced
636
+
637
+ | Token | Value | Used in |
638
+ |-----------------------|---------------|---------------------------------|
639
+ | `color.primary` | {#hex} | Primary buttons, links, active states |
640
+ | `color.surface` | {#hex} | Card backgrounds |
641
+ | `spacing.md` | {16px / 4} | Standard vertical gap |
642
+ | `typography.heading2` | {font/size} | Screen titles |
643
+
644
+ ## References
645
+
646
+ - [{TICKET-ID}]({prd-path}) — Business PRD (source of AC, UC, BR)
647
+ - {[Other Design Spec](./other-ds.md) — if this feature shares screens}
648
+
649
+ ## AI Assumptions
650
+
651
+ > Each assumption below was made because PO input was incomplete.
652
+ > PO must review and confirm before sign-off.
653
+
654
+ - {Assumption 1 — [AI DRAFT]}
655
+
656
+ ---
657
+
658
+ ## Changelog
659
+
660
+ | Version | Date | Changes |
661
+ |---------|--------------|-----------------|
662
+ | 1.0 | {YYYY-MM-DD} | Initial version |
663
+
664
+ <!--
665
+ NEXT STEPS:
666
+ 1. Share with Designer — verify Figma links, update component inventory.
667
+ 2. PO + Designer sign off: change Status → "approved".
668
+ 3. Run /generate-bdd "{prd-file}" — BDD uses AC-UI from this spec for FE scenarios.
669
+ -->
670
+ ````
671
+
672
+ ---
673
+
674
+ ## Quality Checklist *(verify before writing)*
675
+
676
+ - [ ] Every screen in Screen Inventory has a complete Screen Spec in Section 2
677
+ - [ ] Every screen has at minimum: default, loading, error states defined
678
+ - [ ] All Figma components mapped in Component Inventory — unmapped flagged as `[NEW]` or `[TODO]`
679
+ - [ ] Only the platform-relevant section generated in Section 3 (no web section in app docs, and vice versa)
680
+ - [ ] Only the platform-relevant section generated in Section 4
681
+ - [ ] AC-UI items are testable (clear pass/fail, not "looks good")
682
+ - [ ] Business PRD cross-reference link is valid relative path
683
+ - [ ] If `figma_url = "TBD"` → AI Assumption added in Appendix
684
+
685
+ ---
686
+
687
+ ## Output
688
+
689
+ # Report Footer — Standard Command Output Format
690
+
691
+ Every command report must end with this standard footer section.
692
+
693
+ ## Status Badge
694
+
695
+ Choose one based on outcome:
696
+ - `✅ Complete` — all steps succeeded, no issues found
697
+ - `❌ Failed` — command could not complete due to a blocking error
698
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
699
+
700
+ ## Output Artifacts
701
+
702
+ List every file created or modified by this command:
703
+ ```
704
+ Output Artifacts:
705
+ {created|updated} {file-path} ({brief description})
706
+ {created|updated} {file-path} ({brief description})
707
+ ```
708
+
709
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
710
+
711
+ ## Next Command Suggestion
712
+
713
+ Suggest the logical next command based on workflow phase:
714
+
715
+ | Current command | Suggest next |
716
+ |-------------------------|-----------------------------------------------|
717
+ | /setup-ai-first | `/define-product` to start your first feature |
718
+ | /define-product | `/generate-prd {product-definition-file}` |
719
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
720
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
721
+ | /review-context (PRD) | FE/App: `/generate-design-spec {prd-file}` (then BDD after sign-off); BE: `/generate-bdd {prd-file}` directly; fix PRD if NEEDS_FIX |
722
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
723
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
724
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
725
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
726
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
727
+ | /generate-code | First gen → `/review-code {UC-ID}`; re-gen → `/generate-tests {UC-ID}` |
728
+ | /generate-tests | `/run-tests {UC-ID}` |
729
+ | /run-tests (passing) | `/review-code {UC-ID}` |
730
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
731
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
732
+ | /smoke-test | Create PR and link to ticket |
733
+ | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
734
+ | /fix-bug | Create PR and link to ticket |
735
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
736
+
737
+ Format the footer as:
738
+ ```
739
+ ---
740
+ Status : {badge}
741
+ {Output Artifacts block}
742
+ Next : {suggested command with example arguments}
743
+ ```
744
+
745
+
746
+ ```
747
+ /generate-design-spec Complete — {TICKET-ID} [{active_platform}]
748
+ ---
749
+ Status : ✅ Complete
750
+ Output Artifacts:
751
+ created {paths.design_spec_dir}/{domain}/{TICKET-ID}-design-spec-{active_platform}-{slug}.md (v1.0)
752
+ Next : Share with Designer → add Figma links → PO + Designer sign-off (Status: approved)
753
+ → /generate-bdd {prd-file} (generates BDD per service; reads AC-UI from Design Spec)
754
+ ```