feat(core,mcp): graph algorithms — PageRank, components, shortest path#19
Merged
Conversation
Key findings: - callers metadata is dead code (not stored in index) — callees-only is correct - Keep incomingRefs as real count, add score field for PageRank - Existing tests need callees data + relative ordering assertions - Add performance test for 2k-node graph Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ortest path Pure functions over the file dependency graph: - pageRank: weighted with dangling node handling and convergence (4ms for 2k nodes) - buildDependencyGraph: callees → weighted edges with sqrt dampening - connectedComponents: BFS on undirected graph for subsystem identification - shortestPath: BFS for call chain tracing (hop count) 24 tests covering ranking, cycles, dangling nodes, weights, components, path finding, edge cases, and performance. Inspired by aider's repo map (https://github.com/Aider-AI/aider). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace computeHotPaths simple reference counting with PageRank over the weighted dependency graph. Files depended on by other important files now rank higher. - HotPath.score: PageRank value (used for sorting) - HotPath.incomingRefs: real incoming edge count (used for display) - Rewrite 4 hot paths tests from dead callers data to callees data - Assert relative ordering, not exact counts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add components field to CodebaseMap. Compute connected components from the dependency graph and display as "Subsystems" section in formatted output. Only shows multi-file components (singles filtered out). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New traceTo parameter on dev_refs: traces the dependency chain from
a function's file to a target file through the call graph.
Example: dev_refs { name: "authenticate", traceTo: "src/database.ts" }
→ "src/auth.ts → src/user-service.ts → src/repository.ts → src/database.ts (3 hops)"
Uses shortestPath BFS from graph.ts. Requires indexer for graph building
(optional — traceTo is ignored without it).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All 6 parts of MCP Phase 1 Tools Improvement are complete: - 1.1: Pure pattern extractors - 1.2: Index-based analysis (10-30x faster) - 1.3: Dead code cleanup - 1.4: Agent usability (merge health, rename params, JSON, suggestions) - 1.5: AST pattern analysis (tree-sitter queries) - 1.6: Graph algorithms (PageRank, components, shortest path) File importance ranking inspired by aider's repo map (https://github.com/Aider-AI/aider). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…aceTo error - Build dependency graph once, pass to both computeHotPaths and connectedComponents - Return explicit error when traceTo is set but indexer is missing - Document directed-only limitation in traceTo description - Switch BFS from queue.shift() (O(n)) to index-based (O(1)) - Require 2+ path segments for subsystem labels (avoid "packages" alone) - Track traceTo adapter test gap in scratchpad Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
059fed8 to
994c1d3
Compare
- Rename traceTo → dependsOn (makes call direction unambiguous) - Cache dependency graph on RefsAdapter (60s TTL, avoids rebuilding per request) - Log warning when 10k doc limit is hit in both dev_map and dev_refs - Remove overly strict shortestPath early return for unknown source nodes - Update docs for dependsOn parameter name - Track hub filtering, 10k scaling, and perf concerns in scratchpad Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
994c1d3 to
8d56e25
Compare
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
Adds graph algorithms over the file dependency graph to improve
dev_mapanddev_refs:dev_maphot pathsdev_mapoutputdev_refsviatraceToCompletes MCP Phase 1 (Parts 1.1–1.6).
What it does
dev_map hot paths — Files are now ranked by graph centrality, not just incoming reference count. A file depended on by other important files ranks higher than a file with many direct but shallow references.
dev_map subsystems — Shows connected components: "Subsystems (3 connected): packages/core (45 files), packages/cli (12 files), ..."
dev_refs path tracing — New
traceToparameter:Changes
New files
packages/core/src/map/graph.ts— PageRank, buildDependencyGraph, connectedComponents, shortestPath (~230 lines)packages/core/src/map/__tests__/graph.test.ts— 24 testsModified files
packages/core/src/map/index.ts— replacecomputeHotPaths, add components to output + formatterpackages/core/src/map/types.ts— addscoreto HotPath,componentsto CodebaseMappackages/core/src/map/__tests__/map.test.ts— rewrite callers→callees testspackages/mcp-server/src/adapters/built-in/refs-adapter.ts— addtraceToparam + path tracingpackages/mcp-server/src/schemas/index.ts— addtraceToto RefsArgsSchemapackages/mcp-server/bin/dev-agent-mcp.ts— wire indexer into RefsAdapterKey design decisions
callersmetadata is dead code — scanner stores onlycallees. PreviouscomputeHotPathshad dead callers path. Fixed.HotPath.incomingRefsis real incoming edge count (for display).HotPath.scoreis PageRank value (for sorting).Test plan
Commits
feat(core): add graph algorithms— pure functions + testsfeat(core): replace ref counting with PageRank in dev_map— wire + rewrite testsfeat(core): wire connected components into dev_map outputfeat(mcp): add path tracing to dev_refs— traceTo parameterdocs: complete MCP Phase 1Inspired by aider's repo map (Apache 2.0).
Generated with Claude Code