name: code-review-blast-radius
description: >-
Build a blast-radius code graph for AI-assisted code review. Maps call chains,
dependency propagation, and community clusters from a code diff to prioritize
which files ACTUALLY matter for review (100% recall, token-budget capped).
Derived from tirth8205/code-review-graph (MIT, 8.4/10 port score). Core
algorithms: tree-sitter AST → call graph → Leiden community detection →
betweenness centrality → blast-radius ranked output. 38×–528× token reduction
vs naive all-files review. Use before any non-trivial PR review or merge.
status: stable
lane: [code-review, analysis, ci]
type: analysis-workflow
trigger: >-
"code review graph", "blast radius", "what does this change affect",
"which files matter for this PR", "call graph review", "impact analysis",
"review this diff with graph"
source-ingest: .planning/ingest/2026-06-06-article-github-com-tirth8205-code-review-graph.md
port-score: 8.4/10
argument-hint: --diff [--budget-tokens 8000]
code-review-blast-radius
AI-assisted code review using a blast-radius call graph. Prioritize the files that propagate changes furthest; ignore files that are purely local.
Derived from tirth8205/code-review-graph (MIT). Clean-room reimplementation of the Leiden + betweenness-centrality blast-radius algorithm in our stack.
Core insight (from RE)
Naive code review sends ALL changed files to the LLM — token-expensive and context-unfocused. The blast-radius approach:
- Parse changed files → call graph (tree-sitter, per language)
- Run Leiden community detection → find module clusters
- Score each changed function by betweenness centrality in the community graph
- Cap output by token budget — send ONLY the highest-centrality files first
- Result: 38×–528× token reduction; 100% recall on high-impact changes
Workflow
1. Build the code graph (once per session/PR)
xp code-graph build --diff HEAD~1..HEAD # or full repo: --path .
# Outputs: .planning/.code-graph/graph.db (SQLite, tree-sitter-derived)
# Languages: Rust, TypeScript, JavaScript, Python (via tree-sitter grammars)
2. Get blast radius for the diff
xp code-graph blast-radius --diff HEAD~1..HEAD --budget-tokens 8000
# Outputs ranked file list: (file, centrality_score, community_id, n_callers, n_callees)
# Example: crates/xp-recall/src/retrieval.rs (centrality=0.89, community=core-retrieval, callers=23)
3. Review in order
Review files in centrality rank order:
- Highest centrality first — these are the load-bearing changes
- Skip or skim files below centrality threshold (configurable, default 0.15)
- If a community cluster appears in multiple changed files — review entire cluster
4. MCP exposure (for Kael/agents)
The code graph exposes 30 MCP tools (mirroring code-review-graph's interface):
code_graph_query(function_name)— get call chain for a functioncode_graph_community(file)— which community cluster does this file belong tocode_graph_blast_radius(diff)— full blast-radius ranked outputcode_graph_callers(function)— who calls this functioncode_graph_callees(function)— what does this function call
5. Post-review: update graph
xp code-graph update --diff HEAD~1..HEAD # incremental update after merge
Token budget control
The blast-radius output is token-budget-capped. Configure per context:
--budget-tokens 4000— tight (fast review, lowest cost)--budget-tokens 8000— standard (recommended)--budget-tokens 20000— deep review (full clusters exposed)
Leiden community detection
Leiden (improvement over Louvain) partitions the call graph into communities. A community = a set of functions that call each other more than they call outside. A changed function in a high-betweenness position bridges communities — changes there propagate everywhere. These are the highest-priority review targets.
Language support (tree-sitter grammars)
| Language | Grammar | Status |
|---|---|---|
| Rust | tree-sitter-rust | supported |
| TypeScript | tree-sitter-typescript | supported |
| JavaScript | tree-sitter-javascript | supported |
| Python | tree-sitter-python | supported |
| Go | tree-sitter-go | future |
Anti-patterns
- Do NOT skip the graph build and just send all diff files to the LLM — this is the expensive baseline this skill replaces
- Do NOT set
--budget-tokensabove 20000 without a good reason — defeats the token-reduction purpose - Do NOT re-build the full graph on every review — use
xp code-graph updatefor incremental diffs after the initial build
Relationship to existing tools
| Tool | Role |
|---|---|
gad concerns |
Stable @concern landmark anchors (line-level); blast-radius is function-graph-level |
xp recall |
BM25 recall over docs/snippets; blast-radius is structural-graph over code |
| GSA callgraph viewer | Visual exploration; blast-radius is algorithmic prioritization |
Provenance
- Source: tirth8205/code-review-graph (MIT) —
.planning/ingest/2026-06-06-article-github-com-tirth8205-code-review-graph.md - Port score: 8.4/10
- Key algorithms: tree-sitter AST → SQLite call graph → Leiden community → betweenness centrality → blast-radius ranking
- Token reduction validated: 38×–528× in upstream benchmarks
- Clean-room: algorithm described from RE spec and README; no Python source copied
- Built: 2026-06-07