@educa-corp/sdd-framework 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/bin/build.js +9 -0
  2. package/bin/index.js +115 -4
  3. package/bin/self-check.js +354 -0
  4. package/bin/trace-schema.json +1199 -0
  5. package/commands/debug.md +19 -12
  6. package/commands/define-product.md +19 -12
  7. package/commands/dev-gen-test.md +53 -19
  8. package/commands/dev-run-test.md +55 -20
  9. package/commands/dev-run-test.tmpl +2 -1
  10. package/commands/dev-smoke-test.md +19 -12
  11. package/commands/extend-prd.md +907 -0
  12. package/commands/extend-prd.tmpl +270 -0
  13. package/commands/fix-bug.md +101 -15
  14. package/commands/fix-bug.tmpl +29 -3
  15. package/commands/generate-architecture.md +19 -12
  16. package/commands/generate-bdd.md +174 -48
  17. package/commands/generate-bdd.tmpl +107 -18
  18. package/commands/generate-code.md +122 -29
  19. package/commands/generate-code.tmpl +69 -10
  20. package/commands/generate-design-spec.md +19 -12
  21. package/commands/generate-prd.md +44 -12
  22. package/commands/generate-prd.tmpl +25 -0
  23. package/commands/generate-spec-manifest.md +19 -12
  24. package/commands/generate-tech-docs.md +22 -15
  25. package/commands/generate-tech-docs.tmpl +2 -2
  26. package/commands/learn.md +19 -12
  27. package/commands/map-testids.md +19 -12
  28. package/commands/propose-scenario.md +91 -15
  29. package/commands/propose-scenario.tmpl +72 -3
  30. package/commands/qc-analyze.md +19 -12
  31. package/commands/qc-design-test.md +20 -12
  32. package/commands/qc-design-test.tmpl +1 -0
  33. package/commands/qc-plan.md +19 -12
  34. package/commands/qc-report.md +19 -12
  35. package/commands/qc-review.md +19 -12
  36. package/commands/qc-run-test.md +88 -22
  37. package/commands/qc-run-test.tmpl +35 -3
  38. package/commands/refine-prd.md +19 -12
  39. package/commands/report-bug.md +19 -12
  40. package/commands/review-code.md +60 -14
  41. package/commands/review-code.tmpl +41 -2
  42. package/commands/review-context.md +62 -16
  43. package/commands/review-context.tmpl +43 -4
  44. package/commands/review-tech-docs.md +50 -14
  45. package/commands/review-tech-docs.tmpl +31 -2
  46. package/commands/setup-ai-first.md +26 -16
  47. package/commands/setup-ai-first.tmpl +7 -4
  48. package/commands/sync.md +43 -18
  49. package/commands/sync.tmpl +37 -14
  50. package/commands/update-framework.md +43 -4
  51. package/commands/update-framework.tmpl +37 -0
  52. package/commands/validate-traces.md +481 -49
  53. package/commands/validate-traces.tmpl +462 -37
  54. package/core/FRAMEWORK_VERSION +1 -1
  55. package/core/README.md +56 -0
  56. package/core/commands/debug.md +19 -12
  57. package/core/commands/define-product.md +19 -12
  58. package/core/commands/dev-gen-test.md +53 -19
  59. package/core/commands/dev-run-test.md +55 -20
  60. package/core/commands/dev-smoke-test.md +19 -12
  61. package/core/commands/extend-prd.md +907 -0
  62. package/core/commands/fix-bug.md +101 -15
  63. package/core/commands/generate-architecture.md +19 -12
  64. package/core/commands/generate-bdd.md +174 -48
  65. package/core/commands/generate-code.md +122 -29
  66. package/core/commands/generate-design-spec.md +19 -12
  67. package/core/commands/generate-prd.md +44 -12
  68. package/core/commands/generate-spec-manifest.md +19 -12
  69. package/core/commands/generate-tech-docs.md +22 -15
  70. package/core/commands/learn.md +19 -12
  71. package/core/commands/map-testids.md +19 -12
  72. package/core/commands/propose-scenario.md +91 -15
  73. package/core/commands/qc-analyze.md +19 -12
  74. package/core/commands/qc-design-test.md +20 -12
  75. package/core/commands/qc-plan.md +19 -12
  76. package/core/commands/qc-report.md +19 -12
  77. package/core/commands/qc-review.md +19 -12
  78. package/core/commands/qc-run-test.md +88 -22
  79. package/core/commands/refine-prd.md +19 -12
  80. package/core/commands/report-bug.md +19 -12
  81. package/core/commands/review-code.md +60 -14
  82. package/core/commands/review-context.md +62 -16
  83. package/core/commands/review-tech-docs.md +50 -14
  84. package/core/commands/setup-ai-first.md +26 -16
  85. package/core/commands/sync.md +43 -18
  86. package/core/commands/update-framework.md +43 -4
  87. package/core/commands/validate-traces.md +481 -49
  88. package/core/modules/android-compose/stack-profile.yaml +1 -1
  89. package/core/modules/flutter/stack-profile.yaml +1 -1
  90. package/core/modules/ios-swiftui/stack-profile.yaml +1 -1
  91. package/core/modules/java-spring/stack-profile.yaml +1 -1
  92. package/core/modules/nextjs/stack-profile.yaml +1 -1
  93. package/core/modules/nuxt/stack-profile.yaml +1 -1
  94. package/core/modules/phaser-game/stack-profile.yaml +1 -1
  95. package/core/modules/php-laravel/stack-profile.yaml +1 -1
  96. package/core/modules/qc-playwright/stack-profile.yaml +1 -1
  97. package/core/modules/react/stack-profile.yaml +1 -1
  98. package/core/modules/react-native/stack-profile.yaml +1 -1
  99. package/core/modules/vue/stack-profile.yaml +1 -1
  100. package/core/rules/workflow.md +29 -0
  101. package/core/steps/gate.md +13 -8
  102. package/core/steps/report-footer.md +6 -4
  103. package/core/steps/trace-mirror.md +34 -7
  104. package/core/templates/README.md +47 -0
  105. package/core/templates/feature.template +14 -11
  106. package/core/templates/project-context.yaml +26 -14
  107. package/core/templates/tech-design.template.md +1 -1
  108. package/docs/01-getting-started/installation.md +18 -1
  109. package/docs/01-getting-started/what-is-sdd.md +4 -2
  110. package/docs/02-concepts/architecture.md +27 -3
  111. package/docs/02-concepts/pipeline-steps/02-specification.md +39 -3
  112. package/docs/02-concepts/pipeline-steps/04-bdd.md +24 -2
  113. package/docs/02-concepts/pipeline-steps/05-tech-docs.md +18 -1
  114. package/docs/02-concepts/pipeline-steps/06-code.md +35 -4
  115. package/docs/02-concepts/pipeline-steps/09-validate-traces.md +137 -12
  116. package/docs/02-concepts/pipeline-steps/10-feedback-loop.md +59 -3
  117. package/docs/02-concepts/roles-and-hitl.md +1 -1
  118. package/docs/02-concepts/traceability.md +126 -94
  119. package/docs/03-guides/developer.md +20 -4
  120. package/docs/03-guides/product-owner.md +72 -68
  121. package/docs/03-guides/tester-qa.md +81 -70
  122. package/docs/04-reference/commands.md +134 -105
  123. package/docs/04-reference/configuration.md +146 -94
  124. package/docs/04-reference/trace-schema.md +145 -37
  125. package/docs/explain/02-generate-prd.md +80 -78
  126. package/docs/explain/02b-extend-prd.md +125 -0
  127. package/docs/explain/03-refine-prd.md +86 -86
  128. package/docs/explain/04-review-context.md +18 -1
  129. package/docs/explain/06-generate-bdd.md +23 -0
  130. package/docs/explain/08-review-tech-docs.md +20 -5
  131. package/docs/explain/10-review-code.md +36 -2
  132. package/docs/explain/19-qc-run-test.md +87 -67
  133. package/docs/explain/21-validate-traces.md +74 -68
  134. package/docs/explain/23-fix-bug.md +19 -3
  135. package/docs/explain/26-propose-scenario.md +70 -63
  136. package/docs/explain/README.md +135 -134
  137. package/modules/android-compose/stack-profile.yaml +1 -1
  138. package/modules/flutter/stack-profile.yaml +1 -1
  139. package/modules/ios-swiftui/stack-profile.yaml +1 -1
  140. package/modules/java-spring/stack-profile.yaml +1 -1
  141. package/modules/nextjs/stack-profile.yaml +1 -1
  142. package/modules/nuxt/stack-profile.yaml +1 -1
  143. package/modules/phaser-game/stack-profile.yaml +1 -1
  144. package/modules/php-laravel/stack-profile.yaml +1 -1
  145. package/modules/qc-playwright/stack-profile.yaml +1 -1
  146. package/modules/react/stack-profile.yaml +1 -1
  147. package/modules/react-native/stack-profile.yaml +1 -1
  148. package/modules/vue/stack-profile.yaml +1 -1
  149. package/package.json +5 -4
  150. package/rules/workflow.md +29 -0
  151. package/scripts/migrate-bdd-platform.js +286 -0
  152. package/steps/gate.md +13 -8
  153. package/steps/report-footer.md +6 -4
  154. package/steps/trace-mirror.md +34 -7
  155. package/templates/README.md +47 -0
  156. package/templates/feature.template +14 -11
  157. package/templates/project-context.yaml +26 -14
  158. package/templates/tech-design.template.md +1 -1
@@ -54,4 +54,4 @@ testing:
54
54
 
55
55
  trace_tags:
56
56
  implements: "// @trace.implements={UC-ID}-SC{N}"
57
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
57
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
@@ -56,4 +56,4 @@ testing:
56
56
 
57
57
  trace_tags:
58
58
  implements: "// @trace.implements={UC-ID}-SC{N}"
59
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
59
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
@@ -52,4 +52,4 @@ testing:
52
52
 
53
53
  trace_tags:
54
54
  implements: "// @trace.implements={UC-ID}-SC{N}"
55
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
55
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
@@ -23,6 +23,6 @@ coding_standards:
23
23
 
24
24
  trace_tags:
25
25
  implements: "@trace.implements={UC-ID}-SC{N}"
26
- source: "@trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
26
+ source: "@trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
27
27
  verifies: "@trace.verifies={UC-ID}"
28
28
  test_type: "@trace.test_type=unit|integration"
@@ -69,6 +69,6 @@ testing:
69
69
 
70
70
  trace_tags:
71
71
  implements: "// @trace.implements={UC-ID}-SC{N}"
72
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
72
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
73
73
  verifies: "// @trace.verifies={UC-ID}"
74
74
  test_type: "// @trace.test_type=unit|e2e"
@@ -53,6 +53,6 @@ testing:
53
53
 
54
54
  trace_tags:
55
55
  implements: "// @trace.implements={UC-ID}-SC{N}"
56
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
56
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
57
57
  verifies: "// @trace.verifies={UC-ID}"
58
58
  test_type: "// @trace.test_type=unit|integration"
@@ -85,6 +85,6 @@ testing:
85
85
 
86
86
  trace_tags:
87
87
  implements: "// @trace.implements={UC-ID}-SC{N}"
88
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
88
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
89
89
  verifies: "// @trace.verifies={UC-ID}"
90
90
  test_type: "// @trace.test_type=unit|integration"
@@ -51,6 +51,6 @@ testing:
51
51
 
52
52
  trace_tags:
53
53
  implements: "// @trace.implements={UC-ID}-SC{N}"
54
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
54
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
55
55
  verifies: "// @trace.verifies={UC-ID}"
56
56
  test_type: "// @trace.test_type=unit|feature"
@@ -59,7 +59,7 @@ testing:
59
59
  trace_tags:
60
60
  # QC tests map back to the framework's scenarios — drives qc_status in the trace TSV.
61
61
  verifies: "# @trace.verifies={UC-ID}-SC{N}"
62
- source: "# @trace.source=<official .feature path>"
62
+ source: "# @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
63
63
  test_type: "# @trace.test_type=functional|integration|e2e|non-functional"
64
64
 
65
65
  # qc_status: /qc-run-test writes pass|fail|skip|not_run + qc_run_at into {trace_dir}/{UC-ID}.tsv
@@ -58,6 +58,6 @@ testing:
58
58
 
59
59
  trace_tags:
60
60
  implements: "// @trace.implements={UC-ID}-SC{N}"
61
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
61
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
62
62
  verifies: "// @trace.verifies={UC-ID}"
63
63
  test_type: "// @trace.test_type=unit|integration"
@@ -53,4 +53,4 @@ testing:
53
53
 
54
54
  trace_tags:
55
55
  implements: "// @trace.implements={UC-ID}-SC{N}"
56
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
56
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
@@ -60,6 +60,6 @@ testing:
60
60
 
61
61
  trace_tags:
62
62
  implements: "// @trace.implements={UC-ID}-SC{N}"
63
- source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{UC-ID}.feature"
63
+ source: "// @trace.source=specs/{domain}/{prd-slug}/bdd/{platform}/{UC-ID}-{slug}.feature"
64
64
  verifies: "// @trace.verifies={UC-ID}"
65
65
  test_type: "// @trace.test_type=unit|integration"
@@ -18,6 +18,35 @@
18
18
  - Do NOT create files outside the directories specified in `project-context.yaml → paths`.
19
19
  - If new scope is discovered mid-command, STOP and ask: "I found additional scope [{description}]. Should I include it? (Y/N)"
20
20
 
