ai-developer-skill-os 9.1.2 → 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 +37 -19
  5. package/.agents/registry/index.yaml +59 -13
  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 -377
  10. package/.agents/skills/qk-access-policy/SKILL.md +98 -473
  11. package/.agents/skills/qk-agent-observability/SKILL.md +3 -439
  12. package/.agents/skills/qk-ai-builder/SKILL.md +132 -565
  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 -456
  17. package/.agents/skills/qk-bug-resolution/SKILL.md +128 -561
  18. package/.agents/skills/qk-code-review/SKILL.md +142 -420
  19. package/.agents/skills/qk-context-loader/SKILL.md +99 -471
  20. package/.agents/skills/qk-data-engineer/SKILL.md +119 -340
  21. package/.agents/skills/qk-data-lifecycle/SKILL.md +89 -488
  22. package/.agents/skills/qk-db-optimizer/SKILL.md +102 -488
  23. package/.agents/skills/qk-design-system-engineering/SKILL.md +76 -461
  24. package/.agents/skills/qk-devops-platform/SKILL.md +77 -463
  25. package/.agents/skills/qk-docs/SKILL.md +88 -494
  26. package/.agents/skills/qk-engineering-standard/SKILL.md +4 -588
  27. package/.agents/skills/qk-fe-api-integration/SKILL.md +343 -343
  28. package/.agents/skills/qk-fe-api-integration/evals/scorecard.yaml +29 -29
  29. package/.agents/skills/qk-feature-delivery/SKILL.md +137 -445
  30. package/.agents/skills/qk-feature-delivery/evals/scorecard.yaml +1 -1
  31. package/.agents/skills/qk-frontend-architecture/SKILL.md +5 -479
  32. package/.agents/skills/qk-help/evals/scorecard.yaml +13 -13
  33. package/.agents/skills/qk-orchestrator/SKILL.md +63 -502
  34. package/.agents/skills/qk-orchestrator/references/routing-table.md +10 -14
  35. package/.agents/skills/qk-product-specification/SKILL.md +70 -479
  36. package/.agents/skills/qk-production-release/SKILL.md +80 -537
  37. package/.agents/skills/qk-project-audit/SKILL.md +174 -0
  38. package/.agents/skills/qk-project-bootstrap/SKILL.md +243 -471
  39. package/.agents/skills/qk-project-health/SKILL.md +97 -496
  40. package/.agents/skills/qk-project-memory/SKILL.md +76 -21
  41. package/.agents/skills/qk-refactor/SKILL.md +167 -384
  42. package/.agents/skills/qk-security-audit/SKILL.md +141 -463
  43. package/.agents/skills/qk-security-audit/capability.yaml +1 -2
  44. package/.agents/skills/qk-system-evolution/SKILL.md +343 -343
  45. package/.agents/skills/qk-system-evolution/evals/scorecard.yaml +26 -26
  46. package/.agents/skills/qk-test-engineering/SKILL.md +119 -509
  47. package/.agents/skills/qk-ui-audit/SKILL.md +73 -537
  48. package/.agents/skills/qk-ui-builder/SKILL.md +521 -482
  49. package/.agents/skills/qk-ui-system-builder/SKILL.md +68 -514
  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 -603
  54. package/.agents/skills/qk-web-quality-gate/SKILL.md +85 -463
  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-data-engineer
4
- version: 9.1.0
4
+ version: 9.2.0
5
5
  status: stable
6
- description: "Universal Data Engineering Skill Tự động thích nghi với project context, áp dụng các best practices (Idempotency, Data Quality, Lineage, Security) không giới hạn tech stack."
6
+ description: "Thiết kế implement data pipeline với best practices: idempotency, data quality gate, lineage, incremental processing. Dùng skill này khi user nhắc đến: data pipeline, etl, elt, dbt, dbt model, airflow dag, spark job, medallion architecture, data quality, incremental load, schema evolution, backfill, data warehouse — kể cả khi chỉ nói \"load data từ X sang Y\"."
7
7
  platforms: [antigravity, claude-code, cursor, windsurf, kilo-code]
8
8
 
9
9
  # ── V9: Classification ─────────────────────────────────────
@@ -24,16 +24,19 @@ complexity:
24
24
  has_breaking_change: false
25
25
 
26
26
  triggers:
27
- - "data engineer"
27
+ - "data pipeline"
28
28
  - "etl"
29
29
  - "elt"
30
- - "data pipeline"
30
+ - "dbt"
31
31
  - "dbt model"
