ai-developer-skill-os 9.3.0 → 10.1.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 (185) hide show
  1. package/.agents/AGENTS.md +60 -40
  2. package/.agents/DEV_PROFILE.md +36 -2
  3. package/.agents/registry/graph.json +95 -342
  4. package/.agents/registry/index.yaml +61 -237
  5. package/.agents/rules/coding.md +30 -12
  6. package/.agents/rules/command-safety.md +19 -8
  7. package/.agents/rules/global.md +234 -28
  8. package/.agents/rules/prompt-compiler.md +170 -0
  9. package/.agents/skills/qk-api-data-discovery/SKILL.md +470 -0
  10. package/.agents/skills/qk-backend-data/SKILL.md +190 -0
  11. package/.agents/skills/qk-bug-resolution/SKILL.md +176 -248
  12. package/.agents/skills/qk-code-cleaner/SKILL.md +250 -0
  13. package/.agents/skills/qk-code-review/SKILL.md +126 -247
  14. package/.agents/skills/qk-devops-release/SKILL.md +145 -0
  15. package/.agents/skills/qk-feature-delivery/SKILL.md +179 -247
  16. package/.agents/skills/qk-orchestrator/SKILL.md +100 -151
  17. package/.agents/skills/qk-product-spec/SKILL.md +113 -0
  18. package/.agents/skills/qk-prompt-compiler/SKILL.md +321 -0
  19. package/.agents/skills/qk-ui-engineer/SKILL.md +137 -0
  20. package/.agents/workflows/feature-delivery.yml +1 -1
  21. package/.agents/workflows/production-release.yml +1 -1
  22. package/.agents/workflows/spec-driven-development.yml +109 -87
  23. package/CHANGELOG.md +54 -0
  24. package/README.md +125 -184
  25. package/bin/install.js +337 -329
  26. package/package.json +2 -2
  27. package/.agents/README.md +0 -90
  28. package/.agents/docs/CHI_TIET_SKILLS.md +0 -126
  29. package/.agents/docs/HUONG_DAN_SU_DUNG.md +0 -120
  30. package/.agents/docs/MIGRATION-CLEANUP-V8.1.3.md +0 -36
  31. package/.agents/docs/MIGRATION-STATUS.md +0 -35
  32. package/.agents/docs/MIGRATION-V8.md +0 -10
  33. package/.agents/docs/ROADMAP-V8.2.md +0 -78
  34. package/.agents/docs/V8-CERTIFICATION.md +0 -27
  35. package/.agents/skills/qk-access-policy/SKILL.md +0 -206
  36. package/.agents/skills/qk-access-policy/capability.yaml +0 -23
  37. package/.agents/skills/qk-access-policy/evals/scorecard.yaml +0 -36
  38. package/.agents/skills/qk-agent-observability/SKILL.md +0 -108
  39. package/.agents/skills/qk-agent-observability/capability.yaml +0 -29
  40. package/.agents/skills/qk-agent-observability/evals/scorecard.yaml +0 -29
  41. package/.agents/skills/qk-agent-observability/references/scorecard.yaml +0 -80
  42. package/.agents/skills/qk-ai-builder/SKILL.md +0 -254
  43. package/.agents/skills/qk-ai-builder/capability.yaml +0 -23
  44. package/.agents/skills/qk-ai-builder/evals/scorecard.yaml +0 -30
  45. package/.agents/skills/qk-api-consumer/SKILL.md +0 -256
  46. package/.agents/skills/qk-api-consumer/capability.yaml +0 -21
  47. package/.agents/skills/qk-api-consumer/evals/scorecard.yaml +0 -29
  48. package/.agents/skills/qk-api-lifecycle/SKILL.md +0 -251
  49. package/.agents/skills/qk-api-lifecycle/capability.yaml +0 -23
  50. package/.agents/skills/qk-api-lifecycle/evals/scorecard.yaml +0 -29
  51. package/.agents/skills/qk-bug-resolution/capability.yaml +0 -25
  52. package/.agents/skills/qk-code-review/capability.yaml +0 -23
  53. package/.agents/skills/qk-context-loader/SKILL.md +0 -198
  54. package/.agents/skills/qk-context-loader/capability.yaml +0 -23
  55. package/.agents/skills/qk-context-loader/evals/scorecard.yaml +0 -28
  56. package/.agents/skills/qk-data-engineer/SKILL.md +0 -253
  57. package/.agents/skills/qk-data-lifecycle/SKILL.md +0 -197
  58. package/.agents/skills/qk-data-lifecycle/capability.yaml +0 -23
  59. package/.agents/skills/qk-data-lifecycle/evals/scorecard.yaml +0 -29
  60. package/.agents/skills/qk-db-optimizer/SKILL.md +0 -210
  61. package/.agents/skills/qk-db-optimizer/capability.yaml +0 -22
  62. package/.agents/skills/qk-db-optimizer/evals/scorecard.yaml +0 -28
  63. package/.agents/skills/qk-design-system-engineering/SKILL.md +0 -193
  64. package/.agents/skills/qk-design-system-engineering/capability.yaml +0 -25
  65. package/.agents/skills/qk-design-system-engineering/evals/scorecard.yaml +0 -27
  66. package/.agents/skills/qk-devops-platform/SKILL.md +0 -198
  67. package/.agents/skills/qk-devops-platform/capability.yaml +0 -29
  68. package/.agents/skills/qk-devops-platform/evals/scorecard.yaml +0 -28
  69. package/.agents/skills/qk-docs/SKILL.md +0 -193
  70. package/.agents/skills/qk-docs/capability.yaml +0 -23
  71. package/.agents/skills/qk-docs/evals/scorecard.yaml +0 -27
  72. package/.agents/skills/qk-engineering-standard/SKILL.md +0 -89
  73. package/.agents/skills/qk-engineering-standard/capability.yaml +0 -23
  74. package/.agents/skills/qk-engineering-standard/evals/scorecard.yaml +0 -28
  75. package/.agents/skills/qk-engineering-standard/references/anti-patterns.md +0 -121
  76. package/.agents/skills/qk-engineering-standard/rules/backend.md +0 -122
  77. package/.agents/skills/qk-engineering-standard/rules/database.md +0 -3
  78. package/.agents/skills/qk-engineering-standard/rules/frontend.md +0 -152
  79. package/.agents/skills/qk-engineering-standard/rules/security.md +0 -3
  80. package/.agents/skills/qk-engineering-standard/rules/testing.md +0 -3
  81. package/.agents/skills/qk-fe-api-integration/SKILL.md +0 -704
  82. package/.agents/skills/qk-fe-api-integration/capability.yaml +0 -21
  83. package/.agents/skills/qk-fe-api-integration/evals/scorecard.yaml +0 -29
  84. package/.agents/skills/qk-feature-delivery/capability.yaml +0 -24
  85. package/.agents/skills/qk-frontend-architecture/SKILL.md +0 -127
  86. package/.agents/skills/qk-frontend-architecture/capability.yaml +0 -28
  87. package/.agents/skills/qk-frontend-architecture/evals/scorecard.yaml +0 -28
  88. package/.agents/skills/qk-help/SKILL.md +0 -107
  89. package/.agents/skills/qk-help/capability.yaml +0 -20
  90. package/.agents/skills/qk-help/evals/scorecard.yaml +0 -13
  91. package/.agents/skills/qk-orchestrator/capability.yaml +0 -22
  92. package/.agents/skills/qk-product-specification/SKILL.md +0 -187
  93. package/.agents/skills/qk-product-specification/capability.yaml +0 -27
  94. package/.agents/skills/qk-product-specification/evals/scorecard.yaml +0 -27
  95. package/.agents/skills/qk-production-release/SKILL.md +0 -188
  96. package/.agents/skills/qk-production-release/capability.yaml +0 -27
  97. package/.agents/skills/qk-production-release/evals/scorecard.yaml +0 -28
  98. package/.agents/skills/qk-project-audit/SKILL.md +0 -174
  99. package/.agents/skills/qk-project-bootstrap/SKILL.md +0 -372
  100. package/.agents/skills/qk-project-bootstrap/capability.yaml +0 -23
  101. package/.agents/skills/qk-project-bootstrap/evals/scorecard.yaml +0 -28
  102. package/.agents/skills/qk-project-health/SKILL.md +0 -202
  103. package/.agents/skills/qk-project-health/capability.yaml +0 -23
  104. package/.agents/skills/qk-project-health/evals/scorecard.yaml +0 -27
  105. package/.agents/skills/qk-project-memory/SKILL.md +0 -303
  106. package/.agents/skills/qk-project-memory/capability.yaml +0 -23
  107. package/.agents/skills/qk-project-memory/evals/scorecard.yaml +0 -27
  108. package/.agents/skills/qk-refactor/SKILL.md +0 -243
  109. package/.agents/skills/qk-refactor/capability.yaml +0 -26
  110. package/.agents/skills/qk-refactor/evals/scorecard.yaml +0 -27
  111. package/.agents/skills/qk-security-audit/SKILL.md +0 -280
  112. package/.agents/skills/qk-security-audit/capability.yaml +0 -29
  113. package/.agents/skills/qk-security-audit/evals/scorecard.yaml +0 -27
  114. package/.agents/skills/qk-system-evolution/SKILL.md +0 -625
  115. package/.agents/skills/qk-system-evolution/capability.yaml +0 -24
  116. package/.agents/skills/qk-system-evolution/evals/scorecard.yaml +0 -26
  117. package/.agents/skills/qk-test-engineering/SKILL.md +0 -215
  118. package/.agents/skills/qk-test-engineering/capability.yaml +0 -28
  119. package/.agents/skills/qk-test-engineering/evals/scorecard.yaml +0 -26
  120. package/.agents/skills/qk-ui-audit/SKILL.md +0 -175
  121. package/.agents/skills/qk-ui-audit/capability.yaml +0 -23
  122. package/.agents/skills/qk-ui-audit/evals/scorecard.yaml +0 -26
  123. package/.agents/skills/qk-ui-audit/references/anti-slop-checklist.md +0 -136
  124. package/.agents/skills/qk-ui-builder/SKILL.md +0 -521
  125. package/.agents/skills/qk-ui-builder/capability.yaml +0 -29
  126. package/.agents/skills/qk-ui-builder/evals/scorecard.yaml +0 -26
  127. package/.agents/skills/qk-ui-builder/references/anti-patterns.md +0 -295
  128. package/.agents/skills/qk-ui-builder/references/color.md +0 -115
  129. package/.agents/skills/qk-ui-builder/references/component-cookbook.md +0 -458
  130. package/.agents/skills/qk-ui-builder/references/copy.md +0 -250
  131. package/.agents/skills/qk-ui-builder/references/interaction-and-states.md +0 -115
  132. package/.agents/skills/qk-ui-builder/references/layout-and-space.md +0 -111
  133. package/.agents/skills/qk-ui-builder/references/macrostructures/01-bento-grid.md +0 -48
  134. package/.agents/skills/qk-ui-builder/references/macrostructures/02-long-document.md +0 -50
  135. package/.agents/skills/qk-ui-builder/references/macrostructures/03-marquee-hero.md +0 -51
  136. package/.agents/skills/qk-ui-builder/references/macrostructures/04-stat-led.md +0 -49
  137. package/.agents/skills/qk-ui-builder/references/macrostructures/05-workbench.md +0 -44
  138. package/.agents/skills/qk-ui-builder/references/macrostructures/06-conversational-faq.md +0 -50
  139. package/.agents/skills/qk-ui-builder/references/macrostructures/07-manifesto.md +0 -51
  140. package/.agents/skills/qk-ui-builder/references/macrostructures/08-photographic.md +0 -50
  141. package/.agents/skills/qk-ui-builder/references/macrostructures/09-quote-led.md +0 -50
  142. package/.agents/skills/qk-ui-builder/references/macrostructures/11-catalogue.md +0 -49
  143. package/.agents/skills/qk-ui-builder/references/macrostructures/12-letter.md +0 -49
  144. package/.agents/skills/qk-ui-builder/references/macrostructures/13-index-first.md +0 -49
  145. package/.agents/skills/qk-ui-builder/references/macrostructures/14-narrative-workflow.md +0 -48
  146. package/.agents/skills/qk-ui-builder/references/macrostructures/15-split-studio.md +0 -48
  147. package/.agents/skills/qk-ui-builder/references/macrostructures/16-feature-stack.md +0 -51
  148. package/.agents/skills/qk-ui-builder/references/macrostructures/17-type-specimen.md +0 -48
  149. package/.agents/skills/qk-ui-builder/references/macrostructures/18-portfolio-grid.md +0 -48
  150. package/.agents/skills/qk-ui-builder/references/macrostructures/19-map-diagram.md +0 -50
  151. package/.agents/skills/qk-ui-builder/references/macrostructures/20-ecosystem-index.md +0 -48
  152. package/.agents/skills/qk-ui-builder/references/macrostructures/21-component-playground.md +0 -45
  153. package/.agents/skills/qk-ui-builder/references/macrostructures.md +0 -38
  154. package/.agents/skills/qk-ui-builder/references/motion.md +0 -95
  155. package/.agents/skills/qk-ui-builder/references/responsive.md +0 -115
  156. package/.agents/skills/qk-ui-builder/references/slop-test.md +0 -135
  157. package/.agents/skills/qk-ui-builder/references/structure.md +0 -280
  158. package/.agents/skills/qk-ui-builder/references/themes/atmospheric.md +0 -53
  159. package/.agents/skills/qk-ui-builder/references/themes/carnival.md +0 -52
  160. package/.agents/skills/qk-ui-builder/references/themes/cobalt.md +0 -52
  161. package/.agents/skills/qk-ui-builder/references/themes/editorial.md +0 -52
  162. package/.agents/skills/qk-ui-builder/references/themes/garden.md +0 -52
  163. package/.agents/skills/qk-ui-builder/references/themes/hum.md +0 -52
  164. package/.agents/skills/qk-ui-builder/references/themes/lumen.md +0 -52
  165. package/.agents/skills/qk-ui-builder/references/themes/midnight.md +0 -52
  166. package/.agents/skills/qk-ui-builder/references/themes/modern-minimal.md +0 -52
  167. package/.agents/skills/qk-ui-builder/references/themes/playful.md +0 -52
  168. package/.agents/skills/qk-ui-builder/references/themes/specimen.md +0 -52
  169. package/.agents/skills/qk-ui-builder/references/themes/terminal.md +0 -52
  170. package/.agents/skills/qk-ui-builder/references/typography.md +0 -129
  171. package/.agents/skills/qk-ui-system-builder/SKILL.md +0 -183
  172. package/.agents/skills/qk-ui-system-builder/capability.yaml +0 -25
  173. package/.agents/skills/qk-ui-system-builder/evals/scorecard.yaml +0 -26
  174. package/.agents/skills/qk-upgrade/SKILL.md +0 -301
  175. package/.agents/skills/qk-upgrade/capability.yaml +0 -24
  176. package/.agents/skills/qk-upgrade/evals/scorecard.yaml +0 -26
  177. package/.agents/skills/qk-validation-gate/SKILL.md +0 -88
  178. package/.agents/skills/qk-validation-gate/capability.yaml +0 -23
  179. package/.agents/skills/qk-validation-gate/evals/scorecard.yaml +0 -26
  180. package/.agents/skills/qk-web-quality-gate/SKILL.md +0 -197
  181. package/.agents/skills/qk-web-quality-gate/capability.yaml +0 -24
  182. package/.agents/skills/qk-web-quality-gate/evals/scorecard.yaml +0 -26
  183. package/.agents/workflows/research.yml +0 -75
  184. package/.agents/workflows/skill-evolution.yml +0 -97
  185. package/tooling/fix-refactor.js +0 -8