21
+ ## Trace Contract
22
+
23
+ - Contract trace (field `@trace.*`, cột `.tsv`, path pattern, giá trị enum) có **một
24
+ nguồn-sự-thật máy đọc**: `bin/trace-schema.json`. Bản cho người đọc:
25
+ `docs/04-reference/trace-schema.md` — giữ hai file đồng bộ.
26
+ - Đổi contract (thêm/bỏ/đổi nghĩa một field, path, hay giá trị enum) → **sửa
27
+ `bin/trace-schema.json` TRƯỚC**, rồi mới sửa lệnh. `npm run build` chạy
28
+ `bin/self-check.js` và **fail** nếu lệnh lệch schema.
29
+ - Field có consumer mà **không có producer** là lỗi chặn build — đó chính là hình dạng
30
+ của G1 (`@trace.sc_version`: 3 consumer, 0 producer, DRIFT chết mà không ai báo).
31
+ - **Làm mất hiệu lực ≠ ghi đè.** Cột trace có chủ sở hữu rõ ràng — `dev_selftest`/`dev_selftest_at`
32
+ thuộc `/dev-run-test` · `qc_status`/`qc_run_at` thuộc `/qc-run-test` · `test_count`/`test_classes`
33
+ thuộc `/dev-gen-test` — và **chỉ chủ được ghi giá trị KHẲNG ĐỊNH** (`pass`/`fail`/số lượng).
34
+ Nhưng lệnh nào làm giá trị đó **HẾT ĐÚNG** (spec đổi, code đổi) thì **BẮT BUỘC** hạ nó về giá
35
+ trị "chưa biết" (`not_run` / `—`). Giữ một `pass` đã hết hiệu lực là **báo cáo sai**, không phải
36
+ tôn trọng quyền sở hữu.
37
+ *Tiền lệ đúng có sẵn: `/fix-bug` hạ `dev_selftest → not_run` với lý do "code vừa đổi nên tín
38
+ hiệu self-test cũ hết hiệu lực". Cùng lý do đó áp cho MỌI lệnh làm đổi spec hoặc code.*
39
+ **Ngoại lệ có chủ ý:** `qc_owner`/`qc_blocked_by` (con trỏ tới bug — spec đổi không làm bug biến
40
+ mất) và `test_count`/`test_classes` (test vẫn tồn tại trên đĩa; số lượng không sai, chỉ nội dung
41
+ cũ → **cảnh báo**, không hạ số, để tỷ lệ coverage không nhảy loạn).
42
+ - **Mỗi audit flag phải quan sát được ở CẢ BA tầng.** Mọi giá trị trong
43
+ `vocabularies.audit_flags` bắt buộc có đủ: **(1)** một counter `{flag_lowercase}_count`
44
+ trong Step 7 + `summary` của `trace-report.json` · **(2)** một mảng trong `issues` ·
45
+ **(3)** một khối trong report terminal. Thiếu tầng nào = cờ vô hình ở tầng đó.
46
+ `bin/self-check.js` R7 ép tầng (1) — **không có ngoại lệ**. Đây là hình dạng của G33:
47
+ 7/10 cờ có counter, 3 cái không, nên dashboard (chỉ đọc `summary`) không tổng hợp
48
+ được — và bất đối xứng 7/10 là bẫy cho người viết dashboard: đọc `summary` rồi tưởng đủ.
49
+
21
50
  ## Code Generation
22
51
 
23
52
  - Never generate code for files not backed by a `.feature` spec (unless `/fix-bug` or `/debug`).
@@ -29,23 +29,23 @@ Hiển thị và chờ phản hồi:
29
29
  ```
30
30
  ⚙️ MODEL CHECK
31
31
  ──────────────────────────────────────────────────────────────────
32
- Recommended : claude-opus-4 (hoặc model Opus mới nhất)
32
+ Recommended : model Opus mới nhất
33
33
  Why needed : Phân tích spec, review kiến trúc, sinh code đòi hỏi
34
- suy luận sâu. Model nhỏ hơn dễ bỏ sót edge case.
34
+ suy luận sâu. Model nhỏ hơn (Haiku/Sonnet) dễ bỏ sót edge case.
35
35
 
36
36
  Cách đổi trong Claude Code:
37
- SettingsModel chọn "claude-opus"
38
- • hoặc: /modelchọn claude-opus
37
+ /modelchọn model Opus
38
+ • hoặc: SettingsModel
39
39
 
40
- Đang chạy claude-opus?
41
- Y — đúng, đang dùng claude-opus → tiếp tục
40
+ Đang chạy một model Opus?
41
+ Y — đúng → tiếp tục
42
42
  S — bỏ qua kiểm tra (tôi chấp nhận rủi ro chất lượng thấp hơn với model hiện tại)
43
43
  ──────────────────────────────────────────────────────────────────
44
44
  ```
45
45
 
46
46
  - "Y" → tiếp tục sang Bước 1.
47
47
  - "S" → tiếp tục sang Bước 1 (người dùng chấp nhận rủi ro, thêm ⚠️ vào report cuối).
48
- - "N" hoặc bất kỳ giá trị nào khác → **DỪNG.** Xuất: "Vui lòng chuyển sang claude-opus rồi chạy lại lệnh này."
48
+ - "N" hoặc bất kỳ giá trị nào khác → **DỪNG.** Xuất: "Vui lòng chuyển sang một model Opus (`/model`) rồi chạy lại lệnh này."
49
49
 
50
50
  ## Bước 1 — Xác định Target File
51
51
 
@@ -54,7 +54,12 @@ Hiển thị và chờ phản hồi:
54
54
  2. Nếu `$ARGUMENTS` là một **UC-ID / ticket ID / tên rút gọn** (không có path) → phân giải thành file bằng cách glob theo bố cục feature-package. `{prd-slug}` lúc này **chưa biết**, nên dùng wildcard `*` cho segment đó, và `**` đệ quy dưới `bdd/` để phủ hết các thư mục con theo platform (`bdd/web/`, `bdd/app/`, `bdd/system/`):
55
55
  - **Lệnh BDD** (target là `.feature`): `{specs_dir}/{domain}/*/bdd/**/{UC-ID}*.feature` — hoặc `{specs_dir}/*/*/bdd/**/{UC-ID}*.feature` nếu domain cũng chưa biết. Nếu lệnh ngụ ý một platform/scope cụ thể (vd: system tech-doc cần BDD `system/`), ưu tiên kết quả trong thư mục con platform đó.
56
56
  - **Lệnh PRD** (target là file PRD `{TICKET-ID}-{prd-slug}.md` — file `.md` duy nhất ở gốc feature folder, cạnh `bdd/`): `{specs_dir}/{domain}/*/{TICKET-ID}*.md` nếu biết TICKET-ID; nếu không, `{specs_dir}/{domain}/*/*.md` (khớp feature folder có id tương ứng), hoặc `{specs_dir}/*/*/*.md` nếu domain cũng chưa biết. *(Glob `*/*.md` ở cấp gốc folder chỉ khớp PRD — tech-docs/design-spec `.md` nằm sâu hơn trong thư mục con.)*
57
- - **Lệnh tech-docs**: `{specs_dir}/{domain}/*/tech-docs/{UC-ID}*-tech-design*.md`.
57
+ - **Lệnh tech-docs** — target là tech-doc **gộp cấp PRD** `{TICKET-ID}-tech-design.md` (MỘT doc phủ nhiều UC; danh sách UC nằm ở `@trace.ucs`). Vì tên file mang `{TICKET-ID}` chứ **không** mang `{UC-ID}`, phải tách trước khi glob:
58
+ - `$ARGUMENTS` là **UC-ID** (`{TICKET-ID}-UC{N}`) → lấy `{TICKET-ID}` = phần **trước** `-UC`, rồi glob `{specs_dir}/{domain}/*/tech-docs/{TICKET-ID}-tech-design.md`.
59
+ - `$ARGUMENTS` là **TICKET-ID** → glob trực tiếp như trên.
60
+ - Chưa biết domain → `{specs_dir}/*/*/tech-docs/{TICKET-ID}-tech-design.md`.
61
+ - Vẫn không khớp → glob rộng `{specs_dir}/*/*/tech-docs/*tech-design*.md` rồi liệt kê để người dùng chọn.
62
+ *(Đừng glob `{UC-ID}*-tech-design*.md` — nó nở thành `FT-001-UC1*-tech-design*.md` và **không bao giờ** khớp `FT-001-tech-design.md`.)*
58
63
  - **Lệnh design-spec**: `{specs_dir}/{domain}/*/design-spec/{TICKET-ID}*.md`.
