feat(agent-runtime): unify agent bindings and sessions
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -176,6 +177,41 @@ def clean_config(config: dict[str, Any]) -> dict[str, Any]:
|
||||
return {key: value for key, value in config.items() if not key.startswith("_")}
|
||||
|
||||
|
||||
def config_from_binding(root: Path, selector: str) -> dict[str, Any]:
|
||||
"""Materialize a common agent-runtime tester binding for legacy local.yaml."""
|
||||
|
||||
runtime_path = Path(__file__).resolve().parents[2] / "skills" / "agent-runtime" / "scripts" / "agent.py"
|
||||
if not runtime_path.is_file():
|
||||
raise RuntimeError(f"找不到共享 agent-runtime: {runtime_path}")
|
||||
spec = importlib.util.spec_from_file_location("pouch_agent_runtime", runtime_path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise RuntimeError(f"无法加载共享 agent-runtime: {runtime_path}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
try:
|
||||
common = module.load_config(root)
|
||||
value = module.binding(common, selector)
|
||||
except (ValueError, OSError) as exc:
|
||||
raise RuntimeError(str(exc)) from exc
|
||||
if value.get("adapter") != "tester":
|
||||
raise RuntimeError(f"binding {selector} 的 adapter 不是 tester")
|
||||
location = value["location"]
|
||||
profile = value["profile"]
|
||||
return {
|
||||
"environment": "" if location.get("environment") == "local" else str(location.get("environment") or ""),
|
||||
"host": str(location.get("host") or "local"),
|
||||
"project": str(location.get("project") or ""),
|
||||
"path": str(location.get("path") or ""),
|
||||
"role": "test",
|
||||
"cli": str(profile.get("cli") or "codex"),
|
||||
"tier": str(profile.get("tier") or "standard"),
|
||||
"model": profile.get("model"),
|
||||
"reasoningEffort": profile.get("reasoningEffort"),
|
||||
"permissionMode": str(profile.get("permissionMode") or "workspace-write"),
|
||||
"_source": f"binding:{selector}",
|
||||
}
|
||||
|
||||
|
||||
def write_local(root: Path, config: dict[str, Any]) -> tuple[Path, dict[str, Any]]:
|
||||
path = root / ".pouch" / "tester" / "local.yaml"
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -233,16 +269,21 @@ def main(argv: list[str] | None = None) -> int:
|
||||
source = parser.add_mutually_exclusive_group(required=True)
|
||||
source.add_argument("--terminal", help="Orca terminal handle")
|
||||
source.add_argument("--project", help="Orca project id、名称或路径")
|
||||
source.add_argument("--binding", help="common agent.yaml 中的 tester.<name> binding")
|
||||
parser.add_argument("--path", help="项目有多个 worktree 时按目标机器上的绝对路径消歧")
|
||||
parser.add_argument("--environment", help="限定 Orca environment")
|
||||
parser.add_argument("--write", action="store_true", help="写入 .pouch/tester/local.yaml")
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
config = (
|
||||
config_from_terminal(args.terminal, args.environment)
|
||||
if args.terminal
|
||||
else config_from_project(args.project, args.environment, args.path)
|
||||
)
|
||||
root = Path(args.root).resolve()
|
||||
if args.binding:
|
||||
config = config_from_binding(root, args.binding)
|
||||
else:
|
||||
config = (
|
||||
config_from_terminal(args.terminal, args.environment)
|
||||
if args.terminal
|
||||
else config_from_project(args.project, args.environment, args.path)
|
||||
)
|
||||
if args.write:
|
||||
path, saved_agent = write_local(Path(args.root).resolve(), config)
|
||||
config = {**config, **saved_agent}
|
||||
|
||||
Reference in New Issue
Block a user