Bỏ qua để đến nội dung

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 là các hướng dẫn được viết bằng Markdown để Agent tuân theo.

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%

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

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 là các quy trình có cấu trúc mà Agent có thể thực hiện.

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

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

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

Đá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`

Sử dụng slash command:

/workflow deploy

Hoặc yêu cầu Agent:

"Chạy workflow deploy cho tôi"
/workflow
Đặ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”
# 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
---
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