59
64
 
60
65
  Khi một file khớp: đặt nó làm target **và** ghi lại `domain` + `prd_slug` từ path của nó (theo quy tắc trích xuất trong `context-loader.md` Bước 1 — `prd_slug` = segment đầu tiên sau `{specs_dir}/{domain}/`). Mọi path mà lệnh đọc/ghi về sau (BDD/tech-docs/design-spec/trace cùng cấp) đều dùng **`prd_slug` đã phân giải đó**, nên tất cả artifact nằm chung một feature package. Nếu nhiều file khớp (vd: nhiều platform), chọn theo platform/scope của lệnh hoặc liệt kê ra và hỏi.
@@ -34,7 +34,7 @@ Tìm lệnh hiện tại trong bảng phase dưới đây và đánh dấu **pha
34
34
  | Phase | Commands |
35
35
  |-------|----------|
36
36
  | Discovery | `/define-product` |
37
- | PRD | `/generate-prd` · `/refine-prd` · `/review-context` (PRD) |
37
+ | PRD | `/generate-prd` · `/extend-prd` · `/refine-prd` · `/review-context` (PRD) |
38
38
  | Design Spec | `/generate-design-spec` |
39
39
  | BDD | `/generate-bdd` · `/review-context` (BDD) |
40
40
  | Tech Design | `/generate-tech-docs` · `/map-testids` · `/review-tech-docs` |
@@ -59,6 +59,7 @@ Gợi ý lệnh kế tiếp hợp lý theo phase của workflow:
59
59
  | /setup-ai-first | `/define-product` để bắt đầu feature đầu tiên |
60
60
  | /define-product | `/generate-prd {product-definition-file}` |
61
61
  | /generate-prd | `/refine-prd {prd-file}` rồi `/review-context {prd-file}` |
62
+ | /extend-prd | `/refine-prd {prd-file}` (soi phần vừa thêm) rồi `/review-context {prd-file}` → PO duyệt → `/generate-bdd` **chỉ cho UC MỚI**; UC cũ dùng `/validate-traces --realign-prd-version {UC-ID}` |
62
63
  | /refine-prd | Mở Review Board → cập nhật PRD → `/review-context {prd-file}` |
63
64
  | /review-context (PRD) | Khi 0 critical → PO đặt `Status: approved`, rồi FE/App: `/generate-design-spec {prd-file}` (→ design sign-off → BDD); BE: `/generate-bdd {prd-file}`. Còn critical/NEEDS_FIX → sửa PRD (giữ draft) |
64
65
  | /generate-design-spec | Designer review → xác nhận link Figma → PO + Designer sign-off → `/generate-bdd {prd-file}` |
@@ -71,6 +72,7 @@ Gợi ý lệnh kế tiếp hợp lý theo phase của workflow:
71
72
  | /qc-run-test | `/qc-report {UC-ID}` rồi `/qc-review {UC-ID}` (review script) |
72
73
  | /qc-review (script) | `/qc-report {UC-ID}` rồi tạo PR nếu APPROVED |
73
74
  | /qc-report | `/validate-traces {UC-ID}` để làm mới Living Docs (qc_status) |
75
+ | /map-testids | `/qc-design-test {UC-ID}` (QC dựng Page Object từ contract §4.5.6 vừa ghi) |
74
76
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
75
77
  | /review-tech-docs | `/generate-code {feature-file}` nếu APPROVED; sửa doc nếu NEEDS_FIX |
76
78
  | /generate-code | Lần gen đầu → `/review-code {UC-ID}`; gen lại → `/dev-gen-test {UC-ID}` |
@@ -79,11 +81,11 @@ Gợi ý lệnh kế tiếp hợp lý theo phase của workflow:
79
81
  | /dev-run-test (failing) | `/fix-bug {ticket-id}` hoặc `/debug {error}` |
80
82
  | /review-code | `/dev-smoke-test {UC-ID}` hoặc tạo PR |
81
83
  | /dev-smoke-test | Tạo PR và link tới ticket |
