@anhth2/spec-driven-dev-plugin 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/bin/index.js +285 -11
  2. package/commands/debug.md +233 -11
  3. package/commands/debug.tmpl +170 -6
  4. package/commands/define-product.md +68 -6
  5. package/commands/define-product.tmpl +5 -1
  6. package/commands/fix-bug.md +111 -11
  7. package/commands/fix-bug.tmpl +48 -6
  8. package/commands/generate-bdd.md +86 -9
  9. package/commands/generate-bdd.tmpl +23 -4
  10. package/commands/generate-code.md +146 -19
  11. package/commands/generate-code.tmpl +83 -14
  12. package/commands/generate-design-spec.md +754 -0
  13. package/commands/generate-design-spec.tmpl +399 -0
  14. package/commands/generate-prd.md +91 -7
  15. package/commands/generate-prd.tmpl +28 -2
  16. package/commands/generate-spec-manifest.md +519 -0
  17. package/commands/generate-spec-manifest.tmpl +164 -0
  18. package/commands/generate-tech-docs.md +122 -9
  19. package/commands/generate-tech-docs.tmpl +59 -4
  20. package/commands/generate-tests.md +491 -37
  21. package/commands/generate-tests.tmpl +428 -32
  22. package/commands/refine-prd.md +76 -8
  23. package/commands/refine-prd.tmpl +13 -3
  24. package/commands/review-code.md +94 -6
  25. package/commands/review-code.tmpl +31 -1
  26. package/commands/review-context.md +118 -12
  27. package/commands/review-context.tmpl +55 -7
  28. package/commands/review-tech-docs.md +76 -9
  29. package/commands/review-tech-docs.tmpl +13 -4
  30. package/commands/run-tests.md +196 -18
  31. package/commands/run-tests.tmpl +133 -13
  32. package/commands/setup-ai-first.md +192 -6
  33. package/commands/setup-ai-first.tmpl +136 -5
  34. package/commands/smoke-test.md +228 -22
  35. package/commands/smoke-test.tmpl +165 -17
  36. package/commands/validate-traces.md +77 -8
  37. package/commands/validate-traces.tmpl +14 -3
  38. package/core/FRAMEWORK_VERSION +1 -1
  39. package/core/commands/debug.md +233 -11
  40. package/core/commands/define-product.md +68 -6
  41. package/core/commands/fix-bug.md +111 -11
  42. package/core/commands/generate-bdd.md +86 -9
  43. package/core/commands/generate-code.md +146 -19
  44. package/core/commands/generate-design-spec.md +754 -0
  45. package/core/commands/generate-prd.md +91 -7
  46. package/core/commands/generate-spec-manifest.md +519 -0
  47. package/core/commands/generate-tech-docs.md +122 -9
  48. package/core/commands/generate-tests.md +491 -37
  49. package/core/commands/refine-prd.md +76 -8
  50. package/core/commands/review-code.md +94 -6
  51. package/core/commands/review-context.md +118 -12
  52. package/core/commands/review-tech-docs.md +76 -9
  53. package/core/commands/run-tests.md +196 -18
  54. package/core/commands/setup-ai-first.md +192 -6
  55. package/core/commands/smoke-test.md +228 -22
  56. package/core/commands/validate-traces.md +77 -8
  57. package/core/skills/code/SKILL.md +68 -8
  58. package/core/skills/debug/SKILL.md +72 -10
  59. package/core/skills/design-spec/SKILL.md +450 -0
  60. package/core/skills/discovery/SKILL.md +62 -4
  61. package/core/skills/prd/SKILL.md +12 -8
  62. package/core/skills/setup-ai-first/SKILL.md +5 -3
  63. package/core/skills/spec/SKILL.md +11 -7
  64. package/core/skills/test/SKILL.md +130 -12
  65. package/core/steps/context-loader.md +57 -1
  66. package/core/steps/gate.md +1 -1
  67. package/core/steps/report-footer.md +5 -3
  68. package/core/steps/spawn-agent.md +3 -1
  69. package/core/templates/design-spec.template.md +209 -0
  70. package/core/templates/project-context.yaml +29 -0
  71. package/package.json +1 -1
  72. package/skills/code/SKILL.md +68 -8
  73. package/skills/debug/SKILL.md +72 -10
  74. package/skills/design-spec/SKILL.md +450 -0
  75. package/skills/design-spec/SKILL.tmpl +95 -0
  76. package/skills/discovery/SKILL.md +62 -4
  77. package/skills/prd/SKILL.md +12 -8
  78. package/skills/setup-ai-first/SKILL.md +5 -3
  79. package/skills/spec/SKILL.md +11 -7
  80. package/skills/test/SKILL.md +130 -12
  81. package/steps/context-loader.md +57 -1
  82. package/steps/gate.md +1 -1
  83. package/steps/report-footer.md +5 -3
  84. package/steps/spawn-agent.md +3 -1
  85. package/templates/design-spec.template.md +209 -0
  86. package/templates/project-context.yaml +29 -0
@@ -31,7 +31,7 @@ Display and wait for response:
31
31
  ```
32
32
  ⚙️ MODEL CHECK
33
33
  ──────────────────────────────────────────────────────────────────
34
- Recommended : claude-opus-4-5 (or claude-opus-4)
34
+ Recommended : claude-opus-4 (or latest Opus model)
35
35
  Why needed : Spec analysis, architecture review, code generation
36
36
  require deep reasoning. Smaller models miss edge cases.
37
37
 
@@ -131,6 +131,7 @@ Read `.agent/project-context.yaml`. Extract and store:
131
131
  - `paths.core_entities` → path to core-entities.md
132
132
  - `paths.tech_docs_dir` → technical documentation root
133
133
  - `paths.trace_dir` → trace state directory
134
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
134
135
 
135
136
  If `paths` section is absent, use these defaults:
136
137
  - `specs_dir` = `specs/bdd`
@@ -140,13 +141,46 @@ If `paths` section is absent, use these defaults:
140
141
  - `domain_knowledge_dir` = `specs/domain-knowledge`
141
142
  - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
142
143
  - `core_entities` = `specs/domain-knowledge/core-entities.md`
143
- - `tech_docs_dir` = `tech-docs`
144
+ - `tech_docs_dir` = `specs/tech-docs`
144
145
  - `trace_dir` = `.trace`
146
+ - `design_spec_dir` = `specs/design-spec`
145
147
 
146
148
  If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
147
149
 
148
150
  ---
149
151
 
152
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
153
+
154
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
155
+
156
+ If `services` section is present:
157
+
158
+ **1. Detect active domain** (in priority order):
159
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
160
+ - Extract from target file path: segment immediately after `prd_dir` base path
161
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
162
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
163
+
164
+ **2. Route to service** — if active domain matches a key in `services`:
165
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
166
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
167
+ - Store `active_service` = `services.{domain}.path`
168
+ - Store `active_service_module` = `services.{domain}.module`
169
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
170
+
171
+ **3. Fallback** — if domain not detected or no matching service key:
172
+ - Keep default paths from Step 1
173
+ - Set `active_service = unresolved`
174
+
175
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
176
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
177
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
178
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
179
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
180
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
181
+
182
+ ---
183
+
150
184
  ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
151
185
 
152
186
  If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
@@ -217,6 +251,26 @@ If the file does not exist → skip silently.
217
251
 
218
252
  ---
219
253
 
254
+ ## Step 6.5 — [PLATFORM] Derive active_module and platform_type
255
+
256
+ Using `tech_stack.module` loaded in Step 1, derive and store two variables for use by all downstream commands:
257
+
258
+ ```
259
+ active_module = tech_stack.module (e.g. "java-spring", "react", "flutter")
260
+ ```
261
+
262
+ | `platform_type` | Modules |
263
+ |---|---|
264
+ | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
265
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
266
+ | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
267
+
268
+ If `tech_stack.module` is blank or not recognized → set `platform_type = "unknown"` and flag as ⚠️ in the Step 7 recap.
269
+
270
+ These two variables (`active_module`, `platform_type`) are the canonical source for all branching logic in commands that need platform-specific behavior (generate-tests, debug, fix-bug, smoke-test).
271
+
272
+ ---
273
+
220
274
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
221
275
 
222
276
  After loading all context, synthesize and output a compact summary block.
@@ -227,10 +281,12 @@ Output exactly this block:
227
281
  ```
228
282
  [CTX LOADED]
229
283
  Stack : {language} / {framework} / {database}
