"""daily_word.py — Scheduled task: Hermes picks an English word and posts it to LINE.

This is the "event-driven" pattern. The agent isn't scheduling itself —
launchd schedules this script, the script uses the agent. Same pattern
works for "scrape a website every hour", "email a daily report", etc.

Run on demand:
    python daily_word.py

Run on a schedule: see com.kruai.daily.plist.
"""
import os
import sys

from agent_pro import build_agent, send_line_push


def main() -> None:
    target = os.getenv("LINE_BROADCAST_USER_ID")
    if not target:
        print("Set LINE_BROADCAST_USER_ID (a userId, groupId, or roomId).")
        sys.exit(1)

    agent = build_agent()
    prompt = (
        "Pick ONE useful English word for a 14-year-old Thai student living in "
        "Chiang Mai. Reply in this exact 3-line shape:\n"
        "  Word: <english>\n"
        "  ความหมาย: <Thai>\n"
        "  Example: <one short English sentence using the word>"
    )
    word_card = str(agent.chat(prompt))
    print("Posting to LINE:\n", word_card)
    print(send_line_push(target, word_card))


if __name__ == "__main__":
    main()
