agentleFS
u9401066u9401066/template-is-all-you-need/.claude/skills/bug-fix/SKILL.md

bug-fix

Skill3 starsChanged 9 months agoApache-2.0View on GitHub

Structured bug fixing workflow with root cause analysis and regression prevention. Triggers: BF, 修 bug, fix bug, debug, 除錯, 錯誤, error, 問題, issue, 修復, fix, 故障, fault, 異常, exception, 失敗, failure, 不能用, broken, 壞掉.

19 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use refactor and code-review.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • GitHubSkill

    refactor

    Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 3 projects that use this

The file

Files
SKILL.md

Bug 修復工作流

描述

結構化的 Bug 修復流程,包含根因分析和回歸測試。

觸發條件

  • 「修 bug」「fix bug」「除錯」
  • 「BF: [問題描述]」

🐛 Bug 修復流程

┌─────────────────────────────────────────────────────────────┐
│                  Bug Fix Workflow                            │
├─────────────────────────────────────────────────────────────┤
│  Step 1: 🔍 重現 (Reproduce)                                 │
│  ├─ 確認重現步驟                                             │
│  ├─ 收集錯誤訊息/日誌                                        │
│  └─ 建立最小重現案例                                         │
├─────────────────────────────────────────────────────────────┤
│  Step 2: 🎯 定位 (Locate)                                    │
│  ├─ 分析錯誤堆疊                                             │
│  ├─ 追蹤程式碼路徑                                           │
│  └─ 識別問題根因                                             │
├─────────────────────────────────────────────────────────────┤
│  Step 3: 🧪 測試先行 (Test First)                            │
│  ├─ 撰寫失敗的測試案例                                       │
│  ├─ 確認測試能重現問題                                       │
│  └─ 這將成為回歸測試                                         │
├─────────────────────────────────────────────────────────────┤
│  Step 4: 🔧 修復 (Fix)                                       │
│  ├─ 實施修復                                                 │
│  ├─ 最小化變更範圍                                           │
│  └─ 確認測試通過                                             │
├─────────────────────────────────────────────────────────────┤
│  Step 5: ✅ 驗證 (Verify)                                    │
│  ├─ 執行完整測試套件                                         │
│  ├─ 檢查是否引入新問題                                       │
│  └─ [code-reviewer] 審查修復                                │
├─────────────────────────────────────────────────────────────┤
│  Step 6: 📝 記錄 (Document)                                  │
│  ├─ 更新 Memory Bank                                        │
│  ├─ 記錄根因分析                                             │
│  └─ 更新相關文檔                                             │
└─────────────────────────────────────────────────────────────┘

🚀 使用範例

基本用法

「修 bug:用戶登入時出現 500 錯誤」

AI 執行:
1. 🔍 要求提供錯誤日誌和重現步驟
2. 🎯 分析堆疊追蹤,定位問題
3. 🧪 建立失敗測試案例
4. 🔧 實施修復
5. ✅ 驗證修復
6. 📝 記錄修復過程

帶錯誤訊息

「BF: TypeError: 'NoneType' object is not subscriptable at line 45」

AI 執行:
1. 讀取相關檔案的第 45 行
2. 分析為什麼變數是 None
3. 建立邊界條件測試
4. 加入 None 檢查或修正邏輯

📊 輸出格式

## 🐛 Bug 修復報告

### 問題描述
用戶登入時出現 500 Internal Server Error

### 根因分析
- **位置**: `src/application/services/auth_service.py:45`
- **原因**: 當 user 不存在時,直接存取 `user.password_hash` 導致 NoneType 錯誤
- **類型**: 邊界條件未處理

### 修復方案

#### 回歸測試(先撰寫)
```python
def test_login_with_nonexistent_user():
    """登入不存在的用戶應返回 401"""
    result = auth_service.login("nonexistent@test.com", "password")
    assert result.is_error
    assert result.error_code == "USER_NOT_FOUND"

程式碼修復

# Before
def login(self, email: str, password: str):
    user = self.user_repo.find_by_email(email)
    if not bcrypt.verify(password, user.password_hash):  # 💥 NoneType!
        ...

# After
def login(self, email: str, password: str):
    user = self.user_repo.find_by_email(email)
    if user is None:
        return Result.failure("USER_NOT_FOUND")
    if not bcrypt.verify(password, user.password_hash):
        ...

驗證結果

  • ✅ 回歸測試通過
  • ✅ 原有測試套件通過 (42/42)
  • ✅ 無新增 lint 錯誤

預防措施

  • 類似的 None 檢查已在 5 個相關方法中加入
  • 建議:啟用 mypy strict mode

---

## 🎯 根因分類

| 類型 | 描述 | 預防 |
|------|------|------|
| **邊界條件** | 未處理 null/empty/邊界值 | 加強邊界測試 |
| **競爭條件** | 並發存取導致 | 加入鎖定機制 |
| **類型錯誤** | 類型不匹配 | 啟用 strict typing |
| **邏輯錯誤** | 業務邏輯不正確 | 加強 domain 測試 |
| **整合問題** | 外部服務互動 | 加強整合測試 |

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.