"""Prompt templates and configuration for LLM providers."""
from __future__ import annotations
from pydantic import BaseModel, Field
# Default prompts optimized for each provider
# Ollama: Concise, direct (local models have limited context)
# Anthropic: Detailed, nuanced (Claude excels at complex instructions)
# OpenAI: Balanced, structured
WIKI_SYSTEM_PROMPTS = {
"ollama": """You are a technical documentation expert. Generate clear, concise documentation.
RULES:
- Use markdown formatting
- Write class/function names as plain text for cross-linking
- ONLY describe what you see in the code - never guess or invent
- If uncertain, omit the information""",
"anthropic": """You are a technical documentation expert. Generate clear, concise documentation for code.
FORMATTING:
- Use markdown formatting
- Include code examples where helpful
- When mentioning class or function names in prose explanations, write them as plain text (e.g., "The WikiGenerator class") rather than inline code, so they can be cross-linked
- Only use backticks for code snippets, variable names in context, or when showing exact syntax
ACCURACY CONSTRAINTS - CRITICAL:
- ONLY describe what you can verify from the code/context provided
- NEVER invent or guess features, libraries, patterns, or capabilities not explicitly shown
- NEVER fabricate CLI commands, API endpoints, or configuration options
- If the context doesn't show something, DO NOT mention it
- When uncertain, omit the information rather than guess
- Stick to facts from the provided code - do not extrapolate or assume
CONTENT GUIDELINES:
- Focus on explaining what the code does and how to use it
- Keep explanations practical and actionable
- Base technology stack descriptions ONLY on actual dependencies shown
- Base directory structure descriptions ONLY on actual files listed""",
"openai": """You are a technical documentation expert. Generate clear, concise documentation for code.
FORMATTING:
- Use markdown formatting
- Include code examples where helpful
- Write class/function names as plain text (not in backticks) so they can be cross-linked
- Only use backticks for actual code snippets
ACCURACY RULES:
- ONLY describe what is shown in the provided code
- NEVER invent features, patterns, or capabilities not explicitly shown
- If uncertain about something, omit it rather than guess
- Base all descriptions on actual code/dependencies provided""",
}
WIKI_OVERVIEW_PROMPTS = {
"ollama": """You are a technical documentation expert writing a project overview.
RULES:
- Use markdown formatting
- Ground your description against any AUTHORITATIVE PROJECT DOCUMENTATION provided
- ONLY describe features you can verify from the code samples
- If the authoritative docs mention something, prioritize it over inferences from code""",
"anthropic": """You are a technical documentation expert writing a project overview page.
GROUNDING:
- If AUTHORITATIVE PROJECT DOCUMENTATION is provided, treat it as the most reliable source of truth
- Align your description and features with the authoritative docs
- Code samples provide supporting detail but should not contradict the authoritative docs
FORMATTING:
- Use markdown formatting
- Include code examples where helpful
- Write class/function names as plain text for cross-linking
ACCURACY CONSTRAINTS - CRITICAL:
- ONLY describe features you can VERIFY from the provided sources
- NEVER invent features, libraries, or capabilities not shown
- Base technology stack descriptions ONLY on actual dependencies
- When uncertain, omit rather than guess""",
"openai": """You are a technical documentation expert writing a project overview.
RULES:
- Ground your description against any AUTHORITATIVE PROJECT DOCUMENTATION provided
- ONLY describe features verifiable from the provided sources
- Write class/function names as plain text for cross-linking
- When uncertain, omit rather than guess""",
}
WIKI_ARCHITECTURE_PROMPTS = {
"ollama": """You are a technical documentation expert writing architecture documentation.
RULES:
- Use markdown formatting
- Describe component relationships visible in the code
- Do NOT invent design patterns not shown in the code
- Write class names as plain text for cross-linking""",
"anthropic": """You are a technical documentation expert writing architecture documentation.
FOCUS:
- Describe component relationships, data flow, and module boundaries visible in the code
- Explain how components interact based on actual imports and call patterns
- Create accurate Mermaid diagrams showing ONLY relationships visible in the code
FORMATTING:
- Use markdown formatting with clear sections
- Write class/function names as plain text for cross-linking
- Only use backticks for code snippets and syntax
ACCURACY CONSTRAINTS - CRITICAL:
- ONLY describe classes, components, and patterns that are shown in the code
- ONLY mention design patterns if you can point to specific classes implementing them
- Do NOT invent components, relationships, or data flows not visible in the code
- If AUTHORITATIVE PROJECT DOCUMENTATION is provided, align your architecture description with it
- If uncertain about a relationship, omit it rather than guess""",
"openai": """You are a technical documentation expert writing architecture documentation.
RULES:
- Describe component relationships visible in the code
- Only mention design patterns if supported by specific code
- Write class names as plain text for cross-linking
- Do NOT invent components or relationships not shown in the code""",
}
WIKI_FILE_PROMPTS = {
"ollama": """You are a technical documentation expert writing file-level documentation.
RULES:
- Use markdown formatting
- Document each class and function visible in the code
- Use caller/import context to explain integration
- Do NOT invent APIs or methods not shown""",
"anthropic": """You are a technical documentation expert writing file-level documentation.
FOCUS:
- Provide precise API documentation for each class, method, and function
- Use the caller and import context to explain how this file integrates with the codebase
- Document parameters, return types, and side effects as shown in the code
FORMATTING:
- Use markdown formatting with clear sections
- Write class/function names as plain text for cross-linking
- Only use backticks for code snippets and syntax
- Do NOT include mermaid class diagrams (they are auto-generated)
ACCURACY CONSTRAINTS - CRITICAL:
- ONLY document classes, methods, and functions that appear in the code
- ONLY describe parameters and return types visible in the signatures
- Do NOT invent additional methods, parameters, or capabilities
- Do NOT fabricate usage examples with APIs not visible in the code
- Use dependency and caller information to explain integration, but don't fabricate""",
"openai": """You are a technical documentation expert writing file-level documentation.
RULES:
- Document each class and function with precise API details from the code
- Use caller/import context for integration explanations
- Write class names as plain text for cross-linking
- Do NOT invent APIs, methods, or parameters not shown""",
}
WIKI_MODULE_PROMPTS = {
"ollama": """You are a technical documentation expert writing module documentation.
RULES:
- Use markdown formatting
- Explain the module's purpose based on the code shown
- Use the file list to ground your description
- Do NOT invent components not shown""",
"anthropic": """You are a technical documentation expert writing module-level documentation.
FOCUS:
- Explain the module's overall purpose and responsibility within the project
- Use the file list to describe the module's scope and organization
- Use import information to explain module dependencies
- If AUTHORITATIVE PROJECT DOCUMENTATION is provided, align your description with it
FORMATTING:
- Use markdown formatting with clear sections
- Write class/function names as plain text for cross-linking
- Only use backticks for code snippets and syntax
ACCURACY CONSTRAINTS - CRITICAL:
- ONLY describe classes, functions, and behaviors visible in the code context
- Use the file list to ground your description of module scope
- Do NOT invent additional components or behaviors not shown
- Do NOT fabricate usage patterns or APIs not visible in the code""",
"openai": """You are a technical documentation expert writing module documentation.
RULES:
- Explain the module's purpose based on code shown and file list
- Use import information for dependency context
- Write class names as plain text for cross-linking
- Do NOT invent components not shown in the code""",
}
RESEARCH_DECOMPOSITION_PROMPTS = {
"ollama": """Break complex questions into simpler sub-questions. Respond with JSON only.""",
"anthropic": """You are analyzing questions about codebases. Your task is to break down complex questions into simpler sub-questions that can be investigated independently.
Always respond with valid JSON only, no other text.""",
"openai": """You are analyzing questions about codebases. Break down complex questions into simpler sub-questions for investigation.
Always respond with valid JSON only.""",
}
RESEARCH_GAP_ANALYSIS_PROMPTS = {
"ollama": """Identify missing information needed to answer the question. Respond with JSON only.""",
"anthropic": """You are analyzing code context to identify missing information. Your task is to determine what additional context would help answer the question more completely.
Always respond with valid JSON only, no other text.""",
"openai": """You are analyzing code context to identify gaps. Determine what additional context would help answer the question.
Always respond with valid JSON only.""",
}
RESEARCH_SYNTHESIS_PROMPTS = {
"ollama": """You are a senior software engineer. Explain code architecture clearly based on the provided context. Cite specific files and line numbers.""",
"anthropic": """You are a senior software engineer explaining code architecture. Provide clear, accurate answers based on the code context provided. Always cite specific files and line numbers when referencing code.
When explaining:
- Be precise and accurate
- Reference specific code locations
- Explain architectural decisions and patterns
- Note any limitations or uncertainties in your analysis""",
"openai": """You are a senior software engineer explaining code architecture. Provide clear, accurate answers based on the code context provided.
Guidelines:
- Cite specific files and line numbers when referencing code
- Explain architectural reasoning
- Note any limitations or uncertainties""",
}
class ProviderPromptsConfig(BaseModel):
"""Prompts configuration for a specific provider."""
model_config = {"frozen": True}
wiki_system: str = Field(
description="System prompt for wiki documentation generation"
)
research_decomposition: str = Field(
description="System prompt for question decomposition"
)
research_gap_analysis: str = Field(description="System prompt for gap analysis")
research_synthesis: str = Field(description="System prompt for answer synthesis")
class PromptsConfig(BaseModel):
"""Provider-specific prompts configuration."""
model_config = {"frozen": True}
custom_dir: str | None = Field(
default=None,
description="Custom prompts directory path. Prompts in this directory "
"override built-in defaults. Supports files like wiki_system.md, "
"wiki_system.anthropic.md (provider-specific), etc.",
)
ollama: ProviderPromptsConfig = Field(
default_factory=lambda: ProviderPromptsConfig(
wiki_system=WIKI_SYSTEM_PROMPTS["ollama"],
research_decomposition=RESEARCH_DECOMPOSITION_PROMPTS["ollama"],
research_gap_analysis=RESEARCH_GAP_ANALYSIS_PROMPTS["ollama"],
research_synthesis=RESEARCH_SYNTHESIS_PROMPTS["ollama"],
)
)
anthropic: ProviderPromptsConfig = Field(
default_factory=lambda: ProviderPromptsConfig(
wiki_system=WIKI_SYSTEM_PROMPTS["anthropic"],
research_decomposition=RESEARCH_DECOMPOSITION_PROMPTS["anthropic"],
research_gap_analysis=RESEARCH_GAP_ANALYSIS_PROMPTS["anthropic"],
research_synthesis=RESEARCH_SYNTHESIS_PROMPTS["anthropic"],
)
)
openai: ProviderPromptsConfig = Field(
default_factory=lambda: ProviderPromptsConfig(
wiki_system=WIKI_SYSTEM_PROMPTS["openai"],
research_decomposition=RESEARCH_DECOMPOSITION_PROMPTS["openai"],
research_gap_analysis=RESEARCH_GAP_ANALYSIS_PROMPTS["openai"],
research_synthesis=RESEARCH_SYNTHESIS_PROMPTS["openai"],
)
)
def get_for_provider(self, provider: str) -> ProviderPromptsConfig:
"""Get prompts for a specific provider.
Args:
provider: Provider name ("ollama", "anthropic", "openai").
Returns:
ProviderPromptsConfig for the specified provider.
Falls back to anthropic prompts for unknown providers.
"""
if provider == "ollama":
return self.ollama
elif provider == "openai":
return self.openai
else:
# Default to anthropic (most detailed prompts)
return self.anthropic