#!/bin/bash
# Demo script showing how to use Qwen consultation hook

set -euo pipefail

echo "====================================="
echo "  Qwen Consultation Hook Demo"
echo "====================================="
echo ""

# Step 1: Show current mode
echo "1. Current QWEN_CONSULT_MODE: ${QWEN_CONSULT_MODE:-off (default)}"
echo ""

# Step 2: Enable delegate mode
echo "2. Enabling delegate mode..."
export QWEN_CONSULT_MODE=delegate
echo "   QWEN_CONSULT_MODE is now: $QWEN_CONSULT_MODE"
echo ""

# Step 3: Trigger consultation with delegate keyword
echo "3. Triggering Qwen consultation..."
echo "   Prompt: 'please consult qwen for advice on bash scripting best practices'"
echo ""

# Clear previous log
> ~/.claude/qwen-output.log

# Trigger the hook
echo '{"prompt": "please consult qwen for advice on bash scripting best practices"}' | \
    /home/uroma/.claude/hooks/qwen-consult.sh 2>&1

# Wait a moment for Qwen to start
sleep 2

# Step 4: Show Qwen is running
echo "4. Checking if Qwen is running..."
if [[ -f ~/.claude/qwen.lock ]]; then
    PID=$(cat ~/.claude/qwen.lock)
    if kill -0 "$PID" 2>/dev/null; then
        echo "   ✓ Qwen is running (PID: $PID)"
    else
        echo "   ✗ Qwen process not found"
    fi
else
    echo "   ✗ Qwen lock file not found"
fi
echo ""

# Step 5: Wait for output and show it
echo "5. Waiting for Qwen's response (10 seconds)..."
sleep 10

echo ""
echo "====================================="
echo "  Qwen's Response:"
echo "====================================="
tail -n +4 ~/.claude/qwen-output.log

echo ""
echo "====================================="
echo "  Monitoring Commands:"
echo "====================================="
echo "View output in real-time:"
echo "  tail -f ~/.claude/qwen-output.log"
echo ""
echo "Check if Qwen is running:"
echo "  ps aux | grep qwen"
echo ""
echo "Stop Qwen:"
echo "  kill \$(cat ~/.claude/qwen.lock)"
echo ""