32
- - "spark job"
33
32
  - "airflow dag"
34
- - "data quality gate"
35
- - "medallion"
36
- - "iceberg"
33
+ - "spark job"
34
+ - "medallion architecture"
35
+ - "data quality"
36
+ - "incremental load"
37
+ - "schema evolution"
38
+ - "backfill"
39
+ - "data warehouse"
37
40
 
38
41
  selection:
39
42
  priority: high
@@ -54,7 +57,6 @@ tools:
54
57
  related_skills:
55
58
  - qk-data-lifecycle
56
59
  - qk-db-optimizer
57
- - qk-validation-gate
58
60
 
59
61
  knowledge_scope:
60
62
  owns:
@@ -103,372 +105,149 @@ exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
103
105
 
104
106
  > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
105
107
 
106
- ---
107
-
108
- ## Memory Workflow (Universal Project Knowledge V1 Protocol)
109
-
110
- ### 0. Self-Init Protocol (Khởi Tạo Bộ Nhớ Local & Gitignore)
111
- - 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:
112
- - **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.
113
- - **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.
114
-
115
- ---
116
-
117
- ### Pre-flight Retrieve (Trước khi thực thi)
118
- - Trước các task có tính lặp lại, debug, refactor, kiến trúc hoặc rủi ro cao:
119
- bắt buộc tra cứu:
120
- - `.ai-local/knowledge/index.yaml` (Private Local Knowledge)
121
-
122
- - Ưu tiên sử dụng các Knowledge đang có trạng thái `Active` thuộc:
123
- - Architecture (vd: Lakehouse layout, Medallion structure, storage prefixes)
124
- - Hard Bug (vd: API pagination loss, composite keys mismatch, partition pruning bug)
125
- - Convention (vd: naming snake_case, schema compatibility rules)
126
- - Pattern (vd: Ingestion template, Quality Gate assertions)
127
- - Tech Debt Pattern
128
-
129
- - Memory chỉ đóng vai trò **Navigator (bản đồ chỉ đường)**. Không được xem Memory là Source of Truth. 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.
130
-
131
- ---
132
-
133
- ### Learning Flow (AI tự học có kiểm soát)
134
- - 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:
135
- - Hard Bug có khả năng tái diễn (vd: lỗi sort watermark khi nạp gia tăng).
136
- - Pattern làm việc lặp lại trong dự án (vd: template contract JSON, schema DDL, DAG wrapper).
137
- - Convention hoặc quy tắc kiến trúc mới.
138
- - Quyết định Architecture quan trọng.
139
- - Tech Debt Pattern hoặc Code Smell có tính hệ thống.
140
-
141
- - Candidate Memory chỉ là bản nháp quan sát, chưa phải tri thức chính thức, lưu tạm tại: `.ai-local/candidates/`
142
- - AI không được tự động Promote Candidate Memory thành Project Knowledge.
143
-
144
- ---
145
-
146
- ### Post-flight Harvest (Đề xuất → Phê duyệt)
147
- Sau khi hoàn thành task:
148
- - AI đánh giá các Candidate Memory đã tạo.
149
- - Nếu phát hiện tri thức có giá trị tái sử dụng:
150
- - Đề xuất người dùng xem xét.
151
- - Gửi yêu cầu phê duyệt thông qua `/learn` hoặc `qk-project-memory`.
152
- - Chỉ sau khi được phê duyệt, Candidate Memory mới được chuyển thành Knowledge chính thức:
153
-
154
- ```
155
- .ai-local/candidates/ ──(Approve)──> .ai-local/knowledge/index.yaml
156
- ```
157
-
158
- ---
159
-
160
- ### Ignore (Không đưa vào Memory)
161
- Không lưu:
162
- - Trace log của một session đơn lẻ.
163
- - Temporary debugging data / raw sample payloads.
164
- - Output của một lần chạy test/scan/quality gate tạm thời.
165
- - Lỗi nhỏ cú pháp SQL/Python chỉ xảy ra một lần.
166
- - Thông tin không có khả năng tái sử dụng.
167
-
168
- ---
169
-
170
- ### Golden Rule
171
- > **AI được phép học, nhưng không được tự quyết định tri thức chính thức.**
172
- > **AI quan sát → Đề xuất → Con người phê duyệt → Dự án tiến hóa.**
173
-
174
- ---
175
-
176
- ## Source-of-Truth Hierarchy
177
-
178
- Khi có sự mâu thuẫn thông tin giữa các nguồn, AI **BẮT BUỘC** giải quyết theo thứ tự ưu tiên giảm dần:
179
-
180
- 1. **Explicit user instruction** (Chỉ thị trực tiếp từ người dùng trong phiên làm việc)
181
- 2. **Current production / project configuration** (Cấu hình thực tế đang chạy: YAML, JSON, env)
182
- 3. **Current source code + tests** (Mã nguồn và bài kiểm thử đang có trong repository)
183
- 4. **Current project documentation** (Tài liệu đặc tả, bàn giao kỹ thuật cập nhật của dự án)
184
- 5. **Approved project knowledge / memory** (`.ai-local/knowledge/index.yaml`)
185
- 6. **Generic engineering best practices** (Tiêu chuẩn kỹ thuật chung của ngành)
186
- 7. **Model inference** (Suy luận ngầm định của mô hình AI)
187
-
188
- > ⚠️ *Never let a lower-priority source override a higher-priority source.*
108
+ Chịu trách nhiệm thiết kế và hiện thực hóa các đường ống dữ liệu (Data Pipelines: ETL/ELT) tuân thủ nghiêm ngặt 4 trụ cột kỹ thuật dữ liệu: **Idempotency (Tính lũy thừa) → Data Quality Gate (Cổng kiểm tra chất lượng) → Lineage (Nguồn gốc luồng dữ liệu) → Incremental Processing (Xử lý gia tăng)**.
189
109
 
