"""把 PAM 部署 Skill 文档加载为简化策略对象。""" from __future__ import annotations from pathlib import Path from .constants import ( ALLOWED_ACTIONS, DEFAULT_PARAMS, GLOBAL_ACTION_SEQUENCE, IP_ACTION_SEQUENCE, REQUIRED_PARAMS, ) from .models import SkillPolicy def load_skill_policy(path: str | Path) -> SkillPolicy: """读取 Skill markdown 头部信息,并填充 action/参数策略。""" skill_path = Path(path) text = skill_path.read_text(encoding="utf-8") name = "pam-auto-deply" description = "" if text.startswith("---"): parts = text.split("---", 2) if len(parts) >= 3: for line in parts[1].splitlines(): if line.startswith("name:"): name = line.split(":", 1)[1].strip() elif line.startswith("description:"): description = line.split(":", 1)[1].strip() return SkillPolicy( name=name, source_path=str(skill_path), description=description, allowed_actions=ALLOWED_ACTIONS, required_params=REQUIRED_PARAMS, optional_params=DEFAULT_PARAMS.copy(), action_sequence=GLOBAL_ACTION_SEQUENCE, ip_action_sequence=IP_ACTION_SEQUENCE, )