Rules & Workflows
Rules và Workflows là các cách để steering (điều hướng) hành vi của Agent theo ý muốn của bạn.
Rules
Phần tiêu đề “Rules”Rules là các hướng dẫn được viết bằng Markdown để Agent tuân theo.
Tạo Rules
Phần tiêu đề “Tạo Rules”Tạo file .agent/rules.md hoặc .gemini/rules.md trong project:
# Project Rules
## Code Style- Sử dụng TypeScript cho tất cả code mới- Prefer functional components trong React- Luôn thêm error handling cho async operations
## Naming Conventions- Components: PascalCase (VD: UserProfile.tsx)- Utilities: camelCase (VD: formatDate.ts)- Constants: UPPER_SNAKE_CASE
## Testing- Viết tests cho mọi public function- Sử dụng Jest + React Testing Library- Coverage tối thiểu 80%Rules hoạt động như thế nào
Phần tiêu đề “Rules hoạt động như thế nào”Agent sẽ:
- Đọc rules file khi bắt đầu conversation
- Tham chiếu rules khi lập kế hoạch
- Tuân theo rules trong quá trình implementation
Best Practices cho Rules
Phần tiêu đề “Best Practices cho Rules”✅ Cụ thể và rõ ràng
❌ "Viết code tốt"✅ "Luôn sử dụng TypeScript strict mode"✅ Có thể thực thi
❌ "Code nên dễ đọc"✅ "Giới hạn function dưới 50 dòng"✅ Có ví dụ
## Error HandlingLuôn wrap async calls trong try-catch:
\`\`\`typescripttry { const data = await fetchUser(id);} catch (error) { logger.error('Failed to fetch user', { id, error }); throw new UserNotFoundError(id);}\`\`\`Workflows
Phần tiêu đề “Workflows”Workflows là các quy trình có cấu trúc mà Agent có thể thực hiện.
Tạo Workflow
Phần tiêu đề “Tạo Workflow”Tạo file trong .agent/workflows/ với format:
---description: Deploy ứng dụng lên production---
# Deploy Workflow
## Pre-deploy Checks1. Chạy tất cả tests: `npm test`2. Build production: `npm run build`3. Check bundle size: `npm run analyze`
## Deploy Steps// turbo4. Push to main branch: `git push origin main`
// turbo5. Deploy to Vercel: `vercel --prod`
## Post-deploy6. Verify deployment tại production URL7. Chạy smoke tests8. Thông báo team qua SlackCú pháp đặc biệt
Phần tiêu đề “Cú pháp đặc biệt”// turbo
Phần tiêu đề “// turbo”Đánh dấu step có thể auto-run (không cần approval):
// turbo3. Install dependencies: `npm install`// turbo-all
Phần tiêu đề “// turbo-all”Đánh dấu tất cả steps có thể auto-run:
---description: Quick setup---// turbo-all
1. Install: `npm install`2. Build: `npm run build`3. Start: `npm run dev`Chạy Workflow
Phần tiêu đề “Chạy Workflow”Sử dụng slash command:
/workflow deployHoặc yêu cầu Agent:
"Chạy workflow deploy cho tôi"Liệt kê Workflows
Phần tiêu đề “Liệt kê Workflows”/workflowSo sánh Rules vs Workflows
Phần tiêu đề “So sánh Rules vs Workflows”| Đặc điểm | Rules | Workflows |
|---|---|---|
| Mục đích | Hướng dẫn chung | Quy trình cụ thể |
| Format | Guidelines | Steps tuần tự |
| Kích hoạt | Tự động | Thủ công (slash command) |
| Ví dụ | “Luôn dùng TypeScript” | “Deploy to production” |
Ví dụ thực tế
Phần tiêu đề “Ví dụ thực tế”Rules cho React Project
Phần tiêu đề “Rules cho React Project”# React Project Rules
## Components- Prefer functional components với hooks- Mỗi component trong file riêng- Export default ở cuối file
## State Management- Sử dụng Zustand cho global state- Local state với useState- Avoid prop drilling quá 2 levels
## Styling- Sử dụng Tailwind CSS- Responsive mobile-first- Dark mode support requiredWorkflow cho Feature Development
Phần tiêu đề “Workflow cho Feature Development”---description: Quy trình phát triển feature mới---
# Feature Development Workflow
## Setup1. Tạo branch mới: `git checkout -b feature/[name]`2. Cập nhật dependencies: `npm install`
## Development3. Tạo component structure4. Implement logic5. Viết tests
## Quality// turbo6. Run linter: `npm run lint`
// turbo7. Run tests: `npm test`
## Submit8. Commit với conventional format9. Push và tạo PR10. Request review