#!/usr/bin/env python3 """ Notes Agent Fetches recent note titles from Apple Notes via the Mac bridge. Returns a markdown section for the daily briefing. Privacy: titles and dates only, no body content. """ import sys from shared import api_request, log_run AGENT_ID = "notes" DEFAULT_BRIDGE_URL = "http://192.168.1.62:8551" def run(config=None): """Run the notes agent. Config keys: bridge_url: Mac bridge URL (default: http://192.168.1.62:8551) limit: max notes to show (default: 10) folder: optional folder filter """ cfg = config or {} bridge_url = cfg.get("bridge_url", DEFAULT_BRIDGE_URL) limit = cfg.get("limit", 10) folder = cfg.get("folder") try: params = f"?limit={limit}" if folder: params += f"&folder={folder}" data = api_request(f"{bridge_url}/api/notes{params}") notes = data.get("notes", []) if not notes: return "## Recent Notes\n\n*No recent notes.*\n", "No notes" md = "## Recent Notes\n\n" md += "| Note | Folder | Modified |\n" md += "|------|--------|----------|\n" for n in notes: mod = n.get("modificationDate", "")[:10] md += f"| {n['name'][:60]} | {n['folder']} | {mod} |\n" md += "\n" summary = f"{len(notes)} recent notes" log_run(AGENT_ID, "success", output=summary) return md, summary except Exception as e: err = f"Notes error: {e}" print(f" {err}", file=sys.stderr) log_run(AGENT_ID, "failed", err=err) return "## Recent Notes\n\n*Could not reach Apple Bridge. Is your Mac online?*\n", f"error: {e}" if __name__ == "__main__": section, summary = run() print(section) print(f"\nSummary: {summary}")