@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
@@ -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
 
@@ -330,6 +382,39 @@ Read:
330
382
 
331
383
  ---
332
384
 
385
+ ## Phase Detection
386
+
387
+ Parse `$ARGUMENTS` for a `--phase` flag:
388
+
389
+ | Flag | Meaning |
390
+ |---|---|
391
+ | `--phase=ui` | FE Phase 1 — generate UI + mock API layer from System BDD contract |
392
+ | `--phase=integration` | FE Phase 2 — replace mock adapter with real API calls from tech docs |
393
+ | *(none)* | Default — full implementation (BE or full-stack without mock split) |
394
+
395
+ **If `--phase` is set — confirm platform:**
396
+ Read `@trace.platform` from the feature file header.
397
+ - If `system` → warn: "`--phase` flag is not applicable for system BDD (BE-facing). Proceeding with default mode." Treat as no flag.
398
+ - If `web` or `app` → continue with phase logic below.
399
+
400
+ **If `--phase=ui`:**
401
+ Load System BDD for this UC: find `{specs_dir}/{domain}/system/{TICKET-ID}*.feature`.
402
+ Extract all `Then` clauses → collect implied response shapes and error states.
403
+ If System BDD not found → warn: "System BDD not found — mock layer will use placeholder fixtures." Continue.
404
+
405
+ **If `--phase=integration`:**
406
+ Read tech-doc `@trace.status` from `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`.
407
+ If `draft` or `in-review` → warn:
408
+ ```
409
+ ⚠ Tech docs for {UC-ID} are {status}.
410
+ BE may not have a stable API contract yet.
411
+ Proceeding — ensure BE endpoint is deployed or confirm contract manually.
412
+ ```
413
+ Locate existing mock adapter from `--phase=ui` run (search for `{UC-ID}MockApiAdapter` in `{paths.src_dir}/{domain}/`).
414
+ If not found → warn: "Mock adapter not found — generating real API adapter from scratch using tech-doc contract."
415
+
416
+ ---
417
+
333
418
  ## Read Trace State
334
419
 
335
420
  Read `{paths.trace_dir}/{UC-ID}.tsv` if it exists. For each scenario row, note its current `status`:
@@ -374,6 +459,7 @@ Ticket : {TICKET_ID if known}
374
459
  Domain : {domain}
375
460
  UC : {UC-ID} only ← other feature files in this folder are NOT read
376
461
  Tech : {language} / {framework}
462
+ Phase : {UI — mock layer | Integration — real API | Default — full} ← omit if no --phase flag
377
463
  Scenarios: {N} total ({X} new, {Y} drifted, {Z} synced-skip)
378
464
  Layer : {from CLAUDE.md §2}
379
465
 
@@ -420,6 +506,53 @@ DTOs → Entity/Model → Repository → Service interface → Service impl →
420
506
 
421
507
  > **Entry-point rule:** `@trace.implements` must appear on the **entry-point layer** as defined in `CLAUDE.md §2`. For REST APIs → Controller. For event-driven modules → event handler / consumer class. For context-engineering → the prompt orchestration function. Never put it only on an inner layer.
422
508
 
509
+ ## Mock API Layer (`--phase=ui` only)
510
+
511
+ *Skip this section entirely if `--phase` is not `ui`.*
512
+
513
+ Using the System BDD `Then` clauses loaded in Phase Detection:
514
+
515
+ 1. **Extract fixture data** per scenario — success responses + error responses.
516
+ 2. **Generate mock adapter** at `{paths.src_dir}/{domain}/{UC-ID}MockApiAdapter.{ext}`:
517
+ - Implements interface `{UC-ID}ApiPort` (same interface the real adapter will implement)
518
+ - Each method returns fixture data matching the BDD `Then` clause
519
+ - Include both success and error states (map to error scenarios in BDD)
520
+ - Traceability tags:
521
+ ```
522
+ @trace.mock_for={UC-ID}
523
+ @trace.system_bdd={paths.specs_dir}/{domain}/system/{UC-ID}*.feature
524
+ ```
525
+ 3. **Wire into service/hook layer** via environment flag or DI:
526
+ ```
527
+ const adapter = IS_MOCK ? new {UC-ID}MockApiAdapter() : new {UC-ID}ApiAdapter()
528
+ ```
529
+ - `IS_MOCK` defaults to `true` in development/test env until real adapter is generated.
530
+
531
+ > Tester uses the mock adapter to test all FE scenarios without waiting for BE.
532
+ > Mock fixture data is derived directly from System BDD — BDD is the source of truth.
533
+
534
+ ---
535
+
536
+ ## Integration Phase (`--phase=integration` only)
537
+
538
+ *Skip this section entirely if `--phase` is not `integration`.*
539
+
540
+ 1. **Read tech-doc API contract** from `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md` — extract endpoints, request/response shapes, error codes.
541
+ 2. **Read existing mock adapter** interface (`{UC-ID}ApiPort`) from the `--phase=ui` output.
542
+ 3. **Generate real API adapter** at `{paths.src_dir}/{domain}/{UC-ID}ApiAdapter.{ext}`:
543
+ - Implements the same `{UC-ID}ApiPort` interface as mock adapter
544
+ - Makes real HTTP calls to endpoints from tech-doc contract
545
+ - Maps response fields to the same shapes the mock adapter returned
546
+ - Traceability tags:
547
+ ```
548
+ @trace.implements={UC-ID}-SC{N}
549
+ @trace.tech_doc_revision={read from tech-doc header}
550
+ ```
551
+ 4. **Flip wire-up**: switch DI binding / env flag so service/hook uses `{UC-ID}ApiAdapter` (real) instead of mock.
552
+ 5. **Do NOT delete mock adapter** — keep it for unit testing.
553
+
554
+ ---
555
+
423
556
  ## Self-Review (3 rounds)
