#!/usr/bin/env python3
"""
备份指定文件夹下面的Agent所有配置文件到指定版本目录。
"""

import argparse
import os
import shutil


def backup_md_dir(
    version: str,
    dir_path: str = "/home/node/.openclaw/workspace-knowledge",
) -> int:
    backup_dir = os.path.join(dir_path, f"backup_v{version}")
    if not os.path.exists(backup_dir):
        os.makedirs(backup_dir)
    for file in os.listdir(dir_path):
        if file.endswith(".md"):
            shutil.copy(os.path.join(dir_path, file), os.path.join(backup_dir, file))
    return backup_dir


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="备份Agent配置文件")
    parser.add_argument("--current-version",  help="当前的版本号")
    parser.add_argument(
        "--dir",
        default="/home/node/.openclaw/workspace-knowledge",
        help="要处理的目录路径（仅该目录下的 .md，不含子目录）",
    )
    args = parser.parse_args()
    backup_dir = backup_md_dir(args.current_version, args.dir)
    print(f"备份成功: {backup_dir}")
    exit(0)
