#!/bin/bash # agent-text — text Craig's phone over Signal, from any machine or agent runtime. # The Signal half of the notification vocabulary: "text me" reaches the phone, # "page me" is the desktop channel (notify). See protocols.org "Reaching Craig". # # Usage: agent-text # # The Signal identity (+15045173983) is held by any daily driver that has it in # its local signal-cli, whether as the registered primary or as a linked device # (ratio, 2026-07-20). So the dispatch is: if the account is registered locally, # send directly; otherwise ssh-relay the send to the first relay host that # actually holds it — a reachable but unregistered host fails and the loop # advances. The recipient is Craig's Signal account UUID; his phone # number reads as unregistered in Signal's directory, so never target the # number. Verified end to end 2026-07-13 (velox) and 2026-07-20 (ratio, # direct). The relay path was verified velox -> ratio on 2026-08-16 by # archsetup, who reported the exact relay command returning a Signal # timestamp with rc 0; that one is on report, not re-run here. # # This is the AWAY channel. At his desk, use the desktop channel instead: # notify info "Title" "Message" --persist # See protocols.org "Reaching Craig" for choosing between them. # # Known caveats (full runbook in rulesets docs/design/): a relay needs at least # one listed host that is both up on the tailnet AND holding the account -- a # reachable host without it fails and the loop moves on. Each device holding the # account wants a # periodic `receive` (staleness warnings appear otherwise); the signal-receive # timer handles that. # # Source: ~/code/rulesets/claude-templates/bin/agent-text # Install: make -C ~/code/rulesets install SIGNAL_ACCOUNT="+15045173983" CRAIG_UUID="b1b5601e-6126-47f8-afaa-0a59f5188fde" # Relay hosts, tried in order until one sends. ratio leads because it is the # always-on desktop at home, while velox is the laptop that travels and sleeps. # Override for a one-off with AGENT_TEXT_RELAYS="host1 host2". AGENT_TEXT_RELAYS="${AGENT_TEXT_RELAYS:-ratio.tailf3bb8c.ts.net velox.tailf3bb8c.ts.net}" if [ $# -eq 0 ]; then echo "usage: agent-text " >&2 exit 2 fi msg="$*" self="$(uname -n)" # The account is local if this machine's signal-cli holds it: the registered # primary or any linked device. Those send directly. if signal-cli listAccounts 2>/dev/null | grep -q "$SIGNAL_ACCOUNT"; then signal-cli -a "$SIGNAL_ACCOUNT" send -m "$msg" "$CRAIG_UUID" rc=$? why="local signal-cli send failed" else rc=1 why="no relay reachable in: $AGENT_TEXT_RELAYS" for host in $AGENT_TEXT_RELAYS; do # Never relay to this machine. Reaching this branch means the account is # NOT local, so an ssh round trip to ourselves lands on the same empty # signal-cli and cannot succeed. velox hit exactly that after its # 2026-08-13 reinstall wiped the registration: the only relay target was # velox, so the fallback pointed at the one machine guaranteed to fail. [ "${host%%.*}" = "${self%%.*}" ] && continue # printf %q hardens the message for the remote shell. ssh -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \ "$host" \ "signal-cli -a $SIGNAL_ACCOUNT send -m $(printf '%q' "$msg") $CRAIG_UUID" rc=$? [ "$rc" -eq 0 ] && break done fi if [ "$rc" -ne 0 ]; then echo "agent-text: phone message failed ($why); fall back to the desktop channel: notify info 'Message' '' --persist" >&2 fi exit "$rc"