Skip to content

feat(cli): add 'dimos graph' subcommand#2213

Open
jeff-hykin wants to merge 26 commits into
mainfrom
jeff/feat/dimos-graph
Open

feat(cli): add 'dimos graph' subcommand#2213
jeff-hykin wants to merge 26 commits into
mainfrom
jeff/feat/dimos-graph

Conversation

@jeff-hykin
Copy link
Copy Markdown
Member

@jeff-hykin jeff-hykin commented May 21, 2026

Adds dimos graph <python_file> to render Blueprint flowchart diagrams as interactive Mermaid in the browser, designed for debugging.

Example

# Open an interactive Mermaid view in the browser
dimos graph dimos/manipulation/blueprints.py

# Print Mermaid markdown to stdout instead
dimos graph dimos/manipulation/blueprints.py --markdown
Screenshot 2026-05-30 at 5 54 06 PM

Options

  • --no-disconnected — hide disconnected streams
  • --markdown — print Mermaid markdown to stdout instead of serving
  • --port — pick HTTP port (default: random)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 79.24945% with 94 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
dimos/utils/cli/graph.py 64.24% 51 Missing and 8 partials ⚠️
dimos/core/introspection/mermaid.py 84.82% 7 Missing and 15 partials ⚠️
dimos/robot/cli/dimos.py 27.27% 8 Missing ⚠️
dimos/utils/cli/test_graph.py 94.04% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@jeff-hykin jeff-hykin marked this pull request as ready for review May 21, 2026 19:35
@jeff-hykin jeff-hykin enabled auto-merge (squash) May 21, 2026 19:35
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

Adds dimos graph <python_file> — a developer debugging tool that introspects Blueprint module-level globals, renders them as Mermaid flowcharts, and either serves an interactive pan/zoom browser view, writes an HTML file, or prints raw Mermaid markdown. The implementation also surfaces connection conflicts and likely typos.

  • dimos/core/introspection/mermaid.py — new Mermaid renderer; sanitize_id correctly escapes all non-alphanumeric characters.
  • dimos/utils/cli/graph.py — blueprint loader emits diagnostics to stderr so stdout stays clean for --markdown piping.
  • dimos/utils/cli/graph.html.jinja — interactive viewer with tab, pan, zoom, and warning overlays.

Confidence Score: 5/5

Safe to merge — this is a new, self-contained developer CLI tool with no changes to existing production paths.

All changed code is additive: new CLI subcommand, new Mermaid renderer, new HTML template, and new tests. The existing codebase is not modified beyond wiring the subcommand into dimos.py.

No files require special attention.

Important Files Changed

Filename Overview
dimos/core/introspection/mermaid.py New Mermaid renderer for Blueprint flowcharts; correctly handles producers/consumers, disconnected streams, edge/node coloring and theming.
dimos/utils/cli/graph.py Main CLI backend. Minor dead code: per_bp_node_colors is accumulated but never passed to the template render call.
dimos/utils/cli/graph.html.jinja Jinja template for the interactive graph viewer; inlines mermaid.js without escaping </script> which is safe today but fragile against future mermaid versions.
dimos/robot/cli/dimos.py Adds the graph Typer subcommand; clean dispatch to print_markdown, save_html, or serve_graph.
dimos/utils/cli/test_graph.py Snapshot test for HTML output and round-trip HTTP serve using write-on-first-run / fail-on-mismatch pattern.
dimos/utils/cli/test_graph_blueprints.py Blueprint fixtures exercising typo-detection and conflict-warning paths.

Reviews (17): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

Comment thread dimos/utils/cli/graph.py Outdated
Comment thread dimos/utils/cli/graph.py
Comment thread dimos/utils/cli/graph.py Outdated
Comment thread dimos/utils/cli/graph.py Outdated
Non-root requests (e.g. /favicon.ico) now return 204 instead of
terminating the single-request server with the HTML payload.
Comment thread dimos/utils/cli/graph.py Outdated
Route the diagnostic 'Found N blueprint(s)' message to stderr so piping
'--markdown' output to a file doesn't get the message injected into the
markdown stream.
jeff-hykin added a commit that referenced this pull request May 22, 2026
Records the 5 greptile review comments on jeff/feat/dimos-graph:
- 3283875847, 3283875929, 3284014771: already addressed in upstream
  commits 482d7ad, f87845e, ddb6856
