# InsuRo 소식지/보험료 AI 채팅을 claude CLI로 전환

## 작업 레벨: Lv.1

## 프로젝트
- InsuRo: `/home/jay/projects/InsuRo`
- 서버: `/home/jay/projects/InsuRo/server`

## 버그
- **현상**: 소식지분석 AI 채팅에서 질문해도 응답 없음
- **서버 에러**: `TypeError: "Could not resolve authentication method. Expected either api_key or auth_token to be set"`
- **원인**: task-2219에서 newsletter-chat/premium-chat을 anthropic SDK로 구현했으나, ANTHROPIC_API_KEY가 미설정
- **위치**: `server/main.py` — `_stream_chat_response()` 함수 (3729행)

## 수정 방향
task-2222(콘텐츠 생성)와 동일하게 **claude CLI subprocess**로 전환:

```python
import subprocess, asyncio

async def _generate_chat_response(system_prompt: str, messages: list) -> str:
    """claude CLI로 채팅 응답 생성 (Max200 플랜 내 처리)"""
    # messages를 텍스트로 조합
    conversation = "\n".join([f"{m['role']}: {m['content']}" for m in messages])
    full_prompt = f"{system_prompt}\n\n대화:\n{conversation}\n\nassistant:"
    
    proc = await asyncio.create_subprocess_exec(
        "claude", "-p", full_prompt, "--model", "haiku", "--output-format", "text",
        stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
    )
    stdout, _ = await proc.communicate()
    return stdout.decode().strip()
```

### 참고
- task-2222의 `generation_queue.py`와 유사한 패턴
- 소식지/보험료 채팅은 generate-content보다 짧은 응답 → haiku 모델 사용
- SSE 스트리밍은 어려우므로 전체 응답 한 번에 반환

### 기존 시스템 프롬프트 유지
- newsletter-chat: DB에서 extracted_text 조회 → 시스템 프롬프트에 context로 포함
- premium-chat: organization_id 필터 적용 → 해당 조직 데이터만

## affected_files
- `server/main.py` (수정 — newsletter-chat, premium-chat 핸들러를 CLI 방식으로 변경)

## 검증 시나리오
1. 소식지분석 → "소식지 내용 어떤 회사 있지?" 질문 → AI 응답 정상
2. 보험료분석 → "3대 질병 보험료 비교" 질문 → AI 응답 정상
3. 서버 에러 로그 없음
