#!/bin/bash
# Sanguo Quant 批量启动所有Agent监控脚本
# 每个Agent启动一个监控进程
# 文件位置：项目根目录/start_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"

# 计数
STARTED=0
FAILED=0

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

for agent in $AGENTS; do
    echo -n "🔄 正在启动 $agent... "
    
    # 检查是否已经运行
    if ps aux | grep "agent_monitor_fixed.sh $agent" | grep -v grep | grep -q .; then
        echo -e "${YELLOW}⚠️  $agent 已经在运行，跳过${NC}"
        STARTED=$((STARTED + 1))
        continue
    fi
    
    # 启动Agent
    nohup ./management/workflow/scripts/agent_monitor_fixed.sh "$agent" >> "${agent}_monitor.log" 2>&1 &
    
    # 等待一下
    sleep 1
    
    # 检查是否启动成功
    if ps aux | grep "agent_monitor_fixed.sh $agent" | grep -v grep | grep -q .; then
        echo -e "${GREEN}✅ $agent 启动成功${NC}"
        STARTED=$((STARTED + 1))
    else
        echo -e "${RED}❌ $agent 启动失败${NC}"
        FAILED=$((FAILED + 1))
    fi
done

echo ""
echo "========================================="
echo "✅ 启动完成"
echo "📊 统计:"
echo "  成功启动: $STARTED 个"
echo "  启动失败: $FAILED 个"
echo "========================================="
echo ""
echo "📝 查看日志:"
echo "  tail -f <agent>_monitor.log"
echo "  ps aux | grep agent_monitor_fixed"
echo " 检查进程"
echo "========================================="
