#!/bin/bash
# AgentPin status line bridge. Claude Code passes the status line JSON (including your plan's
# 5-hour and weekly usage) on stdin. This sends it to the AgentPin panel, then runs the status
# line you had before AgentPin (if any) with the same input, so your status line looks the same.
DIR="$HOME/Library/Application Support/AgentPin"
input="$(cat)"
TOKEN="$(cat "$DIR/token" 2>/dev/null)"
PORT="$(cat "$DIR/port" 2>/dev/null)"
line=""
if [ -n "$TOKEN" ]; then
  line="$(printf '%s' "$input" | curl -s --fail --connect-timeout 0.5 --max-time 1 -H 'Expect:' \
    -H 'Content-Type: application/json' -H "X-AgentPin-Token: $TOKEN" \
    --data-binary @- "http://127.0.0.1:${PORT:-47321}/statusline" 2>/dev/null)"
fi
PREV="$DIR/statusline-previous.sh"
if [ -s "$PREV" ]; then
  printf '%s' "$input" | /bin/bash "$PREV"
else
  [ -n "$line" ] && printf '%s\n' "$line"
fi
exit 0
