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

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 (93) hide show
  1. package/ARCHITECTURE.md +6 -2
  2. package/commands/debug.md +152 -0
  3. package/commands/debug.tmpl +16 -0
  4. package/commands/define-product.md +57 -0
  5. package/commands/fix-bug.md +153 -0
  6. package/commands/fix-bug.tmpl +17 -0
  7. package/commands/generate-bdd.md +277 -13
  8. package/commands/generate-bdd.tmpl +220 -13
  9. package/commands/generate-code.md +154 -2
  10. package/commands/generate-code.tmpl +97 -2
  11. package/commands/generate-design-spec.md +57 -0
  12. package/commands/generate-prd.md +114 -20
  13. package/commands/generate-prd.tmpl +57 -20
  14. package/commands/generate-spec-manifest.md +57 -0
  15. package/commands/generate-tech-docs.md +79 -1
  16. package/commands/generate-tech-docs.tmpl +22 -1
  17. package/commands/generate-tests.md +57 -0
  18. package/commands/learn.md +554 -0
  19. package/commands/learn.tmpl +63 -0
  20. package/commands/propose-scenario.md +521 -0
  21. package/commands/propose-scenario.tmpl +109 -0
  22. package/commands/refine-prd.md +66 -1
  23. package/commands/refine-prd.tmpl +9 -1
  24. package/commands/report-bug.md +543 -0
  25. package/commands/report-bug.tmpl +131 -0
  26. package/commands/review-code.md +153 -0
  27. package/commands/review-code.tmpl +17 -0
  28. package/commands/review-context.md +65 -0
  29. package/commands/review-context.tmpl +8 -0
  30. package/commands/review-tech-docs.md +146 -4
  31. package/commands/review-tech-docs.tmpl +89 -4
  32. package/commands/run-tests.md +82 -0
  33. package/commands/run-tests.tmpl +25 -0
  34. package/commands/setup-ai-first.md +15 -5
  35. package/commands/setup-ai-first.tmpl +10 -5
  36. package/commands/smoke-test.md +57 -0
  37. package/commands/sync.md +405 -0
  38. package/commands/sync.tmpl +345 -0
  39. package/commands/update-framework.md +211 -0
  40. package/commands/update-framework.tmpl +151 -0
  41. package/commands/validate-traces.md +115 -2
  42. package/commands/validate-traces.tmpl +58 -2
  43. package/core/FRAMEWORK_VERSION +1 -1
  44. package/core/commands/debug.md +152 -0
  45. package/core/commands/define-product.md +57 -0
  46. package/core/commands/fix-bug.md +153 -0
  47. package/core/commands/generate-bdd.md +277 -13
  48. package/core/commands/generate-code.md +154 -2
  49. package/core/commands/generate-design-spec.md +57 -0
  50. package/core/commands/generate-prd.md +114 -20
  51. package/core/commands/generate-spec-manifest.md +57 -0
  52. package/core/commands/generate-tech-docs.md +79 -1
  53. package/core/commands/generate-tests.md +57 -0
  54. package/core/commands/learn.md +554 -0
  55. package/core/commands/propose-scenario.md +521 -0
  56. package/core/commands/refine-prd.md +66 -1
  57. package/core/commands/report-bug.md +543 -0
  58. package/core/commands/review-code.md +153 -0
  59. package/core/commands/review-context.md +65 -0
  60. package/core/commands/review-tech-docs.md +146 -4
  61. package/core/commands/run-tests.md +82 -0
  62. package/core/commands/setup-ai-first.md +15 -5
  63. package/core/commands/smoke-test.md +57 -0
  64. package/core/commands/sync.md +405 -0
  65. package/core/commands/update-framework.md +211 -0
  66. package/core/commands/validate-traces.md +115 -2
  67. package/core/skills/code/SKILL.md +62 -0
  68. package/core/skills/debug/SKILL.md +67 -0
  69. package/core/skills/design-spec/SKILL.md +57 -0
  70. package/core/skills/discovery/SKILL.md +57 -0
  71. package/core/skills/prd/SKILL.md +10 -0
  72. package/core/skills/setup-ai-first/SKILL.md +5 -0
  73. package/core/skills/spec/SKILL.md +10 -0
  74. package/core/skills/test/SKILL.md +119 -0
  75. package/core/steps/capture-lesson.md +79 -0
  76. package/core/steps/context-loader.md +52 -0
  77. package/core/steps/report-footer.md +5 -0
  78. package/core/templates/prd.template.md +35 -20
  79. package/core/templates/project-context.yaml +11 -0
  80. package/package.json +9 -2
  81. package/skills/code/SKILL.md +62 -0
  82. package/skills/debug/SKILL.md +67 -0
  83. package/skills/design-spec/SKILL.md +57 -0
  84. package/skills/discovery/SKILL.md +57 -0
  85. package/skills/prd/SKILL.md +10 -0
  86. package/skills/setup-ai-first/SKILL.md +5 -0
  87. package/skills/spec/SKILL.md +10 -0
  88. package/skills/test/SKILL.md +119 -0
  89. package/steps/capture-lesson.md +79 -0
  90. package/steps/context-loader.md +52 -0
  91. package/steps/report-footer.md +5 -0
  92. package/templates/prd.template.md +35 -20
  93. package/templates/project-context.yaml +11 -0
package/ARCHITECTURE.md CHANGED
@@ -196,7 +196,7 @@ spec-driven-dev/
196
196
  │ ├── build.js ← assembles *.tmpl → *.md
197
197
  │ └── index.js ← npm installer + hook installer
198
198
  ├── commands/
199
- │ └── *.tmpl ← slash commands (14 commands)
199
+ │ └── *.tmpl ← slash commands (23 commands)
200
200
  ├── hooks/
201
201
  │ ├── data-guard.js ← PreToolUse sensitive file protection
202
202
  │ └── settings.json ← hook registration template
@@ -209,10 +209,12 @@ spec-driven-dev/
209
209
  │ ├── data-protection.md ← what AI must NEVER read/write
210
210
  │ └── workflow.md ← general AI behavior rules
211
211
  ├── skills/
212
- │ └── {name}/SKILL.tmpl ← Claude plugin skills (7 skills)
212
+ │ └── {name}/SKILL.tmpl ← Claude plugin skills (8 skills)
213
213
  ├── steps/
214
214
  │ ├── gate.md ← shared: file resolve + checkpoint
215
215
  │ ├── context-loader.md ← shared: load all project context
216
+ │ ├── spawn-agent.md ← shared: sub-agent orchestration
217
+ │ ├── capture-lesson.md ← shared: record a guardrail (/learn etc.)
216
218
  │ └── report-footer.md ← shared: standard output format
217
219
  └── templates/
218
220
  ├── project-context.yaml ← consumer project config template
@@ -220,6 +222,8 @@ spec-driven-dev/
220
222
  └── platform-guide.template.md
221
223
  ```
222
224
 
225
+ > Build output (gitignored): `commands/*.md`, `skills/**/SKILL.md`, and `core/` (the distributable copied into a consumer's `.agent/` by `--init`). Consumer-side tester artifacts live in the shared spec repo under `feedback/bug-reports/` and `feedback/bdd-proposals/`.
226
+
223
227
  ---
224
228
 
225
229
  ## Maintenance Guide
package/commands/debug.md CHANGED
@@ -181,6 +181,37 @@ If `services` section is present:
181
181
  - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
182
182
  - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
183
183
  - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
184
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
185
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
186
+
187
+ > **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.
188
+
189
+ ---
190
+
191
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
192
+
193
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
194
+
195
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
196
+
197
+ **1. Locate service config** — try in priority order:
198
+ - `{active_service}/.agent/project-context.yaml`
199
+ - `{active_service}/project-context.yaml`
200
+
201
+ **2. If found, override with service-specific values:**
202
+
203
+ | Variable | Source |
204
+ |----------|--------|
205
+ | `conventions.test_command` | service's `conventions.test_command` |
206
+ | `conventions.build_command` | service's `conventions.build_command` |
207
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
208
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
209
+
210
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
211
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
212
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
213
+
214
+ **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).
184
215
 
185
216
  ---
186
217
 
@@ -274,6 +305,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
274
305
 
275
306
  ---
276
307
 
308
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
309
+
310
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
311
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
312
+
313
+ Resolve the lessons file path:
314
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
315
+ - Else default `specs/domain-knowledge/lessons-learned.md`
316
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
317
+
318
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
319
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
320
+ - 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).
321
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
322
+
323
+ If the file does not exist → skip silently (no lessons captured yet).
324
+
325
+ ---
326
+
277
327
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
278
328
 
279
329
  After loading all context, synthesize and output a compact summary block.
@@ -289,7 +339,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
289
339
  Ticket : {ticket_prefix}-
290
340
  Dict : {loaded — N canonical terms, M banned terms | missing}
291
341
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
342
+ Lessons : {loaded — N guardrails | none yet}
292
343
  Service : {active_service} ({active_service_module}) | single-service
344
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
293
345
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
294
346
  ```
295
347
 
@@ -562,6 +614,11 @@ Suggest the logical next command based on workflow phase:
562
614
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
563
615
  | /fix-bug | Create PR and link to ticket |
564
616
  | /debug | `/fix-bug {ticket-id}` if fix needed |
617
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
618
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
619
+ | /learn | Continue working — lesson applies on next command |
620
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
621
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
565
622
 
566
623
  Format the footer as:
567
624
  ```
@@ -594,3 +651,98 @@ See CLAUDE.md §{section}
594
651
  - To fully fix → /fix-bug {TICKET_ID}
595
652
  - Just needed analysis → done
596
653
  ```
654
+
655
+ ---
656
+
657
+ ## Offer to Record a Lesson (optional)
658
+
659
+ If the root cause is a **mistake the AI made when generating code and could repeat**
660
+ (not an environment/config issue or external cause), ask:
661
+
662
+ ```
663
+ This looks like a repeatable AI mistake. Record it as a project lesson? (Y/N)
664
+ ```
665
+
666
+ If `Y` → run the capture procedure below with `source=/debug`, an appropriate `category`
667
+ (usually `code-gen`), and `scope` = the affected domain or file glob.
668
+
669
+ # Capture Lesson — Record a Recurring Mistake as a Guardrail
670
+
671
+ Reusable procedure to persist a "lesson" so the AI does not repeat a mistake in this project.
672
+ Used by `/learn` (manual) and offered by `/review-code`, `/fix-bug`, `/debug` (auto).
673
+
674
+ > **Project memory, not model training.** A lesson is plain text injected into context at the
675
+ > start of every command (context-loader Step 6.7). Functionally this stops the repeat — the AI
676
+ > sees the guardrail before it generates. No model weights change.
677
+
678
+ ## L1 — Resolve the lessons file
679
+
680
+ Resolve `lessons_path` in this order:
681
+ 1. `paths.lessons_file` from loaded context (may be service-overridden in umbrella mode, Step 1.6)
682
+ 2. Default `specs/domain-knowledge/lessons-learned.md` (single-service)
683
+ 3. In umbrella/service mode (when `service_root` is set) default `{service_root}/.agent/project-lessons.md`
684
+
685
+ ## L2 — Build the lesson
686
+
687
+ Gather these fields — from `$ARGUMENTS` (for `/learn`) or from the calling command's findings
688
+ (for `/review-code`, `/fix-bug`, `/debug`):
689
+
690
+ | Field | Meaning |
691
+ |-------|---------|
692
+ | `category` | one of: `code-gen` \| `bdd` \| `tech-docs` \| `tests` \| `prd` \| `general` |
693
+ | `title` | short phrase naming the mistake |
694
+ | `mistake` | concretely, what the AI did wrong |
695
+ | `rule` | imperative correction — "Always …" / "Never …" — testable, not vague |
696
+ | `scope` | where it applies: a domain, a file glob (e.g. `*Controller.*`), or `all` |
697
+ | `source` | how captured: `/learn` \| `/review-code {UC-ID}` \| `/fix-bug {TICKET}` \| `/debug` |
698
+
699
+ If `rule` is vague (e.g. "be careful"), rewrite it into a concrete, checkable instruction before saving.
700
+
701
+ ## L3 — De-duplicate
702
+
703
+ Read existing lessons in `lessons_path`. If one already covers the same mistake:
704
+ - **Refine** that entry (tighten the Rule, widen/narrow Scope, bump Date, append the new Source) — do NOT add a duplicate.
705
+
706
+ Otherwise assign the next id `L-{NNN}` = (highest existing number + 1), zero-padded to 3 digits.
707
+
708
+ ## L4 — Write
709
+
710
+ If `lessons_path` does not exist, create it with this header first:
711
+
712
+ ```markdown
713
+ # Project Lessons — Learned Guardrails
714
+
715
+ > Mistakes the AI must NOT repeat in this project. Loaded by context-loader at the start of
716
+ > every command and treated as hard constraints (same priority as CLAUDE.md coding standards).
717
+ > Add with /learn, or accept the prompt during /review-code, /fix-bug, /debug.
718
+ > Commit this file so the whole team shares the guardrails.
719
+
720
+ | Category | Applies to |
721
+ |----------|-----------|
722
+ | code-gen | /generate-code output |
723
+ | bdd | /generate-bdd output |
724
+ | tech-docs | /generate-tech-docs output |
725
+ | tests | /generate-tests output |
726
+ | prd | /generate-prd, /refine-prd output |
727
+ | general | every command |
728
+
729
+ ---
730
+ ```
731
+
732
+ Insert the new lesson directly under the `---` separator (**newest first**), in this exact shape:
733
+
734
+ ```markdown
735
+ ### L-{NNN} — [{category}] {title}
736
+ - **Date**: {today YYYY-MM-DD}
737
+ - **Scope**: {scope}
738
+ - **Mistake**: {mistake}
739
+ - **Rule**: {rule}
740
+ - **Source**: {source}
741
+
742
+ ```
743
+
744
+ ## L5 — Confirm
745
+
746
+ Print: `📝 Lesson {id} recorded → {lessons_path} ([{category}] {title})`
747
+ Then remind: `Commit {lessons_path} so the team shares this guardrail.`
748
+
@@ -239,3 +239,19 @@ See CLAUDE.md §{section}
239
239
  - To fully fix → /fix-bug {TICKET_ID}
240
240
  - Just needed analysis → done
241
241
  ```
242
+
243
+ ---
244
+
245
+ ## Offer to Record a Lesson (optional)
246
+
247
+ If the root cause is a **mistake the AI made when generating code and could repeat**
248
+ (not an environment/config issue or external cause), ask:
249
+
250
+ ```
251
+ This looks like a repeatable AI mistake. Record it as a project lesson? (Y/N)
252
+ ```
253
+
254
+ If `Y` → run the capture procedure below with `source=/debug`, an appropriate `category`
255
+ (usually `code-gen`), and `scope` = the affected domain or file glob.
256
+
257
+ {{include:steps/capture-lesson.md}}
@@ -178,6 +178,37 @@ If `services` section is present:
178
178
  - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
179
179
  - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
180
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).
181
212
 
182
213
  ---
183
214
 
@@ -271,6 +302,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
271
302
 
272
303
  ---
273
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
+
274
324
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
275
325
 
276
326
  After loading all context, synthesize and output a compact summary block.
@@ -286,7 +336,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
286
336
  Ticket : {ticket_prefix}-
287
337
  Dict : {loaded — N canonical terms, M banned terms | missing}
288
338
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
339
+ Lessons : {loaded — N guardrails | none yet}
289
340
  Service : {active_service} ({active_service_module}) | single-service
341
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
290
342
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
291
343
  ```
292
344
 
@@ -496,6 +548,11 @@ Suggest the logical next command based on workflow phase:
496
548
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
497
549
  | /fix-bug | Create PR and link to ticket |
498
550
  | /debug | `/fix-bug {ticket-id}` if fix needed |
551
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
552
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
553
+ | /learn | Continue working — lesson applies on next command |
554
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
555
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
499
556
 
500
557
  Format the footer as:
501
558
  ```
@@ -178,6 +178,37 @@ If `services` section is present:
178
178
  - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
179
179
  - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
180
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).
181
212
 
182
213
  ---
183
214
 
@@ -271,6 +302,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
271
302
 
272
303
  ---
273
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
+
274
324
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
275
325
 
276
326
  After loading all context, synthesize and output a compact summary block.
@@ -286,7 +336,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
286
336
  Ticket : {ticket_prefix}-
287
337
  Dict : {loaded — N canonical terms, M banned terms | missing}
288
338
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
339
+ Lessons : {loaded — N guardrails | none yet}
289
340
  Service : {active_service} ({active_service_module}) | single-service
341
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
290
342
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
291
343
  ```
292
344
 
@@ -410,6 +462,101 @@ git commit -m "fix({TICKET_ID}): {description}"
410
462
  git push -u origin fix/{TICKET_ID}-{slug}
411
463
  ```
412
464
 
465
+ ## Phase 6 — Offer to Record a Lesson (optional)
466
+
467
+ If the root cause was a **mistake the AI made during generation and could repeat**
468
+ (e.g. it generated code that skipped a layer, missed a null guard, used a wrong pattern —
469
+ NOT an external cause like a third-party outage or bad input data), ask:
470
+
471
+ ```
472
+ This root cause looks like a repeatable AI mistake.
473
+ Record it as a project lesson so it isn't generated again? (Y/N)
474
+ ```
475
+
476
+ If `Y` → run the capture procedure below with `source=/fix-bug {TICKET_ID}`, an appropriate
477
+ `category` (usually `code-gen`), and `scope` = the affected domain or file glob.
478
+
479
+ # Capture Lesson — Record a Recurring Mistake as a Guardrail
480
+
481
+ Reusable procedure to persist a "lesson" so the AI does not repeat a mistake in this project.
482
+ Used by `/learn` (manual) and offered by `/review-code`, `/fix-bug`, `/debug` (auto).
483
+
484
+ > **Project memory, not model training.** A lesson is plain text injected into context at the
485
+ > start of every command (context-loader Step 6.7). Functionally this stops the repeat — the AI
486
+ > sees the guardrail before it generates. No model weights change.
487
+
488
+ ## L1 — Resolve the lessons file
489
+
490
+ Resolve `lessons_path` in this order:
491
+ 1. `paths.lessons_file` from loaded context (may be service-overridden in umbrella mode, Step 1.6)
492
+ 2. Default `specs/domain-knowledge/lessons-learned.md` (single-service)
493
+ 3. In umbrella/service mode (when `service_root` is set) default `{service_root}/.agent/project-lessons.md`
494
+
495
+ ## L2 — Build the lesson
496
+
497
+ Gather these fields — from `$ARGUMENTS` (for `/learn`) or from the calling command's findings
498
+ (for `/review-code`, `/fix-bug`, `/debug`):
499
+
500
+ | Field | Meaning |
501
+ |-------|---------|
502
+ | `category` | one of: `code-gen` \| `bdd` \| `tech-docs` \| `tests` \| `prd` \| `general` |
503
+ | `title` | short phrase naming the mistake |
504
+ | `mistake` | concretely, what the AI did wrong |
505
+ | `rule` | imperative correction — "Always …" / "Never …" — testable, not vague |
506
+ | `scope` | where it applies: a domain, a file glob (e.g. `*Controller.*`), or `all` |
507
+ | `source` | how captured: `/learn` \| `/review-code {UC-ID}` \| `/fix-bug {TICKET}` \| `/debug` |
508
+
509
+ If `rule` is vague (e.g. "be careful"), rewrite it into a concrete, checkable instruction before saving.
510
+
511
+ ## L3 — De-duplicate
512
+
513
+ Read existing lessons in `lessons_path`. If one already covers the same mistake:
514
+ - **Refine** that entry (tighten the Rule, widen/narrow Scope, bump Date, append the new Source) — do NOT add a duplicate.
515
+
516
+ Otherwise assign the next id `L-{NNN}` = (highest existing number + 1), zero-padded to 3 digits.
517
+
518
+ ## L4 — Write
519
+
520
+ If `lessons_path` does not exist, create it with this header first:
521
+
522
+ ```markdown
523
+ # Project Lessons — Learned Guardrails
524
+
525
+ > Mistakes the AI must NOT repeat in this project. Loaded by context-loader at the start of
526
+ > every command and treated as hard constraints (same priority as CLAUDE.md coding standards).
527
+ > Add with /learn, or accept the prompt during /review-code, /fix-bug, /debug.
528
+ > Commit this file so the whole team shares the guardrails.
529
+
530
+ | Category | Applies to |
531
+ |----------|-----------|
532
+ | code-gen | /generate-code output |
533
+ | bdd | /generate-bdd output |
534
+ | tech-docs | /generate-tech-docs output |
535
+ | tests | /generate-tests output |
536
+ | prd | /generate-prd, /refine-prd output |
537
+ | general | every command |
538
+
539
+ ---
540
+ ```
541
+
542
+ Insert the new lesson directly under the `---` separator (**newest first**), in this exact shape:
543
+
544
+ ```markdown
545
+ ### L-{NNN} — [{category}] {title}
546
+ - **Date**: {today YYYY-MM-DD}
547
+ - **Scope**: {scope}
548
+ - **Mistake**: {mistake}
549
+ - **Rule**: {rule}
550
+ - **Source**: {source}
551
+
552
+ ```
553
+
554
+ ## L5 — Confirm
555
+
556
+ Print: `📝 Lesson {id} recorded → {lessons_path} ([{category}] {title})`
557
+ Then remind: `Commit {lessons_path} so the team shares this guardrail.`
558
+
559
+
413
560
  ## Output
414
561
 
415
562
  # Report Footer — Standard Command Output Format
@@ -459,6 +606,11 @@ Suggest the logical next command based on workflow phase:
459
606
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
460
607
  | /fix-bug | Create PR and link to ticket |
461
608
  | /debug | `/fix-bug {ticket-id}` if fix needed |
609
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
610
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
611
+ | /learn | Continue working — lesson applies on next command |
612
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
613
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
462
614
 
463
615
  Format the footer as:
464
616
  ```
