ai-developer-skill-os 9.1.1 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.agents/AGENTS.md +139 -42
  2. package/.agents/DEV_PROFILE.md +95 -0
  3. package/.agents/registry/capability-graph.yml +171 -334
  4. package/.agents/registry/graph.json +52 -18
  5. package/.agents/registry/index.yaml +66 -12
  6. package/.agents/registry/skills-index.yml +204 -447
  7. package/.agents/rules/coding.md +23 -0
  8. package/.agents/rules/global.md +44 -30
  9. package/.agents/skills/_template/SKILL.md +2 -300
  10. package/.agents/skills/qk-access-policy/SKILL.md +98 -393
  11. package/.agents/skills/qk-agent-observability/SKILL.md +3 -359
  12. package/.agents/skills/qk-ai-builder/SKILL.md +132 -485
  13. package/.agents/skills/qk-api-consumer/SKILL.md +256 -0
  14. package/.agents/skills/qk-api-consumer/capability.yaml +21 -0
  15. package/.agents/skills/qk-api-consumer/evals/scorecard.yaml +29 -0
  16. package/.agents/skills/qk-api-lifecycle/SKILL.md +133 -376
  17. package/.agents/skills/qk-bug-resolution/SKILL.md +128 -481
  18. package/.agents/skills/qk-code-review/SKILL.md +142 -340
  19. package/.agents/skills/qk-context-loader/SKILL.md +99 -391
  20. package/.agents/skills/qk-data-engineer/SKILL.md +253 -0
  21. package/.agents/skills/qk-data-lifecycle/SKILL.md +89 -408
  22. package/.agents/skills/qk-db-optimizer/SKILL.md +102 -408
  23. package/.agents/skills/qk-design-system-engineering/SKILL.md +76 -381
  24. package/.agents/skills/qk-devops-platform/SKILL.md +77 -383
  25. package/.agents/skills/qk-docs/SKILL.md +88 -414
  26. package/.agents/skills/qk-engineering-standard/SKILL.md +4 -508
  27. package/.agents/skills/qk-fe-api-integration/SKILL.md +343 -263
  28. package/.agents/skills/qk-fe-api-integration/evals/scorecard.yaml +29 -29
  29. package/.agents/skills/qk-feature-delivery/SKILL.md +137 -365
  30. package/.agents/skills/qk-feature-delivery/evals/scorecard.yaml +1 -1
  31. package/.agents/skills/qk-frontend-architecture/SKILL.md +5 -399
  32. package/.agents/skills/qk-help/evals/scorecard.yaml +13 -13
  33. package/.agents/skills/qk-orchestrator/SKILL.md +63 -422
  34. package/.agents/skills/qk-orchestrator/references/routing-table.md +10 -14
  35. package/.agents/skills/qk-product-specification/SKILL.md +70 -399
  36. package/.agents/skills/qk-production-release/SKILL.md +80 -457
  37. package/.agents/skills/qk-project-audit/SKILL.md +174 -0
  38. package/.agents/skills/qk-project-bootstrap/SKILL.md +244 -392
  39. package/.agents/skills/qk-project-health/SKILL.md +97 -416
  40. package/.agents/skills/qk-project-memory/SKILL.md +76 -21
  41. package/.agents/skills/qk-refactor/SKILL.md +167 -304
  42. package/.agents/skills/qk-security-audit/SKILL.md +141 -383
  43. package/.agents/skills/qk-security-audit/capability.yaml +1 -2
  44. package/.agents/skills/qk-system-evolution/SKILL.md +343 -263
  45. package/.agents/skills/qk-system-evolution/evals/scorecard.yaml +26 -26
  46. package/.agents/skills/qk-test-engineering/SKILL.md +119 -429
  47. package/.agents/skills/qk-ui-audit/SKILL.md +73 -457
  48. package/.agents/skills/qk-ui-builder/SKILL.md +521 -482
  49. package/.agents/skills/qk-ui-system-builder/SKILL.md +68 -434
  50. package/.agents/skills/qk-upgrade/SKILL.md +301 -0
  51. package/.agents/skills/qk-upgrade/capability.yaml +24 -0
  52. package/.agents/skills/qk-upgrade/evals/scorecard.yaml +26 -0
  53. package/.agents/skills/qk-validation-gate/SKILL.md +4 -523
  54. package/.agents/skills/qk-web-quality-gate/SKILL.md +85 -383
  55. package/.agents/workflows/bug-resolution.yml +6 -6
  56. package/.agents/workflows/context-discovery.yml +94 -0
  57. package/.agents/workflows/feature-delivery.yml +8 -4
  58. package/.agents/workflows/refactor.yml +6 -3
  59. package/.agents/workflows/shared/quality-gate.yml +94 -0
  60. package/.agents/workflows/skin-governance.yml +115 -0
  61. package/README.md +152 -67
  62. package/package.json +2 -2
  63. package/tooling/build-registry.js +30 -8
