@anhth2/spec-driven-dev-plugin 0.5.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 (152) hide show
  1. package/ARCHITECTURE.md +243 -0
  2. package/bin/build.js +230 -0
  3. package/bin/index.js +311 -0
  4. package/commands/debug.md +374 -0
  5. package/commands/debug.tmpl +77 -0
  6. package/commands/define-product.md +451 -0
  7. package/commands/define-product.tmpl +154 -0
  8. package/commands/fix-bug.md +379 -0
  9. package/commands/fix-bug.tmpl +82 -0
  10. package/commands/generate-bdd.md +591 -0
  11. package/commands/generate-bdd.tmpl +294 -0
  12. package/commands/generate-code.md +395 -0
  13. package/commands/generate-code.tmpl +98 -0
  14. package/commands/generate-prd.md +488 -0
  15. package/commands/generate-prd.tmpl +191 -0
  16. package/commands/generate-tech-docs.md +362 -0
  17. package/commands/generate-tech-docs.tmpl +65 -0
  18. package/commands/generate-tests.md +377 -0
  19. package/commands/generate-tests.tmpl +80 -0
  20. package/commands/refine-prd.md +408 -0
  21. package/commands/refine-prd.tmpl +111 -0
  22. package/commands/review-code.md +354 -0
  23. package/commands/review-code.tmpl +57 -0
  24. package/commands/review-context.md +646 -0
  25. package/commands/review-context.tmpl +349 -0
  26. package/commands/review-tech-docs.md +518 -0
  27. package/commands/review-tech-docs.tmpl +221 -0
  28. package/commands/run-tests.md +343 -0
  29. package/commands/run-tests.tmpl +46 -0
  30. package/commands/setup-ai-first.md +278 -0
  31. package/commands/setup-ai-first.tmpl +197 -0
  32. package/commands/smoke-test.md +366 -0
  33. package/commands/smoke-test.tmpl +69 -0
  34. package/commands/validate-traces.md +529 -0
  35. package/commands/validate-traces.tmpl +232 -0
  36. package/core/FRAMEWORK_VERSION +1 -0
  37. package/core/commands/debug.md +374 -0
  38. package/core/commands/define-product.md +451 -0
  39. package/core/commands/fix-bug.md +379 -0
  40. package/core/commands/generate-bdd.md +591 -0
  41. package/core/commands/generate-code.md +395 -0
  42. package/core/commands/generate-prd.md +488 -0
  43. package/core/commands/generate-tech-docs.md +362 -0
  44. package/core/commands/generate-tests.md +377 -0
  45. package/core/commands/refine-prd.md +408 -0
  46. package/core/commands/review-code.md +354 -0
  47. package/core/commands/review-context.md +646 -0
  48. package/core/commands/review-tech-docs.md +518 -0
  49. package/core/commands/run-tests.md +343 -0
  50. package/core/commands/setup-ai-first.md +278 -0
  51. package/core/commands/smoke-test.md +366 -0
  52. package/core/commands/validate-traces.md +529 -0
  53. package/core/hooks/data-guard.js +141 -0
  54. package/core/hooks/settings.json +18 -0
  55. package/core/modules/angular/architecture-snippets/component-patterns.md +187 -0
  56. package/core/modules/angular/module.yaml +6 -0
  57. package/core/modules/angular/stack-profile.yaml +38 -0
  58. package/core/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  59. package/core/modules/context-engineering/module.yaml +9 -0
  60. package/core/modules/context-engineering/stack-profile.yaml +61 -0
  61. package/core/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  62. package/core/modules/dotnet/module.yaml +6 -0
  63. package/core/modules/dotnet/stack-profile.yaml +50 -0
  64. package/core/modules/golang/architecture-snippets/domain-layout.md +283 -0
  65. package/core/modules/golang/module.yaml +6 -0
  66. package/core/modules/golang/stack-profile.yaml +40 -0
  67. package/core/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  68. package/core/modules/java-spring/module.yaml +15 -0
  69. package/core/modules/java-spring/stack-profile.yaml +28 -0
  70. package/core/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  71. package/core/modules/nextjs/module.yaml +14 -0
  72. package/core/modules/nextjs/stack-profile.yaml +74 -0
  73. package/core/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  74. package/core/modules/php-laravel/module.yaml +15 -0
  75. package/core/modules/php-laravel/stack-profile.yaml +56 -0
  76. package/core/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  77. package/core/modules/react/module.yaml +14 -0
  78. package/core/modules/react/stack-profile.yaml +63 -0
  79. package/core/rules/data-protection.md +80 -0
  80. package/core/rules/workflow.md +44 -0
  81. package/core/skills/code/SKILL.md +526 -0
  82. package/core/skills/debug/SKILL.md +584 -0
  83. package/core/skills/discovery/SKILL.md +363 -0
  84. package/core/skills/prd/SKILL.md +456 -0
  85. package/core/skills/setup-ai-first/SKILL.md +160 -0
  86. package/core/skills/spec/SKILL.md +361 -0
  87. package/core/skills/test/SKILL.md +862 -0
  88. package/core/steps/context-loader.md +163 -0
  89. package/core/steps/gate.md +81 -0
  90. package/core/steps/report-footer.md +53 -0
  91. package/core/steps/spawn-agent.md +123 -0
  92. package/core/templates/architecture.template.md +113 -0
  93. package/core/templates/feature.template +259 -0
  94. package/core/templates/platform-guide.template.md +145 -0
  95. package/core/templates/prd.template.md +312 -0
  96. package/core/templates/product-definition.template.md +168 -0
  97. package/core/templates/project-context.yaml +78 -0
  98. package/hooks/data-guard.js +141 -0
  99. package/hooks/settings.json +18 -0
  100. package/modules/angular/architecture-snippets/component-patterns.md +187 -0
  101. package/modules/angular/module.yaml +6 -0
  102. package/modules/angular/stack-profile.yaml +38 -0
  103. package/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  104. package/modules/context-engineering/module.yaml +9 -0
  105. package/modules/context-engineering/stack-profile.yaml +61 -0
  106. package/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  107. package/modules/dotnet/module.yaml +6 -0
  108. package/modules/dotnet/stack-profile.yaml +50 -0
  109. package/modules/golang/architecture-snippets/domain-layout.md +283 -0
  110. package/modules/golang/module.yaml +6 -0
  111. package/modules/golang/stack-profile.yaml +40 -0
  112. package/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  113. package/modules/java-spring/module.yaml +15 -0
  114. package/modules/java-spring/stack-profile.yaml +28 -0
  115. package/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  116. package/modules/nextjs/module.yaml +14 -0
  117. package/modules/nextjs/stack-profile.yaml +74 -0
  118. package/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  119. package/modules/php-laravel/module.yaml +15 -0
  120. package/modules/php-laravel/stack-profile.yaml +56 -0
  121. package/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  122. package/modules/react/module.yaml +14 -0
  123. package/modules/react/stack-profile.yaml +63 -0
  124. package/package.json +42 -0
  125. package/rules/data-protection.md +80 -0
  126. package/rules/workflow.md +44 -0
  127. package/scripts/init.sh +49 -0
  128. package/scripts/upgrade.sh +94 -0
  129. package/skills/code/SKILL.md +526 -0
  130. package/skills/code/SKILL.tmpl +176 -0
  131. package/skills/debug/SKILL.md +584 -0
  132. package/skills/debug/SKILL.tmpl +262 -0
  133. package/skills/discovery/SKILL.md +363 -0
  134. package/skills/discovery/SKILL.tmpl +147 -0
  135. package/skills/prd/SKILL.md +456 -0
  136. package/skills/prd/SKILL.tmpl +188 -0
  137. package/skills/setup-ai-first/SKILL.md +160 -0
  138. package/skills/setup-ai-first/SKILL.tmpl +107 -0
  139. package/skills/spec/SKILL.md +361 -0
  140. package/skills/spec/SKILL.tmpl +174 -0
  141. package/skills/test/SKILL.md +862 -0
  142. package/skills/test/SKILL.tmpl +296 -0
  143. package/steps/context-loader.md +163 -0
  144. package/steps/gate.md +81 -0
  145. package/steps/report-footer.md +53 -0
  146. package/steps/spawn-agent.md +123 -0
  147. package/templates/architecture.template.md +113 -0
  148. package/templates/feature.template +259 -0
  149. package/templates/platform-guide.template.md +145 -0
  150. package/templates/prd.template.md +312 -0
  151. package/templates/product-definition.template.md +168 -0
  152. package/templates/project-context.yaml +78 -0