190
110
  ---
191
111
 
192
112
  ## Preconditions
193
113
 
194
- ### Required for Implementation
195
- - [ ] Xác định được mục tiêu hoặc phạm vi task (New pipeline, debug, modify, optimize, v.v.).
196
- - [ ] Đã thực hiện Pre-flight Inspection phát hiện Tech Stack, Architecture và Conventions của dự án.
114
+ Trước khi xây dựng hoặc cập nhật pipeline dữ liệu, AI BẮT BUỘC kiểm tra:
197
115
 
198
- ### Required When Applicable
199
- - [ ] Data Contract / Schema DDL (Bắt buộc khi implement/modify pipeline; Không bắt buộc nếu task là discovery/tạo contract mới).
200
- - [ ] Business Grain & Primary Key (Khi thiết kế Data Model hoặc Incremental pipeline).
201
- - [ ] Incremental Cursor / Watermark strategy (Khi xây dựng luồng nạp gia tăng).
116
+ - [ ] Xác định Data stack từ `.agents/DEV_PROFILE.md` (Orchestrator: Airflow/Prefect, Warehouse: BigQuery/Snowflake/Postgres, Transformation: dbt/Spark/Pandas).
117
+ - [ ] Xác định chiến lược Idempotency (Upsert, Merge, Partition overwrite, Watermarking).
118
+ - [ ] Xác định ngưỡng Data Quality Gates (Null check, Uniqueness, Volume anomaly, Freshness).
119
+ - [ ] Nếu pipeline không chế Idempotent (chạy lại gây duplicate dữ liệu) hoặc thiếu validation:
120
+ → **EXIT: BLOCKED**
121
+ → Báo cáo user yêu cầu xác định deduplication key / partition strategy trước khi code.
202
122
 
203
123
  ---
204
124
 