82
- | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/dev-gen-test {UC-ID}`; tất cả OK tạo PR |
83
- | /fix-bug | Tạo PR link tới ticket |
84
+ | /validate-traces | **Cờ 🔴 trước (chặn PR):** SEAM_UNWIRED → nối binding sang class thật, xoá/thay stub · STUB_UNRESOLVED → `/generate-code {owner_uc}` (lấp logic tại chỗ + xoá hàm song song) · ORPHANED/TRACE_ORPHAN → quyết định thủ công (xoá code+test, đưa scenario trở lại `.feature`, hoặc sửa `sc_id` của tag). **Rồi:** DRIFT/UNTRACKED → `/generate-code {UC-ID}` · BDD_DRIFT → `/generate-code {feature-file}` · tech-doc lỗi thời vs BDD → `/generate-tech-docs` → `/review-tech-docs` · PRD drift → `/generate-bdd {prd-file}` · GAP → `/dev-gen-test {UC-ID}`. **Chỉ tạo PR khi mọi cờ 🔴 = 0** |
85
+ | /fix-bug | `/dev-run-test {UC-ID}` (dev_selftest vừa reset về not_run) → tạo PR; nếu fix một `{BUG-ID}` → QC chạy `/qc-run-test {UC-ID}` để verify + đóng bug |
84
86
  | /debug | `/fix-bug {ticket-id}` nếu cần sửa |
85
87
  | /report-bug | Gửi cho dev (`/fix-bug {BUG-ID}`); nếu thiếu coverage → `/propose-scenario {UC-ID}` |
86
- | /propose-scenario | Báo PO/Dev review proposal trong `feedback/bdd-proposals/` |
88
+ | /propose-scenario | **Case A** (thiếu scenario cho AC có sẵn) → báo PO/Dev review trong `feedback/bdd-proposals/`; `/generate-bdd` tự chèn khi `Status: accepted`. **Case B** (requirement mới) → `feedback/prd-change-requests/` — PO phải đưa vào PRD trước, KHÔNG tự vào BDD được; `/validate-traces` nhắc lại kèm số ngày chờ chừng nào `Status: Open` |
87
89
  | /learn | Tiếp tục làm việc — lesson áp dụng ở lệnh kế tiếp |
88
90
  | /sync | `/validate-traces` để xem độ phủ đầy đủ; xử lý mọi `📥 tester feedback` được nêu |
89
91
  | /update-framework | Review `git diff .agent/`, commit; `/sync` để đồng bộ nội dung dự án |
@@ -1,7 +1,31 @@
1
- # Làm mới panel mirror của Living Docs *(local, chế độ umbrella)*
1
+ # Làm mới panel mirror của Living Docs *(local)*
2
2
 
3
- *Bỏ qua hoàn toàn chế độ single-service (không `services` không `setup.spec_source`) — đó
4
- `.trace/` của chính repo CHÍNH LÀ vị trí panel, nên không có gì để mirror.*
3
+ > **Hai vị trí, HAI TÊN KHÁC NHAU đọc trước khi sửa đây.**
4
+ >
5
+ > | Đường dẫn | Vai trò | Git |
6
+ > |---|---|---|
7
+ > | `{paths.trace_dir}` (`.trace/` hoặc `{spec_source}/.trace/`) | **AUTHORITATIVE** — TSV + `trace-history.jsonl`. Không regenerate được. | **PHẢI commit** |
8
+ > | `./.trace-mirror/` ở gốc workspace hiện tại | **MIRROR** — bản sao tiện cho panel VS Code. Sinh lại được bất cứ lúc nào. | **Luôn gitignore** |
9
+ >
10
+ > Trước v0.4.3 cả hai đều tên `.trace`, nên một luật gitignore theo tên có thể **xoá sạch sổ gốc**
11
+ > khi dev mở thẳng spec repo làm workspace (lúc đó hai path bằng nhau). Hai tên khác nhau làm
12
+ > luật git đọc được bằng mắt và **không còn ca nhập nhằng nào**: `.trace-mirror/` không bao giờ
13
+ > commit, `.trace/` không bao giờ gitignore.
14
+
15
+ ## Khi nào CÓ mirror
16
+
17
+ Mirror chỉ tồn tại khi **`{paths.trace_dir}` nằm NGOÀI workspace hiện tại** — panel đọc từ workspace đang mở nên cần một bản sao ở đây.
18
+
19
+ | Tình huống | `{paths.trace_dir}` | Có mirror? |
20
+ |---|---|---|
21
+ | Single-service | `./.trace` — **trong** workspace | ❌ Không. Panel đọc thẳng `.trace/trace-report.json`. Bỏ qua cả file này. |
22
+ | Dev mở thẳng **spec repo** | `./.trace` — **trong** workspace | ❌ Không. Như trên. |
23
+ | Umbrella + `spec_source`, dev đứng ở umbrella hoặc service submodule | `{spec_source}/.trace` — **ngoài** workspace | ✅ Có |
24
+ | Umbrella legacy (không `spec_source`) | `.trace` theo từng service | ✅ Có |
25
+
26
+ Quy tắc một dòng: **phân giải `panel_mirror = ./.trace-mirror` ở gốc workspace hiện tại; nếu `{paths.trace_dir}` đã nằm trong workspace này thì bỏ qua toàn bộ bước mirror.**
27
+
28
+ ---
5
29
 
6
30
  Sau khi cập nhật TSV authoritative tại `{paths.trace_dir}`:
7
31
 
@@ -9,11 +33,14 @@ Sau khi cập nhật TSV authoritative tại `{paths.trace_dir}`:
9
33
  `{paths.trace_dir}` phân giải về `{spec_source}/.trace` — vị trí authoritative duy nhất.
10
34
  Lệnh này chạy từ `service_root`, nên thao tác ghi là **liên-repo vào spec submodule**;
11
35
  commit/push spec submodule cho lần cập nhật trace (giống như `feedback/`).
12
- 1. Phân giải `panel_mirror = ./.trace` tại **gốc workspace hiện tại**.
13
- 2. Nếu `panel_mirror` phân giải ra path khác với `{paths.trace_dir}`, copy mỗi
36
+
37
+ 1. Phân giải `panel_mirror = ./.trace-mirror` tại **gốc workspace hiện tại**.
38
+ 2. Nếu `{paths.trace_dir}` **không** nằm trong workspace hiện tại, copy mỗi
14
39
  `{UC-ID}-{platform}.tsv` vừa cập nhật → `{panel_mirror}/{UC-ID}-{platform}.tsv` (tạo thư mục; ghi đè).
15
- Không namespace theo service — chỉ có một bộ trace; service sở hữu được mang trong
16
- `@trace.service` của từng row.
40
+ Không namespace theo service — chỉ có một bộ trace; service sở hữu được mang
41
+ **cột `service` (cột 23)** của chính từng row, do `/generate-bdd` ghi từ `@trace.service`.
42
+ 3. **KHÔNG copy `trace-history.jsonl`.** Nó là dữ liệu tích luỹ, không phải thứ sinh lại được —
43
+ nhân bản nó ra một thư mục gitignore là tạo hai lịch sử lệch nhau rồi mất bản thật.
17
44
 
18
45
  **Legacy (không có `spec_source` — trace theo service):**
19
46
  Copy mỗi `{UC-ID}-{platform}.tsv` vừa cập nhật → `{panel_mirror}/{service-name}/{UC-ID}-{platform}.tsv`
@@ -0,0 +1,47 @@
1
+ # templates/ — build-time skeletons
2
+
3
+ > **Nếu bạn đang mở thư mục này ở `.agent/templates/` trong một project: sửa file ở đây KHÔNG có tác dụng.**
4
+
5
+ ## Vì sao
6
+
7
+ Các skeleton trong thư mục này được `{{include}}` **nướng cứng vào file lệnh lúc `npm run build`**:
8
+
9
+ ```
10
+ templates/feature.template
11
+ ↓ {{include:templates/feature.template}} ← bin/build.js, thay thế văn bản lúc build
12
+ commands/generate-bdd.md
13
+ ↓ copy vào core/ → mirror sang .agent/
14
+ .agent/commands/generate-bdd.md ← LỆNH THẬT SỰ CHẠY (đã chứa sẵn skeleton)
15
+ .agent/templates/feature.template ← bản tham khảo, KHÔNG lệnh nào đọc
16
+ ```
17
+
18
+ Không lệnh nào đọc một path template lúc chạy. `paths.feature_template` / `paths.prd_template` từng tồn tại trong `project-context.yaml` nhưng chưa bao giờ có tác dụng — đã được gỡ bỏ (xem `GAPS.md` G9).
19
+
20
+ **Thêm nữa:** `.agent/` là vùng bị ghi đè. `/update-framework` chạy `npx … --init`, và `--init` copy `core/` → `.agent/` **vô điều kiện** (`bin/index.js` → `copyDirRecursive`, không có existence check, không backup). File duy nhất được giữ lại là `.agent/project-context.yaml`. Nên mọi chỉnh sửa ở `.agent/templates/` sẽ **biến mất im lặng** ở lần nâng cấp kế tiếp.
21
+
22
+ ## Muốn đổi cấu trúc artifact sinh ra thì làm gì
23
+
24
+ Sửa file trong **repo framework** rồi build lại:
25
+
26
+ ```bash
27
+ # trong repo sdd-framework
28
+ vim templates/feature.template # hoặc prd.template.md, tech-design.template.md, …
29
+ npm run build # inline lại vào commands/*.md + core/ + .agent/
30
+ ```
31
+
32
+ Rồi phát hành version mới; project chạy `/update-framework` để nhận.
33
+
34
+ ## File nào ở đây đi vào đâu
35
+
36
+ | Template | Được include vào | Trở thành |
37
+ |---|---|---|
38
+ | `feature.template` | `commands/generate-bdd.tmpl` | mỗi file `.feature` |
39
+ | `prd.template.md` | `commands/generate-prd.tmpl` | mỗi PRD |
40
+ | `tech-design.template.md` | `commands/generate-tech-docs.tmpl` | tech-doc gộp / PRD |
41
+ | `design-spec.template.md` | `commands/generate-design-spec.tmpl` | design-spec / platform |
42
+ | `architecture.template.md` | `commands/generate-architecture.tmpl` | tài liệu kiến trúc |
43
+ | `product-definition.template.md` | `commands/define-product.tmpl` | product definition |
44
+ | `platform-guide.template.md` | (tham khảo) | — |
45
+ | `project-context.yaml` | **không** include — được copy thẳng làm file config khởi tạo | `.agent/project-context.yaml` |
46
+
47
+ > Lưu ý `project-context.yaml` là ngoại lệ duy nhất: nó **được** copy ra làm file thật của project, và **được bảo vệ** khỏi ghi đè khi nâng cấp (chỉ tạo nếu chưa tồn tại).
@@ -1,18 +1,18 @@
1
1
  # ============================================================
2
2
  # @trace.id: {TICKET-ID}-UC{N}
3
3
  # @trace.title: <Feature name>
4
- # @trace.revision: 1 ← field tĩnh; dùng @trace.bdd_version để theo dõi version (tăng bởi /review-context --fix hoặc --resume)
4
+ # @trace.revision: 1 ← field tĩnh; version theo dõi bằng @trace.bdd_version
5
5
  # @trace.domain: <domain>
6
- # @trace.platform: {active_platform — web | app | system | (bỏ trong umbrella mode)}
7
- # @trace.service: {active_service — bỏ trong spec repo mode}
6
+ # @trace.platform: {active_platform — web | app | system} ← BẮT BUỘC mọi mode; phải khớp segment bdd/{platform}/ của path
7
+ # @trace.service: {active_service — BẮT BUỘC mọi mode. "—" ở single-service/spec repo mode; "multi" nếu chưa chốt; "unresolved" nếu routing sai. Nguồn của cột TSV `service` — trace gộp không tách theo service nên đây là chỗ DUY NHẤT mang thông tin sở hữu}
8
8
  # @trace.module: {active_module trong umbrella mode; "unknown" trong spec repo mode}
9
9
  # @trace.status: draft
10
10
  # @trace.author: AI-generated
11
11
  # @trace.created_at: {YYYY-MM-DD}
12
12
  # @trace.prd: {TICKET-ID}
13
13
  # @trace.prd_version: {đọc từ metadata PRD "| **Version** |"}
14
- # @trace.bdd_version: {1.0 nếu gen mới; tăng 0.1 khi gen lại vd 1.0 1.1}
15
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1, {TICKET-ID}-UC{N}-BR2
14
+ # @trace.bdd_version: {cấp FILE — 1.0 nếu gen mới; tăng 0.1 khi gen lại. Khác @trace.sc_version (cấp từng SC) bên dưới}
15
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}, {TICKET-ID}-UC{N}-BR{m+1} ← {m} lấy NGUYÊN từ PRD §3: BR đánh số LIÊN TỤC toàn PRD, KHÔNG reset theo UC
16
16
  # @trace.dataset: {domain}.testdata.yaml
17
17
  # ============================================================
18
18
 
@@ -59,8 +59,8 @@ Feature: <Feature name>
59
59
 
60
60
  # Side-effects: <liệt kê ngắn các Then side-effect cần verify>
61
61
  # @trace.scenario: {TICKET-ID}-UC{N}-SC1
62
- # @trace.sc_version: 1.0
63
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
62
+ # @trace.sc_version: 1.0 ← cấp SCENARIO. Sửa thân SC này (tên/step/table/side-effect) thì +0.1, nếu không code cũ mãi hiện OK
63
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}
64
64
  @happy
65
65
  Scenario: <mô tả business outcome — dùng động từ chính xác: create/receive/assign/block>
66
66
  Given <input state — alias từ dataset>
@@ -71,7 +71,7 @@ Feature: <Feature name>
71
71
  # Side-effects: <...>
72
72
  # @trace.scenario: {TICKET-ID}-UC{N}-SC2
73
73
  # @trace.sc_version: 1.0
74
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
74
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}
75
75
  @happy @alternative
76
76
  Scenario: <cùng theme NHÓM 1 nhưng path khác — vd: giá trị enum khác>
77
77
  Given <state>
@@ -85,7 +85,7 @@ Feature: <Feature name>
85
85
  # Side-effects: <...>
86
86
  # @trace.scenario: {TICKET-ID}-UC{N}-SC3
87
87
  # @trace.sc_version: 1.0
88
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR2
88
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m+2}
89
89
  @edge
90
90
  Scenario: <scenario boundary / error>
91
91
  Given <state>
@@ -97,8 +97,8 @@ Feature: <Feature name>
97
97
  # AC1 (...) → SC1, SC2
98
98
  # AC2 (...) → SC3
99
99
  # BR mapping (mỗi bullet PHẢI có ≥1 SC — C.2):
100
- # {TICKET-ID}-UC{N}-BR1 (...) → SC1, SC2
101
- # {TICKET-ID}-UC{N}-BR2 (...) → SC3
100
+ # {TICKET-ID}-UC{N}-BR{m} (...) → SC1, SC2
101
+ # {TICKET-ID}-UC{N}-BR{m+2} (...) → SC3
102
102
  # Wireframe mapping (mỗi component/action ≥1 SC — C.1):
103
103
  # Screen "<screen name>":
104
104
  # [x] <action 1> → SC1
@@ -111,6 +111,9 @@ Feature: <Feature name>
111
111
 
112
112
  # === PRE-MERGE CHECKLIST ===
113
113
  # - [ ] Mỗi SC có Side-effects + @trace.scenario + @trace.sc_version + @trace.business_rules
114
+ # - [ ] SỬA nội dung một SC (tên / step / data table / side-effect) → đã bump @trace.sc_version của
115
+ # CHÍNH SC đó (+0.1). Quên bump = code sinh từ SC cũ vẫn hiện OK, không ai biết phải regen.
116
+ # (Đổi @trace.business_rules / tag / comment → KHÔNG bump: không đổi hành vi cần implement.)
114
117
  # - [ ] Coverage Matrix: 0 dòng MISSING (C.1)
115
118
  # - [ ] FE/App: mỗi Screen State (≠default) + AC-UI behavioral của design-spec có ≥1 SC (C.1 mở rộng)
116
119
  # - [ ] Mỗi AC/BR map tới ≥1 SC (C.2)
@@ -25,28 +25,41 @@ project:
25
25
  # All paths are relative to workspace root.
26
26
  paths:
27
27
  # Feature-Package Layout:
28
- # specs/{domain}/{prd-slug}/{TICKET-ID}-{prd-slug}.md — PRD document
29
- # specs/{domain}/{prd-slug}/bdd/ — BDD .feature files
30
- # specs/{domain}/{prd-slug}/tech-docs/ — Technical design docs
31
- # specs/{domain}/{prd-slug}/design-spec/ — Design specs (FE/App only)
32
- # .trace/{domain}/{prd-slug}/{UC-ID}.tsv Trace state
28
+ # specs/{domain}/{prd-slug}/{TICKET-ID}-{prd-slug}.md — PRD document
29
+ # specs/{domain}/{prd-slug}/bdd/{platform}/ — BDD .feature ({platform} = web | app | system)
30
+ # specs/{domain}/{prd-slug}/tech-docs/ — Technical design (ONE merged doc per PRD: {TICKET-ID}-tech-design.md)
31
+ # specs/{domain}/{prd-slug}/design-spec/ — Design specs (FE/App only)
32
+ # specs/{domain}/{prd-slug}/changelog/ PRD changelog overflow (created once history exceeds 5 versions)
33
+ # .trace/{domain}/{prd-slug}/{UC-ID}-{platform}.tsv — Trace state (ONE book per UC × platform)
34
+ #
35
+ # The {platform} segment is NOT optional — in any mode, including umbrella.
36
+ # A UC's `web` and `system` features are two different files; without the segment they
37
+ # collide on one filename and overwrite each other. Trace is split the same way, so the
38
+ # spec layout has to match it. Every .feature also carries `@trace.platform` matching
39
+ # its own {platform} segment. (Projects still on the old flat bdd/ layout:
40
+ # run `npx @educa-corp/sdd-framework --migrate-bdd-platform` — dry-run by default.)
33
41
  #
34
42
  # specs_dir is the unified root for all spec artifact types (PRD, BDD, tech-docs, design-spec).
35
43
  # prd-slug is derived from the PRD folder path — not a separate config variable.
36
44
  specs_dir: "specs"
37
- templates_dir: "specs/templates"
38
45
 
39
46
  # Source code root — gốc mã nguồn của service/app này (nơi generate-code đặt & quét code).
40
47
  # BE thường suy vị trí từ CLAUDE.md §2 (code_base_package + layer); src_dir là gốc chung,
41
48
  # và là NGUỒN CHÍNH cho FE (component/hook/service/adapter) + phạm vi quét reuse (DS5).
42
49
  # Ví dụ: "src" (mono FE), "app/src", "src/main/java" (BE). Chỉnh theo layout thật của repo.
43
50
  src_dir: "src"
44
- feature_template: ".agent/templates/feature.template" # SoT skeleton .feature (dùng bởi /generate-bdd qua {{include}})
45
- bdd_writing_guide: "specs/templates/bdd-writing-guide.md"
46
- trace_report: "specs/.trace/trace-report.md"
47
51
 
48
- # PRD template (PRDs are at specs/{domain}/{prd-slug}/{TICKET-ID}-{prd-slug}.md)
49
- prd_template: "specs/templates/prd.template.md"
52
+ # ── Template artifact KHÔNG cấu hình được ──
53
+ # Đã bỏ 6 key chết (không lệnh nào đọc): feature_template · prd_template ·
54
+ # templates_dir · bdd_writing_guide · product_definition_template · trace_report.
55
+ # Các skeleton được {{include}} NƯỚNG CỨNG vào file lệnh lúc `npm run build`,
56
+ # nên lệnh không bao giờ đọc một path template lúc chạy.
57
+ # (trace_report còn trỏ sai hẳn: report thật là {trace_dir}/trace-report.json.)
58
+ #
59
+ # Đổi cấu trúc .feature / PRD sinh ra = sửa templates/*.template* TRONG REPO
60
+ # FRAMEWORK rồi build lại. Sửa .agent/templates/* trong project KHÔNG có tác
61
+ # dụng, và sẽ bị GHI ĐÈ IM LẶNG ở lần /update-framework kế tiếp (--init copy
62
+ # core/ → .agent/ vô điều kiện; file duy nhất được giữ là .agent/project-context.yaml).
50
63
  refinement_dir: ".agent/review"
51
64
 
52
65
  # QC's OWN analysis/design working docs (qc-analyze/plan/design-test outputs:
@@ -66,7 +79,6 @@ paths:
66
79
 
67
80
  # Product Definitions
68
81
  product_definitions_dir: "specs/product-definition"
69
- product_definition_template: "specs/templates/product-definition.template.md"
70
82
 
71
83
  # Domain Knowledge
72
84
  domain_knowledge_dir: "specs/domain-knowledge"
@@ -90,7 +102,7 @@ paths:
90
102
  # This variable is no longer needed as a separate path — derived from specs_dir.
91
103
  # design_spec_dir: "specs/design-spec" ← removed; use specs_dir instead
92
104
 
93
- # Trace (internal structure: .trace/{domain}/{prd-slug}/{UC-ID}.tsv)
105
+ # Trace (internal structure: .trace/{domain}/{prd-slug}/{UC-ID}-{platform}.tsv — one book per UC × platform)
94
106
  trace_dir: ".trace"
95
107
 
96
108
  # Tester / QC feedback (written by /report-bug and /propose-scenario).
@@ -133,7 +145,7 @@ domains:
133
145
  # specs_dir → {spec_source}/specs # unified root — PRD/BDD/tech-docs/design-spec
134
146
  # tech_docs_dir → {spec_source}/specs # merged into specs_dir
135
147
  # domain_knowledge_dir → {spec_source}/specs/domain-knowledge
136
- # trace_dir → {spec_source}/.trace # structure: .trace/{domain}/{prd-slug}/{UC-ID}.tsv
148
+ # trace_dir → {spec_source}/.trace # structure: .trace/{domain}/{prd-slug}/{UC-ID}-{platform}.tsv
137
149
  # (You can still override these manually in paths: section below.)
138
150
  # With spec_source set, only ONE override is needed instead of four separate dir vars.
139
151
  #
@@ -40,7 +40,7 @@
40
40
  @trace.service: {service — từ header BDD @trace.service}
41
41
  @trace.module: {module liên quan — vd dotnet, angular}
42
42
  @trace.platforms: {system | web | app — tuỳ thư mục BDD nào tồn tại}
43
- @trace.bdd_version: {map theo từng platform — vd system=1.5, web=1.9, app=1.7; chỉ platform có mặt. Mỗi feature mang bdd_version riêng; đừng gộp về một số.}
43
+ @trace.bdd_versions: {MAP theo từng platform — số nhiều, KHÁC @trace.bdd_version (scalar) của .feature — vd system=1.5, web=1.9, app=1.7; chỉ platform có mặt. Mỗi feature mang bdd_version riêng; đừng gộp về một số.}
44
44
  @trace.api_source: {existing | —}
45
45
  @trace.revision: 1
46
46
  @trace.status: draft
@@ -77,12 +77,29 @@ AI *follow* các file này — để trống thì nó *đoán*:
77
77
 
78
78
  | Lệnh | Việc | Ghi đè | KHÔNG đụng |
79
79
  |------|------|--------|-----------|
80
- | `/update-framework` | Sync bản npm mới | `.agent/commands\|steps\|hooks\|rules\|templates\|skills\|modules` | `CLAUDE.md`, `project-context.yaml`, `domain-knowledge/`, `.trace/` |
80
+ | `/update-framework` | Sync bản npm mới | `.agent/commands\|steps\|hooks\|rules\|templates\|skills\|modules` | `CLAUDE.md`, `.agent/project-context.yaml`, `.agent/project-lessons.md`, `.agent/review/`, `domain-knowledge/`, `.trace/`, `feedback/` |
81
81
  | `/sync` (umbrella) | Pull + init submodule + nổi feedback + Living Docs | — | — |
82
82
 
83
83
  Kiểm tra version mới nhất: `npm view @educa-corp/sdd-framework version`.
84
84
 
85
85
  > **Quy tắc edit (critical):** `.tmpl` + `steps/` là source of truth. Sửa framework artifact phải sửa `.tmpl`/`steps` rồi `node bin/build.js`. Sửa thẳng `.agent/commands/*.md` sẽ **mất** khi rebuild/update.
86
+ >
87
+ > Từ v0.4.2, nâng cấp **cứu** file bạn đã sửa trong vùng ghi đè: bản cũ lưu ở `.agent/.overwritten-{version}-{date}/` và danh sách được in ra. Ranh giới vùng-sửa-được đầy đủ: `.agent/README.md`. Chi tiết cơ chế: [Configuration › Vùng nào bị ghi đè](../04-reference/configuration.md#vùng-nào-bị-ghi-đè-khi-update).
88
+
89
+ ### Migration bố cục spec
90
+
91
+ Một số version đổi **bố cục** chứ không chỉ nội dung lệnh. `/update-framework` Step 5.5 tự quét và nhắc, hoặc chạy tay (đều **dry-run mặc định**, thêm `--apply` để thực thi):
92
+
93
+ | Lệnh | Khi nào cần |
94
+ |---|---|
95
+ | `--migrate-bdd-platform` | Có `.feature` nằm **trực tiếp** dưới `bdd/` (bố cục phẳng trước v0.4.1) → chuyển sang `bdd/{platform}/`. Bố cục phẳng làm `web`/`system` cùng UC **va tên và ghi đè nhau**. |
96
+ | `--migrate-specs` | Còn `specs/prd/` hay `specs/bdd/` ở cấp gốc (bố cục artifact-type-first rất cũ) |
97
+ | `--rename-prd-files` | PRD còn tên cố định `prd.md` thay vì `{TICKET-ID}-{prd-slug}.md` |
98
+
99
+ ```bash
100
+ npx @educa-corp/sdd-framework --migrate-bdd-platform # xem plan
101
+ npx @educa-corp/sdd-framework --migrate-bdd-platform --apply # thực thi
102
+ ```
86
103
 
87
104
  ---
88
105
 
@@ -26,8 +26,10 @@ Dùng AI tự do (mở chat, gõ prompt, copy-paste) → AI suy diễn theo tr
26
26
  | Vấn đề | Cách giải |
27
27
  |--------|-----------|
28
28
  | AI viết lung tung, không bám requirement | Spec là **anchor cứng**; code link `@trace.source` về scenario |
29
- | Sửa code → spec lệch → AI hiểu sai lần sau | **Spec là single source of truth**; code không lưu version riêng |
30
- | Sửa spec → không biết code nào cần regen | **Trace state `.tsv` per-UC** phát hiện OK/GAP/DRIFT/UNTRACKED |
29
+ | Sửa code → spec lệch → AI hiểu sai lần sau | **Spec là SSOT của "bản hiện tại"**; code mang version của "bản tôi được sinh theo" — **lệch nhau chính là tín hiệu drift** |
30
+ | Sửa spec → không biết code nào cần regen | **Trace state `.tsv`** một sổ / UC × platform `OK`/`GAP`/`DRIFT`/`UNTRACKED`/`ORPHANED` |
31
+ | Xoá scenario → code mồ côi nằm im | **Quét ngược code → spec**; code trỏ vào SC không còn tồn tại bị gắn cờ 🔴, không tự hết |
32
+ | Build xanh nhưng ghép luồng chạy vào no-op | **Sổ seam/stub** — bắt lớp lỗi mà build + test từng-UC không thấy |
31
33
  | PRD/BDD kém → code rác hàng loạt | **Quality gate** (`/review-context`) phải sạch critical + PO approve |
32
34
  | Lỗi/định hướng sai lặp lại | **`/learn`** ghi lesson, nạp lại vào context |
33
35
  | Đổi tech stack → viết lại workflow | **Module overlay** — skill đọc `stack-profile.yaml`, không hardcode |
@@ -62,13 +62,37 @@ Spec-driven thành/bại phụ thuộc **~80%** vào việc context được n
62
62
 
63
63
  ```
64
64
  .tmpl (source) + steps/*.md --[node bin/build.js, {{include:...}}]--> commands/*.md + core/
65
-
66
-
67
- .agent/commands/*.md (runtime)
65
+
66
+ │ templates/*.template* cũng được inline │
67
+ ▼ ▼
68
+ bin/self-check.js (fail build) .agent/commands/*.md (runtime)
68
69
  ```
69
70
 
70
71
  - Cơ chế `{{include:steps/...}}` ghép phẳng → single source of truth ở `.tmpl` + `steps/`.
71
72
  - **Không sửa tay** `commands/*.md` / `.agent/` — sửa `.tmpl`/`steps` rồi `node bin/build.js`. *(Quy ước + memory bảo vệ, không phải hook.)*
73
+ - **Template artifact cũng bị inline lúc build.** `templates/feature.template` và `prd.template.md` được `{{include}}` **nướng cứng** vào file lệnh, nên lệnh không đọc path template lúc chạy — sửa `.agent/templates/` **không có tác dụng**. Đổi cấu trúc `.feature`/PRD = sửa `templates/*` trong repo framework rồi build lại.
74
+
75
+ ### Self-check — contract trace không được lệch
76
+
77
+ ```
78
+ bin/trace-schema.json ──[bin/self-check.js]──> đối chiếu commands/*.tmpl + steps/*.md
79
+ (SoT máy đọc) → exit 1 nếu lệch → build FAIL
80
+ ```
81
+
82
+ **Vì sao cần:** phần lớn lỗi lịch sử của framework là **cùng một dạng** — contract (field `@trace.*`, cột `.tsv`, path pattern, giá trị enum) được phát biểu lại bằng **prose** ở nhiều lệnh rồi lệch nhau qua từng lần sửa, và không có gì phát hiện. Ca thuần khiết nhất: `@trace.sc_version` từng có **3 consumer, 0 producer** — nghĩa là `DRIFT` chết hoàn toàn — mà không lệnh nào, cổng nào, test nào bắt được.
83
+
84
+ | Rule | Bắt gì | Mức |
85
+ |:---:|---|:---:|
86
+ | R1 | field có consumer nhưng **không producer** | ERROR |
87
+ | R2 | field có producer nhưng **không ai đọc** (field chết) | WARN |
88
+ | R3 | actor khai trong schema mà file của nó **không nhắc** field | ERROR |
89
+ | R4 | `{paths.X}` dùng mà không khai / khai mà không ai dùng | ERROR / WARN |
90
+ | R5 | pattern bị cấm **quay lại** (vd `bdd/` thiếu `{platform}`) | ERROR |
91
+ | R6 | giá trị enum khai mà **không xuất hiện ở đâu** | WARN |
92
+
93
+ **Quy tắc vận hành:** đổi contract → sửa `bin/trace-schema.json` **TRƯỚC**, rồi mới sửa lệnh, rồi cập nhật [Trace Schema (người đọc)](../04-reference/trace-schema.md). Chạy riêng: `npm run self-check`.
94
+
95
+ *(Schema là JSON chứ không YAML vì `package.json` có **zero dependency** — npx chạy không cần install; thêm `js-yaml` chỉ để đọc một file build-time là không đáng. Nó nằm ở `bin/` chứ không `templates/` để không lọt vào `.agent/templates/` của mọi project.)*
72
96
 
73
97
  ---
74
98