@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
@@ -84,6 +84,7 @@ Write `{paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md` using the structure below
84
84
  | **Domain** | {domain} |
85
85
  | **Created** | {YYYY-MM-DD} |
86
86
  | **Updated** | {YYYY-MM-DD} |
87
+ | **API Source** | *(bỏ trống nếu greenfield — thêm `existing` nếu API đã tồn tại trên hệ thống)* |
87
88
 
88
89
  ---
89
90
 
@@ -97,13 +98,14 @@ Write `{paths.prd_dir}/{domain}/{TICKET-ID}-{slug}.md` using the structure below
97
98
 
98
99
  ## a. User Story
99
100
 
100
- As a {User role}
101
- I want to {User goal}
102
- So that {Business value}
101
+ - **As a** {User role}
102
+ - **I want to** {User goal}
103
+ - **So that** {Business value}
103
104
 
104
105
  ## b. Scope
105
106
 
106
- In Scope
107
+ **In Scope**
108
+
107
109
  - {Function 1}
108
110
  - {Function 2}
109
111
 
@@ -111,24 +113,36 @@ In Scope
111
113
 
112
114
  # 2. Acceptance Criteria
113
115
 
114
- AC1: {Acceptance criterion — testable, observable, no UI details}
115
- AC2: {Acceptance criterion}
116
+ - **AC1:** {Acceptance criterion — testable, observable, no UI details}
117
+ - **AC2:** {Acceptance criterion}
116
118
 
117
119
  ---
118
120
 
119
121
  # 3. Use Case
120
122
 
121
123
  #### {TICKET-ID}-UC1: {Use Case Name}
122
- Actor: {User performing the action}
123
- Description: {Business scenario description — 1 sentence}
124
- Pre-condition: {Condition that must be true BEFORE use case begins}
125
- Post-condition: {State / result AFTER use case completes}
126
124
 
127
- Business Rule
128
- | ID | Business Rule | Business Logic |
129
- |-------------------------|--------------------------------------|-------------------------------------------|
130
- | {TICKET-ID}-UC1-BR1 | {Rule WHAT the system must do} | - Logic 1<br/>- Logic 2<br/>- Logic 3 |
131
- | {TICKET-ID}-UC1-BR2 | {Rule} | - Logic |
125
+ - **Actor:** {User performing the action}
126
+ - **Description:** {Business scenario description — 1 sentence}
127
+ - **Pre-condition:** {Condition that must be true BEFORE use case begins}
128
+ - **Post-condition:** {State / result AFTER use case completes}
129
+
130
+ **Business Rule**
131
+
132
+ | ID | Business Rule |
133
+ |----|---------------|
134
+ | {TICKET-ID}-UC1-BR1 | {Rule — WHAT the system must do} |
135
+ | {TICKET-ID}-UC1-BR2 | {Rule} |
136
+
137
+ **Business Logic**
138
+
139
+ **{TICKET-ID}-UC1-BR1:**
140
+ - Logic 1
141
+ - Logic 2
142
+ - Logic 3
143
+
144
+ **{TICKET-ID}-UC1-BR2:**
145
+ - Logic
132
146
 
133
147
  ---
134
148
 
@@ -150,11 +164,16 @@ flowchart TD
150
164
 
151
165
  **Screen 1: {Screen Name}**
152
166
 
153
- | Component | Details |
154
- |----------------|-----------------------------------------------------------------|
155
- | **Screen** | {Screen name} |
156
- | **Components** | - {Component 1}<br/>- {Component 2}<br/>- {Component 3} |
157
- | **Actions** | - {Action 1} → {Result}<br/>- {Action 2} → {Result} |
167
+ **Screen:** {Screen name}
168
+
169
+ **Components:**
170
+ - {Component 1}
171
+ - {Component 2}
172
+ - {Component 3}
173
+
174
+ **Actions:**
175
+ - {Action 1} → {Result}
176
+ - {Action 2} → {Result}
158
177
 
159
178
  ---
160
179
 
