fix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

fix

修复

Name

名称

han-core:fix - Debug and fix bugs, errors, or unexpected behavior
han-core:fix - 调试并修复程序漏洞、错误或异常行为

Synopsis

语法

/fix [arguments]
/fix [参数]

Description

描述

Debug and fix bugs, errors, or unexpected behavior
调试并修复程序漏洞、错误或异常行为

Implementation

实现方式

Investigate, diagnose, and fix bugs or unexpected behavior in the codebase.
调查、诊断并修复代码库中的漏洞或异常行为。

Process

流程

Follow this process to fix bugs:
  1. Reproduce the issue: Confirm the bug exists and understand when it happens
  2. Gather information: Error messages, logs, stack traces, user reports
  3. Form hypothesis: What might be causing the issue?
  4. Investigate: Use debugging tools, add logging, trace execution
  5. Identify root cause: Find the actual source of the problem
  6. Implement fix: Change code to resolve the issue
  7. Verify fix: Confirm the bug is resolved and no new issues introduced
  8. Add regression test: Prevent the bug from returning
遵循以下流程修复漏洞:
  1. 复现问题:确认漏洞存在并明确触发场景
  2. 收集信息:错误信息、日志、堆栈跟踪、用户反馈
  3. 提出假设:可能是什么原因导致了该问题?
  4. 调查分析:使用调试工具、添加日志、追踪执行流程
  5. 定位根因:找到问题的实际根源
  6. 实施修复:修改代码解决问题
  7. 验证修复:确认漏洞已解决且未引入新问题
  8. 添加回归测试:防止漏洞再次出现

Bug Fixing Principles

漏洞修复原则

Understand before fixing:
  • Don't guess and patch - find the root cause
  • Reproduce reliably before attempting fix
  • Understand why the bug exists, not just symptoms
Fix properly:
  • Fix the cause, not symptoms
  • Consider edge cases and similar issues
  • Add tests to prevent regression
  • Document why the fix works
Verify thoroughly:
  • Original issue resolved
  • No new bugs introduced
  • Related scenarios still work
  • Tests pass (existing + new)
先理解再修复:
  • 不要盲目猜测和打补丁 - 找到问题的根本原因
  • 在尝试修复前确保能稳定复现问题
  • 理解漏洞产生的原因,而不只是表面症状
正确修复:
  • 修复问题根源,而非表面症状
  • 考虑边缘情况和类似问题
  • 添加测试以防止回归
  • 记录修复的原理
全面验证:
  • 原始问题已解决
  • 未引入新漏洞
  • 相关场景仍能正常工作
  • 测试通过(现有测试 + 新增测试)

Examples

示例

When the user says:
  • "This function throws an error when passed null"
  • "The page crashes on mobile devices"
  • "Users report checkout fails intermittently"
  • "Fix the memory leak in the background worker"
  • "Debug why tests are failing on CI"
当用户提出以下需求时:
  • "当传入null时,这个函数会抛出错误"
  • "移动端页面会崩溃"
  • "用户反馈结账流程间歇性失败"
  • "修复后台 worker 中的内存泄漏问题"
  • "调试为什么CI上的测试失败"

Debugging Techniques

调试技巧

Add logging:
typescript
console.log('Value at checkpoint:', value)
logger.debug('Processing item', { id: item.id, status: item.status })
Use debugger:
typescript
debugger;  // Browser will pause here
Binary search:
  • Comment out half the code
  • If bug disappears, it's in that half
  • Repeat until isolated
Compare working vs broken:
  • What changed between working and broken?
  • Git bisect to find breaking commit
  • Compare with known-good version
添加日志:
typescript
console.log('检查点数值:', value)
logger.debug('处理项目', { id: item.id, status: item.status })
使用调试器:
typescript
debugger;  // 浏览器将在此处暂停
二分排查法:
  • 注释掉一半代码
  • 如果漏洞消失,说明问题在该部分代码中
  • 重复此过程直至定位到问题点
对比正常与异常版本:
  • 正常版本和异常版本之间有哪些变化?
  • 使用Git bisect找到引入问题的提交
  • 与已知正常版本进行对比

Output Format

输出格式

After fixing:
markdown
undefined
修复完成后,按照以下格式输出:
markdown
undefined

Bug Fix: [Brief description]

Bug修复: [简要描述]

Issue

问题

[What was broken and how it manifested]
[问题表现及具体症状]

Root Cause

根因

[Why the bug existed]
[漏洞产生的原因]

Fix

修复方案

[What was changed and why it fixes the issue]
[修改内容及修复原理]

Verification

验证结果

[Evidence the fix works - use proof-of-work skill]
  • Original issue no longer reproduces
  • Tests pass (include test output)
  • Related scenarios still work
[证明修复有效的证据 - 使用proof-of-work技能]
  • 原始问题不再复现
  • 测试通过(包含测试输出)
  • 相关场景仍正常运行

Prevention

预防措施

[What test was added to prevent regression]
undefined
[新增的用于防止回归的测试内容]
undefined

Notes

注意事项

  • Use TaskCreate to track debugging steps
  • Document findings even if you don't find the root cause immediately
  • Use proof-of-work skill to show the bug is actually fixed
  • Consider using boy-scout-rule skill to improve surrounding code
  • Add test to prevent regression (use test-driven-development skill)
  • 使用TaskCreate追踪调试步骤
  • 即使未立即找到根因,也要记录调查结果
  • 使用proof-of-work技能证明漏洞已被实际修复
  • 考虑使用boy-scout-rule技能优化周边代码
  • 添加测试以防止回归(使用test-driven-development技能)