# task-2146: impact_scanner.py 신규 생성 — 수정 파일 기반 역방향 영향 범위 스캔

## ★ 프로젝트: `/home/jay/workspace/`

## 3문서 참조 (필독)
- 프로젝트 계획서: `/home/jay/workspace/memory/plans/system/dispatch-quality-gates/plan.md` — 컴포넌트 1번
- 맥락노트: `/home/jay/workspace/memory/plans/system/dispatch-quality-gates/context-notes.md`
- 미팅 기록: `/home/jay/workspace/memory/meetings/2026-04-24-dispatch-quality-automation.md` (Cycle 2-3 헤르메스 의견)

## 문제
봇이 파일 A를 수정했는데, 동일 함수/타입이 파일 B에서도 참조되고 있는 경우를 자동 감지하지 못함.
실제 사례: task-2142 — FeatureGate.tsx 수정했으나 use-feature-access.ts에 동일 로직 누락.

## 구현

### 파일: `/home/jay/workspace/scripts/impact_scanner.py` (신규, ~200줄)

#### 함수 시그니처
```python
def extract_symbols_python(file_path: str, diff_lines: list[int]) -> list[str]:
    """Python AST에서 변경된 라인의 함수/클래스 이름 추출"""

def extract_symbols_typescript(file_path: str, diff_lines: list[int]) -> list[str]:
    """TypeScript에서 변경된 라인의 export 심볼 추출 (regex)"""
    # regex: r'export\s+(function|class|type|interface|const|enum)\s+(\w+)'

def grep_references(symbol: str, project_root: str, exclude_files: list[str]) -> list[dict]:
    """프로젝트 전체에서 심볼 참조를 grep으로 검색"""

def scan(project_root: str, modified_files: list[str], task_id: str = "") -> dict:
    """메인 스캔 로직"""
```

#### CLI 인터페이스
```bash
python3 impact_scanner.py --project-root /path --task-id task-2142 [--max-symbols 5] [--timeout 30]
```

#### 출력 (JSON, stdout 마지막 줄)
```json
{"task_id": "...", "gate_result": "PASS|WARN|BLOCK", "unmodified_references": [...], "symbols_checked": [...]}
```

#### 임계치
- 0건: PASS (exit 0)
- 1-5건: WARN (exit 1)
- 6건+: BLOCK (exit 2)

#### 안전장치
- grep 타임아웃: 심볼당 3초, 전체 15초
- 심볼 최대 5개 (--max-symbols)
- exclude: node_modules, .git, __pycache__, dist, build, .worktrees, .next
- COMMON_FILTER: data, result, config, props, state, error, value, item, items, list, name, path, type, id, key, index, event, options (20단어)

## ★ 먼저 읽을 파일
- `/home/jay/workspace/scripts/` — 기존 스크립트 구조 확인
- `/home/jay/workspace/dispatch.py` L766-932 — 기존 affected_files 관련 함수 참조

## 검증 시나리오

### 시나리오 1: Python 심볼 역추적
`utils/calc.py`의 `calculate_premium()` 수정 → `pages/quote.py`에서 참조 발견 → WARN

### 시나리오 2: TypeScript 심볼 역추적
`FeatureGate.tsx`의 `FeatureGate` 컴포넌트 수정 → `use-feature-access.ts` 참조 발견 → WARN

### 시나리오 3: COMMON_FILTER 동작
`data` 변수 수정 → COMMON_FILTER에 포함 → grep 건너뜀

### 시나리오 4: 타임아웃 동작
거대 프로젝트에서 grep 3초 초과 → 해당 심볼 건너뜀, 전체 15초 초과 → 중단 + WARN

### 시나리오 5: 참조 0건
수정 파일의 심볼이 다른 곳에서 참조되지 않음 → PASS

## 완료 시그니처
- 4개 함수 + CLI 구현
- Python AST + TypeScript regex 모두 동작
- COMMON_FILTER 20단어 적용
- 타임아웃 동작 확인
- 단위 테스트 5건+ PASS (tests/test_impact_scanner.py)

## 레벨
- critical

## 프로젝트
- dev-system