@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,131 @@
1
+ # /report-bug — File a Spec-Traced Bug (Tester-Facing)
2
+
3
+ For **testers**. Produces a structured bug report with full spec context, classifies the likely
4
+ layer, and saves it for handoff to the dev team.
5
+
6
+ **READ-ONLY on specs and code.** This command never edits PRD, BDD, tech-docs, or source.
7
+ Fixing is the dev's job (`/fix-bug`); writing scenarios is `/propose-scenario`.
8
+
9
+ Usage: `/report-bug {UC-ID or TICKET} {short description}`
10
+ Example: `/report-bug FT-001 account locks after 6 failed logins, spec says 5`
11
+
12
+ ## Gate
13
+ {{include:steps/gate.md}}
14
+
15
+ *Note: For this command, the target in Step 1 is a UC-ID / TICKET from `$ARGUMENTS`. Resolve the matching `.feature` file if one exists; if not, continue — a bug can still be filed.*
16
+
17
+ ## Context
18
+ {{include:steps/context-loader.md}}
19
+
20
+ ---
21
+
22
+ ## Step 1 — Resolve Spec Context
23
+
24
+ Locate the spec chain for the bug's UC/TICKET. Prefer `spec-manifest.yaml` (umbrella/tester setup) if present; else use resolved `paths`.
25
+
26
+ Gather and store:
27
+ - `prd_path` + current PRD `Version`
28
+ - `bdd_path` (the `.feature` for this UC) + the specific **failing scenario** title, if one matches
29
+ - `tech_doc_path` (if any)
30
+ - `service` / domain
31
+
32
+ If no `.feature` scenario matches the reported behavior → set `coverage_gap = true` (the behavior is untested by BDD).
33
+
34
+ ## Step 2 — Gather Bug Details
35
+
36
+ If not already in `$ARGUMENTS`, ask the tester (one compact prompt):
37
+
38
+ ```
39
+ File a bug — answer what you can:
40
+ 1. Where does it occur? (endpoint / screen / flow)
41
+ 2. Steps to reproduce?
42
+ 3. Expected (per spec) vs Actual?
43
+ 4. Error / log / status code?
44
+ 5. Environment? (staging / prod / local)
45
+ ```
46
+
47
+ ## Step 3 — Identify the AC Violated
48
+
49
+ Read the PRD acceptance criteria for this UC. Match the bug to the specific **AC** it violates
50
+ (e.g. `AC3: "5 failed logins → lock 30m"`). Quote it verbatim. If the behavior maps to no AC →
51
+ note "No AC covers this" and treat as a possible PRD gap.
52
+
53
+ ## Step 4 — Classify Likely Layer (BUG_FLOW)
54
+
55
+ Apply the BUG_FLOW decision table to suggest where the root cause likely is — this routes the bug:
56
+
57
+ | If… | Likely layer | Route to |
58
+ |------|-------------|----------|
59
+ | Code contradicts a BDD scenario | **Code bug** (Case 1) | Dev → `/fix-bug` |
60
+ | BDD scenario contradicts PRD AC | **BDD bug** (Case 2) | Dev/PO fix BDD |
61
+ | PRD AC is ambiguous / silent | **PRD ambiguity** (Case 3) | PO clarifies PRD |
62
+ | Behavior correct but **no scenario covers it** | **BDD coverage gap** | Tester → `/propose-scenario` |
63
+ | UI ≠ Design Spec | **Design Spec bug** (Case 5) | Dev/Designer |
64
+ | Env / data only | **Environment** (Case 6) | DevOps |
65
+
66
+ State the classification as a suggestion (dev confirms during `/fix-bug`).
67
+
68
+ ## Step 5 — Write the Report
69
+
70
+ Assign `BUG-{today YYYYMMDD}-{NN}` (NN = next sequence among existing reports).
71
+ Write to `{paths.bug_reports_dir}/{BUG-ID}.md` (resolved to `{spec_source}/feedback/bug-reports/` in umbrella mode; create dir if needed) using the structure in the Output block, and also print it for pasting into Jira/Slack.
72
+
73
+ ## Step 6 — Handoff (so PO/Dev actually see it)
74
+
75
+ The report only reaches PO/Dev if it is **committed and pushed to the shared spec repo**. A local file is a dead drop.
76
+
77
+ Determine the repo that owns `{paths.bug_reports_dir}`:
78
+ - Umbrella mode → the spec submodule at `{spec_source}`
79
+ - Single-service → the current repo
80
+
81
+ Then commit + push **that** repo:
82
+
83
+ ```bash
84
+ cd {spec_source} # umbrella: the spec submodule; single-service: omit
85
+ git add feedback/bug-reports/{BUG-ID}.md
86
+ git commit -m "qa(bug): {BUG-ID} — {short description}"
87
+ git push # → PO/Dev see it on their next /sync
88
+ ```
89
+
90
+ - If the tester lacks push rights to the spec repo → open a PR / MR instead, or hand the file to whoever owns it. Print this fallback.
91
+ - Print the exact commands if you do not run them automatically.
92
+
93
+ > PO/Dev are notified through their normal routine: `/sync` lists newly-pulled bug reports.
94
+
95
+ ---
96
+
97
+ ## Output
98
+
99
+ {{include:steps/report-footer.md}}
100
+
101
+ ```
102
+ 🐞 {BUG-ID} → {paths.bug_reports_dir}/{BUG-ID}.md (in shared spec repo)
103
+
104
+ Feature : {UC-ID} — {feature name} | Service: {service} | Severity: {Critical|Major|Minor}
105
+
106
+ Spec context
107
+ PRD : {prd_path} (v{prd_version})
108
+ BDD : {bdd_path} → Scenario: "{scenario title}" {or: ⚠️ no scenario covers this}
109
+ Tech Doc : {tech_doc_path}
110
+
111
+ AC violated
112
+ {AC-N}: "{AC text}"
113
+
114
+ Expected (per spec) : {expected}
115
+ Actual : {actual}
116
+ Steps to reproduce : {1..N}
117
+ Environment : {env}
118
+
119
+ Likely layer : {Code | BDD | PRD | Design Spec | Env} → {route}
120
+
121
+ Handoff : {✅ committed + pushed to spec repo | ⚠️ run the git commands above / open a PR}
122
+
123
+ ---
124
+ Status : ✅ Complete (read-only on specs/code — only wrote the feedback file)
125
+ Output Artifacts: created {paths.bug_reports_dir}/{BUG-ID}.md (pushed to shared spec repo)
126
+ Next :
127
+ - PO/Dev will see this on their next /sync
128
+ - Code bug → dev runs /fix-bug {BUG-ID}
129
+ - PRD ambiguity → PO (BUG_FLOW Case 3)
130
+ - Coverage gap → /propose-scenario {UC-ID}
131
+ ```
@@ -133,6 +133,7 @@ Read `.agent/project-context.yaml`. Extract and store:
133
133
  - `paths.core_entities` → path to core-entities.md
134
134
  - `paths.tech_docs_dir` → technical documentation root
135
135
  - `paths.trace_dir` → trace state directory
136
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
136
137
 
137
138
  If `paths` section is absent, use these defaults:
138
139
  - `specs_dir` = `specs/bdd`
@@ -144,11 +145,75 @@ If `paths` section is absent, use these defaults:
144
145
  - `core_entities` = `specs/domain-knowledge/core-entities.md`
145
146
  - `tech_docs_dir` = `specs/tech-docs`
146
147
  - `trace_dir` = `.trace`
148
+ - `design_spec_dir` = `specs/design-spec`
147
149
 
148
150
  If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
149
151
 
150
152
  ---
151
153
 
154
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
155
+
156
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
157
+
158
+ If `services` section is present:
159
+
160
+ **1. Detect active domain** (in priority order):
161
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
162
+ - Extract from target file path: segment immediately after `prd_dir` base path
163
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
164
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
165
+
166
+ **2. Route to service** — if active domain matches a key in `services`:
167
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
168
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
169
+ - Store `active_service` = `services.{domain}.path`
170
+ - Store `active_service_module` = `services.{domain}.module`
171
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
172
+
173
+ **3. Fallback** — if domain not detected or no matching service key:
174
+ - Keep default paths from Step 1
175
+ - Set `active_service = unresolved`
176
+
177
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
178
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
179
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
180
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
181
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
182
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
183
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
184
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
185
+
186
+ > **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.
187
+
188
+ ---
189
+
190
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
191
+
192
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
193
+
194
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
195
+
196
+ **1. Locate service config** — try in priority order:
197
+ - `{active_service}/.agent/project-context.yaml`
198
+ - `{active_service}/project-context.yaml`
199
+
200
+ **2. If found, override with service-specific values:**
201
+
202
+ | Variable | Source |
203
+ |----------|--------|
204
+ | `conventions.test_command` | service's `conventions.test_command` |
205
+ | `conventions.build_command` | service's `conventions.build_command` |
206
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
207
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
208
+
209
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
210
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
211
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
212
+
213
+ **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).
214
+
215
+ ---
216
+
152
217
  ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
