"""
Agent Presets - Agent 类型预设配置

定义不同类型 Agent 的工具权限和运行参数。
用户可通过 .agent/presets.json 覆盖或添加预设。
"""

from dataclasses import dataclass, field
from typing import Optional, List


@dataclass
class AgentPreset:
    """Agent 预设配置"""

    # 工具权限
    allowed_tools: Optional[List[str]] = None  # None 表示允许全部
    denied_tools: Optional[List[str]] = None   # 黑名单

    # 运行参数
    max_iterations: int = 30
    temperature: Optional[float] = None

    # 描述
    description: Optional[str] = None


# 内置预设
AGENT_PRESETS = {
    "default": AgentPreset(
        allowed_tools=None,
        max_iterations=30,
        description="默认 Agent，拥有全部工具权限",
    ),
    "explore": AgentPreset(
        allowed_tools=["read", "glob", "grep", "list_files"],
        denied_tools=["write", "edit", "bash", "task"],
        max_iterations=15,
        description="探索型 Agent，只读权限，用于代码分析",
    ),
    "analyst": AgentPreset(
        allowed_tools=["read", "glob", "grep", "web_search", "webfetch"],
        denied_tools=["write", "edit", "bash", "task"],
        temperature=0.3,
        max_iterations=25,
        description="分析型 Agent，用于深度分析和研究",
    ),
}


def get_preset(name: str) -> AgentPreset:
    """获取预设配置"""
    if name not in AGENT_PRESETS:
        raise ValueError(f"Unknown preset: {name}. Available: {list(AGENT_PRESETS.keys())}")
    return AGENT_PRESETS[name]


def register_preset(name: str, preset: AgentPreset) -> None:
    """注册自定义预设"""
    AGENT_PRESETS[name] = preset
