mirror of
https://github.com/budelius/stoz3n-workflow-movies.git
synced 2026-11-21 16:15:55 +00:00
65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Validate this repository's stoz3n workflow manifest without dependencies."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
MANIFEST_PATH = ROOT / "stoz3n-workflow.json"
|
|
NAME_RE = re.compile(r"^[a-z0-9][a-z0-9-]*$")
|
|
DOMAIN_RE = re.compile(r"^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$")
|
|
CAPABILITIES = {"web_search", "web_extract"}
|
|
|
|
|
|
def require(condition: bool, message: str) -> None:
|
|
if not condition:
|
|
raise SystemExit(f"manifest invalid: {message}")
|
|
|
|
|
|
def string_list(data: dict[str, Any], key: str) -> list[str]:
|
|
value = data.get(key)
|
|
require(isinstance(value, list) and value, f"{key} must be a non-empty list")
|
|
require(all(isinstance(item, str) and item for item in value), f"{key} must contain strings")
|
|
return value
|
|
|
|
|
|
def main() -> None:
|
|
data = json.loads(MANIFEST_PATH.read_text(encoding="utf-8"))
|
|
require(isinstance(data, dict), "root must be an object")
|
|
require(data.get("schema_version") == 1, "schema_version must be 1")
|
|
require(isinstance(data.get("name"), str) and NAME_RE.fullmatch(data["name"]), "invalid name")
|
|
require(bool(str(data.get("routing_description", "")).strip()), "routing_description is required")
|
|
require(bool(str(data.get("system_prompt", "")).strip()), "system_prompt is required")
|
|
|
|
for key in ("slash_commands", "mention_handles"):
|
|
values = string_list(data, key)
|
|
require(len(values) == len(set(values)), f"{key} contains duplicates")
|
|
require(all(NAME_RE.fullmatch(value) for value in values), f"{key} contains an invalid name")
|
|
|
|
capabilities = set(string_list(data, "capabilities"))
|
|
require(capabilities <= CAPABILITIES, f"unsupported capabilities: {sorted(capabilities - CAPABILITIES)}")
|
|
|
|
domains = string_list(data, "allowed_domains")
|
|
require(len(domains) <= 30, "allowed_domains exceeds 30 entries")
|
|
require(all(DOMAIN_RE.fullmatch(domain) for domain in domains), "allowed_domains contains an invalid host")
|
|
|
|
require(1 <= int(data.get("max_search_results", 0)) <= 10, "max_search_results must be 1..10")
|
|
require(1 <= int(data.get("max_tool_rounds", 0)) <= 8, "max_tool_rounds must be 1..8")
|
|
require(
|
|
1 <= int(data.get("max_concurrent_invocations", 0)) <= 20,
|
|
"max_concurrent_invocations must be 1..20",
|
|
)
|
|
|
|
canonical = json.dumps(data, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
|
|
digest = hashlib.sha256(canonical.encode()).hexdigest()
|
|
print(f"valid workflow={data['name']} sha256={digest}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|