---
name: learn-rule
description: Capture a correction or lesson as a persistent learning rule with category, mistake, and correction. Stores, categorises, and retrieves rules for future sessions. Use after mistakes or when the user says "remember this", "don't forget", "note this", or "learn from this".
---

# Learn Rule

Capture a lesson from the current session into permanent memory.

## Trigger

Use when the user says "remember this", "add to rules", "don't do that again", or after a mistake is identified.

## Workflow

1. Identify the lesson — what mistake was made? What should happen instead?
2. **QMD 중복 체크** — 볼트에 이미 유사한 학습이 있는지 검색:
   ```bash
   qmd search "관련 키워드" -c obsidian --limit 3
   ```
   이미 존재하면 기존 노트에 append하거나, 새 교훈이면 신규 생성.
3. Format the rule with full context.
4. Propose the addition and wait for user approval.
5. After approval, persist to LEARNED section or project memory.

## Format

```
[LEARN] Category: One-line rule
Mistake: What went wrong
Correction: How it was fixed
```

## Categories

| Category | Examples |
|----------|---------|
| Navigation | File paths, finding code, wrong file edited |
| Editing | Code changes, patterns, wrong approach |
| Testing | Test approaches, coverage gaps, flaky tests |
| Git | Commits, branches, merge issues |
| Quality | Lint, types, style violations |
| Context | When to clarify, missing requirements |
| Architecture | Design decisions, wrong abstractions |
| Performance | Optimization, O(n^2) loops, memory |
| Classification | 위키 분류 수정 — entity↔concept 경계, 폴더 이동, 태그 변경. Boundary Shift 발생 시 `20_Wiki/06_Meta/policy.md`의 Boundary Shift 이력 테이블도 갱신한다. |

## Example

```
Recent mistake: Edited wrong utils.ts file

[LEARN] Navigation: Confirm full path when multiple files share a name.

Add to LEARNED section? (y/n)
```

## Guardrails

- Always wait for user approval before persisting.
- Keep rules to one line — specific and actionable.
- Bad: "Write good code". Good: "Always use snake_case for database columns".
- Include the mistake context so the rule makes sense later.

## Output

- The proposed `[LEARN]` rule with category
- Confirmation after persisting

## MANDATORY — Save Learning to Vault

교훈이 확정되면 **반드시** `30_Claude/02_Learnings/`에 저장. 이는 `replay-learnings` 스킬이 미래 세션에서 과거 실수를 상기시킬 수 있도록 하는 필수 단계.

**저장 경로**: `${OBSIDIAN_VAULT_PATH}/30_Claude/02_Learnings/{YYYY-MM-DD}-{slug}.md`

**파일 포맷**:
```markdown
---
title: "{교훈 한 줄 요약}"
tags:
  - 개발/학습
  - 카테고리/{category}
  - 프로젝트/{name}
date: {YYYY-MM-DD}
category: "{Testing|Navigation|Architecture|etc}"
---
# {교훈 제목}

## 실수 (Mistake)
{구체적으로 무엇을 잘못했는지}

## 교훈 (Rule)
{[LEARN] 규칙}

## 맥락 (Context)
{왜 이 실수가 발생했는지, 어떤 상황이었는지}

## 적용 범위 (When to Apply)
{이 교훈이 언제 다시 떠올라야 하는지}

## Related
- [[관련-세션 또는 설계]]
```

**저장 후 필수**:
1. `30_Claude/00_Meta/index.md`의 `## 02_Learnings` 섹션에 항목 추가
2. `30_Claude/00_Meta/log.md` 상단에 이력 추가 (`## {date} | learn-rule ({slug})`)

**Trigger**: 모든 learn-rule 실행 시 (옵션 아님).
