#!/bin/sh # Join the Rider Leaderboard: https://swarm-rider.github.io # # curl -fsSL https://raw.githubusercontent.com/swarm-rider/swarm-rider.github.io/main/tools/join.sh | sh # ... | sh -s -- --leave stop the daily update (your entries stay on the board) # # What it does: # 1. forks swarm-rider/swarm-rider.github.io to your GitHub account and clones it to ~/.swarm-rider/repo # 2. counts your coding-agent tokens (Claude Code, Codex, Gemini CLI, OpenCode) on your machine and sends # your entry as a pull request: entries//.json, numbers only # 3. schedules tools/daily.sh once a day (launchd on macOS, cron on Linux) # Needs: git, python3, and the GitHub CLI (gh) logged in. { set -eu UPSTREAM=swarm-rider/swarm-rider.github.io HOME_DIR="${SWARM_RIDER_HOME:-$HOME/.swarm-rider}" LABEL=io.github.swarm-rider.daily PLIST="$HOME/Library/LaunchAgents/$LABEL.plist" say() { printf '\033[1m%s\033[0m\n' "$*"; } die() { printf 'swarm-rider: %s\n' "$*" >&2; exit 1; } if [ "${1:-}" = "--leave" ]; then if [ "$(uname)" = Darwin ]; then launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true rm -f "$PLIST" else crontab -l 2>/dev/null | grep -v 'swarm-rider/repo/tools/daily.sh' | crontab - || true fi say "Daily update stopped. Your entries stay on the board. Delete $HOME_DIR to remove the local copy." exit 0 fi for c in git python3 gh; do command -v "$c" >/dev/null || die "needs $c"; done gh auth status >/dev/null 2>&1 || die "log in to GitHub first: gh auth login" HANDLE=$(gh api user --jq .login) say "Joining as @$HANDLE" # 1. Fork and clone. gh repo fork "$UPSTREAM" --clone=false --fork-name swarm-rider-leaderboard >/dev/null 2>&1 || true FORK="" for i in 1 2 3 4 5 6 7 8 9 10; do FORK=$(gh repo list "$HANDLE" --fork --limit 1000 --json nameWithOwner,parent \ --jq ".[] | select(.parent.owner.login + \"/\" + .parent.name == \"$UPSTREAM\") | .nameWithOwner" | head -1) [ -n "$FORK" ] && break sleep 3 done [ -n "$FORK" ] || die "could not find your fork of $UPSTREAM" mkdir -p "$HOME_DIR" if [ ! -d "$HOME_DIR/repo/.git" ]; then for i in 1 2 3 4 5; do git clone -q "https://github.com/$FORK.git" "$HOME_DIR/repo" && break sleep 3 done fi cd "$HOME_DIR/repo" git remote set-url origin "https://github.com/$FORK.git" git remote get-url upstream >/dev/null 2>&1 || git remote add upstream "https://github.com/$UPSTREAM.git" # 2. First update now. say "Counting your tokens (takes a few seconds)..." python3 -I tools/count.py || die "found no logs from Claude Code, Codex, Gemini CLI or OpenCode" sh tools/daily.sh >>"$HOME_DIR/daily.log" 2>&1 || die "first update failed; see $HOME_DIR/daily.log" tail -3 "$HOME_DIR/daily.log" # 3. Schedule it daily. MIN=$(awk 'BEGIN{srand(); print int(rand()*60)}') if [ "$(uname)" = Darwin ]; then mkdir -p "$(dirname "$PLIST")" cat >"$PLIST" < Label$LABEL ProgramArguments/bin/sh$HOME_DIR/repo/tools/daily.sh EnvironmentVariablesPATH$PATHSWARM_RIDER_HOME$HOME_DIR StartCalendarIntervalHour5Minute$MIN StandardOutPath$HOME_DIR/daily.log StandardErrorPath$HOME_DIR/daily.log EOF launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true launchctl bootstrap "gui/$(id -u)" "$PLIST" WHEN="every day at 5:$(printf %02d "$MIN") (or when your Mac wakes)" else LINE="$MIN 5 * * * PATH='$PATH' SWARM_RIDER_HOME='$HOME_DIR' /bin/sh '$HOME_DIR/repo/tools/daily.sh' >>'$HOME_DIR/daily.log' 2>&1" (crontab -l 2>/dev/null | grep -v 'swarm-rider/repo/tools/daily.sh'; echo "$LINE") | crontab - WHEN="every day at 5:$(printf %02d "$MIN")" fi say "You are in. Your numbers update $WHEN." echo "Board: https://swarm-rider.github.io Log: $HOME_DIR/daily.log" echo "To stop: curl -fsSL https://raw.githubusercontent.com/$UPSTREAM/main/tools/join.sh | sh -s -- --leave" exit 0 }