153
218
 
154
219
  If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
@@ -239,6 +304,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
239
304
 
240
305
  ---
241
306
 
307
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
308
+
309
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
310
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
311
+
312
+ Resolve the lessons file path:
313
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
314
+ - Else default `specs/domain-knowledge/lessons-learned.md`
315
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
316
+
317
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
318
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
319
+ - 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).
320
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
321
+
322
+ If the file does not exist → skip silently (no lessons captured yet).
323
+
324
+ ---
325
+
242
326
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
243
327
 
244
328
  After loading all context, synthesize and output a compact summary block.
@@ -254,6 +338,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
254
338
  Ticket : {ticket_prefix}-
255
339
  Dict : {loaded — N canonical terms, M banned terms | missing}
256
340
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
341
+ Lessons : {loaded — N guardrails | none yet}
342
+ Service : {active_service} ({active_service_module}) | single-service
343
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
257
344
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
258
345
  ```
259
346
 
@@ -355,7 +442,8 @@ Suggest the logical next command based on workflow phase:
355
442
  | /define-product | `/generate-prd {product-definition-file}` |
356
443
  | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
357
444
  | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
358
- | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
445
+ | /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 |
446
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
359
447
  | /generate-bdd | `/review-context {feature-file}` to verify coverage |
360
448
  | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
361
449
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
@@ -369,6 +457,11 @@ Suggest the logical next command based on workflow phase:
369
457
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
370
458
  | /fix-bug | Create PR and link to ticket |
371
459
  | /debug | `/fix-bug {ticket-id}` if fix needed |
460
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
461
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
462
+ | /learn | Continue working — lesson applies on next command |
463
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
464
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
372
465
 
373
466
  Format the footer as:
374
467
  ```
@@ -404,3 +497,99 @@ If NEEDS_FIX ❌:
404
497
  - Logic / architecture issue → /fix-bug {TICKET_ID}
405
498
  - Spec mismatch (code ≠ scenario) → /generate-code {feature-file} (re-gen affected UC)
406
499
  ```
500
+
501
+ ---
502
+
503
+ ## Offer to Record Lessons (optional)
504
+
505
+ For each **Critical/Major** finding that represents a **repeatable AI mistake** during code generation
506
+ (an architecture/standards violation the AI is likely to make again — NOT a one-off typo or an external cause), ask:
507
+
508
+ ```
509
+ Finding "{issue}" looks like a repeatable mistake.
510
+ Record it as a project lesson so /generate-code won't repeat it? (Y/N)
511
+ ```
512
+
513
+ If `Y` → run the capture procedure below with `category=code-gen`, `source=/review-code {UC-ID}`,
514
+ `scope` = the affected domain or file glob.
515
+
516
+ # Capture Lesson — Record a Recurring Mistake as a Guardrail
517
+
518
+ Reusable procedure to persist a "lesson" so the AI does not repeat a mistake in this project.
519
+ Used by `/learn` (manual) and offered by `/review-code`, `/fix-bug`, `/debug` (auto).
520
+
521
+ > **Project memory, not model training.** A lesson is plain text injected into context at the
522
+ > start of every command (context-loader Step 6.7). Functionally this stops the repeat — the AI
523
+ > sees the guardrail before it generates. No model weights change.
524
+
525
+ ## L1 — Resolve the lessons file
526
+
527
+ Resolve `lessons_path` in this order:
528
+ 1. `paths.lessons_file` from loaded context (may be service-overridden in umbrella mode, Step 1.6)
529
+ 2. Default `specs/domain-knowledge/lessons-learned.md` (single-service)
530
+ 3. In umbrella/service mode (when `service_root` is set) default `{service_root}/.agent/project-lessons.md`
531
+
532
+ ## L2 — Build the lesson
533
+
534
+ Gather these fields — from `$ARGUMENTS` (for `/learn`) or from the calling command's findings
535
+ (for `/review-code`, `/fix-bug`, `/debug`):
536
+
537
+ | Field | Meaning |
538
+ |-------|---------|
539
+ | `category` | one of: `code-gen` \| `bdd` \| `tech-docs` \| `tests` \| `prd` \| `general` |
540
+ | `title` | short phrase naming the mistake |
541
+ | `mistake` | concretely, what the AI did wrong |
542
+ | `rule` | imperative correction — "Always …" / "Never …" — testable, not vague |
543
+ | `scope` | where it applies: a domain, a file glob (e.g. `*Controller.*`), or `all` |
544
+ | `source` | how captured: `/learn` \| `/review-code {UC-ID}` \| `/fix-bug {TICKET}` \| `/debug` |
545
+
546
+ If `rule` is vague (e.g. "be careful"), rewrite it into a concrete, checkable instruction before saving.
547
+
548
+ ## L3 — De-duplicate
549
+
550
+ Read existing lessons in `lessons_path`. If one already covers the same mistake:
551
+ - **Refine** that entry (tighten the Rule, widen/narrow Scope, bump Date, append the new Source) — do NOT add a duplicate.
552
+
553
+ Otherwise assign the next id `L-{NNN}` = (highest existing number + 1), zero-padded to 3 digits.
554
+
555
+ ## L4 — Write
556
+
557
+ If `lessons_path` does not exist, create it with this header first:
558
+
559
+ ```markdown
560
+ # Project Lessons — Learned Guardrails
561
+
562
+ > Mistakes the AI must NOT repeat in this project. Loaded by context-loader at the start of
563
+ > every command and treated as hard constraints (same priority as CLAUDE.md coding standards).
564
+ > Add with /learn, or accept the prompt during /review-code, /fix-bug, /debug.
565
+ > Commit this file so the whole team shares the guardrails.
566
+
567
+ | Category | Applies to |
568
+ |----------|-----------|
569
+ | code-gen | /generate-code output |
570
+ | bdd | /generate-bdd output |
571
+ | tech-docs | /generate-tech-docs output |
572
+ | tests | /generate-tests output |
573
+ | prd | /generate-prd, /refine-prd output |
574
+ | general | every command |
575
+
576
+ ---
577
+ ```
578
+
579
+ Insert the new lesson directly under the `---` separator (**newest first**), in this exact shape:
580
+
581
+ ```markdown
582
+ ### L-{NNN} — [{category}] {title}
583
+ - **Date**: {today YYYY-MM-DD}
584
+ - **Scope**: {scope}
585
+ - **Mistake**: {mistake}
586
+ - **Rule**: {rule}
587
+ - **Source**: {source}
588
+
589
+ ```
590
+
591
+ ## L5 — Confirm
592
+
593
+ Print: `📝 Lesson {id} recorded → {lessons_path} ([{category}] {title})`
594
+ Then remind: `Commit {lessons_path} so the team shares this guardrail.`
595
+
@@ -85,3 +85,20 @@ If NEEDS_FIX ❌:
85
85
  - Logic / architecture issue → /fix-bug {TICKET_ID}
86
86
  - Spec mismatch (code ≠ scenario) → /generate-code {feature-file} (re-gen affected UC)
87
87
  ```
88
+
89
+ ---
90
+
91
+ ## Offer to Record Lessons (optional)
92
+
93
+ For each **Critical/Major** finding that represents a **repeatable AI mistake** during code generation
94
+ (an architecture/standards violation the AI is likely to make again — NOT a one-off typo or an external cause), ask:
95
+
96
+ ```
97
+ Finding "{issue}" looks like a repeatable mistake.
98
+ Record it as a project lesson so /generate-code won't repeat it? (Y/N)
99
+ ```
100
+
101
+ If `Y` → run the capture procedure below with `category=code-gen`, `source=/review-code {UC-ID}`,
102
+ `scope` = the affected domain or file glob.
103
+
104
+ {{include:steps/capture-lesson.md}}
@@ -138,6 +138,7 @@ Read `.agent/project-context.yaml`. Extract and store:
138
138
  - `paths.core_entities` → path to core-entities.md
