Skip to content

Feature: Add codegraph export command#630

Open
Michael2150 wants to merge 1 commit into
colbymchenry:mainfrom
Michael2150:feat/graph-export
Open

Feature: Add codegraph export command#630
Michael2150 wants to merge 1 commit into
colbymchenry:mainfrom
Michael2150:feat/graph-export

Conversation

@Michael2150
Copy link
Copy Markdown

Add codegraph export command

Adds a new codegraph export CLI command that lets you dump your indexed graph to a file for visualization or further processing.

What's in this PR

  • Four output formats: DOT (Graphviz), Mermaid flowchart, Cytoscape JSON, and a self-contained interactive HTML page (no server needed — just open it in a browser).
  • Filtering options: --kind to pick specific node types, --edge-kind to filter relationship types, --all-kinds to include everything, and --limit to cap node count (defaults to 1000 with a warning when truncated).
  • HTML viewer includes a sidebar with per-kind checkboxes, a live search, hover tooltips, and neighbourhood highlight on click — useful for quickly exploring a codebase's structure visually.
  • Two new public API methods on CodeGraph: getAllNodes() and findEdgesBetweenNodes(), which the exporter uses internally but are also handy for anyone embedding the library.

Why

There was no way to get the graph data out of CodeGraph in a format you could hand to an external tool. DOT and Mermaid cover the "render it as a diagram" use case; Cytoscape JSON covers the "load it into my own viz tool" case; and the HTML format is the zero-friction option when you just want to poke around without setting anything up.

Usage

# Interactive HTML — open in browser
codegraph export -f html -o graph.html

# Graphviz
codegraph export -f dot | dot -Tsvg > graph.svg

# Only show functions and methods
codegraph export -f dot --kind function,method -o graph.dot

# Raise the node cap
codegraph export -f cytoscape --limit 5000 -o graph.json

Introduce a new `codegraph export` CLI command and export pipeline. The CLI supports formats: dot, mermaid, cytoscape (JSON), and self-contained interactive HTML; options include --format, --output, --kind, --edge-kind, --all-kinds, --limit, and --title. The command validates formats/kinds, deduplicates nodes, applies a node limit (with warning), filters edges to the exported node set, and writes to stdout or a file.

Add a new src/export/index.ts that implements the formatters (DOT, Mermaid, Cytoscape JSON, HTML with a Cytoscape viewer), colour palette, escaping helpers, and edge bounding. Update src/index.ts to expose getAllNodes() and findEdgesBetweenNodes() used by the exporter. Update CHANGELOG.md to document the new feature.
@Michael2150 Michael2150 changed the title Feat/Add codegraph export command Feature: Add codegraph export command Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant