feat(mermaid): human/AI-readable node ids instead of MD5 hashes (#210)#213
Conversation
Replace `n_<md5>` node ids with deterministic readable slugs so edge lines can be matched back to nodes by eye (and by an LLM) without cross-referencing the label block. Pairs with #209: JSON for machine joins, readable Mermaid for humans. - internal node → `<file_stem>_<Class>_<method>` (symbol suffix peeled off the module FQN derived from file_path); module/file node → bare stem - phantom/external/raw_call endpoints → readable FQN-tail slug (`_fqn_slug`) - `_IdAllocator` guarantees uniqueness (idempotent per key; `_2`/`_3` suffix on collision, deterministic in call order) and threads through compile/subgraphs/ edges; subgraph ids become `sg_<stem>` - guards: Mermaid reserved words (`end`, `graph`, …) and leading digits get an `id_` prefix so the diagram never breaks - since #209 ships JSON with real FQNs for machine joins, these ids only need to be human-scannable, not joinable — readability wins Before: `n_a62c26d1… -->|CALLS| n_600a3205…` After: `cli_render_graph -->|CALLS| mermaid_MermaidCompiler_compile` `_normalize_id` (md5) removed; tests updated to assert the slug format, collision suffixing, and reserved-word guarding. 846 passed, self-drift unchanged (mermaid is display-only). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request replaces deterministic MD5 hashing for Mermaid node IDs with human-readable slug IDs based on file stems, classes, and methods, and introduces an _IdAllocator to manage unique IDs and handle collisions. Feedback on these changes highlights a potential mismatch between node IDs and module FQNs when custom source roots are configured, as well as a potential IndexError in _guard_token if an empty slug is processed.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…y-slug guard Address gemini review on PR #213: - HIGH: when the ingest root differs from the file path's root (e.g. `cgis ingest ./src` yields ids `cgis.pipeline.X` while file_path derives `src.cgis.pipeline`), the exact-prefix check failed and dropped the `<file_stem>` prefix. `_node_slug` now matches the longest module suffix of the path FQN (extracted into `_internal_node_slug`), keeping the stem regardless of root. Regression test added (red before this fix). - MEDIUM: `_guard_token` guards against an empty slug before indexing `slug[0]` (defensive — all current callers pass sanitized non-empty tokens). 847 passed, mypy strict + ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks @gemini-code-assist — both addressed in
847 passed, mypy strict + ruff + Sonar green. |
|
Thanks for the update, @zaebee. The implementation of |
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the MD5-hash-based ID generation for Mermaid diagrams with a human- and AI-readable slug-based ID system. It introduces several helper functions for token sanitization, guarding reserved words, and generating readable slugs based on file stems, classes, and methods. Additionally, an _IdAllocator class is introduced to handle ID allocation and resolve collisions deterministically. Unit tests have been updated and expanded to verify the new slug generation, collision handling, and edge cases. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.



Closes #210.
What
Replaces
n_<md5>Mermaid node ids with deterministic readable slugs, so edge lines are matchable back to nodes by eye and by an LLM — no more cross-referencing hashes against the label block.Before:
After (real output from
cgis impact MermaidCompiler.compile):Pairs with the just-merged #209: JSON with real FQNs for machine joins, readable Mermaid for humans. Since machines now have the JSON path, the Mermaid ids only need to be human-scannable, not joinable — so readability wins.
How
<file_stem>_<Class>_<method>: the symbol suffix is peeled off the module FQN derived fromfile_path(exact, since internal FQNs are built fromfile_path_to_module_fqn); a module/file node → bare stem.raw_call:endpoints (no module context) → readable FQN-tail slug via_fqn_slug._IdAllocatorguarantees uniqueness: idempotent per key,_2/_3suffix on collision, deterministic in call order. Threaded throughcompile/_render_subgraphs/_render_edges; subgraph ids becomesg_<stem>.end,graph,subgraph, …) and leading digits get anid_prefix so a method literally namedendcan't break the diagram.The scheme (full-path slug) was chosen over a compact initialism because an LLM parses
IngestionPipeline_runfar better thanIP_R(no legend to hold in context).Scope & notes
mermaid.py+test_mermaid.pyonly._normalize_id(md5) removed.docs/architecture/diagrams/pipeline_flow.mermaid, README graph) will refresh to the new ids via the autodoc workflow post-merge — not hand-touched, per our generated-docs-are-owned-by-autodoc policy.Verification
make format && make lint && make type-check && make pytest && make doc-coverageall green — 846 passed, doc-coverage 99.5%, self-drift unchanged (mermaid is display-only). Dogfooded on the self-graph (shown above). New tests cover slug format, module-node stem, collision_2suffixing, reserved-word/leading-digit guarding, and readable phantomraw_callids.🤖 Generated with Claude Code