139
139
  - `paths.tech_docs_dir` → technical documentation root
140
140
  - `paths.trace_dir` → trace state directory
141
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
141
142
 
142
143
  If `paths` section is absent, use these defaults:
143
144
  - `specs_dir` = `specs/bdd`
@@ -149,11 +150,75 @@ If `paths` section is absent, use these defaults:
149
150
  - `core_entities` = `specs/domain-knowledge/core-entities.md`
150
151
  - `tech_docs_dir` = `specs/tech-docs`
151
152
  - `trace_dir` = `.trace`
153
+ - `design_spec_dir` = `specs/design-spec`
152
154
 
153
155
  If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
154
156
 
155
157
  ---
156
158
 
159
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
160
+
161
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
162
+
163
+ If `services` section is present:
164
+
165
+ **1. Detect active domain** (in priority order):
166
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
167
+ - Extract from target file path: segment immediately after `prd_dir` base path
168
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
169
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
170
+
171
+ **2. Route to service** — if active domain matches a key in `services`:
172
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
173
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
174
+ - Store `active_service` = `services.{domain}.path`
175
+ - Store `active_service_module` = `services.{domain}.module`
176
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
177
+
178
+ **3. Fallback** — if domain not detected or no matching service key:
179
+ - Keep default paths from Step 1
180
+ - Set `active_service = unresolved`
181
+
182
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
183
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
184
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
185
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
186
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
187
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
188
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
189
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
190
+
191
+ > **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.
192
+
193
+ ---
194
+
195
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
196
+
197
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
198
+
199
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
200
+
201
+ **1. Locate service config** — try in priority order:
202
+ - `{active_service}/.agent/project-context.yaml`
203
+ - `{active_service}/project-context.yaml`
204
+
205
+ **2. If found, override with service-specific values:**
206
+
207
+ | Variable | Source |
208
+ |----------|--------|
209
+ | `conventions.test_command` | service's `conventions.test_command` |
210
+ | `conventions.build_command` | service's `conventions.build_command` |
211
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
212
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
213
+
214
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
215
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
216
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
217
+
218
+ **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).
219
+
220
+ ---
221
+
157
222
  ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
158
223
 
159
224
  If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
@@ -244,6 +309,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
244
309
 
245
310
  ---
246
311
 
312
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
313
+
314
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
315
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
316
+
317
+ Resolve the lessons file path:
318
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
319
+ - Else default `specs/domain-knowledge/lessons-learned.md`
320
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
321
+
322
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
323
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
324
+ - 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).
325
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
326
+
327
+ If the file does not exist → skip silently (no lessons captured yet).
328
+
329
+ ---
330
+
247
331
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
248
332
 
249
333
  After loading all context, synthesize and output a compact summary block.
@@ -259,6 +343,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
259
343
  Ticket : {ticket_prefix}-
260
344
  Dict : {loaded — N canonical terms, M banned terms | missing}