@@ -1,9 +1,9 @@
1
- ---
1
+ ---
2
2
  # ── Identity ───────────────────────────────────────────────
3
3
  name: qk-ai-builder
4
- version: 9.1.0
4
+ version: 9.2.0
5
5
  status: stable
6
- description: "Thiết kế Governed AI Agent & RAG pipelines theo chuẩn V8.2 Đóng gói bằng capability.yaml, data discipline 4-folder Eval Pipeline."
6
+ description: "Thiết kế implement AI Agent hoặc RAG pipeline với eval criteria bắt buộc. Dùng skill này khi user nhắc đến: build ai, rag pipeline, prompt engineering, viết prompt, thiết kế agent, llm, vector database, embedding, retrieval, chatbot, ai logic, tạo skill — kể cả khi chỉ nói \"muốn AI trả lời từ tài liệu của mình\"."
7
7
  platforms: [antigravity, claude-code, cursor, windsurf, kilo-code]
8
8
 
9
9
  # ── V9: Classification ─────────────────────────────────────
@@ -21,12 +21,20 @@ complexity:
21
21
  has_external_dependency: true
22
22
  has_breaking_change: false
23
23
 
24
- triggers:
25
- - "build ai"
26
- - "viết prompt"
27
- - "thiết kế bot"
28
- - "ai logic"
29
- - "tạo skill"
24
+ triggers:
25
+ - "build ai"
26
+ - "rag pipeline"
27
+ - "prompt engineering"
28
+ - "viết prompt"
29
+ - "thiết kế agent"
30
+ - "llm"
31
+ - "vector database"
32
+ - "embedding"
33
+ - "retrieval"
34
+ - "chatbot"
35
+ - "ai logic"
36
+ - "tạo skill"
37
+
30
38
 
31
39
  # ── V8: References ─────────────────────────────────────────
32
40
  workflow: feature-delivery
@@ -78,530 +86,169 @@ token_budget:
78
86
  max_shell_commands: 0
79
87
  stop_early: true
80
88
 
81
- exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
89
+ exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
82
90
  ---
83
91
 
84
92
  # qk-ai-builder — AI Integration Designer
85
93
 
86
94
  > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
87
95
 
88
- ---
89
-
90
- ## Memory Workflow
91
-
92
- ### 0. Self-Init Protocol (Khởi Tạo Bộ Nhớ Local & Gitignore)
93
- - Trước khi tra cứu hoặc lưu trữ tri thức, BẮT BUỘC kiểm tra sự tồn tại của thư mục `.ai-local/` tại gốc dự án:
94
- - **Tự động tạo mới:** Nếu `.ai-local/` chưa tồn tại, AI phải tự động tạo cấu trúc thư mục `.ai-local/knowledge/` (và file `index.yaml` nếu cần thiết) cùng `.ai-local/candidates/`. Tuyệt đối không ngưng chạy hay hỏi ý kiến người dùng về thao tác khởi tạo tiêu chuẩn này.
95
- - **Bảo mật Gitignore:** BẮT BUỘC kiểm tra file `.gitignore` của dự án, nếu chưa có dòng `.ai-local/` thì phải tự động thêm vào để tuyệt đối bảo mật tri thức cá nhân và tránh lộ lọt lên Git.
96
-
97
- ---
98
-
99
- ### Pre-flight Retrieve (Trước khi thực thi)
100
- - Trước các task có tính lặp lại, debug, refactor, kiến trúc hoặc rủi ro cao:
101
- bắt buộc tra cứu:
102
- - `.ai-local/knowledge/index.yaml` (Private Local Knowledge)
103
-
104
- - Ưu tiên sử dụng các Knowledge đang có trạng thái `Active` thuộc:
105
- - Architecture
106
- - Hard Bug
107
- - Convention
108
- - Pattern
109
- - Tech Debt Pattern
110
- - 👉 *Domain Focus:* Architecture/Pattern (vd: cấu hình provider LLM, chuẩn RAG pipeline, prompt template).
111
-
112
- - Memory chỉ đóng vai trò **Navigator (bản đồ chỉ đường)**.
113
- Không được xem Memory là Source of Truth.
114
- Luôn xác minh lại bằng source code, configuration và trạng thái hiện tại của dự án trước khi áp dụng.
115
-
116
- ---
117
-
118
- ### Learning Flow (AI tự học có kiểm soát)
119
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
120
- - Hard Bug có khả năng tái diễn.
121
- - Pattern làm việc lặp lại trong dự án.
122
- - Convention hoặc quy tắc kiến trúc mới.
123
- - Quyết định Architecture quan trọng.
124
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
125
- - 👉 *Domain Harvest:* Pattern hoặc Convention mới (vd: quy chuẩn JSON schema cho prompt, scorecard định lượng).
126
-
127
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
128
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
129
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
130
-
131
- ---
132
-
133
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
134
- Sau khi hoàn thành task:
135
- - AI đánh giá các Candidate Memory đã tạo.
136
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
137
- - Đề xuất người dùng xem xét.
138
- - Gửi yêu cầu phê duyệt thông qua:
139
- - `/learn`
140
- - `qk-project-memory`
141
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
142
-
143
- ```
144
- .ai-local/candidates/ ──(Approve)──> .ai-local/knowledge/index.yaml
145
- ```
146
-
147
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
148
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
149
-
150
- ---
151
-
152
- ### Ignore (Không đưa vào Memory)
153
- Không lưu:
154
- - Trace log của một session đơn lẻ.
155
- - Temporary debugging data.
156
- - Output của một lần chạy test/scan.
157
- - Report health tạm thời của một đợt kiểm tra.
158
- - Lỗi nhỏ chỉ xảy ra một lần.
159
- - Thông tin không có khả năng tái sử dụng.
160
- - 👉 *Domain Ignore:* Các thao tác tinh chỉnh từ ngữ prompt tạm thời cho 1 task đơn lẻ.
161
-
162
- ---
163
-
164
- ### Golden Rule
165
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
166
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
167
-
168
- ---
169
-
170
-
171
-
172
- ### Pre-flight Retrieve (Trước khi thực thi)
173
- - Trước các task có tính lặp lại, debug, refactor, kiến trúc hoặc rủi ro cao:
174
- bắt buộc tra cứu:
175
- - `.agents/knowledge/index.yaml` (Shared Project Knowledge)
176
- - `.ai-local/knowledge/index.yaml` (Private Local Knowledge)
177
-
178
- - Ưu tiên sử dụng các Knowledge đang có trạng thái `Active` thuộc:
179
- - Architecture
180
- - Hard Bug
181
- - Convention
182
- - Pattern
183
- - Tech Debt Pattern
184
- - 👉 *Domain Focus:* Architecture/Pattern (vd: cấu hình provider LLM, chuẩn RAG pipeline, prompt template).
185
-
186
- - Memory chỉ đóng vai trò **Navigator (bản đồ chỉ đường)**.
187
- Không được xem Memory là Source of Truth.
188
- Luôn xác minh lại bằng source code, configuration và trạng thái hiện tại của dự án trước khi áp dụng.
189
-
190
- ---
191
-
192
- ### Learning Flow (AI tự học có kiểm soát)
193
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
194
- - Hard Bug có khả năng tái diễn.
195
- - Pattern làm việc lặp lại trong dự án.
196
- - Convention hoặc quy tắc kiến trúc mới.
197
- - Quyết định Architecture quan trọng.
198
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
199
- - 👉 *Domain Harvest:* Pattern hoặc Convention mới (vd: quy chuẩn JSON schema cho prompt, scorecard định lượng).
200
-
201
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
202
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
203
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
204
-
205
- ---
206
-
207
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
208
- Sau khi hoàn thành task:
209
- - AI đánh giá các Candidate Memory đã tạo.
210
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
211
- - Đề xuất người dùng xem xét.
212
- - Gửi yêu cầu phê duyệt thông qua:
213
- - `/learn`
214
- - `qk-project-memory`
215
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
216
-
217
- ```
218
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
219
- ```
220
-
221
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
222
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
223
-
224
- ---
225
-
226
- ### Ignore (Không đưa vào Memory)
227
- Không lưu:
228
- - Trace log của một session đơn lẻ.
229
- - Temporary debugging data.
230
- - Output của một lần chạy test/scan.
231
- - Report health tạm thời của một đợt kiểm tra.
232
- - Lỗi nhỏ chỉ xảy ra một lần.
233
- - Thông tin không có khả năng tái sử dụng.
234
- - 👉 *Domain Ignore:* Các thao tác tinh chỉnh từ ngữ prompt tạm thời cho 1 task đơn lẻ.
235
-
236
- ---
237
-
238
- ### Golden Rule
239
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
240
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
241
-
242
- ---
243
- ---
244
-
245
- ### Learning Flow (AI tự học có kiểm soát)
246
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
247
- - Hard Bug có khả năng tái diễn.
248
- - Pattern làm việc lặp lại trong dự án.
249
- - Convention hoặc quy tắc kiến trúc mới.
250
- - Quyết định Architecture quan trọng.
251
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
252
- - 👉 *Domain Harvest:* Pattern hoặc Convention mới (vd: quy chuẩn JSON schema cho prompt, scorecard định lượng).
253
-
254
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
255
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
256
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
257
-
258
- ---
259
-
260
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
261
- Sau khi hoàn thành task:
262
- - AI đánh giá các Candidate Memory đã tạo.
263
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
264
- - Đề xuất người dùng xem xét.
265
- - Gửi yêu cầu phê duyệt thông qua:
266
- - `/learn`
267
- - `qk-project-memory`
268
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
269
-
270
- ```
271
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
272
- ```
273
-
274
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
275
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
276
-
277
- ---
278
-
279
- ### Ignore (Không đưa vào Memory)
280
- Không lưu:
281
- - Trace log của một session đơn lẻ.
282
- - Temporary debugging data.
283
- - Output của một lần chạy test/scan.
284
- - Report health tạm thời của một đợt kiểm tra.
285
- - Lỗi nhỏ chỉ xảy ra một lần.
286
- - Thông tin không có khả năng tái sử dụng.
287
- - 👉 *Domain Ignore:* Các thao tác tinh chỉnh từ ngữ prompt tạm thời cho 1 task đơn lẻ.
288
-
289
- ---
290
-
291
- ### Golden Rule
292
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
293
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
294
-
295
- ---
296
- ---
297
-
298
- ### Learning Flow (AI tự học có kiểm soát)
299
- - Trong quá trình làm việc, AI được phép tự phát hiện và tạo **Candidate Memory** khi nhận thấy:
300
- - Hard Bug có khả năng tái diễn.
301
- - Pattern làm việc lặp lại trong dự án.
302
- - Convention hoặc quy tắc kiến trúc mới.
303
- - Quyết định Architecture quan trọng.
304
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
305
- - 👉 *Domain Harvest:* Pattern hoặc Convention mới (vd: quy chuẩn JSON schema cho prompt, scorecard định lượng).
306
-
307
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức.
308
- - Candidate Memory có thể lưu tạm tại: `.ai-local/candidates/`
309
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
310
-
311
- ---
312
-
313
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
314
- Sau khi hoàn thành task:
315
- - AI đánh giá các Candidate Memory đã tạo.
316
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
317
- - Đề xuất người dùng xem xét.
318
- - Gửi yêu cầu phê duyệt thông qua:
319
- - `/learn`
320
- - `qk-project-memory`
321
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
322
-
323
- ```
324
- .ai-local/candidates/ ──(Approve)──> .agents/knowledge/index.yaml
325
- ```
326
-
327
- - Project Knowledge phải được xem như tài sản kỹ thuật của dự án:
328
- - Có thể review, cập nhật, loại bỏ và có lịch sử thay đổi.
329
-
330
- ---
331
-
332
- ### Ignore (Không đưa vào Memory)
333
- Không lưu:
334
- - Trace log của một session đơn lẻ.
335
- - Temporary debugging data.
336
- - Output của một lần chạy test/scan.
337
- - Report health tạm thời của một đợt kiểm tra.
338
- - Lỗi nhỏ chỉ xảy ra một lần.
339
- - Thông tin không có khả năng tái sử dụng.
340
- - 👉 *Domain Ignore:* Các thao tác tinh chỉnh từ ngữ prompt tạm thời cho 1 task đơn lẻ.
341
-
342
- ---
343
-
344
- ### Golden Rule
345
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
346
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
347
-
348
- ---
349
- ---
350
- ---
351
- ---
352
-
353
- ## Preconditions
354
- - [ ] AI task is defined: what input → what output
355
- - [ ] LLM provider is specified (OpenAI, Anthropic, Gemini, local)
96
+ Chịu trách nhiệm thiết kế và hiện thực hóa AI Agent, RAG pipelines, prompt systems và eval criteria. Cam kết chống hallucination, tối ưu hóa token budget, quản lý context window và bảo vệ dữ liệu nhạy cảm.
356
97
 
357
98
  ---
358
99
 
359
- ## Scope & V8.2 Governed Capability Design
360
- - ✅ **Capability Packaging:** Design modular AI capabilities paired with machine-readable `capability.yaml` and `scorecard.yaml` eval rubrics. *(Note: This packaging requirement applies only to new AI-agent/RAG capabilities generated by this skill, not to general-purpose dev-tooling skills).*
361
- - ✅ **Universal 4-Folder Discipline:** Enforce clean separation of Prompt Engineering (`prompts/`), Immutable Raw Data vs Clean Processed Chunks (`data/`), Modular Micro-skills (`agents/`), and Empirical Evals (`evals/`).
362
- - ✅ **Eval-Driven Pipeline:** Move from static `Prompt -> Output` to the closed-loop V8.2 workflow:
363
- `Prompt -> Execution -> Trace Log -> Evaluation (scorecard) -> Quality Gate -> Release Report`
364
- - ✅ Design strict, deterministic system prompts with structured JSON outputs.
365
- - ✅ Sanitize user inputs before LLM ingestion (Anti-Injection).
366
-
367
- ## Non-Goals
368
- - ❌ Modify or override files located in `data/raw/` (must remain immutable ground-truth)
369
- - ❌ Create unguided AI chat loops without structured eval criteria or trace records
370
- - ❌ Trust LLM output for critical logic without quantitative verification via `qk-validation-gate`
371
- - ❌ Use raw user input directly in prompts without sanitization
372
-
373
- ---
374
-
375
- ## System Prompt Template (Required Structure)
376
-
377
- ```
378
- [ROLE]
379
- You are a [specific role]. You [specific expertise].
380
-
381
- [TASK]
382
- Your task is to [exact task description].
383
-
384
- [CONSTRAINTS]
385
- - Always [constraint 1]
386
- - Never [constraint 2]
387
- - If [edge case] → [specific action]
388
-
389
- [OUTPUT FORMAT]
390
- Return ONLY valid JSON matching this schema:
391
- {
392
- "field1": "string",
393
- "field2": number,
394
- "confidence": "high|medium|low"
395
- }
396
-
397
- [EXAMPLES]
398
- Input: [example]
399
- Output: {"field1": "...", "field2": 0, "confidence": "high"}
400
- ```
401
-
402
- ---
403
-
404
- ## Anti-Injection Checklist (Tuân thủ R-SEC-04)
405
- ```
406
- [ ] User input is wrapped in XML tags: <user_input>{input}</user_input>
407
- [ ] System instructions are separate from user content
408
- [ ] Input is validated/sanitized before injection (no raw HTML/JS)
409
- [ ] Max token limit set for user input
410
- [ ] Output is parsed as JSON (not eval'd)
411
- [ ] Confidence field in output triggers human review if "low"
412
- ```
100
+ ## Preconditions
413
101
 
