---
id: wiki-2026-0508-p-reinforce
title: P-Reinforce
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Auto-Reinforce, Wiki-Reinforcement, Reinforcement-Marker]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [wiki, automation, knowledge-management, claude-code]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: markdown
  framework: obsidian
---

# P-Reinforce

## 매 한 줄
> **"매 wiki entry 의 자동 강화 marker"**. P-Reinforce 는 Claude Code agent 가 wiki node 를 재방문할 때마다 frontmatter 의 `last_reinforced` 를 갱신하고 missing graph link 을 보충하는 light-weight reinforcement loop. 매 hand-curated knowledge graph 의 staleness 방지.

## 매 핵심

### 매 trigger 조건
- agent 가 file 을 Read 하고 substantive change (>= 3 lines) 을 적용한 경우.
- backlink resolver 가 dangling `[[X]]` 을 발견 후 stub 을 만든 경우.
- weekly cron (`/loop 7d /reinforce`) 의 sweep.

### 매 frontmatter 의 강화 field
- `last_reinforced` — ISO date.
- `confidence_score` — 0..1, decay 0.02/month, +0.05 per reinforcement.
- `verification_status` — `applied` | `pending` | `redirected`.
- `source_trust_level` — A/B/C.

### 매 응용
1. Wiki staleness audit — `last_reinforced < 90d` 의 file 을 batch 로 재방문.
2. Confidence-weighted retrieval — RAG 가 high-confidence node 을 prefer.
3. Graph hygiene — orphan / dangling link 을 reinforcement pass 에서 fix.

## 💻 패턴

### Frontmatter reinforcement (Python)
```python
import re, yaml, datetime, pathlib

def reinforce(path: pathlib.Path, bump: float = 0.05):
    text = path.read_text()
    m = re.match(r"^---\n(.*?)\n---\n(.*)$", text, re.DOTALL)
    if not m:
        return False
    fm = yaml.safe_load(m.group(1)) or {}
    fm["last_reinforced"] = datetime.date.today().isoformat()
    fm["confidence_score"] = min(0.99, fm.get("confidence_score", 0.5) + bump)
    fm["verification_status"] = "applied"
    new = "---\n" + yaml.safe_dump(fm, sort_keys=False, allow_unicode=True) + "---\n" + m.group(2)
    path.write_text(new)
    return True
```

### Decay sweep (cron)
```python
from datetime import date, timedelta

def decayed(fm: dict, days: int = 90) -> bool:
    last = date.fromisoformat(fm.get("last_reinforced", "1970-01-01"))
    return (date.today() - last) > timedelta(days=days)

stale = [p for p in pathlib.Path("10_Wiki").rglob("*.md")
         if decayed(load_fm(p))]
```

### Dangling link harvest
```python
import re
LINK = re.compile(r"\[\[([^\]|#]+)")
def dangling(root):
    existing = {p.stem for p in root.rglob("*.md")}
    for md in root.rglob("*.md"):
        for tgt in LINK.findall(md.read_text()):
            if tgt not in existing:
                yield md, tgt
```

### Reinforcement-aware retrieval (BM25 + confidence)
```python
def score(doc, query):
    bm = bm25(doc.text, query)
    conf = doc.frontmatter.get("confidence_score", 0.5)
    age = days_since(doc.frontmatter["last_reinforced"])
    decay = max(0.5, 1 - age / 365)
    return bm * conf * decay
```

### Claude Code hook (settings.json)
```json
{
  "hooks": {
    "Stop": [{
      "command": "python ~/scripts/reinforce_touched.py"
    }]
  }
}
```

## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 active editing | inline reinforcement on Write |
| 매 background hygiene | weekly cron sweep |
| 매 large refactor | manual `verification_status: applied` bump |
| 매 redirect/duplicate | `verification_status: redirected`, no decay |

**기본값**: Stop hook + weekly sweep 의 조합.

## 🔗 Graph
- 부모: [[Knowledge-Graph]] · [[Wiki-Architecture]]
- 변형: [[Auto-Curation]] · [[Spaced-Repetition]]
- 응용: [[RAG]] · [[Agent-Memory]]
- Adjacent: [[Obsidian-Frontmatter]] · [[Confidence-Scoring]]

## 🤖 LLM 활용
**언제**: 매 long-lived wiki / second-brain 의 staleness 가 문제일 때.
**언제 X**: 매 ephemeral note / scratchpad — overhead > benefit.

## ❌ 안티패턴
- **Reinforce without read**: blind date bump — confidence 의 의미를 잃음.
- **Unbounded confidence growth**: cap 없이 +0.05 누적 — 매 1.0 saturation. cap 0.99.
- **Decay-only no-bump**: stale 만 잡고 fresh 강화는 없음 — graph 가 균질하게 늙음.

## 🧪 검증 / 중복
- Verified (in-house spec, CLEANUP_SPEC.md).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full content for P-Reinforce framework |
