spec-lite 1.4.7 → 1.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.
@@ -183,7 +183,7 @@ Hiển thị draft đầy đủ — chưa ghi file.
183
183
 
184
184
  ### Bước 6: Save
185
185
 
186
- Ghi `.specs/main/feature/{F-XXX}-{slug}/tsd.md` với status `draft` (feature-level artifact có lifecycle riêng, không phải `approved` — QC còn fill placeholders nên status `draft` cho đến khi đầy đủ).
186
+ Ghi `.specs/main/feature/{F-XXX}-{slug}/tsd.md` với status `draft` (feature-level artifact có lifecycle riêng, không phải `approved` — QC còn fill placeholders nên status `draft` cho đến khi đầy đủ). Frontmatter lấy `template_version` từ `tsd-template.md` (xem `conventions.md` §7).
187
187
 
188
188
  Nếu overwrite — file backup `tsd.md.bak.{timestamp}` đã tạo ở Bước 2.
189
189
 
@@ -238,3 +238,4 @@ Trước khi ghi file:
238
238
  - [ ] Priority deterministic theo bảng 4.3
239
239
  - [ ] Nếu overwrite: tsd.md.bak.{timestamp} đã được tạo
240
240
  - [ ] QC đã confirm draft
241
+ - [ ] Frontmatter có `template_version` copy từ `tsd-template.md`
@@ -220,34 +220,35 @@ Nhóm skill dọn dẹp / migrate artifacts hiện có sau khi template được
220
220
 
221
221
  | Command | Reads | Writes |
222
222
  | --- | --- | --- |
223
- | `/spec-frd-update` | `feature/*/frd.md`, `frd-template.md` | `feature/*/frd.md`, cascade: `fdd.md`, `tsd.md`, `integrations/*/spec.md`, `tech.md`, `test.md` |
223
+ | `/artifact-audit [type]` | `.specs/**` artifacts, `.claude/templates/*-template.md` | *(báo cáo; + stamp `template_version` cho artifact legacy conform)* |
224
+ | `/artifact-migrate [path]` | `.specs/**` artifacts, `.claude/templates/*-template.md` (block `migrations`) | artifact được migrate (structure + `template_version`) |
224
225
 
225
- ### `/spec-frd-update`
226
+ ### `/artifact-audit [type]`
226
227
 
227
- Migrate frd.md hiện lên format mới nhất của `templates/main/feature/frd-template.md`. Dùng cho repo đã chạy `/spec-brownfield-feature` hoặc `/spec-new` từ trước, frd.md sinh ra theo template cũ.
228
+ Phát hiện artifact lỗi thời so với template (xem `conventions.md` §7 Template Versioning). So `template_version` của artifact với `template_version` đọc thẳng từ template tại `.claude/templates/` không manifest, không cache.
228
229
 
229
- **8 migration vectors** detect tự động:
230
+ **Scope:** argument là 1 type (`/artifact-audit frd`) hoặc list (`frd,spec`); không có arg → audit mọi type. Type resolve theo **filename** (integration artifact không có field `type`).
230
231
 
231
- | Vector | Action | Risk |
232
- |---|---|---|
233
- | V1 | Fix Mermaid syntax `[{...}]` → `["..."]` | None |
234
- | V2 | Insert "Flow numbering stable" note | None |
235
- | V3 | Rename `Feature-level AC` → `Feature AC` + 4 nhóm chuẩn | Low |
236
- | V4 | Rename `AC-F{NNN}-` (Feature AC) → `FAC-F{NNN}-` (counter riêng) + cascade refs | **HIGH** |
237
- | V5 | Insert US/AC stability notes | None |
238
- | V6 | Propose Verification Rules từ User Stories → user approve → insert | Medium |
239
- | V7 | Move `Components Consumed` → `Dependencies > Components Used` | Low |
240
- | V8 | Derive Mermaid flows từ User Stories → propose → user approve → insert | Medium |
232
+ **Phân loại mỗi artifact:**
233
+ - Có `template_version` → `==`: **up-to-date**; `!=`: **out-dated** `(vX → vY)` → migrate.
234
+ - Thiếu version (legacy) presence-check (đủ required `##` + không còn section `migrations.remove`): conform **stamp** `template_version` (có confirm); lệch → **out-dated** + tóm tắt phần thiếu.
241
235
 
242
- **Workflow:** Pre-flight git clean check discover & classify per-FRD context load apply mechanical vectors (V1/V2/V3/V5/V7) → V4 dry-run preview với cascade impact → confirm → V6 propose VR → confirm → V8 propose Flows → confirm → validate → report.
236
+ **Ranh giới:** chỉ phát hiện + stamp legacy conform. **KHÔNG migrate** đổi structure việc của `/artifact-migrate`. Bỏ qua `.specs/archive/` `.specs/removed/`.
243
237
 
244
- **Cảnh báo:**
245
- - V4 mặc định dry-run, in remap table + cascade diff trước khi ghi.
246
- - V6 luôn propose-then-approve, không auto-apply (model dễ bịa rule).
247
- - V8 luôn propose-then-approve — model derive flow từ US journey grouping, BA phải review để catch glue step bịa hoặc grouping sai.
248
- - KHÔNG tạo file `.bak` — rollback dùng `git checkout -- {file}`. Pre-flight yêu cầu working tree clean.
238
+ ### `/artifact-migrate [path]`
249
239
 
250
- **No-op safe:** nếu mọi FRD đã clean, skill báo dừng không ghi gì.
240
+ Migrate artifact lỗi thời lên structure template mới nhất, generic cho mọi type (vế **fix** đối xứng với `/artifact-audit` vế **detect**).
241
+
242
+ **Scope:** arg = 1 artifact (path) → migrate riêng nó; không arg → quét toàn bộ, migrate từng cái có confirm + skip.
243
+
244
+ **Quy trình:** pre-flight git clean → **tự chạy `/artifact-audit` classify-only (scoped)** để phát hiện out-dated (up-to-date → no-op sớm) → đọc block `migrations` của template lấy delta `add`/`remove`/`update` → dry-run + confirm → apply (set `template_version` = current; main artifact thêm Change History `manual`/migrate).
245
+
246
+ **Quy tắc:**
247
+ - **ADD** = required `##` thiếu (skeleton từ body template); section nội dung mới → interview hoặc `NEEDS_CLARIFY`, **KHÔNG bịa**.
248
+ - **REMOVE** = section trong `migrations.remove` còn sót (có confirm); giữ content tác giả khác (superset).
249
+ - **UPDATE** = section trong `migrations.update` — giữ section + ngữ nghĩa, chỉ đổi **format/cách thể hiện** (vd ASCII → Mermaid); show cũ + đề xuất mới, confirm; KHÔNG thêm/bớt thông tin. (Không presence-check được → chỉ bắt qua version compare.)
250
+ - Rename (remove+add) → hỏi carry-over nội dung.
251
+ - **Single-artifact, KHÔNG cascade.** ID remap (hiếm) → ghi ở `note`, sửa tay. Rollback dùng git (không `.bak`).
251
252
 
252
253
  ---
253
254
 
@@ -6,6 +6,10 @@ features: []
6
6
  components: []
7
7
  status: draft
8
8
  created: {YYYY-MM-DD}
9
+ template_version: 1
10
+ migrations:
11
+ - to: 1
12
+ note: "baseline"
9
13
  referenced_by:
10
14
  - conventions.md > 4. Integration Artifacts > 4.5 plan.md > Cấu trúc
11
15
  - skills/plan/SKILL.md > Output Format > plan.md
@@ -6,6 +6,10 @@ features: []
6
6
  components: []
7
7
  status: draft
8
8
  created: {YYYY-MM-DD}
9
+ template_version: 1
10
+ migrations:
11
+ - to: 1
12
+ note: "baseline"
9
13
  referenced_by:
10
14
  - conventions.md > 4. Integration Artifacts > 4.3 spec.md > Cấu trúc
11
15
  - skills/spec-new/SKILL.md > Process > Bước 5: Write — sinh draft
@@ -6,6 +6,10 @@ features: []
6
6
  components: []
7
7
  status: draft
8
8
  created: {YYYY-MM-DD}
9
+ template_version: 1
10
+ migrations:
11
+ - to: 1
12
+ note: "baseline"
9
13
  referenced_by:
10
14
  - conventions.md > 4. Integration Artifacts > 4.4 tech.md > Cấu trúc
11
15
  - skills/spec-tech/SKILL.md > Process > Bước 4: Write — sinh draft
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  slug: "{slug}"
3
3
  created: {YYYY-MM-DD}
4
+ template_version: 1
5
+ migrations:
6
+ - to: 1
7
+ note: "baseline"
4
8
  referenced_by:
5
9
  - skills/review-integration/SKILL.md > Bước 2 — Luôn ghi findings vào techdebt.md
6
10
  ---
@@ -5,6 +5,10 @@ title: "{title}"
5
5
  features: []
6
6
  status: draft
7
7
  created: {YYYY-MM-DD}
8
+ template_version: 1
9
+ migrations:
10
+ - to: 1
11
+ note: "baseline"
8
12
  referenced_by:
9
13
  - conventions.md > 4. Integration Artifacts > 4.7 test.md > Cấu trúc
10
14
  - skills/spec-test/SKILL.md > Process > Bước 4: Write — sinh draft
@@ -5,6 +5,10 @@ title: "{title}"
5
5
  features: []
6
6
  components: []
7
7
  created: {YYYY-MM-DD}
8
+ template_version: 1
9
+ migrations:
10
+ - to: 1
11
+ note: "baseline"
8
12
  referenced_by:
9
13
  - conventions.md > 4. Integration Artifacts > 4.6 todo.md > Cấu trúc
10
14
  - skills/plan/SKILL.md > Output Format > todo.md
@@ -4,6 +4,10 @@ type: cdd
4
4
  status: draft