414
- ---
102
+ Trước khi triển khai bất kỳ hệ thống AI nào, AI BẮT BUỘC kiểm tra:
415
103
 
416
- ## RAG Pipeline Pattern
417
- ```
418
- User Query
419
- └─ Sanitize + embed query
420
- └─ Vector search (top-K = 5)
421
- └─ Re-rank by relevance
422
- └─ Build prompt: [System] + [Retrieved Context] + [User Query]
423
- └─ LLM call
424
- └─ Validate output schema
425
- └─ Return to user
426
- ```
104
+ - [ ] Xác định AI stack từ `.agents/DEV_PROFILE.md` (LLM provider, Vector DB, Framework như LangChain/LlamaIndex/Vercel AI SDK).
105
+ - [ ] Xác định rõ Evaluation criteria: Tiêu chí đo lường độ chính xác (Relevance, Faithfulness, Hallucination rate).
106
+ - [ ] Kiểm tra chính sách dữ liệu: Có dữ liệu PII (thông tin định danh cá nhân) hoặc secrets cần sanitize trước khi gửi LLM không?
107
+ - [ ] Nếu không có phương án kiểm thử / eval criteria đo lường chất lượng AI:
108
+ **EXIT: BLOCKED**
109
+ Báo cáo user: Bắt buộc định nghĩa Eval criteria trước khi tiến hành code pipeline.
427
110
 
428
111
  ---
429
112
 
430
- ---
113
+ ## Scope
431
114
 
432
- ## Priority Order
115
+ Skill này làm:
116
+ - Thiết kế luồng RAG (Chunking, Embedding, Vector Search, Re-ranking, Context Augmentation).
117
+ - Xây dựng Agent logic (Tool use, Function calling, Structured output, Memory loop).
118
+ - Tối ưu hóa System Prompt: Vai trò, nhiệm vụ, định dạng output (JSON schema/Markdown), guardrails.
119
+ - Xây dựng Eval suite và bộ test cases đánh giá định lượng câu trả lời của AI.
120
+ - Quản lý token budget, streaming response, và cơ chế fallback khi LLM timeout/rate-limit.
433
121
 