@@ -0,0 +1,250 @@
1
+ ---
2
+ name: qk-code-cleaner
3
+ version: 10.1.0
4
+ status: stable
5
+ subtitle: "Refactor & Viết Test"
6
+ description: "Kỹ nghệ Tái cấu trúc (Zero Behavior Change), Nâng cấp thư viện an toàn có Rollback và Xây dựng lưới kiểm thử tự động. Dùng khi: refactor code, tái cấu trúc hàm/file, extract function/hook, clean code, giảm độ phức tạp cyclomatic, nâng cấp dependency package, audit breaking changes, viết unit/integration test — TUYỆT ĐỐI KHÔNG dùng khi chỉ sửa bug đơn lẻ (dùng qk-bug-resolution) hoặc build tính năng mới (dùng qk-feature-delivery)."
7
+ tools:
8
+ - filesystem
9
+ - terminal
10
+ rules:
11
+ - global
12
+ - coding-standards
13
+ - safety
14
+ workflow: refactor
15
+ triggers:
16
+ - "refactor"
17
+ - "tái cấu trúc"
18
+ - "tách file quá dài"
19
+ - "extract function"
20
+ - "extract hook"
21
+ - "clean code"
22
+ - "giảm complexity"
23
+ - "nâng cấp thư viện"
24
+ - "upgrade package"
25
+ - "migrate framework"
26
+ - "cập nhật dependency"
27
+ - "viết unit test"
28
+ - "viết test"
29
+ - "integration test"
30
+ - "test strategy"
31
+ ---
32
+
33
+ # qk-code-cleaner — Refactor & Viết Test (Modernization & Test Safety Engine)
34
+
35
+ > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
36
+
37
+ ---
38
+
39
+ ## 1. Nguyên Tắc Cốt Lõi & Luật Chống Over-Engineering
40
+
41
+ > **Core Principle:** Metrics are signals, not goals. Never refactor code merely to satisfy a metric. Optimize for maintainability, correctness, testability, and minimal risk.
42
+ > **Verification Principle:** PASS is a verified conclusion, never a target. Zero workarounds.
43
+
44
+ ### 🛡️ Anti-Overengineering Rule (BẮT BUỘC TUÂN THỦ)
45
+ - **Cấm trừu tượng hóa quá đà:** Tuyệt đối KHÔNG tự ý tạo Design Patterns phức tạp (Abstract Factory, Decorator, Strategy...), Interfaces tầng tầng lớp lớp, Generic Wrappers, hay Custom Hooks nếu không mang lại lợi ích cụ thể, thực tế và rõ ràng cho việc đọc hiểu hoặc kiểm thử.
46
+ - **Ưu tiên giải pháp tối thiểu:** Luôn chọn sự thay đổi cấu trúc nhỏ nhất (smallest structural change) mà giải quyết được vấn đề bảo trì. 3 dòng code tường minh tốt hơn 30 dòng code pattern trừu tượng.
47
+ - **Không chạm vào code đang chạy tốt:** Nếu một đoạn code dài nhưng mạch lạc, có tính bao đóng tốt và không có yêu cầu thay đổi, KHÔNG ĐƯỢC phép xé nhỏ nó chỉ để chạy theo chỉ tiêu số dòng.
48
+
49
+ ### 🔒 No Unrelated Changes Rule (CẤM SỬA LAN MAN)
50
+ - Chỉ sửa các file, hàm hoặc package nằm trong phạm vi tái cấu trúc được yêu cầu.
51
+ - **CẤM** reformat hoặc format lại các file lân cận không thuộc scope.
52
+ - **CẤM** đổi tên biến, signature hàm của các module khác ngoài phạm vi.
53
+ - Nếu phát hiện code smell hoặc vấn đề ngoài scope: **Chỉ ghi nhận vào báo cáo**, tuyệt đối không tự ý chạm vào.
54
+
55
+ ### 🛡️ Anti-Fake-Pass Rule (CẤM ÉP PASS ẢO - R-G-14.5)
56
+ - **CẤM** dùng `as any`, `@ts-ignore`, hoặc `@ts-expect-error` để giấu lỗi type sau khi refactor.
57
+ - **CẤM** làm yếu assertions (weakening assertions), xóa test case hoặc skip test đang fail chỉ để test suite xanh.
58
+ - **CẤM** dùng `catch (e) {}` rỗng để nuốt ngoại lệ.
59
+
60
+ ### ⚖️ Verify Before Claim Rule (CHỐNG BỐC PHÉT DỮ LIỆU)
61
+ - **Chạy lệnh trước khi báo cáo:** Tuyệt đối **KHÔNG ĐƯỢC** tuyên bố "Tests pass", "Types clean", "Build successful", hay "Zero behavior change" nếu chưa thực sự thực thi các câu lệnh kiểm chứng trong terminal (`npm test`, `pytest`, `tsc --noEmit`).
62
+ - **Trung thực khi không chạy được:** Nếu môi trường thiếu dependencies, thiếu database test, hoặc lệnh test không khả dụng, AI **BẮT BUỘC** ghi rõ: `"Trạng thái: NOT VERIFIED — Chưa kiểm chứng bằng lệnh thực tế (Cần user verify thủ công)"`. Cấm bịa đặt số lượng test hay kết quả 100% ảo.
63
+
64
+ ---
65
+
66
+ ## 2. Ranh Giới & Tiêu Chí Phân Định (Decision Rules)
67
+
68
+ ### Khi nào CẦN và KHÔNG CẦN can thiệp:
69
+ 1. **File dài (> 300 dòng):**
70
+ - *Hướng dẫn:* File vượt quá 300 dòng **phải được xem xét (reviewed for decomposition)**, nhưng CHỈ BẮT BUỘC TÁCH khi file có quá nhiều trách nhiệm (vi phạm SRP), logic lộn xộn, hoặc khó kiểm thử.
71
+ - *Ngoại lệ:* Schema files, DTOs, configurations, code sinh tự động (generated code), hoặc component có cấu trúc đơn khối rõ ràng thì 400-500 dòng vẫn được phép giữ nguyên.
72
+ 2. **Hàm dài (> 40 dòng) & Nesting sâu (> 3 tầng):**
73
+ - Áp dụng **Guard Clauses (Early Return)** để triệt tiêu các khối `if/else` lồng nhau.
74
+ - Tách các đoạn logic tính toán phức tạp thành các Pure Helper Functions độc lập.
75
+ 3. **Chiến lược Test Pyramid (Target Guideline):**
76
+ - *Định hướng:* Ưu tiên kim tự tháp kiểm thử nghiêng về Unit Tests (chạy nhanh, cô lập), kế đến là Integration Tests, và số ít E2E Tests trọng yếu.
77
+ - *Tính linh hoạt:* Tỷ lệ 70/20/10 là mục tiêu tham chiếu (Guideline), không phải giáo điều bắt buộc. Tùy thuộc vào bản chất dự án (CRUD, Data pipeline hay UI library) mà điều chỉnh tỷ lệ phù hợp.
78
+
79
+ ### Planning Gate & Exceptions:
80
+ - Với tác vụ thay đổi ≥ 2 files hoặc nâng cấp major package, BẮT BUỘC lập `implementation_plan.md` với `RequestFeedback: true` và dừng lại chờ phê duyệt.
81
+ - **Ngoại lệ bỏ qua Planning Gate:**
82
+ - Tái cấu trúc chỉ nằm trong duy nhất 1 file (Single-file refactor).
83
+ - Tinh chỉnh Guard Clauses nhỏ hoặc thêm type annotation đơn giản.
84
+ - Người dùng chỉ định rõ ràng yêu cầu thực thi ngay lập tức.
85
+
86
+ ### Ranh giới chuyển giao (Scope Handoff):
87
+ - ❌ Nếu phát hiện bug logic trong code cũ → Chuyển sang `qk-bug-resolution`.
88
+ - ❌ Nếu cần phát triển tính năng mới → Chuyển sang `qk-feature-delivery`.
89
+
90
+ ---
91
+
92
+ ## 3. Quy Trình Thực Thi Tuần Tự 5 Bước (Sequential Procedure)
93
+
94
+ Mọi tác vụ Tái cấu trúc / Nâng cấp / Viết test BẮT BUỘC tuân thủ đúng thứ tự:
95
+
96
+ ```
97
+ [Bước 1: Baseline Check] ── Chạy test/type hiện có, đo lường hiện trạng trước khi đụng vào code
98
+ │
99
+ ▼
100
+ [Bước 2: Safety Net Harness] ── Nếu module chưa có test, viết Characterization Test bảo vệ hiện trạng
101
+ │
102
+ ▼
103
+ [Bước 3: Planning Gate] ── Nếu sửa ≥ 2 files, tạo plan & chờ duyệt (trừ trường hợp ngoại lệ)
104
+ │
105
+ ▼
106
+ [Bước 4: Incremental Refactor]── Sửa từng bước nhỏ (Surgical), áp dụng Guard Clauses, bump từng pkg
107
+ │
108
+ ▼
109
+ [Bước 5: Verify or Rollback] ── Chạy lại test thật. Nếu FAIL ──► Kích hoạt Failure Protocol (Revert ngay)
110
+ ```
111
+
112
+ ### Chi tiết từng bước:
113
+ - **Bước 1: Baseline Check:** Chạy bộ test hoặc type-check hiện có để biết hệ thống ban đầu xanh hay đỏ. Không refactor trên nền tảng đang bị gãy mà không báo trước cho user.
114
+ - **Bước 2: Safety Net Harness (Lưới an toàn):** Nếu code cũ không có test, hãy tạo một file test nhỏ kiểm chứng các đầu vào - đầu ra quan trọng hiện thời (Characterization Tests) trước khi đổi cấu trúc.
115
+ - **Bước 3: Planning Gate:** Nếu tác vụ thay đổi ≥ 2 files hoặc nâng cấp major package, tạo artifact `implementation_plan.md` với `RequestFeedback: true` theo mẫu ở Mục 5 và dừng lại chờ phê duyệt (trừ ngoại lệ).
116
+ - **Bước 4: Incremental Refactoring:**
117
+ - Tái cấu trúc từng khối nhỏ một. Không sửa đồng loạt nhiều module.
118
+ - Áp dụng Guard Clauses loại bỏ if lồng nhau.
119
+ - **Bước 5: Verification & Zero Behavior Change:**
120
+ - Chạy lại test suite. Đối chiếu đầu ra đảm bảo 100% khớp với baseline.
121
+ - CẤM mọi hành vi ép test pass bằng cách sửa assertion hay ép kiểu bẩn.
122
+
123
+ ---
124
+
125
+ ## 4. Xử Lý Sự Cố & Kế Hoạch Khôi Phục (Failure Path & Rollback)
126
+
127
+ ### 🚨 Khi kiểm thử thất bại (Test Fail) hoặc Behavior bị sai lệch:
128
+ 1. **Dừng ngay lập tức:** Không cố chấp viết thêm code "vá chằng vá đụp" lên đoạn refactor hỏng.
129
+ 2. **Kích hoạt Revert Bước Vừa Làm:**
130
+ ```bash
131
+ # Nếu chỉ sửa 1 file:
132
+ git checkout HEAD -- path/to/file.ts
133
+ # Nếu đã sửa nhiều file trong workspace:
134
+ git restore <các_file_vừa_sửa>
135
+ ```
136
+ 3. **Phân tích Delta (Nguyên nhân thất bại):** Xác định tại sao thay đổi nhỏ đó lại làm đổi behavior (Side-effect ngầm? Mutation ẩn? Thứ tự promise bị đảo lộn?).
137
+ 4. **Hạ quy mô (Step-down):** Thử lại với bước tái cấu trúc nhỏ hơn một nửa. Nếu vẫn không an toàn, báo cáo dừng lại và giữ nguyên code gốc.
138
+
139
+ ### 📦 Khi nâng cấp Package gặp xung đột (Dependency Conflict / Lockfile):
140
+ 1. **Khôi phục ngay:** `git checkout HEAD -- package.json package-lock.json pnpm-lock.yaml`
141
+ 2. **Không ép buộc (No `--force` / `--legacy-peer-deps` bừa bãi):** Tìm hiểu chính xác package nào xung đột peer dependency từ changelog, đề xuất user nâng cấp đồng thời hoặc tìm thư viện thay thế.
142
+
143
+ ---
144
+
145
+ ## 5. Khung Kế Hoạch Chuẩn (Implementation Plan Skeleton)
146
+
147
+ Khi tạo artifact `implementation_plan.md` cho các tác vụ ≥ 2 files:
148
+
149
+ ```markdown
150
+ # Implementation Plan: [Refactor / Upgrade / Testing] - [Tên Module]
151
+
152
+ ## 1. Mục tiêu & Giới hạn phạm vi
153
+ - Mục tiêu: [Cải thiện khả năng đọc / Tách file Service / Thêm unit tests]
154
+ - Cam kết: 100% Zero Behavior Change. Không đổi API contracts hay DB schema.
155
+
156
+ ## 2. Rủi ro & Điểm nhạy cảm
157
+ - [Rủi ro tiềm ẩn, ví dụ: Hàm X có side-effect ngầm, Package Y có breaking change ở v2]
158
+
159
+ ## 3. Các bước thực hiện từng file
160
+ - [ ] [TênFileGốc.ts](file:///<workspace-root>/src/...): Trích xuất logic X sang Helper
161
+ - [ ] [NEW] [TênFileMới.ts](file:///<workspace-root>/src/...): Nhận các pure functions
162
+ - [ ] [TênTest.test.ts](file:///<workspace-root>/tests/...): Chạy kiểm chứng
163
+
164
+ ## 4. Kế hoạch Rollback tức thì
165
+ - Lệnh khôi phục: `git restore src/path/to/files`
166
+ ```
167
+
168
+ ---
169
+
170
+ ## 6. Mẫu Code Đa Ngôn Ngữ Thực Chiến (Guard Clauses)
171
+
172
+ ### TypeScript Pattern:
173
+ ```typescript
174
+ // ❌ Cũ: Lồng ghép sâu, khó đọc
175
+ function processOrder(order: Order | null, user: User | null) {
176
+ if (order) {
177
+ if (user && user.isActive) {
178
+ if (order.items.length > 0) {
179
+ return calculateTotal(order);
180
+ }
181
+ }
182
+ }
183
+ return null;
184
+ }
185
+
186
+ // ✅ Mới: Tường minh, phẳng hóa logic bằng Early Return
187
+ function processOrder(order: Order | null, user: User | null): number | null {
188
+ if (!order || !user) return null;
189
+ if (!user.isActive) return null;
190
+ if (order.items.length === 0) return null;
191
+
192
+ return calculateTotal(order);
193
+ }
194
+ ```
195
+
196
+ ### Python Pattern:
197
+ ```python
198
+ # ❌ Cũ: Nesting lồng nhau
199
+ def calculate_discount(order, customer):
200
+ if order is not None:
201
+ if customer and customer.is_active:
202
+ if order.total_amount > 1000:
203
+ return order.total_amount * 0.1
204
+ return 0.0
205
+
206
+ # ✅ Mới: Guard Clauses đanh thép
207
+ def calculate_discount(order, customer) -> float:
208
+ if not order or not customer or not customer.is_active:
209
+ return 0.0
210
+ if order.total_amount <= 1000:
211
+ return 0.0
212
+
213
+ return order.total_amount * 0.1
214
+ ```
215
+
216
+ ---
217
+
218
+ ## 7. Thích Ứng Theo Role Kỹ Thuật (Role Adaptation)
219
+
220
+ | Role | Trọng tâm khi Refactor & Viết Test | Hành vi kỹ thuật đặc thù |
221
+ |---|---|---|
222
+ | `frontend` | Tách nhỏ UI component, trích xuất custom hooks, tối ưu re-render | Tách container/presentational, Memoization, component unit test |
223
+ | `backend` | Tách God Service, áp dụng Dependency Injection, chuẩn hóa DTOs | Phân tầng Controller-Service-Repo, Unit test Service với mocked repository |
224
+ | `fullstack` | Đồng bộ hóa contracts, refactor shared types, end-to-end integration | Đồng bộ schemas giữa client/server, viết integration test luồng dữ liệu |
225
+ | `qa` | Thiết kế Test Matrix, tự động hóa regression test suites | Viết test cases biên (boundary analysis), mock scenarios |
226
+ | `data` | Refactor complex SQL queries, module hóa dbt models | Chia nhỏ staging/intermediate/marts models trong dbt, dbt tests |
227
+
228
+ ---
229
+
230
+ ## 8. Báo Cáo Nghiệm Thu Chuẩn Xác (Truth-First Report)
231
+
232
+ ```markdown
233
+ 🧹 Code Cleaner Summary [Role: <role> | Task: <Tên công việc>]
234
+ ─────────────────────────────────────────────────────────────────────
235
+ Trạng thái: [SUCCESS | BLOCKED | FAILED | PARTIAL]
236
+ Phạm vi thực tế: [N files đã chỉnh sửa / tạo mới]
237
+ Cam kết tính năng: ✅ Zero Behavior Change (Hành vi bên ngoài giữ nguyên 100%)
238
+
239
+ Chi tiết cải thiện (Laser Focus):
240
+ • [Loại thay đổi]: [Tên file và chi tiết việc đã làm]
241
+
242
+ Kiểm chứng thực tế (Verify Before Claim):
243
+ • Lệnh test đã chạy: [npm test / pytest / tsc --noEmit / Chưa chạy (Nêu lý do)]
244
+ • Kết quả xác thực: [Pass N/N tests / Types Clean / NOT VERIFIED]
245
+ • Anti-overengineering: ✅ 0 abstraction thừa, giữ giải pháp tối giản nhất
246
+ • Zero Hack: ✅ Không dùng any, @ts-ignore, hay làm yếu test assertion
247
+
248
+ ⚠️ Phương án Rollback nếu cần:
249
+ • Lệnh: `git restore <các-file-đã-sửa>`
250
+ ```
@@ -1,253 +1,132 @@
1
1
  ---
