Add opt-in grouped/directory-based mode to get_architecture (#90) - #93
Merged
Merged
Conversation
Reuses every node's existing file_path - no new indexing/extraction - matching #89's established opt-in-parameter, default-unchanged pattern. - nexus-index: GraphStore::directory_groups(depth) groups nodes by the first depth components of their file_path's parent directory, and classifies every edge as within-group or cross-group by looking up its two endpoints' groups. get_architecture_grouped(repo_path, depth) wraps this alongside the existing flat ArchitectureSummary via a shared architecture_summary helper, so both paths compute the flat half identically off one GraphStore::open. - nexusd: get_architecture tool gains grouped (bool, default false) and depth (integer, default 1, clamped via the existing clamp_depth). grouped=false takes the untouched pre-existing code path and cache key - same response shape and cost as before. grouped=true adds a grouped object: groups (path/total_nodes/node_counts by kind), within_group_edges, and cross_group_edges (from/to/count). - Tests: directory_group_key boundary cases; a three-directory fixture (two with dense internal calls, one call crossing between them, one isolated) confirms grouping and cross-group edge counts; an allowed_roots regression test for get_architecture_grouped; a default-output-unchanged regression test comparing get_architecture against the flat half of get_architecture_grouped. - Docs: MCP-Tools.md updated; ADR 0017 records the path-based-only decision and explicitly scopes out semantic subsystem/layer inference, per the issue's own instruction. Closes #90. Claude-Session: https://claude.ai/code/session_01D6ND42psexN5cWTKewSpBG
…navigation # Conflicts: # crates/nexus-index/src/lib.rs # docs/NexusContext-Wiki/ADRs/README.md
6 tasks
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.
What
Adds an opt-in grouped/directory-based mode to
get_architecture(issue#90): in addition to the existing flat node/edge summary, optionally
groups the graph by directory and reports per-directory node counts plus
which directories actually call into which.
Schema
get_architectureMCP tool gains two new optional parameters:grouped(boolean, defaultfalse)depth(integer, default1, clamped via the existingclamp_depth/SERVER_MAX_DEPTH)When
grouped=false(the default): response is the exact same JSON thetool has always returned, taking the exact same code path
(
index::get_architecture) and cache key it always has.When
grouped=true: response gains agroupedobject:{ "total_nodes": 42, "total_edges": 61, "busiest_files": [ ...unchanged... ], "language_breakdown": [ ...unchanged... ], "grouped": { "depth": 1, "groups": [ { "path": "pkg/a", "total_nodes": 2, "node_counts": [{ "kind": "Function", "count": 2 }] }, { "path": "pkg/b", "total_nodes": 1, "node_counts": [{ "kind": "Function", "count": 1 }] } ], "within_group_edges": 1, "cross_group_edges": [ { "from": "pkg/a", "to": "pkg/b", "count": 1 } ] }, "index_freshness": { ... } }Reuse, not a new subsystem
Per the issue's explicit guidance ("investigate what's cheaply derivable
from the existing graph without new indexing infrastructure... do not
attempt automatic subsystem/layer detection"), this builds entirely on
data already in
nodes/edges:GraphStore::directory_groups(depth)groups every node by the firstdepthcomponents of its existingfile_path's parent directory, andclassifies every edge as within-group or cross-group by looking up its
two endpoints' groups - one pass over
nodes, one overedges, no newtables, no new extraction pass.
get_architecture_grouped(repo_path, depth)shares oneGraphStore::opencall with the flat summary via a factored-out
architecture_summaryhelper, so both paths compute the flat half identically.
depthis named/clamped the same waytrace_call_path/detect_changes'sblast_radiusmode ([Feature] Blast-radius mode for detect_changes (impact analysis) #89, in review as Add opt-in blast-radius mode to detect_changes (#89) #92) clamp their owndepthparameter - no new bound was invented.
pathis always the literal directorystring, never a guessed subsystem/layer label. See ADR 0017.
Default-behavior-unchanged guarantee
crates/nexus-index/src/queries.rs::get_architectureis now a thinwrapper around a shared
architecture_summaryhelper that also backs thegrouped path -
get_architecture's own signature/behavior is otherwiseuntouched. The MCP handler's
grouped=falsebranch calls that sameget_architectureand never touchesdirectory_groupsat all, and usesa distinct cache-key suffix so a
grouped=truecall can never serve astale flat-only cache entry or vice versa.
Verified by:
get_architecture_default_output_is_unchanged_by_the_grouped_mode_existing(
crates/nexus-index/tests/path_security.rs) - asserts the plainget_architecture(&repo)call and the flat half ofget_architecture_grouped(&repo, 2)agree exactly on a real graph.db.get_architecture_enforces_allowed_rootsintegrationtest still passes unmodified; a matching
get_architecture_grouped_enforces_allowed_rootstest covers the newfunction.
Tests
directory_group_key_*- path-grouping boundary cases (nested depth,depth beyond actual nesting, no-parent-directory files).
groups_nodes_by_top_level_directory_with_per_kind_counts,counts_within_group_calls_separately_from_the_one_cross_group_call,a_directory_with_no_calls_reports_zero_cross_group_involvement(
crates/nexus-index/src/graph.rs) - a synthetic three-directoryfixture (
pkg/aandpkg/beach with dense internal calls, one callcrossing
pkg/a->pkg/b,pkg/cisolated) confirms grouping andcross-group edge counts are both correct.
grouped_mode_reports_the_dense_internal_and_single_cross_directory_call(
crates/nexus-index/tests/path_security.rs) - the same shape exercisedend to end through the public
get_architecture_groupedfunction.Verification
cargo build --workspace- cleancargo test --workspace- all greencargo fmt --all -- --check- cleancargo clippy --workspace --all-targets -- -D warnings- cleanDocs
docs/NexusContext-Wiki/MCP-Tools.md-get_architecturerow updatedwith the new parameter/response shape (git-host-agnostic language - no
comparison to any specific hosting service's UI).
docs/NexusContext-Wiki/ADRs/0017-grouped-architecture-view-is-path-based-not-semantic.md-new ADR recording the path-based-only decision and explicitly scoping
out semantic subsystem/layer inference, per the issue's own instruction.
Closes #90.
https://claude.ai/code/session_01D6ND42psexN5cWTKewSpBG