434
- | Priority | Task | Skip Threshold |
435
- |----------|------|----------------|
436
- | P1 | System Prompt structure defined | Never |
437
- | P2 | Anti-Injection checklist applied | Never |
438
- | P3 | Output schema validated | Budget < 30% |
439
- | P4 | 4-folder discipline (prompts/data/agents/evals) set up | Budget < 50% |
440
- | P5 | Examples/few-shot added | Budget < 70% |
122
+ Skill này KHÔNG làm:
123
+ - Huấn luyện hoặc fine-tune foundation models từ đầu (pre-training).
124
+ - Viết giao diện Frontend Chatbot hoàn chỉnh (→ `qk-ui-builder` hoặc `qk-api-consumer`).
125
+ - Quản hạ tầng GPU / Kubernetes cluster chạy model (→ `qk-devops-platform`).
441
126
 
442
127
  ---
443
128
 
444
- ## Workflow
445
-
446
- ### Phase 1 — Prompt Design
447
- **Steps:**
448
- 1. Define the system prompt using the Required Structure (ROLE, TASK, CONSTRAINTS).
449
- 2. Explicitly specify the OUTPUT FORMAT as structured JSON.
450
- 3. Add few-shot EXAMPLES to guide the LLM.
129
+ ## Execution Steps
451
130
 
452
- **Decision:**
131
+ ### Step 1 — Architecture & Pipeline Design
453
132
  ```
454
- IF prompt has all sections
455
- → Confidence: HIGH → go to Phase 2
456
- ELSE
457
- EXIT: BLOCKED request missing details
133
+ Inputs: Yêu cầu từ user, Data sources, DEV_PROFILE.md
134
+ Actions:
135
+ - Lựa chọn mô hình: Direct prompting vs RAG vs Agentic tool calling.
136
+ - Thiết kế chiến lược chia nhỏ dữ liệu (Chunk size, chunk overlap) và vector embedding.
137
+ - Xác định schema cho Structured Output (JSON Schema / Zod).
138
+ Output: AI Architecture Specification
458
139
  ```
459
140
 
460
- ### Phase 2 — Security & Validation
461
- **Steps:**
462
- 1. Apply the Anti-Injection Checklist.
463
- 2. Validate that user inputs are wrapped in XML tags and sanitized.
464
- 3. Ensure the output schema contains a confidence score field.
465
-
466
- **Decision:**
141
+ ### Step 2 — Prompt Engineering & Guardrails
467
142
  ```
468
- IF all security checks pass
469
- → Confidence: HIGH → go to Phase 3
470
- ELSE
471
- EXIT: FAILED fix security gaps
143
+ Inputs: AI Architecture Specification
144
+ Actions:
145
+ - Viết System Prompt có cấu trúc rõ ràng: Role, Capabilities, Boundaries, Output Format.
146
+ - Thiết lập Guardrails: Khử jailbreak, cấm hallucination khi thiếu dữ liệu, lọc PII.
147
+ - Thiết lập vài ví dụ minh họa (Few-shot learning) nếu cần chuẩn hóa logic phức tạp.
148
+ Output: Production-grade Prompt definitions
472
149
  ```
473
150
 
474
- ### Phase 3 — Pipeline & Packaging
475
- **Steps:**
476
- 1. Map the process to the RAG Pipeline Pattern if context retrieval is needed.
477
- 2. Ensure files are organized into the 4-Folder Discipline (prompts/, data/, agents/, evals/).
478
- 3. Generate `capability.yaml` and `scorecard.yaml` for evaluation.
479
-
480
- **Decision:**
151
+ ### Step 3 — Pipeline Implementation & Integration
481
152
  ```
482
- IF packaging complete
483
- → EXIT: SUCCESS
484
- ELSE
485
- EXIT: PARTIAL note missing folder structure or evals
153
+ Inputs: Prompts, Schemas, AI SDK
154
+ Actions:
155
+ - Code pipeline tích hợp LLM client với error handling, retry backoff và fallback logic.
156
+ - Kết nối Vector store / Document retriever reranker (nếu là RAG).
157
+ - Tích hợp function calling và parse structured outputs an toàn.
158
+ Output: Functional AI Pipeline code
486
159
  ```
487
160
 
488
- ---
489
-
490
- ## Output Format
491
-
161
+ ### Step 4 — Verification & Eval Execution
492
162
  ```
493
- 🤖 AI Builder Output
494
- ─────────────────────────────────────────────────
495
- Task: [Description of the AI task]
496
- Confidence: [HIGH | MEDIUM | LOW]
497
-
498
- Design:
499
- ✅ System Prompt Template created
500
- ✅ Output JSON Schema defined
501
- ✅ [N] few-shot examples included
502
-
503
- Security & Validation:
504
- ✅ User input wrapped in <user_input> tags
505
- ✅ Anti-Injection checklist passed
506
-
507
- Packaging:
508
- ✅ 4-folder structure initialized
509
- ✅ capability.yaml & scorecard.yaml generated
510
-
511
- Exit Code: [SUCCESS | PARTIAL | BLOCKED | FAILED]
163
+ Inputs: AI Pipeline, Test dataset
164
+ Actions:
165
+ - Chạy eval test cases để đo lường: Faithfulness (độ trung thực), Retrieval recall, Latency.
166
+ - Đảm bảo token cost nằm trong ngân sách cho phép.
167
+ Exit: SUCCESS nếu vượt qua các ngưỡng benchmark chất lượng đã cam kết.
512
168
  ```
