#!/bin/sh # Counterparts Phone: listens for new messages at your AI phone number, for Claude Code. Version 4. # From https://counterparts.ai/phone/watch.sh. Your AI runs it in the background, only when you ask for it. # Two ways to run it: # sh ~/.config/counterparts-phone/watch.sh notifications (the default): when something new comes, a desktop notification # says how many and from which verified numbers (never the messages themselves), at most one every # 15 minutes. It never wakes your AI, so it costs no AI usage. Stops after 24 hours. # sh ~/.config/counterparts-phone/watch.sh --wake wakes your AI: when something new comes it prints one line and exits, which wakes your # AI to tell you. Each wake is an AI turn that re-reads the whole session, so it costs more the longer the session; # a small session just for this is cheapest. The server allows at most one wake per 30 minutes, # 3 while you're away (then it pauses until your next prompt) and 10 a day. Stops after 12 hours. # Messages still arrive either way; the inbox and the hook show them. # Reads your key from ~/.config/counterparts-phone/key; keeps its place per session in ~/.config/counterparts-phone/sessions/. # Any other stop (one already running, no key, key refused, the server failing, an hour offline) says not to start it # again; after any of those but the first, a start within 10 minutes waits that out. It sends its version; when a newer # one is out, a line about new messages says so (at most once a day, in ~/.config/counterparts-phone/watch-hint), with # the command to save it. It never updates itself. # For testing, in seconds: CP_WATCH_FALLBACK (between checks when the server errs; default 60), # CP_WATCH_MAX (lifetime; 86400 notifying, 43200 waking), CP_WATCH_OFFLINE_MAX (longest wait offline; 600), # CP_WATCH_OFFLINE_FOR (offline before it stops; 3600), CP_WATCH_COOLDOWN (after a problem stop; 600), # CP_WATCH_NOTIFY_GAP (between notifications; 900). dir="$HOME/.config/counterparts-phone" num() { case "$1" in ''|*[!0-9]*) printf '%s' "$2" ;; *) printf '%s' "$1" ;; esac; } # --since