#!/bin/bash
# Usage: queue-check.sh <agent-name>
# Prints pending tasks from queue.json for the agent to act on

AGENT=$1
QUEUE="/home/ccuser/${AGENT}/queue.json"

if [ ! -f "$QUEUE" ]; then
  echo "NO_TASKS"
  exit 0
fi

PENDING=$(python3 -c "
import json
with open('$QUEUE') as f:
    data = json.load(f)
tasks = [t for t in data.get('tasks', []) if t.get('status') == 'pending']
if not tasks:
    print('NO_TASKS')
else:
    for t in tasks:
        print(f\"[{t['priority'].upper()}] {t['id']}: {t['title']}\")
        print(f\"  {t['description'][:200]}\")
        print(f\"  Due: {t.get('due', 'none')}\")
        print()
" 2>/dev/null)

echo "$PENDING"
