-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathgenerate_agent_catalog.py
More file actions
50 lines (38 loc) · 1.46 KB
/
generate_agent_catalog.py
File metadata and controls
50 lines (38 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""Validate or export the agents catalog by scanning catalog package folders."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from catalog_index import build_agent_manifest, collect_agents
ROOT = Path(__file__).resolve().parents[1]
MANIFEST_PATH = ROOT / "artifacts" / "agent-catalog.json"
def write_manifest(output_path: Path, agents: list[dict[str, object]]) -> None:
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(json.dumps(build_agent_manifest(agents), indent=2, sort_keys=False) + "\n", encoding="utf-8")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--output",
type=Path,
default=MANIFEST_PATH,
help="Write a transient exported manifest to this path.",
)
parser.add_argument(
"--validate-only",
action="store_true",
help="Validate agent metadata without writing an output file.",
)
return parser.parse_args()
def main() -> int:
args = parse_args()
agents = collect_agents()
if args.validate_only:
print(f"Agent metadata is valid for {len(agents)} agents.")
return 0
output_path = args.output.resolve()
write_manifest(output_path, agents)
print(f"Generated agent catalog for {len(agents)} agents at {output_path}.")
return 0
if __name__ == "__main__":
raise SystemExit(main())