spec-lite 1.1.0 → 1.1.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.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Spec-driven development kit for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,266 @@
1
+ ---
2
+ name: spec-brownfield-component
3
+ description: Discover components từ code, generate crd.md + cdd.md cho từng component, điền Component Index vào prd.md. Phải chạy /spec-brownfield-init trước.
4
+ ---
5
+
6
+ # spec-brownfield-component
7
+
8
+ ## Overview
9
+
10
+ Tạo `specs/main/component/{C-XXX}-{component-name}/crd.md` và `cdd.md` cho các components trong brownfield project.
11
+
12
+ Skill này **tự discover** component boundaries từ code (không dựa vào init), sau đó scan sâu từng component để extract responsibilities, entities, public interface, business rules. Khi hoàn thành, **điền Component Index vào prd.md** và **đề xuất Shared Entities cascade vào domain.md**.
13
+
14
+ ## When to Use
15
+
16
+ - Sau khi `/spec-brownfield-init` đã chạy và `prd.md` tồn tại
17
+ - Cần generate component artifacts cho brownfield project
18
+
19
+ ## When NOT to Use
20
+
21
+ - `prd.md` chưa có → chạy `/spec-brownfield-init` trước
22
+ - Greenfield project → component artifacts mọc dần qua cascade từ integrations (`/spec-new`)
23
+
24
+ ---
25
+
26
+ ## Process
27
+
28
+ ### Bước 1: Load context và xác định path
29
+
30
+ **Path:** Nếu có ARGUMENT là path → dùng làm root. Nếu không → CWD.
31
+
32
+ **Load:**
33
+ - `specs/main/prd.md` — kiểm tra tồn tại; đọc problem statement và NFRs để hiểu business context
34
+ - `specs/main/domain.md` — đọc Glossary để reuse business terms
35
+
36
+ Nếu `prd.md` không tồn tại → dừng:
37
+ > `prd.md` chưa có nội dung. Hãy chạy `/spec-brownfield-init` trước.
38
+
39
+ **Attachments:**
40
+ > Bạn có tài liệu bổ sung nào không? (API docs, architecture diagrams, design docs)
41
+ > Nhập `không` để bỏ qua.
42
+
43
+ ---
44
+
45
+ ### Bước 2: Discover component boundaries
46
+
47
+ Scan directory structure để tìm component candidates. Thử các patterns sau theo thứ tự:
48
+
49
+ 1. `src/modules/*/` — modular structure (NestJS, v.v.)
50
+ 2. `src/*/` — flat module structure (nếu có `service` hoặc `controller` bên trong)
51
+ 3. `services/*/` — microservices
52
+ 4. `packages/*/` — monorepo packages
53
+ 5. `apps/*/` — monorepo apps
54
+
55
+ Với mỗi candidate directory, xác nhận đây là component bằng cách kiểm tra có ít nhất một trong: `*controller*`, `*service*`, `*repository*`, `*handler*`, `*module*` file bên trong.
56
+
57
+ Ghi lại cho mỗi component candidate:
58
+ - Directory path
59
+ - File count
60
+ - Patterns detected: controller / service / repository / event publisher / consumer
61
+
62
+ ---
63
+
64
+ ### Bước 3: Confirm component list
65
+
66
+ Trình bày kết quả discovery cho user confirm:
67
+
68
+ ```
69
+ Tôi phát hiện {N} components từ codebase:
70
+ [C-001] auth → src/modules/auth/ (15 files: controller+service+repo)
71
+ [C-002] user → src/modules/user/ (12 files: controller+service+repo)
72
+ [C-003] payment → src/modules/payment/ (8 files: service+repo)
73
+ [C-004] notification → src/modules/notification/ (6 files: service+event)
74
+
75
+ Điều chỉnh nếu cần:
76
+ - Đổi tên: "C-002 → profile" hoặc nhập tên khác
77
+ - Bỏ component: "bỏ C-004"
78
+ - Thêm component: "thêm reporting tại src/reporting/"
79
+ - Merge: "merge C-001 và C-002 thành auth-user"
80
+
81
+ Confirm danh sách? [y] hoặc nhập điều chỉnh:
82
+ ```
83
+
84
+ Sau khi confirm, assign C-XXX IDs theo thứ tự tăng dần.
85
+
86
+ ---
87
+
88
+ ### Bước 4: Scan sâu từng component
89
+
90
+ Với mỗi component, đọc code files bên trong để extract:
91
+
92
+ **4a. Responsibilities:**
93
+ - Public method names trong service files
94
+ - Class-level comments / JSDoc nếu có
95
+ - Export declarations
96
+
97
+ **4b. Owned Entities:**
98
+ - Entity / model files trong component directory
99
+ - Decorators: `@Entity()` (TypeORM), Prisma model blocks, `@Schema()` (Mongoose), SQLAlchemy models
100
+ - Migration files gắn với component
101
+
102
+ **4c. Public Interface:**
103
+ - Controller files: HTTP method + path mỗi endpoint
104
+ - Event publisher: `@EventPattern`, `eventEmitter.emit()`, message queue producers
105
+ - Exported service methods nếu là shared library
106
+
107
+ **4d. Dependencies:**
108
+ - Import statements referencing other component directories
109
+ - Injectable services từ other modules
110
+ - HTTP client calls đến other services
111
+
112
+ **4e. Business Rules:**
113
+ - Validation decorators (`@Min`, `@Max`, `@IsEmail`, custom validators)
114
+ - Guard conditions trong service (`if (!user.isActive) throw ...`)
115
+ - Domain events và điều kiện trigger
116
+ - Comments có từ khóa: "must", "should", "only", "never", "không được"
117
+
118
+ **4f. Internal design (cho cdd.md):**
119
+ - Module structure: list sub-modules / file groups
120
+ - ORM/storage usage: repository pattern, raw queries, cache decorators
121
+ - Internal service/repository interface contracts
122
+
123
+ ---
124
+
125
+ ### Bước 5: Identify cross-component entities
126
+
127
+ Trong quá trình scan, ghi nhận các entities được **import hoặc reference từ nhiều hơn 1 component** → đây là candidate Shared Entities cho `domain.md`.
128
+
129
+ Ví dụ: `Order` được dùng trong `payment/` và `inventory/` → candidate Shared Entity, cần xác định owner.
130
+
131
+ ---
132
+
133
+ ### Bước 6: Hỏi clarification — batch
134
+
135
+ Sau khi scan xong tất cả components, hỏi một lần — tối đa **5 câu tổng cộng**. Ưu tiên những điểm ảnh hưởng đến component boundaries hoặc entity ownership.
136
+
137
+ ```
138
+ Cần làm rõ {N} điểm:
139
+
140
+ [C-001 auth]
141
+ Q1. Method `validateToken` được call từ cả auth/ và user/ —
142
+ đây là public interface hay internal helper?
143
+ [public / internal / skip]
144
+
145
+ [cross-component]
146
+ Q2. Entity `Order` được dùng trong payment/ và inventory/ —
147
+ component nào sở hữu?
148
+ [payment / inventory / skip]
149
+
150
+ Trả lời hoặc "skip all" để đánh dấu NEEDS_CLARIFY hết:
151
+ ```
152
+
153
+ ---
154
+
155
+ ### Bước 7: Generate artifacts
156
+
157
+ Với mỗi component, generate 2 files dùng templates tương ứng:
158
+
159
+ **`crd.md`** — WHAT (dùng `.claude/templates/main/component/crd-template.md`):
160
+ - Role, Responsibilities, Owned Entities, Public Interface, Business Rules, Domain Events, Dependencies
161
+
162
+ **`cdd.md`** — HOW (dùng `.claude/templates/main/component/cdd-template.md`):
163
+ - Module structure, Internal data flow, Storage & persistence, Internal interfaces, Technical decisions
164
+
165
+ **Nguyên tắc:**
166
+ - Mọi phần không detect được → NEEDS_CLARIFY, không bịa
167
+ - Business rules detect được từ code → đánh dấu `(detected from code)`
168
+ - crd.md không chứa internal design; cdd.md không chứa public interface
169
+
170
+ ---
171
+
172
+ ### Bước 8: Cascade Proposals — domain.md
173
+
174
+ Nếu có Shared Entities được phát hiện ở Bước 5:
175
+
176
+ ```
177
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
178
+ SHARED ENTITIES DETECTED
179
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
180
+ Các entities sau được dùng bởi nhiều components.
181
+ Đề xuất thêm vào specs/main/domain.md (Shared Entities):
182
+
183
+ Entity: Order (Owner: C-003-payment)
184
+ Dùng bởi: C-003-payment, C-005-inventory
185
+ Fields detected: id, userId, items[], status, totalAmount
186
+
187
+ Entity: User (Owner: C-001-auth)
188
+ Dùng bởi: C-001-auth, C-002-user, C-004-notification
189
+ Fields detected: id, email, role, isActive
190
+
191
+ Apply cascade proposals vào domain.md? [y/n/edit]
192
+ ```
193
+
194
+ Nếu `y` → update `specs/main/domain.md` Shared Entities section.
195
+ Nếu `edit` → hỏi chỉnh sửa từng entity trước khi apply.
196
+
197
+ ---
198
+
199
+ ### Bước 9: Review và save artifacts
200
+
201
+ ```
202
+ Sẽ tạo {N} components ({2N} files):
203
+ ✓ specs/main/component/C-001-auth/crd.md (3 NEEDS_CLARIFY)
204
+ ✓ specs/main/component/C-001-auth/cdd.md (1 NEEDS_CLARIFY)
205
+ ✓ specs/main/component/C-002-user/crd.md (0 NEEDS_CLARIFY)
206
+ ✓ specs/main/component/C-002-user/cdd.md (2 NEEDS_CLARIFY)
207
+ ...
208
+
209
+ Ghi tất cả? [y] hoặc review từng file trước [r]:
210
+ ```
211
+
212
+ - `y` → ghi tất cả
213
+ - `r` → hiển thị lần lượt từng file, user confirm / skip / edit từng cái
214
+
215
+ ---
216
+
217
+ ### Bước 10: Điền Component Index vào prd.md
218
+
219
+ Sau khi artifacts đã được ghi, update `specs/main/prd.md` Component Index với danh sách đã confirm:
220
+
221
+ ```
222
+ Sẽ điền Component Index vào prd.md:
223
+ C-001 | auth | Xác thực và phân quyền người dùng | active
224
+ C-002 | user | Quản lý thông tin người dùng | active
225
+ C-003 | payment | Xử lý thanh toán và giao dịch | active
226
+ C-004 | notification | Gửi thông báo qua email/push | active
227
+
228
+ Apply? [y/n]
229
+ ```
230
+
231
+ ---
232
+
233
+ ### Bước 11: Summary
234
+
235
+ ```
236
+ ✓ Generated {N} components:
237
+ specs/main/component/C-001-auth/ (crd.md + cdd.md)
238
+ specs/main/component/C-002-user/ (crd.md + cdd.md)
239
+ ...
240
+
241
+ ✓ prd.md Component Index: {N} entries đã được điền
242
+
243
+ {nếu có} ✓ domain.md Shared Entities: {N} entities đã được cascade
244
+
245
+ NEEDS_CLARIFY summary — {total} items:
246
+ C-001-auth: {n} — [business rules, domain events, ...]
247
+ C-002-user: {n} — [entity ownership, ...]
248
+ ...
249
+
250
+ Bước tiếp theo:
251
+ /spec-brownfield-feature → discover features, generate frd.md + fdd.md, điền Feature Index
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Verification
257
+
258
+ - [ ] Mỗi component có đủ crd.md + cdd.md
259
+ - [ ] crd.md không chứa internal design (đã ở cdd.md)
260
+ - [ ] cdd.md không chứa public interface (đã ở crd.md)
261
+ - [ ] Mọi entity trong crd.md có đúng 1 owner component (hoặc NEEDS_CLARIFY)
262
+ - [ ] Dependencies chỉ reference C-XXX IDs, không reference file paths
263
+ - [ ] Business rules detect được đánh dấu `(detected from code)`
264
+ - [ ] prd.md Component Index đã được update
265
+ - [ ] Shared Entities đã được cascade vào domain.md (nếu có)
266
+ - [ ] NEEDS_CLARIFY items được list đầy đủ trong summary
@@ -0,0 +1,239 @@
1
+ ---
2
+ name: spec-brownfield-feature
3
+ description: Discover features từ code, generate frd.md + fdd.md cho từng feature, điền Feature Index vào prd.md. Phải chạy /spec-brownfield-component trước vì fdd.md tham chiếu C-XXX từ Component Index.
4
+ ---
5
+
6
+ # spec-brownfield-feature
7
+
8
+ ## Overview
9
+
10
+ Tạo `specs/main/feature/{F-XXX}-{feature-name}/frd.md` và `fdd.md` cho các features trong brownfield project.
11
+
12
+ Skill này **tự discover** features từ routes, use cases, và test files, sau đó scan sâu để extract user stories, AC, và inter-component flows. Khi hoàn thành, **điền Feature Index vào prd.md**.
13
+
14
+ **Phải chạy sau `/spec-brownfield-component`** vì fdd.md mô tả inter-component interaction và cần tham chiếu C-XXX IDs từ Component Index đã được điền.
15
+
16
+ ## When to Use
17
+
18
+ - Sau khi `/spec-brownfield-component` đã chạy xong
19
+ - prd.md có Component Index (C-XXX IDs đã có)
20
+ - Cần generate feature artifacts cho brownfield project
21
+
22
+ ## When NOT to Use
23
+
24
+ - `/spec-brownfield-component` chưa chạy → chạy component skill trước
25
+ - Greenfield project → feature artifacts mọc dần qua cascade từ integrations (`/spec-new`)
26
+
27
+ ---
28
+
29
+ ## Process
30
+
31
+ ### Bước 1: Load context và xác định path
32
+
33
+ **Path:** Nếu có ARGUMENT là path → dùng làm root. Nếu không → CWD.
34
+
35
+ **Load:**
36
+ - `specs/main/prd.md` — kiểm tra Component Index đã được điền
37
+ - `specs/main/domain.md` — đọc Glossary và Shared Entities
38
+ - `specs/main/component/*/crd.md` — đọc Public Interface của từng component (để cross-reference trong fdd.md)
39
+
40
+ **Kiểm tra preconditions:**
41
+
42
+ Nếu `prd.md` không tồn tại → dừng:
43
+ > `prd.md` chưa có nội dung. Hãy chạy `/spec-brownfield-init` trước.
44
+
45
+ Nếu `prd.md` Component Index còn trống (không có C-XXX entries) → dừng:
46
+ > Component Index chưa có entries. Hãy chạy `/spec-brownfield-component` trước.
47
+ > fdd.md cần tham chiếu C-XXX để mô tả inter-component flows.
48
+
49
+ Nếu `specs/main/component/` không có crd.md nào → cảnh báo tương tự và dừng.
50
+
51
+ **Attachments:**
52
+ > Bạn có tài liệu bổ sung nào không? (user stories, test plans, wireframes, existing specs)
53
+ > Nhập `không` để bỏ qua.
54
+
55
+ ---
56
+
57
+ ### Bước 2: Discover feature boundaries
58
+
59
+ Scan codebase để tìm feature candidates. Tìm theo thứ tự ưu tiên:
60
+
61
+ 1. **Use case / interactor files**: `*UseCase.{ts,js}`, `*Interactor.{ts,js}`, `*Handler.{ts,js}`, thư mục `application/*/`
62
+ 2. **Route groups**: controller files grouped by path prefix (`/auth/*`, `/payment/*`, `/orders/*`)
63
+ 3. **Test describe blocks**: `describe('User Registration', ...)`, `describe('Checkout Flow', ...)`
64
+ 4. **Page / screen directories**: `pages/{feature}/`, `screens/{feature}/`, `views/{feature}/`
65
+
66
+ Với mỗi candidate, ghi lại:
67
+ - Entry point file(s)
68
+ - Route paths liên quan
69
+ - Test files có hay không
70
+ - Components được call (từ import statements) → map sang C-XXX IDs
71
+
72
+ ---
73
+
74
+ ### Bước 3: Confirm feature list
75
+
76
+ ```
77
+ Tôi phát hiện {N} features từ codebase:
78
+ [F-001] user-registration → RegisterUseCase + POST /auth/register (5 tests)
79
+ [F-002] authentication → POST /auth/login, /auth/refresh (3 tests)
80
+ [F-003] checkout-flow → CheckoutUseCase + /checkout/* (8 tests)
81
+ [F-004] order-history → GET /orders/* (no tests)
82
+
83
+ Điều chỉnh nếu cần:
84
+ - Đổi tên: "F-003 → place-order"
85
+ - Bỏ feature: "bỏ F-004"
86
+ - Thêm feature: "thêm password-reset"
87
+ - Merge: "merge F-001 và F-002 thành auth-flow"
88
+
89
+ Confirm danh sách? [y] hoặc nhập điều chỉnh:
90
+ ```
91
+
92
+ Sau khi confirm, assign F-XXX IDs theo thứ tự tăng dần.
93
+
94
+ ---
95
+
96
+ ### Bước 4: Scan sâu từng feature
97
+
98
+ **4a. User stories — infer từ:**
99
+ - Use case class names và public methods → action descriptions
100
+ - Route names + HTTP methods → "As a user, I want to POST /auth/register..."
101
+ - Test `describe` / `it` blocks → `it('should register a new user', ...)` → user story
102
+
103
+ Đánh dấu source: `(inferred from routes)` hoặc `(from tests)`.
104
+
105
+ **4b. Acceptance criteria — extract từ:**
106
+ - Test assertions: `expect(response.status).toBe(201)`, `expect(user.email).toBe(...)`
107
+ - Input validation rules từ DTO / request validators
108
+ - Expected error codes / messages từ error handling code
109
+
110
+ Nếu không có tests → AC section sẽ là NEEDS_CLARIFY.
111
+
112
+ **4c. Components consumed — extract từ:**
113
+ - Import statements trong feature's controllers / use cases → map sang C-XXX IDs (đã có từ Component Index)
114
+ - Cross-reference với crd.md Public Interface để confirm
115
+
116
+ **4d. Inter-component flow cho fdd.md — extract từ:**
117
+ - Call chain trong use case file: `authService → userRepo → notificationService`
118
+ - Event publications và subscriptions trong flow
119
+ - Transaction boundaries nếu explicit (`@Transaction`, `queryRunner`)
120
+ - Retry / timeout config nếu detect được
121
+
122
+ ---
123
+
124
+ ### Bước 5: Hỏi clarification — batch
125
+
126
+ Sau khi scan xong tất cả, hỏi một lần — tối đa **5 câu tổng cộng**:
127
+
128
+ ```
129
+ Cần làm rõ {N} điểm:
130
+
131
+ [F-001 user-registration]
132
+ Q1. Flow này chỉ register bằng email/password, hay còn OAuth nữa?
133
+ (Tôi detect email/password flow nhưng thấy OAuth client được import)
134
+ [email/password only / cả hai / skip]
135
+
136
+ [F-003 checkout-flow]
137
+ Q2. Sau khi place order, payment được xử lý sync hay async?
138
+ (Tôi thấy PaymentService được call nhưng không rõ transaction boundary)
139
+ [sync / async / skip]
140
+
141
+ Trả lời hoặc "skip all":
142
+ ```
143
+
144
+ ---
145
+
146
+ ### Bước 6: Generate artifacts
147
+
148
+ Với mỗi feature, generate 2 files dùng templates tương ứng:
149
+
150
+ **`frd.md`** — WHAT (dùng `.claude/templates/main/feature/frd-template.md`):
151
+ - Description và business goal (infer từ feature name + use case, NEEDS_CLARIFY nếu không rõ)
152
+ - User stories (đánh dấu source)
153
+ - Acceptance criteria (extract từ tests nếu có, NEEDS_CLARIFY nếu không)
154
+ - Scope: In scope từ detected routes/actions; Out of scope → NEEDS_CLARIFY
155
+ - Components consumed: list C-XXX từ Component Index
156
+ - Dependencies: feature-to-feature dependencies nếu detect được
157
+
158
+ **`fdd.md`** — HOW / inter-component (dùng `.claude/templates/main/feature/fdd-template.md`):
159
+ - Inter-component data flow: sequence diagram từ detected call chain (Mermaid hoặc ASCII)
160
+ - Orchestration: retry / timeout / fallback nếu detect được
161
+ - Cross-component invariants: transaction boundaries nếu detect được
162
+
163
+ **Nguyên tắc:**
164
+ - fdd.md là **file mỏng** — chỉ mô tả tương tác giữa components, không lặp nội dung từ crd.md / cdd.md
165
+ - Mọi phần không detect được → NEEDS_CLARIFY, không bịa
166
+
167
+ ---
168
+
169
+ ### Bước 7: Review và save artifacts
170
+
171
+ ```
172
+ Sẽ tạo {N} features ({2N} files):
173
+ ✓ specs/main/feature/F-001-user-registration/frd.md (4 NEEDS_CLARIFY)
174
+ ✓ specs/main/feature/F-001-user-registration/fdd.md (2 NEEDS_CLARIFY)
175
+ ✓ specs/main/feature/F-002-authentication/frd.md (1 NEEDS_CLARIFY)
176
+ ✓ specs/main/feature/F-002-authentication/fdd.md (0 NEEDS_CLARIFY)
177
+ ...
178
+
179
+ Ghi tất cả? [y] hoặc review từng file trước [r]:
180
+ ```
181
+
182
+ ---
183
+
184
+ ### Bước 8: Điền Feature Index vào prd.md
185
+
186
+ Sau khi artifacts đã được ghi, update `specs/main/prd.md` Feature Index:
187
+
188
+ ```
189
+ Sẽ điền Feature Index vào prd.md:
190
+ F-001 | user-registration | Đăng ký tài khoản mới qua email/password | Must | TODO
191
+ F-002 | authentication | Đăng nhập và refresh token | Must | TODO
192
+ F-003 | checkout-flow | Đặt hàng và thanh toán | Must | TODO
193
+ F-004 | order-history | Xem lịch sử đơn hàng | Should | TODO
194
+
195
+ Apply? [y/n]
196
+ ```
197
+
198
+ ---
199
+
200
+ ### Bước 9: Summary
201
+
202
+ ```
203
+ ✓ Generated {N} features:
204
+ specs/main/feature/F-001-user-registration/ (frd.md + fdd.md)
205
+ specs/main/feature/F-002-authentication/ (frd.md + fdd.md)
206
+ ...
207
+
208
+ ✓ prd.md Feature Index: {N} entries đã được điền
209
+
210
+ NEEDS_CLARIFY summary — {total} items:
211
+ F-001: {n} — [business goal, out of scope, AC, ...]
212
+ F-002: {n} — [...]
213
+ ...
214
+
215
+ Brownfield init hoàn tất! Main artifacts:
216
+ specs/main/
217
+ ├── prd.md (Component Index: {N} | Feature Index: {N})
218
+ ├── domain.md (Glossary: {N} terms | Shared Entities: {N})
219
+ ├── sad.md
220
+ ├── component/ ({N} components, mỗi cái có crd.md + cdd.md)
221
+ └── feature/ ({N} features, mỗi cái có frd.md + fdd.md)
222
+
223
+ Để bắt đầu implement, dùng /spec-new để tạo integration đầu tiên.
224
+ grep "NEEDS_CLARIFY" để tìm và fill in khi có thêm context.
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Verification
230
+
231
+ - [ ] Chạy sau `/spec-brownfield-component` — Component Index đã có entries
232
+ - [ ] Mỗi feature có đủ frd.md + fdd.md
233
+ - [ ] frd.md có ít nhất 1 user story hoặc NEEDS_CLARIFY rõ ràng
234
+ - [ ] fdd.md chỉ mô tả inter-component interaction — không lặp nội dung từ crd.md / cdd.md
235
+ - [ ] Components consumed list reference đúng C-XXX IDs từ Component Index
236
+ - [ ] User stories và AC detect được đánh dấu source `(inferred)` hoặc `(from tests)`
237
+ - [ ] Feature không có tests → AC section có NEEDS_CLARIFY rõ ràng
238
+ - [ ] prd.md Feature Index đã được update
239
+ - [ ] NEEDS_CLARIFY items được list đầy đủ trong summary
@@ -0,0 +1,300 @@
1
+ ---
2
+ name: spec-brownfield-init
3
+ description: Khởi tạo main artifacts (prd.md, domain.md, sad.md) cho brownfield project bằng cách scan codebase và interview với pre-filled options. Dùng khi onboarding một project đã chạy vào SDD workflow.
4
+ ---
5
+
6
+ # spec-brownfield-init
7
+
8
+ ## Overview
9
+
10
+ Tạo `specs/main/prd.md`, `specs/main/domain.md`, và `specs/main/sad.md` cho một project đã tồn tại.
11
+
12
+ Skill này chỉ tập trung vào **product và architecture level** — những gì có thể extract từ README, docs, config, và kiến trúc tổng thể. Component Index và Feature Index trong prd.md sẽ **để trống** — chúng sẽ được điền bởi `/spec-brownfield-component` và `/spec-brownfield-feature` sau khi scan code chuyên sâu.
13
+
14
+ Thông tin không thể detect từ code được đánh dấu nhất quán:
15
+
16
+ ```
17
+ **[NEEDS_CLARIFY]** <mô tả điều chưa rõ và câu hỏi cần trả lời>
18
+ ```
19
+
20
+ ## When to Use
21
+
22
+ - Onboarding một brownfield project vào SDD workflow
23
+ - `specs/main/prd.md` chưa có hoặc còn trống
24
+
25
+ ## When NOT to Use
26
+
27
+ - Greenfield project chưa có code → dùng `/spec-prd` + `/spec-sad`
28
+ - `prd.md` đã có nội dung đầy đủ → dùng `/spec-prd` hoặc `/spec-sad` để update từng phần
29
+
30
+ ---
31
+
32
+ ## Process
33
+
34
+ ### Bước 1: Xác định target path và load attachments
35
+
36
+ **Path:**
37
+ - Nếu có ARGUMENT là path → đây là root của project cần scan.
38
+ - Nếu không có → mặc định dùng current working directory.
39
+
40
+ Thông báo: `Sẽ scan: {path}`
41
+
42
+ **Attachments:**
43
+ Hỏi ngay đầu — không hỏi lại sau:
44
+
45
+ > Bạn có tài liệu bổ sung nào không? (README, API spec, wiki, ADR, existing docs)
46
+ > Paste nội dung hoặc cung cấp file path. Nhập `không` để bỏ qua.
47
+
48
+ Load tất cả attachments trước khi scan. Dùng làm context bổ sung trong mọi bước tiếp theo.
49
+
50
+ ---
51
+
52
+ ### Bước 2: Kiểm tra existing specs
53
+
54
+ Kiểm tra `specs/main/prd.md`, `specs/main/domain.md`, `specs/main/sad.md`:
55
+
56
+ Nếu một trong ba đã có nội dung thực → cảnh báo:
57
+
58
+ ```
59
+ ⚠ File đã có nội dung:
60
+ - specs/main/prd.md
61
+ - specs/main/sad.md
62
+
63
+ Skill này sẽ overwrite các file trên. Tiếp tục? [y/n]
64
+ ```
65
+
66
+ Nếu user chọn `n` → dừng.
67
+
68
+ ---
69
+
70
+ ### Bước 3: Scan codebase
71
+
72
+ Scan tuần tự. **Không hỏi user trong bước này** — chỉ thu thập thông tin.
73
+
74
+ **3a. Package & tech stack:**
75
+ Đọc (nếu tồn tại): `package.json`, `yarn.lock`, `pnpm-lock.yaml`, `requirements.txt`, `pyproject.toml`, `go.mod`, `Cargo.toml`, `pom.xml`, `build.gradle`, `composer.json`, `Gemfile`, `pubspec.yaml`
76
+
77
+ Extract: ngôn ngữ, framework chính, major dependencies, build/test scripts.
78
+
79
+ **3b. README và existing docs:**
80
+ Đọc (nếu tồn tại): `README.md`, `README.*`, `docs/`, `ARCHITECTURE.md`, `DESIGN.md`
81
+
82
+ Extract: mô tả project, target users được nhắc đến, business context.
83
+
84
+ **3c. Directory structure — top level:**
85
+ List 1-2 levels từ root — không đọc nội dung file source.
86
+
87
+ Detect: architecture pattern (monolith / microservices / monorepo). Không cần lấy tên từng module — đó là việc của `/spec-brownfield-component`.
88
+
89
+ **3d. Auth & middleware:**
90
+ Tìm files liên quan: auth, middleware, interceptor, guard, rate-limit, logging config.
91
+
92
+ Infer: auth strategy, cross-cutting patterns đang dùng.
93
+
94
+ **3e. Infrastructure:**
95
+ Đọc (nếu tồn tại): `docker-compose.yml`, `Dockerfile`, `.github/workflows/`, `k8s/`, `terraform/`, `serverless.yml`, `.env.example`
96
+
97
+ Extract: deployment target, số services (để confirm architecture pattern), số môi trường.
98
+
99
+ ---
100
+
101
+ ### Bước 4: Tóm tắt scan và xác nhận tiếp tục
102
+
103
+ ```
104
+ SCAN RESULTS — {path}
105
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
106
+ Tech stack: {e.g. TypeScript / NestJS / PostgreSQL / Redis}
107
+ Architecture: {e.g. Modular Monolith}
108
+ Auth pattern: {e.g. JWT Bearer / Session / không detect được}
109
+ Docs loaded: {list files đọc được}
110
+
111
+ Tiếp tục với brownfield init? [y/n]
112
+ ```
113
+
114
+ Nếu `n` → dừng.
115
+
116
+ ---
117
+
118
+ ### Bước 5: Interview — prd.md
119
+
120
+ Hỏi tuần tự từng phần. Mỗi câu hỏi có options pre-filled từ scan. Luôn có `[0] Chưa rõ → NEEDS_CLARIFY`. Khi user chọn `[0]` → đánh dấu và tiếp tục, không dừng lại.
121
+
122
+ **Phần 1 — Problem Statement:**
123
+
124
+ ```
125
+ ❓ Hệ thống này giải quyết vấn đề gì?
126
+ [1] {Trích từ README: "..."}
127
+ [2] Nhập mô tả khác
128
+ [0] Chưa rõ → NEEDS_CLARIFY
129
+ ```
130
+
131
+ **Phần 2 — Target Users:**
132
+
133
+ ```
134
+ ❓ Ai là người dùng chính?
135
+ [1] {Detected từ auth guards / README: e.g. "admin, user, guest"}
136
+ [2] Nhập personas khác
137
+ [0] Chưa rõ → NEEDS_CLARIFY
138
+ ```
139
+
140
+ Nếu user chọn [1] → hỏi thêm một câu: "Bạn muốn mô tả thêm mục tiêu / pain point cho từng role không? [y/n]"
141
+
142
+ **Phần 3 — Scope:**
143
+
144
+ ```
145
+ ❓ In scope — những gì hệ thống có:
146
+ [1] {Infer từ README/docs: "..."}
147
+ [2] Nhập danh sách khác
148
+ [0] Chưa rõ → NEEDS_CLARIFY
149
+
150
+ ❓ Out of scope — những gì hệ thống KHÔNG làm:
151
+ [1] Nhập nội dung
152
+ [0] Chưa rõ → NEEDS_CLARIFY
153
+ ```
154
+
155
+ **Phần 4 — NFRs:**
156
+
157
+ ```
158
+ ❓ Non-Functional Requirements:
159
+ Detected từ config / code:
160
+ {e.g. Rate limit: 100 req/min (từ rate-limit config)}
161
+ {e.g. DB pool: max 10 connections (từ DB config)}
162
+
163
+ Có thêm NFR nào không? (performance targets, availability SLA, security compliance, scalability)
164
+ [1] Dùng detected + nhập thêm nếu có
165
+ [2] Nhập lại từ đầu
166
+ [0] Chưa rõ → NEEDS_CLARIFY tất cả
167
+ ```
168
+
169
+ **Phần 5 — Business Constraints:**
170
+
171
+ ```
172
+ ❓ Business constraints và assumptions:
173
+ (deadline, budget, compliance, vendor lock-in, team constraints)
174
+ [1] Nhập nội dung
175
+ [0] Chưa rõ → NEEDS_CLARIFY
176
+ ```
177
+
178
+ **Lưu ý:** prd.md sẽ có Component Index và Feature Index **để trống** với placeholder. Chúng sẽ được điền bởi `/spec-brownfield-component` và `/spec-brownfield-feature`.
179
+
180
+ ---
181
+
182
+ ### Bước 6: Tạo domain.md — Glossary
183
+
184
+ domain.md ở bước này chỉ có **Glossary** — Shared Entities để trống, sẽ được mọc qua cascade proposals từ `/spec-brownfield-component` khi nó phát hiện cross-component entities.
185
+
186
+ Extract glossary terms từ: README/docs (business terms được nhắc đến), tên các key concepts trong problem statement vừa thu thập.
187
+
188
+ Hỏi:
189
+ ```
190
+ ❓ Glossary terms cần define:
191
+ Tôi nhận diện được các terms sau từ docs:
192
+ - {term 1}: {định nghĩa inferred hoặc NEEDS_CLARIFY}
193
+ - {term 2}: {định nghĩa inferred hoặc NEEDS_CLARIFY}
194
+
195
+ [1] Dùng list này — có thể thêm/sửa/xóa
196
+ [2] Nhập danh sách mới
197
+ [0] Chưa rõ / bỏ qua → để trống, điền sau
198
+ ```
199
+
200
+ ---
201
+
202
+ ### Bước 7: Auto-generate — sad.md
203
+
204
+ Phần lớn auto từ scan. Chỉ hỏi 2 câu.
205
+
206
+ **7a. Auto-fill từ scan:**
207
+ - Tech stack: từ package files
208
+ - Architecture style: infer từ directory structure top-level + docker-compose
209
+ - Cross-cutting concerns: infer từ middleware / interceptors / guards detected
210
+ - Inter-service communication: infer từ message queue / HTTP client usage
211
+ - Infrastructure: infer từ docker-compose, cloud configs
212
+
213
+ **7b. Hỏi Guardrails:**
214
+
215
+ ```
216
+ ❓ Architectural Guardrails:
217
+ Dựa trên {stack}, tôi đề xuất:
218
+ GUARD-001: {rule cụ thể}
219
+ GUARD-002: {rule cụ thể}
220
+ ...
221
+
222
+ [1] Dùng set này — có thể thêm/bớt
223
+ [2] Nhập guardrails khác
224
+ [0] Chưa rõ → NEEDS_CLARIFY tất cả
225
+ ```
226
+
227
+ **7c. Hỏi additional constraints:**
228
+
229
+ ```
230
+ ❓ Có architectural decision nào quan trọng chưa detect được không?
231
+ (patterns bắt buộc dùng, patterns bị cấm, third-party services phải dùng)
232
+ [1] Nhập thêm
233
+ [0] Không có thêm
234
+ ```
235
+
236
+ ---
237
+
238
+ ### Bước 8: Review drafts
239
+
240
+ Hiển thị draft từng file lần lượt. Với mỗi file:
241
+
242
+ ```
243
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
244
+ DRAFT: specs/main/{file}
245
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
246
+ {nội dung draft}
247
+
248
+ [NEEDS_CLARIFY trong file này: {count} items]
249
+
250
+ Confirm? [y] Bỏ qua [n] Chỉnh sửa [e]:
251
+ ```
252
+
253
+ - `y` → ghi file, chuyển sang file tiếp theo
254
+ - `n` → bỏ qua file này
255
+ - `e` → hỏi chỉnh sửa cụ thể, show lại draft, hỏi confirm lần nữa
256
+
257
+ ---
258
+
259
+ ### Bước 9: Save
260
+
261
+ Tạo `specs/main/` nếu chưa có. Ghi các files đã được confirm.
262
+
263
+ ```
264
+ ✓ specs/main/prd.md (Component Index và Feature Index: placeholder — chưa có)
265
+ ✓ specs/main/domain.md (Glossary: {n} terms | Shared Entities: trống — sẽ mọc qua cascade)
266
+ ✓ specs/main/sad.md
267
+
268
+ NEEDS_CLARIFY summary — {total} items cần làm rõ:
269
+ prd.md: {n} — [Problem Statement, Business Constraints, ...]
270
+ domain.md: {n} — [glossary terms, ...]
271
+ sad.md: {n} — [guardrails, ...]
272
+
273
+ Bước tiếp theo:
274
+ /spec-brownfield-component → scan code, generate crd.md + cdd.md, điền Component Index
275
+ /spec-brownfield-feature → scan code, generate frd.md + fdd.md, điền Feature Index
276
+ (chạy component trước — feature phụ thuộc vào component)
277
+ ```
278
+
279
+ ---
280
+
281
+ ## NEEDS_CLARIFY Convention
282
+
283
+ Format chuẩn — dùng nhất quán trong tất cả artifacts:
284
+
285
+ ```markdown
286
+ **[NEEDS_CLARIFY]** Mô tả ngắn điều chưa rõ. Câu hỏi cần trả lời để fill in.
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Verification
292
+
293
+ - [ ] Scan results đã được hiển thị và user confirm trước khi interview
294
+ - [ ] Mọi section có ít nhất một trong ba: nội dung thực / pre-filled option / NEEDS_CLARIFY
295
+ - [ ] prd.md có Component Index placeholder (chưa có entries — sẽ điền sau)
296
+ - [ ] prd.md có Feature Index placeholder (chưa có entries — sẽ điền sau)
297
+ - [ ] domain.md có Glossary (ít nhất skeleton) và Shared Entities trống
298
+ - [ ] sad.md có Architectural Guardrails section
299
+ - [ ] NEEDS_CLARIFY items được list đầy đủ trong summary cuối
300
+ - [ ] User đã confirm từng file trước khi ghi