# Trang 6.1: Tìm hiểu về file quy tắc GEMINI.md và cách tùy chỉnh hành vi AI.

## 1. `GEMINI.md` là gì?

**`GEMINI.md`** là file quan trọng nhất trong toàn bộ hệ thống Antigravity Kit. Nó nằm tại:

```html
.agent/rules/GEMINI.md
```

File này là **"hiến pháp"** định nghĩa cách AI phải hành xử trong **mọi** tình huống. Khi AI đọc file này, nó hiểu rõ:

- **Ưu tiên nào cao hơn** (quy tắc nào được áp dụng khi có xung đột).
- **Phân loại yêu cầu** như thế nào (câu hỏi, code đơn giản, task phức tạp).
- **Chọn Agent** nào cho từng loại yêu cầu.
- **Các quy tắc code toàn cục** phải tuân thủ.

---

## 2. Kiến trúc phân cấp ưu tiên

```html
P0: GEMINI.md ← Cao nhất — luôn có hiệu lực
P1: Agent .md ← Quy tắc riêng của từng Agent
P2: SKILL.md ← Kiến thức chuyên sâu từng lĩnh vực
```

Khi có xung đột giữa các cấp, cấp cao hơn luôn thắng.

---

## 3. Cấu trúc của `GEMINI.md`

File được tổ chức theo hệ thống **TIER** (Tầng):

### TIER 0 — Universal Rules (Luôn áp dụng)

Các quy tắc này hoạt động trong **mọi** yêu cầu, bất kể Agent nào được kích hoạt:

<div class="my-4 rounded-lg overflow-hidden border border-gray-500/20 [&_thead_tr:first-child_th:first-child]:border-t-0 [&_thead_tr:first-child_th:first-child]:border-l-0 [&_thead_tr:first-child_th:last-child]:border-t-0 [&_thead_tr:first-child_th:last-child]:border-r-0 [&_tbody_tr:last-child_td:first-child]:border-b-0 [&_tbody_tr:last-child_td:first-child]:border-l-0 [&_tbody_tr:last-child_td:last-child]:border-b-0 [&_tbody_tr:last-child_td:last-child]:border-r-0 [&_thead_tr:first-child_th]:border-t-0 [&_tbody_tr:last-child_td]:border-b-0 [&_th:first-child]:border-l-0 [&_td:first-child]:border-l-0 [&_th:last-child]:border-r-0 [&_td:last-child]:border-r-0" id="bkmrk-quy-t%E1%BA%AFc-n%E1%BB%99i-dung-lan"><table class="min-w-full border-separate border-spacing-0"><thead><tr><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Quy tắc</th><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Nội dung</th></tr></thead><tbody><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**Language Handling**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Khi người dùng không dùng tiếng Anh, AI dịch nội bộ nhưng trả lời bằng ngôn ngữ của người dùng</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**Clean Code**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Mọi code phải theo tiêu chuẩn `clean-code` — ngắn gọn, tự mô tả, không over-engineer</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**File Dependency Awareness**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Trước khi sửa file nào, kiểm tra file phụ thuộc và cập nhật đồng bộ</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**System Map Read**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Đọc <div>  
</div><span class="context-scope-mention"><span class="inline-flex items-center gap-0.5 rounded-md align-middle text-sm font-medium transition-[opacity,background-color] cursor-pointer hover:bg-gray-500/20 select-text translate-y-[-1px]" draggable="true"><span class="inline-flex break-all leading-tight">ARCHITECTURE.md</span></span></span> khi khởi động để hiểu hệ sinh thái</td></tr></tbody></table>

</div>### Request Classifier — Phân loại yêu cầu

Bảng phân loại tự động để AI biết cần làm gì:

<div class="my-4 rounded-lg overflow-hidden border border-gray-500/20 [&_thead_tr:first-child_th:first-child]:border-t-0 [&_thead_tr:first-child_th:first-child]:border-l-0 [&_thead_tr:first-child_th:last-child]:border-t-0 [&_thead_tr:first-child_th:last-child]:border-r-0 [&_tbody_tr:last-child_td:first-child]:border-b-0 [&_tbody_tr:last-child_td:first-child]:border-l-0 [&_tbody_tr:last-child_td:last-child]:border-b-0 [&_tbody_tr:last-child_td:last-child]:border-r-0 [&_thead_tr:first-child_th]:border-t-0 [&_tbody_tr:last-child_td]:border-b-0 [&_th:first-child]:border-l-0 [&_td:first-child]:border-l-0 [&_th:last-child]:border-r-0 [&_td:last-child]:border-r-0" id="bkmrk-lo%E1%BA%A1i-y%C3%AAu-c%E1%BA%A7u-t%E1%BB%AB-kh%C3%B3a"><table class="min-w-full border-separate border-spacing-0"><thead><tr><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Loại yêu cầu</th><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Từ khóa kích hoạt</th><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Kết quả</th></tr></thead><tbody><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**QUESTION**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">"là gì", "giải thích", "tại sao"</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Chỉ trả lời văn bản</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**SURVEY**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">"phân tích", "liệt kê", "tổng quan"</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Phân tích, không tạo file</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**SIMPLE CODE**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">"sửa", "thêm", "đổi" (1 file)</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Chỉnh sửa trực tiếp</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**COMPLEX CODE**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">"xây dựng", "tạo", "triển khai"</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Tạo file kế hoạch <div>  
</div><span class="context-scope-mention"><span class="inline-flex items-center gap-0.5 rounded-md align-middle text-sm font-medium transition-[opacity,background-color] cursor-pointer hover:bg-gray-500/20 select-text translate-y-[-1px]" draggable="true"><span class="inline-flex break-all leading-tight">.md</span></span></span></td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**DESIGN/UI**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">"thiết kế", "UI", "giao diện"</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Tạo file kế hoạch + components</td></tr></tbody></table>

</div>### Intelligent Routing Checklist

Checklist bắt buộc AI phải hoàn thành trước khi viết code:

```html
Bước 1: Đã xác định Agent phù hợp chưa?
Bước 2: Đã đọc file .md của Agent chưa?
Bước 3: Đã thông báo Agent cho người dùng chưa?
Bước 4: Đã tải Skills cần thiết chưa?
```

### TIER 1 — Code Rules (Khi viết code)

Chỉ áp dụng khi AI cần viết hoặc sửa code:

<div class="my-4 rounded-lg overflow-hidden border border-gray-500/20 [&_thead_tr:first-child_th:first-child]:border-t-0 [&_thead_tr:first-child_th:first-child]:border-l-0 [&_thead_tr:first-child_th:last-child]:border-t-0 [&_thead_tr:first-child_th:last-child]:border-r-0 [&_tbody_tr:last-child_td:first-child]:border-b-0 [&_tbody_tr:last-child_td:first-child]:border-l-0 [&_tbody_tr:last-child_td:last-child]:border-b-0 [&_tbody_tr:last-child_td:last-child]:border-r-0 [&_thead_tr:first-child_th]:border-t-0 [&_tbody_tr:last-child_td]:border-b-0 [&_th:first-child]:border-l-0 [&_td:first-child]:border-l-0 [&_th:last-child]:border-r-0 [&_td:last-child]:border-r-0" id="bkmrk-quy-t%E1%BA%AFc-n%E1%BB%99i-dung-pro"><table class="min-w-full border-separate border-spacing-0"><thead><tr><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Quy tắc</th><th class="bg-gray-500/20 px-3 py-2 text-left font-medium leading-snug border border-gray-500/20">Nội dung</th></tr></thead><tbody><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**Project Type Routing**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Mobile → `mobile-developer`, Web → `frontend-specialist`, API → `backend-specialist`</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**Socratic Gate**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Với tác vụ phức tạp: bắt buộc hỏi ít nhất 3 câu làm rõ trước khi code</td></tr><tr><td class="px-3 py-2 leading-snug border border-gray-500/20">**Final Checklist Protocol**</td><td class="px-3 py-2 leading-snug border border-gray-500/20">Khi người dùng nói "final checks", chạy <div>  
</div><span class="context-scope-mention"><span class="inline-flex items-center gap-0.5 rounded-md align-middle text-sm font-medium transition-[opacity,background-color] cursor-pointer hover:bg-gray-500/20 select-text translate-y-[-1px]" draggable="true"><span class="inline-flex break-all leading-tight">checklist.py</span></span></span></td></tr></tbody></table>

</div>---

## 4. Tùy chỉnh `GEMINI.md` cho đội ngũ của bạn

### Nguyên tắc tùy chỉnh an toàn

**✅ Có thể sửa:**

- Thêm quy tắc mới vào cuối file.
- Thêm các ràng buộc về ngôn ngữ lập trình hoặc naming convention.
- Định nghĩa các pattern bị cấm trong dự án.

**⚠️ Cẩn thận khi sửa:**

- Bảng Request Classifier (có thể làm AI nhận diện sai loại yêu cầu).
- Agent Routing rules (có thể gây định tuyến sai Agent).

**❌ Không nên xóa:**

- Cấu trúc TIER 0 và TIER 1 cơ bản.
- Intelligent Routing Checklist.

### Ví dụ tùy chỉnh thực tế

**Thêm quy tắc ngôn ngữ:**

<div class="relative whitespace-pre-wrap word-break-all my-2 rounded-lg bg-list-hover-subtle border border-gray-500/20" id="bkmrk--3" node="[object Object]"><div class="min-h-7 relative box-border flex flex-row items-center justify-between rounded-t border-b border-gray-500/20 px-2 py-0.5"></div></div>```markdown
markdown
## CUSTOM TEAM RULES


### Quy tắc ngôn ngữ
- Tất cả comment trong code phải bằng tiếng Anh
- Tên biến và hàm theo camelCase (không dùng snake_case trong JS/TS)
- Không dùng `any` trong TypeScript — phải có type cụ thể

Thêm pattern bị cấm:

markdown
### Các pattern bị cấm trong dự án này
- KHÔNG dùng `console.log` trong production code (dùng logger service)
- KHÔNG hard-code URL — phải dùng environment variables
- KHÔNG commit secret key hoặc password
- KHÔNG viết SQL raw — phải dùng Prisma ORM

Thêm convention đặt tên:

markdown
### Naming Convention
- Component: PascalCase (UserCard, ProductList)
- Hook: camelCase bắt đầu bằng "use" (useAuth, useCart)
- File component: PascalCase.tsx
- File util: camelCase.ts
- Test file: tên-file.test.ts

Thêm quy tắc về Tech Stack:

markdown
### Tech Stack bắt buộc cho dự án này
- Framework: Next.js 14 (App Router) — không dùng Pages Router
- Styling: Tailwind CSS — không dùng CSS Modules hay styled-components
- Database: Prisma + PostgreSQL — không dùng raw SQL
- Auth: NextAuth.js — không tự viết auth logic
```

---

## 5. Chia sẻ cấu hình với cả đội

Để toàn đội cùng dùng chung một bộ quy tắc:

```bash
bash
# Commit thư mục .agent/ vào Git
git add .agent/
git commit -m "chore: add/update Antigravity Kit team rules"
git push
```

Khi thành viên mới clone dự án, họ sẽ tự động có đầy đủ cấu hình đã được thống nhất.

---

## 6. Kiểm tra quy tắc có được áp dụng không

Sau khi sửa `GEMINI.md`, bạn có thể kiểm tra bằng cách:

```html
👤 Bạn: "Hãy kiểm tra và cho tôi biết các quy tắc nào bạn
đang áp dụng cho dự án này"


🤖 AI: Tôi đang áp dụng các quy tắc từ .agent/rules/GEMINI.md:
- TIER 0: Universal Rules (Language, Clean Code...)
- Custom Team Rules: No console.log, PascalCase components...
- Tech Stack: Next.js 14 App Router, Tailwind CSS...
```