- 3283876031: fixed in autofix commit f62f2f5 (_mermaid_id)
- 3283875688: skipped (JS refactor in embedded template, exceeds easy
  threshold; symptom is mild)
@jeff-hykin jeff-hykin force-pushed the jeff/feat/dimos-graph branch from 6c2ea2c to f87845e Compare May 22, 2026 08:17
Comment thread dimos/utils/cli/graph.py
@leshy
Copy link
Copy Markdown
Member

leshy commented May 22, 2026

we already have a very detailed renderer for dimos blueprints used in our documentation, as well as rerun blueprint graph view tab

https://github.com/dimensionalOS/dimos/blob/main/docs/usage/modules.md

is there a reason to introduce a new one?

from dimos.core.introspection.svg import to_svg
from dimos.robot.unitree_webrtc.unitree_go2_blueprints import agentic

to_svg(agentic, "assets/go2_agentic.svg")

I don't super mind this if someone prefers to above, but can add to core.introspection.mermaid perhaps

jeff-hykin added a commit that referenced this pull request May 22, 2026
…, leshy)

Adds an entry for greptile P1 review #3286995045 (relative-imports fix
above), records leshy's design question about merging this renderer with
core.introspection.svg as a discussion-only entry, and standardizes the
existing _mermaid_id entry on a full 40-char commit SHA.
Comment thread dimos/utils/cli/graph.py Outdated
mustafab0
mustafab0 previously approved these changes May 23, 2026
jeff-hykin added a commit that referenced this pull request May 23, 2026
Record pr_responses.yaml entry for mustafab0's 2026-05-23 review comment on
PR #2213 (#3292493576) suggesting the 242-line embedded HTML f-string in
_build_html become a separate graph.html file. Marked skipped — the choice
of templating mechanism (str.format vs string.Template vs marker .replace
vs Jinja2) is an architectural call that needs Jeff's input, and there are
no unit tests covering _build_html so a silent rendering regression would
not be caught by CI.
Stream names with characters like [ ] ( ) . would produce invalid
Mermaid syntax and break diagram rendering.
@jeff-hykin
Copy link
Copy Markdown
Member Author

jeff-hykin commented May 30, 2026

we already have a very detailed renderer for dimos blueprints used in our documentation, as well as rerun blueprint graph view tab

@leshy

Yeah I know. For context, I never planned to PR this, I've been using it since February - Mustafa and Andrew just saw me using it and asked if I could add it to dimos.

I don't find the existing tools useful for debugging blueprint streams, so I end up using this a lot.

Main differences:

  • Doesn't hide anything (need to see disconnected edges and show all modules for debugging)
  • Easy one-off invoke; no blueprint/rerun launching, no writing python code to import a blueprint, just cli command pointed at a python file
  • Lighter weight (e.g. no graphviz)
  • Different layout (each node owns its output)

…nt.mermaid

Move render_mermaid, themes, and color logic out of the CLI module into
a reusable location. Add ocean/ember/forest/light themes with per-theme
background colors, wire --theme through the CLI, and fix stream
resolution for files using `from __future__ import annotations`.
…ering

Snapshot test builds HTML from a complex blueprint with dangling streams,
serves it over HTTP, and compares to a cached file. Snapshot auto-updates
on mismatch so the next run passes.
…rmaid_blueprint for snapshot

- Add "Possible Input Fighting" warning box showing topics with 2+ publishers
- Color conflict items to match diagram node/stream colors
- Module names shown as rounded pills with background color, streams as bordered boxes
- Separator lines between multiple conflicts
- Return node_color_map from render_mermaid for reuse
- Simplify test to load blueprints from test_mermaid_blueprint.py directly
- Bundle mermaid.min.js inline so generated HTML works without network
- Track mermaid.min.js with Git LFS
- Detect possible typos: dangling In/Out streams with matching types
  and Levenshtein distance <= 2 (e.g. color_img vs color_image)
- Normalize mermaid JS out of snapshot to keep it small
@jeff-hykin jeff-hykin force-pushed the jeff/feat/dimos-graph branch from c425955 to 61c8a5f Compare May 30, 2026 23:50
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.

3 participants