feat(core): port server/tools_viz.py to backend-neutral queries#22
Merged
Conversation
Sixth step of the Kuzu -> DuckDB migration. The Mermaid / DOT diagram
generators in tools_viz.py and the graph_stats / live_graph_stats
MCP tools no longer emit Cypher. Both backends produce identical
diagram input and identical node counts.
What lands:
- codegraph/core/protocol.py: two helper additions on GraphDB.
- find_neighbors gets a limit= parameter for the bounded-traversal
patterns in the viz tools (call graph, class hierarchy, etc.
all take a max_nodes hint).
- count_nodes(label, where=...) for the 6 "count of nodes" sites
in graph_stats and live_graph_stats — single COUNT(*) per call
on DuckDB, one cheap MATCH count() on Kuzu.
- codegraph/server/tools_viz.py: every conn.execute() against the
graph DB gone. _rows import gone.
- _viz_file_imports: two find_neighbors calls (outgoing + incoming)
replacing the UNION ALL pattern. Filtered or unfiltered via the
src_key / no-anchor distinction.
- _viz_call_graph and _viz_class_hierarchy: when symbol_name is
supplied, the Cypher "WHERE caller.name = $n OR callee.name = $n"
becomes two filtered find_neighbors calls unioned in Python.
Cheap because LIMIT bounds each side.
- _viz_file_symbols: three find_nodes calls (Function / Class /
MdSection by file_path) with order_by=['start_line'].
- _viz_doc_structure: one find_nodes call with file_path filter
+ order_by + limit.
- _viz_full_overview: file aggregation by language done in Python
(Counter) since GROUP BY isn't a protocol primitive yet. Top
files by symbol density similarly aggregated from find_neighbors
over DEFINES_FN edges. Both small-N enough that the Python pass
is negligible.
- graph_stats / live_graph_stats: 6 conn.execute count() calls
each become count_nodes() helper calls.
The SQLite FTS count in live_graph_stats stays as direct fts_conn
.execute() — that's a different database and out of scope for the
graph backend swap.
Test count: 298 (unchanged; no new tests, the existing 298-test
suite already covers find_neighbors with limit + count semantics
through the helper parity sweep).
End-to-end smoke on a 3-file Python repo:
Kuzu: Files=5 Functions=2 Classes=2 IMPORTS=2 INHERITS=1
DuckDB: Files=5 Functions=2 Classes=2 IMPORTS=2 INHERITS=1
What's left for the migration:
- cli/commands_monitor.py (12 stats queries — task #10)
- federation.py (kuzu-direct child DB opens — task #11)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sixth PR in the Kuzu → DuckDB migration. The Mermaid / DOT diagram generators in `tools_viz.py` and the `graph_stats` / `live_graph_stats` MCP tools no longer emit Cypher.
What lands
Notable porting decisions:
End-to-end verification
3-file Python repo with imports + inheritance:
Tests
298 / 298 pass, lint clean. No new tests added in this PR — the existing helper parity sweep (40 tests across both backends) already covers `find_neighbors` with `limit` and `count_nodes` semantics.
Remaining migration work