5
5
  owner: "{Tech Lead / Senior Dev}"
6
6
  component_id: "{Component ID, ví dụ C-001}"
7
+ template_version: 1
8
+ migrations:
9
+ - to: 1
10
+ note: "baseline"
7
11
  referenced_by:
8
12
  - conventions.md > 3. Main Artifacts > 3.2 Component level > cdd.md > Cấu trúc
9
13
  - skills/spec-tech/SKILL.md > Process > Cascade Proposals > component cdd.md
@@ -4,6 +4,10 @@ type: crd
4
4
  status: draft
5
5
  owner: "{BA / Tech Lead}"
6
6
  component_id: "{Component ID từ PRD Component Index, ví dụ C-001}"
7
+ template_version: 1
8
+ migrations:
9
+ - to: 1
10
+ note: "baseline"
7
11
  referenced_by:
8
12
  - conventions.md > 3. Main Artifacts > 3.2 Component level > crd.md > Cấu trúc
9
13
  - skills/spec-new/SKILL.md > Process > Bước 5: Write — sinh draft > component/{C-XXX}/crd.md
@@ -3,6 +3,10 @@ id: domain
3
3
  type: domain
4
4
  status: draft
5
5
  owner: "{BA/Domain Expert}"
6
+ template_version: 1
7
+ migrations:
8
+ - to: 1
9
+ note: "baseline"
6
10
  referenced_by:
7
11
  - conventions.md > 3. Main Artifacts > 3.1 Product level > domain.md > Cấu trúc
8
12
  - skills/spec-prd/SKILL.md > Process > Bước 5: Save (scaffold domain.md skeleton)
@@ -4,6 +4,10 @@ type: fdd
4
4
  status: draft
5
5
  owner: "{Tech Lead / Senior Dev}"
6
6
  feature_id: "{Feature ID}"
7
+ template_version: 1
8
+ migrations:
9
+ - to: 1
10
+ note: "baseline"
7
11
  referenced_by:
8
12
  - conventions.md > 3. Main Artifacts > 3.3 Feature level > fdd.md > Cấu trúc
9
13
  - skills/spec-tech/SKILL.md > Process > Bước 4: Write — sinh draft > Cascade Proposals > fdd.md
@@ -4,6 +4,10 @@ type: frd
4
4
  status: draft
5
5
  owner: "{BA}"
6
6
  feature_id: "{Feature ID từ PRD Feature Index}"
7
+ template_version: 1
8
+ migrations:
9
+ - to: 1
10
+ note: "baseline"
7
11
  referenced_by:
8
12
  - conventions.md > 3. Main Artifacts > 3.3 Feature level > frd.md > Cấu trúc
9
13
  - skills/spec-frd/SKILL.md > Process > Bước 5: Write — sinh draft
@@ -158,7 +162,8 @@ Tham chiếu đến `.specs/main/component/{C-XXX}-...`.
158
162
  ## Open Questions
159
163
 
160
164
  <!-- Các câu hỏi cần làm rõ trong interview / với stakeholder trước khi proceed.
161
- Cũng dùng để note component candidate chưa carve (xem skills/spec-frd). Xóa section nếu không còn câu hỏi nào. -->
165
+ Cũng dùng để note component candidate chưa carve (xem skills/spec-frd).
166
+ Section required-emptyable: GIỮ heading; để trống (không có bullet) nếu không còn câu hỏi nào. -->
162
167
 
163
168
  - [ ] {câu hỏi cần clarify} — {ai trả lời / khi nào}
164
169
 
@@ -5,6 +5,10 @@ status: draft
5
5
  owner: "{QC}"
6
6
  feature_id: "{Feature ID — match frd.md}"
7
7
  frd_ref: "feature/{F-XXX}-{slug}/frd.md"
8
+ template_version: 1
9
+ migrations:
10
+ - to: 1
11
+ note: "baseline"
8
12
  referenced_by:
9
13
  - conventions.md > 3. Main Artifacts > 3.3 Feature level > tsd.md > Cấu trúc
10
14
  ---
@@ -4,6 +4,10 @@ type: prd
4
4
  status: draft
5
5
  owner: "{PM/BA}"
6
6
  project_name: "{tên dự án}"
7
+ template_version: 1
8
+ migrations:
9
+ - to: 1
10
+ note: "baseline"
7
11
  referenced_by:
8
12
  - conventions.md > 3. Main Artifacts > 3.1 Product level > prd.md > Cấu trúc
9
13
  - skills/spec-prd/SKILL.md > Process > Bước 1: Kiểm tra preconditions
@@ -3,6 +3,10 @@ id: sad
3
3
  type: sad
4
4
  status: draft
5
5
  owner: "{Tech Lead / Architect}"
6
+ template_version: 1
7
+ migrations:
8
+ - to: 1
9
+ note: "baseline"
6
10
  referenced_by:
7
11
  - conventions.md > 3. Main Artifacts > 3.1 Product level > sad.md > Cấu trúc
