How Wiki Generation Works with Optional LLM Summaries in Code Review Graph
The generate_wiki function in code_review_graph/wiki.py creates deterministic Markdown documentation for code communities, while generate_wiki_func in code_review_graph/tools/docs.py optionally enriches these pages with LLM-generated natural language summaries.
The code-review-graph repository transforms code analysis into navigable documentation by mapping repository structure into community-based wikis. This article explains how the wiki generation pipeline constructs markdown pages from graph data and how the optional LLM summary feature augments these pages with AI-generated context.
Core Wiki Generation Pipeline
The wiki generation process operates in three distinct stages orchestrated by the generate_wiki function.
Community Discovery
The pipeline begins by invoking code_review_graph.communities.get_communities(store) to extract community metadata from the graph store. Each community dictionary contains:
name– The community identifiersize– Number of memberscohesion– Internal connection strengthdominant_language– Primary programming languagedescription– Structural descriptionmembers– List of qualified names belonging to the community
Page Rendering with Safe File Operations
For every discovered community, the generator creates a dedicated Markdown file through _generate_community_page. The rendering process includes several safety and formatting layers:
Slug Generation
The _slugify helper (lines 23–27 in code_review_graph/wiki.py) converts community names into filesystem-safe identifiers by lower-casing, replacing non-alphanumeric characters with hyphens, and truncating to 80 characters.
Content Structure Each generated page contains four specific sections:
- Overview – Community metadata and characteristics
- Members – Table of community members (limited to the first 50 entries)
- Execution Flows – Entry points and call chains discovered in the graph
- Dependencies – External relationships and imports
All node details are retrieved via store.get_node(qn) and sanitized using _sanitize_name from code_review_graph/graph.py to prevent injection issues.
Index Generation
After processing all communities, the system generates an index.md file (line 257) that serves as the wiki homepage, linking to every community page with proper relative paths.
Optional LLM Summaries
The high-level tool generate_wiki_func exposed in code_review_graph/tools/docs.py wraps the core generation logic and adds optional AI summarization capabilities.
How the LLM Integration Works
When invoked with summary=True, the tool performs the following operations:
- Context Preparation – Collects the community description and structural metadata
- LLM Invocation – Routes the request through the generic LLM client in
code_review_graph.main, supporting OpenAI, Azure, LiteLLM, and vLLM backends - Content Injection – Inserts the generated natural language text into the Overview section before the static bullet points (see line 82 in
tools/docs.py)
The LLM receives a prompt requesting a concise summary of the community’s purpose and key characteristics, augmenting the deterministic structural data with human-readable context.
Default Behavior
When summary=False (the default), the wiki contains only the deterministic information extracted directly from the graph store. This mode requires no external API calls and completes entirely offline.
Helper Functions and Safety Features
The wiki module includes utility functions for safe page retrieval and path handling:
get_wiki_page(wiki_dir, slug)– Retrieves content from the wiki directory with path-traversal protection, returning the Markdown string orNoneif the page does not exist_sanitize_name– Prevents markdown injection by escaping special characters in qualified names
Implementation Examples
Basic Deterministic Generation
Generate a structural wiki without LLM augmentation:
from code_review_graph.wiki import generate_wiki
result = generate_wiki(store, "/tmp/my_wiki")
print(result)
# Output: {"pages_generated": 12, "pages_updated": 0, "pages_unchanged": 0}
LLM-Enriched Wiki Generation
Enable natural language summaries using the tools wrapper:
from code_review_graph.tools.docs import generate_wiki_func
result = generate_wiki_func(
store=store,
wiki_dir="/tmp/my_wiki",
summary=True, # Enable LLM summaries
force=False # Only regenerate changed pages
)
Safe Page Retrieval
Access individual pages without directory traversal risks:
from code_review_graph.wiki import get_wiki_page
content = get_wiki_page("/tmp/my_wiki", "data-processing")
print(content) # Returns Markdown string or None
Source File Reference
| File | Purpose |
|---|---|
code_review_graph/wiki.py |
Core generation logic including generate_wiki, _slugify, and _generate_community_page |
code_review_graph/tools/docs.py |
High-level interface generate_wiki_func with optional LLM summarization |
code_review_graph/communities.py |
Community detection via get_communities |
code_review_graph/graph.py |
GraphStore implementation and _sanitize_name utility |
tests/test_wiki.py |
Test coverage for page generation, index linking, and path traversal safety |
Summary
- Community-driven structure – Wiki pages map directly to communities discovered in the code graph via
get_communities - Deterministic rendering – The
_generate_community_pagefunction creates consistent Markdown output containing Overview, Members, Execution Flows, and Dependencies sections - Optional AI augmentation – Passing
summary=Truetogenerate_wiki_funcinvokes the configured LLM to generate natural language descriptions inserted into each page - Safe file operations – The
_slugifyhelper ensures valid filenames whileget_wiki_pageprevents path traversal attacks - Modular architecture – Core generation logic resides in
wiki.pywhile the LLM wrapper lives intools/docs.py, allowing both modes to share the same underlying pipeline
Frequently Asked Questions
How do I enable LLM summaries for my wiki?
Pass summary=True when calling generate_wiki_func from code_review_graph.tools.docs. This triggers the LLM client configured in code_review_graph.main to generate descriptions for each community page. Ensure your environment has the appropriate API keys configured for your chosen LLM provider (OpenAI, Azure, etc.).
What happens if a community name contains special characters?
The _slugify function in code_review_graph/wiki.py automatically converts community names to safe filenames by lower-casing the string, replacing non-alphanumeric characters with hyphens, and truncating to 80 characters. This prevents filesystem errors while maintaining readable URLs.
Can I generate a wiki without using an external LLM service?
Yes. The generate_wiki function in code_review_graph/wiki.py operates entirely offline using only the graph store data. Omit the summary parameter or set it to False when using generate_wiki_func to skip all LLM API calls and generate purely structural documentation.
How does the system prevent path traversal when accessing wiki pages?
The get_wiki_page function validates the requested slug against the wiki directory before reading any files, ensuring callers cannot escape the wiki root using .. sequences or absolute paths. This safety mechanism is tested in tests/test_wiki.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →