bug-fix

bug-fix is a cursor rule for coding agents from Mr-chen-05/rules-2.1-optimized-zh. It costs 0 tokens per session (2,263 once invoked), scanned A, original, MIT.

A step-by-step process for fixing a software bug, from recording and reproducing the problem to testing the fix and opening a pull request. A pull request is a proposed code change for review before it is merged.

In plain words
What is it for?
Use it to document bugs, reproduce them, write a test that initially fails, implement a fix, verify it, and prepare the change for review.
Why use it?
It gives the team a shared way to investigate the cause and verify that the fix works. It also keeps issue details, branches, tests, and review steps together.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mr-chen-05/rules-2.1-optimized-zh/bug-fix
Clone the repo
git clone --depth 1 https://github.com/Mr-chen-05/rules-2.1-optimized-zh

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for bug-fix

README.md
[![agentmods](https://agentmods.dev/badge/rules/mr-chen-05/rules-2.1-optimized-zh/bug-fix.svg)](https://agentmods.dev/rules/mr-chen-05/rules-2.1-optimized-zh/bug-fix)
Your own site
<a href="https://agentmods.dev/rules/mr-chen-05/rules-2.1-optimized-zh/bug-fix"><img src="https://agentmods.dev/badge/rules/mr-chen-05/rules-2.1-optimized-zh/bug-fix.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,263 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02263
Opus 5 $0.00000 $0.01131
Sonnet 5 $0.00000 $0.00453
Haiku 4.5 $0.00000 $0.00226

Measured 4d ago against content hash e97bd156f887, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

bug-fix scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

项目规则/bug-fix.mdc · 326 lines

How it starts

The opening of the file, as written. The whole thing — 326 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🐛 Bug Fix Workflow - Bug修复工作流

从问题创建到拉取请求的完整Bug修复工作流程。

🚀 Commands - 命令

  • /bug-fix - 启动Bug修复工作流
  • /reproduce-bug - 重现Bug
  • /root-cause - 根因分析
  • /fix-verify - 修复验证

📋 Process - 修复流程

🔍 Before Starting - 开始前准备

1. GitHub Issue Creation - 创建GitHub问题
**Bug标题**: [组件/模块] 简短描述性标题

**环境信息**:
- 操作系统: Windows 11 / macOS 13 / Ubuntu 22.04
- 浏览器: Chrome 120 / Firefox 121 / Safari 17
- 应用版本: v2.1.0
- Node.js版本: v18.19.0

**重现步骤**:
1. 打开应用
2. 点击登录按钮
3. 输入有效凭据
4. 点击提交

**预期行为**: 用户应该成功登录并跳转到仪表板

**实际行为**: 显示"网络错误",用户停留在登录页面

**错误信息**:

TypeError: Cannot read property 'token' of undefined at LoginComponent.handleLogin (login.component.ts:45)


**截图/录屏**: [附加相关截图或录屏]

**优先级**: High / Medium / Low
**标签**: bug, frontend, authentication
2. Git Branch Creation - 创建Git分支
# 创建并切换到功能分支
git checkout -b fix/login-token-error

# 或者使用更具描述性的分支名
git checkout -b fix/issue-123-login-authentication-error

🔧 Fix the Bug - 修复Bug

Step 1: Reproduce the Issue - 重现问题
# 1. 切换到问题分支
git checkout main
git pull origin main

# 2. 尝试重现Bug
npm start
# 按照问题描述的步骤操作

# 3. 确认问题存在
# 记录重现步骤和错误信息
Step 2: Write Failing Test - 编写失败测试
// 示例:为Bug编写测试用例
describe('LoginComponent', () => {
  it('should handle login with valid credentials', async () => {
    // 这个测试应该失败,因为Bug存在
    const mockUser = { username: 'test', password: 'password' };
    const result = await loginComponent.handleLogin(mockUser);
    
    expect(result.success).toBe(true);
    expect(result.token).toBeDefined();
    expect(result.user).toEqual(expect.objectContaining({
      username: 'test'
    }));
  });

  it('should handle undefined response gracefully', async () => {
    // 测试边界条件
    mockApiService.login.mockResolvedValue(undefined);
    
    const result = await loginComponent.handleLogin(mockUser);
    expect(result.success).toBe(false);
    expect(result.error).toBeDefined();
  });
});
Step 3: Implement the Fix - 实现修复
// 修复前的代码
async handleLogin(credentials: LoginCredentials) {
  try {
    const response = await this.authService.login(credentials);
    // Bug: 没有检查response是否存在
    localStorage.setItem('token', response.token);
    this.router.navigate(['/dashboard']);
  } catch (error) {
    this.showError('登录失败');
  }
}

// 修复后的代码
async handleLogin(credentials: LoginCredentials) {
  try {
    const response = await this.authService.login(credentials);
    
    // 修复: 添加响应验证
    if (!response || !response.token) {
      throw new Error('Invalid response from server');
    }
    
    localStorage.setItem('token', response.token);
    this.router.navigate(['/dashboard']);
    return { success: true, token: response.token, user: response.user };
  } catch (error) {
    console.error('Login error:', error);
    this.showError('登录失败: ' + error.message);
    return { success: false, error: error.message };
  }
}

Read the full file on GitHub · 326 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 326 lines · 0 tokens per session scan A e97bd156f887

Subscribe to this mod's changes

bug-fix is a cursor rule published in the GitHub repository Mr-chen-05/rules-2.1-optimized-zh (29 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,263 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.