#!/usr/bin/env bash # Create the weekly review as an Agent of Empires session, then ping the phone. # See README "Weekly review timer" for why this is interactive and not `-p`. set -euo pipefail REPO="${WEEK_REVIEW_REPO:-$HOME/tea/yolo/agent-skills}" PROMPT="${WEEK_REVIEW_PROMPT:-/week-review}" TOPIC="${WEEK_REVIEW_NTFY_TOPIC:-homelab}" AOE="${WEEK_REVIEW_AOE:-$HOME/.local/bin/aoe}" LOG="$HOME/.local/state/week-review/run.log" WEEK="$(date +%G-W%V)" TITLE="week-review-$WEEK" BRANCH="week-review/$WEEK" mkdir -p "$(dirname "$LOG")" exec >>"$LOG" 2>&1 echo "=== $(date -Is) starting $TITLE ===" # NTFY_URL/NTFY_TOKEN live here; ~/.zshrc only sources it for interactive shells. # shellcheck disable=SC1091 [ -f "$HOME/.env.claude" ] && . "$HOME/.env.claude" notify() { # notify <priority> <message> [ -n "${NTFY_URL:-}" ] || { echo "no NTFY_URL, skipping notify"; return 0; } curl -sS -m 10 -o /dev/null \ -H "Authorization: Bearer ${NTFY_TOKEN:-}" \ -H "Title: $1" -H "Priority: $2" -H "Tags: calendar" \ -d "$3" "$NTFY_URL/$TOPIC" || echo "notify failed" } open="$("$AOE" list 2>/dev/null | awk '$1 ~ /^week-review-/ { print $1 }' || true)" if [ -n "$open" ]; then echo "already open: $open — not starting a second one" notify "Week review skipped" default \ "An earlier review is still open ($open). Finish or remove it." exit 0 fi "$AOE" add "$REPO" --title "$TITLE" --cmd claude --worktree "$BRANCH" --new-branch \ --yolo --trust-hooks # not `add --launch`: that attaches, and attaching without a TTY fails the run # after the session is already up. "$AOE" session start "$TITLE" # The agent needs its TUI up before it can take a prompt; `send` into a # still-booting pane is dropped silently. sleep 25 if "$AOE" send "$TITLE" "$PROMPT"; then echo "session $TITLE launched and prompted" notify "Week review ready" default "aoe: $TITLE — waiting on your first answer" else echo "failed to send prompt to $TITLE" notify "Week review failed to start" high "session $TITLE — see $LOG" exit 1 fi