# 교차검증 워크플로우 Phase 1 완성 — 기반 인프라 연동

## 배경
3문서(task-1837)의 Phase 1 기반 인프라가 부분 구현 상태.
gate_instructions.py는 존재하지만 연동 안 됨. affected_files 겹침 감지, batch_id 미구현.

## 현재 상태
- ✅ gate_instructions.py 파일 존재 (47줄, Lv.0~4 전체 게이트 지시 작성 완료)
- ✅ QC-RULES.md 존재 (셀프 디버깅)
- ❌ dispatch.py에서 gate_instructions.py import + 프롬프트 삽입 미연동
- ❌ team_prompts.py에서 게이트 지시 미포함
- ❌ affected_files 겹침 감지 미구현
- ❌ batch_id 미구현
- ❌ 레벨 자동 추정 경고 미구현

## 작업 내용

### 1. gate_instructions.py 연동
- `/home/jay/workspace/prompts/gate_instructions.py` — 이미 존재, 수정 불필요
- `/home/jay/workspace/dispatch.py`에서:
  - `from prompts.gate_instructions import format_for_prompt` import 추가
  - 팀장 프롬프트 생성 시 `format_for_prompt(level)` 호출하여 게이트 지시 삽입
- `/home/jay/workspace/prompts/team_prompts.py`에서:
  - `_build_direct_prompt()` 함수에서 level 파라미터 받아 게이트 지시 포함
  - 또는 dispatch.py에서 프롬프트 조립 시 직접 삽입

### 2. affected_files 겹침 감지
- dispatch.py에 affected_files 파싱 로직 추가
  - task 파일(--task-file)에서 `affected_files:` 필드 파싱
  - 또는 --affected-files CLI 옵션 추가
- task-timers.json의 running task들에서 affected_files 추출
- 겹침 감지: 새 task의 affected_files와 running task의 affected_files 교집합
- 겹침 발견 시 경고 메시지 출력 (에러 아님, 경고)
- Lv.2 이상에서 affected_files 미기재 시 경고

### 3. batch_id 필드
- dispatch.py에 --batch-id CLI 옵션 추가
- 병렬 위임 시 동일 batch_id 부여 가능
- task-timers.json에 batch_id 필드 저장
- batch_id 기반 전팀 완료 조회 함수: `get_batch_status(batch_id)` → {total, completed, pending}

### 4. 레벨 자동 추정 경고
- dispatch.py에서 task 파일의 affected_files 개수로 최소 레벨 추정
  - affected_files >= 3 → 최소 Lv.2 권장
  - affected_files >= 5 → 최소 Lv.3 권장
- 수동 지정 레벨 < 자동 추정 시 경고: "⚠️ Lv.{수동} 지정했지만 affected_files {N}개로 Lv.{추정} 이상 권장"

## 참고 파일
- 3문서 체크리스트: `/home/jay/workspace/memory/plans/cross-verification-workflow/checklist.md` (Phase 1 섹션)
- 3문서 계획서: `/home/jay/workspace/memory/plans/cross-verification-workflow/plan.md`
- gate_instructions.py: `/home/jay/workspace/prompts/gate_instructions.py`

## 검증 시나리오 (이게 되면 성공)
1. `--level normal` 위임 시 팀장 프롬프트에 "[G2 구현 게이트] 셀프 QC..." 포함
2. `--level critical` 위임 시 팀장 프롬프트에 "[G1 설계 게이트] 3문서 필수..." 포함
3. affected_files 겹침 시 경고 메시지 출력
4. batch_id 지정 시 task-timers.json에 저장
5. Lv.1인데 affected_files 5개면 경고 출력
6. 기존 dispatch 기능 회귀 없음

## 주의사항
- dispatch.py는 핵심 인프라 — 수정 후 반드시 기존 위임 플로우 테스트
- team_prompts.py 대용량(46KB) — offset/limit 분할 읽기
- 수정 후 즉시 커밋