File: //tmp/hb_collect.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'
AUTH_HEADER="Authorization: Bearer $AUTH_TOKEN"
health=$(curl -fsS -H "$AUTH_HEADER" -o /tmp/hb_health_body -w '%{http_code}' "$BASE_URL/healthz")
boards=$(curl -fsS -H "$AUTH_HEADER" -o /tmp/hb_boards_body -w '%{http_code}' "$BASE_URL/api/v1/agent/boards")
tasks=$(curl -fsS -H "$AUTH_HEADER" -o /tmp/hb_tasks_body -w '%{http_code}' "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks")
heartbeat=$(curl -fsS -H "$AUTH_HEADER" -H 'Content-Type: application/json' -X POST -d '{"agent_name":"altaira","agent_id":"e4c57543-6899-4be1-b449-f6cf886c39f8","board_id":"2857b7e4-abd0-41ae-8185-4bc3c37cfee1"}' -o /tmp/hb_heartbeat_body -w '%{http_code}' "$BASE_URL/api/v1/agent/heartbeat")
for status in inbox in_progress review; do
curl -fsS -H "$AUTH_HEADER" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks?status=$status" > "/tmp/tasks_$status.json"
done
curl -fsS -H "$AUTH_HEADER" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/memory?limit=20" > /tmp/board_memory.json
curl -fsS -H "$AUTH_HEADER" "$BASE_URL/api/v1/boards/$BOARD_ID/group-memory?limit=20" > /tmp/group_memory.json
curl -fsS -H "$AUTH_HEADER" "$BASE_URL/api/v1/boards/$BOARD_ID/group-snapshot?include_self=true" > /tmp/group_snapshot.json
jq -n \
--arg health "$health" \
--arg boards "$boards" \
--arg tasks "$tasks" \
--arg heartbeat "$heartbeat" \
--slurpfile hb /tmp/hb_heartbeat_body \
--slurpfile bl /tmp/hb_boards_body \
--slurpfile tl /tmp/hb_tasks_body \
--slurpfile ti /tmp/tasks_inbox.json \
--slurpfile tp /tmp/tasks_in_progress.json \
--slurpfile tr /tmp/tasks_review.json \
--slurpfile bm /tmp/board_memory.json \
--slurpfile gm /tmp/group_memory.json \
--slurpfile gs /tmp/group_snapshot.json '
def newest_non_chat(items): (items | map(select((.type // "") != "chat")) | sort_by(.created_at // .timestamp // "") | last // null);
{
http: {healthz:$health, boards:$boards, tasks:$tasks, heartbeat:$heartbeat},
heartbeat_last_seen_at: (($hb[0].last_seen_at // $hb[0].item.last_seen_at) // null),
board: (($bl[0].items // []) | map(select(.id == "2857b7e4-abd0-41ae-8185-4bc3c37cfee1")) | first // null),
task_counts: {
total: (($tl[0].total // (($tl[0].items // []) | length)) // 0),
inbox: (($ti[0].items // []) | length),
in_progress: (($tp[0].items // []) | length),
review: (($tr[0].items // []) | length)
},
latest_board_memory_non_chat: newest_non_chat(($bm[0].items // [])),
latest_group_memory: ((($gm[0].items // []) | sort_by(.created_at // .timestamp // "") | last) // null),
group_snapshot: {group: ($gs[0].group // null), boards: (($gs[0].boards // []) | length)}
}'