#!/usr/bin/env python3 from __future__ import annotations import os import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[1] if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) from ai_daily_report.env import read_env_file PROJECT_ENV_PATH = PROJECT_ROOT / ".env" OUT_DIR = Path.home() / ".hermes" / "scripts" / "ai_morning_out" def load_env() -> dict[str, str]: env: dict[str, str] = {} env.update(read_env_file(PROJECT_ENV_PATH)) env.update(read_env_file(Path.home() / ".hermes" / ".env")) env.update({key: value for key, value in os.environ.items() if value}) return env def is_dry_run(env: dict[str, str]) -> bool: return (env.get("AI_DAILY_DRY_RUN") or "").strip().lower() in {"1", "true", "yes"} def requires_blog_token(env: dict[str, str]) -> bool: return not is_dry_run(env) def main() -> None: from ai_daily_report.runner import run_daily_report env = load_env() dry_run = is_dry_run(env) result = run_daily_report( run_date=env.get("AI_DAILY_RUN_DATE") or "today", mode="dry-run" if dry_run else env.get("AI_DAILY_MODE", "publish"), source_mode=env.get("AI_DAILY_SOURCE_MODE", "live"), llm_mode=env.get("AI_DAILY_LLM_MODE", "live"), out_dir=Path(env.get("AI_DAILY_OUT_DIR") or OUT_DIR), base_url=env.get("BLOG_API_BASE_URL", "https://blog.ephron.ren"), sources_path=Path(env["AI_DAILY_SOURCES_PATH"]) if env.get("AI_DAILY_SOURCES_PATH") else None, env=env, ) stage8 = result.get("reports", {}).get("stage8", {}) if stage8.get("status") in {"blocked", "failed"}: print(f"AI daily report failed quality gate: {stage8.get('error') or stage8.get('status')}", file=sys.stderr) raise SystemExit(2) if __name__ == "__main__": main()