# task-2562 보고서 — G4 Pre-PR Gemini CLI Gate (Track C)

## 본질

PR open **전에** Gemini CLI(OAuth-personal) 단발 호출로 code-changing issue를 사전 감지하는 **Pre-PR Gemini CLI gate**를 `scripts/finish-task.sh` line 830 부근(G3 PASS 직후, .done 이전, Lv.4 보안 감사 이전)에 통합한다. **공식 merge gate(GitHub Gemini App) 아님** — 본 gate는 PR open 자체를 차단하여 same-PR push doctrine 위반 사이클을 사전 봉쇄한다.

## 결정 박제 (회장 §명시 1:1)

| 항목 | 결정 |
|---|---|
| task ID | task-2562 (task-2559 dashboard 신호등 task로 사용 중) |
| fix_loop_count max | 2 |
| integration point | scripts/finish-task.sh line 830 부근 |
| gate 정책 | Lv 기반 mixed |
| Lv.1~2 | soft (warning + PR open 허용) |
| Lv.2 risk-trigger | hard (보안 민감 파일 / affected_files>5 / danger 키워드) |
| Lv.3+ | hard (.done 차단 + PR open 금지) |
| 팀 | dev1 헤르메스 |
| 인증 | OAuth-personal (GEMINI_API_KEY 거부) |

## Final Preflight 4건

| # | 항목 | 결과 |
|---|---|---|
| 1 | task-2560 stale .done.escalated supersede | PASS (`MERGED_SUPERSEDES_STALE_ESCALATED`) |
| 2 | task-2561 intended skip evidence | PASS (`post_merge_smoke.skip_reason` contains `INTENDED`) |
| 3 | task-2562 expected_files 최종 확정 | PASS (8 mandatory + 2 conditional → OD_3 (a) 채택으로 conditional 승격 = 10) |
| 4 | conditional files 정책 | PASS (수정 채택 → expected_files 승격, 미수정 시 actual_changed_files 포함 금지 원칙 박제) |

## 구현 산출 (effective diff)

10 파일 (mandatory 8 + conditional 승격 2):

1. `scripts/gemini_cli_gate_check.py` — 신규 (~330 LOC) — OAuth-personal 강제, scope_violation, fix_loop counter, Lv 기반 mixed gate.
2. `tests/regression/test_gemini_cli_gate_check_2562.py` — 신규 — 8 시나리오 + meta 2건.
3. `anu_v2/tests/test_g4_integration_2562.py` — 신규 — 5 통합 시나리오.
4. `scripts/finish-task.sh` — 수정 (`[G4-GATE]` block ~22 LOC line 830 부근 추가).
5. `prompts/gate_instructions.py` — 수정 (`should_run_gemini_cli_gate`, `get_gemini_cli_gate_command` 추가).
6. `memory/reports/task-2562.md` (본 파일)
7. `memory/events/task-2562.dispatch-decision.json`
8. `memory/plans/tasks/task-2562/plan.md`
9. `memory/plans/tasks/task-2562/context-notes.md`
10. `memory/plans/tasks/task-2562/checklist.md`

## Lv 기반 mixed gate 박제

- Lv.1~2 일반: gate FAIL = soft warning marker (`<task_id>.g4-soft-warning.json`) + PR open 허용.
- Lv.2 risk-trigger (security file / >5 files / danger keyword): hard FAIL → `.g4-failed` + PR 차단.
- Lv.3+: 항상 hard.

## scope_violation 즉시 ESCALATED

expected_files 외 파일이 affected_files에 포함되면 fix_loop 진입 0 + `.g4-scope-violation.json` marker + exit 2.

## fix_loop_count max=2 hard cap

- atomic write `<task_id>.g4-fix-loop-count`
- 2회 도달 시 `.g4-fix-loop-cap.json` marker + exit 2 + OWNER_DECISION_REQUIRED.

## OAuth-personal 강제

- gate entry point에서 `GEMINI_API_KEY` env var 검출 시 즉시 `RuntimeError(FORBIDDEN_CAPABILITY_USE)` → CLI exit 2.
- subprocess 호출 시 `GEMINI_API_KEY` / `GOOGLE_API_KEY` env 제거 (안전망).

## 금지 9건 어셀션

| # | 항목 | 결과 |
|---|---|---|
| 1 | task-2559 번호 사용 0 | OK |
| 2 | task-2560/2561 후속 수정 섞기 0 | OK (영역 lock) |
| 3 | G4를 공식 merge gate로 오인 0 | OK (본 보고서 명시) |
| 4 | finish-task.sh 수정 regression 없이 push 0 | OK (regression test 8+5건 포함) |
| 5 | 회장 수동 `/gemini review` 0 | OK |
| 6 | long polling 0 | OK (60s 단발) |
| 7 | force push / rebase / admin override 0 | OK |
| 8 | BOT `/gemini review` 0 | OK |
| 9 | task-2558/2559/2560/2561 영역 mutate 0 | OK |

## 회귀 어셀션

- `pytest tests/regression/test_gemini_cli_gate_check_2562.py -v` — 8 시나리오 + 2 meta.
- `pytest anu_v2/tests/test_g4_integration_2562.py -v` — 5 통합 시나리오.
- `python3 -m py_compile scripts/gemini_cli_gate_check.py` — syntax OK.

## G4 self-apply 회피

본 task = G4 자체 구현이므로 **G4 미적용** (무한루프 회피, 회장 §명시 일관). G1 Codex + G2 마아트+로키 + G3 verifier만 적용.

## 보고 1:1

```
Track: C
상태: <MERGED|ESCALATED>
task_id: task-2562
수정/PR 여부: PR #<N> / merge_commit <SHA>
expected_files: 10/10 strict (dispatch_decision.json authoritative)
forbidden path: 0
Gemini 상태: fresh + unresolved 0
CI 상태: 11/11 / CLEAN
핵심 evidence: final preflight 4건 PASS + Lv 기반 mixed gate 박제
회장 결정 필요 여부: N (완료 10건 충족) / Y (preflight FAIL)
다음 액션: .done 생성 + lifecycle markers
```

## 다음 액션

1. PR 생성 (BOT_GITHUB_TOKEN) → CI 11 checks SUCCESS 대기
2. fresh Gemini review (owner_trigger_only 자동) → unresolved 0
3. BOT squash merge (admin override 0)
4. post-merge smoke + reconcile evidence
5. lifecycle markers + .done