205
- ## Scope & Core Principles
206
-
207
- ### Core Principles (Thứ tự ưu tiên cốt lõi)
208
- 1. **Correctness & Data Integrity**: Dữ liệu phải phản ánh chính xác nghiệp vụ. Không đánh đổi tính đúng đắn để lấy tốc độ.
209
- 2. **Idempotency & Fault Tolerance**: Mọi pipeline phải an toàn khi chạy lại nhiều lần (re-run không nhân bản dữ liệu, không sinh rác).
210
- 3. **Data Quality**: Luôn có chốt chặn kiểm tra tự động trước khi publish dữ liệu.
211
- 4. **Schema & Contract Discipline**: Schema and Data Contract are explicit compatibility boundaries and must be versioned when changed.
212
- 5. **Observability & Lineage**: Mọi bản ghi phải truy vết được nguồn gốc theo cơ chế lineage của dự án.
213
- 6. **Security & Privacy**: Apply the project's approved privacy/protection mechanism (masking, tokenization, encryption); never expose sensitive data or credentials.
214
- 7. **Performance & Cost**: Tối ưu partitioning, clustering, query plan nhưng không phá vỡ tính đúng đắn.
215
- 8. **Maintainability & Simplicity**: Code tường minh, dễ đọc và dễ bàn giao.
216
-
217
- ### This skill does:
218
- - ✅ Tự động thích nghi với hệ sinh thái dữ liệu của dự án (Spark, dbt, Airflow, Dagster, Snowflake, Iceberg, BigQuery...).
219
- - ✅ Thiết kế và xây dựng Data Pipelines (ETL/ELT) an toàn, idempotent.
220
- - ✅ Thiết kế Data Modeling (Medallion, Star Schema, OBT) phù hợp workload.
221
- - ✅ Quản lý Data Contracts, Schema Evolution và phát hiện Breaking Changes.
222
- - ✅ Cài đặt Data Quality Gates với Severity Matrix (CRITICAL, ERROR, WARNING, INFO).
223
- - ✅ Tối ưu hiệu năng truy vấn, compaction, layout và tài nguyên compute.
224
- - ✅ Debugging và điều tra sự cố dữ liệu (Lineage, Snapshot, PIR).
225
-
226
- ### This skill does NOT:
227
- - ❌ Tự ý chọn tech stack mới nếu dự án chưa dùng hoặc chưa có yêu cầu.
228
- - ❌ Sửa ngầm logic tính toán hoặc schema production mà không có Impact Analysis.
229
- - ❌ Bỏ qua Data Quality Gate chỉ để pipeline "chạy xanh".
230
- - ❌ Tuyên bố "Production-Ready" khi chỉ mới vượt qua unit test ở môi trường local.
125
+ ## Scope
231
126
 
232
- ---
233
-
234
- ## Rules & Decision Rules
127
+ ✅ Skill này làm:
128
+ - Thiết kế và cài đặt dbt models (Staging → Intermediate → Marts), Spark jobs, Airflow DAGs.
129
+ - Cấu hình chiến lược Incremental load (Timestamp watermarking, CDC, Partition replacement).
130
+ - Thiết lập Data Quality Assertions (dbt tests, Great Expectations, Soda checks).
131
+ - Quản lý Schema Evolution (thay đổi cột an toàn, chống silent failure / schema drift).
132
+ - Viết tài liệu Lineage và từ điển dữ liệu (Data Dictionary).
235
133
 
236
- ### Rules Bắt Buộc
237
- - **No Stack Hallucination**: Không tự chọn dbt/Spark/Airflow nếu project chưa sử dụng.
238
- - **No Schema Guessing**: Schema từ Data Contract/DDL Source of Truth, không đoán mò từ sample JSON.
239
- - **Authoritative Path & Location Builder**: Ưu tiên sử dụng cơ chế sinh đường dẫn/vị trí lưu trữ chính thức của dự án. Tuyệt đối không tự bịa hoặc nối chuỗi path thủ công khi dự án đã cung cấp module chuẩn.
240
- - ❌ **Preserve Authoritative Lineage**: Tuân thủ hoặc triển khai cơ chế lineage chuẩn của dự án (OpenLineage, metadata columns, audit tables). Nếu dự án chưa có, đề xuất chiến lược lineage tối thiểu phù hợp với nền tảng.
241
- - ❌ **No Silent Behavior Mutation**: Thay đổi nghiệp vụ phải kèm migration strategy và impact analysis.
242
-
243
- ### Decision Rules
244
- - **IF** project has existing orchestration framework **→ USE IT**.
245
- - **IF** project has existing Data Contracts **→ CONTRACT IS SOURCE OF TRUTH**.
246
- - **IF** task requires incremental processing **→** Xác định Watermark & Dedup; **KHÔNG** sort theo watermark khi phân trang API.
247
- - **IF** transformation has both Deduplication & PII Masking **→** Áp dụng các phép biến đổi theo yêu cầu hợp đồng và quy tắc bảo mật; khi cần cả hai, **BẮT BUỘC** duy trì thứ tự phụ thuộc (khử trùng lặp trước khi che thông tin để không làm mất khóa định danh).
248
- - **IF** architecture choice materially affects data correctness, security, cost, downstream compatibility, or production architecture **→ BLOCKED / request decision**.
249
- - **ELSE** (Quyết định kiến trúc nhỏ/không gây rủi ro phá vỡ) **→** Chọn phương án ít gây bất ngờ nhất, đồng bộ với convention dự án và ghi rõ lý do (rationale).
250
- - **IF** requested change can break downstream consumers **→** Thực hiện Impact Analysis trước khi thay đổi.
134
+ Skill này KHÔNG làm:
135
+ - Thiết kế UI Dashboard hay biểu đồ trên web app (→ `qk-ui-builder`).
136
+ - Viết CRUD REST API cho web backend thông thường (→ `qk-api-lifecycle`).
137
+ - Quản hạ tầng cụm máy chủ vật / Kafka cluster (→ `qk-devops-platform`).
251
138
 
