Skip to content

Commit 84c9548

Browse files
committed
feat: add knowledge graph tools and documentation for code review, debugging, and refactoring
1 parent 31bee08 commit 84c9548

9 files changed

Lines changed: 206 additions & 1 deletion

File tree

.claude/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write|Bash",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "code-review-graph update --skip-flows",
10+
"timeout": 30
11+
}
12+
]
13+
}
14+
],
15+
"SessionStart": [
16+
{
17+
"matcher": "",
18+
"hooks": [
19+
{
20+
"type": "command",
21+
"command": "code-review-graph status",
22+
"timeout": 10
23+
}
24+
]
25+
}
26+
]
27+
}
28+
}

.claude/skills/debug-issue.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Debug Issue
3+
description: Systematically debug issues using graph-powered code navigation
4+
---
5+
6+
## Debug Issue
7+
8+
Use the knowledge graph to systematically trace and debug issues.
9+
10+
### Steps
11+
12+
1. Use `semantic_search_nodes` to find code related to the issue.
13+
2. Use `query_graph` with `callers_of` and `callees_of` to trace call chains.
14+
3. Use `get_flow` to see full execution paths through suspected areas.
15+
4. Run `detect_changes` to check if recent changes caused the issue.
16+
5. Use `get_impact_radius` on suspected files to see what else is affected.
17+
18+
### Tips
19+
20+
- Check both callers and callees to understand the full context.
21+
- Look at affected flows to find the entry point that triggers the bug.
22+
- Recent changes are the most common source of new issues.
23+
24+
## Token Efficiency Rules
25+
- ALWAYS start with `get_minimal_context(task="<your task>")` before any other graph tool.
26+
- Use `detail_level="minimal"` on all calls. Only escalate to "standard" when minimal is insufficient.
27+
- Target: complete any review/debug/refactor task in ≤5 tool calls and ≤800 total output tokens.

.claude/skills/explore-codebase.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Explore Codebase
3+
description: Navigate and understand codebase structure using the knowledge graph
4+
---
5+
6+
## Explore Codebase
7+
8+
Use the code-review-graph MCP tools to explore and understand the codebase.
9+
10+
### Steps
11+
12+
1. Run `list_graph_stats` to see overall codebase metrics.
13+
2. Run `get_architecture_overview` for high-level community structure.
14+
3. Use `list_communities` to find major modules, then `get_community` for details.
15+
4. Use `semantic_search_nodes` to find specific functions or classes.
16+
5. Use `query_graph` with patterns like `callers_of`, `callees_of`, `imports_of` to trace relationships.
17+
6. Use `list_flows` and `get_flow` to understand execution paths.
18+
19+
### Tips
20+
21+
- Start broad (stats, architecture) then narrow down to specific areas.
22+
- Use `children_of` on a file to see all its functions and classes.
23+
- Use `find_large_functions` to identify complex code.
24+
25+
## Token Efficiency Rules
26+
- ALWAYS start with `get_minimal_context(task="<your task>")` before any other graph tool.
27+
- Use `detail_level="minimal"` on all calls. Only escalate to "standard" when minimal is insufficient.
28+
- Target: complete any review/debug/refactor task in ≤5 tool calls and ≤800 total output tokens.

.claude/skills/refactor-safely.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Refactor Safely
3+
description: Plan and execute safe refactoring using dependency analysis
4+
---
5+
6+
## Refactor Safely
7+
8+
Use the knowledge graph to plan and execute refactoring with confidence.
9+
10+
### Steps
11+
12+
1. Use `refactor_tool` with mode="suggest" for community-driven refactoring suggestions.
13+
2. Use `refactor_tool` with mode="dead_code" to find unreferenced code.
14+
3. For renames, use `refactor_tool` with mode="rename" to preview all affected locations.
15+
4. Use `apply_refactor_tool` with the refactor_id to apply renames.
16+
5. After changes, run `detect_changes` to verify the refactoring impact.
17+
18+
### Safety Checks
19+
20+
- Always preview before applying (rename mode gives you an edit list).
21+
- Check `get_impact_radius` before major refactors.
22+
- Use `get_affected_flows` to ensure no critical paths are broken.
23+
- Run `find_large_functions` to identify decomposition targets.
24+
25+
## Token Efficiency Rules
26+
- ALWAYS start with `get_minimal_context(task="<your task>")` before any other graph tool.
27+
- Use `detail_level="minimal"` on all calls. Only escalate to "standard" when minimal is insufficient.
28+
- Target: complete any review/debug/refactor task in ≤5 tool calls and ≤800 total output tokens.

