52 lines
1.8 KiB
Python
Executable File
52 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Validate an optional ACK .pouch/ack/agents.yaml routing override."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from validate_tasks import load_document, validate_with_schema
|
|
from worker_profiles import validate_orchestration
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description="校验 ACK agents.yaml 结构")
|
|
parser.add_argument("agents", nargs="?", default="agents.yaml", help="agents.yaml 路径")
|
|
parser.add_argument("--schema", help="agents.schema.json 路径(默认自动探测)")
|
|
args = parser.parse_args(argv)
|
|
|
|
agents_path = Path(args.agents)
|
|
if not agents_path.is_file() or agents_path.is_symlink():
|
|
sys.stderr.write(f"agents.yaml 必须是普通文件且不能是 symlink: {agents_path}\n")
|
|
return 2
|
|
|
|
data = load_document(agents_path)
|
|
schema_path = Path(args.schema) if args.schema else (
|
|
Path(__file__).resolve().parent.parent / "templates" / "agents.schema.json"
|
|
)
|
|
errors = validate_orchestration(data, where="agents.yaml")
|
|
mode = "内置语义规则"
|
|
try:
|
|
import jsonschema # type: ignore # noqa: F401
|
|
|
|
if schema_path.is_file():
|
|
errors = validate_with_schema(data, schema_path) + errors
|
|
mode = f"schema ({schema_path.name}) + 内置语义规则"
|
|
except ImportError:
|
|
pass
|
|
|
|
if errors:
|
|
sys.stderr.write(f"agents.yaml 校验失败({mode}),共 {len(errors)} 项:\n")
|
|
for error in dict.fromkeys(errors):
|
|
sys.stderr.write(f" - {error}\n")
|
|
return 1
|
|
|
|
sys.stdout.write(f"agents.yaml 校验通过({mode}):{agents_path}\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|