feat(core): port tools_arch / tools_docs / dead_code / context_builder#21
Merged
Conversation
Fifth step of the Kuzu -> DuckDB migration. Smaller-but-spread-out
files all ported in one PR: tools_arch.py, tools_docs.py,
analysis/dead_code.py, analysis/context_builder.py. After this,
tools_viz.py (Mermaid generators) and the federation port are the
last remaining Cypher emitters on the read side.
What lands:
- codegraph/core/protocol.py: two new helpers on GraphDB.
- find_nodes gets an order_by= parameter for ORDER BY support.
Needed by architecture_overview (sort by layer/role/path) and
doc_outline (sort by start_line).
- find_nodes_without_incoming(label, edge_type, contains=...,
exclude_name_prefix=..., return_fields=...) covers the dead-code
detector's "no incoming CALLS / INHERITS edge" pattern. Single
query each backend (Cypher's NOT (n)<-[]-() vs DuckDB's
NOT EXISTS subquery).
- codegraph/core/db_duckdb.py edge case: exclude_name_prefix='_'
uses substr() rather than LIKE so the underscore isn't treated as
a LIKE wildcard (would match every single-char-name function).
- codegraph/server/tools_arch.py:
- architecture_overview ported to find_nodes with order_by.
- domain_map ported to find_nodes (no order needed, filter in Python).
- endpoints ported: find_nodes for the Endpoint list, then for each
endpoint find_neighbors(IMPLEMENTED_BY) to look up the handler
name. Two-query pattern replaces Cypher's OPTIONAL MATCH; the
cost is one extra round-trip per endpoint, fine for the
small-N this tool returns.
- Stops importing _rows.
- codegraph/server/tools_docs.py:
- search_docs ported to find_nodes with contains and limit.
- doc_outline ported to find_nodes with where + order_by.
- doc_refs ported to find_neighbors anchored on the dst side
(Function/Class name match) returning src (MdSection) +
edge.context. Plus a final find_nodes pass for body_preview
text mentions.
- Stops importing _rows.
- codegraph/analysis/dead_code.py:
- find_dead_code now uses find_nodes_without_incoming for both
functions (no CALLS) and classes (no INHERITS). file_filter
becomes contains={'file_path': ...}. exclude_name_prefix='_'
when include_private is False.
- Stops importing kuzu + _rows. The function signature drops the
kuzu.Connection type annotation; GraphDB is structurally
compatible so callers see no change.
- codegraph/analysis/context_builder.py:
- The three find_neighbors patterns (caller / callee / parent
class lookups) ported. LIMIT 3 in Cypher becomes a Python slice
on the helper result — small N each call so the difference is
immaterial.
- Stops importing kuzu + _rows. Function signature uses a plain
parameter type for kuzu_conn (structural typing keeps callers
working).
- tests/test_core/test_graph_helpers.py: 6 new parametrized tests
(3 patterns × 2 backends) covering order_by, find_nodes_without_
incoming including the underscore-prefix edge case that caught
the LIKE wildcard bug on DuckDB.
Test count: 292 -> 298 (+6 new parity tests, all existing still green).
What's NOT in this PR (remaining work):
- tools_viz.py (19 Cypher queries — Mermaid generators, dedicated PR)
- cli/commands_monitor.py (12 stats queries — task #10)
- federation.py (kuzu-direct 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
Fifth PR in the Kuzu → DuckDB migration. Four files all ported in one bundle so the same parity-test sweep covers them: `server/tools_arch.py`, `server/tools_docs.py`, `analysis/dead_code.py`, `analysis/context_builder.py`.
What lands
Test count
292 → 298 (+6 new parity tests).
Not in this PR (final migration work)