AgentSkillsCN

error-diagnosis

当用户遭遇“错误”“异常”“运行失败”“堆栈跟踪”“程序崩溃”或需要对错误进行分类时,此技能可提供结构化的根源分析与预防策略。

SKILL.md
--- frontmatter
name: error-diagnosis
description: When user encounters "error", "exception", "failed", "stack trace", "crashed", or needs error categorization. Provides structured root cause analysis and prevention strategies.

Error Diagnosis Framework

When This Activates

This skill activates when:

  • User shares an error message or stack trace
  • Something failed unexpectedly
  • Debugging session errors
  • Need to categorize and prevent errors

Error Categories

1. Prompt Errors (User → Claude)

SubcategoryDescriptionPrevention
ambiguous_instructionCould be interpreted multiple waysBe specific about expected output
missing_constraintsDidn't specify what NOT to doState exclusions explicitly
too_verboseKey requirements buried in textPut critical info first
implicit_expectationsRequirements in head, not promptWrite everything down
wrong_abstractionToo high/low level for taskMatch detail to task complexity

2. Context Errors (Session State)

SubcategoryDescriptionPrevention
context_rotConversation too longClear context periodically
stale_contextOld info polluting responsesStart fresh for new topics
missing_contextAssumed Claude rememberedRe-state critical context
wrong_contextIrrelevant info drowning signalProvide focused context

3. Harness Errors (Agent System)

SubcategoryDescriptionPrevention
subagent_context_lossInfo didn't reach subagentsPass explicit context
wrong_agent_typeUsed wrong specialized agentMatch agent to task
no_guardrailsDidn't constrain behaviorSet clear boundaries
missing_validationNo check that output correctVerify results

4. Tool Errors (Execution)

SubcategoryDescriptionPrevention
wrong_commandIncorrect command/syntaxVerify syntax before running
missing_dependencyPackage not installedCheck deps first
permission_errorInsufficient permissionsCheck access rights
path_errorFile/directory not foundVerify paths exist
syntax_errorCode syntax issueLint before running

Diagnosis Workflow

Step 1: Categorize

code
Error received → Identify category → Identify subcategory

Step 2: Extract Details

json
{
  "category": "tool",
  "subcategory": "path_error",
  "summary": "File not found when trying to read config",
  "root_cause": "Path was relative but CWD was different",
  "prevention": "Use absolute paths or verify CWD"
}

Step 3: Generate Fix

Based on category, apply targeted fix strategy.

Step 4: Record Learning

Add to ReasoningBank for future reference.

Common Error Patterns

"Module not found"

code
Category: tool/missing_dependency
Check: Is the package installed? Right version? Correct import path?
Fix: npm install / pip install / check import statement

"Permission denied"

code
Category: tool/permission_error
Check: File permissions? Running as correct user? Sudo needed?
Fix: chmod, chown, or run with appropriate privileges

"Undefined is not a function"

code
Category: tool/syntax_error (or context/stale_context)
Check: Is object initialized? Correct method name? Async/await issue?
Fix: Add null checks, verify object shape, await promises

"CORS error"

code
Category: tool/wrong_command (or infrastructure)
Check: Server CORS config? Proxy setup? Credentials mode?
Fix: Configure CORS headers, use proxy in dev

"Claude did the wrong thing"

code
Category: prompt/* (most likely)
Check: Was instruction ambiguous? Missing constraints? Too much context?
Fix: Rewrite prompt with specific details

Error Response Template

When diagnosing an error, respond with:

markdown
## Error Analysis

**Category:** [category/subcategory]
**Root Cause:** [what actually went wrong]

## Fix
[specific steps to resolve]

## Prevention
[how to avoid this in the future]

## Similar Past Issues
[if any relevant observations exist]

MCP Tools for Diagnosis

code
# Check past similar errors
memory_sessions category=bugfix query="similar error"

# Get reasoning bank solutions
reasoning_query context="error description"

# Check if this was a known gotcha
memory_sessions category=gotcha query="topic"

Learning Integration

Errors feed into:

  • ReasoningBank trajectories
  • Observation extractor (bugfix category)
  • Confidence calibration (track error rates by domain)