# ANU Executor 4-Rule Codification Spec (260530)

> 상태: **READ-ONLY 설계 단일소스 — dispatch 회장 승인 대기**
> 발단: PR #161 (task-2712) 운영에서 4개 상태전이/책임경계가 코드화 안 되어 매 단계 사람 재판정 반복
> 회장 verbatim 2026-05-30: "더 세세한 지시가 아니라 아래 4개 규칙을 아누 내부 실행기로 고정"
> 원칙: **텍스트 doctrine ≠ 코드 enforce** (반복 박제된 교훈). 4 규칙을 dispatch/finish-task/watcher 파이프라인에 결선한다.

---

## Rule 1 — GEMINI_FINDING_CLASSIFIER
**목적**: Gemini finding 을 자동 분류 → same-PR micro-fix 자동수렴 vs 회장 보고 분기.
- **입력**: Gemini review thread(severity, path, line, body)
- **분류 enum**:
  - `EXPECTED_FILES_MICRO_FIX`: severity∈{HIGH,MEDIUM,LOW} ∧ path∈expected_files ∧ behavior/schema 변경 0 ∧ credential net-new 0 ∧ scope 확장 0 → authorized same-PR micro-fix (회장 1회 인가 범위 내 자동수렴 후보)
  - `CHAIR_REQUIRED`: Critical7 match ∨ 권한/credential net-new expansion ∨ expected_files 밖 ∨ admin override ∨ scope 확장 → 회장 보고
- **판별 근거**: path∈expected_files(handoff) 교차 + Critical7 매처 + credential 3-tier(BLOCKING/EXISTING/NET-NEW) + scope diff
- **실증**: PR #161 4 finding(dispatch.py·finish-task.sh·hook·dispatcher) 전부 EXPECTED_FILES_MICRO_FIX 였음

## Rule 2 — REMEDIATION_HEAD_ADVANCE_POLICY
**목적**: authorized same-PR fix/cleanup push 시 handoff head 자동 갱신 + watcher 재감시.
- **트리거**: PR head_sha 가 handoff.head_sha 보다 advance(FF descendant) ∧ push 가 authorized(EXCEPTIONAL_OWNER_TRIGGER 또는 ANU hygiene)
- **동작**: handoff.head_sha ← new head + head_sha_history append + watcher 가 새 head 기준 재점검
- **금지오판 방지**: head advance ≠ STALE/drift. STALE 은 "handoff 가 advance 를 반영 못 한 상태"에만. watcher 는 head 를 **하드코딩 말고 handoff 에서 동적 read**
- **실증**: PR #161 ea2eb02a push 후 handoff 미갱신 → watcher STALE 오판(본 사고)

## Rule 3 — PR_DIFF_HYGIENE_GUARD
**목적**: runtime code PR diff 에 artifact 혼입 차단(runtime-code-artifact separation doctrine 코드화).
- **차단 대상**: `memory/reports/**`(단 해당 task 의 원 expected report 1개는 정책 결정), `memory/events/**` markers, `memory/artifacts/**`, `*-evidence.md`, envelope/decision/handoff/checklist/context-notes/plan docs
- **동작**: PR open/ push 시 diff 검사 → 혼입 발견 시 `PR_DIFF_CONTAMINATED` → 보고 + cleanup 권고(forward git rm 커밋, 코드 0)
- **실증**: PR #161 ea2eb02a 에 task-2712+2-gemini-fix-evidence.md 131줄 혼입 → 4aa779ec cleanup

## Rule 4 — CALLBACK_LOCATION_METADATA (= task-2713)
**목적**: collector 가 실제 작업 폴더(target_worktree)와 finish 폴더(finish_task_cwd)를 항상 구분.
- **11 필드**: execution_cwd · target_worktree · artifact_root · git_branch · git_head · report_path · decision_path · verification_commands · finish_task_cwd · goal_assertion_cwd · worktree_role
- **동작**: envelope 에 11 필드 additive. collector 가 `finish_task_cwd != target_worktree` ∨ `artifact_root=/tmp/**` 탐지 시 `WORKTREE_CONTEXT_MISMATCH` / `EVIDENCE_NOT_DURABLE`
- **단일소스**: `system_callback_envelope_location_metadata_enhancement_spec_260530.md`
- **실증**: task-2712+1 WORKTREE_CONTEXT_MISMATCH

---

## 결선 지점 (wiring)
- Rule 1: dispatch/watcher 의 Gemini finding 처리부
- Rule 2: watcher head check + handoff updater
- Rule 3: PR open/push preflight (finish-task.sh PR 단계 또는 watcher)
- Rule 4: failure_envelope_writer / callback envelope builder

## 제안 task 분해 (dispatch 승인 대기)
- **task-2713**: Rule 4 CALLBACK_LOCATION_METADATA (이미 task md 초안 존재)
- **task-2714**: Rule 1 GEMINI_FINDING_CLASSIFIER
- **task-2715**: Rule 2 REMEDIATION_HEAD_ADVANCE_POLICY
- **task-2716**: Rule 3 PR_DIFF_HYGIENE_GUARD
- 각 task: 모듈 + 테스트(fixture 기반) + dispatch/finish-task/watcher 결선 + dead-code 금지(실사용 통합). PR 진입은 회장 인가.

## 금지/주의
- 본 spec 은 설계만 — 코드 구현/dispatch 는 회장 승인 후. PR #161(task-2712) 에 혼입 금지(별도 task).
- 4 규칙 구현 PR 도 runtime-code-only(Rule 3 자기적용).