@@ -168,6 +187,23 @@ flowchart TD
168
187
 
169
188
  - {[TICKET-ID](./TICKET-ID-slug.md) — relationship description}
170
189
 
190
+ ## Existing API Contract *(chỉ điền khi API Source = existing)*
191
+
192
+ > API đã tồn tại trên hệ thống. PO ghi lại contract để BDD generation dùng trực tiếp —
193
+ > không cần tổng hợp từ FE/App BDD, không cần T7 sign-off gate.
194
+
195
+ | Method | Path | Auth | Request | Response |
196
+ |--------|------|------|---------|----------|
197
+ | {GET/POST/PUT/DELETE} | {/api/v1/path} | {Bearer / none} | `{ field: type }` | `{ field: type }` |
198
+
199
+ **Error responses:**
200
+
201
+ | HTTP Status | Error Code | Khi nào xảy ra |
202
+ |-------------|------------|----------------|
203
+ | {4xx/5xx} | {ERR_CODE} | {condition} |
204
+
205
+ ---
206
+
171
207
  ## AI Assumptions
172
208
 
173
209
  > Assumptions AI made when information was incomplete. Needs PO review and confirmation.
@@ -187,6 +223,7 @@ flowchart TD
187
223
  - [ ] No banned terms (if dictionary exists)
188
224
  - [ ] User Flow includes error path / exception path
189
225
  - [ ] Wireframe covers all screens related to Use Cases
226
+ - [ ] **Đị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
190
227
 
191
228
  ## Changelog Section (append at end of PRD)
192
229
 
@@ -183,6 +183,37 @@ If `services` section is present:
183
183
  - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
184
184
  - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
185
185
  - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
186
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
187
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
188
+
189
+ > **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.
190
+
191
+ ---
192
+
193
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
194
+
195
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
196
+
197
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
198
+
199
+ **1. Locate service config** — try in priority order:
200
+ - `{active_service}/.agent/project-context.yaml`
201
+ - `{active_service}/project-context.yaml`
202
+
203
+ **2. If found, override with service-specific values:**
204
+
205
+ | Variable | Source |
206
+ |----------|--------|
207
+ | `conventions.test_command` | service's `conventions.test_command` |
208
+ | `conventions.build_command` | service's `conventions.build_command` |
209
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
210
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
211
+
212
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
213
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
214
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
215
+
216
+ **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).
186
217
 
187
218
  ---
188
219
 
@@ -276,6 +307,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
276
307
 
277
308
  ---
278
309
 
310
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
311
+
312
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
313
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
314
+
315
+ Resolve the lessons file path:
316
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
317
+ - Else default `specs/domain-knowledge/lessons-learned.md`
318
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
319
+
320
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
321
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
322
+ - 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).
323
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
324
+
325
+ If the file does not exist → skip silently (no lessons captured yet).
326
+
327
+ ---
328
+
279
329
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
280
330
 
281
331
  After loading all context, synthesize and output a compact summary block.
@@ -291,7 +341,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
291
341
  Ticket : {ticket_prefix}-
292
342
  Dict : {loaded — N canonical terms, M banned terms | missing}
293
343
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
344
+ Lessons : {loaded — N guardrails | none yet}
294
345
  Service : {active_service} ({active_service_module}) | single-service
346
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
295
347
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
296
348
  ```
297
349
 
@@ -485,6 +537,11 @@ Suggest the logical next command based on workflow phase:
485
537
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
486
538
  | /fix-bug | Create PR and link to ticket |
487
539
  | /debug | `/fix-bug {ticket-id}` if fix needed |
540
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
541
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
542
+ | /learn | Continue working — lesson applies on next command |
543
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
544
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
488
545
 
489
546
  Format the footer as:
490
547
  ```
@@ -199,6 +199,37 @@ If `services` section is present:
199
199
  - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
200
200
  - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
201
201
  - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
