aboutsummaryrefslogtreecommitdiff
path: root/claude-templates/bin/agent-page
blob: 8e9b23caa7e977f7158a48169ba6a796a22cec17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# agent-page — page Craig's phone over Signal, from any machine or agent runtime.
#
# Usage: agent-page <message...>
#
# The pager identity (+15045173983) is registered in velox's signal-cli, and
# any daily driver linked as a device of that account (ratio, 2026-07-20) can
# send directly too. So the dispatch is: if the pager account is registered in
# the local signal-cli, send directly; otherwise ssh-relay the send to velox
# over the tailnet. A direct send from a linked device still lands when velox
# is down — the reason ratio was linked. The recipient is Craig's Signal
# account UUID — his phone number reads as unregistered in Signal's directory,
# so never page the number. Verified end to end 2026-07-13 (velox) and
# 2026-07-20 (ratio, direct).
#
# This is the AWAY channel. At his desk, use the desktop channel instead:
#   notify info "Title" "Message" --persist
# See protocols.org "Paging Craig" for choosing between them.
#
# Known caveats (tracked on the rulesets Signal-pager task, full runbook in
# rulesets docs/design/): a relay from a non-linked machine needs velox up on
# the tailnet, and 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-page
# Install: make -C ~/code/rulesets install

PAGER_ACCOUNT="+15045173983"
CRAIG_UUID="b1b5601e-6126-47f8-afaa-0a59f5188fde"
VELOX_HOST="velox.tailf3bb8c.ts.net"

if [ $# -eq 0 ]; then
  echo "usage: agent-page <message...>" >&2
  exit 2
fi

msg="$*"

# The pager account is local if this machine's signal-cli holds it — the
# registered primary (velox) or any linked device. Those send directly.
if signal-cli listAccounts 2>/dev/null | grep -q "$PAGER_ACCOUNT"; then
  signal-cli -a "$PAGER_ACCOUNT" send -m "$msg" "$CRAIG_UUID"
  rc=$?
else
  # printf %q hardens the message for the remote shell.
  ssh -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \
    "$VELOX_HOST" \
    "signal-cli -a $PAGER_ACCOUNT send -m $(printf '%q' "$msg") $CRAIG_UUID"
  rc=$?
fi

if [ "$rc" -ne 0 ]; then
  echo "agent-page: phone page failed (velox down or unreachable?) — fall back to the desktop channel: notify info 'Page' '<message>' --persist" >&2
fi
exit "$rc"