"""清理工具：调用注册层删除工具的项目文件和注册信息

用法：
    uv run python -m tests.cleanup_tool image_stitcher
    uv run python -m tests.cleanup_tool --all
"""

import argparse
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "src"))

from tool_agent.registry.registry import ToolRegistry


def main():
    parser = argparse.ArgumentParser(description="清理工具")
    parser.add_argument("tool_id", nargs="?", help="要清理的 tool_id")
    parser.add_argument("--all", action="store_true", help="清除所有工具")
    args = parser.parse_args()

    import logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s: %(message)s")

    registry = ToolRegistry()

    if args.all:
        result = registry.destroy_all()
        print(f"Cleaned {result['count']} tools")
    elif args.tool_id:
        result = registry.destroy(args.tool_id)
        print(f"Cleaned: {result['cleaned']}")
    else:
        parser.print_help()


if __name__ == "__main__":
    main()
