AgentSkillsCN

learn

从对话中提炼经验教训,并将其持久化至AI助手的配置文件中(CLAUDE.md、GEMINI.md、AGENTS.md、Cursor、Copilot、Windsurf、Continue)。当调试揭示问题、命令曾失败又成功、假设被证伪、发现了规避方案、发现了未记录的行为,或当用户说“记住这件事”时,可使用此功能。

SKILL.md
--- frontmatter
name: learn
description: >-
  Extracts lessons learned from conversations and persists them to AI assistant
  config files (CLAUDE.md, GEMINI.md, AGENTS.md, Cursor, Copilot, Windsurf,
  Continue). Use when: debugging revealed issues, commands failed then succeeded,
  assumptions proved wrong, workarounds were discovered, undocumented behavior
  found, or user says "remember this".
license: MIT
compatibility: Requires bash shell and file system write access
metadata:
  author: Gregory Murray
  repository: github.com/whatifwedigdeeper/agent-skills
  version: "0.3"

Learn from Conversation

Analyze the conversation to extract lessons learned, then persist them to AI assistant configuration files.

Supported Assistants

AssistantConfig FileFormat
Claude CodeCLAUDE.mdMarkdown
GeminiGEMINI.mdMarkdown
AGENTS.mdAGENTS.mdMarkdown
Cursor.cursorrules or .cursor/rules/*.mdcMarkdown/MDC
GitHub Copilot.github/copilot-instructions.mdMarkdown
Windsurf.windsurf/rules/rules.mdMarkdown
Continue.continuerc.jsonJSON

See references/assistant-configs.md for format details.

Process

1. Detect and Assess Configurations

Scan for config files and check their sizes:

bash
for f in CLAUDE.md GEMINI.md AGENTS.md .cursorrules .github/copilot-instructions.md \
  .windsurf/rules/rules.md .continuerc.json; do
  [ -f "$f" ] && wc -l "$f"
done
find .cursor/rules -name "*.mdc" -exec wc -l {} \; 2>/dev/null

Behavior based on detection:

ScenarioAction
Single config foundUpdate it automatically
Multiple configs foundPrompt user to select which to update
No configs foundDisplay init commands from assistant-configs.md, then exit

Size Thresholds

LinesStatusAction
< 400HealthyAdd learnings directly
400-500WarningAdd carefully, suggest cleanup
> 500OversizedRefactor before adding new content

Discover Existing Skills

List skills for routing decisions:

bash
find . -name "SKILL.md" -type f 2>/dev/null | grep -v node_modules | \
  xargs grep -l "^name:" | while read -r f; do
  grep -m1 "^name:" "$f" | sed 's/name: //'
done

2. Analyze Conversation

Scan for:

  • Corrections: Commands retried, assumptions proven wrong, missing prerequisites
  • Discoveries: Undocumented patterns, integration quirks, environment requirements
  • Improvements: Steps that should be automated or validated earlier

3. Categorize and Route Each Learning

CategoryPrimary DestinationFallback When Oversized
Project factsConfig fileExtract to new skill
PrerequisitesConfig fileExtract to project-setup skill
EnvironmentConfig fileExtract to environment-setup skill
Workflow patternExisting related skillCreate new skill
Automated workflowNew skillNew skill (always)

Routing Decision Tree

For each learning, evaluate in order:

  1. Is this a multi-step automated workflow (>5 steps)?

    • YES → Create new skill (proceed to Step 5, Route C)
    • NO → Continue
  2. Does an existing skill cover this topic?

    • YES → Update that skill
    • NO → Continue
  3. Is the target config file oversized (>500 lines)?

    • YES → Create new skill OR offer refactoring (see Step 4)
    • NO → Continue
  4. Is this learning situation-specific (applies to narrow context)?

    • YES → Create new skill with globs or context constraints
    • NO → Add to config file

Size-Based Rules

Learning SizePreferred Destination
< 3 linesConfig file (even if near threshold)
3-30 linesFollow decision tree above
> 30 linesStrongly prefer skill creation

Skill Relevance Matching

Match learnings to existing skills using these criteria:

Learning TopicMatching Skill Indicators
Testing patternsSkill name contains: test, spec, e2e, unit
Build/compile issuesSkill name contains: build, compile, bundle
DependenciesSkill name contains: package, dependency, npm, yarn
API patternsSkill name contains: api, http, fetch, request
DatabaseSkill name contains: db, database, migration, schema
DeploymentSkill name contains: deploy, release, ci, cd

Also check skill description field for keyword overlap with the learning topic.

4. Present and Confirm

For each learning, show:

code
**[Category]**: [Brief description]
- Source: [What happened in conversation]
- Proposed change: [Exact text or file to add]
- Destination: [Config file] ([current] → [projected] lines)

Handle Size Threshold

If adding the learning would push a config file over threshold:

code
Adding this learning would bring [filename] to [X] lines (threshold: [Y]).

Options:
1. Add learning anyway (not recommended)
2. [Refactor](references/refactoring.md) existing content to skills first, then add
3. Create a new skill for this learning instead
4. Skip this config file

Ask for confirmation before applying each change.

5. Apply Changes

Apply changes based on routing decision from Step 3:

Route A: Add to Config File

Markdown configs (CLAUDE.md, GEMINI.md, AGENTS.md, Copilot, Windsurf):

  • Find appropriate section, preserve existing structure
  • Append to relevant section or create new section if needed

Cursor rules:

Continue (.continuerc.json):

Route B: Update Existing Skill

When adding to an existing skill:

  1. Read the skill file: skills/[name]/SKILL.md
  2. Find appropriate section or create new one
  3. Append learning, maintaining the skill's existing structure
  4. If skill has references, consider adding to reference file instead

Skill update format:

markdown
## [New Section or append to existing]

[Learning content formatted as guidance or workflow step]

Route C: Create New Skill

Create in skills/[name]/SKILL.md with this template:

markdown
---
name: [learning-topic]
description: [What this handles and when to use it - triggers belong here, not in body]
---

# [Learning Topic]

[Learning content structured as workflow]

## Process

### 1. [First Step]
[Details]

6. Verify Changes

After applying each change, confirm success by showing:

code
✓ Added to [file path]:
  [Section name]
  > [First 2-3 lines of added content...]

If a write failed, report the error and offer to retry or skip.

7. Summarize

List:

  • Config files modified (with full paths)
  • Sections updated in each file
  • Any skills created

Examples

SituationLearning
"e2e tests failed because API wasn't running"Add prerequisite to selected config(s)
"Parse SDK doesn't work with Vite out of the box"Document workaround in selected config(s)
"Build failed because NODE_ENV wasn't set"Add required env var to selected config(s)
"Every component needs tests, lint, build..."Create add-component skill

Edge Cases

ScenarioHandling
No configs detectedGuide user to initialize one first, exit early
Multiple configs foundPrompt user to select which to update
Malformed config fileWarn and skip that file
Duplicate content existsCheck before adding, warn if similar learning exists
Config file already oversizedOffer refactoring before adding (Step 4)
Learning matches multiple skillsPresent options, let user choose which skill to update
Skill file also oversizedSuggest creating sub-skills or reference files
Learning is very small (<3 lines)Prefer config file even if near threshold
Learning is very large (>30 lines)Strongly suggest skill creation
No existing skills foundSkip skill matching, proceed with config or new skill

Guidelines

See references/guidelines.md for learning quality principles.