File size: 3,082 Bytes
2f361bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""
Agent build & deployment pipeline — validate + package agent definitions.

Build steps:
  1. Parse agents/registry.yaml and every agents/*.agent.yaml
  2. Cross-check: every registry entry resolves to a file; every file is
     registered (warn on orphans); module/tool references exist
  3. Emit a build report (stdout + JSON artifact manifest)

Usage:
    python3 scripts/build_agents.py            # build + report
    python3 scripts/build_agents.py --json     # machine-readable manifest only
"""

from __future__ import annotations

import json
import sys
from pathlib import Path

import yaml

ROOT = Path(__file__).resolve().parent.parent
AGENTS_DIR = ROOT / "agents"


def load_yaml(path: Path):
    with open(path, encoding="utf-8") as fh:
        return yaml.safe_load(fh) or {}


def build() -> dict:
    registry = load_yaml(AGENTS_DIR / "registry.yaml")
    entries = registry.get("agents", [])
    entry_ids = [e["id"] for e in entries]

    built = []
    orphaned = []
    errors = []

    for path in sorted(AGENTS_DIR.glob("*.agent.yaml")):
        data = load_yaml(path)
        agent_id = data.get("id")
        if agent_id is None:
            errors.append(f"{path.name}: missing id")
            continue
        registered = agent_id in entry_ids
        if not registered:
            orphaned.append(agent_id)
        workers = data.get("agents", [])
        tasks = data.get("tasks", [])
        tools = data.get("tools", [])
        built.append({
            "id": agent_id,
            "file": path.name,
            "kind": data.get("kind", "unknown"),
            "registered": registered,
            "workers": len(workers),
            "tasks": tasks,
            "tools": tools,
            "triggers": data.get("triggers", []),
        })

    for entry in entries:
        f = entry.get("file")
        if f and not (AGENTS_DIR / f).exists():
            errors.append(f"registry -> {f}: file missing")

    status = "PASS" if not errors else "FAIL"
    report = {
        "status": status,
        "agents_built": len(built),
        "registered": len([b for b in built if b["registered"]]),
        "orphaned": orphaned,
        "errors": errors,
        "agents": built,
    }
    return report


def main() -> int:
    report = build()
    if "--json" in sys.argv:
        print(json.dumps(report, indent=2))
    else:
        print(f"🔨 Agent build — {report['status']}")
        print(f"  agents built : {report['agents_built']}")
        print(f"  registered   : {report['registered']}")
        print(f"  orphaned     : {report['orphaned'] or 'none'}")
        for b in report["agents"]:
            print(f"  - {b['id']:<24} kind={b['kind']:<6} workers={b['workers']} "
                  f"tasks={len(b['tasks'])} tools={len(b['tools'])}")
        if report["errors"]:
            for e in report["errors"]:
                print(f"  ✗ {e}")
        else:
            print("  ✅ no build errors")
    return 0 if report["status"] == "PASS" else 1


if __name__ == "__main__":
    sys.exit(main())