#!/bin/bash
# aria-idempotency-check.sh
# Usage: aria-idempotency-check.sh <ACTIVE_TASK_FILE> <ACTION_TOKEN>
# Exit 0 = already done (skip action).
# Exit 1 = not done (proceed with action).
#
# Example:
#   aria-idempotency-check.sh /root/aria/state/workers/myworker/active-task.md GIT_PUSH_main \
#     || git push origin main
TASK_FILE="${1:-/root/aria/state/active-task.md}"
TOKEN="$2"
if [ -z "$TOKEN" ]; then exit 1; fi
if grep -q " $TOKEN:" "$TASK_FILE" 2>/dev/null; then
    echo "ALREADY_DONE: $TOKEN"
    exit 0
fi
exit 1
