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