513
169
 
514
170
  ---
515
- ## Exit Codes
516
- | Code | Meaning | When |
517
- |------|---------|------|
518
- | SUCCESS | Prompt designed with all required sections, anti-injection applied | All checks passed |
519
- | PARTIAL | Prompt works but missing examples or output validation | Medium confidence result |
520
- | BLOCKED | Task or output format not defined clearly enough | Cannot design without clear spec |
521
- | FAILED | Prompt design has security vulnerability (direct injection risk) | Security gate failure |
522
171
 
523
- ---
172
+ ## Prompt Template
524
173
 
525
- ## Confidence Model
526
- | Level | Condition | Action |
527
- |-------|-----------|--------|
528
- | HIGH | Task clearly defined, output format specified, examples provided | Build directly |
529
- | MEDIUM | Task clear but output format ambiguous | Note assumption, add validation layer |
530
- | LOW | Task too vague ("make an AI assistant") | EXIT: BLOCKED — define specific task |
531
-
532
- ---
174
+ AI đọc `DEV_PROFILE.md` để biết LLM, vector DB, và pipeline framework đang dùng.
175
+ tả agent/pipeline cần build AI thiết kế đúng kiến trúc, không generic.
533
176
 
534
- ## Severity
535
- | Level | Definition | Example |
536
- |-------|-----------|---------|
537
- | CRITICAL | Prompt injection attack possible | User input directly in system prompt |
538
- | HIGH | LLM output used without validation in business logic | JSON parse without schema check |
539
- | MEDIUM | Missing examples leads to inconsistent output | No few-shot examples in prompt |
540
- | LOW | Output format not explicitly stated | Returns text instead of JSON |
177
+ ```
178
+ Build: [RAG pipeline / AI agent / prompt chain / eval suite / ...]
179
+ Mục đích: [System này làm gì, cho ai dùng]
180
+ Input: [User query / document / event / ...]
181
+ Output: [Response format, citation style, action taken]
182
+ Constraints: [Latency budget, cost/query, context window limit, PII rules]
183
+ Eval: [Thành công trông như thế nào metric cụ thể]
184
+ ```
541
185
 
542
186
  ---
543
187
 
544
- ## Evidence Format
545
- ```
546
- [SEVERITY] src/prompts/[name].ts:LINE
547
- Issue: [specific vulnerability or gap]
548
- Confidence: HIGH
549
- Fix: [specific change]
550
- ```
188
+ ### dụ theo use case:
551
189
 
552
- **Example:**
190
+ **RAG — Tài liệu nội bộ (OpenAI + pgvector + LangChain)**
553
191
  ```
554
- [CRITICAL] src/prompts/chat.ts:34
555
- Issue: User input `${userMessage}` injected directly in system promptinjection risk
556
- Confidence: HIGH
557
- Fix: Wrap in <user_input>{userMessage}</user_input> XML tags
192
+ Build: RAG pipeline cho Q&A tài liệu nội bộ công ty
193
+ Mục đích: Nhân viên hỏi về policy, quy trình, handbookAI trả lời có citation
194
+ Input: User question (text), corpus: 500 PDF files (~50k pages)
195
+ Output: { answer: string, citations: [{doc, page, excerpt}], confidence: high|low }
196
+ Constraints: Latency < 3s, cost < $0.01/query, không trả lời ngoài corpus
197
+ Eval: Faithfulness > 0.85, Answer relevance > 0.80, No hallucination on factual Q
558
198
  ```
199
+ → AI thiết kế: chunking strategy (semantic vs fixed với overlap),
200
+ embedding model (text-embedding-3-small vs large — cost vs quality),
201
+ pgvector index type (ivfflat vs hnsw), retrieval pipeline (vector search → rerank),
202
+ system prompt với grounding enforcement, citation extraction,
203
+ eval harness (RAGAS metrics), fallback khi confidence thấp.
559
204
 