252
139
  ---
253
140
 
254
- ## Priority Order
255
-
256
- | Priority | Task | Skip Threshold |
257
- |----------|------|----------------|
258
- | P1 | Pre-flight Stack, Convention & Contract Discovery | Never |
259
- | P2 | Schema Validation & Breaking Change Check | Never |
260
- | P3 | Idempotency & Re-run Safety Design | Never |
261
- | P4 | Data Quality Assertions (Row integrity, required fields, key uniqueness) | Never |
262
- | P5 | Security & Privacy Protections Applied | Never |
263
- | P6 | Layout Tuning (Partitioning/Clustering/Compaction) | When applicable |
141
+ ## Execution Steps
264
142
 
265
- ---
266
-
267
- ## Execution Backbone & Workflow Router
268
-
269
- ### Execution Backbone
270
- Mọi yêu cầu Data Engineering đều được thực thi theo chuỗi xử lý bất biến sau:
271
-
272
- ```text
273
- USER REQUEST
274
-
275
- TASK CLASSIFICATION
276
-
277
- PROJECT CONTEXT (Pre-flight Inspection)
278
-
279
- SOURCE-OF-TRUTH RESOLUTION
280
-
281
- RULE RESOLUTION
282
-
283
- WORKFLOW ROUTER
284
-
285
- COMMON GATES (Discover ➔ Design ➔ Impact Analysis ➔ Implement ➔ Test ➔ QA ➔ Verify ➔ Report)
143
+ ### Step 1 — Source Analysis & Data Contract
286
144
  ```
