#!/bin/bash
# hermes-enqueue — drop a task into the self-prompt queue
# Usage: hermes-enqueue "Run make test and report results"
#        hermes-enqueue -p high "Fix the broken import in router.py"
#        echo "multi-line prompt" | hermes-enqueue -

set -euo pipefail

QUEUE_DIR="$HOME/.hermes/queue"
PRIORITY="normal"

while [[ $# -gt 0 ]]; do
  case "$1" in
    -p|--priority) PRIORITY="$2"; shift 2 ;;
    -) PROMPT="$(cat)"; shift ;;
    *) PROMPT="$1"; shift ;;
  esac
done

if [[ -z "${PROMPT:-}" ]]; then
  echo "Usage: hermes-enqueue [-p high|normal|low] \"prompt text\""
  exit 1
fi

TIMESTAMP=$(date +%s)
ID="${TIMESTAMP}_$$"
TASK_FILE="$QUEUE_DIR/pending/${PRIORITY}_${ID}.task"

cat > "$TASK_FILE" <<EOF
CREATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)
PRIORITY=$PRIORITY
PROMPT=$PROMPT
EOF

echo "Queued: $TASK_FILE"
