spec-lite 1.3.2 → 1.4.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.
package/README.md CHANGED
@@ -51,6 +51,9 @@ Scan codebase để extract main artifacts, sau đó vào Integration Pipeline.
51
51
  /spec-brownfield-feature
52
52
 
53
53
 
54
+ /spec-tsd [F-XXX] (tùy chọn — bootstrap tsd.md cho từng feature)
55
+
56
+
54
57
  (fill in NEEDS_CLARIFY khi có thêm context)
55
58
 
56
59
 
@@ -66,6 +69,9 @@ Scan module dirs, tạo `crd.md` + `cdd.md` cho từng component, điền Compon
66
69
  #### `/spec-brownfield-feature [path]`
67
70
  Scan routes/use cases/tests, tạo `frd.md` + `fdd.md` cho từng feature, điền Feature Index vào `prd.md`. Yêu cầu `component` đã chạy (fdd.md cần C-XXX IDs từ Component Index).
68
71
 
72
+ #### `/spec-tsd [F-XXX]`
73
+ Bootstrap `feature/{F-XXX}/tsd.md` (Test Spec Document) trực tiếp từ `frd.md` — mechanical derive Test Scenarios + Test Cases (mỗi Flow → TS, mỗi US/AC → Functional TC, mỗi VR → ≥1 positive + 1+ negative, mỗi FAC → Feature AC TC). Không interview, không cần integration. Dùng sau `/spec-brownfield-feature` để có test coverage tracking từ ngày 1, hoặc khi tsd drift khỏi frd cần regenerate fresh.
74
+
69
75
  > **NEEDS_CLARIFY:** Các mục chưa rõ khi scan được đánh dấu `[NEEDS_CLARIFY]` — không block workflow, fill in dần khi có thêm context.
70
76
 
71
77
  ---
@@ -78,17 +84,21 @@ Mỗi requirement mới đều đi qua pipeline này.
78
84
  /spec-new [requirement]
79
85
  (human review + apply cascade proposals + approve)
80
86
 
