File: //tmp/hb_pull.sh
#!/usr/bin/env bash
set -euo pipefail
BASE_URL="https://altaira.panomity.com/mc"
AUTH_TOKEN="ztbHKAe1UYI66HCFvSAyo4wrAAD6frNCyAZ67aKVeSE"
BOARD_ID="2857b7e4-abd0-41ae-8185-4bc3c37cfee1"
mkdir -p /tmp/hb
curl -sS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks?status=inbox" > /tmp/hb/inbox.json
curl -sS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks?status=in_progress" > /tmp/hb/in_progress.json
curl -sS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks?status=review" > /tmp/hb/review.json
curl -sS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/memory?is_chat=false&limit=5" > /tmp/hb/board_memory.json
curl -sS "$BASE_URL/api/v1/boards/$BOARD_ID/group-snapshot?include_self=true" > /tmp/hb/group_snapshot.json
curl -sS "$BASE_URL/api/v1/boards/$BOARD_ID/group-memory?limit=8" > /tmp/hb/group_memory.json
heartbeat_code=$(curl -sS -o /tmp/hb/heartbeat.json -w "%{http_code}" -X POST -H "Authorization: Bearer $AUTH_TOKEN" -H "Content-Type: application/json" -d '{"agent_name":"altaira","agent_id":"e4c57543-6899-4be1-b449-f6cf886c39f8","board_id":"2857b7e4-abd0-41ae-8185-4bc3c37cfee1"}' "$BASE_URL/api/v1/agent/heartbeat")
objective=$(jq -r --arg id "$BOARD_ID" '.items[] | select(.id == $id) | .objective // empty' /tmp/hb_boards.json | head -n1)
status=$(jq -r --arg id "$BOARD_ID" '.items[] | select(.id == $id) | .status // empty' /tmp/hb_boards.json | head -n1)
lead_agent_id=$(jq -r --arg id "$BOARD_ID" '.items[] | select(.id == $id) | .lead_agent_id // empty' /tmp/hb_boards.json | head -n1)
jq -n \
--arg heartbeat_code "$heartbeat_code" \
--arg last_seen_at "$(jq -r '.last_seen_at // empty' /tmp/hb/heartbeat.json)" \
--argjson inbox_total "$(jq '.total // 0' /tmp/hb/inbox.json)" \
--argjson in_progress_total "$(jq '.total // 0' /tmp/hb/in_progress.json)" \
--argjson review_total "$(jq '.total // 0' /tmp/hb/review.json)" \
--argjson tasks_total "$(jq '.total // 0' /tmp/hb_tasks.json)" \
--arg objective "$objective" \
--arg status "$status" \
--arg lead_agent_id "$lead_agent_id" \
--arg board_memory_latest "$(jq -r '.items[0].created_at // empty' /tmp/hb/board_memory.json)" \
--arg board_memory_latest_id "$(jq -r '.items[0].id // empty' /tmp/hb/board_memory.json)" \
--arg group_memory_latest "$(jq -r '.items[0].created_at // empty' /tmp/hb/group_memory.json)" \
--arg group_memory_latest_tags "$(jq -r '(.items[0].tags // []) | join(",")' /tmp/hb/group_memory.json)" \
--arg group_boards "$(jq -r '(.boards // []) | map(.board.id) | join(",")' /tmp/hb/group_snapshot.json)" \
'{heartbeat_code:$heartbeat_code,last_seen_at:$last_seen_at,tasks_total:$tasks_total,inbox_total:$inbox_total,in_progress_total:$in_progress_total,review_total:$review_total,objective:($objective|select(length>0)),status:($status|select(length>0)),lead_agent_id:($lead_agent_id|select(length>0)),board_memory_latest:$board_memory_latest,board_memory_latest_id:$board_memory_latest_id,group_memory_latest:$group_memory_latest,group_memory_latest_tags:$group_memory_latest_tags,group_boards:$group_boards}'