261
345
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
346
+ Lessons : {loaded — N guardrails | none yet}
347
+ Service : {active_service} ({active_service_module}) | single-service
348
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
262
349
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
263
350
  ```
264
351
 
@@ -301,6 +388,44 @@ Derive the output findings filename:
301
388
 
302
389
  ## PRD Review Mode
303
390
 
391
+ ### P0 — Umbrella Routing Check (umbrella mode only)
392
+
393
+ *Skip this check entirely if `setup.mode` is not `"umbrella"` (i.e., `services` section absent from project-context.yaml).*
394
+
395
+ When `setup.mode = umbrella`, the PRD must have correct routing metadata so context-loader Step 1.5 can direct generated output to the right service submodule. Run these checks **before P1–P5**:
396
+
397
+ **P0.1 — `@trace.domain` presence**
398
+ - Read the PRD frontmatter block (lines starting with `@trace.` at top of file)
399
+ - If `@trace.domain` is **absent** → **critical** finding:
400
+ - `finding`: "`@trace.domain` is missing. Dev team's umbrella routing depends on this field to route BDD and code output to the correct service submodule."
401
+ - `suggestion`: "Add `@trace.domain: {domain}` to the PRD frontmatter. Use one of the domain keys defined in the umbrella's `project-context.yaml` services section."
402
+ - `auto_fixable: false` — PO must confirm the correct domain name
403
+
404
+ **P0.2 — `@trace.domain` matches a service key**
405
+ - If `@trace.domain` is present, check if its value matches any key in the `services` section of project-context.yaml
406
+ - If **no match found** → **critical** finding:
407
+ - `finding`: "`@trace.domain: {value}` does not match any key in the umbrella's `services` config. Routing will fall back to default paths and BDD may be generated to the wrong location."
408
+ - `suggestion`: "Either update `@trace.domain` to match an existing service key ({list known keys}), or add a new entry to `services` in project-context.yaml for domain `{value}`."
409
+ - `auto_fixable: false`
410
+ - If `services` section is not yet configured (empty/placeholder) → **major** finding:
411
+ - `finding`: "Umbrella `services` section is not yet configured. Cannot verify domain routing."
412
+ - `suggestion`: "Update `.agent/project-context.yaml` services section with domain-to-submodule mapping before generating BDD."
413
+ - `auto_fixable: false`
414
+
415
+ **P0.3 — `@trace.status` check**
416
+ - If `@trace.status` is absent → **minor**, `auto_fixable: true` (add `@trace.status: draft`)
417
+ - If `@trace.status: draft` → **major**, `auto_fixable: false`:
418
+ - `finding`: "PRD status is `draft`. Dev team should not generate BDD from an unapproved PRD."
419
+ - `suggestion`: "PO/SA should review and update status to `approved` before dev team proceeds."
420
+
421
+ > **P0 is a gate check:** If P0.1 or P0.2 yields a critical finding, display a warning before proceeding:
422
+ > ```
423
+ > ⚠️ ROUTING WARNING: @trace.domain issue detected.
424
+ > BDD/code generated from this PRD may land in the wrong service submodule.
425
+ > Resolve P0 findings before running /generate-bdd.
426
+ > ```
427
+ > Then continue with P1–P5 (do not abort — PO may be reviewing early-stage PRDs).
428
+
304
429
  ### P1 — Terminology Check (Business Dictionary)
305
430
 
306
431
  Load `{paths.business_dictionary}`.
@@ -493,7 +618,8 @@ Suggest the logical next command based on workflow phase:
493
618
  | /define-product | `/generate-prd {product-definition-file}` |
494
619
  | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
495
620
  | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
496
- | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
621
+ | /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 |
622
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
497
623
  | /generate-bdd | `/review-context {feature-file}` to verify coverage |
498
624
  | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
499
625
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
@@ -507,6 +633,11 @@ Suggest the logical next command based on workflow phase:
507
633
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
508
634
  | /fix-bug | Create PR and link to ticket |
509
635
  | /debug | `/fix-bug {ticket-id}` if fix needed |
636
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
637
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
638
+ | /learn | Continue working — lesson applies on next command |
639
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
640
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
510
641
 
511
642
  Format the footer as:
512
643
  ```
