Last active
January 18, 2026 21:29
-
-
Save aronchick/40c5fa835f40c81bcd33be5892119d22 to your computer and use it in GitHub Desktop.
Register agent with swarm overseer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Register current repo as a swarm agent | |
| # | |
| # Usage: | |
| # curl -fsSL https://bac.al/register-agent | bash | |
| # | |
| set -e | |
| # --- Dependency checks --- | |
| check_deps() { | |
| local missing=() | |
| if ! command -v gh &>/dev/null; then | |
| missing+=("gh (GitHub CLI) - install: brew install gh") | |
| elif ! gh auth status &>/dev/null; then | |
| echo "✗ gh is installed but not authenticated" | |
| echo " Run: gh auth login" | |
| exit 1 | |
| fi | |
| if ! command -v jj &>/dev/null && ! command -v git &>/dev/null; then | |
| missing+=("jj or git - install: brew install jj") | |
| fi | |
| if [ ${#missing[@]} -gt 0 ]; then | |
| echo "✗ Missing dependencies:" | |
| printf ' - %s\n' "${missing[@]}" | |
| exit 1 | |
| fi | |
| } | |
| check_deps | |
| # --- Config --- | |
| OVERSEER_REPO="${OVERSEER_REPO:-overseer}" | |
| # --- Get GitHub user --- | |
| USER=$(gh api user -q .login) | |
| # --- Get hostname --- | |
| HOSTNAME=$(hostname -s 2>/dev/null || hostname) | |
| # --- Get org/repo from remote URL --- | |
| if [[ -d .jj ]]; then | |
| URL=$(jj git remote list 2>/dev/null | awk '/origin/{print $2}') | |
| elif [[ -d .git ]]; then | |
| URL=$(git remote get-url origin 2>/dev/null) | |
| fi | |
| if [[ -z "$URL" ]]; then | |
| echo "✗ Not in a git/jj repo with an origin remote" | |
| echo " Run this from inside an agent repo directory" | |
| exit 1 | |
| fi | |
| # Extract owner/repo from URL | |
| ORG_REPO=$(echo "$URL" | sed -E 's#(git@|https://)github\.com[:/]##' | sed 's/\.git$//') | |
| AGENT="$HOSTNAME:$ORG_REPO" | |
| echo "┌────────────────────────────────────────┐" | |
| echo "│ Registering: $AGENT" | |
| echo "│ Overseer: $USER/$OVERSEER_REPO" | |
| echo "└────────────────────────────────────────┘" | |
| # --- Fetch current agents.txt via API --- | |
| RESP=$(gh api "repos/$USER/$OVERSEER_REPO/contents/agents.txt" 2>/dev/null) || { | |
| echo "✗ Cannot find $USER/$OVERSEER_REPO/agents.txt" | |
| echo " Make sure the overseer repo exists and has agents.txt" | |
| exit 1 | |
| } | |
| SHA=$(echo "$RESP" | gh api --input - -q .sha 2>/dev/null || echo "$RESP" | sed -n 's/.*"sha":"\([^"]*\)".*/\1/p') | |
| CONTENT=$(echo "$RESP" | gh api --input - -q .content 2>/dev/null | base64 -d 2>/dev/null || echo "$RESP" | sed -n 's/.*"content":"\([^"]*\)".*/\1/p' | base64 -d) | |
| # --- Check if already registered --- | |
| if echo "$CONTENT" | grep -qxF "$AGENT"; then | |
| echo "✓ Already registered" | |
| exit 0 | |
| fi | |
| # --- Append and push via API --- | |
| NEW_CONTENT=$(printf '%s\n%s' "$CONTENT" "$AGENT" | sort -u | base64 | tr -d '\n') | |
| gh api -X PUT "repos/$USER/$OVERSEER_REPO/contents/agents.txt" \ | |
| -f message="Register agent: $AGENT" \ | |
| -f content="$NEW_CONTENT" \ | |
| -f sha="$SHA" \ | |
| >/dev/null | |
| echo "✓ Registered! Dashboard updates in ~60s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment