learn

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Learn Error Pattern Skill

错误模式学习Skill

Operator Context

技能操作上下文

This skill operates as an operator for manual knowledge ingestion, configuring Claude to parse user-provided error-solution pairs and store them in the cross-session learning database. It implements a Parse-Classify-Store-Confirm workflow with deterministic Python scripts performing all database operations.
本技能作为手动知识注入的操作符,配置Claude以解析用户提供的错误-解决方案配对,并将其存储到跨会话学习数据库中。它实现了解析-分类-存储-确认的工作流,所有数据库操作均由确定性Python脚本执行。

Hardcoded Behaviors (Always Apply)

硬编码行为(始终生效)

  • Input Validation: Never store empty error patterns or empty solutions
  • Environment Variable Injection Prevention: Always pass values via environment variables to the Python script, never inline user strings into code
  • High Confidence: Manually taught patterns always receive confidence 0.9
  • Single Pattern Per Invocation: Store exactly one pattern per
    /learn
    call
  • 输入验证:绝不存储空错误模式或空解决方案
  • 防止环境变量注入:始终通过环境变量向Python脚本传递值,绝不将用户字符串直接嵌入代码
  • 高置信度:手动传授的模式始终获得0.9的置信度
  • 每次调用仅存储单个模式:每个
    /learn
    调用仅存储一个模式

Default Behaviors (ON unless disabled)

默认行为(启用状态,除非手动禁用)

  • Auto-Classification: Determine error type and fix type from solution text
  • Confirmation Output: Display stored pattern details back to user
  • Duplicate Handling: If pattern already exists, update its confidence to 0.9
  • 自动分类:根据解决方案文本确定错误类型和修复类型
  • 确认输出:向用户显示已存储的模式详情
  • 重复处理:如果模式已存在,将其置信度更新为0.9

Optional Behaviors (OFF unless enabled)

