返回 Skill 列表
extension
分类: 开发与工程无需 API Key

script-bugfix

通过隔离副作用,将核心逻辑提取到受控环境中进行行为验证,然后以最小的改动重新集成,来调试和修复复杂的脚本。当脚本缺乏单元测试,并且由于IO、环境或编排复杂性而难以推理时,请使用这种方法。

person作者: jakexiaohubgithub

This skill guides safe and effective bug fixing in complex, side-effect-heavy scripts (especially shell scripts) by reducing cognitive load and state space before attempting a fix.

The goal is not to refactor the whole system, but to locate the root cause by temporarily transforming the problem into a no-side-effect form.

Core Principle

Isolate side effects → Fix core logic → Minimize integration

Treat debugging as a process of complexity reduction, not trial-and-error.

When to Use

Use this skill when:

  • The script performs IO, calls external commands, mutates environment, or depends on timing.
  • There is little or no unit test coverage.
  • Bugs are hard to reproduce or reason about in the full system.
  • Only a specific logic slice actually needs fixing.

Method

First, identify the core logic that likely contains the bug. This is the part that transforms inputs into decisions or outputs, not the part that touches the outside world.

Next, isolate side effects:

  • Do not debug inside the live system.
  • Create a local, controlled environment (e.g. an internal folder) where side effects are replaced with mocks, stubs, or fixed inputs.
  • Make behavior deterministic and repeatable.

Then, extract the logic:

  • Move or reimplement the core logic so it can run without real filesystem, network, time, or external commands.
  • Pass all dependencies explicitly instead of reading global state.

Now, debug and fix:

  • Reproduce the bug inside the controlled environment.
  • Fix the logic where inputs and outputs are clear.
  • Validate correctness through repeated runs, not intuition.

Finally, reintegrate minimally:

  • Bring the fixed logic back into the original script.
  • Change as little orchestration code as possible.
  • Avoid unrelated refactors during integration.

Debugging Mindset

  • Reduce the problem’s state space before reasoning.
  • Prefer controlled experiments over live-system probing.
  • Treat side effects as noise until logic is proven correct.
  • Aim for local certainty before global confidence.

This skill prioritizes root cause clarity over speed, and determinism over cleverness.