2
- # ── Identity ───────────────────────────────────────────────
3
- name: qk-code-review
4
- version: 9.2.0
5
- status: stable
6
- description: "Review code, AI config, hoặc skin rules theo 4 phases với Architect mindset — phát hiện bug, security issue, architecture smell, logic error. Dùng skill này khi user nhắc đến: review code, code review, kiểm tra code, đánh giá code, review skin, review rule, review ai config, audit PR — kể cả khi chỉ nói \"xem thử code này ổn không\"."
7
- platforms: [antigravity, claude-code, cursor, windsurf, kilo-code]
8
-
9
- # ── V9: Classification ─────────────────────────────────────
10
- type: utility
11
-
12
- intent:
13
- - code-review
14
- - quality-assurance
15
- - architecture-review
16
- - ai-config-audit
17
-
18
- complexity:
19
- level: high
20
- criteria:
21
- files_affected: "1-15"
22
- has_behavior_change: false
23
- has_external_dependency: false
24
- has_breaking_change: false
25
-
2
+ name: qk-code-review
3
+ version: 10.1.0
4
+ status: stable
5
+ subtitle: "Review Code & Audit"
6
+ description: "Kiểm toán mã nguồn toàn diện: Đánh giá kiến trúc, chấm điểm sức khỏe Codebase Health Score (0–100), quét bảo mật OWASP Top 10 và kiểm định chất lượng Web WCAG AA. Dùng khi: review code, code review, kiểm tra code, đánh giá code, health check, nợ kỹ thuật, security audit, scan lỗ hổng, owasp, secret leak, a11y, accessibility, wcag — TUYỆT ĐỐI KHÔNG dùng khi trực tiếp sửa code (dùng qk-code-cleaner)."
7
+ tools:
8
+ - filesystem
9
+ - terminal
10
+ rules:
11
+ - global
12
+ - coding-standards
13
+ - security
14
+ workflow: code-review
26
15
  triggers:
