How to Build Repository-Level Code Intelligence with Repowise Using Graph Analysis, Dead-Code Detection, Decisions, and AI Context
In this tutorial, we discover how to use Repowise to construct repository-level intelligence for the itsdangerous Python mission in a sensible and reproducible method. We begin with an already cloned repository, configure Repowise utilizing the obtainable LLM credentials, and initialize its indexing pipeline. We then examine the generated .repowise artifacts, analyze the repository graph with PageRank and group detection, examine Git intelligence, run dead-code detection, seize architectural selections, generate a CLAUDE.md file, and work together with Repowise’s MCP-style instruments via the CLI. Finally, we visualize a very powerful nodes within the repository graph to higher perceive the construction, affect, dependencies, and upkeep priorities of various information or modules.
import os, sys, json, subprocess, textwrap, shutil, re
from pathlib import Path
TARGET = Path("/content material/itsdangerous")
assert TARGET.exists(), "Run §1–§2 first to clone the goal repo."
os.chdir(TARGET)
def sh(cmd, examine=False, cwd=None, timeout=None, env=None):
print(f"n$ {cmd}")
proc = subprocess.run(
cmd, shell=True,
env={**os.environ, **(env or {})},
cwd=cwd, textual content=True, timeout=timeout,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
)
if proc.stdout:
print(proc.stdout.rstrip())
print(f" ↳ exit {proc.returncode}")
if examine and proc.returncode != 0:
increase RuntimeError(f"command failed (exit {proc.returncode}): {cmd}")
return proc
def banner(t):
print(f"n{'═'*(len(t)+4)}n {t}n{'═'*(len(t)+4)}")
We start by importing the required libraries, setting the goal repository path, and transferring into the itsdangerous mission listing. We outline a reusable sh() helper perform to run shell instructions, seize their output, and show exit codes clearly. We additionally create a banner() perform so every tutorial part prints with a readable heading.
banner("§5 Building intelligence layers (fastened)")
sh("repowise --version")
sh("repowise init --help")
HAS_ANTHROPIC = bool(os.environ.get("ANTHROPIC_API_KEY"))
HAS_OPENAI = bool(os.environ.get("OPENAI_API_KEY"))
HAS_LLM = HAS_ANTHROPIC or HAS_OPENAI
if HAS_ANTHROPIC:
supplier, mannequin = "anthropic", "claude-sonnet-4-5"
elif HAS_OPENAI:
supplier, mannequin = "openai", "gpt-4o-mini"
else:
supplier, mannequin = "mock", "mock"
(TARGET / ".repowise").mkdir(exist_ok=True)
(TARGET / ".repowise" / "config.yaml").write_text(textwrap.dedent(f"""
supplier: {supplier}
mannequin: {mannequin}
embedding_model: voyage-3
reasoning: auto
git:
co_change_commit_limit: 200
blame_enabled: true
dead_code:
enabled: true
safe_to_delete_threshold: 0.7
upkeep:
cascade_budget: 10
""").lstrip())
print(f"Provider chosen: {supplier} | LLM obtainable: {HAS_LLM}")
init_cmd = "repowise init . --index-only" if not HAS_LLM else "repowise init ."
res = sh(init_cmd, timeout=20*60)
if res.returncode != 0:
print("n
init nonetheless failed. Things to attempt:")
print(" • pip set up -U repowise (older variations lacked --index-only)")
print(" • set an ANTHROPIC_API_KEY and re-run with out --index-only")
print(" • copy the FIRST error line above — it tells the true story")
increase SystemExit(1)
We begin the Repowise initialization stage by checking the put in model and viewing the supported init choices. We decide whether or not an Anthropic or OpenAI API secret is obtainable, then mechanically choose the proper supplier and mannequin configuration. We write the .repowise/config.yaml file and run Repowise initialization, utilizing index-only mode when no LLM secret is obtainable.
banner("§6 .repowise/ artifact tree")
for p in sorted((TARGET / ".repowise").rglob("*")):
if p.is_file():
print(f" {str(p.relative_to(TARGET)):60s} {p.stat().st_size:>9,d} B")
banner("§7 Graph Intelligence")
import networkx as nx
G = None
for gp in (TARGET / ".repowise").rglob("*"):
if gp.is_file() and gp.suffix in {".json", ".gml", ".graphml"} and "graph" in gp.identify.decrease():
attempt:
if gp.suffix == ".json":
information = json.masses(gp.read_text())
if isinstance(information, dict) and "nodes" in information:
G = nx.node_link_graph(information)
elif gp.suffix == ".gml":
G = nx.read_gml(gp)
elif gp.suffix == ".graphml":
G = nx.read_graphml(gp)
if G isn't None:
print(f"Loaded {gp.identify}: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges")
break
besides Exception as e:
print(f" ({gp.identify}: {e})")
pr = {}
if G isn't None:
pr = nx.pagerank(G)
print("nTop 10 nodes by PageRank:")
for n, s in sorted(pr.objects(), key=lambda x: -x[1])[:10]:
print(f" {s:.4f} {n}")
attempt:
from networkx.algorithms.group import greedy_modularity_communities
comms = listing(greedy_modularity_communities(G.to_undirected()))
print(f"n{len(comms)} communities detected; sizes:",
[len(c) for c in comms[:8]])
besides Exception as e:
print(f" communities skipped: {e}")
else:
print("(no graph artifact discovered — your model could identify it otherwise;"
" run `ls -R .repowise/` to examine.)")
We examine the generated .repowise artifact tree to perceive what information Repowise creates after indexing the repository. We then seek for graph artifacts, load the repository graph utilizing NetworkX, and print the variety of nodes and edges. We calculate PageRank scores, show a very powerful nodes, and detect communities to perceive how the codebase is structurally grouped.
banner("§8 Git Intelligence")
sh("repowise standing")
banner("§9 Doc Intelligence")
if HAS_LLM:
sh('repowise search "URL-safe token signing"')
sh('repowise question "How does Signer detect tampered payloads?"')
else:
print("(skipped — no LLM key set; supplier=mock cannot reply actual questions)")
banner("§10 Dead-code detection")
sh("repowise dead-code")
sh("repowise dead-code --safe-only")
banner("§11 Architectural selections")
src = TARGET / "src" / "itsdangerous" / "signer.py"
if src.exists() and "DECISION:" not in src.read_text():
src.write_text(
"# DECISION: Signers are stateless by design — secrets and techniques are handed atn"
"# development so signing will be parallelised safely.n"
+ src.read_text()
)
sh('git -c consumer.e-mail=demo@x -c consumer.identify=demo commit -am "demo: inline choice"')
sh("repowise replace .")
sh("repowise choice listing")
sh("repowise choice well being")
We use Repowise standing to examine Git intelligence and perceive the present repository state. We then run documentation-focused search and question instructions when an LLM secret is obtainable, whereas safely skipping them in mock mode. We additionally run dead-code detection, insert an inline architectural choice into signer.py, replace Repowise, and examine the choice listing and choice well being.
banner("§12 CLAUDE.md")
sh("repowise generate-claude-md")
md = TARGET / "CLAUDE.md"
if md.exists():
print(md.read_text()[:4000])
banner("§13 MCP instruments through CLI")
base = [
("get_dead_code", "repowise dead-code --safe-only"),
("search_codebase", 'repowise search "timestamp expiry validation"'),
]
llm_only = [
("get_overview", 'repowise query "Architecture overview please"'),
("get_context", 'repowise query "Explain signer and serializer modules"'),
("get_risk", 'repowise query "What is risky about changing signer.py?"'),
("get_why", 'repowise query "Why are signers stateless?"'),
("get_dependency_path", 'repowise query "How does URLSafeSerializer reach Signer?"'),
("get_architecture_diagram", 'repowise query "Produce a Mermaid diagram of the package"'),
]
for identify, cmd in base + (llm_only if HAS_LLM else []):
print(f"n──── {identify} ────")
sh(cmd)
if not HAS_LLM:
print("n(7 of 9 instruments above want an LLM key — set ANTHROPIC_API_KEY and re-run §13.)")
banner("§14 Graph plot")
if G isn't None:
import matplotlib.pyplot as plt
prime = [n for n, _ in sorted(pr.items(), key=lambda x: -x[1])[:40]]
H = G.subgraph(prime).copy()
sizes = [4000 * pr[n] / max(pr.values()) + 80 for n in H.nodes]
plt.determine(figsize=(12, 8))
pos = nx.spring_layout(H, seed=7, ok=0.9)
nx.draw_networkx_edges(H, pos, alpha=0.25, arrows=False)
nx.draw_networkx_nodes(H, pos, node_size=sizes, node_color="#F59520", alpha=0.85)
nx.draw_networkx_labels(H, pos,
labels={n: Path(n).identify if isinstance(n, str) else n for n in H.nodes},
font_size=8)
plt.title("itsdangerous — top-40 nodes by PageRank")
plt.axis("off"); plt.tight_layout(); plt.present()
print("n
carried out.")
We generate a CLAUDE.md file to expose helpful mission context for AI-assisted growth. We then run a number of Repowise MCP-style instruments via CLI instructions, together with dead-code checks, code search, and LLM-powered structure queries when obtainable. Also, we visualize the highest PageRank nodes within the repository graph to clearly see essentially the most influential information and relationships.
In conclusion, we created a sensible workflow for turning a normal code repository into an intelligence-rich mission workspace that helps a deeper understanding of the codebase. We used Repowise to index and examine the codebase, uncover graph relationships, determine vital information, detect potential useless code, doc architectural selections, and put together context information for AI-assisted growth. This offers us a transparent view of how repository intelligence instruments can enhance code understanding, upkeep, refactoring, collaboration, and future onboarding, whereas nonetheless working in each LLM-enabled and mock-provider modes.
Check out the Full Codes with Notebook here. Also, be happy to observe us on Twitter and don’t overlook to be a part of our 150k+ ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.
Need to accomplice with us for selling your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar and so on.? Connect with us
The submit How to Build Repository-Level Code Intelligence with Repowise Using Graph Analysis, Dead-Code Detection, Decisions, and AI Context appeared first on MarkTechPost.
