spec-lite 1.2.2 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-lite",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "Spec-driven development kit for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -266,6 +266,10 @@ Brownfield init hoàn tất! Main artifacts:
266
266
  ├── component/ ({N} components, mỗi cái có crd.md + cdd.md)
267
267
  └── feature/ ({N} features, mỗi cái có frd.md + fdd.md)
268
268
 
269
+ Bước tiếp theo (tùy chọn):
270
+ /spec-tsd [F-XXX] → bootstrap tsd.md (Test Spec Document) cho từng feature
271
+ — derive 1:1 từ frd.md, có test coverage tracking từ ngày 1.
272
+
269
273
  Để bắt đầu implement, dùng /spec-new để tạo integration đầu tiên.
270
274
  grep "NEEDS_CLARIFY" để tìm và fill in khi có thêm context.
271
275
  ```
@@ -0,0 +1,310 @@
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) | Insert section placeholder với `<!-- TODO: BA fill in flows -->`. **KHÔNG tự sinh flow.** | None |
56
+
57
+ ---
58
+
59
+ ## Process
60
+
61
+ ### Bước 1: Discover & classify
62
+
63
+ Quét `specs/main/feature/*/frd.md`. Với mỗi file:
64
+
65
+ 1. Parse headings và frontmatter.
66
+ 2. Run detection cho V1–V8.
67
+ 3. Build classification table.
68
+
69
+ Display kết quả:
70
+
71
+ ```
72
+ Detected FRDs:
73
+
74
+ [1] F-001 — auth | Era: 2026-04 | Vectors needed: V1, V3, V4 (3 IDs), V5, V6
75
+ [2] F-002 — checkout | Era: 2026-05 | Vectors needed: V5, V6
76
+ [3] F-003 — refund | Era: current | Vectors needed: — (đã clean)
77
+ [4] F-004 — admin-panel | Era: pre-flows | Vectors needed: V1, V3, V4 (2 IDs), V5, V6, V7, V8
78
+
79
+ Tổng: 4 FRDs · 3 cần migration · 1 đã sạch.
80
+ ```
81
+
82
+ Hỏi user scope:
83
+
84
+ ```
85
+ Migrate FRDs nào?
86
+ [A] Tất cả cần migration (3 files)
87
+ [1] Chỉ F-001
88
+ [2] Chỉ F-002
89
+ ...
90
+ [N] Chọn subset (nhập danh sách số, vd: "1 4")
91
+ [X] Hủy
92
+
93
+ Lựa chọn:
94
+ ```
95
+
96
+ 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.
97
+
98
+ ---
99
+
100
+ ### Bước 2: Load context per FRD
101
+
102
+ 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):
103
+
104
+ | File | Bắt buộc | Mục đích |
105
+ |---|---|---|
106
+ | `specs/main/feature/{F-XXX}-{slug}/frd.md` | ✓ | File cần migrate |
107
+ | [templates/main/feature/frd-template.md](../../templates/main/feature/frd-template.md) | ✓ | Target structure — copy text cho V2/V3/V5 |
108
+ | `specs/main/feature/{F-XXX}-{slug}/fdd.md` | nếu tồn tại | Cascade target cho V4 (AC→FAC rename) |
109
+ | `specs/main/feature/{F-XXX}-{slug}/tsd.md` | nếu tồn tại | Cascade target cho V4 |
110
+ | `specs/main/domain.md` (Shared Entities block) | optional | Cho V6 — match field name với entity glossary để pick semantic type consistent |
111
+
112
+ **KHÔNG load:**
113
+ - `conventions.md` — template đã self-contained, load là thừa
114
+ - Source code — frd là WHAT, derive VR từ US/AC chứ không phải implementation
115
+ - `tech.md`/`cdd.md` — có thể contaminate VR bằng tech detail (regex, varchar(255)…)
116
+
117
+ ---
118
+
119
+ ### Bước 3: Apply mechanical vectors (V1, V2, V3, V5, V7, V8)
120
+
121
+ Đây là các vector **không cần model reasoning** — pure text manipulation. Apply tuần tự, không hỏi user.
122
+
123
+ #### V1 — Mermaid syntax fix
124
+ - Regex trong mỗi code block ```mermaid: `\[\{([^}]+)\}\]` → `["$1"]`
125
+ - Edge case: keep escaped braces nguyên vẹn, chỉ replace pattern `[{...}]` ở edge label / node label.
126
+
127
+ #### V2 — Flow stability note
128
+ - Sau bullet intro của `## User Flows` (dòng `{Mỗi flow là một Mermaid…}`), insert:
129
+ > 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).
130
+
131
+ #### V3 — Section rename + structure
132
+ - Rename heading `## Feature-level Acceptance Criteria` → `## Feature Acceptance Criteria`.
133
+ - 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.
134
+
135
+ #### V5 — US/AC stability notes
136
+ - Sau dòng `US ID format: ...` trong User Stories section, đảm bảo có 2 dòng:
137
+ > 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.
138
+ >
139
+ > 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.
140
+
141
+ #### V7 — Components Used relocation
142
+ - Detect `## Components Consumed` section.
143
+ - Cắt nội dung bảng, xóa heading.
144
+ - 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).
145
+
146
+ #### V8 — User Flows placeholder
147
+ - Sau `## Overview`, insert:
148
+ > ## User Flows
149
+ >
150
+ > <!-- TODO: BA fill in flows. KHÔNG tự sinh — flow là decision của product, không derive được từ AC. -->
151
+
152
+ ---
153
+
154
+ ### Bước 4: V4 — AC → FAC renumber với cascade
155
+
156
+ **Đây là vector cao risk nhất.** Mỗi feature làm tuần tự, không batch.
157
+
158
+ #### 4.1 Parse Feature AC IDs
159
+ - Trong section `## Feature Acceptance Criteria` (đã rename ở V3), extract tất cả ID dạng `AC-F{NNN}-{seq}`.
160
+ - List: `[AC-F001-002, AC-F001-005, AC-F001-007]` (gap OK).
161
+
162
+ #### 4.2 Build remap table
163
+ - Cũ → mới: reset counter từ 001, giữ thứ tự xuất hiện.
164
+ - Ví dụ:
165
+ ```
166
+ AC-F001-002 → FAC-F001-001
167
+ AC-F001-005 → FAC-F001-002
168
+ AC-F001-007 → FAC-F001-003
169
+ ```
170
+
171
+ #### 4.3 Scan cascade references
172
+ - Grep toàn `specs/` cho từng ID cũ.
173
+ - **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.
174
+ - Tạo bảng impact:
175
+ ```
176
+ Cascade impact for F-001:
177
+ feature/F-001-auth/fdd.md 3 refs
178
+ feature/F-001-auth/tsd.md 5 refs
179
+ integrations/003-otp-flow/spec.md 1 ref
180
+ integrations/003-otp-flow/test.md 2 refs
181
+ ```
182
+
183
+ #### 4.4 Dry-run preview
184
+ Hiển thị:
185
+ - Full remap table
186
+ - Per-file diff snippet (3 dòng context mỗi ref)
187
+ - Confirm prompt:
188
+
189
+ ```
190
+ Apply remap cho F-001? (yes / no / skip-feature)
191
+ yes → apply tất cả changes (frd.md + cascade files)
192
+ no → hủy V4 cho feature này, vẫn giữ AC-F prefix
193
+ skip-feature → bỏ qua toàn bộ migration cho F-001
194
+ ```
195
+
196
+ #### 4.5 Apply
197
+ - Edit `frd.md`: rewrite IDs trong section Feature AC.
198
+ - Edit từng cascade file: replace exact ID strings (sử dụng Edit với context dòng để tránh false-positive).
199
+ - Validate: re-grep ID cũ, phải về 0 trong Feature AC scope; Story AC giữ nguyên.
200
+
201
+ ---
202
+
203
+ ### Bước 5: V6 — Generate Verification Rules section
204
+
205
+ **Vector tiêu tốn LLM nhất.** Run nếu V6 detected.
206
+
207
+ #### 5.1 Load minimal context
208
+ - Section `## User Stories` của FRD đó (đã chứa AC).
209
+ - Optional: `domain.md > Shared Entities` block (nếu có field match entity name).
210
+
211
+ **KHÔNG load:** code, fdd.md, tech.md. Mục đích: tránh contamination bằng HOW.
212
+
213
+ #### 5.2 Derive rules
214
+ Quét từng AC trong User Stories:
215
+ - Identify input action ("nhập email", "submit form", "chọn date", "upload file"…).
216
+ - Extract field name + implicit constraint.
217
+ - Output bảng VR theo format template:
218
+ - **Type**: semantic (`string`, `email`, `enum<A|B|C>`, …) — không bao giờ concrete tech type.
219
+ - **Rule**: human-readable diễn đạt, không regex.
220
+ - **Refs**: trỏ tới US/AC source.
221
+ - Sub-rule phức tạp (vd: password = letter + digit + symbol) → tách flat thành nhiều ID.
222
+
223
+ #### 5.3 Propose & approve
224
+ Hiển thị bảng VR đề xuất:
225
+
226
+ ```
227
+ Proposed Verification Rules for F-001:
228
+
229
+ | ID | Field | Type | Required | Rule | Refs |
230
+ |----|-------|------|----------|------|------|
231
+ | VR-F001-001 | email | email | yes | định dạng email hợp lệ | US-F001-001 |
232
+ | VR-F001-002 | password | string | yes | tối thiểu 8 ký tự | US-F001-001 |
233
+ ...
234
+
235
+ Apply? (yes / edit / skip-vr)
236
+ yes → insert vào frd.md
237
+ edit → user trả lời text-edit rules nào cần sửa
238
+ skip-vr → giữ FRD không có VR section
239
+ ```
240
+
241
+ #### 5.4 Insert
242
+ - Insert `## Verification Rules` section ngay trước `## Scope` (theo thứ tự template).
243
+ - Copy nguyên block intro + quy ước từ template, chỉ replace bảng bằng nội dung derived.
244
+
245
+ ---
246
+
247
+ ### Bước 6: Validate
248
+
249
+ Sau khi apply hết vectors cho một FRD, chạy check:
250
+
251
+ - [ ] `## Feature Acceptance Criteria` (không phải Feature-**level**)
252
+ - [ ] Không còn ID `AC-F{NNN}-` trong scope Feature AC (chỉ có `FAC-F{NNN}-`)
253
+ - [ ] Story AC vẫn dùng `AC-F{NNN}-` (không bị remap nhầm)
254
+ - [ ] Mermaid blocks không còn pattern `[{...}]`
255
+ - [ ] Có heading `## Verification Rules` (nếu V6 applied)
256
+ - [ ] VR Rule column không chứa keyword UI copy: "error message", "vui lòng", "hint", "tooltip"
257
+ - [ ] Frontmatter `referenced_by` trỏ tới `3.3 Feature level` (không phải `3.2`)
258
+
259
+ Nếu check fail → rollback bằng cách restore từ backup `.bak.{timestamp}` (skill tạo backup trước khi modify mỗi file).
260
+
261
+ ---
262
+
263
+ ### Bước 7: Report + changelog
264
+
265
+ Cho mỗi FRD đã migrate:
266
+
267
+ ```
268
+ ✓ F-001 — auth
269
+ Vectors applied: V1, V3, V4 (3 IDs remapped), V5, V6 (8 VRs added)
270
+ Cascade: fdd.md (3 refs), tsd.md (5 refs), integrations/003 (3 refs)
271
+ Backup: frd.md.bak.20260519-1430
272
+
273
+ ✓ F-002 — checkout
274
+ Vectors applied: V5, V6 (5 VRs added)
275
+ Backup: frd.md.bak.20260519-1430
276
+ ```
277
+
278
+ Append vào [changelogs.md](../../changelogs.md) `## [Unreleased]`:
279
+
280
+ ```
281
+ - chore: migrate frd.md format cho {N} features (vectors: ...)
282
+ ```
283
+
284
+ ---
285
+
286
+ ## Common Rationalizations
287
+
288
+ | Rationalization | Reality |
289
+ |---|---|
290
+ | "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. |
291
+ | "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. |
292
+ | "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ộ. |
293
+ | "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-V3, V5, V7, V8 (mechanical, low risk). |
294
+
295
+ ## Red Flags
296
+
297
+ - Apply V4 không có dry-run preview → user không kịp catch cascade reference sai.
298
+ - VR Rule column chứa regex `^[a-z]+$` hoặc tech type `varchar(255)` — đó là HOW, sai vị trí.
299
+ - V8 placeholder bị fill nội dung tự sinh (model bịa flow) — flow là decision của product.
300
+ - Validate fail nhưng skip rollback → file ở trạng thái nửa migrate, khó debug sau.
301
+ - Load conventions.md hoặc source code "for safety" → contamination, tốn context, không cải thiện output.
302
+
303
+ ## Verification
304
+
305
+ Trước khi mark feature done:
306
+ - [ ] Tất cả vectors detected đã apply (hoặc skip có log lý do)
307
+ - [ ] Validate Bước 6 pass
308
+ - [ ] Backup `.bak.{timestamp}` còn nguyên
309
+ - [ ] Cascade ID đã re-grep và confirm 0 false-positive
310
+ - [ ] User confirm VR proposal nếu V6 applied