74 lines
2.7 KiB
Python
Executable File
74 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Generate a maintainable Mermaid dependency graph from manifest.json."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from component_registry import build_manifest
|
|
|
|
|
|
def node_id(prefix: str, name: str) -> str:
|
|
return prefix + "_" + name.replace("-", "_")
|
|
|
|
|
|
def render(root: Path) -> str:
|
|
manifest = build_manifest(root)
|
|
lines = [
|
|
"# AG Kit Dependency Graph",
|
|
"",
|
|
"> Generated by `.agents/scripts/dependency_graph.py`. Do not edit manually.",
|
|
"",
|
|
f"Kit version: `{manifest['kitVersion']}` · {len(manifest['agents'])} agents · {len(manifest['skills'])} skills · {len(manifest['workflows'])} workflows",
|
|
"",
|
|
"```mermaid",
|
|
"flowchart LR",
|
|
" subgraph Workflows",
|
|
]
|
|
for name in manifest["workflows"]:
|
|
lines.append(f' {node_id("W", name)}["/{name}"]')
|
|
lines.extend([" end", " subgraph Agents"])
|
|
for name in manifest["agents"]:
|
|
lines.append(f' {node_id("A", name)}["{name}"]')
|
|
lines.extend([" end", " subgraph Skills"])
|
|
for name in manifest["skills"]:
|
|
lines.append(f' {node_id("S", name)}["{name}"]')
|
|
lines.append(" end")
|
|
|
|
for workflow, data in manifest["workflows"].items():
|
|
for agent in data["requires"]["agents"]:
|
|
lines.append(f" {node_id('W', workflow)} --> {node_id('A', agent)}")
|
|
for skill in data["requires"]["skills"]:
|
|
lines.append(f" {node_id('W', workflow)} -.-> {node_id('S', skill)}")
|
|
for agent, data in manifest["agents"].items():
|
|
for skill in data["requires"]["skills"]:
|
|
lines.append(f" {node_id('A', agent)} --> {node_id('S', skill)}")
|
|
lines.extend(["```", "", "## Contracts", ""])
|
|
for key, value in manifest["contracts"].items():
|
|
lines.append(f"- `{key}`: `{value}`")
|
|
lines.append("")
|
|
return "\n".join(lines)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Generate AG Kit dependency graph")
|
|
parser.add_argument("path", nargs="?", default=None, help="Path to .agents")
|
|
parser.add_argument("--check", action="store_true", help="Fail when DEPENDENCY_GRAPH.md is stale")
|
|
args = parser.parse_args()
|
|
root = Path(args.path).resolve() if args.path else Path(__file__).resolve().parents[1]
|
|
output = root / "DEPENDENCY_GRAPH.md"
|
|
expected = render(root)
|
|
if args.check:
|
|
if not output.is_file() or output.read_text("utf-8") != expected:
|
|
print("DEPENDENCY_GRAPH.md is stale")
|
|
return 1
|
|
print("Dependency graph is synchronized.")
|
|
return 0
|
|
output.write_text(expected, "utf-8")
|
|
print(f"Wrote {output}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|