Skip to Content
🛠️ Công cụ AIAntigravityPreviewRules & Workflows

Rules & Workflows

RulesWorkflows là các cách để steering (điều hướng) hành vi của Agent theo ý muốn của bạn.

Rules

Rules là các hướng dẫn được viết bằng Markdown để Agent tuân theo.

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

Agent sẽ:

  1. Đọc rules file khi bắt đầu conversation
  2. Tham chiếu rules khi lập kế hoạch
  3. Tuân theo rules trong quá trình implementation

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 Handling Luôn wrap async calls trong try-catch: \`\`\`typescript try { const data = await fetchUser(id); } catch (error) { logger.error('Failed to fetch user', { id, error }); throw new UserNotFoundError(id); } \`\`\`

Workflows

Workflows là các quy trình có cấu trúc mà Agent có thể thực hiện.

Tạo Workflow

Tạo file trong .agent/workflows/ với format:

--- description: Deploy ứng dụng lên production --- # Deploy Workflow ## Pre-deploy Checks 1. Chạy tất cả tests: `npm test` 2. Build production: `npm run build` 3. Check bundle size: `npm run analyze` ## Deploy Steps // turbo 4. Push to main branch: `git push origin main` // turbo 5. Deploy to Vercel: `vercel --prod` ## Post-deploy 6. Verify deployment tại production URL 7. Chạy smoke tests 8. Thông báo team qua Slack

Cú pháp đặc biệt

// turbo

Đánh dấu step có thể auto-run (không cần approval):

// turbo 3. Install dependencies: `npm install`

// 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

Sử dụng slash command:

/workflow deploy

Hoặc yêu cầu Agent:

"Chạy workflow deploy cho tôi"

Liệt kê Workflows

/workflow

So sánh Rules vs Workflows

Đặc điểmRulesWorkflows
Mục đíchHướng dẫn chungQuy trình cụ thể
FormatGuidelinesSteps tuần tự
Kích hoạtTự độngThủ công (slash command)
Ví dụ”Luôn dùng TypeScript""Deploy to production”

Ví dụ thực tế

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 required

Workflow cho Feature Development

--- description: Quy trình phát triển feature mới --- # Feature Development Workflow ## Setup 1. Tạo branch mới: `git checkout -b feature/[name]` 2. Cập nhật dependencies: `npm install` ## Development 3. Tạo component structure 4. Implement logic 5. Viết tests ## Quality // turbo 6. Run linter: `npm run lint` // turbo 7. Run tests: `npm test` ## Submit 8. Commit với conventional format 9. Push và tạo PR 10. Request review
Last updated on