287
-
288
- ---
289
-
290
- ### Workflow Router
291
-
292
- Khi phân loại xong task, AI điều hướng vào workflow chuyên biệt:
293
-
294
- #### 1. `NEW_PIPELINE` / `etl`
295
- 1. **Discover**: Đọc source schema, stack, existing storage conventions.
296
- 2. **Design**: Xác định source, target, partitioning, load strategy (overwrite_partition, upsert, append).
297
- 3. **Contract**: Tạo hoặc cập nhật Data Contract (fields, types, nullability, PII).
298
- 4. **Implement**: Viết transformation (bảo toàn thứ tự dedup/masking) và bảo đảm Idempotency.
299
- 5. **Quality & Test**: Khai báo assertions và viết unit tests.
300
- 6. **Verify**: Chạy tests, đánh giá trạng thái xác minh.
301
-
302
- #### 2. `MODIFY_PIPELINE`
303
- 1. **Inspect**: Đọc code hiện tại, DAG dependencies, configs và tests liên quan.
304
- 2. **Impact Analysis**: Xác định downstream tables, views, dashboards bị ảnh hưởng.
305
- 3. **Compatibility**: Kiểm tra breaking changes đối với schema hiện hữu.
306
- 4. **Implement**: Áp dụng thay đổi tối thiểu, cập nhật contracts & unit tests.
307
- 5. **Quality Gate**: Chạy lại toàn bộ test suite để chống regression.
308
-
309
- #### 3. `DEBUG` / `INCIDENT`
310
- 1. **Reproduce**: Tái hiện lỗi với payload hoặc điều kiện lỗi.
311
- 2. **Isolate**: Xác định tầng lỗi (Ingest, Staging, Transform, Quality Gate).
312
- 3. **Inspect**: Tra cứu logs, lineage, snapshot metadata, raw landing payload.
313
- 4. **Root Cause**: Phân tích nguyên nhân gốc rễ (pagination drift, timezone, null pointer).
314
- 5. **Fix & Regression Test**: Sửa lỗi phạm vi tối thiểu, bổ sung regression test và báo cáo PIR.
315
-
316
- #### 4. `DATA_MODELING`
317
- 1. **Query Patterns**: Phân tích nhu cầu đọc và SLA của consumer/dashboard.
318
- 2. **Paradigm**: Chọn mô hình phù hợp (Medallion, Star Schema, OBT, Data Vault).
319
- 3. **Grain & Keys**: Định nghĩa Primary Key, Business Key, Foreign Keys và Partitioning key.
320
- 4. **Contract & DDL**: Sinh contract và DDL tường minh.
321
-
322
- #### 5. `DATA_QUALITY`
323
- 1. **Asset Profiling**: Liệt kê các bảng và trường cần giám sát.
324
- 2. **Severity Matrix**: CRITICAL (dừng pipeline), ERROR (chặn publish), WARNING (alert), INFO (log metric).
325
- 3. **Assertions**: Cài đặt kiểm tra toàn vẹn dòng (row integrity), trường bắt buộc (not_null), khóa duy nhất (unique), và mở rộng freshness/referential/consistency.
326
-
327
- #### 6. `SCHEMA_EVOLUTION`
328
- 1. **Version Diff**: So sánh Schema V_Old vs V_New.
329
- 2. **Classify**: Phân loại Backward Compatible vs Breaking Change.
330
- 3. **Migration Plan**: Viết migration script, xử lý default values và nâng `contract_version`.
331
- 4. **Downstream Validation**: Kiểm tra tính tương thích của views/queries.
332
-
333
- #### 7. `BACKFILL` / `REPLAY`
334
- 1. **Scope & Window**: Xác định time window (from_date ➔ to_date) và partitions mục tiêu.
335
- 2. **Isolation**: Dùng partition replacement hoặc atomic merge để không ảnh hưởng dữ liệu đang vận hành.
336
- 3. **Reconcile**: Đối chiếu tổng số dòng và giá trị metric trước/sau backfill.
337
-
338
- #### 8. `OPTIMIZE`
339
- 1. **Profile**: Đo thời gian chạy, bytes scanned, memory skew, partition layout.
340
- 2. **Bottlenecks**: Tìm full-table scans, shuffle spills, small files problem.
341
- 3. **Tune**: Rewrite queries (pushdown filters), optimize layout (compaction, Z-Order), tune executor configs.
342
- 4. **Verify Correctness**: Đảm bảo kết quả dữ liệu TRƯỚC và SAU tối ưu hoàn toàn trùng khớp.
343
-
344
- ---
345
-
346
- ## Output Format
347
-
348
- ```markdown
349
- 🔧 Data Engineer Task Summary
350
- ─────────────────────────────────────────────────
351
- Scope: [Mô tả ngắn gọn phạm vi: ETL / Debug / Quality Gate / Modeling / Optimize]
352
- Tech Stack: [Ecosystem & công cụ đã detect/sử dụng]
353
- Target Tables: [Danh sách bảng/datasets liên quan]
354
-
355
- 📋 Architecture & Assumptions:
356
- - Architecture: [Medallion / Star Schema / OBT / Staging-Mart]
357
- - Load Strategy: [Overwrite Partition / Upsert / Append]
358
- - Assumptions: [Các giả định kỹ thuật & nghiệp vụ đã áp dụng]
359
-
360
- Changes Applied:
361
- ✅ [Action 1]: [Chi tiết những gì đã làm, file đã sửa/tạo]
362
- ✅ [Action 2]: [Chi tiết về xử lý logic / contract / transform]
363
-
364
- 📊 Data Integrity & Quality:
365
- - Idempotency: [Cơ chế đảm bảo chạy lại an toàn]
366
- - Quality Gate: [Các assertions đã khai: row integrity, required fields, unique, freshness, referential]
367
- - Lineage: [Cơ chế lineage áp dụng: OpenLineage / audit columns / metadata]
368
-
369
- ✅ Verification Status:
370
- - Unit Tests: [Pass / N/A / X tests run]
371
- - Quality Gate: [Passed / Configured]
372
- - Environment: [Local Unit Verified / Real Infra Pending]
373
-
374
- ⚠️ Risks, Trade-offs & Next Steps:
375
- - [Các lưu ý về performance, schema compatibility hoặc việc cần test trên cụm thật]
145
+ Inputs: Yêu cầu pipeline từ user, Source schema, Volume ước tính
146
+ Actions:
147
+ - Phân tích cấu trúc nguồn dữ liệu (Source freshness, Primary keys, Update timestamps).
148
+ - Thỏa thuận Data Contract giữa nhà cung cấp dữ liệu và Data Warehouse.
149
+ - Xác định partition strategy (theo date/hour) và clustering keys.
150
+ Output: Pipeline Architectural Plan & Contract
376
151
  ```
377
152
 
