@anhth2/spec-driven-dev-plugin 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/ARCHITECTURE.md +6 -2
  2. package/bin/index.js +105 -0
  3. package/commands/debug.md +189 -1
  4. package/commands/debug.tmpl +16 -0
  5. package/commands/define-product.md +94 -1
  6. package/commands/fix-bug.md +190 -1
  7. package/commands/fix-bug.tmpl +17 -0
  8. package/commands/generate-bdd.md +314 -14
  9. package/commands/generate-bdd.tmpl +220 -13
  10. package/commands/generate-code.md +191 -3
  11. package/commands/generate-code.tmpl +97 -2
  12. package/commands/generate-design-spec.md +811 -0
  13. package/commands/generate-design-spec.tmpl +399 -0
  14. package/commands/generate-prd.md +133 -1
  15. package/commands/generate-prd.tmpl +39 -0
  16. package/commands/generate-spec-manifest.md +576 -0
  17. package/commands/generate-spec-manifest.tmpl +164 -0
  18. package/commands/generate-tech-docs.md +116 -2
  19. package/commands/generate-tech-docs.tmpl +22 -1
  20. package/commands/generate-tests.md +94 -1
  21. package/commands/learn.md +554 -0
  22. package/commands/learn.tmpl +63 -0
  23. package/commands/propose-scenario.md +521 -0
  24. package/commands/propose-scenario.tmpl +109 -0
  25. package/commands/refine-prd.md +94 -1
  26. package/commands/report-bug.md +543 -0
  27. package/commands/report-bug.tmpl +131 -0
  28. package/commands/review-code.md +190 -1
  29. package/commands/review-code.tmpl +17 -0
  30. package/commands/review-context.md +134 -1
  31. package/commands/review-context.tmpl +40 -0
  32. package/commands/review-tech-docs.md +176 -5
  33. package/commands/review-tech-docs.tmpl +82 -4
  34. package/commands/run-tests.md +119 -1
  35. package/commands/run-tests.tmpl +25 -0
  36. package/commands/setup-ai-first.md +142 -4
  37. package/commands/setup-ai-first.tmpl +135 -3
  38. package/commands/smoke-test.md +94 -1
  39. package/commands/sync.md +405 -0
  40. package/commands/sync.tmpl +345 -0
  41. package/commands/update-framework.md +211 -0
  42. package/commands/update-framework.tmpl +151 -0
  43. package/commands/validate-traces.md +152 -3
  44. package/commands/validate-traces.tmpl +58 -2
  45. package/core/FRAMEWORK_VERSION +1 -1
  46. package/core/commands/debug.md +189 -1
  47. package/core/commands/define-product.md +94 -1
  48. package/core/commands/fix-bug.md +190 -1
  49. package/core/commands/generate-bdd.md +314 -14
  50. package/core/commands/generate-code.md +191 -3
  51. package/core/commands/generate-design-spec.md +811 -0
  52. package/core/commands/generate-prd.md +133 -1
  53. package/core/commands/generate-spec-manifest.md +576 -0
  54. package/core/commands/generate-tech-docs.md +116 -2
  55. package/core/commands/generate-tests.md +94 -1
  56. package/core/commands/learn.md +554 -0
  57. package/core/commands/propose-scenario.md +521 -0
  58. package/core/commands/refine-prd.md +94 -1
  59. package/core/commands/report-bug.md +543 -0
  60. package/core/commands/review-code.md +190 -1
  61. package/core/commands/review-context.md +134 -1
  62. package/core/commands/review-tech-docs.md +176 -5
  63. package/core/commands/run-tests.md +119 -1
  64. package/core/commands/setup-ai-first.md +142 -4
  65. package/core/commands/smoke-test.md +94 -1
  66. package/core/commands/sync.md +405 -0
  67. package/core/commands/update-framework.md +211 -0
  68. package/core/commands/validate-traces.md +152 -3
  69. package/core/skills/code/SKILL.md +101 -2
  70. package/core/skills/debug/SKILL.md +108 -3
  71. package/core/skills/design-spec/SKILL.md +507 -0
  72. package/core/skills/discovery/SKILL.md +94 -1
  73. package/core/skills/prd/SKILL.md +14 -2
  74. package/core/skills/setup-ai-first/SKILL.md +7 -1
  75. package/core/skills/spec/SKILL.md +14 -2
  76. package/core/skills/test/SKILL.md +195 -3
  77. package/core/steps/capture-lesson.md +79 -0
  78. package/core/steps/context-loader.md +87 -0
  79. package/core/steps/report-footer.md +7 -1
  80. package/core/templates/design-spec.template.md +209 -0
  81. package/core/templates/project-context.yaml +40 -0
  82. package/package.json +1 -1
  83. package/skills/code/SKILL.md +101 -2
  84. package/skills/debug/SKILL.md +108 -3
  85. package/skills/design-spec/SKILL.md +507 -0
  86. package/skills/design-spec/SKILL.tmpl +95 -0
  87. package/skills/discovery/SKILL.md +94 -1
  88. package/skills/prd/SKILL.md +14 -2
  89. package/skills/setup-ai-first/SKILL.md +7 -1
  90. package/skills/spec/SKILL.md +14 -2
  91. package/skills/test/SKILL.md +195 -3
  92. package/steps/capture-lesson.md +79 -0
  93. package/steps/context-loader.md +87 -0
  94. package/steps/report-footer.md +7 -1
  95. package/templates/design-spec.template.md +209 -0
  96. package/templates/project-context.yaml +40 -0
