feat(mcp/cli): add codegraph_check for circular import detection#889
Open
goutham80808 wants to merge 5 commits into
Open
feat(mcp/cli): add codegraph_check for circular import detection#889goutham80808 wants to merge 5 commits into
goutham80808 wants to merge 5 commits into
Conversation
Wires the existing (previously uncalled) CodeGraph.findCircularDependencies() DFS detector into the MCP tool surface. No new algorithm; the handler formats the string[][] result as markdown. Tool is callable but not added to DEFAULT_MCP_TOOLS -- respects the deliberate 4-tool surface trim.
Prints file-level import cycles and exits non-zero when any are found, so it works as a git pre-commit hook. Backed by the same findCircularDependencies() DFS as the codegraph_check MCP tool.
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
Surfaces the existing
findCircularDependencies()DFS detector (src/graph/queries.ts:225) on two channels:codegraph_check) — callable by AI agents, ships functional but NOT inDEFAULT_MCP_TOOLS(deliberate surface-trim per CLAUDE.md eval evidence)codegraph check [path]) — deterministic, git-hook ready (exits non-zero on cycles)Closes #888
What Changed
5 files, 341 insertions, 0 deletions:
src/mcp/tools.ts— tool def (~line 600) + dispatch case (~line 1123) +handleCheckhandler (~line 3256)src/bin/codegraph.ts—codegraph check [path]subcommand (~line 1859),process.exitCode = 1on cycles__tests__/mcp-check-circular-imports.test.ts(new) — 4 MCP tests__tests__/cli-check.test.ts(new) — 2 CLI testsCHANGELOG.md—[Unreleased]entryWhy
The DFS detector at
src/graph/queries.ts:225was fully implemented with zero callers — dead code. Circular imports cause build failures, slow bundlers, and create maintenance traps. This PR completes the feature by wiring the existing algorithm to both agent and developer workflows.The CLI channel is the primary path (deterministic, user-invoked). The MCP channel is correctly low-salience —
DEFAULT_MCP_TOOLSremains unchanged per CLAUDE.md's evidence that agents under-pick new tools.Design Decisions
codegraph_checkNOT inDEFAULT_MCP_TOOLScodegraph check || exit 1);--jsonflag available for scriptscodegraph init --index; setsCODEGRAPH_NO_DAEMON=1Verification
Test Coverage
Migration
None.
codegraph_checkis a new MCP tool (additive).codegraph checkis a new CLI subcommand (additive). No schema changes. No breaking changes.To enable
codegraph_checkfor agents, addchecktoCODEGRAPH_MCP_TOOLSenv var. To run as a git hook:codegraph check || exit 1in.git/hooks/pre-commit.