.claude/skills/review-changes.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Review Changes
3+
description: Perform a structured code review using change detection and impact
4+
---
5+
6+
## Review Changes
7+
8+
Perform a thorough, risk-aware code review using the knowledge graph.
9+
10+
### Steps
11+
12+
1. Run `detect_changes` to get risk-scored change analysis.
13+
2. Run `get_affected_flows` to find impacted execution paths.
14+
3. For each high-risk function, run `query_graph` with pattern="tests_for" to check test coverage.
15+
4. Run `get_impact_radius` to understand the blast radius.
16+
5. For any untested changes, suggest specific test cases.
17+
18+
### Output Format
19+
20+
Provide findings grouped by risk level (high/medium/low) with:
21+
- What changed and why it matters
22+
- Test coverage status
23+
- Suggested improvements
24+
- Overall merge recommendation
25+
26+
## Token Efficiency Rules
27+
- ALWAYS start with `get_minimal_context(task="<your task>")` before any other graph tool.
28+
- Use `detail_level="minimal"` on all calls. Only escalate to "standard" when minimal is insufficient.
29+
- Target: complete any review/debug/refactor task in ≤5 tool calls and ≤800 total output tokens.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ htpasswd
88
# Rendered stack files (generated by stackctl/tools)
99
*.rendered.yml
1010
.venv/
11-
__pycache__/
11+
__pycache__/
12+
# Added by code-review-graph
13+
.code-review-graph/

.mcp.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"mcpServers": {
3+
"code-review-graph": {
4+
"command": "uvx",
5+
"args": [
6+
"code-review-graph",
7+
"serve"
8+
],
9+
"type": "stdio"
10+
}
11+
}
12+
}

.opencode.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"mcpServers": {
3+
"code-review-graph": {
4+
"command": "uvx",
5+
"args": [
6+
"code-review-graph",
7+
"serve"
8+
],
9+
"type": "stdio",
10+
"env": []
11+
}
12+
}
13+
}

AGENTS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!-- code-review-graph MCP tools -->
2+
## MCP Tools: code-review-graph
3+
4+
**IMPORTANT: This project has a knowledge graph. ALWAYS use the
5+
code-review-graph MCP tools BEFORE using Grep/Glob/Read to explore
6+
the codebase.** The graph is faster, cheaper (fewer tokens), and gives
7+
you structural context (callers, dependents, test coverage) that file
8+
scanning cannot.
9+
10+
### When to use graph tools FIRST
11+
12+
- **Exploring code**: `semantic_search_nodes` or `query_graph` instead of Grep
13+
- **Understanding impact**: `get_impact_radius` instead of manually tracing imports
14+
- **Code review**: `detect_changes` + `get_review_context` instead of reading entire files
15+
- **Finding relationships**: `query_graph` with callers_of/callees_of/imports_of/tests_for
16+
- **Architecture questions**: `get_architecture_overview` + `list_communities`
17+
18+
Fall back to Grep/Glob/Read **only** when the graph doesn't cover what you need.
19+
20+
### Key Tools
21+
22+
| Tool | Use when |
23+
|------|----------|
24+
| `detect_changes` | Reviewing code changes — gives risk-scored analysis |
25+
| `get_review_context` | Need source snippets for review — token-efficient |
26+
| `get_impact_radius` | Understanding blast radius of a change |
27+
| `get_affected_flows` | Finding which execution paths are impacted |
28+
| `query_graph` | Tracing callers, callees, imports, tests, dependencies |
29+
| `semantic_search_nodes` | Finding functions/classes by name or keyword |
30+
| `get_architecture_overview` | Understanding high-level codebase structure |
31+
| `refactor_tool` | Planning renames, finding dead code |
32+
33+
### Workflow
34+
35+
1. The graph auto-updates on file changes (via hooks).
36+
2. Use `detect_changes` for code review.
37+
3. Use `get_affected_flows` to understand impact.
38+
4. Use `query_graph` pattern="tests_for" to check coverage.

0 commit comments

Comments
 (0)