@@ -0,0 +1,521 @@
1
+ # /propose-scenario — Propose a New BDD Scenario (Tester-Facing)
2
+
3
+ For **testers** who discover an edge case not covered by existing BDD. Drafts a Gherkin scenario
4
+ into a **proposals area** for PO/Dev to review and promote.
5
+
6
+ **Does NOT edit the canonical `.feature` file.** BDD is owned by PO/Dev — this command only writes
7
+ a proposal. Promotion into the real BDD is a PO/Dev action.
8
+
9
+ Usage: `/propose-scenario {UC-ID} {edge case description}`
10
+ Example: `/propose-scenario FT-001 login with email that has trailing spaces should still succeed`
11
+
12
+ ## Gate
13
+ # Gate — Universal Entry Procedure
14
+
15
+ Every command must execute this gate before proceeding with its specific logic.
16
+
17
+ ## Step 0 — Sub-Agent Mode Check
18
+
19
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
20
+
21
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
22
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
23
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
24
+ - Set target file = `payload.target_file`
25
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
26
+ - Set UC scope = `payload.uc_id` (process only this UC)
27
+ - Set line range = `payload.uc_section` (read only that PRD section)
28
+ - Proceed directly to the command-specific logic.
29
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
30
+
31
+ ## Step 0-B — Model Check
32
+
33
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
34
+
35
+ Complex generation and review commands require strong reasoning.
36
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
37
+
38
+ Display and wait for response:
39
+
40
+ ```
41
+ ⚙️ MODEL CHECK
42
+ ──────────────────────────────────────────────────────────────────
43
+ Recommended : claude-opus-4 (or latest Opus model)
44
+ Why needed : Spec analysis, architecture review, code generation
45
+ require deep reasoning. Smaller models miss edge cases.
46
+
47
+ To switch in Claude Code:
48
+ • Settings → Model → select "claude-opus"
49
+ • or: /model → choose claude-opus
50
+
51
+ Running on claude-opus?
52
+ Y — yes, on claude-opus → proceed
53
+ S — skip check (I accept lower quality risk with current model)
54
+ ──────────────────────────────────────────────────────────────────
55
+ ```
56
+
57
+ - "Y" → proceed to Step 1.
58
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
59
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
60
+
61
+ ## Step 1 — Resolve Target File
62
+
63
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
64
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
65
+ 3. If `$ARGUMENTS` is empty or no match found:
66
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
67
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
68
+ - Wait for user selection before continuing.
69
+
70
+ ## Step 2 — Execute Context Loader
71
+
72
+ Load all project context by following the procedure in `steps/context-loader.md`.
73
+ Store all loaded context in memory for use throughout this command session.
74
+
75
+ ## Step 3 — CHECKPOINT
76
+
77
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
78
+
79
+ ```
80
+ CHECKPOINT
81
+ -----------
82
+ Target : {resolved file path}
83
+ Project : {project.name from project-context.yaml}
84
+ Tech stack : {language} / {framework}
85
+ Module : {module if set, else "not configured"}
86
+ Domains : {comma-separated domain list}
87
+
88
+ Proceed? (Y/N)
89
+ ```
90
+
91
+ Wait for explicit "Y" or "N" from the user before continuing.
92
+ - "Y" → proceed to the command-specific steps below.
93
+ - "N" → stop and ask what the user wants to change.
94
+
95
+
96
+ *Note: For this command, the target in Step 1 is a UC-ID from `$ARGUMENTS`. Resolve its `.feature` file (for vocabulary + existing scenarios) and its PRD.*
97
+
98
+ ## Context
99
+ # Context Loader — Load All Project Context
100
+
101
+ Execute these steps in order. Store everything in memory for the duration of the command session.
102
+
103
+ **Priority guide (anti-lost-in-middle):**
104
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
105
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
106
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
107
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
108
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
109
+
110
+ ---
111
+
112
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
113
+
114
+ Read `.agent/project-context.yaml`. Extract and store:
115
+
116
+ **Tech Stack:**
117
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
118
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
119
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
120
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
121
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
122
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
123
+
124
+ **Conventions:**
125
+ - `conventions.build_command` → how to compile/build
126
+ - `conventions.test_command` → how to run tests
127
+ - `conventions.service_run` → how to start the service
128
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
129
+
130
+ **Domains:**
131
+ - `domains` → list of active business domains
132
+
133
+ **Paths (if present):**
134
+ - `paths.specs_dir` → BDD specs root
135
+ - `paths.prd_dir` → PRD documents root
136
+ - `paths.refinement_dir` → findings/review output dir
137
+ - `paths.product_definitions_dir` → product definitions root
138
+ - `paths.domain_knowledge_dir` → domain knowledge root
139
+ - `paths.business_dictionary` → path to business-dictionary.md
140
+ - `paths.core_entities` → path to core-entities.md
141
+ - `paths.tech_docs_dir` → technical documentation root
142
+ - `paths.trace_dir` → trace state directory
143
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
144
+
145
+ If `paths` section is absent, use these defaults:
146
+ - `specs_dir` = `specs/bdd`
147
+ - `prd_dir` = `specs/prd`
148
+ - `refinement_dir` = `.agent/review`
149
+ - `product_definitions_dir` = `specs/product-definition`
150
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
151
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
152
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
153
+ - `tech_docs_dir` = `specs/tech-docs`
154
+ - `trace_dir` = `.trace`
155
+ - `design_spec_dir` = `specs/design-spec`
156
+
157
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
158
+
159
+ ---
160
+
161
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
162
+
163
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
164
+
165
+ If `services` section is present:
166
+
167
+ **1. Detect active domain** (in priority order):
168
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
169
+ - Extract from target file path: segment immediately after `prd_dir` base path
170
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
171
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
172
+
173
+ **2. Route to service** — if active domain matches a key in `services`:
174
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
175
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
176
+ - Store `active_service` = `services.{domain}.path`
177
+ - Store `active_service_module` = `services.{domain}.module`
178
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
179
+
180
+ **3. Fallback** — if domain not detected or no matching service key:
181
+ - Keep default paths from Step 1
182
+ - Set `active_service = unresolved`
183
+
184
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
185
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
186
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
187
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
188
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
189
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
190
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
191
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
192
+
193
+ > **Why under `spec_source`:** tester feedback (`/report-bug`, `/propose-scenario`) must land in the **shared spec repo** so PO/Dev see it when they `/sync`. In single-service mode (no `spec_source`), these default to `feedback/bug-reports` and `feedback/bdd-proposals` at repo root — still shared, same repo.
194
+
195
+ ---
196
+
197
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
198
+
199
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
200
+
201
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
202
+
203
+ **1. Locate service config** — try in priority order:
204
+ - `{active_service}/.agent/project-context.yaml`
205
+ - `{active_service}/project-context.yaml`
206
+
207
+ **2. If found, override with service-specific values:**
208
+
209
+ | Variable | Source |
210
+ |----------|--------|
211
+ | `conventions.test_command` | service's `conventions.test_command` |
212
+ | `conventions.build_command` | service's `conventions.build_command` |
213
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
214
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
215
+
216
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
217
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
218
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
219
+
220
+ **4. If service config not found** — keep umbrella defaults, still set `service_root = {active_service}` (path anchor is always needed even without a config override).
221
+
222
+ ---
223
+
224
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
225
+
226
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
227
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
228
+ If the file does not exist → skip silently.
229
+
230
+ ---
231
+
232
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
233
+
234
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
235
+
236
+ Read `CLAUDE.md`. Extract and store:
237
+
238
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
239
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
240
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
241
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
242
+ - **§7 Git Conventions** → branch naming pattern, commit message format
243
+
244
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
245
+
246
+ ---
247
+
248
+ ## Step 4 — [SAFETY] Load Data Protection Rules
249
+
250
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
251
+
252
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
253
+
254
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
255
+
256
+ ---
257
+
258
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
259
+
260
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
261
+
262
+ If it exists, read it and extract:
263
+ - **Canonical Terms** → complete list of approved terms and their definitions
264
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
265
+ - **Status / Enum Registry** → allowed enum values per entity
266
+
267
+ Store the banned terms list for **active enforcement** throughout the command session:
268
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
269
+ - Replace banned terms with their canonical equivalents automatically
270
+
271
+ If the file does not exist → skip silently. Do not warn or block.
272
+
273
+ ---
274
+
275
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
276
+
277
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
278
+ Default path: `specs/domain-knowledge/core-entities.md`.
279
+
280
+ If it exists, read it and store:
281
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
282
+ - **Field name registry** → canonical field names to use in generated code and documents
283
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
284
+
285
+ **How to use this catalog:**
286
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
287
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
288
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
289
+
290
+ If the file does not exist → skip silently.
291
+
292
+ ---
293
+
294
+ ## Step 6.5 — [PLATFORM] Derive active_module and platform_type
295
+
296
+ Using `tech_stack.module` loaded in Step 1, derive and store two variables for use by all downstream commands:
297
+
298
+ ```
299
+ active_module = tech_stack.module (e.g. "java-spring", "react", "flutter")
300
+ ```
301
+
302
+ | `platform_type` | Modules |
303
+ |---|---|
304
+ | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
305
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
306
+ | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
307
+
308
+ If `tech_stack.module` is blank or not recognized → set `platform_type = "unknown"` and flag as ⚠️ in the Step 7 recap.
309
+
310
+ 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).
311
+
312
+ ---
313
+
314
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
315
+
316
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
317
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
318
+
319
+ Resolve the lessons file path:
320
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
321
+ - Else default `specs/domain-knowledge/lessons-learned.md`
322
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
323
+
324
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
325
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
326
+ - Before generating or modifying any artifact (PRD, BDD, tech-doc, code, test), check the output against every lesson whose `category` matches the current command AND whose `scope` matches the target (domain / file).
327
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
328
+
329
+ If the file does not exist → skip silently (no lessons captured yet).
330
+
331
+ ---
332
+
333
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
334
+
335
+ After loading all context, synthesize and output a compact summary block.
336
+ This recap ensures the most critical facts are stated at the END of context loading
337
+ (recency effect — freshest in working memory when the task begins).
338
+
339
+ Output exactly this block:
340
+ ```
341
+ [CTX LOADED]
342
+ Stack : {language} / {framework} / {database}
343
+ Platform : {active_module} ({platform_type})
344
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
345
+ Ticket : {ticket_prefix}-
346
+ Dict : {loaded — N canonical terms, M banned terms | missing}
347
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
348
+ Lessons : {loaded — N guardrails | none yet}
349
+ Service : {active_service} ({active_service_module}) | single-service
350
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
351
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
352
+ ```
353
+
354
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
355
+
356
+ ---
357
+
358
+ ## Context Load Complete
359
+
360
+ After completing all steps, you have loaded:
361
+ - Project identity, tech stack, module conventions
362
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
363
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
364
+ - Data protection rules (sensitive file patterns to never access)
365
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
366
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
367
+ - All configured paths
368
+
369
+ Proceed to the next step of the calling command.
370
+
371
+
372
+ ---
373
+
374
+ ## Step 1 — Resolve UC + Platform
375
+
376
+ Locate (via `spec-manifest.yaml` if present, else `paths`):
377
+ - `prd_path` + the UC's acceptance criteria list
378
+ - `bdd_path` + `active_platform` (web / app / system) — to match scenario vocabulary and `@trace` tags
379
+ - existing scenario titles for this UC (to avoid proposing a duplicate)
380
+
381
+ ## Step 2 — Coverage Decision (CRITICAL)
382
+
383
+ A BDD scenario must trace to a PRD acceptance criterion. Determine which case applies:
384
+
385
+ **Case A — behavior IS within an existing AC** (the AC implies it, BDD just lacks a scenario):
386
+ → This is a coverage gap. Proceed to draft the scenario (Step 3), mapped to that AC.
387
+
388
+ **Case B — behavior is NOT in any AC** (genuinely new requirement):
389
+ → STOP. A scenario here would have nothing to trace to. Do **not** draft it as a BDD proposal.
390
+ Instead output a **PRD change request** for the PO:
391
+ ```
392
+ ⚠️ Not covered by any PRD AC — this is a new requirement, not a coverage gap.
393
+ Route to PO: add/extend an AC in {prd_path}, then re-run /generate-bdd.
394
+ Requested behavior: {description}
395
+ Suggested AC: "{draft AC text}"
396
+ ```
397
+ Then end (no proposal file written for BDD).
398
+
399
+ If unsure which case → show the AC list and ask the tester which AC this maps to, or confirm it's new.
400
+
401
+ ## Step 3 — Draft the Scenario (Case A only)
402
+
403
+ Write Gherkin consistent with `/generate-bdd` conventions for `active_platform`:
404
+ - Use the platform vocabulary (web: clicks/sees; app: taps/sees; system: business events)
405
+ - Include `@trace` tags: `@trace.uc={UC-ID}`, `@trace.ac={AC-N}`, plus `@proposed @from-test`
406
+ - One focused scenario; concrete Given/When/Then; no implementation detail
407
+
408
+ ## Step 4 — Write the Proposal
409
+
410
+ Write to `{paths.bdd_proposals_dir}/{UC-ID}-{slug}.md` (resolved to `{spec_source}/feedback/bdd-proposals/` in umbrella mode; create dir if needed).
411
+ Do NOT touch the canonical `.feature`. The proposal doc contains the draft + review metadata
412
+ (see Output). If the source was a bug, reference its `BUG-ID`.
413
+
414
+ ## Step 5 — Handoff (so PO/Dev actually see it)
415
+
416
+ A proposal only reaches PO/Dev if it is **committed and pushed to the shared spec repo**.
417
+
418
+ ```bash
419
+ cd {spec_source} # umbrella: the spec submodule; single-service: omit
420
+ git add feedback/bdd-proposals/{UC-ID}-{slug}.md
421
+ git commit -m "qa(proposal): {UC-ID} — {title}"
422
+ git push # → PO/Dev see it on their next /sync
423
+ ```
424
+
425
+ - No push rights to the spec repo → open a PR / MR instead. Print this fallback.
426
+ - For a **PRD change request** (Case B), the same handoff applies — commit the request doc so the PO sees it.
427
+
428
+ > PO/Dev are notified through their normal routine: `/sync` lists newly-pulled proposals.
429
+
430
+ ---
431
+
432
+ ## Output
433
+
434
+ # Report Footer — Standard Command Output Format
435
+
436
+ Every command report must end with this standard footer section.
437
+
438
+ ## Status Badge
439
+
440
+ Choose one based on outcome:
441
+ - `✅ Complete` — all steps succeeded, no issues found
442
+ - `❌ Failed` — command could not complete due to a blocking error
443
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
444
+
445
+ ## Output Artifacts
446
+
447
+ List every file created or modified by this command:
448
+ ```
449
+ Output Artifacts:
450
+ {created|updated} {file-path} ({brief description})
451
+ {created|updated} {file-path} ({brief description})
452
+ ```
453
+
454
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
455
+
456
+ ## Next Command Suggestion
457
+
458
+ Suggest the logical next command based on workflow phase:
459
+
460
+ | Current command | Suggest next |
461
+ |-------------------------|-----------------------------------------------|
462
+ | /setup-ai-first | `/define-product` to start your first feature |
463
+ | /define-product | `/generate-prd {product-definition-file}` |
464
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
465
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
466
+ | /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 |
467
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
468
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
469
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
470
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
471
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
472
+ | /generate-code | First gen → `/review-code {UC-ID}`; re-gen → `/generate-tests {UC-ID}` |
473
+ | /generate-tests | `/run-tests {UC-ID}` |
474
+ | /run-tests (passing) | `/review-code {UC-ID}` |
475
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
476
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
477
+ | /smoke-test | Create PR and link to ticket |
478
+ | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
479
+ | /fix-bug | Create PR and link to ticket |
480
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
481
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
482
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
483
+ | /learn | Continue working — lesson applies on next command |
484
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
485
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
486
+
487
+ Format the footer as:
488
+ ```
489
+ ---
490
+ Status : {badge}
491
+ {Output Artifacts block}
492
+ Next : {suggested command with example arguments}
493
+ ```
494
+
495
+
496
+ ```
497
+ 📝 Scenario proposal → {paths.bdd_proposals_dir}/{UC-ID}-{slug}.md
498
+
499
+ UC : {UC-ID} ({active_platform})
500
+ Maps to AC : {AC-N} — "{AC text}"
501
+ Source : {BUG-ID if any | tester observation}
502
+
503
+ Proposed scenario (DRAFT — pending PO/Dev review):
504
+ @proposed @from-test @trace.uc={UC-ID} @trace.ac={AC-N}
505
+ Scenario: {title}
506
+ Given {…}
507
+ When {…}
508
+ Then {…}
509
+
510
+ For PO/Dev to promote:
511
+ [ ] AC mapping correct? (or update PRD if requirement is actually new)
512
+ [ ] Add scenario to {bdd_path} (edit, or re-run /generate-bdd if PRD changed)
513
+ [ ] Then: /generate-code {UC-ID} + /generate-tests {UC-ID}
514
+
515
+ Handoff : {✅ committed + pushed to spec repo | ⚠️ run git commands above / open a PR}
516
+
517
+ ---
518
+ Status : ✅ Complete (read-only on canonical BDD — proposal only)
519
+ Output Artifacts: created {paths.bdd_proposals_dir}/{UC-ID}-{slug}.md (pushed to shared spec repo)
520
+ Next : PO/Dev see it on their next /sync → review & promote
521
+ ```
@@ -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`
@@ -142,11 +143,75 @@ If `paths` section is absent, use these defaults:
142
143
  - `core_entities` = `specs/domain-knowledge/core-entities.md`
143
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
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
182
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
183
+
184
+ > **Why under `spec_source`:** tester feedback (`/report-bug`, `/propose-scenario`) must land in the **shared spec repo** so PO/Dev see it when they `/sync`. In single-service mode (no `spec_source`), these default to `feedback/bug-reports` and `feedback/bdd-proposals` at repo root — still shared, same repo.
185
+
186
+ ---
187
+
188
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
189
+
190
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
191
+
192
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
193
+
194
+ **1. Locate service config** — try in priority order:
195
+ - `{active_service}/.agent/project-context.yaml`
196
+ - `{active_service}/project-context.yaml`
197
+
198
+ **2. If found, override with service-specific values:**
199
+
200
+ | Variable | Source |
201
+ |----------|--------|
202
+ | `conventions.test_command` | service's `conventions.test_command` |
203
+ | `conventions.build_command` | service's `conventions.build_command` |
204
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
205
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
206
+
207
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
208
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
209
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
210
+
211
+ **4. If service config not found** — keep umbrella defaults, still set `service_root = {active_service}` (path anchor is always needed even without a config override).
212
+
213
+ ---
214
+
150
215
  ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
151
216
 
152
217
  If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
@@ -237,6 +302,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
237
302
 
238
303
  ---
239
304
 
305
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
306
+
307
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
308
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
309
+
310
+ Resolve the lessons file path:
311
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
312
+ - Else default `specs/domain-knowledge/lessons-learned.md`
313
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
314
+
315
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
316
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
317
+ - Before generating or modifying any artifact (PRD, BDD, tech-doc, code, test), check the output against every lesson whose `category` matches the current command AND whose `scope` matches the target (domain / file).
318
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
319
+
320
+ If the file does not exist → skip silently (no lessons captured yet).
321
+
322
+ ---
323
+
240
324
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
241
325
 
242
326
  After loading all context, synthesize and output a compact summary block.
@@ -252,6 +336,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
252
336
  Ticket : {ticket_prefix}-
253
337
  Dict : {loaded — N canonical terms, M banned terms | missing}
254
338
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
339
+ Lessons : {loaded — N guardrails | none yet}
340
+ Service : {active_service} ({active_service_module}) | single-service
341
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
255
342
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
256
343
  ```
257
344
 
@@ -349,7 +436,8 @@ Suggest the logical next command based on workflow phase:
349
436
  | /define-product | `/generate-prd {product-definition-file}` |
350
437
  | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
351
438
  | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
352
- | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
439
+ | /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 |
440
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
353
441
  | /generate-bdd | `/review-context {feature-file}` to verify coverage |
354
442
  | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
355
443
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
@@ -363,6 +451,11 @@ Suggest the logical next command based on workflow phase:
363
451
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
364
452
  | /fix-bug | Create PR and link to ticket |
365
453
  | /debug | `/fix-bug {ticket-id}` if fix needed |
454
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
455
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
456
+ | /learn | Continue working — lesson applies on next command |
457
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
458
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
366
459
 
367
460
  Format the footer as:
368
461
  ```