Архитектура
Layer 1: Episodes — core/learnings/episodes.jsonl (append-only)
Layer 2: Learnings — core/LEARNINGS.md (scored, max 30)
Layer 3: Rules — rules.md / CLAUDE.md (promoted, owner only)
CLI
Engine: ~/.claude/scripts/learnings-engine.mjs
ENGINE="node ~/.claude/scripts/learnings-engine.mjs"
# Record new episode
echo '{"context":"...","error":"...","rule":"...","impact":"high","tags":["workflow"]}' | $ENGINE capture
# View scored learnings
$ENGINE score
# Lint: find HOT (freq 3+), STALE (score < 0.15), PROMOTE (score > 0.8)
$ENGINE lint
# Promote learning to rules
$ENGINE promote EP-20260411-007
# Archive stale learning
$ENGINE archive EP-20260411-009
# Bump frequency (repeat violation)
$ENGINE bump EP-20260411-001
# Generate markdown report
$ENGINE report
Scoring
Composite score: Recency (40%) + Frequency (30%) + Impact (30%)
- Recency:
max(0, 1 - ageDays / 30) — decay to 0 over 30 days
- Frequency:
min(1, freq / 3) — 3+ violations = max score
- Impact: critical=1.0, high=0.7, medium=0.4, low=0.1
Thresholds
| Condition |
Action |
| Score > 0.8 |
Propose promotion to rules (via owner) |
| Score < 0.15 |
Propose archival |
| Freq 3+ in 30 days |
ALERT: rule not working, change system |
When to record
Record ONLY when:
- Owner explicitly corrected ("no, do it this way", "wrong")
- Expensive error (access, security, infrastructure, data)
- Repeated pattern (same mistake twice)
- Owner sets new standard/rule
Do NOT record:
- Normal clarifications
- Choice between options
- Minor style tweaks without pattern
Episode format
{
"id": "EP-YYYYMMDD-NNN",
"ts": "ISO8601",
"type": "correction|insight|knowledge_gap",
"agent": "{{AGENT_ID}}",
"source": "owner|experience|review",
"context": "situation",
"error": "what went wrong",
"rule": "rule for the future",
"impact": "critical|high|medium|low",
"tags": ["tag1"],
"freq": 1,
"status": "active|promoted|archived"
}
Access zones for auto-fix
| Zone |
Files |
Who edits |
| GREEN |
SKILL.md, TOOLS.md, LEARNINGS.md |
Agent autonomously |
| YELLOW |
AGENTS.md, decisions.md |
Agent with justification |
| RED |
rules.md, CLAUDE.md |
Owner only |
What to do at freq 3+
| Error type |
Action |
| Forgot a step |
Add hook (PreToolUse/PostToolUse) |
| Wrong response style |
Update CLAUDE.md or rules.md (via owner) |
| Used wrong tool |
Update TOOLS.md |
| Asked unnecessary question |
Add rule to CLAUDE.md (via owner) |
| Code error |
Add test or lint rule |
Hooks integration
- SessionStart: inject scored top-5 from
$ENGINE score
- Stop: analyze session corrections, auto-capture episodes
- Weekly cron:
$ENGINE lint + report to owner
1---2name: learnings3description: Learnings System v2 — self-improvement через scoring ошибок. 3 слоя: Episodes (сырой лог) → Learnings (scored) → Rules (promoted). Используй когда: (1) пользователь поправил действие, (2) обнаружена ошибка, (3) нужен отчёт по learnings, (4) lint/audit накопленных уроков.4---56## Архитектура78```9Layer 1: Episodes — core/learnings/episodes.jsonl (append-only)10Layer 2: Learnings — core/LEARNINGS.md (scored, max 30)11Layer 3: Rules — rules.md / CLAUDE.md (promoted, owner only)12```1314## CLI1516Engine: `~/.claude/scripts/learnings-engine.mjs`1718```bash19ENGINE="node ~/.claude/scripts/learnings-engine.mjs"2021# Record new episode22echo '{"context":"...","error":"...","rule":"...","impact":"high","tags":["workflow"]}' | $ENGINE capture2324# View scored learnings25$ENGINE score2627# Lint: find HOT (freq 3+), STALE (score < 0.15), PROMOTE (score > 0.8)28$ENGINE lint2930# Promote learning to rules31$ENGINE promote EP-20260411-0073233# Archive stale learning34$ENGINE archive EP-20260411-0093536# Bump frequency (repeat violation)37$ENGINE bump EP-20260411-0013839# Generate markdown report40$ENGINE report41```4243## Scoring4445Composite score: `Recency (40%) + Frequency (30%) + Impact (30%)`4647- Recency: `max(0, 1 - ageDays / 30)` — decay to 0 over 30 days48- Frequency: `min(1, freq / 3)` — 3+ violations = max score49- Impact: critical=1.0, high=0.7, medium=0.4, low=0.15051## Thresholds5253| Condition | Action |54|---|---|55| Score > 0.8 | Propose promotion to rules (via owner) |56| Score < 0.15 | Propose archival |57| Freq 3+ in 30 days | ALERT: rule not working, change system |5859## When to record6061Record ONLY when:62- Owner explicitly corrected ("no, do it this way", "wrong")63- Expensive error (access, security, infrastructure, data)64- Repeated pattern (same mistake twice)65- Owner sets new standard/rule6667Do NOT record:68- Normal clarifications69- Choice between options70- Minor style tweaks without pattern7172## Episode format7374```json75{76 "id": "EP-YYYYMMDD-NNN",77 "ts": "ISO8601",78 "type": "correction|insight|knowledge_gap",79 "agent": "{{AGENT_ID}}",80 "source": "owner|experience|review",81 "context": "situation",82 "error": "what went wrong",83 "rule": "rule for the future",84 "impact": "critical|high|medium|low",85 "tags": ["tag1"],86 "freq": 1,87 "status": "active|promoted|archived"88}89```9091## Access zones for auto-fix9293| Zone | Files | Who edits |94|---|---|---|95| GREEN | SKILL.md, TOOLS.md, LEARNINGS.md | Agent autonomously |96| YELLOW | AGENTS.md, decisions.md | Agent with justification |97| RED | rules.md, CLAUDE.md | Owner only |9899## What to do at freq 3+100101| Error type | Action |102|---|---|103| Forgot a step | Add hook (PreToolUse/PostToolUse) |104| Wrong response style | Update CLAUDE.md or rules.md (via owner) |105| Used wrong tool | Update TOOLS.md |106| Asked unnecessary question | Add rule to CLAUDE.md (via owner) |107| Code error | Add test or lint rule |108109## Hooks integration110111- **SessionStart**: inject scored top-5 from `$ENGINE score`112- **Stop**: analyze session corrections, auto-capture episodes113- **Weekly cron**: `$ENGINE lint` + report to owner