202
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
203
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
204
+
205
+ > **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.
206
+
207
+ ---
208
+
209
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
210
+
211
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
212
+
213
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
214
+
215
+ **1. Locate service config** — try in priority order:
216
+ - `{active_service}/.agent/project-context.yaml`
217
+ - `{active_service}/project-context.yaml`
218
+
219
+ **2. If found, override with service-specific values:**
220
+
221
+ | Variable | Source |
222
+ |----------|--------|
223
+ | `conventions.test_command` | service's `conventions.test_command` |
224
+ | `conventions.build_command` | service's `conventions.build_command` |
225
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
226
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
227
+
228
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
229
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
230
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
231
+
232
+ **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).
202
233
 
203
234
  ---
204
235
 
@@ -292,6 +323,25 @@ These two variables (`active_module`, `platform_type`) are the canonical source
292
323
 
293
324
  ---
294
325
 
326
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
327
+
328
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
329
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
330
+
331
+ Resolve the lessons file path:
332
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
333
+ - Else default `specs/domain-knowledge/lessons-learned.md`
334
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
335
+
336
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
337
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
338
+ - 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).
339
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
340
+
341
+ If the file does not exist → skip silently (no lessons captured yet).
342
+
343
+ ---
344
+
295
345
  ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
296
346
 
297
347
  After loading all context, synthesize and output a compact summary block.
@@ -307,7 +357,9 @@ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Ser
307
357
  Ticket : {ticket_prefix}-
308
358
  Dict : {loaded — N canonical terms, M banned terms | missing}
309
359
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
360
+ Lessons : {loaded — N guardrails | none yet}
310
361
  Service : {active_service} ({active_service_module}) | single-service
362
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
311
363
  Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
312
364
  ```
313
365
 
@@ -329,6 +381,22 @@ After completing all steps, you have loaded:
329
381
  Proceed to the next step of the calling command.
330
382
 
331
383
 
384
+ ---
385
+
386
+ ## Brownfield Check
387
+
388
+ Read the source `.feature` file header for `@trace.api_source`.
389
+ Also check the source PRD Metadata table for `| **API Source** | existing |`.
390
+
391
+ | Value | Mode |
392
+ |-------|------|
393
+ | `existing` | **Reverse-document** — API đã tồn tại; mô tả lại as-is, note gaps, không cần design mới |
394
+ | absent / other | **Greenfield** — thiết kế API từ đầu |
395
+
396
+ Store `active_mode = {reverse-document | greenfield}`.
397
+
398
+ If `active_mode = reverse-document` → load bảng "Existing API Contract" từ PRD làm input cho §2.
399
+
332
400
  ---
333
401
 
334
402
  ## CHECKPOINT — Tech Design Plan
@@ -341,13 +409,14 @@ Tech Design Plan — {UC-ID}
341
409
  UC : {UC-ID} — {feature title}
342
410
  Service : {trace.service}
343
411
  Module : {trace.module}
412
+ Mode : {Reverse-document (API đã tồn tại) | Greenfield (thiết kế mới)}
344
413
  Scenarios: {N} scenarios
345
414
  BDD ver : {trace.bdd_version}
346
415
  Output : {paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md
347
416
 
348
417
  Sections to generate:
349
418
  §1 Overview
350
- §2 API Endpoints ({N} endpoints inferred from scenarios)
419
+ §2 API Endpoints ({Reverse-document: tả lại từ PRD contract | Greenfield: infer từ scenarios})
351
420
  §3 Data Model ({entities from core-entities.md relevant to this UC})
352
421
  §4 Service Flow
353
422
  §5 Business Rules ({N} BRs from feature header)
@@ -379,11 +448,15 @@ Write `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`:
379
448
  @trace.bdd_version: {read @trace.bdd_version from the .feature file header}
380
449
  @trace.revision: 1
381
450
  @trace.status: draft
451
+ @trace.api_source: {existing | —}
382
452
  @trace.generated_at: {YYYY-MM-DD}
383
453
  ---
384
454
 
385
455
  ## §1. Overview
386
456
  ## §2. API Endpoints
457
+ *Greenfield:* endpoints được infer từ BDD scenarios — thiết kế mới.
458
+ *Reverse-document:* mô tả lại API đã tồn tại từ bảng "Existing API Contract" trong PRD.
459
+ Ghi chú gaps nếu contract thực tế khác với BDD expectations.
387
460
  | Method | Path | Auth/Role | Request | Response |
388
461
  ## §3. Data Model
389
462
  Key entities and relationships.
@@ -456,6 +529,11 @@ Suggest the logical next command based on workflow phase:
456
529
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
457
530
  | /fix-bug | Create PR and link to ticket |
458
531
  | /debug | `/fix-bug {ticket-id}` if fix needed |
532
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
533
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
534
+ | /learn | Continue working — lesson applies on next command |
535
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
536
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
459
537
 
460
538
  Format the footer as:
461
539
  ```
