@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,294 @@
1
+ # /generate-bdd — Generate BDD Feature Files
2
+
3
+ ## Gate
4
+ {{include:steps/gate.md}}
5
+
6
+ ## Context
7
+ {{include:steps/context-loader.md}}
8
+
9
+ ---
10
+
11
+ ## Orchestration Check
12
+
13
+ *Skip this section if already in sub-agent mode (Step 0 of Gate was triggered).*
14
+
15
+ After loading context, check if the target PRD is large enough to warrant sub-agents:
16
+
17
+ 1. Count `#### {TICKET-ID}-UC` headings in the PRD → **UC count**.
18
+ 2. Count total lines in the PRD → **line count**.
19
+ 3. If **UC count > 3** OR **line count > 300**:
20
+ - Switch to orchestration mode — follow `steps/spawn-agent.md`.
21
+ - The main session becomes the orchestrator: spawn 1 sub-agent per UC.
22
+ - Each sub-agent runs `/generate-bdd` with `_agent_mode: true` payload.
23
+ - Collect results and show merged report.
24
+ - **Do NOT continue with the steps below.**
25
+ 4. If UC count ≤ 3 AND line count ≤ 300 → continue with Version Check below (single-session mode).
26
+
27
+ ---
28
+
29
+ ## Version Check
30
+
31
+ Before generating, check for existing `.feature` files for this PRD:
32
+
33
+ 1. Look for `{paths.specs_dir}/{domain}/{TICKET-ID}-UC*.feature`.
34
+ 2. Read current PRD `| **Version** |` from metadata (e.g., `1.2`).
35
+
36
+ **If no existing feature files** → fresh generation, proceed normally. Use PRD version as `@trace.prd_version`.
37
+
38
+ **If existing feature files found**:
39
+ - Read `# @trace.prd_version:` from the existing feature file header.
40
+ - Compare with current PRD version.
41
+ - If **same** → ask: "BDD already generated from PRD v{version}. Regenerate? (Y/N)"
42
+ - If **different** (PRD was updated):
43
+ 1. Read `## Changelog` from the PRD — extract all rows newer than the existing BDD's `@trace.prd_version`.
44
+ 2. Show CHECKPOINT:
45
+ ```
46
+ ⚠️ PRD version drift detected
47
+ BDD was generated from PRD v{old}
48
+ PRD is now at v{new}
49
+
50
+ Changes since v{old}:
51
+ {changelog rows}
52
+
53
+ Options:
54
+ Y — update only affected scenarios
55
+ F — full regeneration of all scenarios
56
+ N — cancel
57
+ ```
58
+ 3. Proceed based on user choice.
59
+
60
+ ---
61
+
62
+ ## BDD Writing Rules (R1-R10 — enforce strictly)
63
+
64
+ | Rule | Name | Requirement |
65
+ |------|------|-------------|
66
+ | R1 | Given/When/Then Semantics | Given=state, When=action, Then=outcome. Every SC needs full G/W/T. |
67
+ | R2 | One Behavior Per Scenario | 1 SC = 1 behavior. Do NOT chain When→Then→When→Then. |
68
+ | R3 | Ubiquitous Language | Do NOT use UI selectors / API names / tech terms in steps. |
69
+ | R4 | Outside-in Naming | SC name describes business outcome. No "click" / "(Case X)" / component names. |
70
+ | R5 | Declarative over Imperative | Describe WHAT (business intent), NOT HOW (UI mechanic). |
71
+ | R6 | Observable Outcomes Only | Then asserts observable outcome. Not UI intermediate state / internal state. |
72
+ | R7 | Key Examples / Concrete | Use concrete values. Not vague "valid data". |
73
+ | R8 | Independence | SC runs independently. Does not depend on state from another SC. |
74
+ | R9 | Test Data Completeness | Data table has enough fields to derive expected Then. |
75
+ | R10 | Scope Boundary Explicit | Cross-UC reference uses navigation wording + Note comment. |
76
+
77
+ ## Project Compliance (fail review if missing — C.1-C.5)
78
+
79
+ | Check | Rule |
80
+ |-------|------|
81
+ | C.1 Wireframe Coverage | Every component/action in Wireframe has ≥1 SC. |
82
+ | C.2 PRD Traceability | Every AC and every BR (including each logic bullet) maps to ≥1 SC. |
83
+ | C.3 Business Dictionary | Use correct canonical terms from business-dictionary.md. |
84
+ | C.4 Banned Terms | 0 banned terms in file — grep before generating. |
85
+ | C.5 NHÓM Grouping | Feature ≥3 SCs → MUST have NHÓM grouping by business theme. |
86
+
87
+ ---
88
+
89
+ ## NHÓM Grouping Convention (C.5 — mandatory for ≥3 scenarios)
90
+
91
+ Group by business theme, NOT by happy/negative/edge.
92
+
93
+ Format header (indent 2 spaces, same level as Background):
94
+ ```
95
+ # ==========================================================
96
+ # NHÓM N: <Business theme> (<BR refs if applicable>)
97
+ # ==========================================================
98
+ ```
99
+
100
+ Rules:
101
+ - Number sequentially NHÓM 1 → N. SC IDs sequential across lifecycle (do not reset per NHÓM).
102
+ - Each NHÓM can contain @happy + @edge + @negative of the same theme.
103
+ - SCs in NHÓM do not need to be in ID order (NHÓM 2 can contain SC4, SC8, SC11 if same theme).
104
+
105
+ Suggested patterns (adjust per UC):
106
+ - `Init / Save success — valid data combinations`
107
+ - `Validation / Block when invalid`
108
+ - `Error handling — API fail / system error`
109
+ - `Cancel changes / Close modal without saving`
110
+ - `Cross-system / Downstream effects`
111
+ - `Idempotency & Concurrency`
112
+
113
+ ---
114
+
115
+ ## UC Decomposition
116
+
117
+ For each UC in the PRD, present the SC outline **before generating**:
118
+ ```
119
+ {TICKET-ID}-UC1: {Use Case Name}
120
+ NHÓM 1: {Theme} (BR1, BR2)
121
+ SC1 [@happy]: {business outcome}
122
+ SC2 [@happy @alternative]: {variant outcome}
123
+ NHÓM 2: {Theme} (BR2, BR3)
124
+ SC3 [@edge]: {edge case}
125
+ SC4 [@negative]: {error handling}
126
+ ACs covered: AC1, AC2
127
+ BRs covered: {TICKET-ID}-UC1-BR1, BR2, BR3
128
+ ```
129
+
130
+ CHECKPOINT: "Does this outline look correct? Do you want to add or remove any SCs?" → **Wait for confirm before generating.**
131
+
132
+ ---
133
+
134
+ ## Generate
135
+
136
+ For each UC, write `{paths.specs_dir}/{domain}/{TICKET-ID}-UC{N}-{slug}.feature`:
137
+
138
+ ```gherkin
139
+ # ============================================================
140
+ # @trace.id: {TICKET-ID}-UC{N}
141
+ # @trace.title: <Feature name>
142
+ # @trace.revision: 1
143
+ # @trace.domain: <domain>
144
+ # @trace.service: <ServiceName>
145
+ # @trace.status: draft
146
+ # @trace.author: AI-generated
147
+ # @trace.created_at: {YYYY-MM-DD}
148
+ # @trace.prd: {TICKET-ID}
149
+ # @trace.prd_version: {read from PRD metadata "| **Version** |"}
150
+ # @trace.bdd_version: {1 if fresh generation; increment by 1 if re-generation}
151
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR1, {TICKET-ID}-UC{N}-BR2
152
+ # @trace.dataset: {domain}.testdata.yaml
153
+ # ============================================================
154
+
155
+ # === CONTEXT ===
156
+ # Actor: <role performing the action, e.g., Consumer, Staff, System>
157
+ # Screens: <related screens, e.g., Cart → Confirm Order → Order Detail>
158
+ # Entities: <business entities, e.g., Order, OrderItem, Consumer>
159
+ # Pre-state: <shared state before entering scenarios>
160
+
161
+ # === SCOPE ===
162
+ # In: <what this UC covers>
163
+ # Out: <what is NOT in this UC — link to other UC/feature (R10)>
164
+
165
+ # === BUSINESS DEFINITION ===
166
+ # Quick reference for terms used in this feature. SoT details: business-dictionary.md
167
+ # <Term 1>: <short definition>
168
+ # <Term 2>: <short definition>
169
+
170
+ Feature: <Feature name>
171
+ As a <role>
172
+ I want to <action>
173
+ So that <business value>
174
+
175
+ Background:
176
+ Given <shared precondition — use aliases from dataset, not technical IDs>
177
+
178
+ # ==========================================================
179
+ # NHÓM 1: <Business theme> (<BR refs>)
180
+ # ==========================================================
181
+
182
+ # Side-effects: <list brief Then side-effects to verify>
183
+ # @trace.scenario: {TICKET-ID}-UC{N}-SC1
184
+ # @trace.sc_version: 1.0
185
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
186
+ @happy
187
+ Scenario: <describe business outcome — use precise verb: create/receive/assign/block>
188
+ Given <input state — alias from dataset>
189
+ When <single action>
190
+ Then <main observable outcome>
191
+ And <side-effect 1 declared in header>
192
+
193
+ # Side-effects: <...>
194
+ # @trace.scenario: {TICKET-ID}-UC{N}-SC2
195
+ # @trace.sc_version: 1.0
196
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
197
+ @happy @alternative
198
+ Scenario: <same NHÓM 1 theme but different path — e.g., different enum value>
199
+ Given <state>
200
+ When <action>
201
+ Then <outcome>
202
+
203
+ # ==========================================================
204
+ # NHÓM 2: <Business theme 2> (<BR refs>)
205
+ # ==========================================================
206
+
207
+ # Side-effects: <...>
208
+ # @trace.scenario: {TICKET-ID}-UC{N}-SC3
209
+ # @trace.sc_version: 1.0
210
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR2
211
+ @edge
212
+ Scenario: <boundary / error scenario>
213
+ Given <state>
214
+ When <action>
215
+ Then <expected error handling>
216
+ ```
217
+
218
+ ### Coverage Matrix & Pre-merge Checklist *(appended to end of each file)*
219
+
220
+ ```gherkin
221
+ # === PRD COVERAGE (C.1 + C.2) ===
222
+ # AC mapping:
223
+ # AC1 (...) → SC1, SC2
224
+ # AC2 (...) → SC3
225
+ # BR mapping (each bullet MUST have ≥1 SC — C.2):
226
+ # {TICKET-ID}-UC{N}-BR1 (...) → SC1, SC2
227
+ # {TICKET-ID}-UC{N}-BR2 (...) → SC3
228
+ # Wireframe mapping (every component/action ≥1 SC — C.1):
229
+ # Screen "<screen name>":
230
+ # [x] <action 1> → SC1
231
+ # [x] <action 2> → SC2
232
+ # [ ] <action 3> → MISSING ← BLOCK MERGE
233
+
234
+ # === PRE-MERGE CHECKLIST ===
235
+ # - [ ] Every SC has Side-effects + @trace.scenario + @trace.sc_version + @trace.business_rules
236
+ # - [ ] Coverage Matrix: 0 MISSING lines (C.1)
237
+ # - [ ] Every AC/BR maps to ≥1 SC (C.2)
238
+ # - [ ] 0 banned terms (C.4) — grep file before merging
239
+ # - [ ] Feature ≥3 SCs has NHÓM grouping by business theme (C.5)
240
+ # - [ ] If popup/modal: Popup/Modal Lifecycle declared in BUSINESS DEFINITION
241
+ # - [ ] If display logic ≥2 dimensions: Display Logic Matrix in BUSINESS DEFINITION
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Write Trace State
247
+
248
+ After generating all `.feature` files, create or update `{paths.trace_dir}/{UC-ID}.tsv` for each UC.
249
+
250
+ **TSV columns (tab-separated, one header row + one data row per scenario):**
251
+ ```
252
+ sc_id\tsc_title\tspec_ver\tgen_ver\timplemented_by\ttest_count\ttest_classes\tprd_version\tbdd_version\ttech_doc_revision\tprd_status\tuc_status\tstatus\tlast_updated
253
+ ```
254
+
255
+ **Rules:**
256
+ - If file does not exist → create with header row + all scenario rows.
257
+ - If file exists (re-generation) → for each SC in the new `.feature`:
258
+ - SC already in `.tsv` → update only: `sc_title`, `spec_ver`, `prd_version`, `bdd_version`, `prd_status`, `uc_status`, `last_updated`. Leave `gen_ver`, `implemented_by`, `test_count`, `test_classes`, `tech_doc_revision` unchanged.
259
+ - SC is new (added in this re-gen) → append new row with `gen_ver`, `implemented_by`, `test_count`, `test_classes`, `tech_doc_revision` all set to `—`.
260
+ - SC no longer in `.feature` (removed) → delete its row.
261
+
262
+ **Values to write for each scenario:**
263
+
264
+ | Column | Value |
265
+ |--------|-------|
266
+ | `sc_id` | `{UC-ID}-SC{N}` |
267
+ | `sc_title` | scenario title text |
268
+ | `spec_ver` | `@trace.sc_version` of this scenario |
269
+ | `gen_ver` | `—` (not yet generated) |
270
+ | `implemented_by` | `—` |
271
+ | `test_count` | `—` |
272
+ | `test_classes` | `—` |
273
+ | `prd_version` | `@trace.prd_version` from `.feature` header |
274
+ | `bdd_version` | `@trace.bdd_version` from `.feature` header |
275
+ | `tech_doc_revision` | `—` |
276
+ | `prd_status` | read `\| **Status** \|` from PRD metadata |
277
+ | `uc_status` | `draft` for new UCs; keep existing value for re-gen |
278
+ | `status` | `UNTRACKED` |
279
+ | `last_updated` | today `YYYY-MM-DD` |
280
+
281
+ ## Output
282
+
283
+ {{include:steps/report-footer.md}}
284
+
285
+ ```
286
+ /generate-bdd Complete
287
+ Files:
288
+ {paths.specs_dir}/{domain}/{TICKET-ID}-UC1-{slug}.feature ({N} scenarios)
289
+ {paths.specs_dir}/{domain}/{TICKET-ID}-UC2-{slug}.feature ({N} scenarios)
290
+ Trace:
291
+ {paths.trace_dir}/{TICKET-ID}-UC1.tsv ({N} rows)
292
+ {paths.trace_dir}/{TICKET-ID}-UC2.tsv ({N} rows)
293
+ Next: /generate-tech-docs OR /generate-code {paths.specs_dir}/{domain}/{TICKET-ID}-UC{N}-{slug}.feature
294
+ ```
@@ -0,0 +1,395 @@
1
+ # /generate-code — Generate Implementation Code
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-5 (or claude-opus-4)
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 in Step 1 is a `.feature` file or UC-ID. If `$ARGUMENTS` is a UC-ID, find the matching feature file under `{paths.specs_dir}/`. Also check `{paths.trace_dir}/{UC-ID}.tsv` for drift (new vs drifted vs synced).*
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
+
135
+ If `paths` section is absent, use these defaults:
136
+ - `specs_dir` = `specs/bdd`
137
+ - `prd_dir` = `specs/prd`
138
+ - `refinement_dir` = `.agent/review`
139
+ - `product_definitions_dir` = `specs/product-definition`
140
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
141
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
142
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
143
+ - `tech_docs_dir` = `tech-docs`
144
+ - `trace_dir` = `.trace`
145
+
146
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
147
+
148
+ ---
149
+
150
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
151
+
152
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
153
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
154
+ If the file does not exist → skip silently.
155
+
156
+ ---
157
+
158
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
159
+
160
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
161
+
162
+ Read `CLAUDE.md`. Extract and store:
163
+
164
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
165
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
166
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
167
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
168
+ - **§7 Git Conventions** → branch naming pattern, commit message format
169
+
170
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
171
+
172
+ ---
173
+
174
+ ## Step 4 — [SAFETY] Load Data Protection Rules
175
+
176
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
177
+
178
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
179
+
180
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
181
+
182
+ ---
183
+
184
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
185
+
186
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
187
+
188
+ If it exists, read it and extract:
189
+ - **Canonical Terms** → complete list of approved terms and their definitions
190
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
191
+ - **Status / Enum Registry** → allowed enum values per entity
192
+
193
+ Store the banned terms list for **active enforcement** throughout the command session:
194
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
195
+ - Replace banned terms with their canonical equivalents automatically
196
+
197
+ If the file does not exist → skip silently. Do not warn or block.
198
+
199
+ ---
200
+
201
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
202
+
203
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
204
+ Default path: `specs/domain-knowledge/core-entities.md`.
205
+
206
+ If it exists, read it and store:
207
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
208
+ - **Field name registry** → canonical field names to use in generated code and documents
209
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
210
+
211
+ **How to use this catalog:**
212
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
213
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
214
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
215
+
216
+ If the file does not exist → skip silently.
217
+
218
+ ---
219
+
220
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
221
+
222
+ After loading all context, synthesize and output a compact summary block.
223
+ This recap ensures the most critical facts are stated at the END of context loading
224
+ (recency effect — freshest in working memory when the task begins).
225
+
226
+ Output exactly this block:
227
+ ```
228
+ [CTX LOADED]
229
+ Stack : {language} / {framework} / {database}
230
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
231
+ Ticket : {ticket_prefix}-
232
+ Dict : {loaded — N canonical terms, M banned terms | missing}
233
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
234
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
235
+ ```
236
+
237
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
238
+
239
+ ---
240
+
241
+ ## Context Load Complete
242
+
243
+ After completing all steps, you have loaded:
244
+ - Project identity, tech stack, module conventions
245
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
246
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
247
+ - Data protection rules (sensitive file patterns to never access)
248
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
249
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
250
+ - All configured paths
251
+
252
+ Proceed to the next step of the calling command.
253
+
254
+
255
+ ---
256
+
257
+ ## CHECKPOINT — Code Generation Plan
258
+
259
+ Before generating any code, show:
260
+ ```
261
+ I understand:
262
+ - Feature: {name} | Ticket: {ID if known}
263
+ - UC: {UC-ID} | Domain: {domain}
264
+ - Scenarios: {N} total ({X} new, {Y} drifted, {Z} synced-skip)
265
+ - Layer order: {from CLAUDE.md §2 architecture}
266
+ - Tech stack: {language} / {framework}
267
+ - Files to create: [list]
268
+ Proceed? (Y/N)
269
+ ```
270
+
271
+ Wait for explicit "Y" before generating.
272
+
273
+ ## Context Load (additional)
274
+ Read: `.feature` file, tech-doc (if exists at `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`), CLAUDE.md §architecture + §coding_standards, existing entity files.
275
+
276
+ ## Branch
277
+ ```bash
278
+ git checkout -b feature/{TICKET_ID}-{slug}
279
+ ```
280
+
281
+ ## Generate (layer order from CLAUDE.md §2)
282
+
283
+ Default order (override from CLAUDE.md if different):
284
+ DTOs → Entity/Model → Repository → Service interface → Service impl → Facade (if applicable) → Controller
285
+
286
+ **Controller must have traceability tags (adapt to your language's comment syntax):**
287
+ ```
288
+ @trace.implements={UC-ID}-SC{N}
289
+ @trace.prd_version={read @trace.prd_version from the .feature file header}
290
+ @trace.bdd_version={read @trace.bdd_version from the .feature file header}
291
+ @trace.tech_doc_revision={read @trace.revision from tech-doc header, or omit if no tech-doc}
292
+ @trace.source={paths.specs_dir}/{domain}/{UC-ID}.feature
293
+ ```
294
+
295
+ `@trace.prd_version` records which PRD version this code was written against.
296
+ `@trace.bdd_version` records which BDD version this code was generated from.
297
+ `@trace.tech_doc_revision` records which tech-design revision this code follows.
298
+ `/validate-traces` will flag drift if any upstream artifact is updated to a newer version.
299
+
300
+ ## Self-Review (3 rounds)
301
+ - [ ] Every scenario has a corresponding endpoint
302
+ - [ ] @trace.implements on every endpoint
303
+ - [ ] Architecture layer rules respected (CLAUDE.md §2)
304
+ - [ ] Error handling matches CLAUDE.md §5
305
+ - [ ] No magic numbers, no debug logging
306
+
307
+ ## Build Verify
308
+ ```bash
309
+ {conventions.build_command} # from project-context.yaml, max 3 retries
310
+ ```
311
+
312
+ ## Write Trace State
313
+
314
+ Update `{paths.trace_dir}/{UC-ID}.tsv` — for each implemented scenario, find the existing row by `sc_id` and update only these columns:
315
+
316
+ | Column | Value |
317
+ |--------|-------|
318
+ | `gen_ver` | copy `spec_ver` from the current `.tsv` row (= scenario version at time of codegen) |
319
+ | `implemented_by` | `{ControllerClass}.{methodName}` |
320
+ | `bdd_version` | `@trace.bdd_version` from `.feature` header |
321
+ | `tech_doc_revision` | `@trace.revision` from tech-doc header, or `—` if no tech-doc |
322
+ | `last_updated` | today `YYYY-MM-DD` |
323
+
324
+ Leave all other columns (`sc_title`, `spec_ver`, `prd_version`, `prd_status`, `uc_status`, `test_count`, `test_classes`) unchanged.
325
+ `status` is computed by `/validate-traces` — do not set here.
326
+
327
+ ## Commit
328
+ ```bash
329
+ git add {files}
330
+ git commit -m "{commit_format}: {description}"
331
+ ```
332
+
333
+ ## Output
334
+
335
+ # Report Footer — Standard Command Output Format
336
+
337
+ Every command report must end with this standard footer section.
338
+
339
+ ## Status Badge
340
+
341
+ Choose one based on outcome:
342
+ - `✅ Complete` — all steps succeeded, no issues found
343
+ - `❌ Failed` — command could not complete due to a blocking error
344
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
345
+
346
+ ## Output Artifacts
347
+
348
+ List every file created or modified by this command:
349
+ ```
350
+ Output Artifacts:
351
+ {created|updated} {file-path} ({brief description})
352
+ {created|updated} {file-path} ({brief description})
353
+ ```
354
+
355
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
356
+
357
+ ## Next Command Suggestion
358
+
359
+ Suggest the logical next command based on workflow phase:
360
+
361
+ | Current command | Suggest next |
362
+ |-------------------------|-----------------------------------------------|
363
+ | /define-product | `/generate-prd {product-definition-file}` |
364
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
365
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
366
+ | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
367
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
368
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
369
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
370
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
371
+ | /generate-code | `/generate-tests {UC-ID}` |
372
+ | /generate-tests | `/run-tests {UC-ID}` |
373
+ | /run-tests (passing) | `/review-code {UC-ID}` |
374
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
375
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
376
+ | /smoke-test | Create PR and link to ticket |
377
+ | /validate-traces | `/generate-code {UC-ID}` for gaps |
378
+ | /fix-bug | Create PR and link to ticket |
379
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
380
+
381
+ Format the footer as:
382
+ ```
383
+ ---
384
+ Status : {badge}
385
+ {Output Artifacts block}
386
+ Next : {suggested command with example arguments}
387
+ ```
388
+
389
+
390
+ ```
391
+ /generate-code Complete — {UC-ID}
392
+ Files: created={N}, updated={M} | Build: SUCCESS
393
+ Branch: feature/{TICKET_ID}-{slug}
394
+ Next: /review-code OR /generate-tests {UC-ID}
395
+ ```