# Morning Briefing Context Collector Pattern

Use this pattern when a daily briefing needs grounded, current context rather than a purely LLM-generated prompt.

## Pattern

1. Put a deterministic collector in `~/.hermes/scripts/<briefing>.py`.
2. The collector prints compact JSON to stdout; the cron job passes that output into the agent prompt.
3. The prompt formats the JSON into a concise Telegram briefing and may add recent-session follow-ups if available.
4. Test the collector independently before updating the cron job.

## Current Morning Briefing Implementation

- Script: `~/.hermes/scripts/morning_briefing.py`
- Cron job: `847bdbc26edf`
- Schedule: `0 5 * * *` Europe/Berlin/Zurich local time
- Model: `openrouter/auto`
- GitHub mirror of sanitized code: `Gamexgit/HealthManager`, `scripts/cron/morning_briefing.py`

## Data Sources Used

- Google Calendar via `gog -a friday.uplink@gmail.com calendar events --all --days 2 --json`
- Todoist REST API v1 using token from `~/.todoist_token`
- Weather for Windisch via Open-Meteo
- Route Windisch → Stein AG, or first external morning calendar location, via OSRM/Nominatim
- Traffic/news signals via Google News RSS queries
- Health context from `~/.hermes/assets/Gesundheit/health_data.db` where available

## Output Sections Expected

- Heute wichtig
- Termine & Fahrplan
- Arbeitsweg & Verkehr
- Wetter Windisch
- Todoist-Pendenzen
- Follow-ups, Chancen & Risiken
- News-Scan: Region, Schweiz/Welt, KI/Crypto
- Proaktiver Tages-Tipp

## Pitfalls

- Do not hard-code dates; compute today/tomorrow from `Europe/Zurich`.
- Do not hard-code credentials in the GitHub mirror. Runtime script may use local env/secrets, but sanitize before committing.
- `OSRM` duration is not live traffic. Label it explicitly as "ohne Live-Verkehr" and infer only soft traffic risk from current traffic/news items.
- Calendar events from imported Outlook calendars may carry UTC/Amsterdam timezones; always convert to local Zurich time for user-facing output.
- Todoist API v1 responses can be slow; use direct `urllib`/timeouts and bucket tasks by overdue/today/tomorrow/next 7 days/no due.
- Telegram does not render tables well; use headings and bullets.

## Verification

```bash
python3 ~/.hermes/scripts/morning_briefing.py > /tmp/morning_briefing_context.json
python3 - <<'PY'
import json
j=json.load(open('/tmp/morning_briefing_context.json'))
print(sorted(j))
print('events_today', len(j['calendar'].get('today', [])))
print('todo_total', j['todoist'].get('total_open'), 'error', j['todoist'].get('error'))
print('weather_error', j['weather_windisch'].get('error'))
print('route', j['commute']['route'])
print('news_counts', {k: len(v) for k, v in j['news'].items()})
PY
```

Then update/verify cron:

```bash
hermes cron list | grep -A3 'Morgen-Briefing'
```