@@ -561,6 +692,7 @@ For each finding where `auto_fixable: true`, in order (critical → major → mi
561
692
 
562
693
  | check_id | What to apply |
563
694
  |----------|--------------|
695
+ | P0.3 (Missing status) | Add `@trace.status: draft` to frontmatter |
564
696
  | P1 (Banned term) | Replace every banned term occurrence with canonical term |
565
697
  | P4 (Structure) | Add missing section/metadata skeleton |
566
698
 
@@ -637,6 +769,7 @@ Apply in order: critical → major → minor.
637
769
  **For PRD findings:**
638
770
  | check_id | What to do |
639
771
  |----------|-----------|
772
+ | P0.3 (Missing status) | Add `@trace.status: draft` to frontmatter |
640
773
  | P1 (Banned term) | Replace every occurrence of banned term with canonical term |
641
774
  | P2 (Ambiguity) | Apply the fix stated in `suggestion` or `modified` note |
642
775
  | P3 (Conflict) | Apply the resolution stated in the modified note |
@@ -36,6 +36,44 @@ Derive the output findings filename:
36
36
 
37
37
  ## PRD Review Mode
38
38
 
39
+ ### P0 — Umbrella Routing Check (umbrella mode only)
40
+
41
+ *Skip this check entirely if `setup.mode` is not `"umbrella"` (i.e., `services` section absent from project-context.yaml).*
42
+
43
+ When `setup.mode = umbrella`, the PRD must have correct routing metadata so context-loader Step 1.5 can direct generated output to the right service submodule. Run these checks **before P1–P5**:
44
+
45
+ **P0.1 — `@trace.domain` presence**
46
+ - Read the PRD frontmatter block (lines starting with `@trace.` at top of file)
47
+ - If `@trace.domain` is **absent** → **critical** finding:
48
+ - `finding`: "`@trace.domain` is missing. Dev team's umbrella routing depends on this field to route BDD and code output to the correct service submodule."
49
+ - `suggestion`: "Add `@trace.domain: {domain}` to the PRD frontmatter. Use one of the domain keys defined in the umbrella's `project-context.yaml` services section."
50
+ - `auto_fixable: false` — PO must confirm the correct domain name
51
+
52
+ **P0.2 — `@trace.domain` matches a service key**
53
+ - If `@trace.domain` is present, check if its value matches any key in the `services` section of project-context.yaml
54
+ - If **no match found** → **critical** finding:
55
+ - `finding`: "`@trace.domain: {value}` does not match any key in the umbrella's `services` config. Routing will fall back to default paths and BDD may be generated to the wrong location."
56
+ - `suggestion`: "Either update `@trace.domain` to match an existing service key ({list known keys}), or add a new entry to `services` in project-context.yaml for domain `{value}`."
57
+ - `auto_fixable: false`
58
+ - If `services` section is not yet configured (empty/placeholder) → **major** finding:
59
+ - `finding`: "Umbrella `services` section is not yet configured. Cannot verify domain routing."
60
+ - `suggestion`: "Update `.agent/project-context.yaml` services section with domain-to-submodule mapping before generating BDD."
61
+ - `auto_fixable: false`
62
+
63
+ **P0.3 — `@trace.status` check**
64
+ - If `@trace.status` is absent → **minor**, `auto_fixable: true` (add `@trace.status: draft`)
65
+ - If `@trace.status: draft` → **major**, `auto_fixable: false`:
66
+ - `finding`: "PRD status is `draft`. Dev team should not generate BDD from an unapproved PRD."
67
+ - `suggestion`: "PO/SA should review and update status to `approved` before dev team proceeds."
68
+
69
+ > **P0 is a gate check:** If P0.1 or P0.2 yields a critical finding, display a warning before proceeding:
70
+ > ```
71
+ > ⚠️ ROUTING WARNING: @trace.domain issue detected.
72
+ > BDD/code generated from this PRD may land in the wrong service submodule.
73
+ > Resolve P0 findings before running /generate-bdd.
74
+ > ```
75
+ > Then continue with P1–P5 (do not abort — PO may be reviewing early-stage PRDs).
76
+
39
77
  ### P1 — Terminology Check (Business Dictionary)
40
78
 
41
79
  Load `{paths.business_dictionary}`.
@@ -242,6 +280,7 @@ For each finding where `auto_fixable: true`, in order (critical → major → mi
242
280
 
243
281
  | check_id | What to apply |
244
282
  |----------|--------------|
283
+ | P0.3 (Missing status) | Add `@trace.status: draft` to frontmatter |
245
284
  | P1 (Banned term) | Replace every banned term occurrence with canonical term |
246
285
  | P4 (Structure) | Add missing section/metadata skeleton |
247
286
 
@@ -318,6 +357,7 @@ Apply in order: critical → major → minor.
318
357
  **For PRD findings:**
319
358
  | check_id | What to do |
320
359
  |----------|-----------|
360
+ | P0.3 (Missing status) | Add `@trace.status: draft` to frontmatter |
321
361
  | P1 (Banned term) | Replace every occurrence of banned term with canonical term |
322
362
  | P2 (Ambiguity) | Apply the fix stated in `suggestion` or `modified` note |
323
363
  | P3 (Conflict) | Apply the resolution stated in the modified note |