import json

# 待办任务
backlog_tasks = [
    {
        "id": "2b14df72-c176-4874-b419-8544cbac374b",
        "identifier": "FET-21",
        "title": "[FET-18] E2E测试实现 - 异常流程",
        "assignee_id": "64b26c5e-1823-477c-9c0f-c5c01d599365",
        "assignee_type": "agent",
        "priority": "none",
        "status": "backlog"
    },
    {
        "id": "1547e85e-4b1d-4e08-9663-41dd421b20e9",
        "identifier": "FET-20",
        "title": "[FET-18] E2E测试实现 - 主流程",
        "assignee_id": "8ddccf1d-9ed4-469e-a335-a14d0b72d025",
        "assignee_type": "agent",
        "priority": "none",
        "status": "backlog"
    }
]

# Agent 状态
agent_status = {
    "64b26c5e-1823-477c-9c0f-c5c01d599365": {
        "name": "自动化测试与QA",
        "running": 0,
        "idle_hours": None,
        "status": "完全空闲"
    },
    "8ddccf1d-9ed4-469e-a335-a14d0b72d025": {
        "name": "前端开发专家",
        "running": 0,
        "idle_hours": 4.7,
        "status": "空闲（超过2小时）"
    },
    "34d7c53d-bd70-45a8-bbbb-77dbb1da16b5": {
        "name": "代码评审专家",
        "running": 0,
        "idle_hours": 4.0,
        "status": "空闲（超过2小时）"
    },
    "79fbfb25-e622-4986-9bb9-21efe499274d": {
        "name": "后端开发专家",
        "running": 0,
        "idle_hours": 8.0,
        "status": "空闲（超过2小时）"
    }
}

print("=" * 80)
print("任务分配分析")
print("=" * 80)
print()

for task in backlog_tasks:
    print(f"任务: {task['identifier']} - {task['title']}")
    print(f"  当前状态: {task['status']}")
    print(f"  优先级: {task['priority']}")
    print(f"  已分配给: {agent_status.get(task['assignee_id'], {}).get('name', '未知')}")
    
    agent = agent_status.get(task['assignee_id'])
    if agent:
        print(f"  Agent状态: {agent['status']}")
        print(f"  正在运行任务数: {agent['running']}")
        
        # 判断是否应该激活
        if task['status'] == 'backlog' and agent['running'] == 0:
            if agent['idle_hours'] is None or agent['idle_hours'] > 2:
                print(f"  ✅ 建议操作: 将任务从 backlog 改为 todo，并 mention agent")
            else:
                print(f"  ⏳ 建议操作: Agent 刚完成任务，稍后再分配")
        elif task['status'] == 'todo' and agent['running'] == 0:
            if agent['idle_hours'] and agent['idle_hours'] > 2:
                print(f"  🔔 建议操作: Mention agent 提醒开始工作")
    
    print()

print("=" * 80)
print("分配决策")
print("=" * 80)
print()
print("1. FET-21 (E2E测试 - 异常流程)")
print("   - 分配给: 自动化测试与QA ✅")
print("   - 理由: 完全空闲，任务类型匹配")
print("   - 操作: backlog → todo + mention")
print()
print("2. FET-20 (E2E测试 - 主流程)")
print("   - 分配给: 前端开发专家 ⚠️")
print("   - 理由: 空闲4.7小时，但这是测试任务")
print("   - 问题: 任务类型不匹配（测试任务分配给前端专家）")
print("   - 建议: 重新分配给自动化测试与QA")
print()

