#!/bin/bash
# Sanguo Quant 停止所有Agent监控脚本
# 文件位置：项目根目录/stop_all_agents.sh

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo "========================================="
echo "🛑 Sanguo Quant 停止所有Agent监控"
echo "时间: $(date)"
echo "========================================="
echo ""

# 项目根目录
PROJECT_DIR="/Users/chufeng/.openclaw/agents/main/workspace/projects/sanguo_quant_live"
cd "$PROJECT_DIR" || {
    echo -e "${RED}❌ 项目目录不存在: $PROJECT_DIR${NC}"
    exit 1
}

# 所有Agent列表
AGENTS="pangtong zhangfei guanyu zhaoyun simayi jiangwei"

# 计数
STOPPED=0
FAILED=0

echo "📋 Agent列表: $AGENTS"
echo ""

for agent in $AGENTS; do
    echo -n "🔄 正在停止 $agent... "
    
    # 查找进程
    PIDS=$(ps aux | grep "agent_monitor_fixed.sh $agent" | grep -v grep | awk '{print $2}')
    
    if [ -z "$PIDS" ]; then
        echo -e "${YELLOW}⚠️  $agent 没有运行${NC}"
        continue
    fi
    
    # 杀死进程
    for pid in $PIDS; do
        kill "$pid" 2>/dev/null
        if [ $? -eq 0 ]; then
            echo -e "${GREEN}✅ $agent 已停止 (PID: $pid)${NC}"
            STOPPED=$((STOPPED + 1))
        else
            echo -e "${RED}❌ $agent 停止失败${NC}"
            FAILED=$((FAILED + 1))
        fi
    done
done

echo ""
echo "========================================="
echo "✅ 停止完成"
echo "📊 统计:"
echo "  成功停止: $STOPPED 个"
echo "  停止失败: $FAILED 个"
echo "========================================="