424
557
  - [ ] Every scenario has a corresponding endpoint
425
558
  - [ ] @trace.implements on every endpoint
@@ -442,6 +575,7 @@ Update `{paths.trace_dir}/{UC-ID}.tsv` — for each implemented scenario, find t
442
575
  | `implemented_by` | `{ControllerClass}.{methodName}` |
443
576
  | `bdd_version` | `@trace.bdd_version` from `.feature` header |
444
577
  | `tech_doc_revision` | `@trace.revision` from tech-doc header, or `—` if no tech-doc |
578
+ | `fe_phase` | `ui` if `--phase=ui` \| `integrated` if `--phase=integration` \| `—` if no phase flag |
445
579
  | `last_updated` | today `YYYY-MM-DD` |
446
580
 
447
581
  Leave all other columns (`sc_title`, `spec_ver`, `prd_version`, `prd_status`, `uc_status`, `test_count`, `test_classes`) unchanged.
@@ -502,6 +636,11 @@ Suggest the logical next command based on workflow phase:
502
636
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
503
637
  | /fix-bug | Create PR and link to ticket |
504
638
  | /debug | `/fix-bug {ticket-id}` if fix needed |
639
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
640
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
641
+ | /learn | Continue working — lesson applies on next command |
642
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
643
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
505
644
 
506
645
  Format the footer as:
507
646
  ```
@@ -516,7 +655,20 @@ Next : {suggested command with example arguments}
516
655
  /generate-code Complete — {UC-ID}
517
656
  Files: created={N}, extended={M}, skipped={K} | Build: SUCCESS
518
657
  Branch: feature/{TICKET_ID}-{slug}
658
+ Phase : {UI (mock layer) | Integration (real API) | Default (full)}
659
+ fe_phase : {ui | integrated | —}
660
+
519
661
  Next:
520
- First generation for this UC → /review-code {UC-ID} ← code review required before tests
521
- Re-generation (already reviewed) /generate-tests {UC-ID}
662
+ --phase=ui done:
663
+ Notify tester: FE is testable via mock adapter
664
+ → Collect BE sign-offs → /review-tech-docs {tech-design-file}
665
+ → When BE ready → /generate-code {feature-file} --phase=integration
666
+
667
+ --phase=integration done:
668
+ → /review-code {UC-ID} ← code review required
669
+ → /generate-tests {UC-ID} ← integration test suite
670
+
671
+ Default (no phase flag):
672
+ → /review-code {UC-ID} ← code review required before tests
673
+ → /generate-tests {UC-ID}
522
674
  ```
@@ -30,6 +30,39 @@ Read:
30
30
 
31
31
  ---
32
32
 
33
+ ## Phase Detection
34
+
35
+ Parse `$ARGUMENTS` for a `--phase` flag:
36
+
37
+ | Flag | Meaning |
38
+ |---|---|
39
+ | `--phase=ui` | FE Phase 1 — generate UI + mock API layer from System BDD contract |
40
+ | `--phase=integration` | FE Phase 2 — replace mock adapter with real API calls from tech docs |
41
+ | *(none)* | Default — full implementation (BE or full-stack without mock split) |
42
+
43
+ **If `--phase` is set — confirm platform:**
44
+ Read `@trace.platform` from the feature file header.
45
+ - If `system` → warn: "`--phase` flag is not applicable for system BDD (BE-facing). Proceeding with default mode." Treat as no flag.
46
+ - If `web` or `app` → continue with phase logic below.
47
+
48
+ **If `--phase=ui`:**
49
+ Load System BDD for this UC: find `{specs_dir}/{domain}/system/{TICKET-ID}*.feature`.
50
+ Extract all `Then` clauses → collect implied response shapes and error states.
51
+ If System BDD not found → warn: "System BDD not found — mock layer will use placeholder fixtures." Continue.
52
+
53
+ **If `--phase=integration`:**
54
+ Read tech-doc `@trace.status` from `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`.
55
+ If `draft` or `in-review` → warn:
56
+ ```
57
+ ⚠ Tech docs for {UC-ID} are {status}.
58
+ BE may not have a stable API contract yet.
59
+ Proceeding — ensure BE endpoint is deployed or confirm contract manually.
60
+ ```
61
+ Locate existing mock adapter from `--phase=ui` run (search for `{UC-ID}MockApiAdapter` in `{paths.src_dir}/{domain}/`).
62
+ If not found → warn: "Mock adapter not found — generating real API adapter from scratch using tech-doc contract."
63
+
64
+ ---
65
+
33
66
  ## Read Trace State
34
67
 
35
68
  Read `{paths.trace_dir}/{UC-ID}.tsv` if it exists. For each scenario row, note its current `status`:
@@ -74,6 +107,7 @@ Ticket : {TICKET_ID if known}
74
107
  Domain : {domain}
75
108
  UC : {UC-ID} only ← other feature files in this folder are NOT read
76
109
  Tech : {language} / {framework}
110
+ Phase : {UI — mock layer | Integration — real API | Default — full} ← omit if no --phase flag
77
111
  Scenarios: {N} total ({X} new, {Y} drifted, {Z} synced-skip)
78
112
  Layer : {from CLAUDE.md §2}
79
113
 
@@ -120,6 +154,53 @@ DTOs → Entity/Model → Repository → Service interface → Service impl →
120
154
 
121
155
  > **Entry-point rule:** `@trace.implements` must appear on the **entry-point layer** as defined in `CLAUDE.md §2`. For REST APIs → Controller. For event-driven modules → event handler / consumer class. For context-engineering → the prompt orchestration function. Never put it only on an inner layer.
122
156
 
157
+ ## Mock API Layer (`--phase=ui` only)
158
+
159
+ *Skip this section entirely if `--phase` is not `ui`.*
160
+
161
+ Using the System BDD `Then` clauses loaded in Phase Detection:
162
+
163
+ 1. **Extract fixture data** per scenario — success responses + error responses.
164
+ 2. **Generate mock adapter** at `{paths.src_dir}/{domain}/{UC-ID}MockApiAdapter.{ext}`:
165
+ - Implements interface `{UC-ID}ApiPort` (same interface the real adapter will implement)
166
+ - Each method returns fixture data matching the BDD `Then` clause
167
+ - Include both success and error states (map to error scenarios in BDD)
168
+ - Traceability tags:
169
+ ```
170
+ @trace.mock_for={UC-ID}
171
+ @trace.system_bdd={paths.specs_dir}/{domain}/system/{UC-ID}*.feature
172
+ ```
173
+ 3. **Wire into service/hook layer** via environment flag or DI:
174
+ ```
175
+ const adapter = IS_MOCK ? new {UC-ID}MockApiAdapter() : new {UC-ID}ApiAdapter()
176
+ ```
177
+ - `IS_MOCK` defaults to `true` in development/test env until real adapter is generated.
178
+
179
+ > Tester uses the mock adapter to test all FE scenarios without waiting for BE.
180
+ > Mock fixture data is derived directly from System BDD — BDD is the source of truth.
181
+
182
+ ---
183
+
184
+ ## Integration Phase (`--phase=integration` only)
185
+
186
+ *Skip this section entirely if `--phase` is not `integration`.*
187
+
188
+ 1. **Read tech-doc API contract** from `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md` — extract endpoints, request/response shapes, error codes.
189
+ 2. **Read existing mock adapter** interface (`{UC-ID}ApiPort`) from the `--phase=ui` output.
190
+ 3. **Generate real API adapter** at `{paths.src_dir}/{domain}/{UC-ID}ApiAdapter.{ext}`:
191
+ - Implements the same `{UC-ID}ApiPort` interface as mock adapter
192
+ - Makes real HTTP calls to endpoints from tech-doc contract
193
+ - Maps response fields to the same shapes the mock adapter returned
194
+ - Traceability tags:
195
+ ```
196
+ @trace.implements={UC-ID}-SC{N}
197
+ @trace.tech_doc_revision={read from tech-doc header}
198
+ ```
199
+ 4. **Flip wire-up**: switch DI binding / env flag so service/hook uses `{UC-ID}ApiAdapter` (real) instead of mock.
200
+ 5. **Do NOT delete mock adapter** — keep it for unit testing.
201
+
202
+ ---
203
+
123
204
  ## Self-Review (3 rounds)
124
205
  - [ ] Every scenario has a corresponding endpoint
125
206
  - [ ] @trace.implements on every endpoint
@@ -142,6 +223,7 @@ Update `{paths.trace_dir}/{UC-ID}.tsv` — for each implemented scenario, find t
142
223
  | `implemented_by` | `{ControllerClass}.{methodName}` |
143
224
  | `bdd_version` | `@trace.bdd_version` from `.feature` header |
144
225
  | `tech_doc_revision` | `@trace.revision` from tech-doc header, or `—` if no tech-doc |
226
+ | `fe_phase` | `ui` if `--phase=ui` \| `integrated` if `--phase=integration` \| `—` if no phase flag |
145
227
  | `last_updated` | today `YYYY-MM-DD` |
146
228
 
147
229
  Leave all other columns (`sc_title`, `spec_ver`, `prd_version`, `prd_status`, `uc_status`, `test_count`, `test_classes`) unchanged.
@@ -161,7 +243,20 @@ git commit -m "{commit_format}: {description}"
161
243
  /generate-code Complete — {UC-ID}
162
244
  Files: created={N}, extended={M}, skipped={K} | Build: SUCCESS
163
245
  Branch: feature/{TICKET_ID}-{slug}
246
+ Phase : {UI (mock layer) | Integration (real API) | Default (full)}
247
+ fe_phase : {ui | integrated | —}
248
+
164
249
  Next:
165
- First generation for this UC → /review-code {UC-ID} ← code review required before tests
166
- Re-generation (already reviewed) /generate-tests {UC-ID}
250
+ --phase=ui done:
251
+ Notify tester: FE is testable via mock adapter
252
+ → Collect BE sign-offs → /review-tech-docs {tech-design-file}
253
+ → When BE ready → /generate-code {feature-file} --phase=integration
254
+
255
+ --phase=integration done:
256
+ → /review-code {UC-ID} ← code review required
257
+ → /generate-tests {UC-ID} ← integration test suite
258
+
259
+ Default (no phase flag):
260
+ → /review-code {UC-ID} ← code review required before tests
261
+ → /generate-tests {UC-ID}
167
262
  ```
@@ -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
 
@@ -733,6 +785,11 @@ Suggest the logical next command based on workflow phase:
733
785
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
734
786
  | /fix-bug | Create PR and link to ticket |
735
787
  | /debug | `/fix-bug {ticket-id}` if fix needed |
788
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
789
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
790
+ | /learn | Continue working — lesson applies on next command |
791
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
792
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
736
793
 
737
794
  Format the footer as:
738
795
  ```
@@ -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
 
@@ -384,6 +436,7 @@ Write `{paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md` using the structure below
384
436
  | **Domain** | {domain} |
385
437
  | **Created** | {YYYY-MM-DD} |
386
438
  | **Updated** | {YYYY-MM-DD} |
439
+ | **API Source** | *(bỏ trống nếu greenfield — thêm `existing` nếu API đã tồn tại trên hệ thống)* |
387
440
 
388
441
  ---
389
442
 
@@ -397,13 +450,14 @@ Write `{paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md` using the structure below
397
450
 
398
451
  ## a. User Story
399
452
 
400
- As a {User role}
401
- I want to {User goal}
402
- So that {Business value}
453
+ - **As a** {User role}
454
+ - **I want to** {User goal}
455
+ - **So that** {Business value}
403
456
 
404
457
  ## b. Scope
405
458
 
406
- In Scope
459
+ **In Scope**
460
+
407
461
  - {Function 1}
408
462
  - {Function 2}
409
463
 
@@ -411,24 +465,36 @@ In Scope
411
465
 
412
466
  # 2. Acceptance Criteria
413
467
 
414
- AC1: {Acceptance criterion — testable, observable, no UI details}
415
- AC2: {Acceptance criterion}
468
+ - **AC1:** {Acceptance criterion — testable, observable, no UI details}
469
+ - **AC2:** {Acceptance criterion}
416
470
 
417
471
  ---
418
472
 
419
473
  # 3. Use Case
420
474
 
421
475
  #### {TICKET-ID}-UC1: {Use Case Name}
422
- Actor: {User performing the action}
423
- Description: {Business scenario description — 1 sentence}
424
- Pre-condition: {Condition that must be true BEFORE use case begins}
425
- Post-condition: {State / result AFTER use case completes}
426
476
 
427
- Business Rule
428
- | ID | Business Rule | Business Logic |
429
- |-------------------------|--------------------------------------|-------------------------------------------|
430
- | {TICKET-ID}-UC1-BR1 | {Rule WHAT the system must do} | - Logic 1<br/>- Logic 2<br/>- Logic 3 |
431
- | {TICKET-ID}-UC1-BR2 | {Rule} | - Logic |
477
+ - **Actor:** {User performing the action}
478
+ - **Description:** {Business scenario description — 1 sentence}
479
+ - **Pre-condition:** {Condition that must be true BEFORE use case begins}
480
+ - **Post-condition:** {State / result AFTER use case completes}
481
+
482
+ **Business Rule**
483
+
484
+ | ID | Business Rule |
485
+ |----|---------------|
486
+ | {TICKET-ID}-UC1-BR1 | {Rule — WHAT the system must do} |
487
+ | {TICKET-ID}-UC1-BR2 | {Rule} |
488
+
489
+ **Business Logic**
490
+
491
+ **{TICKET-ID}-UC1-BR1:**
492
+ - Logic 1
493
+ - Logic 2
494
+ - Logic 3
495
+
496
+ **{TICKET-ID}-UC1-BR2:**
497
+ - Logic
432
498
 
433
499
  ---
434
500
 
@@ -450,11 +516,16 @@ flowchart TD
450
516
 
451
517
  **Screen 1: {Screen Name}**
452
518
 
453
- | Component | Details |
454
- |----------------|-----------------------------------------------------------------|
455
- | **Screen** | {Screen name} |
456
- | **Components** | - {Component 1}<br/>- {Component 2}<br/>- {Component 3} |
457
- | **Actions** | - {Action 1} → {Result}<br/>- {Action 2} → {Result} |
519
+ **Screen:** {Screen name}
520
+
521
+ **Components:**
522
+ - {Component 1}
523
+ - {Component 2}
524
+ - {Component 3}
525
+
526
+ **Actions:**
527
+ - {Action 1} → {Result}
528
+ - {Action 2} → {Result}
458
529
 
459
530
  ---
460
531
 
@@ -468,6 +539,23 @@ flowchart TD
468
539
 
469
540
  - {[TICKET-ID](./TICKET-ID-slug.md) — relationship description}
470
541
 
542
+ ## Existing API Contract *(chỉ điền khi API Source = existing)*
543
+
544
+ > API đã tồn tại trên hệ thống. PO ghi lại contract để BDD generation dùng trực tiếp —
545
+ > không cần tổng hợp từ FE/App BDD, không cần T7 sign-off gate.
546
+
547
+ | Method | Path | Auth | Request | Response |
548
+ |--------|------|------|---------|----------|
549
+ | {GET/POST/PUT/DELETE} | {/api/v1/path} | {Bearer / none} | `{ field: type }` | `{ field: type }` |
550
+
551
+ **Error responses:**
552
+
553
+ | HTTP Status | Error Code | Khi nào xảy ra |
554
+ |-------------|------------|----------------|
555
+ | {4xx/5xx} | {ERR_CODE} | {condition} |
556
+
557
+ ---
558
+
471
559
  ## AI Assumptions
472
560
 
473
561
  > Assumptions AI made when information was incomplete. Needs PO review and confirmation.
@@ -487,6 +575,7 @@ flowchart TD
487
575
  - [ ] No banned terms (if dictionary exists)
488
576
  - [ ] User Flow includes error path / exception path
489
577
  - [ ] Wireframe covers all screens related to Use Cases
578
+ - [ ] **Định dạng (readability)**: User Story / AC / các field của UC (Actor, Description, Pre/Post-condition) viết dạng bullet `- **Label:** …` — mỗi ý MỘT dòng, KHÔNG viết các dòng liền nhau (sẽ bị dồn thành 1 đoạn khi render); có một dòng trống trước và sau mỗi bảng
490
579
 
491
580
  ## Changelog Section (append at end of PRD)
492
581
 
@@ -551,6 +640,11 @@ Suggest the logical next command based on workflow phase:
551
640
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
552
641
  | /fix-bug | Create PR and link to ticket |
553
642
  | /debug | `/fix-bug {ticket-id}` if fix needed |
643
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
644
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
645
+ | /learn | Continue working — lesson applies on next command |
646
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
647
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
554
648
 
555
649
  Format the footer as:
556
650
  ```