name: daily_digest
description: 每天早上聚合多源資料 (KBDB / RSS / GitHub trending) → claude 摘要 → telegram

flow:
  - "morning_cron >> ON_SUCCESS >> fetch_kbdb_yesterday"
  - "morning_cron >> ON_SUCCESS >> fetch_rss"
  - "morning_cron >> ON_SUCCESS >> fetch_github_trending"
  - "fetch_kbdb_yesterday >> ON_SUCCESS >> compose_digest"
  - "fetch_rss >> ON_SUCCESS >> compose_digest"
  - "fetch_github_trending >> ON_SUCCESS >> compose_digest"
  - "compose_digest >> ON_SUCCESS >> push_digest"

config:
  morning_cron:
    component: cron
    cron_expr: "0 0 * * *"   # UTC 00:00 = 台灣 08:00

  fetch_kbdb_yesterday:
    component: kbdb_get
    api_key: "{{api_key}}"
    type: "note"
    source: "km-writer-direct"
    limit: 50

  fetch_rss:
    component: http_request
    url: "https://hnrss.org/frontpage?count=10"
    method: GET

  fetch_github_trending:
    component: http_request
    url: "https://api.github.com/search/repositories?q=created:>{{_yesterday}}+stars:>500&sort=stars&order=desc&per_page=5"
    method: GET
    headers:
      Accept: "application/vnd.github+json"

  # compose 收三條 fan-in（cypher-executor 自動等三個 source 都完成才跑）
  compose_digest:
    component: claude_api
    timeout_ms: 60000
    _recipe_output_format: text
    prompt: |
      整理 leo 今天的「晨間訊息摘要」。三部分各取重點 5-8 條：

      ## 我昨天寫的（KBDB notes）
      {{fetch_kbdb_yesterday.blocks}}

      ## Hacker News
      {{fetch_rss.data}}

      ## GitHub 熱門新 repo
      {{fetch_github_trending.data}}

      格式：markdown bullets，每條 < 30 字，標明來源。

  push_digest:
    component: telegram_send
    chat_id: "{{secret.LEO_TELEGRAM_CHAT_ID}}"
    text: |
      ☀️ 早安 {{_today}}

      {{compose_digest.data.text}}