可选行为(禁用状态,除非手动启用)

  • Batch Mode: Accept multiple patterns from a file (one per line,
    error -> solution
    format)
  • Dry Run: Parse and classify without storing, showing what would be saved
  • 批量模式:从文件中接收多个模式(每行一个,格式为
    error -> solution
  • 试运行模式:仅解析和分类,不存储,显示将要保存的内容

What This Skill CAN Do

本技能可实现的功能

  • Parse "error -> solution" input into structured pattern data
  • Classify fix types (auto, skill, agent, manual) from solution text
  • Store patterns in the unified learning database at 0.9 confidence
  • Update confidence on existing patterns for the same error signature
  • 将「error -> solution」输入解析为结构化模式数据
  • 根据解决方案文本分类修复类型(自动、skill、agent、手动)
  • 以0.9的置信度将模式存储到统一学习数据库中
  • 针对相同错误签名的现有模式更新其置信度

What This Skill CANNOT Do

本技能不可实现的功能

  • Debug live issues (use systematic-debugging instead)
  • Automatically learn from tool errors (that is the error-learner hook)
  • Query or list existing patterns (use
    python3 ~/.claude/scripts/learning-db.py query --category error
    )
  • Delete or reset the database (remove
    ~/.claude/learning/learning.db
    )
  • Store patterns without user-provided error AND solution text

  • 调试实时问题(请使用systematic-debugging技能)
  • 从工具错误中自动学习(该功能由error-learner钩子负责)
  • 查询或列出现有模式(请使用
    python3 ~/.claude/scripts/learning-db.py query --category error
  • 删除或重置数据库(请删除
    ~/.claude/learning/learning.db
    文件)
  • 在用户未同时提供错误和解决方案文本的情况下存储模式

Instructions

操作步骤

Phase 1: PARSE

阶段1:解析

Goal: Extract error pattern and solution from user input.
Step 1: Identify input format
Accepted formats:
  • /learn "error pattern" -> "solution"
  • /learn "error pattern" => "solution"
  • Freeform: "teach that X means Y" or "remember: when X, do Y"
Step 2: Extract fields
  • error_pattern
    : The error message or symptom text
  • solution
    : The fix or resolution text
Gate: Both error_pattern and solution are non-empty strings. If either is missing, ask the user for the missing part. Do not proceed with empty fields.
目标:从用户输入中提取错误模式和解决方案。
步骤1:识别输入格式
支持的格式:
  • /learn "错误模式" -> "解决方案"
  • /learn "错误模式" => "解决方案"
  • 自由格式:「告知X对应Y」或「记住:当出现X时执行Y」
步骤2:提取字段
  • error_pattern
    :错误消息或症状文本
  • solution
    :修复或解决方法文本
校验门
error_pattern
solution
都必须是非空字符串。如果任一为空,请向用户索要缺失的部分。不得处理空字段。

Phase 2: CLASSIFY

阶段2:分类

Goal: Determine fix type and action from the solution text.
Apply these rules in order:
  1. Solution contains install command (pip install, npm install, apt install) ->
    fix_type=auto
    ,
    fix_action=install_dependency
  2. Solution contains
    replace_all
    ->
    fix_type=auto
    ,
    fix_action=use_replace_all
  3. Solution references a skill name ->
    fix_type=skill
    ,
    fix_action=<skill-name>
  4. Solution references an agent name ->
    fix_type=agent
    ,
    fix_action=<agent-name>
  5. Otherwise ->
    fix_type=manual
    ,
    fix_action=apply_suggestion
Gate: fix_type and fix_action are determined. Proceed.
目标:根据解决方案文本确定修复类型和操作。
按以下顺序应用规则:
  1. 解决方案包含安装命令(pip install、npm install、apt install)→
    fix_type=auto
    fix_action=install_dependency
  2. 解决方案包含
    replace_all
    fix_type=auto
    fix_action=use_replace_all
  3. 解决方案引用技能名称 →
    fix_type=skill
    fix_action=<skill-name>
  4. 解决方案引用agent名称 →
    fix_type=agent
    fix_action=<agent-name>
  5. 其他情况 →
    fix_type=manual
    fix_action=apply_suggestion
校验门:确定fix_type和fix_action后,继续执行。

Phase 3: STORE

阶段3:存储

Goal: Persist the pattern to the learning database.
Execute the storage script using the
learning-db.py
CLI:
bash
python3 ~/.claude/scripts/learning-db.py record \
  "<error_type>" \
  "<error_signature>" \
  "<error_pattern> → <solution>" \
  --category error \
  --confidence 0.9
Where
<error_type>
is the classified type (e.g., "missing_file", "multiple_matches") and
<error_signature>
is a kebab-case key derived from the error pattern.
Example:
bash
python3 ~/.claude/scripts/learning-db.py record \
  "multiple_matches" \
  "edit-tool-multiple-matches" \
  "Edit tool fails with 'found N matches' → Use replace_all=True parameter" \
  --category error \
  --confidence 0.9
Gate: Script exits 0 and prints confirmation. If script fails, see Error Handling.
目标:将模式持久化到学习数据库中。
使用
learning-db.py
CLI执行存储脚本:
bash
python3 ~/.claude/scripts/learning-db.py record \
  "<error_type>" \
  "<error_signature>" \
  "<error_pattern> → <solution>" \
  --category error \
  --confidence 0.9
其中
<error_type>
是分类后的错误类型(例如"missing_file"、"multiple_matches"),
<error_signature>
是从错误模式衍生的短横线命名格式的键。
示例:
bash
python3 ~/.claude/scripts/learning-db.py record \
  "multiple_matches" \
  "edit-tool-multiple-matches" \
  "Edit tool fails with 'found N matches' → Use replace_all=True parameter" \
  --category error \
  --confidence 0.9
校验门:脚本返回0并打印确认信息。如果脚本执行失败,请查看错误处理部分。

Phase 4: CONFIRM

阶段4:确认

Goal: Report stored pattern back to the user.
Display:
Learned pattern:
  Error: "<error_pattern>"
  Solution: "<solution>"
  Type: <fix_type> (<fix_action>)
  Confidence: 0.9
Gate: User sees confirmation. Skill complete.

目标:向用户报告已存储的模式。
显示内容:
已学习模式:
  错误:"<error_pattern>"
  解决方案:"<solution>"
  类型:<fix_type> (<fix_action>)
  置信度:0.9
校验门:用户看到确认信息后,技能执行完成。

Error Handling

错误处理

Error: "Script fails with ImportError or FileNotFoundError"

错误:"Script fails with ImportError or FileNotFoundError"

Cause: scripts/learning-db.py not found or not synced to ~/.claude/scripts/ Solution: Verify working directory is the repo root, or use
~/.claude/scripts/learning-db.py
for cross-repo access.
原因:scripts/learning-db.py未找到或未同步到~/.claude/scripts/目录 解决方案:确认工作目录为仓库根目录,或使用
~/.claude/scripts/learning-db.py
以实现跨仓库访问。

Error: "Database locked"

错误:"Database locked"

Cause: Another process holds the SQLite lock Solution: Retry after 2 seconds. If persistent, check for hung processes with
lsof ~/.claude/learning/learning.db
.
原因:另一个进程持有SQLite锁 解决方案:2秒后重试。如果问题持续,使用
lsof ~/.claude/learning/learning.db
检查是否有挂起的进程。

Error: "User provides only error, no solution"

错误:"User provides only error, no solution"

Cause: Incomplete input Solution: Ask the user explicitly for the solution text. Do not guess or fabricate solutions.

原因:输入不完整 解决方案:明确向用户索要解决方案文本。不得猜测或编造解决方案。

Anti-Patterns

反模式

Anti-Pattern 1: Storing Vague Patterns

反模式1:存储模糊模式

What it looks like:
/learn "it broke" -> "fix it"
Why wrong: Pattern too vague to match future errors. Solution provides no actionable guidance. Do instead: Ask user to provide the specific error message and concrete fix steps.
表现
/learn "it broke" -> "fix it"
问题:模式过于模糊,无法匹配未来的错误。解决方案未提供可操作的指导。 正确做法:请用户提供具体的错误消息和明确的修复步骤。

Anti-Pattern 2: Inlining User Strings Into Python Code

反模式2:将用户字符串嵌入Python代码

What it looks like: Building Python code with f-strings containing user input Why wrong: Injection risk. Quotes or special characters in error text break the script. Do instead: Always pass via environment variables as shown in Phase 3.
表现:使用包含用户输入的f-string构建Python代码 问题:存在注入风险。错误文本中的引号或特殊字符会导致脚本崩溃。 正确做法:始终如阶段3所示,通过环境变量传递用户输入。

Anti-Pattern 3: Storing Without Confirming Back

反模式3:存储后不向用户确认

What it looks like: Running the script and saying "done" without showing what was stored Why wrong: User cannot verify correctness. Typos go unnoticed. Do instead: Always complete Phase 4 with the full confirmation output.

表现:运行脚本后仅告知"完成",不显示存储的内容 问题:用户无法验证正确性。输入错误无法被发现。 正确做法:始终完成阶段4,显示完整的确认输出。

References

参考资料

  • hooks/lib/learning_db_v2.py
    : Unified learning database module
  • scripts/learning-db.py
    : CLI for recording, querying, and managing learnings
  • hooks/error-learner.py
    : Automatic error learning hook (complementary system)
  • hooks/lib/learning_db_v2.py
    :统一学习数据库模块
  • scripts/learning-db.py
    :用于记录、查询和管理学习内容的CLI工具
  • hooks/error-learner.py
    :自动错误学习钩子(互补系统)