@@ -31,6 +31,22 @@
31
31
 
32
32
  ---
33
33
 
34
+ ## Brownfield Check
35
+
36
+ Read the source `.feature` file header for `@trace.api_source`.
37
+ Also check the source PRD Metadata table for `| **API Source** | existing |`.
38
+
39
+ | Value | Mode |
40
+ |-------|------|
41
+ | `existing` | **Reverse-document** — API đã tồn tại; mô tả lại as-is, note gaps, không cần design mới |
42
+ | absent / other | **Greenfield** — thiết kế API từ đầu |
43
+
44
+ Store `active_mode = {reverse-document | greenfield}`.
45
+
46
+ If `active_mode = reverse-document` → load bảng "Existing API Contract" từ PRD làm input cho §2.
47
+
48
+ ---
49
+
34
50
  ## CHECKPOINT — Tech Design Plan
35
51
 
36
52
  Before generating, scan the feature file for scenario count, referenced BRs, and entities. Display and wait for Y:
@@ -41,13 +57,14 @@ Tech Design Plan — {UC-ID}
41
57
  UC : {UC-ID} — {feature title}
42
58
  Service : {trace.service}
43
59
  Module : {trace.module}
60
+ Mode : {Reverse-document (API đã tồn tại) | Greenfield (thiết kế mới)}
44
61
  Scenarios: {N} scenarios
45
62
  BDD ver : {trace.bdd_version}
46
63
  Output : {paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md
47
64
 
48
65
  Sections to generate:
49
66
  §1 Overview
50
- §2 API Endpoints ({N} endpoints inferred from scenarios)
67
+ §2 API Endpoints ({Reverse-document: tả lại từ PRD contract | Greenfield: infer từ scenarios})
51
68
  §3 Data Model ({entities from core-entities.md relevant to this UC})
52
69
  §4 Service Flow
53
70
  §5 Business Rules ({N} BRs from feature header)
@@ -79,11 +96,15 @@ Write `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`:
79
96
  @trace.bdd_version: {read @trace.bdd_version from the .feature file header}
80
97
  @trace.revision: 1
81
98
  @trace.status: draft
99
+ @trace.api_source: {existing | —}
82
100
  @trace.generated_at: {YYYY-MM-DD}
83
101
  ---
84
102
 
85
103
  ## §1. Overview
86
104
  ## §2. API Endpoints
105
+ *Greenfield:* endpoints được infer từ BDD scenarios — thiết kế mới.
106
+ *Reverse-document:* mô tả lại API đã tồn tại từ bảng "Existing API Contract" trong PRD.
107
+ Ghi chú gaps nếu contract thực tế khác với BDD expectations.
87
108
  | Method | Path | Auth/Role | Request | Response |
88
109
  ## §3. Data Model
89
110
  Key entities and relationships.
@@ -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
 
@@ -812,6 +864,11 @@ Suggest the logical next command based on workflow phase:
812
864
  | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
813
865
  | /fix-bug | Create PR and link to ticket |
814
866
  | /debug | `/fix-bug {ticket-id}` if fix needed |
867
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
868
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
869
+ | /learn | Continue working — lesson applies on next command |
870
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
871
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
815
872
 
816
873
  Format the footer as:
817
874
  ```