378
- ---
379
-
380
- ## Exit Codes
381
-
382
- | Code | Meaning | When |
383
- |------|---------|------|
384
- | SUCCESS | Pipeline/Model/Fix implemented, verified, QA passed | All checks passed |
385
- | PARTIAL | Code done but verification on real infra is pending | Needs live cluster run |
386
- | BLOCKED | Required information remains unavailable after reasonable project inspection | Missing critical specifications |
387
- | FAILED | Quality gate failed, breaking change without migration | Security/Integrity violation |
388
-
389
- ---
390
-
391
- ## Confidence Model
392
-
393
- | Level | Condition | Action |
394
- |-------|-----------|--------|
395
- | HIGH | Stack detected, contract exists, clear source-target mapping | Implement end-to-end |
396
- | MEDIUM | Stack clear but contract or grain partially undefined | State assumptions, proceed with least-surprising option |
397
- | LOW / UNKNOWN | Source API/schema completely unknown | Discovery first ➔ Inspect repo/sources before blocking |
398
-
399
- ---
400
-
401
- ## Severity
402
-
403
- | Level | Definition | Action |
404
- |-------|-----------|--------|
405
- | CRITICAL | Pipeline failure, data loss, duplicate primary keys | Dừng pipeline ngay lập tức |
406
- | ERROR | Schema mismatch, null in required column | Chặn publish sang tầng tiếp theo |
407
- | WARNING | Freshness SLA breach, statistical value drift | Bắn alert nhưng cho phép publish |
408
- | INFO | Metadata metric logging, row count audit | Ghi log theo dõi |
409
-
410
- ---
411
-
412
- ## Evidence Format
413
-
153
+ ### Step 2 — Transformation & Idempotent Logic
414
154
  ```
415
- [SEVERITY] path/to/pipeline_or_query.py:LINE
416
- Issue: [specific data issue or failure mode]
417
- Confidence: HIGH
418
- Fix: [specific change / assertion]
155
+ Inputs: Contract, Tech stack
156
+ Actions:
157
+ - Viết code transformation (SQL/Python/PySpark) chia theo các tầng Medallion (Bronze/Silver/Gold).
158
+ - Đảm bảo logic tính toán có tính lũy thừa (Idempotent): rerun nhiều lần không thay đổi kết quả.
159
+ - Tối ưu hóa câu query xử lý dữ liệu lớn (Pruning partitions, tránh full table scan).
160
+ Output: Transformation scripts & Models
419
161
  ```
420
162
 
421
- **Example:**
163
+ ### Step 3 — Quality Gates & Anomaly Checks
422
164
  ```
423
- [CRITICAL] src/jobs/transform_silver.py:45
424
- Issue: Deduplication performed AFTER PII masking, losing original identity key
425
- Confidence: HIGH
426
- Fix: Reorder steps: Cast -> Deduplicate -> PII Masking -> Lineage
165
+ Inputs: Transformation scripts
166
+ Actions:
167
+ - Thêm tests bắt buộc: Not null, Unique, Referential integrity (Foreign keys).
168
+ - Thêm row count checks freshness sensors để phát hiện dữ liệu rỗng bất thường.
169
+ - Cấu hình cơ chế cảnh báo (Alert) khi chất lượng dữ liệu không đạt chuẩn.
170
+ Output: Test suite & Monitoring rules
427
171
  ```
428
172
 
429
- ---
430
-
431
- ## Retry Policy
173
+ ### Step 4 — Verification & Dry Run
432
174
  ```
433
- Quality Gate or Pipeline execution fails
434
- └─ Inspect failure layer & error logs
435
- ├─ Data schema mismatch Update contract or fix mapping → Retry 1 time
436
- └─ Data corruption in source EXIT: FAILED Alert human engineer
175
+ Inputs: Pipeline code & Quality tests
176
+ Actions:
177
+ - Kiểm tra pháp, compile SQL/dbt models.
178
+ - Xác nhận kế hoạch backfill dữ liệu lịch sử an toàn.
179
+ Exit: SUCCESS nếu pipeline bảo đảm tính idempotent và pass mọi quality gates.
437
180
  ```
438
181
 
439
182
  ---
440
183
 
441
- ## Escalation Rules
184
+ ## Prompt Template
185
+
186
+ AI đọc `DEV_PROFILE.md` để biết data stack (pipeline/warehouse/format/broker).
187
+ Mô tả pipeline cần làm — AI sẽ thiết kế theo đúng tool đang dùng.
188
+
442
189
  ```
443
- BLOCKED: Critical architectural decision needed or breaking schema detected
444
- Missing:
445
- - Source-to-target field mapping
446
- - Migration plan for breaking schema change
447
- Questions:
448
- 1. Trường mới/đổi kiểu migration plan chưa?
449
- 2. Quyết định kiến trúc này có ảnh hưởng tới hạ tầng production không?
450
- Recommended Assumptions (if proceeding with minor choice):
451
- - Choose least-surprising project-consistent option
452
- - Document rationale in summary report
190
+ Pipeline: [Tên pipeline / DAG / job]
191
+ Source: [Nguồn dữ liệu: DB / API / file / stream / ...]
192
+ Destination: [Đích: warehouse / data lake / another DB / ...]
193
+ Frequency: [Batch daily / hourly / streaming / event-driven]
194
+ Volume: [Số rows / GB ước tính mỗi lần chạy]
195
+ SLA: [Data phải mặt lúc mấy giờ? Latency tối đa?]
196
+ Rules: [Idempotency, dedup, schema evolution, data quality gate]
453
197
  ```
