Skip to content

tools: add DOT and JSON graph output support#1177

Merged
adulau merged 1 commit intomainfrom
codex/add-output-formats-for-graph-representation
Apr 13, 2026
Merged

tools: add DOT and JSON graph output support#1177
adulau merged 1 commit intomainfrom
codex/add-output-formats-for-graph-representation

Conversation

@adulau
Copy link
Copy Markdown
Member

@adulau adulau commented Apr 13, 2026

Motivation

  • Provide alternative serialized outputs (Graphviz DOT and JSON graph) for easier visualization and integration with other tooling.
  • Avoid duplicating relationship generation logic by building a shared in-memory graph model before serialization.

Description

  • Refactored tools/gen_graphml.py to produce a shared graph model via GraphNode and GraphEdge and a new build_graph() that returns (nodes, edges) instead of writing XML directly.
  • Added GraphNode / GraphEdge dataclasses and new serializers to_dot() (Graphviz DOT) and to_json_graph() (JSON object with nodes and edges).
  • Restored GraphML serialization via a new build_graphml(nodes, edges) function and added a CLI option --output-format with choices graphml, dot, and json-graph (default graphml).
  • Preserved existing behavior for explicit and inferred relationships (--no-existing-relationships, --cross-cluster-matching) and updated the success message to include the selected output format.

Testing

  • Ran python3 tools/gen_graphml.py --help which displayed the updated CLI options and succeeded.
  • Generated GraphML with python3 tools/gen_graphml.py --output /tmp/test.graphml --output-format graphml which wrote the GraphML file successfully.
  • Generated DOT with python3 tools/gen_graphml.py --output /tmp/test.dot --output-format dot --cross-cluster-matching value which wrote the DOT file successfully.
  • Generated JSON graph with python3 tools/gen_graphml.py --output /tmp/test.json --output-format json-graph --no-existing-relationships and validated it with python3 -m json.tool /tmp/test.json, which succeeded.

Codex Task

@adulau adulau merged commit db9a6c9 into main Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant