- 新增 pam_deploy_graph 包,包含 agent、action router、runner、parser 和配置加载能力 - 支持 hybrid_node_mcp 路由策略:PAM_HOME 走脚本 action,PAM_NODE 走 MCP - 新增 fake runner 和 CLI 预演/全局流程验证入口 - 新增路由、输出解析、配置加载、脚本命令构造、Skill 策略加载测试 - 在 README 中记录当前代码骨架、实现进度、使用方式和下一步建议
115 lines
3.1 KiB
Python
115 lines
3.1 KiB
Python
"""Subprocess runner for deploy.sh and deploy.ps1 action calls."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from .models import ActionResult
|
|
from .output_parser import parse_script_result
|
|
|
|
|
|
class ScriptActionRunner:
|
|
def __init__(self, script_base_dir: str | Path = "doc_scripts") -> None:
|
|
self.script_base_dir = Path(script_base_dir)
|
|
|
|
def run(
|
|
self,
|
|
action: str,
|
|
*,
|
|
params: dict[str, Any],
|
|
script_entry: str,
|
|
config_path: str,
|
|
ip: str | None = None,
|
|
hash_code: str | None = None,
|
|
stop_first: bool = False,
|
|
trace_file_path: str | None = None,
|
|
timeout_sec: int | None = None,
|
|
) -> ActionResult:
|
|
command = self.build_command(
|
|
action,
|
|
script_entry=script_entry,
|
|
config_path=config_path,
|
|
ip=ip,
|
|
hash_code=hash_code,
|
|
stop_first=stop_first,
|
|
trace_file_path=trace_file_path,
|
|
)
|
|
completed = subprocess.run(
|
|
command,
|
|
cwd=str(self.script_base_dir),
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=timeout_sec,
|
|
check=False,
|
|
)
|
|
return parse_script_result(
|
|
action=action,
|
|
stdout=completed.stdout,
|
|
stderr=completed.stderr,
|
|
exit_code=completed.returncode,
|
|
backend="script",
|
|
tool_name=script_entry,
|
|
)
|
|
|
|
def build_command(
|
|
self,
|
|
action: str,
|
|
*,
|
|
script_entry: str,
|
|
config_path: str,
|
|
ip: str | None = None,
|
|
hash_code: str | None = None,
|
|
stop_first: bool = False,
|
|
trace_file_path: str | None = None,
|
|
) -> list[str]:
|
|
if script_entry == "deploy.sh":
|
|
command = [
|
|
"bash",
|
|
"./deploy.sh",
|
|
"--config",
|
|
config_path,
|
|
"--action",
|
|
action,
|
|
]
|
|
if ip:
|
|
command.extend(["--ip", ip])
|
|
if hash_code:
|
|
command.extend(["--hash-code", hash_code])
|
|
if stop_first:
|
|
command.append("--stop-first")
|
|
if trace_file_path:
|
|
command.extend(["--trace-file", trace_file_path])
|
|
return command
|
|
|
|
if script_entry == "deploy.ps1":
|
|
command = [
|
|
"powershell",
|
|
"-File",
|
|
".\\deploy.ps1",
|
|
"-ConfigPath",
|
|
config_path,
|
|
"-Action",
|
|
action,
|
|
]
|
|
if ip:
|
|
command.extend(["-Ip", ip])
|
|
if hash_code:
|
|
command.extend(["-HashCode", hash_code])
|
|
if stop_first:
|
|
command.append("-RollbackStopFirst")
|
|
return command
|
|
|
|
raise ValueError(f"Unsupported script entry: {script_entry}")
|
|
|
|
|
|
def select_script_entry(os_name: str | None = None) -> str:
|
|
import platform
|
|
|
|
name = (os_name or platform.system()).lower()
|
|
if "windows" in name:
|
|
return "deploy.ps1"
|
|
return "deploy.sh"
|
|
|