560
- ---
561
-
562
- ## Retry Policy
205
+ **Agentic — Tool-calling Agent (OpenAI + LangGraph)**
563
206
  ```
564
- LLM output validation fails
565
- └─ Retry with stronger output format instruction (add explicit JSON schema)
566
- ├─ PASS on retry → EXIT: SUCCESS, note "required stronger schema enforcement"
567
- └─ FAIL on retry EXIT: PARTIAL add human review gate
568
- └─ Do NOT auto-retry more than 1 time — risk of infinite loop
207
+ Build: Customer support agent tự động xử lý refund requests
208
+ Mục đích: Giảm ticket cho support team tự xử 80% refund đơn giản
209
+ Input: Customer message qua chat widget
210
+ Output: Tự động: approve/reject refund, update order status, gửi email
211
+ Escalate: chuyển human agent nếu case phức tạp
212
+ Constraints: Không approve refund > $500 tự động, log mọi quyết định,
213
+ PII không được gửi sang LLM ngoài (dùng on-premise model)
214
+ Eval: Accuracy > 95% trên refund eligibility, escalation rate < 20%,
215
+ False approve rate = 0% cho orders > $500
569
216
  ```
217
+ → AI thiết kế: tool definitions (check_order, process_refund, escalate_to_human),
218
+ LangGraph state machine cho multi-turn conversation,
219
+ guardrails cho financial limits (rule-based, không phụ thuộc LLM),
220
+ audit trail cho mọi action, PII redaction trước khi gửi LLM,
221
+ human-in-the-loop node, eval test cases với adversarial inputs.
570
222
 
571
- ---
572
-
573
- ## Escalation Rules
223
+ **Prompt Engineering — Structured Output (Anthropic Claude)**
574
224
  ```
575
- BLOCKED: AI task not specific enough to design prompt
576
- Missing:
577
- - Specific task description (what input what output)
578
- - Output format specification (JSON schema or text structure)
579
- Questions:
580
- 1. Input cụ thể là gì? (user text, document, structured data)
581
- 2. Output cần trả về dạng gì? (JSON với field gì / plain text)
582
- Recommended Assumptions (if proceeding):
583
- - Structured JSON output with confidence field
584
- - Deny-by-default: reject off-topic requests in system prompt
225
+ Build: Pipeline extract thông tin từ hóa đơn PDF → JSON
226
+ Mục đích: Tự động hóa nhập liệu kế toán — xử lý 1000 hóa đơn/ngày
227
+ Input: PDF hóa đơn (scan hoặc digital), đa ngôn ngữ (VN, EN, JP)
228
+ Output: { vendor, date, total, currency, lineItems: [], taxAmount, invoiceNumber }
229
+ Constraints: Accuracy > 99% trên digital PDFs, > 95% trên scanned,
230
+ Latency < 5s/invoice, cost < $0.005/invoice
231
+ Eval: Field-level accuracy per invoice type, error rate theo language
585
232
  ```
233
+ → AI thiết kế: PDF parsing strategy (PyMuPDF vs vision model),
234
+ structured output với JSON schema (tool_use / response_format),
235
+ few-shot examples cho từng invoice format,
236
+ confidence scoring per field, human review queue cho low-confidence,
237
+ batch processing pipeline, cost tracking per document type,
238
+ A/B test prompt versions.
586
239
 
587
- ---
588
-
589
- ## Handoff Contract
590
- ### Consumes
591
- ```json
592
- {
593
- "from": "user",
594
- "required_fields": ["task_description", "input_type", "output_format"],
595
- "optional_fields": ["examples", "llm_provider", "max_tokens"]
596
- }
240
+ **Eval Suite — Đánh giá AI system hiện có**
597
241
  ```
598
- ### Produces
599
- ```json
600
- {
601
- "to": "user or qk-validation-gate",
602
- "output_fields": ["system_prompt", "output_schema", "anti_injection_checklist", "exit_code"]
603
- }
242
+ Build: Eval pipeline cho RAG system đang chạy production
243
+ Mục đích: Detect regression khi thay đổi prompt hoặc retrieval config
244
+ Input: Golden dataset: 200 Q&A pairs có ground truth answers
245
+ Output: Eval report: faithfulness, relevance, correctness per category,
246
+ comparison vs baseline version
247
+ Constraints: Eval phải chạy trong CI/CD, kết quả trong < 10 phút
248
+ Eval: Chính eval này cần được validate bằng human judgment sample
604
249
  ```
605
-
606
- ---
607
-
250
+ → AI thiết kế: RAGAS framework setup, golden dataset format,
251
+ LLM-as-judge prompt design (với rubric rõ ràng),
252
+ metric thresholds cho CI gate (fail build nếu faithfulness < 0.80),
253
+ regression detection (compare vs previous run),
254
+ human calibration workflow cho judge prompts.