8
12
  - skills/spec-sad/SKILL.md > Process > Bước 1: Kiểm tra preconditions
@@ -1,398 +0,0 @@
1
- ---
2
- name: spec-frd-update
3
- description: Migrate frd.md hiện có lên cấu trúc template mới nhất — fix Mermaid syntax, rename Feature AC → FAC (counter riêng), thêm Verification Rules section, cascade ID remap qua fdd/tsd/test/spec/tech. Dùng cho repo đã onboard SDD từ trước khi template thay đổi.
4
- ---
5
-
6
- # spec-frd-update
7
-
8
- ## Overview
9
-
10
- Migrate các file `.specs/main/feature/{F-XXX}-{slug}/frd.md` hiện có sang **format mới nhất** của [templates/main/feature/frd-template.md](../../templates/main/feature/frd-template.md).
11
-
12
- Skill này **chỉ làm migration mechanical + propose** — không phải BA interview. Mọi quyết định nội dung mới (Verification Rules content) đều cần user approve trước khi ghi.
13
-
14
- ## When to Use
15
-
16
- - Repo đã chạy `/spec-brownfield-feature` hoặc `/spec-new` từ lâu, frd.md sinh ra theo template cũ — giờ template đã update.
17
- - Sau khi `git pull` kit mới và phát hiện frd.md hiện tại thiếu section so với template mới.
18
- - Audit định kỳ để đảm bảo mọi frd.md tuân thủ cùng format.
19
-
20
- ## When NOT to Use
21
-
22
- - frd.md chưa tồn tại → dùng `/spec-brownfield-feature` (brownfield) hoặc `/spec-new` (greenfield).
23
- - Muốn thay đổi **nội dung** frd (thêm US, đổi AC text) → edit thủ công hoặc qua integration changeset.
24
- - Template chưa thay đổi gì so với khi frd.md được tạo → skill này sẽ no-op, không có gì để làm.
25
-
26
- ---
27
-
28
- ## Cảnh báo về ID cascade
29
-
30
- Skill này có thể **rename Feature AC ID** từ `AC-F{NNN}-{seq}` sang `FAC-F{NNN}-{seq}` (counter riêng, reset từ 001). Các file sau có thể reference những ID này và cần cascade:
31
-
32
- - `feature/{F-XXX}/fdd.md` — section Verification Implementation
33
- - `feature/{F-XXX}/tsd.md` — Traceability Matrix, Test Cases
34
- - `integrations/*/spec.md` — Cascade Proposals, Changes blocks
35
- - `integrations/*/tech.md` — Changes blocks
36
- - `integrations/*/test.md` — Coverage table
37
-
38
- **Mặc định dry-run** — skill in toàn bộ ID remap + diff trước khi ghi, user xác nhận từng feature một.
39
-
40
- ---
41
-
42
- ## Migration vectors
43
-
44
- Skill detect từng frd hiện tại thuộc "era" nào và apply vectors tương ứng:
45
-
46
- | Vector | Detect bằng | Action | Risk |
47
- |---|---|---|---|
48
- | **V1 Mermaid syntax** | Có pattern `\[\{.+?\}\]` trong code block mermaid | Rewrite `[{X}]` → `["X"]` | None |
49
- | **V2 Flow stability note** | Section `## User Flows` thiếu chuỗi "Flow numbering" | Insert dòng note sau intro | None |
50
- | **V3 Section rename** | Có heading `## Feature-level Acceptance Criteria` | Rename → `## Feature Acceptance Criteria` + insert 4-group block + Out-of-scope note | Low |
51
- | **V4 FAC ID renumber** | Trong section Feature AC, IDs dùng prefix `AC-F` (chứ không phải `FAC-F`) | Remap → `FAC-F{NNN}-001..N` + cascade references trong repo | **HIGH** |
52
- | **V5 US/AC stability notes** | Section User Stories thiếu chuỗi "ID stable" | Insert 2 dòng note | None |
53
- | **V6 VR section** | Không có heading `## Verification Rules` | Propose VR table từ User Stories → user approve → insert | Medium |
54
- | **V7 Components Used location** | Section `## Components Consumed` đứng riêng (era pre-84d7303) | Move xuống `## Dependencies` thành subsection `### Components Used` | Low |
55
- | **V8 User Flows missing** | Không có heading `## User Flows` (era pre-84d7303) | Derive Mermaid flows từ User Stories → propose → user approve → insert. 1 flow / nhóm US liên quan theo journey logic. **Bắt buộc — không có option skip; FRD migration không hoàn tất nếu thiếu User Flows.** | Medium |
56
-
57
- ---
58
-
59
- ## Process
60
-
61
- ### Bước 0: Pre-flight — working tree clean
62
-
63
- Chạy `git status --porcelain`. Nếu output không rỗng (có file modified / untracked / staged):
64
-
65
- ```
66
- ⛔ Working tree không clean. Skill không tạo file backup `.bak` — rollback dựa vào git.
67
- Hãy commit hoặc stash thay đổi hiện tại trước khi chạy `/spec-frd-update`, rồi chạy lại.
68
-
69
- Files dirty:
70
- M .specs/main/feature/F-001-auth/frd.md
71
- ?? notes.md
72
- ```
73
-
74
- Dừng hoàn toàn. Skill chỉ proceed khi `git status` clean — đảm bảo mọi change sau đó đều thuộc migration, dễ revert bằng `git checkout -- {path}` hoặc `git restore`.
75
-
76
- Nếu repo không phải git repo → cảnh báo và yêu cầu confirm:
77
- > ⚠ Thư mục này không phải git repo. Skill không tạo file backup. Nếu apply sai, không thể rollback. Tiếp tục? (yes / no — default no)
78
-
79
- ---
80
-
81
- ### Bước 1: Discover & classify
82
-
83
- Quét `.specs/main/feature/*/frd.md`. Với mỗi file:
84
-
85
- 1. Parse headings và frontmatter.
86
- 2. Run detection cho V1–V8.
87
- 3. Build classification table.
88
-
89
- Display kết quả:
90
-
91
- ```
92
- Detected FRDs:
93
-
94
- [1] F-001 — auth | Era: 2026-04 | Vectors needed: V1, V3, V4 (3 IDs), V5, V6
95
- [2] F-002 — checkout | Era: 2026-05 | Vectors needed: V5, V6
96
- [3] F-003 — refund | Era: current | Vectors needed: — (đã clean)
97
- [4] F-004 — admin-panel | Era: pre-flows | Vectors needed: V1, V3, V4 (2 IDs), V5, V6, V7, V8
98
-
99
- Tổng: 4 FRDs · 3 cần migration · 1 đã sạch.
100
- ```
101
-
102
- Hỏi user scope:
103
-
104
- ```
105
- Migrate FRDs nào?
106
- [A] Tất cả cần migration (3 files)
107
- [1] Chỉ F-001
108
- [2] Chỉ F-002
109
- ...
110
- [N] Chọn subset (nhập danh sách số, vd: "1 4")
111
- [X] Hủy
112
-
113
- Lựa chọn:
114
- ```
115
-
116
- Nếu không có FRD nào cần migration → thông báo `Tất cả frd.md đã clean. No-op.` rồi dừng.
117
-
118
- ---
119
-
120
- ### Bước 2: Load context per FRD
121
-
122
- Với mỗi FRD đã chọn, load các file sau (chỉ những gì cần thiết — KHÔNG load conventions.md, KHÔNG load source code):
123
-
124
- | File | Bắt buộc | Mục đích |
125
- |---|---|---|
126
- | `.specs/main/feature/{F-XXX}-{slug}/frd.md` | ✓ | File cần migrate |
127
- | [templates/main/feature/frd-template.md](../../templates/main/feature/frd-template.md) | ✓ | Target structure — copy text cho V2/V3/V5 |
128
- | `.specs/main/feature/{F-XXX}-{slug}/fdd.md` | nếu tồn tại | Cascade target cho V4 (AC→FAC rename) |
129
- | `.specs/main/feature/{F-XXX}-{slug}/tsd.md` | nếu tồn tại | Cascade target cho V4 |
130
- | `.specs/main/domain.md` (Shared Entities block) | optional | Cho V6 — match field name với entity glossary để pick semantic type consistent |
131
-
132
- **KHÔNG load:**
133
- - `conventions.md` — template đã self-contained, load là thừa
134
- - Source code — frd là WHAT, derive VR từ US/AC chứ không phải implementation
135
- - `tech.md`/`cdd.md` — có thể contaminate VR bằng tech detail (regex, varchar(255)…)
136
-
137
- ---
138
-
139
- ### Bước 3: Apply mechanical vectors (V1, V2, V3, V5, V7)
140
-
141
- Đây là các vector **không cần model reasoning** — pure text manipulation. Apply tuần tự, không hỏi user.
142
-
143
- #### V1 — Mermaid syntax fix
144
- - Regex trong mỗi code block ```mermaid: `\[\{([^}]+)\}\]` → `["$1"]`
145
- - Edge case: keep escaped braces nguyên vẹn, chỉ replace pattern `[{...}]` ở edge label / node label.
146
-
147
- #### V2 — Flow stability note
148
- - Sau bullet intro của `## User Flows` (dòng `{Mỗi flow là một Mermaid…}`), insert:
149
- > Flow numbering **stable** — không renumber khi xóa flow. Nếu xóa Flow 1, Flow 2 giữ nguyên số (không tái sử dụng số 1).
150
-
151
- #### V3 — Section rename + structure
152
- - Rename heading `## Feature-level Acceptance Criteria` → `## Feature Acceptance Criteria`.
153
- - Replace block intro (dòng "Criteria áp dụng cho toàn bộ feature — không gắn với story…") bằng full block từ template (4 nhóm + Out-of-scope + Format note). Copy nguyên văn từ frd-template.md.
154
-
155
- #### V5 — US/AC stability notes
156
- - Sau dòng `US ID format: ...` trong User Stories section, đảm bảo có 2 dòng:
157
- > US ID format: `US-F{NNN}-{seq}` — đánh số tăng dần toàn feature. ID **stable** — không tái sử dụng seq khi xóa, không renumber.
158
- >
159
- > Story AC ID format: `AC-F{NNN}-{seq}` — đánh số tăng dần toàn feature (không reset giữa các story). ID **stable** — không tái sử dụng seq khi xóa, không renumber.
160
-
161
- #### V7 — Components Used relocation
162
- - Detect `## Components Consumed` section.
163
- - Cắt nội dung bảng, xóa heading.
164
- - Trong `## Dependencies`, ensure có 2 subsections: `### Feature Dependencies` (giữ bảng cũ nếu có) và `### Components Used` (chèn bảng vừa cắt).
165
-
166
- ---
167
-
168
- ### Bước 4: V4 — AC → FAC renumber với cascade
169
-
170
- **Đây là vector cao risk nhất.** Mỗi feature làm tuần tự, không batch.
171
-
172
- #### 4.1 Parse Feature AC IDs
173
- - Trong section `## Feature Acceptance Criteria` (đã rename ở V3), extract tất cả ID dạng `AC-F{NNN}-{seq}`.
174
- - List: `[AC-F001-002, AC-F001-005, AC-F001-007]` (gap OK).
175
-
176
- #### 4.2 Build remap table
177
- - Cũ → mới: reset counter từ 001, giữ thứ tự xuất hiện.
178
- - Ví dụ:
179
- ```
180
- AC-F001-002 → FAC-F001-001
181
- AC-F001-005 → FAC-F001-002
182
- AC-F001-007 → FAC-F001-003
183
- ```
184
-
185
- #### 4.3 Scan cascade references
186
- - Grep toàn `.specs/` cho từng ID cũ.
187
- - **CRITICAL**: chỉ remap những match THUỘC Feature AC (Bước 4.1 list). KHÔNG đụng Story AC trùng namespace `AC-F{NNN}-{seq}` — đây là string overlap nhưng khác counter.
188
- - Tạo bảng impact:
189
- ```
190
- Cascade impact for F-001:
191
- feature/F-001-auth/fdd.md 3 refs
192
- feature/F-001-auth/tsd.md 5 refs
193
- integrations/003-otp-flow/spec.md 1 ref
194
- integrations/003-otp-flow/test.md 2 refs
195
- ```
196
-
197
- #### 4.4 Dry-run preview
198
- Hiển thị:
199
- - Full remap table
200
- - Per-file diff snippet (3 dòng context mỗi ref)
201
- - Confirm prompt:
202
-
203
- ```
204
- Apply remap cho F-001? (yes / no / skip-feature)
205
- yes → apply tất cả changes (frd.md + cascade files)
206
- no → hủy V4 cho feature này, vẫn giữ AC-F prefix
207
- skip-feature → bỏ qua toàn bộ migration cho F-001
208
- ```
209
-
210
- #### 4.5 Apply
211
- - Edit `frd.md`: rewrite IDs trong section Feature AC.
212
- - Edit từng cascade file: replace exact ID strings (sử dụng Edit với context dòng để tránh false-positive).
213
- - Validate: re-grep ID cũ, phải về 0 trong Feature AC scope; Story AC giữ nguyên.
214
-
215
- ---
216
-
217
- ### Bước 5: V6 — Generate Verification Rules section
218
-
219
- **Vector tiêu tốn LLM nhất.** Run nếu V6 detected.
220
-
221
- #### 5.1 Load minimal context
222
- - Section `## User Stories` của FRD đó (đã chứa AC).
223
- - Optional: `domain.md > Shared Entities` block (nếu có field match entity name).
224
-
225
- **KHÔNG load:** code, fdd.md, tech.md. Mục đích: tránh contamination bằng HOW.
226
-
227
- #### 5.2 Derive rules
228
- Quét từng AC trong User Stories:
229
- - Identify input action ("nhập email", "submit form", "chọn date", "upload file"…).
230
- - Extract field name + implicit constraint.
231
- - Output bảng VR theo format template:
232
- - **Type**: semantic (`string`, `email`, `enum<A|B|C>`, …) — không bao giờ concrete tech type.
233
- - **Rule**: human-readable diễn đạt, không regex.
234
- - **Refs**: trỏ tới US/AC source.
235
- - Sub-rule phức tạp (vd: password = letter + digit + symbol) → tách flat thành nhiều ID.
236
-
237
- #### 5.3 Propose & approve
238
- Hiển thị bảng VR đề xuất:
239
-
240
- ```
241
- Proposed Verification Rules for F-001:
242
-
243
- | ID | Field | Type | Required | Rule | Refs |
244
- |----|-------|------|----------|------|------|
245
- | VR-F001-001 | email | email | yes | định dạng email hợp lệ | US-F001-001 |
246
- | VR-F001-002 | password | string | yes | tối thiểu 8 ký tự | US-F001-001 |
247
- ...
248
-
249
- Apply? (yes / edit / skip-vr)
250
- yes → insert vào frd.md
251
- edit → user trả lời text-edit rules nào cần sửa
252
- skip-vr → giữ FRD không có VR section
253
- ```
254
-
255
- #### 5.4 Insert
256
- - Insert `## Verification Rules` section ngay trước `## Scope` (theo thứ tự template).
257
- - Copy nguyên block intro + quy ước từ template, chỉ replace bảng bằng nội dung derived.
258
-
259
- ---
260
-
261
- ### Bước 6: V8 — Derive User Flows section
262
-
263
- **Run nếu V8 detected. Bắt buộc — không có option skip.** Propose-then-approve giống V6 nhưng loop cho tới khi user approve: model derive draft, user duyệt (yes) hoặc trả phản hồi (edit) → model regenerate. FRD migration chỉ hoàn tất khi `## User Flows` đã insert.
264
-
265
- #### 6.1 Load minimal context
266
- - Section `## Overview` của FRD (framing scope + actors).
267
- - Section `## User Stories` (đã chứa AC — source của journey steps).
268
-
269
- **KHÔNG load:** code, fdd.md, tech.md, sequence diagrams hiện có. Mục đích: flow ở frd là **user-facing journey** (WHAT), không phải implementation sequence (HOW thuộc fdd).
270
-
271
- #### 6.2 Derive flows
272
- Nhóm User Stories theo journey logic, mỗi journey → 1 Mermaid flowchart:
273
-
274
- - **Grouping rule:** US chia sẻ chung trigger / actor / postcondition → cùng 1 flow. Vd `US-001 Đăng ký` + `US-002 Xác thực email` → 1 flow "Onboarding"; còn `US-003 Reset password` là journey riêng.
275
- - **Mermaid structure:**
276
- - Start node = trigger (user action mở đầu, từ Given của AC đầu tiên).
277
- - Decision nodes = branch từ AC (happy / error paths).
278
- - End node = postcondition (từ Then của AC cuối).
279
- - Edge label = user action hoặc system response (từ When / Then).
280
- - **Naming:** `Flow {N}: {tên ngắn}` — N đánh số từ 1 theo thứ tự xuất hiện trong frd.
281
- - **Mermaid syntax:** dùng `["..."]` chứ KHÔNG `[{...}]` (V1 convention).
282
-
283
- #### 6.3 Propose & approve
284
-
285
- Hiển thị draft full mermaid blocks (chưa ghi file):
286
-
287
- ```
288
- Proposed User Flows for F-001:
289
-
290
- Flow 1: Onboarding (đăng ký + xác thực email)
291
- Spans: US-F001-001, US-F001-002
292
- ```mermaid
293
- flowchart TD
294
- A["User mở trang Sign up"] --> B["Nhập email + password"]
295
- B --> C{"Validation pass?"}
296
- C -->|yes| D["Gửi email xác thực"]
297
- C -->|no| E["Hiển thị lỗi"]
298
- D --> F["User click link trong email"]
299
- F --> G["Account active"]
300
- ```
301
-
302
- Flow 2: Login
303
- Spans: US-F001-003
304
- ```mermaid
305
- ...
306
- ```
307
-
308
- Apply? (yes / edit)
309
- yes → insert vào frd.md
310
- edit → user góp ý flow nào cần sửa (vd: "Flow 1 thiếu nhánh email đã tồn tại") → regenerate draft, loop lại
311
-
312
- User Flows là **bắt buộc** — không có option skip. Nếu user muốn dừng toàn bộ migration cho feature này, dùng "skip-feature" ở Bước 4 hoặc abort skill (Ctrl-C) trước khi V8 chạy.
313
- ```
314
-
315
- #### 6.4 Insert
316
- - Insert section `## User Flows` ngay sau `## Overview` (theo thứ tự template).
317
- - Copy intro + **Flow numbering stable** note (V2 convention) từ template, sau đó list các Mermaid blocks theo flow numbering.
318
-
319
- ---
320
-
321
- ### Bước 7: Validate
322
-
323
- Sau khi apply hết vectors cho một FRD, chạy check:
324
-
325
- - [ ] `## Feature Acceptance Criteria` (không phải Feature-**level**)
326
- - [ ] Không còn ID `AC-F{NNN}-` trong scope Feature AC (chỉ có `FAC-F{NNN}-`)
327
- - [ ] Story AC vẫn dùng `AC-F{NNN}-` (không bị remap nhầm)
328
- - [ ] Mermaid blocks không còn pattern `[{...}]`
329
- - [ ] Có heading `## Verification Rules` (nếu V6 applied)
330
- - [ ] Có heading `## User Flows` với ít nhất 1 Mermaid flowchart (bắt buộc — nếu V8 detected mà section vẫn vắng thì migration chưa hoàn tất)
331
- - [ ] VR Rule column không chứa keyword UI copy: "error message", "vui lòng", "hint", "tooltip"
332
- - [ ] Frontmatter `referenced_by` trỏ tới `3.3 Feature level` (không phải `3.2`)
333
-
334
- Nếu check fail → rollback bằng `git checkout -- {file}` (skill không tạo backup vật lý vì git history đã đảm nhận vai trò này). Yêu cầu working tree clean trước khi chạy skill — nếu dirty, skill báo lỗi và dừng để tránh trộn lẫn change của user với change của migration.
335
-
336
- ---
337
-
338
- ### Bước 8: Report + changelog
339
-
340
- Cho mỗi FRD đã migrate:
341
-
342
- ```
343
- ✓ F-001 — auth
344
- Vectors applied: V1, V3, V4 (3 IDs remapped), V5, V6 (8 VRs added), V8 (2 flows added)
345
- Cascade: fdd.md (3 refs), tsd.md (5 refs), integrations/003 (3 refs)
346
-
347
- ✓ F-002 — checkout
348
- Vectors applied: V5, V6 (5 VRs added)
349
- ```
350
-
351
- **Change History append:** Cho mỗi FRD vừa migrate (và mỗi cascade target `fdd.md`/`tsd.md` bị touched), append entry vào section `## Change History` theo `conventions.md` §5.5:
352
-
353
- ```markdown
354
- ### {YYYY-MM-DD} — manual — update
355
-
356
- - **Migration**: applied vectors V1, V3, V4 (3 IDs remapped: AC-F001-001→FAC-F001-001, ...), V5, V6 (8 VRs added), V8 (2 flows added) qua /spec-frd-update
357
- ```
358
-
359
- Nếu artifact chưa có section `## Change History` (vì template cũ) → tạo section mới ở cuối file rồi append entry. Đây cũng là một migration vector ngầm — đảm bảo mọi main artifact sau migration đều có Change History section.
360
-
361
- Rollback (nếu user phát hiện sai sau khi skill xong): `git checkout -- .specs/main/feature/{F-XXX}-{slug}/` để revert toàn bộ feature dir, hoặc `git restore -p` để revert per-hunk.
362
-
363
- Append vào [changelogs.md](../../changelogs.md) `## [Unreleased]`:
364
-
365
- ```
366
- - chore: migrate frd.md format cho {N} features (vectors: ...)
367
- ```
368
-
369
- ---
370
-
371
- ## Common Rationalizations
372
-
373
- | Rationalization | Reality |
374
- |---|---|
375
- | "Format mới optional, frd cũ vẫn dùng được" | Đúng cho đọc thủ công. Nhưng `/spec-test` và `/spec-tsd` derive TC theo IDs FAC/VR — frd thiếu sẽ break derivation, fallback bằng placeholder không trace được. |
376
- | "Tự sinh VR an toàn, model giỏi infer constraint" | Model dễ bịa rule không có trong AC ("password tối thiểu 12 ký tự" khi AC chỉ nói "password hợp lệ"). Luôn propose-then-approve, không auto-apply. |
377
- | "Skip cascade, chỉ rename trong frd thôi" | Sẽ break tsd.md Traceability Matrix và test.md Coverage. Hoặc cascade full, hoặc skip V4 toàn bộ. |
378
- | "Migrate batch tất cả cùng lúc cho nhanh" | V4 cascade dễ break — user cần xem diff per-feature. Batch mode chỉ áp dụng cho V1, V2, V3, V5, V7 (mechanical, low risk). V6 và V8 phải propose-then-approve. |
379
-
380
- ## Red Flags
381
-
382
- - Apply V4 không có dry-run preview → user không kịp catch cascade reference sai.
383
- - VR Rule column chứa regex `^[a-z]+$` hoặc tech type `varchar(255)` — đó là HOW, sai vị trí.
384
- - V8 flows auto-apply không qua propose-then-approve → model có thể bịa glue step / sai journey grouping mà BA không kịp catch.
385
- - V8 flow chứa step không trace được lên US nào (model bịa) → BA reject draft và yêu cầu regenerate.
386
- - Để FRD không có `## User Flows` sau migration vì "draft chưa ổn" → sai. V8 bắt buộc; nếu draft chưa ổn, dùng `edit` loop cho tới khi approve. FRD không có User Flows = migration chưa hoàn tất.
387
- - V8 Mermaid block dùng syntax `[{...}]` thay vì `["..."]` — vi phạm V1 convention.
388
- - Validate fail nhưng skip rollback → file ở trạng thái nửa migrate, khó debug sau.
389
- - Load conventions.md hoặc source code "for safety" → contamination, tốn context, không cải thiện output.
390
-
391
- ## Verification
392
-
393
- Trước khi mark feature done:
394
- - [ ] Tất cả vectors detected đã apply (hoặc skip có log lý do — riêng V8 KHÔNG được skip)
395
- - [ ] Validate Bước 6 pass
396
- - [ ] Working tree clean trước khi skill chạy (git status verified) — rollback dùng git, không có file backup
397
- - [ ] Cascade ID đã re-grep và confirm 0 false-positive
398
- - [ ] User confirm VR proposal nếu V6 applied