Download testing/nano_simulation_agents/src/verification_simulation_agents/cli.py from yuhanqin/ut-evaluation: direct link, hf CLI and curl.
- Browser
- Download file 3.46 kB
-
https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/nano_simulation_agents/src/verification_simulation_agents/cli.py
- Command line
-
hf download hf://datasets/yuhanqin/ut-evaluation/testing/nano_simulation_agents/src/verification_simulation_agents/cli.py
-
curl -L -o cli.py https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/nano_simulation_agents/src/verification_simulation_agents/cli.py
3.46 kB
| """Unified command line for verification simulation runtimes.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| from typing import Any | |
| from verification_simulation_agents.common import atomic_json | |
| from verification_simulation_agents.config import RUNTIMES, SimulationConfigError, load_simulation_config | |
| from verification_simulation_agents.nano_runtime import run_nano | |
| from verification_simulation_agents.offline_runtime import run_offline | |
| from verification_simulation_agents.opencode_runtime import run_opencode | |
| from verification_simulation_agents.workspace import WorkspaceError, create_workspace | |
| REQUEST_VERSION = "verification-simulation/request-v1" | |
| def _load_request(path: Path) -> dict[str, Any]: | |
| try: | |
| value = json.loads(Path(path).read_text(encoding="utf-8")) | |
| except (OSError, UnicodeError, json.JSONDecodeError) as error: | |
| raise ValueError(f"cannot load simulation request: {error}") from error | |
| if not isinstance(value, dict) or value.get("schema_version") != REQUEST_VERSION: | |
| raise ValueError(f"simulation request must use {REQUEST_VERSION}") | |
| for key in ("case_id", "case_name", "target_skill_path", "fixture_path"): | |
| if not isinstance(value.get(key), str) or not value[key].strip(): | |
| raise ValueError(f"simulation request field {key} must be a non-empty string") | |
| runtime = value.get("runtime", "offline") | |
| if runtime not in RUNTIMES: | |
| raise ValueError(f"runtime must be one of {RUNTIMES}") | |
| value["runtime"] = runtime | |
| return value | |
| def run(config_path: Path, request_path: Path, output_path: Path) -> tuple[int, Path]: | |
| output = Path(output_path).resolve() | |
| config = load_simulation_config(config_path) | |
| request = _load_request(request_path) | |
| if request["runtime"] not in config.verification.allowed_runtimes: | |
| raise ValueError(f"runtime {request['runtime']!r} is not allowed by nano_agent.toml") | |
| workspace = create_workspace( | |
| Path(request["target_skill_path"]), | |
| Path(request["fixture_path"]), | |
| output, | |
| request["case_name"], | |
| ) | |
| if request["runtime"] == "offline": | |
| result = run_offline(config, request, workspace) | |
| elif request["runtime"] == "opencode": | |
| result = run_opencode(config, request, workspace) | |
| else: | |
| result = run_nano(config, request, workspace) | |
| result_path = output / "simulation-result.json" | |
| atomic_json(result_path, result) | |
| code = 0 if result["status"] == "SUCCEEDED" else (2 if result["status"] == "BLOCKED" else 1) | |
| return code, result_path | |
| def main(argv: list[str] | None = None) -> int: | |
| parser = argparse.ArgumentParser(prog="verification-simulation-agent") | |
| subparsers = parser.add_subparsers(dest="command", required=True) | |
| command = subparsers.add_parser("run", help="run one supervised Skill-verification simulation") | |
| command.add_argument("--config", required=True) | |
| command.add_argument("--request", required=True) | |
| command.add_argument("--output", required=True) | |
| args = parser.parse_args(argv) | |
| try: | |
| code, result = run(Path(args.config), Path(args.request), Path(args.output)) | |
| except (OSError, ValueError, SimulationConfigError, WorkspaceError) as error: | |
| print(f"verification simulation error: {error}", file=sys.stderr) | |
| return 2 | |
| print(result) | |
| return code | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |