Files
2nd/10_Wiki/Topic_Programming/Architecture/The Two Hats.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.5 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-the-two-hats The Two Hats 10_Wiki/Topics verified self
Two Hats Rule
Beck's Two Hats
두 모자
none A 0.92 applied
tdd
refactoring
kent-beck
discipline
2026-05-10 pending
language framework
TypeScript Vitest

The Two Hats

매 한 줄

"매 한 번에 한 hat 만 — adding feature OR refactoring, never both". Kent Beck 의 TDD By Example (2003) 의 핵심 discipline. 매 mode-switching 의 명시적 awareness 가 매 code change 의 quality 를 결정. 매 Feathers 의 legacy work 에서도 동일 principle.

매 핵심

매 두 hat

  • Adding Feature hat: 매 new behavior. 매 fail test 작성 → minimum code 로 pass. 매 design improvement 의 X.
  • Refactoring hat: 매 behavior 의 preservation. 매 all test green. 매 new feature 의 X.

매 switching rule

  1. 매 hat 의 명시적 awareness — 매 commit message 에 표시.
  2. 매 transition 시 모든 test green 확인.
  3. 매 hat 을 동시에 쓰면 — 매 step back, 매 separate commit.

매 응용

  1. PR 분리 — 매 refactor PR + 매 feature PR (reviewer 부담 감소).
  2. Commit hygiene — 매 "refactor: extract method" + 매 "feat: add discount logic".
  3. Code review — 매 "이거 refactor 야 feature 야?" 질문 의 명시.

💻 패턴

Hat marker in commit

# Refactor hat
git commit -m "refactor: extract calculatePrice into PriceCalculator

No behavior change. All 142 tests green before and after."

# Feature hat
git commit -m "feat: add VIP tier discount

- Add VIPDiscount strategy
- Test: VIP gets 20% off
- Test: STANDARD unchanged"

TDD cycle with hats

// === FEATURE HAT ===
// 1. Write failing test
it('VIP customer gets 20% discount', () => {
  expect(calculateDiscount(100, 'VIP')).toBe(80);
});

// 2. Minimum code to pass (ugly OK)
function calculateDiscount(price: number, tier: string): number {
  if (tier === 'VIP') return price * 0.8;
  return price;
}

// === REFACTOR HAT === (all tests green)
// 3. Improve design without behavior change
type Tier = 'VIP' | 'STANDARD';
const DISCOUNT: Record<Tier, number> = { VIP: 0.2, STANDARD: 0 };

function calculateDiscount(price: number, tier: Tier): number {
  return price * (1 - DISCOUNT[tier]);
}
// Run tests → green. Commit as refactor.

// === FEATURE HAT === again for next behavior
it('GOLD customer gets 10% discount', () => { /* ... */ });

Mode-switch checklist

// Before switching to Refactor hat:
// [ ] All tests green?
// [ ] Last commit clean?
// [ ] No half-written feature?

// Before switching to Feature hat:
// [ ] Refactor commit complete?
// [ ] Tests still green?
// [ ] Clear what new behavior to add?

Sprout method (Feathers, refactor-friendly feature add)

// Legacy mess — don't refactor (Feature hat)
function processOrder(order: any) {
  // ... 300 lines, low test coverage ...
}

// Add new behavior in NEW pure function (Feature hat)
export function calculateLoyaltyPoints(order: Order): number {
  return Math.floor(order.total / 10);
}

// Wire it in — minimal touch
function processOrder(order: any) {
  const points = calculateLoyaltyPoints(order);  // sprout
  // ... existing mess unchanged ...
}
// Later, separate Refactor hat session can clean up `processOrder`.

Detecting hat conflation (smell)

// SMELL: PR titled "Add discount logic" but diff includes:
//   - new feature ✓
//   - rename 5 unrelated variables ✗
//   - extract 3 unrelated methods ✗
//   - reformat whole file ✗
//
// Reviewer cannot tell what changed semantically.
// Fix: split into 3-4 commits/PRs by hat.

Pre-commit hook (hat enforcement)

#!/bin/bash
# .git/hooks/pre-commit
msg=$(cat "$1")
if [[ ! "$msg" =~ ^(feat|fix|refactor|docs|test|chore): ]]; then
  echo "Commit message must start with type prefix indicating hat"
  exit 1
fi

매 결정 기준

상황 Hat
New behavior needed Feature
Existing test green, code ugly Refactor
Bug fix (changes behavior to correct) Feature (failing test first)
Rename for clarity Refactor
Extract method Refactor
Add parameter Feature (likely)
Mixed urge Stop — split into two

기본값: 매 explicit hat awareness, 매 separate commit, 매 green test 의 transition gate.

🔗 Graph

🤖 LLM 활용

언제: PR splitting advice, commit message disciplining, refactor-vs-feature classification. 언제 X: 매 actual editor mode-switching automation — 매 human discipline 이 본질.

안티패턴

  • Mixed PR: refactor + feature 의 단일 PR — 매 review 가 noise 에 묻힘.
  • "While I'm here": 매 unrelated tweak — 매 feature 가 endless drift.
  • Refactor in red: 매 broken test 에서 refactor — 매 behavior change 의 hidden source.
  • Big-bang refactor: 매 multi-day refactor 의 isolation — 매 daily incremental 이 안전.

🧪 검증 / 중복

  • Verified (Beck 2003 TDD By Example; Feathers 2004 WELC).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Beck two hats + sprout + commit hygiene