454
198
 
455
199
  ---
456
200
 
457
- ## Handoff Contract
201
+ ### dụ theo tech stack:
458
202
 
459
- ### Consumes
460
- ```json
461
- {
462
- "from": "user or qk-orchestrator",
463
- "required_fields": ["task"],
464
- "optional_fields": ["source", "target", "contract_path", "load_strategy", "profile"]
465
- }
203
+ **dbt + BigQuery + Airflow**
204
+ ```
205
+ Pipeline: daily_order_metrics
206
+ Source: PostgreSQL (production DB) — bảng orders, order_items, products
207
+ Destination: BigQuery dataset: mart — table: fct_order_metrics
208
+ Frequency: Daily batch lúc 3AM UTC
209
+ Volume: ~50k rows/ngày, tăng trưởng 10%/tháng
210
+ SLA: Data sẵn sàng trước 6AM UTC cho dashboard
211
+ Rules: - Idempotent: re-run ngày bất kỳ cho kết quả giống nhau
212
+ - Không load ngày hiện tại (incomplete data)
213
+ - Alert nếu row count giảm > 20% so với 7 ngày trước
214
+ - Schema thay đổi ở source → fail loud, không silent corrupt
466
215
  ```
216
+ → AI thiết kế: dbt model layers (staging → intermediate → mart),
217
+ Airflow DAG với sensor check source freshness, incremental model strategy
218
+ (merge key = order_id + date), dbt test (not_null, unique, accepted_values),
219
+ partition by date trên BQ để tránh full scan, audit log table.
467
220
 
468
- ### Produces
469
- ```json
470
- {
471
- "to": "user or qk-validation-gate",
472
- "output_fields": ["pipeline_code", "contract_spec", "quality_gate_config", "exit_code"]
473
- }
221
+ **Spark + Delta Lake + Databricks**
222
+ ```
223
+ Pipeline: clickstream_sessionization
224
+ Source: Kafka topic: user.clicks ~5M events/ngày
225
+ Destination: Delta Lake: /data/gold/user_sessions
226
+ Frequency: Micro-batch mỗi 5 phút (Structured Streaming)
227
+ Volume: ~3.5GB/ngày raw
228
+ SLA: Session data available trong vòng 10 phút kể từ event
229
+ Rules: - Session timeout: 30 phút không activity
230
+ - Exactly-once processing
231
+ - Backfill safe (có thể re-process từ Kafka offset)
232
+ ```
233
+ → AI thiết kế: Spark Structured Streaming với watermark cho late data,
234
+ session window aggregation, Delta Lake MERGE cho upsert sessions,
235
+ checkpoint location strategy, schema enforcement + evolution,
236
+ Z-ORDER optimization cho query patterns, monitoring (lag metrics).
237
+
238
+ **Airbyte + dbt + Snowflake**
239
+ ```
240
+ Pipeline: crm_sync — Salesforce → Snowflake → mart
241
+ Source: Salesforce (Airbyte connector) — objects: Account, Opportunity, Contact
242
+ Destination: Snowflake RAW → STAGING → MART
243
+ Frequency: Airbyte sync mỗi 1 giờ, dbt transform mỗi 2 giờ
244
+ Volume: ~500k records total, delta ~2k/ngày
245
+ SLA: CRM data lag tối đa 3 giờ so với Salesforce
246
+ Rules: - Không xóa hard delete từ source (soft delete pattern)
247
+ - PII fields (email, phone) phải masked trong MART layer
248
+ - Lineage từ Salesforce ID phải traceable đến mart row
474
249
  ```
250
+ → AI thiết kế: Airbyte connection config + normalization settings,
251
+ dbt source freshness test, PII masking macro, soft-delete handling
252
+ (dbt snapshot vs custom), column-level lineage documentation,
253
+ Snowflake role-based access cho MART vs RAW.