Auto-fixes for jeff/feat/dimos-graph#2358
Conversation
DEFAULT_IGNORED_CONNECTIONS/DEFAULT_IGNORED_MODULES were empty module-level mutable sets used only as None-fallback defaults. Assign set() directly in the None branches instead.
render_mermaid reached into _ColorAssigner._assigned from outside the object. Expose an 'assigned' property that returns a copy and use it.
The theme dict has fixed keys with mixed value types (background and mermaid_theme are str; nodes and edges are list[str]). A TypedDict types it precisely and drops the Any, letting graph.py read keys directly.
The valid color themes are fixed (THEMES keys) and were restated in a CLI help string. Define ThemeName once as a Literal and use it for THEMES, DEFAULT_THEME, render_mermaid, the graph.py helpers, and the typer option so typer generates the choice list and validates input. With the Literal, THEMES lookups become direct instead of silently defaulting on a bad name. ThemeName lives in the lightweight introspection.utils so the dimos CLI can use it as an option type without importing the heavy mermaid module at startup (mirrors RerunOpenOption in rerun/constants).
render_mermaid returned a 4-tuple unpacked positionally by callers, which is easy to misorder. Return a MermaidRender NamedTuple and access fields by name in graph.py.
The conflict/typo dicts hold mixed value types (str plus lists), so use dict[str, Any] (consistent with per_bp_conflicts). Likewise the log_message override takes *args: Any.
Producer-conflict detection and the levenshtein-based stream-typo detection are blueprint-graph analysis, not HTML/serving concerns. Move them (and _levenshtein) next to render_mermaid as find_producer_conflicts and find_stream_typos, returning structured findings. graph.py keeps only the color decoration for the template. Output is unchanged.
Importing graph.py ran get_data('mermaid.min.js') (an LFS pull that
blocks) and read/compiled the jinja template at module import. Move both
behind functools.lru_cache loaders called from _build_html, and resolve
the JS via LfsPath so the download happens only when the HTML is built.
The HTML contains non-ASCII characters and the corresponding reads already pass encoding='utf-8'.
serve_graph created an HTTPServer and called handle_request() but never server_close(). Close it in a finally so the socket is released.
Use 'str | None' defaulting to None and check 'is not None' rather than the empty-string sentinel with a truthiness check.
…prints Neither was used in this blueprint-fixture module.
The data/module classes and _build_blueprint duplicated the fixtures in test_graph_blueprints.py (which the test loads from disk) and were never used; their In/Out/Module/Blueprint/autoconnect imports go with them.
Greptile SummaryThis automated cleanup PR refactors the Blueprint graph visualization tooling on the
Confidence Score: 5/5All changes are mechanical refactors with no altered business logic; the one behavioural fix (socket cleanup) reduces a resource leak. Safe to merge. Every changed code path is either a type-annotation tightening, a straight extraction of inline logic into a named function with identical semantics, or a genuine small fix (server_close, UTF-8 encoding, None sentinel). No logic is changed in the conflict/typo detection, the Mermaid renderer, or the HTTP serving path. No files require special attention. test_graph.py retains snapshot testing and HTTP round-trip coverage despite the blueprint definitions moving out of the file. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as dimos CLI (dimos.py)
participant Graph as graph.py
participant Mermaid as mermaid.py
participant Template as graph.html.jinja
CLI->>Graph: serve_graph / save_html / print_markdown (ThemeName)
Graph->>Graph: _load_blueprints(python_file)
Graph->>Mermaid: render_mermaid(bp, theme) → MermaidRender
Mermaid-->>Graph: MermaidRender(code, label_colors, disconnected, node_colors)
Graph->>Mermaid: find_producer_conflicts(bp) → list[ProducerConflict]
Mermaid-->>Graph: list[ProducerConflict]
Graph->>Mermaid: find_stream_typos(bp) → list[StreamTypo]
Mermaid-->>Graph: list[StreamTypo]
Graph->>Graph: _load_template() [lru_cache]
Graph->>Graph: _load_mermaid_js() [lru_cache]
Graph->>Template: render(mermaid_code, conflicts, typos, ...)
Template-->>Graph: HTML string
Graph-->>CLI: HTML / markdown / file
Reviews (2): Last reviewed commit: "chore: remove dead code in test_graph.py" | Re-trigger Greptile |
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
cc1c060 to
b5f87f6
Compare
These are automated fixes. Each fix is a separate commit. Use
git rebase -ito drop any you disagree with.