Fix — Sửa bug
Phân tích và sửa bug tự động. Tuân thủ nguyên tắc: tìm root cause TRƯỚC, fix SAU. Tự động detect loại bug và chọn strategy phù hợp.Cú pháp
Luồng hoạt động bên trong
Khi bạn gõ/fix "API returns 500 when creating order", đây là 6 bước xảy ra:
Bước 1: Scout (BẮT BUỘC — không bao giờ skip)
Kích hoạt
ck:scout skill HOẶC spawn 2-3 Explore subagents song song.
Mục tiêu: hiểu codebase TRƯỚC khi đưa ra giả thuyết.- Tìm: affected files, dependencies, related tests, recent changes (git log)
- Đọc
./docsnếu chưa quen project
Step 1: Scouted — 12 files mapped, 5 dependencies, 3 tests foundBước 2: Diagnose (BẮT BUỘC — không bao giờ skip)
Phân tích root cause có hệ thống. KHÔNG đoán.
- Ghi lại pre-fix state: error messages, failing test output, stack traces
- Kích hoạt
ck:debugskill (systematic debugging + root cause tracing) - Kích hoạt
ck:sequential-thinking— hình thành giả thuyết qua lý luận - Spawn
Exploreagents song song test từng giả thuyết - Nếu 2+ giả thuyết sai → tự động kích hoạt
ck:problem-solving - Tạo diagnosis report: confirmed root cause, evidence chain
Step 2: Diagnosed — Root cause: missing Site relation in Prisma include, Evidence: stack trace line 42Bước 3: Complexity Assessment
Phân loại độ phức tạp trước khi chọn workflow:
| Level | Dấu hiệu | Workflow |
|---|---|---|
| Simple | 1 file, lỗi rõ ràng, type/lint | Quick |
| Moderate | Nhiều file, root cause không rõ | Standard |
| Complex | System-wide, ảnh hưởng architecture | Deep |
| Parallel | 2+ issues độc lập | Multi-agent |
Bước 4: Fix Implementation
Implement fix dựa trên diagnosis findings.
Fix ROOT CAUSE, không fix triệu chứng.
Minimal changes, follow patterns hiện có.
Bước 5: Verify + Prevent (BẮT BUỘC)
- Verify: Chạy ĐÚNG commands từ pre-fix state. So sánh output.
- Regression test: Thêm/update test cho issue vừa fix. Test PHẢI fail nếu bỏ fix.
- Prevention gate: Thêm defense-in-depth nếu applicable.
- Parallel verification: Typecheck + lint + build + test chạy song song.
Step 5: Verified — before: HTTP 500, after: HTTP 201, 2 tests added, 1 guard addedHard Gate: KHÔNG được đề xuất hay implement fix trước khi hoàn thành Bước 1-2 (Scout + Diagnose). Fix triệu chứng là THẤT BẠI. Tìm root cause trước.
Ví dụ thực tế
- Input
- Output
So sánh với chat trực tiếp
| Tiêu chí | /fix | Chat trực tiếp |
|---|---|---|
| Diagnosis | 6 bước có hệ thống, evidence-based | Đoán nguyên nhân, thử fix |
| Root cause | BẮT BUỘC tìm root cause trước | Thường fix triệu chứng |
| Regression test | BẮT BUỘC thêm test cho bug đã fix | Có thể bỏ qua |
| Prevention | Thêm guards (validation, type check) | Chỉ fix bug hiện tại |
| Verify | Chạy lại ĐÚNG commands, so sánh before/after | Claim “đã fix” mà không verify |
| Escalation | Sau 3 lần fail → dừng, hỏi user | Tiếp tục thử |
| Documentation | Tự động cập nhật docs | Không cập nhật |
Khi nào dùng / không dùng
| Dùng | Không dùng |
|---|---|
| Bug runtime (500 error, crash) | Implement feature mới (dùng /cook) |
| Tests đang fail | Lập kế hoạch (dùng /plan) |
| TypeScript errors | Review code (dùng /code-review) |
| CI/CD bị lỗi | Tạo dự án mới (dùng /bootstrap) |
| UI/CSS bị vỡ | Thay đổi business logic lớn |
8 Sub-commands chi tiết
/fix "mô tả" — Intelligent Routing (mặc định)
Tự động detect loại bug và route tới sub-command phù hợp:
| Keywords trong mô tả | Route tới |
|---|---|
| type, typescript, tsc | /fix:types |
| ui, ux, design, layout, css, responsive | /fix:ui |
| github actions, pipeline, ci/cd, build failed | /fix:ci |
| test, spec, jest, vitest, failing test | /fix:test |
| logs, error logs, stack trace | /fix:logs |
| 2+ issues không liên quan | /fix:parallel |
| complex, architecture, refactor, system-wide | /fix:hard |
| Mặc định (bug nhỏ, 1 file) | /fix:fast |
/fix:fast — Fix nhanh
/fix:hard — Fix phức tạp
/fix:test — Fix failing tests
/fix:ci — Fix CI/CD
/fix:types — Fix TypeScript errors
tsc --noEmit → tìm tất cả type errors → fix type definitions → đảm bảo strict mode pass.
/fix:ui — Fix UI issues
ck:chrome-devtools screenshot + analyze. Fix layout, responsive, style.
/fix:logs — Phân tích logs
/fix:parallel — Fix song song
fullstack-developer agents fix song song cho các issues độc lập.
Lưu ý & Best Practices
Sai lầm phổ biến:
- Fix triệu chứng thay vì root cause → bug quay lại tuần sau
- Không viết regression test → same bug tái phát khi refactor
- Retry 3+ lần cùng approach → tốn token, vẫn không fix được
- Dùng
/fixchung thay vì sub-command chuyên biệt → chẩn đoán chậm
Tips từ team:
- Luôn chẩn đoán trước:
/scout→/ck-debug→ rồi mới/fix - Viết test reproduce bug TRƯỚC khi fix — đảm bảo fix đúng chỗ
- Nếu 3 lần fail → dừng, dùng
/brainstormhoặc hỏi team - Dùng đúng sub-command:
/fix:typescho TS errors,/fix:cicho CI,/fix:uicho layout