File: //proc/self/root/tmp/altaira_heartbeat_check.sh
#!/usr/bin/env bash
set -euo pipefail
cd /home/altaira.panomity.com/workspace-mc-e4c57543-6899-4be1-b449-f6cf886c39f8
BASE_URL=$(sed -n 's/.*`BASE_URL=\(.*\)`.*/\1/p' TOOLS.md)
AUTH_TOKEN=$(sed -n 's/.*`AUTH_TOKEN=\(.*\)`.*/\1/p' TOOLS.md)
AGENT_NAME=$(sed -n 's/.*`AGENT_NAME=\(.*\)`.*/\1/p' TOOLS.md)
AGENT_ID=$(sed -n 's/.*`AGENT_ID=\(.*\)`.*/\1/p' TOOLS.md)
BOARD_ID=$(sed -n 's/.*`BOARD_ID=\(.*\)`.*/\1/p' TOOLS.md)
printf 'HEARTBEAT_PATH_OK\n'
[ -f HEARTBEAT.md ]
curl -fsS "$BASE_URL/openapi.json" -o /tmp/openapi.json
jq -r '
.paths | to_entries[] | .key as $path
| .value | to_entries[]
| select((.value.tags // []) | index("agent-worker"))
| ((.value.summary // "") | gsub("\\s+"; " ")) as $summary
| "\(.key|ascii_upcase)\t\($path)\t\(.value.operationId // "-")\t\(.value["x-llm-intent"] // "-")\t\(.value["x-when-to-use"] // [] | join(" | "))\t\(.value["x-routing-policy"] // [] | join(" | "))\t\($summary)"
' /tmp/openapi.json | sort > /tmp/agent-worker-operations.tsv
healthz=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/healthz")
boards=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards")
tasks=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/tasks")
heartbeat=$(curl -fsS -X POST -H "Authorization: Bearer $AUTH_TOKEN" -H "Content-Type: application/json" "$BASE_URL/api/v1/agent/heartbeat" -d "{\"agent_name\":\"$AGENT_NAME\",\"agent_id\":\"$AGENT_ID\"}")
board_memory=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/agent/boards/$BOARD_ID/memory?limit=10")
group_snapshot=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/boards/$BOARD_ID/group-snapshot?include_self=true")
group_memory=$(curl -fsS -H "Authorization: Bearer $AUTH_TOKEN" "$BASE_URL/api/v1/boards/$BOARD_ID/group-memory?limit=10")
printf 'HEALTHZ %s\n' "$(jq -c . <<<"$healthz")"
printf 'BOARDS %s\n' "$(jq -c '{count:(.items|length), ids:(.items|map(.id)), board:(.items[]|select(.id=="'"$BOARD_ID"'")|{id,objective,status,lead_agent_id,board_group_id})}' <<<"$boards")"
printf 'TASKS %s\n' "$(jq -c '{total, active:(.items|map(select(.status=="in_progress" or .status=="review" or .status=="inbox")|{id,status,assignee_agent_id,title}))}' <<<"$tasks")"
printf 'HEARTBEAT %s\n' "$(jq -c . <<<"$heartbeat")"
printf 'BOARD_MEMORY %s\n' "$(jq -c '{count:(.items|length), newest_non_chat:(.items|map(select(.type != "chat"))|.[0] // null)}' <<<"$board_memory")"
printf 'GROUP_SNAPSHOT %s\n' "$(jq -c '{group_id:(.group.id // null), boards:(.boards|map(.board.id))}' <<<"$group_snapshot")"
printf 'GROUP_MEMORY %s\n' "$(jq -c '{count:(.items|length), newest:(.items[0] // null)}' <<<"$group_memory")"