Spaces:
Sleeping
Sleeping
| """codegraph/serializer.py — JSON serialization helpers for CodeGraph state().""" | |
| import json | |
| from .graph import CodeGraph | |
| def to_dict(graph: CodeGraph) -> dict: | |
| return { | |
| "episode_seed": graph.episode_seed, | |
| "conventions": graph.conventions, | |
| "components": { | |
| name: { | |
| "file": comp.get("file", ""), | |
| "language": comp.get("language", "py"), | |
| "functions": comp.get("functions", [])[:20], | |
| "imports": comp.get("imports", [])[:15], | |
| "conventions": comp.get("conventions", {}), | |
| "created_at_step": comp.get("created_at_step", 0), | |
| } | |
| for name, comp in graph.components.items() | |
| }, | |
| } | |
| def to_json(graph: CodeGraph) -> str: | |
| return json.dumps(to_dict(graph), indent=2) | |