AgentSkillsCN

learning-loop

在重大任务完成后,系统化总结经验教训。分类包括:模式、反模式、工具发现、配置洞察。将这些内容存储于.claude/config/knowledge_base.yml中,并调用已有学习成果进行查询。

SKILL.md
--- frontmatter
name: learning-loop
description: |
  Capture structured lessons learned after major tasks. Categories: pattern,
  antipattern, tool discovery, configuration insight. Stores in
  .claude/config/knowledge_base.yml and queries existing learnings.

Learning Loop Skill

After completing significant tasks, capture structured lessons learned. Stores knowledge entries in a YAML knowledge base for future reference. Can also query existing entries by language, tool, or category.

Arguments

  • $ARGUMENTS -- One of:
    • capture -- Interactive capture of a new learning (default if no args)
    • query <term> -- Search existing learnings by keyword
    • list [category] -- List all entries, optionally filtered by category
    • stats -- Show knowledge base statistics

Phase 1: Mode Detection

ArgumentAction
(empty) or captureBegin structured capture flow
query <term>Search knowledge base for matching entries
list [category]List entries, filter by category if provided
statsShow entry counts by category, language, recency

Phase 2: Capture Flow

When capturing a new learning, gather the following fields:

Required Fields

FieldDescriptionExample
titleShort descriptive title"Ruff replaces flake8+isort+black"
categoryOne of: pattern, antipattern, tool-discovery, config-insighttool-discovery
languageLanguage/ecosystem (or general)python
description1-3 sentence explanation"Ruff is a single tool that replaces..."

Optional Fields

FieldDescriptionExample
tagsSearchable keywords[linting, formatting, migration]
toolSpecific tool involvedruff
sourceWhere this was learnedtask-42, pr-review, debugging
confidenceHow proven is this (high/medium/low)high
exampleBrief code/config exampleruff check --fix .

Context Inference

Before prompting, infer context from the current session:

  • Check recent git log for task context
  • Check current directory for language indicators
  • Pre-fill fields where possible to reduce friction

Phase 3: Storage

Store entries in .claude/config/knowledge_base.yml using this schema:

yaml
# Knowledge Base - Auto-managed by learning-loop skill
# Do not edit manually unless correcting entries
version: 1
entries:
  - id: "20260211-001"
    title: "Ruff replaces flake8+isort+black"
    category: tool-discovery
    language: python
    description: "Ruff is a single Rust-based tool that replaces flake8, isort, and black with faster execution."
    tags: [linting, formatting, migration]
    tool: ruff
    source: refactor-python
    confidence: high
    example: "ruff check --fix . && ruff format ."
    created: "2026-02-11T14:30:00Z"
    last_referenced: "2026-02-11T14:30:00Z"

ID Generation

Format: YYYYMMDD-NNN where NNN is a zero-padded sequence number for that date.

File Creation

If knowledge_base.yml does not exist, create it with the version header and an empty entries list before adding the first entry.


Phase 4: Query Flow

When querying, search across these fields: title, description, tags, tool, language, category.

bash
# Search examples
/learning-loop query ruff
/learning-loop query "go test"
/learning-loop list antipattern
/learning-loop list tool-discovery
/learning-loop stats

Query Output

markdown
## Knowledge Base: Query Results

**Query**: {search-term}
**Matches**: {count}

| ID | Category | Title | Language | Confidence |
|----|----------|-------|----------|------------|
| 20260211-001 | tool-discovery | Ruff replaces flake8+isort+black | python | high |
| 20260210-003 | pattern | Use ruff in pre-commit hooks | python | high |

### Details

#### 20260211-001: Ruff replaces flake8+isort+black
- **Category**: tool-discovery
- **Language**: python
- **Description**: Ruff is a single Rust-based tool that replaces flake8, isort, and black.
- **Example**: `ruff check --fix . && ruff format .`
- **Source**: refactor-python

Stats Output

markdown
## Knowledge Base Statistics

**Total entries**: {count}
**Date range**: {oldest} to {newest}

| Category | Count |
|----------|-------|
| pattern | 12 |
| antipattern | 8 |
| tool-discovery | 5 |
| config-insight | 3 |

| Language | Count |
|----------|-------|
| python | 10 |
| go | 6 |
| node | 5 |
| general | 7 |

Phase 5: Reference Tracking

When a knowledge base entry is relevant to a current task, update its last_referenced timestamp. This enables staleness tracking and prioritization.


Safety Checks

  • Never delete existing entries -- append only
  • Validate YAML syntax before writing
  • Deduplicate: warn if a similar title+category+language already exists
  • Back up knowledge_base.yml before writing (copy to knowledge_base.yml.bak)
  • Maximum 500 entries per file (suggest archiving if exceeded)