81
- /spec-tech
82
- (human review + apply cascade proposals + approve)
83
-
84
- /plan
85
- (human approve)
86
-
87
- /build ◄──────────────┐
88
-
89
- /review-integration │ (nếu Critical/Important → sửa và build lại)
90
-
91
- [approve] ───────────┘ (nếu chỉ Suggestion hoặc không có finding)
87
+ ├─────────────────┐
88
+ ▼ ▼
89
+ /spec-tech /spec-test (song song — cả hai chỉ phụ thuộc spec.md)
90
+ (DEV approve) (QC approve, cascade lên feature/*/tsd.md)
91
+ │ │
92
+ └────────┬────────┘
93
+
94
+ /plan
95
+ (human approve)
96
+
97
+ /build ◄──────────────┐
98
+ │ │
99
+ /review-integration │ (nếu Critical/Important → sửa và build lại)
100
+ │ │
101
+ [approve] ───────────┘ (nếu chỉ Suggestion hoặc không có finding)
92
102
  ```
93
103
 
94
104
  #### `/spec-new [requirement]`
@@ -98,11 +108,14 @@ Tạo `specs/integrations/{slug}/spec.md` cho một integration mới.
98
108
  - Không có argument → hiển thị danh sách features TODO từ `prd.md` để chọn
99
109
 
100
110
  #### `/spec-tech [number]`
101
- Tạo `specs/integrations/{slug}/tech.md` sau khi `spec.md` được approve.
111
+ Tạo `specs/integrations/{slug}/tech.md` sau khi `spec.md` được approve. Chạy bởi **DEV**.
102
112
 
103
113
  - Có argument → chọn integration theo số thứ tự luôn
104
114
  - Không có argument → hiển thị danh sách tất cả integrations
105
115
 
116
+ #### `/spec-test [number]`
117
+ Tạo `specs/integrations/{slug}/test.md` sau khi `spec.md` được approve. Chạy bởi **QC**, **song song / độc lập** với `/spec-tech` — cả hai chỉ phụ thuộc `spec.md`. Mechanical derive Test Scenarios + Test Cases từ frd.md (Flow → TS, US/AC → Functional TC, VR → positive + negative, FAC → Feature AC TC), priority deterministic. Cascade lên `feature/{F-XXX}/tsd.md` qua Changes blocks. Gate: integration phải có `features:` non-empty (component-thuần không áp dụng).
118
+
106
119
  #### `/plan`
107
120
  Tạo `plan.md` và `todo.md` từ `spec.md` + `tech.md`.
108
121
 
@@ -122,6 +135,17 @@ Sau khi có findings, hỏi user severity tier muốn xử lý (Critical / Criti
122
135
 
123
136
  ---
124
137
 
138
+ ## Maintenance — migrate artifacts khi template thay đổi
139
+
140
+ Skill ad-hoc dùng khi template đã được update và artifacts hiện có cần migrate. Không phải pipeline — chạy khi cần.
141
+
142
+ #### `/spec-frd-update`
143
+ Migrate `feature/*/frd.md` hiện có sang format mới nhất của [frd-template.md](.claude/templates/main/feature/frd-template.md). Detect 8 migration vectors: fix Mermaid syntax `[{...}]` → `["..."]`, rename `Feature-level AC` → `Feature AC` với 4 nhóm chuẩn, rename `AC-F{NNN}-*` (Feature AC) → `FAC-F{NNN}-*` + cascade ID remap qua `fdd.md`/`tsd.md`/`integrations/*/{spec,tech,test}.md`, insert US/AC stability notes + Verification Rules, derive Mermaid User Flows từ User Stories, v.v.
144
+
145
+ Pre-flight yêu cầu git working tree clean — rollback dùng `git checkout -- {file}`, **không** tạo file `.bak`. V4 (FAC remap), V6 (Verification Rules propose), V8 (User Flows propose) đều có confirm step trước khi ghi. No-op safe: nếu mọi FRD đã clean, skill dừng mà không ghi gì.
146
+
147
+ ---
148
+
125
149
  ## Files được tạo ra
126
150
 
127
151
  | Command | Output |
@@ -131,8 +155,11 @@ Sau khi có findings, hỏi user severity tier muốn xử lý (Critical / Criti
131
155
  | `/spec-brownfield-init` | `specs/main/prd.md`, `specs/main/domain.md`, `specs/main/sad.md` |
132
156
  | `/spec-brownfield-component` | `specs/main/component/{C-XXX}-*/crd.md + cdd.md` |
133
157
  | `/spec-brownfield-feature` | `specs/main/feature/{F-XXX}-*/frd.md + fdd.md` |
158
+ | `/spec-tsd` | `specs/main/feature/{F-XXX}-*/tsd.md` |
159
+ | `/spec-frd-update` | *(modify in-place `feature/*/frd.md` + cascade refs)* |
134
160
  | `/spec-new` | `specs/integrations/{slug}/spec.md` |
135
161
  | `/spec-tech` | `specs/integrations/{slug}/tech.md` |
162
+ | `/spec-test` | `specs/integrations/{slug}/test.md`, cascade: `feature/{F-XXX}/tsd.md` |
136
163
  | `/plan` | `specs/integrations/{slug}/plan.md`, `todo.md` |
137
164
  | `/build` | *(implements tasks từ `plan.md`/`todo.md`)* |
138
165
  | `/review-integration` | *(findings report — không tạo file)* |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-lite",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Spec-driven development kit for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -123,7 +123,7 @@ Dùng `.claude/templates/integrations/plan-template.md` làm skeleton, điền n
123
123
  **Lưu ý format:**
124
124
  - Task ID dùng `·` (middle dot), không dùng `—`
125
125
  - `**Các bước:**` là numbered list, đủ cụ thể để agent implement không cần đoán
126
- - `**Verification:**` là checklist `- [ ]`, gắn AC ID khi
126
+ - `**Verification:**` là checklist `- [ ]` test case hoặc observable result cụ thể
127
127
  - `**depends:**` luôn có, dùng `—` nếu không có dependency
128
128
 
129
129
  ### todo.md
@@ -191,7 +191,16 @@ Các entities sau được dùng bởi nhiều components.
191
191
  Apply cascade proposals vào domain.md? [y/n/edit]
192
192
  ```
193
193
 
194
- Nếu `y` → update `specs/main/domain.md` Shared Entities section.
194
+ Nếu `y` → update `specs/main/domain.md` Shared Entities section, đồng thời append entry vào `## Change History` của domain.md (theo `conventions.md` §5.5):
195
+
196
+ ```markdown
197
+ ### {YYYY-MM-DD} — manual — update
198
+
199
+ - **Shared Entities**:
200
+ - [NEW] Order — owner C-003-payment, used by inventory (detected từ /spec-brownfield-component scan)
201
+ - [NEW] User — owner C-001-auth, used by user/notification
202
+ ```
203
+
195
204
  Nếu `edit` → hỏi chỉnh sửa từng entity trước khi apply.
196
205
 
197
206
  ---
@@ -212,6 +221,14 @@ Ghi tất cả? [y] hoặc review từng file trước [r]:
212
221
  - `y` → ghi tất cả
213
222
  - `r` → hiển thị lần lượt từng file, user confirm / skip / edit từng cái
214
223
 
224
+ **Change History:** Append entry vào section `## Change History` cuối mỗi `crd.md`/`cdd.md` vừa ghi (theo `conventions.md` §5.5):
225
+
226
+ ```markdown
227
+ ### {YYYY-MM-DD} — manual — create
228
+
229
+ - **All sections**: initial brownfield scaffold qua /spec-brownfield-component (discovered từ code scan)
230
+ ```
231
+
215
232
  ---
216
233
 
217
234
  ### Bước 10: Điền Component Index vào prd.md + sad.md Components table
@@ -238,6 +255,18 @@ Apply? [y/n]
238
255
 
239
256
  Cột architectural notes trong sad.md nên ngắn gọn — tập trung vào boundary/deployment/key tech concern, không lặp lại business role từ prd.md.
240
257
 
258
+ Khi apply → đồng thời append entry vào `## Change History` của prd.md và sad.md (theo `conventions.md` §5.5):
259
+
260
+ ```markdown
261
+ ### {YYYY-MM-DD} — manual — update
262
+
263
+ - **Components**:
264
+ - [NEW] C-001 — auth (discovered từ /spec-brownfield-component scan)
265
+ - [NEW] C-002 — user
266
+ - [NEW] C-003 — payment
267
+ - [NEW] C-004 — notification
268
+ ```
269
+
241
270
  ---
242
271
 
243
272
  ### Bước 11: Summary
@@ -225,6 +225,14 @@ Sẽ tạo {N} features ({2N} files):
225
225
  Ghi tất cả? [y] hoặc review từng file trước [r]:
226
226
  ```
227
227
 
228
+ **Change History:** Append entry vào section `## Change History` cuối mỗi `frd.md`/`fdd.md` vừa ghi (theo `conventions.md` §5.5):
229
+
230
+ ```markdown
231
+ ### {YYYY-MM-DD} — manual — create
232
+
233
+ - **All sections**: initial brownfield scaffold qua /spec-brownfield-feature (discovered từ code scan)
234
+ ```
235
+
228
236
  ---
229
237
 
230
238
  ### Bước 8: Điền Feature Index vào prd.md
@@ -241,6 +249,18 @@ Sẽ điền Feature Index vào prd.md:
241
249
  Apply? [y/n]
242
250
  ```
243
251
 
252
+ Khi apply → đồng thời append entry vào `## Change History` của prd.md (theo `conventions.md` §5.5):
253
+
254
+ ```markdown
255
+ ### {YYYY-MM-DD} — manual — update
256
+
257
+ - **Features**:
258
+ - [NEW] F-001 — user-registration (discovered từ /spec-brownfield-feature scan)
259
+ - [NEW] F-002 — authentication
260
+ - [NEW] F-003 — checkout-flow
261
+ - [NEW] F-004 — order-history
262
+ ```
263
+
244
264
  ---
245
265
 
246
266
  ### Bước 9: Summary
@@ -272,6 +272,14 @@ Confirm? [y] Bỏ qua [n] Chỉnh sửa [e]:
272
272
 
273
273
  Tạo `specs/main/` nếu chưa có. Ghi các files đã được confirm.
274
274
 
275
+ **Change History:** Append entry vào section `## Change History` cuối mỗi file vừa ghi (`prd.md`, `domain.md`, `sad.md`) theo `conventions.md` §5.5:
276
+
277
+ ```markdown
278
+ ### {YYYY-MM-DD} — manual — create
279
+
280
+ - **All sections**: initial brownfield scaffold qua /spec-brownfield-init (scan codebase + interview)
281
+ ```
282
+
275
283
  ```
276
284
  ✓ specs/main/prd.md (Component Index và Feature Index: placeholder — chưa có)
277
285
  ✓ specs/main/domain.md (Glossary: {n} terms | Shared Entities: trống — sẽ mọc qua cascade)
@@ -52,7 +52,7 @@ Skill detect từng frd hiện tại thuộc "era" nào và apply vectors tươn
52
52
  | **V5 US/AC stability notes** | Section User Stories thiếu chuỗi "ID stable" | Insert 2 dòng note | None |
53
53
  | **V6 VR section** | Không có heading `## Verification Rules` | Propose VR table từ User Stories → user approve → insert | Medium |
54
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. | Medium |
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
56
 
57
57
  ---
58
58
 
@@ -260,7 +260,7 @@ Apply? (yes / edit / skip-vr)
260
260
 
261
261
  ### Bước 6: V8 — Derive User Flows section
262
262
 
263
- **Run nếu V8 detected.** Propose-then-approve giống V6 model derive draft, user duyệt trước khi ghi.
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
264
 
265
265
  #### 6.1 Load minimal context
266
266
  - Section `## Overview` của FRD (framing scope + actors).
@@ -305,10 +305,11 @@ Flow 2: Login
305
305
  ...
306
306
  ```
307
307
 
308
- Apply? (yes / edit / skip-flows)
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")
311
- skip-flows → giữ FRD không có User Flows section
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.
312
313
  ```
313
314
 
314
315
  #### 6.4 Insert
@@ -326,6 +327,7 @@ Sau khi apply hết vectors cho một FRD, chạy check:
326
327
  - [ ] Story AC vẫn dùng `AC-F{NNN}-` (không bị remap nhầm)
327
328
  - [ ] Mermaid blocks không còn pattern `[{...}]`
328
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)
329
331
  - [ ] VR Rule column không chứa keyword UI copy: "error message", "vui lòng", "hint", "tooltip"
330
332
  - [ ] Frontmatter `referenced_by` trỏ tới `3.3 Feature level` (không phải `3.2`)
331
333
 
@@ -346,6 +348,16 @@ Cho mỗi FRD đã migrate:
346
348
  Vectors applied: V5, V6 (5 VRs added)
347
349
  ```
348
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
+
349
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.
350
362
 
351
363
  Append vào [changelogs.md](../../changelogs.md) `## [Unreleased]`:
@@ -371,6 +383,7 @@ Append vào [changelogs.md](../../changelogs.md) `## [Unreleased]`:
371
383
  - VR Rule column chứa regex `^[a-z]+$` hoặc tech type `varchar(255)` — đó là HOW, sai vị trí.
372
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.
373
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.
374
387
  - V8 Mermaid block dùng syntax `[{...}]` thay vì `["..."]` — vi phạm V1 convention.
375
388
  - Validate fail nhưng skip rollback → file ở trạng thái nửa migrate, khó debug sau.
376
389
  - Load conventions.md hoặc source code "for safety" → contamination, tốn context, không cải thiện output.
@@ -378,7 +391,7 @@ Append vào [changelogs.md](../../changelogs.md) `## [Unreleased]`:
378
391
  ## Verification
379
392
 
380
393
  Trước khi mark feature done:
381
- - [ ] Tất cả vectors detected đã apply (hoặc skip có log lý do)
394
+ - [ ] Tất cả vectors detected đã apply (hoặc skip có log lý do — riêng V8 KHÔNG được skip)
382
395
  - [ ] Validate Bước 6 pass
383
396
  - [ ] Working tree clean trước khi skill chạy (git status verified) — rollback dùng git, không có file backup
384
397
  - [ ] Cascade ID đã re-grep và confirm 0 false-positive
@@ -360,6 +360,30 @@ Cho từng block:
360
360
  - `[REMOVE]` → xóa item khỏi artifact (ID không tái sử dụng — không renumber các ID khác)
361
361
  - Ghi lại artifact
362
362
 
363
+ **[7.2.5] Append Change History entry** vào mỗi main artifact bị touched (theo `conventions.md` §5.5). Đây là phần atomic của auto-apply — nếu fail thì rollback luôn cả entry này.
364
+
365
+ Cho mỗi artifact:
366
+
367
+ 1. Mở file, tìm section `## Change History` (mọi template main đã scaffold sẵn section này — nếu thiếu, append vào cuối file).
368
+ 2. Append entry mới ở cuối section, format:
369
+
370
+ ```markdown
371
+ ### {YYYY-MM-DD} — [{NNN}-{slug}](../../integrations/{NNN}-{slug}/spec.md) — {operation}
372
+
373
+ - **{Section name 1}**:
374
+ - [marker] {ID/item} — {mô tả ngắn 1 dòng}
375
+ - **{Section name 2}**:
376
+ - [marker] {ID/item} — {mô tả ngắn 1 dòng}
377
+ ```
378
+
379
+ - Operation = `create` nếu vừa scaffold artifact mới, `update` nếu apply Changes block lên artifact đã tồn tại.
380
+ - Section name = tên section trong template gốc (`User Stories`, `Verification Rules`, `Components`, `Public Interface`, ...).
381
+ - Mỗi item có marker trong Changes block phải xuất hiện ở entry, không gộp, không bỏ sót.
382
+ - Mô tả ngắn 1 dòng: đủ context để hiểu thay đổi mà không phải mở `spec.md`. Ví dụ tốt: `[NEW] US-F002-005 — Refund order story cho customer`; ví dụ xấu: `[NEW] US-F002-005`.
383
+ - Path link: dùng relative path từ artifact đến `integrations/{NNN}-{slug}/spec.md` (số `../` phụ thuộc depth của artifact: 2 cho prd/domain/sad, 3 cho component/feature artifacts).
384
+
385
+ 3. Với operation=create và artifact được seed từ template trống (không có content từ Changes block) → entry body có thể đơn giản: `- **All sections**: initial scaffold`.
386
+
363
387
  **[7.3] Side-effects bổ sung:**
364
388
 
365
389
  - Nếu integration gắn với feature từ prd.md và prd.md Changes block không tự đổi status → tự động đổi `TODO` → `In Progress` cho feature đó trong prd.md.
@@ -415,4 +439,5 @@ Trước khi user confirm (Bước 6), kiểm tra:
415
439
  Sau khi user confirm (Bước 7):
416
440
 
417
441
  - [ ] Auto-apply chạy theo thứ tự prd → domain → sad → crd → frd
418
- - [ ] Fail-safe: nếu apply fail thì không ghi spec.md
442
+ - [ ] Mỗi artifact bị touched entry mới được append vào `## Change History` (xem `conventions.md` §5.5)
443
+ - [ ] Fail-safe: nếu apply fail thì không ghi spec.md (rollback luôn Change History entries)
@@ -152,6 +152,18 @@ Chỉ ghi file sau khi user confirm. Nếu user yêu cầu chỉnh sửa → c
152
152
 
153
153
  Nếu `domain.md` đã tồn tại với nội dung thực → không đụng tới.
154
154
 
155
+ **5c. Append Change History entry** vào mỗi artifact vừa ghi/scaffold (theo `conventions.md` §5.5):
156
+
157
+ ```markdown
158
+ ### {YYYY-MM-DD} — manual — create
159
+
160
+ - **All sections**: initial scaffold qua /spec-prd
161
+ ```
162
+
163
+ - Áp dụng cho `prd.md` (mỗi lần skill chạy — nếu là lần đầu thì `create`, nếu là update thì `update` và body liệt kê section bị đổi).
164
+ - Áp dụng cho `domain.md` chỉ khi vừa scaffold lần đầu — không đụng nếu đã tồn tại.
165
+ - Operation `update`: liệt kê section đã thay đổi với mô tả ngắn, ví dụ `- **Features**: updated Feature Index từ interview`.
166
+
155
167
  Thông báo kết quả:
156
168
  ```
157
169
  ✓ specs/main/prd.md đã được cập nhật (status: draft)
@@ -169,6 +169,16 @@ Chỉ ghi file sau khi user confirm. Nếu user yêu cầu chỉnh sửa → c
169
169
 
170
170
  Ghi nội dung đã được confirm vào `specs/main/sad.md`.
171
171
 
172
+ **Change History:** Append entry vào section `## Change History` cuối `sad.md` (theo `conventions.md` §5.5):
173
+
174
+ ```markdown
175
+ ### {YYYY-MM-DD} — manual — create
176
+
177
+ - **All sections**: initial scaffold qua /spec-sad
178
+ ```
179
+
180
+ Nếu chạy lần thứ N (sad.md đã có) → operation = `update`, body liệt kê section đã đổi với mô tả ngắn.
181
+
172
182
  Thông báo kết quả:
173
183
  ```
174
184
  ✓ specs/main/sad.md đã được cập nhật (status: draft)
@@ -64,12 +64,7 @@ Nếu `status` **không phải** `approved`:
64
64
 
65
65
  > ⛔ `spec.md` của integration **{slug}** chưa được approve (status hiện tại: `{status}`).
66
66
  >
67
- > Để tiếp tục:
68
- > 1. Review `specs/integrations/{slug}/spec.md`
69
- > 2. Apply Cascade Proposals vào main artifacts (nếu có)
70
- > 3. Đổi `status: draft` → `status: approved` trong frontmatter
71
- >
72
- > Sau khi approve xong, chạy lại `/spec-tech`.
67
+ > `/spec-new` luôn ghi `spec.md` với `status: approved` sau khi auto-cascade thành công. Nếu file đang ở `draft` → có thể `/spec-new` bị fail giữa chừng hoặc user đổi tay status. Chạy lại `/spec-new` cho integration này.
73
68
 
74
69
  **Dừng hoàn toàn. Không tiếp tục.**
75
70
 
@@ -147,7 +142,7 @@ Tổng hợp và viết draft `tech.md`:
147
142
 
148
143
  **Cấu trúc file**: dùng `.claude/templates/integrations/tech-template.md` làm skeleton, điền nội dung từ interview vào.
149
144
 
150
- **Cascade Proposals** — agent đề xuất delta cho main artifacts theo các targets sau (chỉ điền nếu thực sự thay đổi, không thì ghi "Khôngthay đổi đề xuất."):
145
+ **Changes blocks** — agent sinh delta cho main artifacts trong section `## Changes` của tech.md. Mỗi block tương ứng 1 artifact bị touched, declare `Operation: create | update`, content theo format template gốc với markers `[NEW] / [MODIFY {field}] / [REMOVE]` cho operation=update. Đây là phần draft sẽ auto-apply sau khi user confirm — không "manual apply" bước riêng. Targets:
151
146
 
152
147
  ### sad.md
153
148
 
@@ -199,7 +194,8 @@ Liệt kê **tất cả** features liên quan trong frontmatter và đánh giá:
199
194
  - Nếu integration thêm/đổi rule trong FRD → cập nhật bảng Verification Implementation tương ứng
200
195
 
201
196
  Bỏ block fdd.md nếu integration không gắn với feature nào (`features: []`).
202
- ```
197
+
198
+ **Cascade Summary** — sau các Changes blocks, sinh bảng tóm tắt liệt kê tất cả targets (kể cả targets không có block, ghi `no-op`) để reviewer scan nhanh.
203
199
 
204
200
  Hiển thị draft cho user xem — **chưa ghi file**.
205
201
 
@@ -209,27 +205,81 @@ Hiển thị draft cho user xem — **chưa ghi file**.
209
205
 
210
206
  > Draft trên đã đúng chưa?
211
207
  > - Technical Design có đủ để DEV implement không?
212
- > - Cascade Proposals (nếu) cần approve trước khi tiến hành.
208
+ > - Changes blocks đã đúng chưa? Mỗi marker khớp current state của main artifact không?
209
+ > - Guardrails Compliance đã pass?
210
+
211
+ > **Sau khi confirm, agent sẽ auto-apply tất cả Changes blocks lên main artifacts (sad → domain → cdd → fdd).** Không có bước manual apply.
213
212
 
214
213
  Chỉ ghi file sau khi user confirm. Nếu user yêu cầu chỉnh sửa → cập nhật draft → hỏi lại.
215
214
 
216
215
  ---
217
216
 
218
- ### Bước 6: Save
217
+ ### Bước 6: Save + Auto-cascade
218
+
219
+ **[6.1] Ghi `specs/integrations/{slug}/tech.md`** với status `approved` (không phải `draft` — human đã confirm ở Bước 5 chính là approval). Frontmatter `features` và `components` mirror từ `spec.md`.
220
+
221
+ **[6.2] Auto-apply mỗi Changes block** vào main artifact tương ứng. Thứ tự apply (để tránh forward reference): `sad.md` → `domain.md` → `component/*/cdd.md` → `feature/*/fdd.md`.
222
+
223
+ Cho từng block:
224
+
225
+ - **Operation=create:**
226
+ - Tạo file mới tại path tương ứng
227
+ - Nội dung = nội dung của Changes block (theo format của template gốc — `cdd-template.md` hoặc `fdd-template.md`)
228
+ - Frontmatter: lấy từ template (status `draft` cho artifact mới — separate lifecycle với tech.md)
229
+
230
+ - **Operation=update:**
231
+ - Đọc artifact hiện tại
232
+ - Với mỗi item trong Changes block:
233
+ - `[NEW]` → append/insert vào section tương ứng (giữ thứ tự numeric của ID)
234
+ - `[MODIFY {field}]` → tìm item bằng ID, update field đã chỉ định, giữ nguyên các field khác
235
+ - `[REMOVE]` → xóa item khỏi artifact (ID không tái sử dụng — không renumber các ID khác)
236
+ - Ghi lại artifact
237
+
238
+ **[6.2.5] Append Change History entry** vào mỗi main artifact bị touched (theo `conventions.md` §5.5). Đây là phần atomic của auto-apply — nếu fail thì rollback luôn cả entry này.
239
+
240
+ Cho mỗi artifact:
219
241
 
220
- Ghi nội dung đã confirm vào `specs/integrations/{slug}/tech.md`.
242
+ 1. Mở file, tìm section `## Change History` (mọi template main đã scaffold sẵn — nếu thiếu, append vào cuối file).
243
+ 2. Append entry mới ở cuối section, format:
244
+
245
+ ```markdown
246
+ ### {YYYY-MM-DD} — [{NNN}-{slug}](../../integrations/{NNN}-{slug}/tech.md) — {operation}
247
+
248
+ - **{Section name}**:
249
+ - [marker] {ID/item} — {mô tả ngắn 1 dòng}
250
+ ```
251
+
252
+ - Operation = `create` (artifact mới) | `update` (artifact đã tồn tại).
253
+ - Integration link trỏ tới `tech.md` (không phải `spec.md`) — đây là cascade từ tech.
254
+ - Section name = tên section trong template gốc (`Module Structure`, `Storage & Persistence`, `Inter-Component Data Flow`, `Verification Implementation`...).
255
+ - Path link: relative từ artifact đến `integrations/{NNN}-{slug}/tech.md` (số `../` phụ thuộc depth: 2 cho sad/domain, 3 cho component/feature).
256
+ - Mọi item có marker trong Changes block phải xuất hiện ở entry, group theo section.
257
+
258
+ 3. Với operation=create từ template trống → entry body có thể là `- **All sections**: initial scaffold`.
259
+
260
+ **[6.3] Atomic rollback:** Nếu apply block nào fail (vd `[MODIFY {ID}]` nhưng ID không tồn tại):
261
+ 1. Rollback các block đã apply trước đó (kể cả Change History entries) về state ban đầu
262
+ 2. **Không** ghi tech.md
263
+ 3. Báo lỗi cụ thể cho user fix draft hoặc artifact hiện tại
264
+
265
+ **[6.4] Thông báo kết quả:**
221
266
 
222
- Thông báo kết quả:
223
267
  ```
224
- ✓ specs/integrations/{slug}/tech.md đã được tạo (status: draft)
268
+ ✓ specs/integrations/{slug}/tech.md đã được tạo (status: approved)
269
+
270
+ Auto-cascade applied:
271
+ ✓ sad.md — {summary | no-op}
272
+ ✓ domain.md — {summary | no-op}
273
+ ✓ component/C-XXX-{slug}/cdd.md — {created | updated: summary}
274
+ ✓ feature/F-XXX-{slug}/fdd.md — {created | updated: summary}
225
275
 
226
276
  Bước tiếp theo:
227
- - Review tech.md và apply Cascade Proposals (nếu có) vào main artifacts thủ công
228
- - Approve tech.md (đổi status: draft → approved)
229
277
  - /plan → tạo plan.md và todo.md cho integration này
230
278
  - Sau khi tất cả tasks done: đổi status F-XXX trong prd.md thành DONE
231
279
  ```
232
280
 
281
+ **Nếu apply fail** → dừng, báo lỗi cụ thể, **không** ghi tech.md. Yêu cầu user fix draft hoặc check artifact hiện tại.
282
+
233
283
  ---
234
284
 
235
285
  ## Common Rationalizations
@@ -238,21 +288,30 @@ Bước tiếp theo:
238
288
  | --- | --- |
239
289
  | "Tech design thì code xong mới biết được" | Không cần design hoàn hảo, cần đủ để thống nhất approach trước khi viết code. |
240
290
  | "Interface thì ghi sau khi implement xong" | Interface chưa được agree = BA không biết integration làm gì, không thể verify AC. |
241
- | "Cascade Proposals thì sau cập nhật cũng được" | Domain SAD shared context. Cập nhật trễ = các tech.md sau dùng context sai. |
291
+ | "Cascade Proposals thì sau cập nhật cũng được" | Cascade auto-apply atomic với save. Không "sau" confirm draft = cascade chạy ngay. |
242
292
 
243
293
  ## Red Flags
244
294
 
245
295
  - Solution Overview không có lý do chọn approach — chỉ mô tả "sẽ làm X" mà không giải thích tại sao
246
296
  - Interface Changes trống trong khi spec.md có AC về API/response shape
247
297
  - Data Model Changes bỏ qua nhưng spec.md có requirement về data mới
248
- - Cascade Proposals không được review trước khi approve
298
+ - Changes blocks không được review trước khi confirm (cascade auto-apply là irreversible — không có undo)
299
+ - Marker không khớp current state: `[NEW]` cho item đã tồn tại, hoặc `[MODIFY]/[REMOVE]` cho ID không có
249
300
 
250
301
  ## Verification
251
302
 
252
- Trước khi ghi file, kiểm tra:
303
+ Trước khi user confirm (Bước 5), kiểm tra:
253
304
 
254
305
  - [ ] Solution Overview có lý do chọn approach (không chỉ mô tả)
255
306
  - [ ] Mỗi Acceptance Criterion trong spec.md đều được cover bởi design
256
307
  - [ ] Interface Changes đầy đủ method, path, auth requirement (nếu có)
257
- - [ ] Cascade Proposals đã được user review
258
- - [ ] User đã confirm draft trước khi ghi file
308
+ - [ ] Mỗi Changes block Operation rõ ràng (create | update)
309
+ - [ ] Mỗi item trong update block marker đúng ([NEW]/[MODIFY {field}]/[REMOVE])
310
+ - [ ] Guardrails Compliance đã pass cho từng GUARD-XXX
311
+ - [ ] Cascade Summary table khớp với các Changes blocks
312
+
313
+ Sau khi user confirm (Bước 6):
314
+
315
+ - [ ] Auto-apply chạy theo thứ tự sad → domain → cdd → fdd
316
+ - [ ] Mỗi artifact bị touched có entry mới được append vào `## Change History` (conventions §5.5)
317
+ - [ ] Fail-safe: nếu apply fail thì không ghi tech.md (rollback luôn Change History entries)
@@ -304,6 +304,23 @@ Cho từng block:
304
304
  - Cập nhật Traceability Matrix: thêm row cho item mới, update row của item bị MODIFY, KHÔNG xóa row của REMOVE (đánh dấu retire)
305
305
  - Ghi lại tsd.md
306
306
 
307
+ **[6.2.5] Append Change History entry** vào mỗi tsd.md bị touched (theo `conventions.md` §5.5). Đây là phần atomic của auto-apply — nếu fail thì rollback luôn.
308
+
309
+ Format entry:
310
+
311
+ ```markdown
312
+ ### {YYYY-MM-DD} — [{NNN}-{slug}](../../../integrations/{NNN}-{slug}/test.md) — {operation}
313
+
314
+ - **{Section name}**:
315
+ - [marker] {TS/TC ID} — {mô tả ngắn 1 dòng}
316
+ ```
317
+
318
+ - Operation = `create` (tsd.md mới) | `update` (tsd.md đã tồn tại).
319
+ - Integration link trỏ tới `test.md` (không phải `spec.md`) — đây là cascade từ test.
320
+ - Section name = tên section trong template tsd (`Test Scenarios`, `Functional Test Cases`, `Validation Test Cases`, `Feature AC Test Cases`, `Traceability Matrix`...).
321
+ - Mọi TS/TC có marker trong Changes block phải xuất hiện ở entry, group theo section.
322
+ - Với operation=create từ template trống (no Changes block content) → entry body có thể là `- **All sections**: initial scaffold`.
323
+
307
324
  **[6.3] Atomic rollback:** Nếu apply block nào fail (vd `[MODIFY TC-F001-005]` nhưng ID không tồn tại):
308
325
  1. Rollback các block đã apply trước đó về state ban đầu
309
326
  2. **Không** ghi integration test.md
@@ -361,5 +378,6 @@ Trước khi QC confirm (Bước 5), kiểm tra:
361
378
  Sau khi QC confirm (Bước 6):
362
379
 
363
380
  - [ ] Auto-apply theo thứ tự features trong frontmatter
364
- - [ ] Fail-safe: nếu apply fail thì không ghi integration test.md
381
+ - [ ] Mỗi tsd.md bị touched entry mới trong `## Change History` (conventions §5.5)
382
+ - [ ] Fail-safe: nếu apply fail thì không ghi integration test.md (rollback luôn Change History entries)
365
383
  - [ ] Mỗi feature tsd.md mới có status `draft` (separate lifecycle)
@@ -187,6 +187,16 @@ Ghi `specs/main/feature/{F-XXX}-{slug}/tsd.md` với status `draft` (feature-lev
187
187
 
188
188
  Nếu overwrite — file backup `tsd.md.bak.{timestamp}` đã tạo ở Bước 2.
189
189
 
190
+ **Change History:** Append entry vào section `## Change History` cuối tsd.md (theo `conventions.md` §5.5):
191
+
192
+ ```markdown
193
+ ### {YYYY-MM-DD} — manual — create
194
+
195
+ - **All sections**: initial scaffold qua /spec-tsd (mechanical derive từ frd.md — N TS, M Functional TC, P Validation TC, Q Feature AC TC)
196
+ ```
197
+
198
+ Nếu overwrite tsd.md cũ → entry vẫn dùng operation `create` (vì IDs regenerate fresh, không phải update), thêm note trong body: `- **Note**: overwrote previous tsd.md (backup tại tsd.md.bak.{timestamp}) — IDs regenerated từ 001`.
199
+
190
200
  Thông báo kết quả:
191
201
 
192
202
  ```
@@ -61,3 +61,17 @@ Các quyết định kỹ thuật đặc thù của component và lý do.
61
61
  | Quyết định | Lý do | Alternatives đã cân nhắc |
62
62
  | --- | --- | --- |
63
63
  | {decision} | {lý do cụ thể} | {option A vs B} |
64
+
65
+ ## Change History
66
+
67
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
68
+
69
+ <!-- Entry format:
70
+ ### YYYY-MM-DD — [{id}-{slug}](../../../integrations/{id}-{slug}/tech.md) — create|update|manual
71
+
72
+ - **{Section name}**:
73
+ - [NEW] {item} — {mô tả ngắn}
74
+ - [MODIFY {field}] {item} — {old → new}
75
+ - [REMOVE] {item} — {lý do}
76
+ -->
77
+
@@ -93,3 +93,17 @@ Các component khác mà component này phụ thuộc.
93
93
  | Component | Loại dependency | Cách dùng |
94
94
  | --- | --- | --- |
95
95
  | `{C-XXX}-{name}` | sync call / event subscription / shared entity | {cụ thể: gọi API nào, subscribe event nào} |
96
+
97
+ ## Change History
98
+
99
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
100
+
101
+ <!-- Entry format:
102
+ ### YYYY-MM-DD — [{id}-{slug}](../../../integrations/{id}-{slug}/spec.md) — create|update|manual
103
+
104
+ - **{Section name}**:
105
+ - [NEW] {item} — {mô tả ngắn}
106
+ - [MODIFY {field}] {item} — {old → new}
107
+ - [REMOVE] {item} — {lý do}
108
+ -->
109
+
@@ -59,3 +59,17 @@ erDiagram
59
59
  EntityA ||--o{ EntityB : ""
60
60
  EntityB }o--|| EntityC : ""
61
61
  ```
62
+
63
+ ## Change History
64
+
65
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
66
+
67
+ <!-- Entry format:
68
+ ### YYYY-MM-DD — [{id}-{slug}](../integrations/{id}-{slug}/spec.md) — create|update|manual
69
+
70
+ - **{Section name}**:
71
+ - [NEW] {item} — {mô tả ngắn}
72
+ - [MODIFY {field}] {item} — {old → new}
73
+ - [REMOVE] {item} — {lý do}
74
+ -->
75
+
@@ -69,3 +69,17 @@ Quy ước:
69
69
  - **Layer**: `client` (UI validation trước submit), `gateway` (API gateway / request validator), `service` (business logic component), hoặc kết hợp (`client + gateway` cho double-check). Layer ảnh hưởng UX (inline vs server round-trip).
70
70
  - **Owning component**: component nào chịu trách nhiệm enforce. Implementation chi tiết (regex, validator code, error class) nằm trong `cdd.md` của component đó.
71
71
  - **Error propagation**: HTTP status + error code semantic + cách render cho user. Wording cụ thể của error message thuộc UI copy artifact, không ở đây.
72
+
73
+ ## Change History
74
+
75
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
76
+
77
+ <!-- Entry format:
78
+ ### YYYY-MM-DD — [{id}-{slug}](../../../integrations/{id}-{slug}/tech.md) — create|update|manual
79
+
80
+ - **{Section name}**:
81
+ - [NEW] {item} — {mô tả ngắn}
82
+ - [MODIFY {field}] {item} — {old → new}
83
+ - [REMOVE] {item} — {lý do}
84
+ -->
85
+
@@ -153,3 +153,17 @@ Tham chiếu đến `specs/main/component/{C-XXX}-...`.
153
153
  | Component | Vai trò trong feature |
154
154
  | --- | --- |
155
155
  | `{C-XXX}-{component-name}` | {component này phục vụ cái gì cho feature này} |
156
+
157
+ ## Change History
158
+
159
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
160
+
161
+ <!-- Entry format:
162
+ ### YYYY-MM-DD — [{id}-{slug}](../../../integrations/{id}-{slug}/spec.md) — create|update|manual
163
+
164
+ - **{Section name}**:
165
+ - [NEW] {item} — {mô tả ngắn}
166
+ - [MODIFY {field}] {item} — {old → new}
167
+ - [REMOVE] {item} — {lý do}
168
+ -->
169
+
@@ -218,3 +218,17 @@ Cover Feature Acceptance Criteria (`FAC-*`) trong frd. Feature AC trong frd đã
218
218
  ### Components Used (input only)
219
219
 
220
220
  Tham chiếu `frd.md > Components Used` để hiểu contract của các component được feature này dùng. Behavior của component được verify **gián tiếp** qua các TC ở đây — không tách tsd riêng cho component.
221
+
222
+ ## Change History
223
+
224
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
225
+
226
+ <!-- Entry format:
227
+ ### YYYY-MM-DD — [{id}-{slug}](../../../integrations/{id}-{slug}/test.md) — create|update|manual
228
+
229
+ - **{Section name}**:
230
+ - [NEW] {item} — {mô tả ngắn}
231
+ - [MODIFY {field}] {item} — {old → new}
232
+ - [REMOVE] {item} — {lý do}
233
+ -->
234
+
@@ -59,3 +59,17 @@ Các thành phần kỹ thuật của hệ thống — chi tiết về vai trò
59
59
 
60
60
  - {ràng buộc kinh doanh} — constraint
61
61
  - {giả định quan trọng} — assumption
62
+
63
+ ## Change History
64
+
65
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
66
+
67
+ <!-- Entry format:
68
+ ### YYYY-MM-DD — [{id}-{slug}](../integrations/{id}-{slug}/spec.md) — create|update|manual
69
+
70
+ - **{Section name}**:
71
+ - [NEW] {item} — {mô tả ngắn}
72
+ - [MODIFY {field}] {item} — {old → new}
73
+ - [REMOVE] {item} — {lý do}
74
+ -->
75
+
@@ -74,3 +74,17 @@ Các nguyên tắc sau là bất biến. Agent phải kiểm tra compliance trư
74
74
  - GUARD-001: {nguyên tắc — ví dụ: Không dùng raw SQL, phải qua ORM}
75
75
  - GUARD-002: {nguyên tắc — ví dụ: Mọi external API call phải có retry + timeout}
76
76
  - GUARD-003: {nguyên tắc — ví dụ: Không để business logic trong API layer}
77
+
78
+ ## Change History
79
+
80
+ Append-only log của các thay đổi cascade lên artifact này. Quy ước xem `conventions.md` §5.5.
81
+
82
+ <!-- Entry format:
83
+ ### YYYY-MM-DD — [{id}-{slug}](../integrations/{id}-{slug}/spec.md) — create|update|manual
84
+
85
+ - **{Section name}**:
86
+ - [NEW] {item} — {mô tả ngắn}
87
+ - [MODIFY {field}] {item} — {old → new}
88
+ - [REMOVE] {item} — {lý do}
89
+ -->
90
+