# 대시보드 토큰 사용량 자동 갱신

## 배경
대시보드의 "작업별 토큰 사용량"이 token-ledger.json 기반인데, 이 파일이 수동 스캔(`python3 scripts/token-tracker.py scan`)으로만 갱신된다.
결과: 새로고침해도 최신 작업의 토큰 데이터가 안 나옴 (last_scan이 수 시간 전에 멈춰 있음).

## 수정 대상
`/home/jay/workspace/dashboard/server.py`

## 수정 내용

### 1. `get_token_usage()` 메서드에 자동 스캔 트리거 추가

`token-ledger.json`을 읽기 전에 `last_scan` 타임스탬프를 확인하고, 30분 이상 경과했으면 `scripts/token-tracker.py scan`을 subprocess로 실행한 뒤 다시 읽는다.

```python
import subprocess

# get_token_usage() 메서드 상단, ledger_file 읽기 전에:
ledger_file = self.memory_dir / "token-ledger.json"
if ledger_file.exists():
    try:
        raw = json.loads(ledger_file.read_text(encoding="utf-8"))
        last_scan = raw.get("last_scan", "")
        if last_scan:
            from datetime import datetime as dt
            scan_time = dt.fromisoformat(last_scan)
            if (dt.now() - scan_time).total_seconds() > 1800:  # 30분
                scanner = self.workspace_dir / "scripts" / "token-tracker.py"
                if scanner.exists():
                    subprocess.run(
                        [sys.executable, str(scanner), "scan"],
                        capture_output=True, timeout=60
                    )
    except Exception:
        pass  # 스캔 실패해도 기존 데이터로 진행
```

### 2. `_enrich_tasks_with_tokens()` 메서드에도 동일 적용

이 메서드도 token-ledger.json을 읽으므로, 스캔 트리거를 공유하면 좋다.
단, 중복 스캔 방지를 위해 인스턴스 변수 `self._last_token_scan_trigger`를 추가하여 30분 내 재트리거 방지.

### 3. import 추가
파일 상단에 `import subprocess` 추가 (이미 있으면 생략).

## 완료 조건
1. 대시보드 새로고침 시 token-ledger.json이 30분 이상 오래되었으면 자동 스캔 실행
2. 스캔 완료 후 최신 데이터로 응답
3. 스캔 실패 시에도 기존 데이터로 정상 응답 (에러 전파 없음)
4. 30분 내 중복 스캔 방지
5. 기존 토큰 관련 로직 파괴 없음

## 주의사항
- subprocess.run에 timeout=60 필수 (스캔이 무한 대기하면 안 됨)
- capture_output=True로 stdout/stderr 숨김
- 서버 응답 지연을 최소화하기 위해 스캔은 동기 실행 (60초 내 완료됨, 보통 5-10초)