284
+ Platform : {active_module} ({platform_type})
230
285
  Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
231
286
  Ticket : {ticket_prefix}-
232
287
  Dict : {loaded — N canonical terms, M banned terms | missing}
233
288
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
289
+ Service : {active_service} ({active_service_module}) | single-service
234
290
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
235
291
  ```
236
292
 
@@ -285,6 +341,27 @@ Never leave TICKET-ID as plain text if a corresponding PRD file exists in `{path
285
341
 
286
342
  ---
287
343
 
344
+ ## Platform Strategy — PRD is platform-agnostic (Option C)
345
+
346
+ PRD mô tả **WHAT** (yêu cầu nghiệp vụ) — không phụ thuộc vào platform nào implement.
347
+ Viết AC theo business outcome, không theo UI/API details:
348
+
349
+ | ✅ Viết trong PRD (platform-agnostic) | ❌ Không viết trong PRD |
350
+ |---|---|
351
+ | "Đăng nhập thành công → truy cập được tính năng" | "Click button → show toast" ← Design Spec |
352
+ | "Sai password 5 lần → khoá tài khoản 30 phút" | "API trả về JWT token" ← Tech Docs |
353
+ | "Session hết hạn → yêu cầu xác thực lại" | "Hiển thị spinner khi loading" ← Design Spec |
354
+
355
+ **Một PRD phục vụ tất cả platform:**
356
+ - **FE/App team** → đọc PRD + Design Spec → `/generate-bdd` (UI-level scenarios)
357
+ - **BE team** → đọc PRD trực tiếp → `/generate-bdd` (API-level scenarios)
358
+ - Design Spec là tài liệu riêng cho FE/App — **không trộn vào PRD**
359
+
360
+ Khi viết AC, nếu PO đề cập chi tiết UI (màu sắc, layout, animation) → nhắc nhở:
361
+ *"Chi tiết UI này thuộc về Design Spec, không thuộc PRD. Ghi nhận lại để tạo Design Spec sau."*
362
+
363
+ ---
364
+
288
365
  ## Generate
289
366
 
290
367
  Write `{paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md` using the structure below.
@@ -455,21 +532,23 @@ Suggest the logical next command based on workflow phase:
455
532
 
456
533
  | Current command | Suggest next |
457
534
  |-------------------------|-----------------------------------------------|
535
+ | /setup-ai-first | `/define-product` to start your first feature |
458
536
  | /define-product | `/generate-prd {product-definition-file}` |
459
537
  | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
460
538
  | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
461
- | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
539
+ | /review-context (PRD) | FE/App: `/generate-design-spec {prd-file}` (then BDD after sign-off); BE: `/generate-bdd {prd-file}` directly; fix PRD if NEEDS_FIX |
540
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
462
541
  | /generate-bdd | `/review-context {feature-file}` to verify coverage |
463
542
  | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
464
543
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
465
544
  | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
466
- | /generate-code | `/generate-tests {UC-ID}` |
545
+ | /generate-code | First gen → `/review-code {UC-ID}`; re-gen → `/generate-tests {UC-ID}` |
467
546
  | /generate-tests | `/run-tests {UC-ID}` |
468
547
  | /run-tests (passing) | `/review-code {UC-ID}` |
469
548
  | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
470
549
  | /review-code | `/smoke-test {UC-ID}` or create PR |
471
550
  | /smoke-test | Create PR and link to ticket |
472
- | /validate-traces | `/generate-code {UC-ID}` for gaps |
551
+ | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
473
552
  | /fix-bug | Create PR and link to ticket |
474
553
  | /debug | `/fix-bug {ticket-id}` if fix needed |
475
554
 
@@ -483,6 +562,11 @@ Next : {suggested command with example arguments}
483
562
 
484
563
 
485
564
  ```
486
- PRD created: {paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md (v1.0)
487
- Next: /refine-prd {paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md
565
+ /generate-prd Complete {TICKET-ID}
566
+ ---
567
+ Status : ✅ Complete
568
+ Output Artifacts:
569
+ created {paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md (PRD v1.0)
570
+ Next : /refine-prd {paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md
571
+ → then /review-context {prd-file} ← verify PRD quality before generating BDD
488
572
  ```
@@ -0,0 +1,519 @@
1
+ # /generate-spec-manifest — Generate Spec Manifest for External Agents
2
+
3
+ Scans all spec files and writes a `spec-manifest.yaml` at the project root.
4
+ This file is for **external agents only** (e.g. tester's agent) — it is not committed to git.
5
+
6
+ ## Gate
7
+
8
+ # Gate — Universal Entry Procedure
9
+
10
+ Every command must execute this gate before proceeding with its specific logic.
11
+
12
+ ## Step 0 — Sub-Agent Mode Check
13
+
14
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
15
+
16
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
17
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
18
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
19
+ - Set target file = `payload.target_file`
20
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
21
+ - Set UC scope = `payload.uc_id` (process only this UC)
22
+ - Set line range = `payload.uc_section` (read only that PRD section)
23
+ - Proceed directly to the command-specific logic.
24
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
25
+
26
+ ## Step 0-B — Model Check
27
+
28
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
29
+
30
+ Complex generation and review commands require strong reasoning.
31
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
32
+
33
+ Display and wait for response:
34
+
35
+ ```
36
+ ⚙️ MODEL CHECK
37
+ ──────────────────────────────────────────────────────────────────
38
+ Recommended : claude-opus-4 (or latest Opus model)
39
+ Why needed : Spec analysis, architecture review, code generation
40
+ require deep reasoning. Smaller models miss edge cases.
41
+
42
+ To switch in Claude Code:
43
+ • Settings → Model → select "claude-opus"
44
+ • or: /model → choose claude-opus
45
+
46
+ Running on claude-opus?
47
+ Y — yes, on claude-opus → proceed
48
+ S — skip check (I accept lower quality risk with current model)
49
+ ──────────────────────────────────────────────────────────────────
50
+ ```
51
+
52
+ - "Y" → proceed to Step 1.
53
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
54
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
55
+
56
+ ## Step 1 — Resolve Target File
57
+
58
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
59
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
60
+ 3. If `$ARGUMENTS` is empty or no match found:
61
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
62
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
63
+ - Wait for user selection before continuing.
64
+
65
+ ## Step 2 — Execute Context Loader
66
+
67
+ Load all project context by following the procedure in `steps/context-loader.md`.
68
+ Store all loaded context in memory for use throughout this command session.
69
+
70
+ ## Step 3 — CHECKPOINT
71
+
72
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
73
+
74
+ ```
75
+ CHECKPOINT
76
+ -----------
77
+ Target : {resolved file path}
78
+ Project : {project.name from project-context.yaml}
79
+ Tech stack : {language} / {framework}
80
+ Module : {module if set, else "not configured"}
81
+ Domains : {comma-separated domain list}
82
+
83
+ Proceed? (Y/N)
84
+ ```
85
+
86
+ Wait for explicit "Y" or "N" from the user before continuing.
87
+ - "Y" → proceed to the command-specific steps below.
88
+ - "N" → stop and ask what the user wants to change.
89
+
90
+
91
+ *Note: For this command, there is no target file — it scans the entire project. Ignore `$ARGUMENTS` unless a domain filter is passed.*
92
+
93
+ ## Context
94
+
95
+ # Context Loader — Load All Project Context
96
+
97
+ Execute these steps in order. Store everything in memory for the duration of the command session.
98
+
99
+ **Priority guide (anti-lost-in-middle):**
100
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
101
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
102
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
103
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
104
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
105
+
106
+ ---
107
+
108
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
109
+
110
+ Read `.agent/project-context.yaml`. Extract and store:
111
+
112
+ **Tech Stack:**
113
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
114
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
115
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
116
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
117
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
118
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
119
+
120
+ **Conventions:**
121
+ - `conventions.build_command` → how to compile/build
122
+ - `conventions.test_command` → how to run tests
123
+ - `conventions.service_run` → how to start the service
124
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
125
+
126
+ **Domains:**
127
+ - `domains` → list of active business domains
128
+
129
+ **Paths (if present):**
130
+ - `paths.specs_dir` → BDD specs root
131
+ - `paths.prd_dir` → PRD documents root
132
+ - `paths.refinement_dir` → findings/review output dir
133
+ - `paths.product_definitions_dir` → product definitions root
134
+ - `paths.domain_knowledge_dir` → domain knowledge root
135
+ - `paths.business_dictionary` → path to business-dictionary.md
136
+ - `paths.core_entities` → path to core-entities.md
137
+ - `paths.tech_docs_dir` → technical documentation root
138
+ - `paths.trace_dir` → trace state directory
139
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
140
+
141
+ If `paths` section is absent, use these defaults:
142
+ - `specs_dir` = `specs/bdd`
143
+ - `prd_dir` = `specs/prd`
144
+ - `refinement_dir` = `.agent/review`
145
+ - `product_definitions_dir` = `specs/product-definition`
146
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
147
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
148
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
149
+ - `tech_docs_dir` = `specs/tech-docs`
150
+ - `trace_dir` = `.trace`
151
+ - `design_spec_dir` = `specs/design-spec`
152
+
153
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
154
+
155
+ ---
156
+
157
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
158
+
159
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
160
+
161
+ If `services` section is present:
162
+
163
+ **1. Detect active domain** (in priority order):
164
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
165
+ - Extract from target file path: segment immediately after `prd_dir` base path
166
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
167
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
168
+
169
+ **2. Route to service** — if active domain matches a key in `services`:
170
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
171
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
172
+ - Store `active_service` = `services.{domain}.path`
173
+ - Store `active_service_module` = `services.{domain}.module`
174
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
175
+
176
+ **3. Fallback** — if domain not detected or no matching service key:
177
+ - Keep default paths from Step 1
178
+ - Set `active_service = unresolved`
179
+
180
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
181
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
182
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
183
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
184
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
185
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
186
+
187
+ ---
188
+
189
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
190
+
191
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
192
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
193
+ If the file does not exist → skip silently.
194
+
195
+ ---
196
+
197
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
198
+
199
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
200
+
201
+ Read `CLAUDE.md`. Extract and store:
202
+
203
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
204
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
205
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
206
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
207
+ - **§7 Git Conventions** → branch naming pattern, commit message format
208
+
209
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
210
+
211
+ ---
212
+
213
+ ## Step 4 — [SAFETY] Load Data Protection Rules
214
+
215
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
216
+
217
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
218
+
219
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
220
+
221
+ ---
222
+
223
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
224
+
225
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
226
+
227
+ If it exists, read it and extract:
228
+ - **Canonical Terms** → complete list of approved terms and their definitions
229
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
230
+ - **Status / Enum Registry** → allowed enum values per entity
231
+
232
+ Store the banned terms list for **active enforcement** throughout the command session:
233
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
234
+ - Replace banned terms with their canonical equivalents automatically
235
+
236
+ If the file does not exist → skip silently. Do not warn or block.
237
+
238
+ ---
239
+
240
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
241
+
242
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
243
+ Default path: `specs/domain-knowledge/core-entities.md`.
244
+
245
+ If it exists, read it and store:
246
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
247
+ - **Field name registry** → canonical field names to use in generated code and documents
248
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
249
+
250
+ **How to use this catalog:**
251
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
252
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
253
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
254
+
255
+ If the file does not exist → skip silently.
256
+
257
+ ---
258
+
259
+ ## Step 6.5 — [PLATFORM] Derive active_module and platform_type
260
+
261
+ Using `tech_stack.module` loaded in Step 1, derive and store two variables for use by all downstream commands:
262
+
263
+ ```
264
+ active_module = tech_stack.module (e.g. "java-spring", "react", "flutter")
265
+ ```
266
+
267
+ | `platform_type` | Modules |
268
+ |---|---|
269
+ | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
270
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
271
+ | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
272
+
273
+ If `tech_stack.module` is blank or not recognized → set `platform_type = "unknown"` and flag as ⚠️ in the Step 7 recap.
274
+
275
+ These two variables (`active_module`, `platform_type`) are the canonical source for all branching logic in commands that need platform-specific behavior (generate-tests, debug, fix-bug, smoke-test).
276
+
277
+ ---
278
+
279
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
280
+
281
+ After loading all context, synthesize and output a compact summary block.
282
+ This recap ensures the most critical facts are stated at the END of context loading
283
+ (recency effect — freshest in working memory when the task begins).
284
+
285
+ Output exactly this block:
286
+ ```
287
+ [CTX LOADED]
288
+ Stack : {language} / {framework} / {database}
289
+ Platform : {active_module} ({platform_type})
290
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
291
+ Ticket : {ticket_prefix}-
292
+ Dict : {loaded — N canonical terms, M banned terms | missing}
293
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
294
+ Service : {active_service} ({active_service_module}) | single-service
295
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
296
+ ```
297
+
298
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
299
+
300
+ ---
301
+
302
+ ## Context Load Complete
303
+
304
+ After completing all steps, you have loaded:
305
+ - Project identity, tech stack, module conventions
306
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
307
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
308
+ - Data protection rules (sensitive file patterns to never access)
309
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
310
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
311
+ - All configured paths
312
+
313
+ Proceed to the next step of the calling command.
314
+
315
+
316
+ ---
317
+
318
+ ## Process
319
+
320
+ ### Step 1 — Determine scan roots
321
+
322
+ Read `project-context.yaml` to determine mode and paths:
323
+
324
+ **Umbrella mode** (`setup.mode: umbrella`):
325
+ ```
326
+ spec_root = {setup.spec_source} ← PO's spec submodule
327
+ prd_glob = {spec_root}/specs/prd/**/*.md
328
+ pdd_glob = {spec_root}/specs/product-definition/**/*.md
329
+ services = {services} ← map of domain → paths
330
+ ```
331
+
332
+ **Single-service mode** (no `setup.mode`):
333
+ ```
334
+ spec_root = .
335
+ prd_glob = {paths.prd_dir}/**/*.md
336
+ pdd_glob = {paths.product_definitions_dir}/**/*.md
337
+ services = { default: { specs_dir: {paths.specs_dir}, tech_docs_dir: {paths.tech_docs_dir} } }
338
+ ```
339
+
340
+ If a domain filter was passed in `$ARGUMENTS` → only scan PRDs matching that domain.
341
+
342
+ ---
343
+
344
+ ### Step 2 — Scan PRD files
345
+
346
+ For each `.md` file matched by `prd_glob`:
347
+
348
+ 1. Read the file metadata table:
349
+ - `TICKET-ID` from `| **PRD ID** |`
350
+ - `domain` from `| **Domain** |`
351
+ - `status` from `| **Status** |`
352
+ - `version` from `| **Version** |`
353
+ 2. Also read frontmatter `@trace.domain` if present (use this over metadata table domain if both exist)
354
+ 3. Record: `{ ticket_id, domain, status, version, prd_path }` — path relative to manifest root
355
+
356
+ Skip files where `TICKET-ID` cannot be determined.
357
+
358
+ ---
359
+
360
+ ### Step 3 — Match PDD files
361
+
362
+ For each TICKET-ID found in Step 2:
363
+
364
+ Search `pdd_glob` for a file whose name contains the TICKET-ID (e.g. `FT-001-*.md`).
365
+ - Found → record `pdd_path` (relative to manifest root)
366
+ - Not found → record `pdd: null`
367
+
368
+ ---
369
+
370
+ ### Step 4 — Match BDD and Tech-Doc files per service
371
+
372
+ For each TICKET-ID, for each service in `services` map:
373
+
374
+ **BDD:**
375
+ - Glob `{service.specs_dir}/**/{TICKET-ID}*.feature`
376
+ - Also check files containing `@trace.prd: {TICKET-ID}` in frontmatter if glob returns nothing
377
+ - Found → record path under `bdd.{service_key}`
378
+ - Not found → omit key (do not write `null` for services with no BDD yet)
379
+
380
+ **Tech-docs:**
381
+ - Glob `{service.tech_docs_dir}/**/{TICKET-ID}*.md`
382
+ - Also check files containing `@trace.prd: {TICKET-ID}` if glob returns nothing
383
+ - Found → record path under `tech_docs.{service_key}`
384
+ - Not found → omit key
385
+
386
+ All paths relative to manifest root (umbrella root or project root).
387
+
388
+ ---
389
+
390
+ ### Step 5 — Write spec-manifest.yaml
391
+
392
+ Write to `{manifest_root}/spec-manifest.yaml` (overwrite if exists).
393
+
394
+ Format:
395
+
396
+ ```yaml
397
+ # Auto-generated by /generate-spec-manifest — DO NOT edit manually
398
+ # To regenerate: /generate-spec-manifest
399
+ # This file is excluded from git — see .gitignore
400
+
401
+ version: "1.0"
402
+ generated_at: "{YYYY-MM-DD}"
403
+ project_mode: "{umbrella | single}"
404
+
405
+ features:
406
+ {TICKET-ID}:
407
+ domain: {domain}
408
+ status: {status}
409
+ prd_version: "{version}"
410
+ prd: "{prd_path}"
411
+ pdd: "{pdd_path}" # omit if null
412
+ tech_docs:
413
+ {service_key}: "{path}" # only include services where file was found
414
+ bdd:
415
+ {service_key}: "{path}" # only include services where file was found
416
+ ```
417
+
418
+ Sort features by TICKET-ID alphabetically.
419
+ Omit `tech_docs` block entirely if no tech-doc found for any service.
420
+ Omit `bdd` block entirely if no BDD found for any service.
421
+
422
+ ---
423
+
424
+ ### Step 6 — Ensure .gitignore
425
+
426
+ Check `{manifest_root}/.gitignore`:
427
+ - If `spec-manifest.yaml` is already listed → no action
428
+ - If not → append the following to `.gitignore`:
429
+
430
+ ```
431
+ # Auto-generated — do not commit
432
+ spec-manifest.yaml
433
+ ```
434
+
435
+ Print: `✅ spec-manifest.yaml added to .gitignore`
436
+
437
+ ---
438
+
439
+ ## Output
440
+
441
+ # Report Footer — Standard Command Output Format
442
+
443
+ Every command report must end with this standard footer section.
444
+
445
+ ## Status Badge
446
+
447
+ Choose one based on outcome:
448
+ - `✅ Complete` — all steps succeeded, no issues found
449
+ - `❌ Failed` — command could not complete due to a blocking error
450
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
451
+
452
+ ## Output Artifacts
453
+
454
+ List every file created or modified by this command:
455
+ ```
456
+ Output Artifacts:
457
+ {created|updated} {file-path} ({brief description})
458
+ {created|updated} {file-path} ({brief description})
459
+ ```
460
+
461
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
462
+
463
+ ## Next Command Suggestion
464
+
465
+ Suggest the logical next command based on workflow phase:
466
+
467
+ | Current command | Suggest next |
468
+ |-------------------------|-----------------------------------------------|
469
+ | /setup-ai-first | `/define-product` to start your first feature |
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) | FE/App: `/generate-design-spec {prd-file}` (then BDD after sign-off); BE: `/generate-bdd {prd-file}` directly; fix PRD if NEEDS_FIX |
474
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
475
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
476
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
477
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
478
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
479
+ | /generate-code | First gen → `/review-code {UC-ID}`; re-gen → `/generate-tests {UC-ID}` |
480
+ | /generate-tests | `/run-tests {UC-ID}` |
481
+ | /run-tests (passing) | `/review-code {UC-ID}` |
482
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
483
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
484
+ | /smoke-test | Create PR and link to ticket |
485
+ | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
486
+ | /fix-bug | Create PR and link to ticket |
487
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
488
+
489
+ Format the footer as:
490
+ ```
491
+ ---
492
+ Status : {badge}
493
+ {Output Artifacts block}
494
+ Next : {suggested command with example arguments}
495
+ ```
496
+
497
+
498
+ ```
499
+ /generate-spec-manifest Complete
500
+ ---
501
+ Status : ✅ Complete
502
+ Output : spec-manifest.yaml ({N} features)
503
+ Mode : {umbrella | single}
504
+ .gitignore : ✅ spec-manifest.yaml excluded
505
+
506
+ Summary:
507
+ {N} PRDs scanned ({A} approved, {D} draft)
508
+ {N} PDDs matched
509
+ {N} BDD files matched (across {S} services)
510
+ {N} Tech-doc files matched (across {S} services)
511
+
512
+ ⚠️ {N} PRDs with no matching BDD:
513
+ - {TICKET-ID} ({domain}) — run /generate-bdd first
514
+ ⚠️ {N} PRDs with no matching tech-docs:
515
+ - {TICKET-ID} ({domain}) — run /generate-tech-docs first
516
+
517
+ Next : Share spec-manifest.yaml path with tester agent
518
+ Regenerate anytime: /generate-spec-manifest
519
+ ```