@@ -0,0 +1,646 @@
1
+ # /review-context — Review PRD or BDD for Quality & Consistency
2
+
3
+ **READ-ONLY analysis mode — writes a findings file, does NOT modify the target.**
4
+ **Use `--resume` to apply accepted findings.**
5
+
6
+ ## Gate
7
+ # Gate — Universal Entry Procedure
8
+
9
+ Every command must execute this gate before proceeding with its specific logic.
10
+
11
+ ## Step 0 — Sub-Agent Mode Check
12
+
13
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
14
+
15
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
16
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
17
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
18
+ - Set target file = `payload.target_file`
19
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
20
+ - Set UC scope = `payload.uc_id` (process only this UC)
21
+ - Set line range = `payload.uc_section` (read only that PRD section)
22
+ - Proceed directly to the command-specific logic.
23
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
24
+
25
+ ## Step 0-B — Model Check
26
+
27
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
28
+
29
+ Complex generation and review commands require strong reasoning.
30
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
31
+
32
+ Display and wait for response:
33
+
34
+ ```
35
+ ⚙️ MODEL CHECK
36
+ ──────────────────────────────────────────────────────────────────
37
+ Recommended : claude-opus-4-5 (or claude-opus-4)
38
+ Why needed : Spec analysis, architecture review, code generation
39
+ require deep reasoning. Smaller models miss edge cases.
40
+
41
+ To switch in Claude Code:
42
+ • Settings → Model → select "claude-opus"
43
+ • or: /model → choose claude-opus
44
+
45
+ Running on claude-opus?
46
+ Y — yes, on claude-opus → proceed
47
+ S — skip check (I accept lower quality risk with current model)
48
+ ──────────────────────────────────────────────────────────────────
49
+ ```
50
+
51
+ - "Y" → proceed to Step 1.
52
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
53
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
54
+
55
+ ## Step 1 — Resolve Target File
56
+
57
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
58
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
59
+ 3. If `$ARGUMENTS` is empty or no match found:
60
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
61
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
62
+ - Wait for user selection before continuing.
63
+
64
+ ## Step 2 — Execute Context Loader
65
+
66
+ Load all project context by following the procedure in `steps/context-loader.md`.
67
+ Store all loaded context in memory for use throughout this command session.
68
+
69
+ ## Step 3 — CHECKPOINT
70
+
71
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
72
+
73
+ ```
74
+ CHECKPOINT
75
+ -----------
76
+ Target : {resolved file path}
77
+ Project : {project.name from project-context.yaml}
78
+ Tech stack : {language} / {framework}
79
+ Module : {module if set, else "not configured"}
80
+ Domains : {comma-separated domain list}
81
+
82
+ Proceed? (Y/N)
83
+ ```
84
+
85
+ Wait for explicit "Y" or "N" from the user before continuing.
86
+ - "Y" → proceed to the command-specific steps below.
87
+ - "N" → stop and ask what the user wants to change.
88
+
89
+
90
+ *Note: For this command, the target in Step 1 is either a `.md` PRD file or a `.feature` BDD file.
91
+ If the path is in `{paths.prd_dir}` → PRD Review Mode.
92
+ If the path ends with `.feature` → BDD Review Mode.
93
+ If `$ARGUMENTS` contains `--resume` → skip to Resume Mode below.
94
+ If `$ARGUMENTS` contains `--fix` → skip to Fix Mode below (apply all auto-fixable findings immediately).*
95
+
96
+ ## Context
97
+ # Context Loader — Load All Project Context
98
+
99
+ Execute these steps in order. Store everything in memory for the duration of the command session.
100
+
101
+ **Priority guide (anti-lost-in-middle):**
102
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
103
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
104
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
105
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
106
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
107
+
108
+ ---
109
+
110
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
111
+
112
+ Read `.agent/project-context.yaml`. Extract and store:
113
+
114
+ **Tech Stack:**
115
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
116
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
117
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
118
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
119
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
120
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
121
+
122
+ **Conventions:**
123
+ - `conventions.build_command` → how to compile/build
124
+ - `conventions.test_command` → how to run tests
125
+ - `conventions.service_run` → how to start the service
126
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
127
+
128
+ **Domains:**
129
+ - `domains` → list of active business domains
130
+
131
+ **Paths (if present):**
132
+ - `paths.specs_dir` → BDD specs root
133
+ - `paths.prd_dir` → PRD documents root
134
+ - `paths.refinement_dir` → findings/review output dir
135
+ - `paths.product_definitions_dir` → product definitions root
136
+ - `paths.domain_knowledge_dir` → domain knowledge root
137
+ - `paths.business_dictionary` → path to business-dictionary.md
138
+ - `paths.core_entities` → path to core-entities.md
139
+ - `paths.tech_docs_dir` → technical documentation root
140
+ - `paths.trace_dir` → trace state directory
141
+
142
+ If `paths` section is absent, use these defaults:
143
+ - `specs_dir` = `specs/bdd`
144
+ - `prd_dir` = `specs/prd`
145
+ - `refinement_dir` = `.agent/review`
146
+ - `product_definitions_dir` = `specs/product-definition`
147
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
148
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
149
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
150
+ - `tech_docs_dir` = `tech-docs`
151
+ - `trace_dir` = `.trace`
152
+
153
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
154
+
155
+ ---
156
+
157
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
158
+
159
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
160
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
161
+ If the file does not exist → skip silently.
162
+
163
+ ---
164
+
165
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
166
+
167
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
168
+
169
+ Read `CLAUDE.md`. Extract and store:
170
+
171
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
172
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
173
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
174
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
175
+ - **§7 Git Conventions** → branch naming pattern, commit message format
176
+
177
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
178
+
179
+ ---
180
+
181
+ ## Step 4 — [SAFETY] Load Data Protection Rules
182
+
183
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
184
+
185
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
186
+
187
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
188
+
189
+ ---
190
+
191
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
192
+
193
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
194
+
195
+ If it exists, read it and extract:
196
+ - **Canonical Terms** → complete list of approved terms and their definitions
197
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
198
+ - **Status / Enum Registry** → allowed enum values per entity
199
+
200
+ Store the banned terms list for **active enforcement** throughout the command session:
201
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
202
+ - Replace banned terms with their canonical equivalents automatically
203
+
204
+ If the file does not exist → skip silently. Do not warn or block.
205
+
206
+ ---
207
+
208
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
209
+
210
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
211
+ Default path: `specs/domain-knowledge/core-entities.md`.
212
+
213
+ If it exists, read it and store:
214
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
215
+ - **Field name registry** → canonical field names to use in generated code and documents
216
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
217
+
218
+ **How to use this catalog:**
219
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
220
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
221
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
222
+
223
+ If the file does not exist → skip silently.
224
+
225
+ ---
226
+
227
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
228
+
229
+ After loading all context, synthesize and output a compact summary block.
230
+ This recap ensures the most critical facts are stated at the END of context loading
231
+ (recency effect — freshest in working memory when the task begins).
232
+
233
+ Output exactly this block:
234
+ ```
235
+ [CTX LOADED]
236
+ Stack : {language} / {framework} / {database}
237
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
238
+ Ticket : {ticket_prefix}-
239
+ Dict : {loaded — N canonical terms, M banned terms | missing}
240
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
241
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
242
+ ```
243
+
244
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
245
+
246
+ ---
247
+
248
+ ## Context Load Complete
249
+
250
+ After completing all steps, you have loaded:
251
+ - Project identity, tech stack, module conventions
252
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
253
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
254
+ - Data protection rules (sensitive file patterns to never access)
255
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
256
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
257
+ - All configured paths
258
+
259
+ Proceed to the next step of the calling command.
260
+
261
+
262
+ ---
263
+
264
+ ## Detect Review Mode
265
+
266
+ After resolving the target file:
267
+ - `.feature` file → **BDD Review Mode** (jump to BDD section)
268
+ - `.md` in `{paths.prd_dir}/**` → **PRD Review Mode** (continue below)
269
+ - Unknown → ask: "Is this a PRD file or a BDD feature file? (prd/bdd)"
270
+
271
+ Also check flags:
272
+ - `--fix` present → after running all checks, apply `auto_fixable: true` findings immediately (skip Review Board)
273
+ - `--resume` present → skip analysis entirely, go to Resume Mode
274
+
275
+ Derive the output findings filename:
276
+ - PRD: `{paths.refinement_dir}/{prd-slug}-review-context-findings.yaml`
277
+ - BDD: `{paths.refinement_dir}/{uc-id}-review-bdd-findings.yaml`
278
+
279
+ ---
280
+
281
+ ## PRD Review Mode
282
+
283
+ ### P1 — Terminology Check (Business Dictionary)
284
+
285
+ Load `{paths.business_dictionary}`.
286
+ Scan the entire PRD for terminology issues:
287
+
288
+ 1. **Banned terms** — every occurrence of a term in §Banned Terms:
289
+ → Severity: **critical**. AI can auto-fix in `--resume`.
290
+
291
+ 2. **Inconsistent usage** — same concept named differently across sections:
292
+ → Severity: **major**. Flag both occurrences. Human decides canonical form in Review Board note.
293
+
294
+ 3. **Unlisted business terms** — important terms absent from the dictionary:
295
+ → Severity: **minor**. Suggest adding to `business-dictionary.md`.
296
+
297
+ ### P2 — Ambiguity Check
298
+
299
+ Scan each AC and BR for:
300
+
301
+ | Signal | Example | Severity |
302
+ |--------|---------|----------|
303
+ | Vague quantifier | "fast", "large", "reasonable", "quickly" | Critical |
304
+ | Missing actor | "the system should" with no trigger specified | Major |
305
+ | Undefined reference | "{SomeThing}" used but never defined in this PRD | Major |
306
+ | Missing negative path | AC only describes happy path but BR has error conditions | Minor |
307
+ | Passive voice hiding actor | "Invoice is created" — who creates it? | Minor |
308
+
309
+ → AI cannot auto-fix P2 findings. Human must write the fix in Review Board "Modify" note.
310
+
311
+ ### P3 — Domain Conflict Check
312
+
313
+ List all other PRDs in `{paths.prd_dir}/{domain}/`.
314
+ For each one, check if this PRD contradicts a defined BR (same trigger, different outcome)
315
+ or redefines an entity field/status transition differently.
316
+
317
+ → Severity: **critical**. Human decides which PRD is correct. Note required.
318
+
319
+ ### P4 — Structural Completeness
320
+
321
+ - [ ] Metadata block: Version, Author, Date, Status
322
+ - [ ] At least 1 UC with `#### {TICKET-ID}-UC{N}:` heading
323
+ - [ ] Each UC has: Description, Actors, Preconditions, Acceptance Criteria, Business Rules
324
+ - [ ] `## Changelog` section exists
325
+ - [ ] No `{{PLACEHOLDER}}` values unfilled
326
+
327
+ → Missing sections: **major**. AI can add skeleton in `--resume` if accepted.
328
+
329
+ ### P5 — Custom Criteria (optional)
330
+
331
+ If `$ARGUMENTS` contains additional criteria after the file path, evaluate them and create
332
+ findings with `check_id: "P5"` and severity as appropriate.
333
+
334
+ ---
335
+
336
+ ## BDD Review Mode
337
+
338
+ ### B1 — PRD Coverage Check
339
+
340
+ Load the PRD referenced by `# @trace.prd:` in the feature file header.
341
+ Map every AC and every BR (including sub-bullets) to scenarios:
342
+
343
+ ```
344
+ AC1 ({short text}) → SC1, SC2 ✅
345
+ AC2 ({short text}) → MISSING ❌
346
+ BR1 ({short text}) → SC1 ✅
347
+ BR2 ({short text}) → MISSING ❌
348
+ ```
349
+
350
+ → Each missing AC/BR coverage: **critical** finding.
351
+ If accepted in Review Board, `--resume` generates the missing scenario(s).
352
+
353
+ ### B2 — Terminology & Entity Check
354
+
355
+ Using `{paths.business_dictionary}` and `{paths.core_entities}`:
356
+
357
+ 1. **Banned terms in steps** → **critical**, auto-fixable in `--resume`
358
+ 2. **Non-canonical entity names** → **major**, auto-fixable
359
+ 3. **Non-canonical field names in data tables** → **major**, auto-fixable
360
+ 4. **Technically-looking sample data** (UUIDs, `item_123`) → **minor**, auto-fixable
361
+
362
+ ### B3 — Gherkin Rules Check (R1–R10)
363
+
364
+ | Rule | Check | Auto-fixable? |
365
+ |------|-------|---------------|
366
+ | R1 | Every scenario has Given + When + Then | No — needs scenario redesign |
367
+ | R2 | No chained `When … Then … When` | No — needs redesign |
368
+ | R3 | No UI selectors / API paths / tech terms in steps | Yes — replace with business phrasing |
369
+ | R4 | Scenario name is a business outcome | No — needs human rename |
370
+ | R5 | Declarative WHAT, not imperative HOW | No — needs rewrite |
371
+ | R6 | `Then` asserts observable business outcome | No — needs redesign |
372
+ | R7 | Concrete values, not "valid data" | Yes — substitute realistic values |
373
+ | R8 | Each scenario is independently runnable | No — needs redesign |
374
+ | R9 | Data tables have enough columns for Then | Yes — add missing columns |
375
+ | R10 | Cross-UC reference uses navigation phrasing + Note | Yes — add Note comment |
376
+
377
+ → R3, R7, R9, R10 violations: auto-fixable. Others require human guidance via Review Board note.
378
+
379
+ ### B4 — Compliance Checks (C.1–C.5)
380
+
381
+ - [ ] C.1 Wireframe Coverage: every screen component/action has ≥1 SC → finding per missing item
382
+ - [ ] C.2 PRD Traceability: same as B1 (deduplicate)
383
+ - [ ] C.3 Business Dictionary terms used → same as B2
384
+ - [ ] C.4 Banned Terms: 0 banned terms → **critical**, auto-fixable
385
+ - [ ] C.5 NHÓM Grouping: if ≥3 SCs, grouped by business theme → **major**, auto-fixable
386
+
387
+ ### B5 — Metadata & Structural Check
388
+
389
+ - [ ] File header has all `@trace.*` fields → **minor**, auto-fixable
390
+ - [ ] Every scenario has `# @trace.scenario`, `# @trace.sc_version`, `# @trace.business_rules`, `# Side-effects:` → **minor**, auto-fixable
391
+ - [ ] Coverage Matrix at end of file → **major**, auto-fixable (AI regenerates)
392
+ - [ ] Pre-merge Checklist at end of file → **minor**, auto-fixable
393
+
394
+ ### B6 — Side-effect Completeness
395
+
396
+ For each `@happy` scenario:
397
+ - `# Side-effects:` comment lists all observable side effects
398
+ - `Then` block has `And <side-effect>` for each listed side effect
399
+
400
+ → Missing side-effect assertion: **major**, auto-fixable.
401
+
402
+ ---
403
+
404
+ ## Write Findings File
405
+
406
+ After running all checks, write `{paths.refinement_dir}/{slug}-review-*-findings.yaml`:
407
+
408
+ ```yaml
409
+ source_file: "{absolute path to reviewed file}"
410
+ generated_at: "{ISO datetime}"
411
+ review_type: "{prd | bdd}"
412
+ status: "pending_review"
413
+
414
+ findings:
415
+ - id: "F001"
416
+ check_id: "P1" # P1-P5 for PRD; B1-B6 for BDD
417
+ severity: "critical" # critical | major | minor
418
+ section: "{section or scenario ID where issue was found}"
419
+ finding: "{clear description of the issue}"
420
+ suggestion: "{specific actionable fix — AI will apply this in --resume if accepted}"
421
+ auto_fixable: true # true = AI can apply; false = human must write note in Review Board
422
+ status: "pending" # pending | accepted | modified | rejected | deferred
423
+
424
+ summary:
425
+ total_findings: {N}
426
+ by_severity: { critical: {N}, major: {N}, minor: {N} }
427
+ auto_fixable: {N}
428
+ requires_human_decision: {N}
429
+ recommendation: "APPROVED | NEEDS_REVISION | BLOCKED"
430
+ ```
431
+
432
+ ## Post-Analysis Routing
433
+
434
+ After running all checks and writing the findings file:
435
+
436
+ **If `--fix` flag present** → jump to Fix Mode (apply `auto_fixable: true` findings immediately).
437
+
438
+ **If no flag** → print Report below and stop.
439
+
440
+ ## Report
441
+
442
+ # Report Footer — Standard Command Output Format
443
+
444
+ Every command report must end with this standard footer section.
445
+
446
+ ## Status Badge
447
+
448
+ Choose one based on outcome:
449
+ - `✅ Complete` — all steps succeeded, no issues found
450
+ - `❌ Failed` — command could not complete due to a blocking error
451
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
452
+
453
+ ## Output Artifacts
454
+
455
+ List every file created or modified by this command:
456
+ ```
457
+ Output Artifacts:
458
+ {created|updated} {file-path} ({brief description})
459
+ {created|updated} {file-path} ({brief description})
460
+ ```
461
+
462
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
463
+
464
+ ## Next Command Suggestion
465
+
466
+ Suggest the logical next command based on workflow phase:
467
+
468
+ | Current command | Suggest next |
469
+ |-------------------------|-----------------------------------------------|
470
+ | /define-product | `/generate-prd {product-definition-file}` |
471
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
472
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
473
+ | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
474
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
475
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
476
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
477
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
478
+ | /generate-code | `/generate-tests {UC-ID}` |
479
+ | /generate-tests | `/run-tests {UC-ID}` |
480
+ | /run-tests (passing) | `/review-code {UC-ID}` |
481
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
482
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
483
+ | /smoke-test | Create PR and link to ticket |
484
+ | /validate-traces | `/generate-code {UC-ID}` for gaps |
485
+ | /fix-bug | Create PR and link to ticket |
486
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
487
+
488
+ Format the footer as:
489
+ ```
490
+ ---
491
+ Status : {badge}
492
+ {Output Artifacts block}
493
+ Next : {suggested command with example arguments}
494
+ ```
495
+
496
+
497
+ ```
498
+ /review-context Complete — {target file}
499
+ Mode: {PRD | BDD}
500
+ Findings: {total} | 🔴 Critical: {N} | 🟡 Major: {N} | 🟢 Minor: {N}
501
+ Auto-fixable: {N} | Needs human decision: {N}
502
+
503
+ Findings file: {paths.refinement_dir}/{slug}-findings.yaml
504
+
505
+ Next options:
506
+ A) Quick fix : /review-context --fix {target-file}
507
+ → applies all auto-fixable findings immediately
508
+ B) Review Board: open findings file → accept/modify/reject
509
+ → /review-context --resume {target-file}
510
+ ```
511
+
512
+ ---
513
+
514
+ ## Fix Mode — Apply Auto-Fixable Findings Immediately
515
+
516
+ *Triggered when `$ARGUMENTS` contains `--fix`.*
517
+ *Example: `/review-context --fix specs/bdd/payment/PAY-001.feature`*
518
+
519
+ This mode runs the full analysis (same as default), then immediately applies every
520
+ `auto_fixable: true` finding without going through the Review Board.
521
+
522
+ Use for: BDD cleanup, terminology fixes, metadata gaps — anything the AI can safely
523
+ correct without a human judgment call. Findings requiring human decisions are written
524
+ to the findings file as usual and left `status: pending`.
525
+
526
+ ### Phase 1 — Run analysis
527
+
528
+ Run all checks (P1–P5 or B1–B6) exactly as in the default mode.
529
+ Write the findings file with all `status: "pending"` as usual.
530
+
531
+ ### Phase 2 — Apply auto-fixable findings
532
+
533
+ For each finding where `auto_fixable: true`, in order (critical → major → minor):
534
+
535
+ **For PRD files:**
536
+
537
+ | check_id | What to apply |
538
+ |----------|--------------|
539
+ | P1 (Banned term) | Replace every banned term occurrence with canonical term |
540
+ | P4 (Structure) | Add missing section/metadata skeleton |
541
+
542
+ **For BDD files:**
543
+
544
+ | check_id | What to apply |
545
+ |----------|--------------|
546
+ | B2 (Terminology) | Replace banned terms, fix entity/field names, fix technical sample data |
547
+ | B3 R3 | Replace tech terms/UI selectors with business phrasing |
548
+ | B3 R7 | Substitute concrete realistic values |
549
+ | B3 R9 | Add missing data table columns |
550
+ | B3 R10 | Add cross-UC navigation Note comment |
551
+ | B4 C4 | Fix banned terms in tags |
552
+ | B4 C5 | Add NHÓM grouping if ≥3 SCs |
553
+ | B5 | Add missing @trace headers, regenerate Coverage Matrix / Pre-merge Checklist |
554
+ | B6 | Add missing `And <side-effect>` to Then blocks |
555
+
556
+ After applying each finding, mark it `status: "applied_automatically"` in the findings file.
557
+
558
+ ### Phase 3 — Version bump
559
+
560
+ - **PRD**: if ≥1 finding applied → bump minor version, add Changelog entry:
561
+ `Auto-fix: applied {N} auto-fixable review-context findings`
562
+ - **BDD**: if ≥1 finding applied → increment `@trace.bdd_version` by 0.1
563
+
564
+ ### Phase 4 — Report
565
+
566
+ ```
567
+ /review-context --fix Applied — {target file}
568
+ Mode: {PRD | BDD}
569
+
570
+ Auto-fixed : {N} findings ({critical} critical, {major} major, {minor} minor)
571
+ - {change 1 summary}
572
+ - {change 2 summary}
573
+
574
+ Still pending (needs human decision): {N}
575
+ - F00X [{severity}] {finding summary} ← open findings file in Review Board
576
+
577
+ {If PRD}: Version bumped: {old} → {new}
578
+ {If BDD}: bdd_version: {old} → {new}
579
+
580
+ Findings file: {paths.refinement_dir}/{slug}-findings.yaml
581
+ Re-run /review-context {file} to confirm 0 remaining critical findings.
582
+ ```
583
+
584
+ If 0 findings were auto-fixable → print:
585
+ ```
586
+ Nothing to auto-fix. All {N} findings require human decision.
587
+ Open findings file in Review Board → then run: /review-context --resume {file}
588
+ ```
589
+
590
+ ---
591
+
592
+ ## Resume Mode — Apply Accepted Findings
593
+
594
+ *Triggered when `$ARGUMENTS` contains `--resume`.*
595
+ *Example: `/review-context --resume specs/prd/payment/PAY-001.md`*
596
+
597
+ ### Phase 1 — Read accepted findings
598
+
599
+ 1. Derive findings filename from target file (same rule as above).
600
+ 2. Read `{paths.refinement_dir}/{slug}-findings.yaml`.
601
+ 3. Collect findings where `status: "accepted"` or `status: "modified"`.
602
+ 4. If none → report "No accepted findings. File unchanged." and stop.
603
+
604
+ ### Phase 2 — Apply fixes
605
+
606
+ Apply in order: critical → major → minor.
607
+
608
+ **For PRD findings:**
609
+ | check_id | What to do |
610
+ |----------|-----------|
611
+ | P1 (Banned term) | Replace every occurrence of banned term with canonical term |
612
+ | P2 (Ambiguity) | Apply the fix stated in `suggestion` or `modified` note |
613
+ | P3 (Conflict) | Apply the resolution stated in the modified note |
614
+ | P4 (Structure) | Add the missing section/metadata field |
615
+ | P5 (Custom) | Apply as stated in suggestion/note |
616
+
617
+ → After applying, bump PRD version (minor) and add Changelog entry.
618
+
619
+ **For BDD findings:**
620
+ | check_id | What to do |
621
+ |----------|-----------|
622
+ | B1 (Coverage gap) | Generate new scenario(s) for the uncovered AC/BR and insert into correct NHÓM |
623
+ | B2 (Terminology) | Replace banned terms, fix entity/field names |
624
+ | B3 (Gherkin rule) | Apply rule-specific fix (replace tech terms, add concrete values, etc.) |
625
+ | B4 (Compliance) | Add NHÓM grouping, fix @trace tags |
626
+ | B5 (Metadata) | Add missing @trace headers, regenerate Coverage Matrix / Pre-merge Checklist |
627
+ | B6 (Side effects) | Add missing `And <side-effect>` to Then block |
628
+
629
+ → After applying, increment `@trace.bdd_version` in file header by 0.1.
630
+
631
+ ### Phase 3 — Report
632
+
633
+ ```
634
+ /review-context --resume Applied — {target file}
635
+ Applied : {N} findings ({critical} critical, {major} major, {minor} minor)
636
+ Skipped : {N} rejected/deferred
637
+
638
+ Changes:
639
+ - {change 1 summary}
640
+ - {change 2 summary}
641
+
642
+ {If PRD}: Version bumped: {old} → {new}
643
+ {If BDD}: bdd_version: {old} → {new}
644
+
645
+ Re-run /review-context {file} to confirm 0 remaining critical findings.
646
+ ```