@@ -474,6 +626,7 @@ Next : {suggested command with example arguments}
474
626
  Root Cause: {analysis}
475
627
  Changes: {list}
476
628
  ✅ Regression test added | ✅ Build: SUCCESS
629
+ {📝 Lesson L-NNN recorded (if captured)}
477
630
  Branch: fix/{TICKET_ID}-{slug}
478
631
  Next: Create PR and link to ticket.
479
632
  ```
@@ -110,6 +110,22 @@ git commit -m "fix({TICKET_ID}): {description}"
110
110
  git push -u origin fix/{TICKET_ID}-{slug}
111
111
  ```
112
112
 
113
+ ## Phase 6 — Offer to Record a Lesson (optional)
114
+
115
+ If the root cause was a **mistake the AI made during generation and could repeat**
116
+ (e.g. it generated code that skipped a layer, missed a null guard, used a wrong pattern —
117
+ NOT an external cause like a third-party outage or bad input data), ask:
118
+
119
+ ```
120
+ This root cause looks like a repeatable AI mistake.
121
+ Record it as a project lesson so it isn't generated again? (Y/N)
122
+ ```
123
+
124
+ If `Y` → run the capture procedure below with `source=/fix-bug {TICKET_ID}`, an appropriate
125
+ `category` (usually `code-gen`), and `scope` = the affected domain or file glob.
126
+
127
+ {{include:steps/capture-lesson.md}}
128
+
113
129
  ## Output
114
130
 
115
131
  {{include:steps/report-footer.md}}
@@ -119,6 +135,7 @@ git push -u origin fix/{TICKET_ID}-{slug}
119
135
  Root Cause: {analysis}
120
136
  Changes: {list}
121
137
  ✅ Regression test added | ✅ Build: SUCCESS
138
+ {📝 Lesson L-NNN recorded (if captured)}
122
139
  Branch: fix/{TICKET_ID}-{slug}
123
140
  Next: Create PR and link to ticket.
124
141
  ```