Spaces:
Sleeping
Sleeping
File size: 830 Bytes
eda351c | 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 | """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)
|