← back to Yolo Agent

promote-and-parallel.sh

117 lines

#!/bin/bash
# ============================================================================
# YOLO Task Promoter — Monitors high-priority completion, then promotes
# medium and low tasks with parallel subagent execution
# ============================================================================

AUTH="admin:DWSecure2024!"
BASE="http://localhost:9670"
TASKS_DIR="/root/DW-Agents/yolo-agent/tasks"

log() { echo "[$(date '+%Y-%m-%d %H:%M:%S PT')] $1"; }

# ── Phase 1: Wait for HIGH priority queue to drain ──────────────────────────
log "PHASE 1: Monitoring HIGH priority tasks (01-10) in YOLO queue..."

while true; do
    QUEUE_COUNT=$(curl -s -u "$AUTH" "$BASE/api/queue" 2>/dev/null | python3 -c "import json,sys; print(len(json.load(sys.stdin)))" 2>/dev/null)
    STATUS=$(curl -s -u "$AUTH" "$BASE/api/status" 2>/dev/null)
    CURRENT=$(echo "$STATUS" | python3 -c "import json,sys; print(json.load(sys.stdin).get('currentTask','none'))" 2>/dev/null)

    if [ "$QUEUE_COUNT" = "0" ] && [ "$CURRENT" = "null" -o "$CURRENT" = "none" -o "$CURRENT" = "None" ]; then
        log "HIGH priority queue DRAINED. Moving to MEDIUM tasks."
        break
    fi

    log "  Queue: $QUEUE_COUNT tasks remaining. Current: $CURRENT"
    sleep 60
done

# ── Phase 2: Promote MEDIUM tasks + launch parallel agents ─────────────────
log "PHASE 2: Promoting MEDIUM priority tasks..."

# Move medium tasks to main queue
for f in "$TASKS_DIR"/medium/*.md; do
    [ -f "$f" ] && cp "$f" "$TASKS_DIR/" && log "  Queued: $(basename $f)"
done

# Start YOLO loop for sequential Shopify tasks (rate-limit sensitive)
curl -s -u "$AUTH" -X POST "$BASE/api/start" > /dev/null 2>&1
log "  YOLO loop started for MEDIUM queue"

# Launch parallel subagents for independent tasks that don't touch Shopify API
log "  Launching parallel subagents for non-Shopify medium tasks..."

# Parallel agent 1: Hollywood Hex Extraction (Gemini API, not Shopify)
nohup bash -c "cat '$TASKS_DIR/medium/13_hollywood-hex-extraction.md' | claude --print --allowedTools Bash Read Write Edit Glob Grep WebFetch WebSearch --max-turns 50" > /tmp/yolo-medium-13-hex.log 2>&1 &
log "  Subagent PID $! → Hollywood Hex Extraction"

# Parallel agent 2: Legal Violations Audit (read-only DB + agent health)
nohup bash -c "cat '$TASKS_DIR/medium/15_legal-violations-audit.md' | claude --print --allowedTools Bash Read Write Edit Glob Grep WebFetch WebSearch --max-turns 30" > /tmp/yolo-medium-15-legal.log 2>&1 &
log "  Subagent PID $! → Legal Violations Audit"

# Wait for MEDIUM queue to drain
log "  Waiting for MEDIUM YOLO queue + subagents to complete..."
while true; do
    QUEUE_COUNT=$(curl -s -u "$AUTH" "$BASE/api/queue" 2>/dev/null | python3 -c "import json,sys; print(len(json.load(sys.stdin)))" 2>/dev/null)
    CURRENT=$(echo "$(curl -s -u "$AUTH" "$BASE/api/status" 2>/dev/null)" | python3 -c "import json,sys; print(json.load(sys.stdin).get('currentTask','none'))" 2>/dev/null)

    if [ "$QUEUE_COUNT" = "0" ] && [ "$CURRENT" = "null" -o "$CURRENT" = "none" -o "$CURRENT" = "None" ]; then
        log "MEDIUM priority queue DRAINED."
        break
    fi

    log "  Queue: $QUEUE_COUNT tasks remaining. Current: $CURRENT"
    sleep 60
done

# ── Phase 3: Promote LOW tasks + launch parallel agents ────────────────────
log "PHASE 3: Promoting LOW priority tasks..."

# Move low tasks to main queue
for f in "$TASKS_DIR"/low/*.md; do
    [ -f "$f" ] && cp "$f" "$TASKS_DIR/" && log "  Queued: $(basename $f)"
done

# Start YOLO loop
curl -s -u "$AUTH" -X POST "$BASE/api/start" > /dev/null 2>&1
log "  YOLO loop started for LOW queue"

# Launch parallel subagents for quick independent low tasks
log "  Launching parallel subagents for quick LOW tasks..."

# Parallel: Phoebe fix (trivial — mkdir + restart)
nohup bash -c "cat '$TASKS_DIR/low/20_phoebe-videos-dir-fix.md' | claude --print --allowedTools Bash Read Write Edit Glob Grep --max-turns 15" > /tmp/yolo-low-20-phoebe.log 2>&1 &
log "  Subagent PID $! → Phoebe Fix"

# Parallel: Cron audit (read-only)
nohup bash -c "cat '$TASKS_DIR/low/22_cron-audit-cleanup.md' | claude --print --allowedTools Bash Read Write Edit Glob Grep --max-turns 20" > /tmp/yolo-low-22-cron.log 2>&1 &
log "  Subagent PID $! → Cron Audit"

# Parallel: Knoll investigation (read-only web check)
nohup bash -c "cat '$TASKS_DIR/low/21_knoll-maharam-scraper-investigate.md' | claude --print --allowedTools Bash Read Write Edit Glob Grep WebFetch --max-turns 20" > /tmp/yolo-low-21-knoll.log 2>&1 &
log "  Subagent PID $! → Knoll Investigation"

# Wait for LOW queue
while true; do
    QUEUE_COUNT=$(curl -s -u "$AUTH" "$BASE/api/queue" 2>/dev/null | python3 -c "import json,sys; print(len(json.load(sys.stdin)))" 2>/dev/null)
    CURRENT=$(echo "$(curl -s -u "$AUTH" "$BASE/api/status" 2>/dev/null)" | python3 -c "import json,sys; print(json.load(sys.stdin).get('currentTask','none'))" 2>/dev/null)

    if [ "$QUEUE_COUNT" = "0" ] && [ "$CURRENT" = "null" -o "$CURRENT" = "none" -o "$CURRENT" = "None" ]; then
        log "LOW priority queue DRAINED."
        break
    fi

    log "  Queue: $QUEUE_COUNT tasks remaining. Current: $CURRENT"
    sleep 60
done

# ── Summary ─────────────────────────────────────────────────────────────────
log "============================================"
log "ALL PHASES COMPLETE"
log "============================================"
log "Check results:"
log "  YOLO history: curl -u admin:DWSecure2024! http://localhost:9670/api/history"
log "  Parallel logs: /tmp/yolo-medium-*.log, /tmp/yolo-low-*.log"
log "  Dashboard: http://45.61.58.125:9670/"