AgentSkillsCN

bd-problem-solving

评估多种方案、开展问题解决、分析逻辑,并确定最优行动路径。适用于决策制定、调试排错、解决技术难题,以及探索代码库。

SKILL.md
--- frontmatter
name: bd-problem-solving
description: Evaluates options, performs problem-solving, analyzes logic, and determines the best course of action. Use for decision-making, debugging, resolving technical issues, and exploring codebases.

Problem Solving

This skill guides systematic approaches to debugging, solution design, and code comprehension. Apply these methodologies when facing technical challenges, exploring unfamiliar codebases, or making architectural decisions.

The user provides a problem to solve: a bug to fix, a feature to design, code to understand, or a technical decision to make. They may include error messages, code snippets, or context about the system.


Problem-Solving Thinking

Before diving into solutions, understand the problem deeply:

  • Symptom vs. Root Cause: What is the visible issue? What is the underlying cause?
  • Scope: Is this a local issue or a systemic problem?
  • Constraints: What are the technical, time, and resource constraints?
  • Success Criteria: How will you know the problem is solved?

CRITICAL: Never treat symptoms. Always find and fix the root cause. A quick fix that masks the issue will resurface later with greater impact.

When This Applies

Use this skill when:

  • Debugging errors or unexpected behavior
  • Designing solutions for new features
  • Understanding unfamiliar codebases
  • Making technical decisions with trade-offs
  • Investigating performance issues
  • Analyzing system failures

Tree of Thoughts Problem-Solving

Applies to: Complex problems with multiple potential solutions, architectural decisions, debugging

Methodology

Explore problems like a tree, branching into multiple potential solutions before committing:

code
Problem
├── Solution A
│   ├── Pro: Fast implementation
│   ├── Con: Technical debt
│   └── Risk: May not scale
├── Solution B
│   ├── Pro: Clean architecture
│   ├── Con: More time needed
│   └── Risk: Over-engineering
└── Solution C
    ├── Pro: Reuses existing code
    ├── Con: Couples to legacy system
    └── Risk: Maintenance burden

Steps

  1. Define the problem clearly - What exactly needs to be solved?
  2. Generate multiple solutions - At least 2-3 different approaches
  3. Evaluate each branch - Consider trade-offs for each
  4. Select and justify - Choose based on constraints and priorities
  5. Validate the choice - Ensure it addresses root cause

Evaluation Criteria

CriterionQuestions to Ask
CorrectnessDoes it fully solve the problem?
SimplicityIs it the simplest solution that works?
MaintainabilityCan others understand and modify it?
ScalabilityWill it work as load/data grows?
TestabilityCan it be effectively tested?
Time-to-implementHow long will it take?
RiskWhat could go wrong?

Graph of Thoughts Code Comprehension

Applies to: Understanding unfamiliar codebases, system analysis, onboarding

Methodology

Map code relationships as a graph to understand how components interact:

code
[Controller] ──calls──> [Service] ──uses──> [Repository]
      │                     │                     │
      │                     v                     v
      │              [Domain Model] <──maps── [Entity]
      │                     │
      └──────returns───────>│

Analysis Approaches

Top-Down Analysis:

  1. Start with entry points (main, routes, handlers)
  2. Follow the request/data flow downward
  3. Identify major components and their responsibilities
  4. Drill into details only as needed

Bottom-Up Analysis:

  1. Start with data models and entities
  2. Find what uses them
  3. Build up understanding of data flow
  4. Connect to entry points

Combine Both: Use top-down for architecture overview, bottom-up for specific feature understanding.

What to Map

ComponentQuestions to Answer
Entry PointsWhere does execution start?
Data FlowHow does data move through the system?
DependenciesWhat depends on what?
Side EffectsWhere does state change? External calls?
Error HandlingWhere are errors caught and handled?
ConfigurationWhat is configurable? Where?

Root Cause Analysis

Applies to: Debugging, incident response, preventing recurrence

The 5 Whys Technique

Keep asking "why" until you reach the root cause (typically 5 levels):

code
Problem: Production server crashed
Why 1: Memory exhausted
Why 2: Memory leak in image processing
Why 3: Images not released after processing
Why 4: Exception skipped cleanup code
Why 5: No try-finally around resource allocation
Root Cause: Missing resource cleanup pattern

Debugging Methodology

StepAction
1. ReproduceCan you reliably trigger the issue?
2. IsolateWhat is the minimal code that exhibits the bug?
3. HypothesizeWhat could cause this behavior?
4. TestValidate or eliminate each hypothesis
5. FixAddress the root cause, not just the symptom
6. VerifyConfirm the fix and check for regressions
7. PreventAdd tests, monitoring, or safeguards

Common Root Cause Categories

CategoryExamples
State ManagementRace conditions, stale cache, incorrect initialization
Resource HandlingLeaks, exhaustion, improper cleanup
Error HandlingSwallowed exceptions, missing cases, incorrect recovery
Data IntegrityInvalid input, encoding issues, type mismatches
TimingTimeouts, ordering assumptions, async issues
ConfigurationEnvironment differences, missing settings

Decision Framework

Applies to: Technical decisions, architecture choices, tool selection

Decision Documentation

For significant decisions, document:

code
## Decision: [Title]

### Context
What is the situation? What problem are we solving?

### Options Considered
1. Option A: [Description]
   - Pros: ...
   - Cons: ...

2. Option B: [Description]
   - Pros: ...
   - Cons: ...

### Decision
We chose Option [X] because...

### Consequences
- Positive: ...
- Negative: ...
- Risks: ...

Trade-off Analysis

DimensionTrade-off
Speed vs. QualityFast delivery vs. maintainable code
Flexibility vs. SimplicityConfigurable vs. easy to understand
Consistency vs. AutonomyStandardization vs. team freedom
Build vs. BuyCustom solution vs. third-party tool
Now vs. LaterImmediate fix vs. long-term solution

Performance Investigation

Applies to: Slow operations, resource issues, scalability problems

Investigation Steps

  1. Measure - Profile before optimizing (don't guess)
  2. Identify - Find the actual bottleneck
  3. Analyze - Understand why it's slow
  4. Optimize - Fix the specific bottleneck
  5. Verify - Measure improvement

Common Performance Issues

IssueInvestigation
N+1 QueriesCheck database query count per request
Memory LeaksMonitor memory over time, check allocations
Blocking I/OLook for synchronous network/disk calls
Inefficient AlgorithmsProfile CPU hotspots, check complexity
Missing IndexesAnalyze query execution plans
Cache MissesCheck cache hit rates and invalidation

Platform-Specific Debugging

Mobile (iOS/Android/Flutter)

Applies to: Mobile application issues

Issue TypeTools/Approach
UI IssuesLayout inspector, view hierarchy debugger
MemoryInstruments (iOS), Memory Profiler (Android)
NetworkCharles Proxy, network inspector
CrashesCrashlytics, console logs, stack traces
PerformanceTime Profiler, systrace

Web (Frontend)

Applies to: Web application issues

Issue TypeTools/Approach
RenderingReact DevTools, Vue DevTools, DOM inspector
NetworkNetwork tab, request/response inspection
PerformanceLighthouse, Performance tab, Web Vitals
StateRedux DevTools, state inspection
MemoryMemory tab, heap snapshots

Backend (APIs/Services)

Applies to: Server-side issues

Issue TypeTools/Approach
Request FlowDistributed tracing (Jaeger, Zipkin)
LogsStructured logging, log aggregation
DatabaseQuery analysis, slow query logs
ResourcesMetrics (CPU, memory, connections)
ErrorsError tracking (Sentry, Bugsnag)

Anti-Patterns (NEVER use)

  • Shotgun debugging: Making random changes hoping something works
  • Symptom fixing: Addressing visible issues without finding root cause
  • Single-solution thinking: Not considering alternatives
  • Premature optimization: Optimizing without profiling first
  • Blame-first debugging: Assuming the problem is elsewhere
  • Ignoring context: Not understanding the system before changing it
  • Copy-paste fixing: Applying fixes without understanding them

Core Philosophy

"Given enough eyeballs, all bugs are shallow." — Linus's Law

Approach every problem systematically. Understand before you act. Fix root causes, not symptoms. Document decisions for future reference.