27
16
  - "review code"
28
17
  - "code review"
29
18
  - "kiểm tra code"
30
19
  - "đánh giá code"
31
- - "review skin"
32
- - "review rule"
33
- - "review ai config"
34
- - "audit PR"
35
-
36
-
37
- selection:
38
- priority: high
39
- confidence_threshold: 0.85
40
-
41
- # ── V8: References ─────────────────────────────────────────
42
- workflow: code-review
43
-
44
- rules:
45
- - global
46
-
47
- tools:
48
- - filesystem
49
-
50
- related_skills:
51
- - qk-project-health
52
- - qk-security-audit
53
-
54
- knowledge_scope:
55
- owns:
56
- - code-review-standards
57
- - ai-configuration-review
58
- - feedback-delivery
59
- references:
60
- - architecture
61
- - security
62
- - anti-patterns
63
-
64
- # ── V8: Verification ───────────────────────────────────────
65
- verification:
66
- required: true
67
- strategy: review
68
-
69
- # ── V8: Knowledge links ────────────────────────────────────
70
- examples: []
71
- learnings: []
72
-
73
- # ── V7 Runtime ─────────────────────────────────────────────
74
- execution_mode: deterministic
75
- cost: high
76
- latency: medium
77
- risk: low
78
- side_effects: read_only
79
- produces: [report]
80
- consumes: [source-code, rules, workflows]
81
-
82
- token_budget:
83
- max_files_read: 10
84
- max_lines_per_read: 300
85
- max_shell_commands: 2
86
- stop_early: true
87
-
88
- exit_codes: [SUCCESS, BLOCKED, FAILED, PARTIAL]
89
- ---
90
-
91
- # qk-code-review — Elite Review System
92
-
93
- > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
94
-
95
- Biến quá trình Code Review từ "bắt bẻ" (gatekeeping) thành "chia sẻ tri thức" (knowledge sharing) thông qua phản hồi mang tính xây dựng, phân tích có hệ thống và hợp tác cải tiến theo tư duy Kiến trúc sư (Architect mindset).
96
-
97
- ---
98
-
99
- ## Preconditions
100
-
101
- Trước khi thực hiện review, AI BẮT BUỘC kiểm tra:
102
-
103
- - [ ] Xác định đối tượng review: files cụ thể, diff/PR, hay cấu hình AI/rules.
104
- - [ ] Đọc `.agents/DEV_PROFILE.md` để nắm coding standards, architectural rules, và constraints.
105
- - [ ] Đảm bảo files cần review tồn tại và có thể đọc được nội dung.
106
- - [ ] Nếu scope review vượt quá khả năng context (ví dụ toàn bộ repo hàng nghìn files cùng lúc):
107
- → **EXIT: BLOCKED**
108
- → Báo cáo user chia nhỏ phạm vi review theo module hoặc PR diff.
109
-
110
- ---
111
-
112
- ## Scope
113
-
114
- ✅ Skill này làm:
115
- - Phân tích code theo 4 tầng: Bug/Logic, Security, Architecture/Maintainability, Coding Standards.
116
- - Đánh giá chất lượng của cấu hình AI (SKILL.md, workflow YAML, system rules).
117
- - Cung cấp feedback định lượng, phân loại độ nghiêm trọng: CRITICAL, HIGH, MEDIUM, LOW.
118
- - Gợi ý giải pháp cụ thể (concrete diffs / refactor snippet) cho từng vấn đề.
119
- - Hoạt động ở chế độ **read-only** (chỉ xuất báo cáo, không tự ý sửa code).
120
-
121
- ❌ Skill này KHÔNG làm:
122
- - Tự động áp dụng code fix vào source code của user (→ user quyết định hoặc dùng `qk-refactor`).
123
- - Quét toàn bộ vulnerabilities của third-party dependencies qua CVE database (→ `qk-security-audit`).
124
- - Đo lường và chấm điểm tổng thể kỹ thuật dự án (→ `qk-project-health`).
125
-
126
- ---
127
-
128
- ## Execution Steps
129
-
130
- ### Step 1 — Context & Target Ingestion
131
- ```
132
- Inputs: Danh sách files/diff từ user, DEV_PROFILE.md
133
- Actions:
134
- - Đọc nội dung source code mục tiêu.
135
- - Phân tích vai trò của file trong kiến trúc chung (domain, service, UI, infra).
136
- Output: Scope boundary & Review target map
137
- ```
138
-
139
- ### Step 2 — Multi-Dimensional Analysis
140
- ```
141
- Inputs: Source code, Standards & Rules
142
- Actions:
143
- - Phase 1: Logic & Correctness (xử lý null/undefined, race conditions, edge cases).
144
- - Phase 2: Security & Privacy (input validation, SQLi/XSS, secret leaks, access control).
145
- - Phase 3: Architecture & Clean Code (SOLID, DRY, coupled dependencies, readability).
146
- - Phase 4: Conventions & Performance (quy ước đặt tên, N+1 query, re-render).
147
- Output: Raw findings list
148
- ```
149
-
150
- ### Step 3 — Constructive Synthesis & Remediation
151
- ```
152
- Inputs: Raw findings list
153
- Actions:
154
- - Lọc bỏ false positives và gán nhãn mức độ nghiêm trọng (CRITICAL/HIGH/MEDIUM/LOW).
155
- - Với mỗi finding, viết lý do (Why) và đề xuất code snippet cải tiến (How to fix).
156
- Output: Structured Review Report
157
- ```
158
-
159
- ### Step 4 — Verification & Delivery
160
- ```
161
- Inputs: Structured Review Report
162
- Actions:
163
- - Rà soát tính khả thi của các đề xuất.
164
- - Trình bày báo cáo rõ ràng, mạch lạc theo ngôn ngữ tiếng Việt (code snippets giữ English).
165
- Exit: SUCCESS
166
- ```
167
-
168
- ---
169
-
170
- ## Prompt Template
171
-
172
- AI đọc `DEV_PROFILE.md` để biết conventions + constraints. Review sẽ đánh giá theo đúng tiêu chuẩn dự án.
173
-
174
- ```
175
- Review: [File / folder / PR diff cần review]
176
- Focus: [security / performance / architecture / logic / correctness — hoặc "full"]
177
- Context: [Đây là feature mới / bug fix / refactor / migration / ...]
178
- Bỏ qua: [Những thứ không cần comment — vd: style, naming, test coverage]
179
- ```
180
-
181
- ---
182
-
183
- ### Theo Role — AI review theo tiêu chí khác nhau:
184
-
185
- **role: fe**
186
- ```
187
- Review: src/features/cart/ (toàn bộ folder — PR mới)
188
- Focus: correctness + performance
189
- Context: Vừa implement giỏ hàng — lần đầu có optimistic updates
190
- Bỏ qua: CSS naming convention
191
- ```
192
- → AI xem xét: race condition trong optimistic update, stale closure trong
193
- useCallback/useEffect, unnecessary re-render (missing memo/deps array),
194
- missing error boundary, accessibility của interactive elements,
195
- bundle size impact của dependencies mới.
196
-
197
- **role: be**
198
- ```
199
- Review: src/routes/payments/ + src/services/PaymentService.ts
200
- Focus: security + correctness
201
- Context: Tích hợp payment gateway mới (Stripe) — business critical
202
- Bỏ qua: Code style
203
- ```
204
- → AI xem xét: idempotency key usage, webhook signature verification,
205
- sensitive data logging (card numbers, CVV không được log),
206
- error handling không leak internal info ra response, DB transaction scope,
207
- rate limiting, secrets không hardcode.
208
-
209
- **role: fullstack**
210
- ```
211
- Review: src/features/reports/ (FE + BE cùng PR)
212
- Focus: architecture + contract
213
- Context: Feature mới — export báo cáo, cả FE và BE trong cùng PR
214
- Bỏ qua: Test coverage (sẽ thêm sau)
215
- ```
216
- → AI xem xét: type contract giữa FE-BE (có dùng shared types không),
217
- FE không hard-code assumptions về response shape, BE thay đổi response
218
- có break FE không, error shape nhất quán, loading state đầy đủ.
219
-
220
- **role: data**
221
- ```
222
- Review: dags/customer_churn_pipeline.py + models/mart/fct_churn.sql
223
- Focus: correctness + reliability
224
- Context: Pipeline mới chạy weekly, dữ liệu dùng cho ML model
225
- Bỏ qua: SQL formatting style
226
- ```
227
- → AI xem xét: idempotency (re-run an toàn không), partition filter đúng chưa
228
- (tránh full scan), data quality assertions có đủ không, schema evolution
229
- strategy, downstream dependencies được documented chưa, SLA realistic không.
230
-
231
- **role: ai-engineer**
232
- ```
233
- Review: prompts/ + retrieval/pipeline.py
234
- Focus: correctness + hallucination risk
235
- Context: RAG pipeline sắp ra production — cần review kỹ trước khi deploy
236
- Bỏ qua: Code style
237
- ```
238
- → AI xem xét: system prompt có enforce grounding không ("chỉ dùng context được cung cấp"),
239
- retrieval có thể trả empty context không (edge case), temperature setting phù hợp,
240
- PII trong training data / retrieved context, prompt injection risk,
241
- eval metrics có được log không, fallback khi LLM unavailable.
242
-
243
- **role: devops**
244
- ```
245
- Review: .github/workflows/ + terraform/modules/ecs/
246
- Focus: security + correctness
247
- Context: Infrastructure change — scale up ECS service + thêm ALB rule
248
- Bỏ qua: Resource naming convention (đã có convention riêng)
249
- ```
250
- → AI xem xét: secrets exposed trong logs hay env vars không, IAM least-privilege
251
- (role có quá nhiều permission không), rollback plan rõ ràng chưa,
252
- state file được lock và store an toàn không, có test trên staging trước prod không,
253
- blast radius nếu Terraform apply fail giữa chừng.
20
+ - "health check"
21
+ - "kiểm tra sức khỏe code"
22
+ - "project score"
23
+ - "nợ kỹ thuật"
24
+ - "tech debt"
25
+ - "security audit"
26
+ - "kiểm tra bảo mật"
27
+ - "scan lỗ hổng"
28
+ - "owasp"
29
+ - "tìm secret leak"
30
+ - "a11y"
31
+ - "wcag"
32
+ ---
33
+
34
+ # qk-code-review — Review Code & Audit (360° Architecture & Security Audit Engine)
35
+
36
+ > **Language rule:** Code, identifiers, file names → English. Explanations, summaries → Vietnamese.
37
+
38
+ ---
39
+
40
+ ## 1. Nguyên Tắc Cốt Lõi & Luật Chống Giáo Điều (Anti-Dogma)
41
+
42
+ > **Core Principle:** Metrics are signals, not goals. A file of 320 lines that is cohesive, clean, and well-tested is far superior to 5 fragmented micro-files created solely to satisfy an arbitrary line-count limit.
43
+ > **Audit Principle:** PASS is a verified conclusion, never a target. Zero sugarcoating.
44
+
45
+ ### 🛡️ Anti-Dogma Review Rule (CẤM BẮT BẺ VỤN VẶT)
46
+ - **Đánh giá theo ngữ cảnh:** Tuyệt đối KHÔNG trừ điểm máy móc nếu file dài hơn 300 dòng một chút nhưng cấu trúc rõ ràng (như DTOs, config, state machine hoặc generated code). Chỉ gắn cờ cảnh báo khi file đó có nhiều trách nhiệm lộn xộn (God file) và khó bảo trì.
47
+ - **Tập trung vào giá trị thực:** Ưu tiên phát hiện rủi ro bảo mật (OWASP), logic lỗi ngầm, rò rỉ bộ nhớ, và vi phạm quyền truy cập thay vì sa đà vào các nhận xét phong cách (formatting/linting) mà prettier có thể tự sửa.
48
+
49
+ ### 🔒 Laser Focus & Repository Inspection Rule (R-G-13)
50
+ - Chỉ quét và kiểm toán các file thuộc diff hoặc module được người dùng chỉ định.
51
+ - **CẤM** quét toàn bộ codebase bừa bãi hoặc biến việc audit thành một bản tấu sớ lan man hàng trăm file không liên quan.
52
+
53
+ ### ⚖️ Verify Before Claim Rule (XÁC MINH TRƯỚC KHI BÁO CÁO - R-G-14.7)
54
+ - **Không bịa đặt số liệu:** Cấm báo cáo "0 Secret Leaks" nếu chưa chạy regex quét chuỗi nhạy cảm. Cấm báo cáo "Đạt chuẩn WCAG AA" nếu chưa kiểm tra màu sắc tương phản và thẻ ARIA.
55
+ - **Rõ ràng phạm vi:** Phải nêu rõ danh sách chính xác các file đã đọc và kiểm toán. Những file chưa đọc phải ghi rõ nằm ngoài phạm vi review đợt này.
56
+
57
+ ---
58
+
59
+ ## 2. Ranh Giới & Phạm Vi Kỹ Thuật (Hard Boundaries)
60
+
61
+ ### ✅ Việc skill này BẮT BUỘC làm:
62
+ - **Tư duy Kiến trúc sư (Architect Mindset):** Đánh giá tính đóng gói, ranh giới giữa các module, luồng dữ liệu một chiều và xử lý lỗi phòng thủ.
63
+ - **Health Scorecard Định Lượng (0–100):** Chấm điểm nợ kỹ thuật theo thang đo khách quan, có đối chứng số dòng và độ sâu lồng ghép.
64
+ - **OWASP Top 10 Scan:** Quét lỗ hổng Broken Access Control (IDOR), SQL Injection, XSS, Secret Leaks (regex quét tokens, passwords, keys).
65
+ - **Dual-Stream Reporting:** Tạo file artifact `review_report.md` chi tiết tại thư mục brain, và chỉ in bản tóm tắt điều hành 15–25 dòng tại cửa sổ chat.
66
+
67
+ ### ❌ Việc skill này TUYỆT ĐỐI KHÔNG làm (Chuyển giao quyền):
68
+ - Tự tiện sửa mã nguồn trong repo → Skill này là Read-Only Auditor. Để thực thi sửa đổi an toàn, chuyển giao sang `qk-code-cleaner`.
69
+
70
+ ---
71
+
72
+ ## 3. Thang Điểm Sức Khỏe Codebase (Health Score: 0–100)
73
+
74
+ ```
75
+ Điểm khởi điểm: 100 điểm. Trừ điểm dựa trên vi phạm thực tế:
76
+ ─────────────────────────────────────────────────────────────────────────────
77
+ • God File (Lộn xộn > 300L): -5 điểm / file (Có xem xét ngữ cảnh)
78
+ • Long Function (Phức tạp > 40L): -2 điểm / hàm
79
+ • Deep Nesting (> 3 tầng if/for): -2 điểm / vị trí
80
+ • Hardcoded Secret (Lộ Key/Pass): -25 điểm (CRITICAL — Báo động đỏ ngay)
81
+ • Broken Access Control (Dính IDOR): -20 điểm (CRITICAL)
82
+ • SQL / Command Injection: -20 điểm (CRITICAL)
83
+ ─────────────────────────────────────────────────────────────────────────────
84
+ Xếp loại: 90-100 (Xuất sắc) | 75-89 (Khá) | 50-74 (Cảnh báo) | <50 (Nguy hiểm)
85
+ ```
86
+
87
+ ---
88
+
89
+ ## 4. Quy Trình Kiểm Toán 4 Bước & Báo Động Khẩn
90
+
91
+ ```
92
+ [Bước 1: Phạm vi & Regex Scan] ── Đọc danh sách file, quét regex tìm Secret Leaks
93
+ │
94
+ ▼
95
+ [Bước 2: OWASP & Logic Audit] ── Rà soát IDOR, Injection, Null safety & Error handling
96
+ │
97
+ ▼
98
+ [Bước 3: Scorecarding] ── Tính điểm Health Score, phân loại P0 (Critical) đến P3
99
+ │
100
+ ▼
101
+ [Bước 4: Dual-Stream Report] ── Xuất review_report.md + Chat Executive Summary 15-25L
102
+ ```
103
+
104
+ ### 🚨 Giao thức Báo Động Khẩn (Critical Security Trigger):
105
+ Nếu phát hiện **Hardcoded API Key/Secret** hoặc **Lỗ hổng SQL Injection/IDOR**:
106
+ - BẮT BUỘC in cảnh báo đỏ nổi bật ngay dòng đầu tiên của chat:
107
+ `🚨 [CRITICAL SECURITY ALERT]: Phát hiện lộ Secret/Lỗ hổng nghiêm trọng tại [TênFile.ts:L42](file:///<workspace-root>/path#L42)! Cần xử lý thu hồi ngay lập tức!`
108
+
109
+ ---
110
+
111
+ ## 5. Chuẩn Báo Cáo Antigravity Dual-Stream (Truth-First)
112
+
113
+ ```markdown
114
+ 🔍 Code Review & Health Scorecard [Role: <role> | Score: <Điểm>/100]
115
+ ─────────────────────────────────────────────────────────────────────
116
+ Phạm vi thực tế: [N files đã rà soát / Tên module]
117
+ Đánh giá chung: [Xuất sắc / Khá / Cảnh báo / Nguy hiểm]
118
+
119
+ 🚨 Vấn đề then chốt cần khắc phục:
120
+ ❌ [CRITICAL/OWASP]: [Mô tả ngắn nếu có — kèm file:/// link]
121
+ ⚠️ [TECH DEBT]: [Các hàm phức tạp hoặc vi phạm SRP cần tách]
122
+
123
+ 📊 Chỉ số đo lường thực tế (Truth-First):
124
+ • Health Score: <Điểm> / 100
125
+ • Secret Leaks: [0 (Đã quét regex) / N phát hiện]
126
+ • OWASP Violations: [N Critical, N Major]
127
+ • Anti-Dogma: ✅ Đã xem xét ngữ cảnh, không bắt bẻ file schema/config
128
+
129
+ 📄 Báo cáo chi tiết & Phương án khắc phục mẫu:
130
+ Đã lưu tại: [review_report.md](file:///C:/Users/qkhanh/.gemini/antigravity-ide/brain/f7ef21b2-6e3e-4177-a422-5ddcad5a5843/review_report.md)
131
+ 👉 Dùng `./qk-code-cleaner` để bắt đầu phân tách và dọn dẹp mã nguồn an toàn.
132
+ ```