Skip to content

feat(core): port tools_arch / tools_docs / dead_code / context_builder#21

Merged
joy-software merged 1 commit into
developfrom
feature/duckdb-rest-tools
Jun 2, 2026
Merged

feat(core): port tools_arch / tools_docs / dead_code / context_builder#21
joy-software merged 1 commit into
developfrom
feature/duckdb-rest-tools

Conversation

@joy-software
Copy link
Copy Markdown
Contributor

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

File Cypher → helpers
`core/protocol.py` 2 new helpers: `find_nodes` gains `order_by=`, new `find_nodes_without_incoming` for the dead-code "no incoming edge" pattern
`core/db_duckdb.py` Edge case fix: `exclude_name_prefix='_'` uses `substr()` instead of `LIKE` (underscore is a LIKE wildcard in DuckDB)
`server/tools_arch.py` `architecture_overview`, `domain_map`, `endpoints` ported. OPTIONAL MATCH on endpoint→handler done as a per-row find_neighbors lookup
`server/tools_docs.py` `search_docs`, `doc_outline`, `doc_refs` ported
`analysis/dead_code.py` `find_dead_code` now uses `find_nodes_without_incoming`. Drops kuzu import
`analysis/context_builder.py` `context_for_task`'s 3 find_neighbors calls ported. Drops kuzu import
`tests/test_core/test_graph_helpers.py` 6 new parametrized tests (order_by, no-incoming, underscore-prefix edge case)

Test count

292 → 298 (+6 new parity tests).

Not in this PR (final migration work)

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)
@joy-software joy-software merged commit d0ba48a into develop Jun 2, 2026
1 check passed
@joy-software joy-software deleted the feature/duckdb-rest-tools branch June 2, 2026 05:43
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.

1 participant