@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,529 @@
1
+ # /validate-traces — Traceability Coverage Matrix
2
+
3
+ Read-only check of coverage between specs, code, and tests — including PRD version drift.
4
+
5
+ ## Gate
6
+ # Gate — Universal Entry Procedure
7
+
8
+ Every command must execute this gate before proceeding with its specific logic.
9
+
10
+ ## Step 0 — Sub-Agent Mode Check
11
+
12
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
13
+
14
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
15
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
16
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
17
+ - Set target file = `payload.target_file`
18
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
19
+ - Set UC scope = `payload.uc_id` (process only this UC)
20
+ - Set line range = `payload.uc_section` (read only that PRD section)
21
+ - Proceed directly to the command-specific logic.
22
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
23
+
24
+ ## Step 0-B — Model Check
25
+
26
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
27
+
28
+ Complex generation and review commands require strong reasoning.
29
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
30
+
31
+ Display and wait for response:
32
+
33
+ ```
34
+ ⚙️ MODEL CHECK
35
+ ──────────────────────────────────────────────────────────────────
36
+ Recommended : claude-opus-4-5 (or claude-opus-4)
37
+ Why needed : Spec analysis, architecture review, code generation
38
+ require deep reasoning. Smaller models miss edge cases.
39
+
40
+ To switch in Claude Code:
41
+ • Settings → Model → select "claude-opus"
42
+ • or: /model → choose claude-opus
43
+
44
+ Running on claude-opus?
45
+ Y — yes, on claude-opus → proceed
46
+ S — skip check (I accept lower quality risk with current model)
47
+ ──────────────────────────────────────────────────────────────────
48
+ ```
49
+
50
+ - "Y" → proceed to Step 1.
51
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
52
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
53
+
54
+ ## Step 1 — Resolve Target File
55
+
56
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
57
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
58
+ 3. If `$ARGUMENTS` is empty or no match found:
59
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
60
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
61
+ - Wait for user selection before continuing.
62
+
63
+ ## Step 2 — Execute Context Loader
64
+
65
+ Load all project context by following the procedure in `steps/context-loader.md`.
66
+ Store all loaded context in memory for use throughout this command session.
67
+
68
+ ## Step 3 — CHECKPOINT
69
+
70
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
71
+
72
+ ```
73
+ CHECKPOINT
74
+ -----------
75
+ Target : {resolved file path}
76
+ Project : {project.name from project-context.yaml}
77
+ Tech stack : {language} / {framework}
78
+ Module : {module if set, else "not configured"}
79
+ Domains : {comma-separated domain list}
80
+
81
+ Proceed? (Y/N)
82
+ ```
83
+
84
+ Wait for explicit "Y" or "N" from the user before continuing.
85
+ - "Y" → proceed to the command-specific steps below.
86
+ - "N" → stop and ask what the user wants to change.
87
+
88
+
89
+ *Note: For this command, the target in Step 1 is a domain name or specific UC-ID from `$ARGUMENTS`. There is no single file to resolve — the command scans multiple directories.*
90
+
91
+ ## Context
92
+ # Context Loader — Load All Project Context
93
+
94
+ Execute these steps in order. Store everything in memory for the duration of the command session.
95
+
96
+ **Priority guide (anti-lost-in-middle):**
97
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
98
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
99
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
100
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
101
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
102
+
103
+ ---
104
+
105
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
106
+
107
+ Read `.agent/project-context.yaml`. Extract and store:
108
+
109
+ **Tech Stack:**
110
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
111
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
112
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
113
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
114
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
115
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
116
+
117
+ **Conventions:**
118
+ - `conventions.build_command` → how to compile/build
119
+ - `conventions.test_command` → how to run tests
120
+ - `conventions.service_run` → how to start the service
121
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
122
+
123
+ **Domains:**
124
+ - `domains` → list of active business domains
125
+
126
+ **Paths (if present):**
127
+ - `paths.specs_dir` → BDD specs root
128
+ - `paths.prd_dir` → PRD documents root
129
+ - `paths.refinement_dir` → findings/review output dir
130
+ - `paths.product_definitions_dir` → product definitions root
131
+ - `paths.domain_knowledge_dir` → domain knowledge root
132
+ - `paths.business_dictionary` → path to business-dictionary.md
133
+ - `paths.core_entities` → path to core-entities.md
134
+ - `paths.tech_docs_dir` → technical documentation root
135
+ - `paths.trace_dir` → trace state directory
136
+
137
+ If `paths` section is absent, use these defaults:
138
+ - `specs_dir` = `specs/bdd`
139
+ - `prd_dir` = `specs/prd`
140
+ - `refinement_dir` = `.agent/review`
141
+ - `product_definitions_dir` = `specs/product-definition`
142
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
143
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
144
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
145
+ - `tech_docs_dir` = `tech-docs`
146
+ - `trace_dir` = `.trace`
147
+
148
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
149
+
150
+ ---
151
+
152
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
153
+
154
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
155
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
156
+ If the file does not exist → skip silently.
157
+
158
+ ---
159
+
160
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
161
+
162
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
163
+
164
+ Read `CLAUDE.md`. Extract and store:
165
+
166
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
167
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
168
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
169
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
170
+ - **§7 Git Conventions** → branch naming pattern, commit message format
171
+
172
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
173
+
174
+ ---
175
+
176
+ ## Step 4 — [SAFETY] Load Data Protection Rules
177
+
178
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
179
+
180
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
181
+
182
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
183
+
184
+ ---
185
+
186
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
187
+
188
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
189
+
190
+ If it exists, read it and extract:
191
+ - **Canonical Terms** → complete list of approved terms and their definitions
192
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
193
+ - **Status / Enum Registry** → allowed enum values per entity
194
+
195
+ Store the banned terms list for **active enforcement** throughout the command session:
196
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
197
+ - Replace banned terms with their canonical equivalents automatically
198
+
199
+ If the file does not exist → skip silently. Do not warn or block.
200
+
201
+ ---
202
+
203
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
204
+
205
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
206
+ Default path: `specs/domain-knowledge/core-entities.md`.
207
+
208
+ If it exists, read it and store:
209
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
210
+ - **Field name registry** → canonical field names to use in generated code and documents
211
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
212
+
213
+ **How to use this catalog:**
214
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
215
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
216
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
217
+
218
+ If the file does not exist → skip silently.
219
+
220
+ ---
221
+
222
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
223
+
224
+ After loading all context, synthesize and output a compact summary block.
225
+ This recap ensures the most critical facts are stated at the END of context loading
226
+ (recency effect — freshest in working memory when the task begins).
227
+
228
+ Output exactly this block:
229
+ ```
230
+ [CTX LOADED]
231
+ Stack : {language} / {framework} / {database}
232
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
233
+ Ticket : {ticket_prefix}-
234
+ Dict : {loaded — N canonical terms, M banned terms | missing}
235
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
236
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
237
+ ```
238
+
239
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
240
+
241
+ ---
242
+
243
+ ## Context Load Complete
244
+
245
+ After completing all steps, you have loaded:
246
+ - Project identity, tech stack, module conventions
247
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
248
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
249
+ - Data protection rules (sensitive file patterns to never access)
250
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
251
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
252
+ - All configured paths
253
+
254
+ Proceed to the next step of the calling command.
255
+
256
+
257
+ ---
258
+
259
+ ## Process
260
+
261
+ ### Step 1 — Load TSV data
262
+
263
+ Read all `{paths.trace_dir}/{UC-ID}.tsv` files matching the target domain (or all domains if no domain filter).
264
+ Each file gives the persisted trace state for that UC.
265
+
266
+ ### Step 2 — Reconcile with current `.feature` files
267
+
268
+ For each `.tsv` row, read the corresponding `.feature` file and get the **current** `@trace.sc_version` for that SC.
269
+ If the `.feature` SC version differs from the `.tsv` `spec_ver` → update `spec_ver` in memory (will be written back).
270
+
271
+ Also detect SCs present in `.feature` but missing from `.tsv` → add as new rows with `status: UNTRACKED`.
272
+
273
+ ### Step 3 — Compute `status` per scenario
274
+
275
+ Apply rules in priority order:
276
+
277
+ | Rule | Status | Condition |
278
+ |------|--------|-----------|
279
+ | 1 | `UNTRACKED` | `implemented_by == —` (no code generated yet) |
280
+ | 2 | `GAP` | `implemented_by != —` AND (`test_count == —` OR `test_count == 0`) |
281
+ | 3 | `DRIFT` | `spec_ver != gen_ver` (scenario updated since last codegen) |
282
+ | 4 | `OK` | all of: `spec_ver == gen_ver`, `implemented_by != —`, `test_count > 0` |
283
+
284
+ ### Step 4 — PRD version drift check
285
+
286
+ For each UC, compare:
287
+ - Current PRD `| **Version** |` from `{paths.prd_dir}/{domain}/{slug}.md`
288
+ - `prd_version` stored in `.tsv` (version at time of BDD generation)
289
+ - `@trace.prd_version` in the code files implementing that UC
290
+
291
+ If any layer is behind current PRD version → flag `PRD_DRIFT` and extract changelog entries since that version.
292
+
293
+ ### Step 5 — Tech-doc revision drift check
294
+
295
+ For each UC that has a tech-doc, compare:
296
+ - Current `@trace.revision` in `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`
297
+ - `tech_doc_revision` stored in `.tsv` (revision at time of codegen)
298
+
299
+ If code was generated from an older revision → flag `TECHDOC_DRIFT`.
300
+
301
+ ### Step 6 — Write status back to TSV
302
+
303
+ For each `.tsv` file processed: write updated `spec_ver`, `status`, `last_updated` back to disk.
304
+
305
+ ### Step 7 — Compute dashboard aggregates
306
+
307
+ ```
308
+ total_prds = count distinct PRD files in {paths.prd_dir}/{domain}/
309
+ approved_prds = PRDs with | Status | approved
310
+ total_ucs = count distinct UC-IDs across all .tsv files
311
+ approved_ucs = UCs with uc_status == approved
312
+ total_scs = total rows across all .tsv files
313
+ code_coverage = rows where implemented_by != — / total_scs
314
+ test_coverage = rows where test_count > 0 / total_scs
315
+ drift_count = rows where status == DRIFT
316
+ untracked_count = rows where status == UNTRACKED
317
+ gap_count = rows where status == GAP
318
+ tech_docs_count = count .md files in {paths.tech_docs_dir}/{domain}/
319
+ ```
320
+
321
+ ### Step 8 — Write JSON report
322
+
323
+ Write `.trace/trace-report.json` (overwrite if exists). This file is the single source of truth for web dashboards — it contains the full snapshot at the time `/validate-traces` was last run.
324
+
325
+ Schema:
326
+
327
+ ```json
328
+ {
329
+ "generated_at": "<ISO-8601 timestamp>",
330
+ "domain": "<domain argument, or 'all' if no filter>",
331
+ "summary": {
332
+ "total_prds": 0,
333
+ "approved_prds": 0,
334
+ "total_ucs": 0,
335
+ "approved_ucs": 0,
336
+ "draft_ucs": 0,
337
+ "total_scs": 0,
338
+ "coded_scs": 0,
339
+ "tested_scs": 0,
340
+ "code_coverage_pct": 0,
341
+ "test_coverage_pct": 0,
342
+ "drift_count": 0,
343
+ "gap_count": 0,
344
+ "untracked_count": 0,
345
+ "tech_docs_count": 0
346
+ },
347
+ "prds": [
348
+ {
349
+ "prd_id": "<e.g. PAY>",
350
+ "prd_status": "approved | draft | other",
351
+ "total_scs": 0,
352
+ "coded_scs": 0,
353
+ "tested_scs": 0,
354
+ "drift_count": 0,
355
+ "gap_count": 0,
356
+ "untracked_count": 0,
357
+ "ucs": [
358
+ {
359
+ "uc_id": "<e.g. PAY-UC01>",
360
+ "uc_status": "approved | draft | other",
361
+ "scenarios": [
362
+ {
363
+ "sc_id": "<e.g. PAY-UC01-SC1>",
364
+ "sc_title": "<title>",
365
+ "spec_ver": "<current version from .feature>",
366
+ "gen_ver": "<version at codegen time>",
367
+ "implemented_by": "<ClassName.method or null>",
368
+ "test_count": 0,
369
+ "test_classes": ["<TestClass1>", "<TestClass2>"],
370
+ "prd_version": "<prd version when BDD was generated>",
371
+ "bdd_version": "<bdd version when code was generated>",
372
+ "tech_doc_revision": 0,
373
+ "status": "OK | DRIFT | GAP | UNTRACKED",
374
+ "last_updated": "<YYYY-MM-DD>"
375
+ }
376
+ ]
377
+ }
378
+ ]
379
+ }
380
+ ],
381
+ "issues": {
382
+ "drift": [
383
+ {
384
+ "sc_id": "<SC-ID>",
385
+ "sc_title": "<title>",
386
+ "spec_ver": "<current>",
387
+ "gen_ver": "<at codegen>",
388
+ "fix": "/generate-code <UC-ID>"
389
+ }
390
+ ],
391
+ "gap": [
392
+ {
393
+ "sc_id": "<SC-ID>",
394
+ "sc_title": "<title>",
395
+ "implemented_by": "<method>",
396
+ "fix": "/generate-tests <UC-ID>"
397
+ }
398
+ ],
399
+ "untracked": [
400
+ {
401
+ "sc_id": "<SC-ID>",
402
+ "sc_title": "<title>",
403
+ "fix": "/generate-code <UC-ID>"
404
+ }
405
+ ],
406
+ "prd_version_drift": [
407
+ {
408
+ "uc_id": "<UC-ID>",
409
+ "code_prd_version": "<version in code tag>",
410
+ "current_prd_version": "<version in PRD file>",
411
+ "changelog_since": ["<v1.1: ...>", "<v1.2: ...>"],
412
+ "fix": "/generate-bdd <prd-file> then /generate-code <UC-ID>"
413
+ }
414
+ ],
415
+ "techdoc_drift": [
416
+ {
417
+ "uc_id": "<UC-ID>",
418
+ "code_revision": 0,
419
+ "current_revision": 0,
420
+ "fix": "/generate-code <UC-ID>"
421
+ }
422
+ ]
423
+ }
424
+ }
425
+ ```
426
+
427
+ **Rules:**
428
+ - `implemented_by`: use `null` (not `"—"`) in JSON when no value
429
+ - `test_count`: use integer `0` (not `"—"`) when no tests
430
+ - `test_classes`: use `[]` (not `"—"`) when no test classes
431
+ - `tech_doc_revision`: use integer; `0` if not yet generated
432
+ - `code_coverage_pct` / `test_coverage_pct`: round to nearest integer (0–100)
433
+ - Always write to `.trace/trace-report.json` regardless of domain filter — if a domain filter was applied, include only those PRDs in `prds[]` but note the domain in the `domain` field
434
+
435
+ ## Output
436
+
437
+ # Report Footer — Standard Command Output Format
438
+
439
+ Every command report must end with this standard footer section.
440
+
441
+ ## Status Badge
442
+
443
+ Choose one based on outcome:
444
+ - `✅ Complete` — all steps succeeded, no issues found
445
+ - `❌ Failed` — command could not complete due to a blocking error
446
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
447
+
448
+ ## Output Artifacts
449
+
450
+ List every file created or modified by this command:
451
+ ```
452
+ Output Artifacts:
453
+ {created|updated} {file-path} ({brief description})
454
+ {created|updated} {file-path} ({brief description})
455
+ ```
456
+
457
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
458
+
459
+ ## Next Command Suggestion
460
+
461
+ Suggest the logical next command based on workflow phase:
462
+
463
+ | Current command | Suggest next |
464
+ |-------------------------|-----------------------------------------------|
465
+ | /define-product | `/generate-prd {product-definition-file}` |
466
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
467
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
468
+ | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
469
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
470
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
471
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
472
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
473
+ | /generate-code | `/generate-tests {UC-ID}` |
474
+ | /generate-tests | `/run-tests {UC-ID}` |
475
+ | /run-tests (passing) | `/review-code {UC-ID}` |
476
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
477
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
478
+ | /smoke-test | Create PR and link to ticket |
479
+ | /validate-traces | `/generate-code {UC-ID}` for gaps |
480
+ | /fix-bug | Create PR and link to ticket |
481
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
482
+
483
+ Format the footer as:
484
+ ```
485
+ ---
486
+ Status : {badge}
487
+ {Output Artifacts block}
488
+ Next : {suggested command with example arguments}
489
+ ```
490
+
491
+
492
+ ```
493
+ /validate-traces — {domain}
494
+
495
+ 📄 .trace/trace-report.json ← updated
496
+
497
+ ┌─────────────────────────────────────────────────────────────────────────────────────┐
498
+ │ PRDs Use Cases Scenarios Code Cov. Test Cov. Drift Untracked Gap │
499
+ │ {N} {N} {N} {N}% {N}% {N} {N} {N} │
500
+ │ {A} appr {A} appr {X}/{T} SCs {X}/{T} SCs │
501
+ └─────────────────────────────────────────────────────────────────────────────────────┘
502
+
503
+ | UC-ID | SC | Title (truncated) | Spec | Gen | Code | Tests | Status |
504
+ |-------------|------|------------------------------|-------|-------|----------------------|----------------|----------|
505
+ | {UC}-UC1 | SC1 | {title...} | v1.0 | v1.0 | ✅ {Controller.fn} | ✅ 10 tests | OK |
506
+ | {UC}-UC1 | SC2 | {title...} | v1.1 | v1.0 | ✅ {Controller.fn} | ✅ 3 tests | DRIFT |
507
+ | {UC}-UC1 | SC6 | {title...} | v1.0 | — | — | — | UNTRACKED|
508
+ | {UC}-UC2 | SC1 | {title...} | v1.0 | v1.0 | ✅ {Controller.fn} | — | GAP |
509
+
510
+ Drift Detail:
511
+ {UC}-UC1-SC2 — spec v1.1 but code generated from v1.0
512
+ → Re-run: /generate-code {UC-ID}
513
+
514
+ PRD Version Drift:
515
+ {UC}-UC2 — code at PRD v1.0, PRD now at v1.2
516
+ Changes since v1.0:
517
+ v1.1: {changelog entry}
518
+ v1.2: {changelog entry}
519
+ → /generate-bdd {prd-file} then /generate-code {UC-ID}
520
+
521
+ Tech-Doc Revision Drift:
522
+ {UC}-UC3 — code generated from tech-doc revision 2, now at revision 4
523
+ → Review tech-doc changes then /generate-code {UC-ID}
524
+
525
+ Recommendations:
526
+ - /generate-code {UC-ID} for DRIFT and UNTRACKED scenarios
527
+ - /generate-tests {UC-ID} for GAP (missing tests)
528
+ - /generate-bdd {prd-file} for PRD version drift
529
+ ```