From 69d982d0fa9400f757fc8fa7fc7814bc5bbe34e6 Mon Sep 17 00:00:00 2001 From: Hara Date: Mon, 4 May 2026 12:51:33 +0200 Subject: [PATCH] hara: add morning heartbeat systemd service + timer Daily 08:07 CEST oneshot: runs claude -p with Gmail MCP to check email, sends a morning Telegram ping via Bot API. Persistent timer survives reboots. --- nixos/hosts/phantom-ship.nix | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/nixos/hosts/phantom-ship.nix b/nixos/hosts/phantom-ship.nix index 7caccf9..13a8dce 100644 --- a/nixos/hosts/phantom-ship.nix +++ b/nixos/hosts/phantom-ship.nix @@ -387,6 +387,48 @@ in }; }; + # Hara morning heartbeat — daily email check + Telegram good-morning ping. + # Runs claude in print mode with the Gmail MCP, then sends output via Bot API. + # Token lives in ~/.claude/channels/telegram/.env (managed by the telegram plugin). + systemd.services.hara-heartbeat = { + description = "Hara morning heartbeat (email check + Telegram ping)"; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + path = [ pkgs.claude-code pkgs.curl pkgs.jq ]; + environment = { + HOME = "/home/danny"; + }; + serviceConfig = { + Type = "oneshot"; + User = "danny"; + Group = "users"; + WorkingDirectory = "/home/danny"; + EnvironmentFile = "/etc/claude-channels/env"; + }; + script = '' + set -euo pipefail + CHAT_ID="66070351" + BOT_TOKEN=$(grep '^TELEGRAM_BOT_TOKEN=' /home/danny/.claude/channels/telegram/.env | cut -d= -f2-) + MSG=$(${pkgs.claude-code}/bin/claude -p \ + "You are Hara, a concise cat-energy AI assistant. Read ~/.hara/HEARTBEAT.md. Check Gmail for both accounts (danielth95 and powerhouseplayer) for urgent unread emails — security alerts, invoices, anything requiring a decision; skip newsletters and marketing. Compose a short morning message for Danny: flag urgent emails if any, otherwise just say good morning. One message, very short, cat energy." \ + --mcp-config /etc/hara/mcp-servers.json \ + 2>/dev/null) + ${pkgs.curl}/bin/curl -sf -X POST \ + "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \ + -H "Content-Type: application/json" \ + -d "{\"chat_id\": $CHAT_ID, \"text\": $(echo "$MSG" | ${pkgs.jq}/bin/jq -Rs .)}" \ + > /dev/null + ''; + }; + + systemd.timers.hara-heartbeat = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "Europe/Copenhagen *-*-* 08:07:00"; + Persistent = true; + }; + }; + # Auto-rebuild service/timer + safe.directory provided by the # shared dotfiles-rebuild NixOS module (see nixos/modules/dotfiles-rebuild.nix). }