"""
运行时工具。

统一处理：
- Python 解释器选择
- task_registry 占位符替换
"""

from __future__ import annotations

from pathlib import Path

from config.settings import OPENCLAW_BASE, PYTHON_BIN, SKILL_BASE


def expand_command_vars(text: str) -> str:
    expanded = (
        text
        .replace("{OPENCLAW_BASE}", str(OPENCLAW_BASE))
        .replace("{SKILL_BASE}", str(SKILL_BASE))
        .replace("{PYTHON_BIN}", PYTHON_BIN)
    )
    if expanded.startswith("python3 "):
        return expanded.replace("python3 ", f"{PYTHON_BIN} ", 1)
    if expanded.startswith("python "):
        return expanded.replace("python ", f"{PYTHON_BIN} ", 1)
    return expanded


def build_python_command(script: str | Path, *args: str) -> list[str]:
    return [PYTHON_BIN, str(script), *[str(arg) for arg in args]]
