Architecture
Technical architecture of Ripperdoc
This document describes the internal architecture of Ripperdoc.
Overview
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLI Layer β
β (ripperdoc/cli/) β
β - Terminal UI, Commands, User Interaction β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Core Layer β
β (ripperdoc/core/) β
β - Query Loop, Tool Registry, Permissions, Hooks β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ
β Providers β β Tools β β Utilities β
β (core/providers/)β β (tools/) β β (utils/) β
β - Anthropic β β - Bash β β - File Watch β
β - OpenAI β β - Read β β - Session Mgmt β
β - Gemini β β - Edit β β - Logging β
β - DeepSeek β β - Glob β β - Permissions β
βββββββββββββββββββββ β - Grep β βββββββββββββββββββββββ
β - Task β
β - ... β
βββββββββββββββCore Components
Query Loop (core/query.py)
The main query loop handles:
- Building the system prompt with tool definitions
- Sending messages to the LLM provider
- Parsing tool calls from responses
- Executing tools and collecting results
- Handling errors and context overflow
async def query(messages, system_prompt, context, query_context):
for iteration in range(MAX_ITERATIONS):
# Build full prompt
full_prompt = build_full_system_prompt(...)
# Call LLM
response = await query_llm(messages, full_prompt, tools)
# Extract and execute tool calls
tool_calls = extract_tool_use_blocks(response)
for tool_call in tool_calls:
result = await execute_tool(tool_call)
# Continue or return based on responseTool System (core/tool.py)
Tools follow a common interface:
class Tool(Generic[TInput, TOutput]):
@property
def name(self) -> str: ...
@property
def input_schema(self) -> type[TInput]: ...
async def validate_input(self, input_data, context) -> ValidationResult: ...
async def call(self, input_data, context) -> AsyncGenerator[ToolOutput]: ...
def needs_permissions(self, input_data) -> bool: ...Provider Abstraction (core/providers/)
Providers normalize different LLM APIs:
class ProviderClient:
async def call(
self,
model_profile: ModelProfile,
system_prompt: str,
normalized_messages: List[Dict],
tools: List[Tool],
**kwargs
) -> ProviderResponse: ...Hook System (core/hooks/)
Hooks intercept lifecycle events:
Event Flow:
1. UserPromptSubmit β User sends message
2. PreToolUse β Before tool execution
3. PermissionRequest β When permission needed
4. PostToolUse β After tool completes
5. Stop β Agent finishes respondingData Flow
Message Flow
User Input
β
βΌ
ββββββββββββββββββ
β CLI Input β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ ββββββββββββββββββ
β Hook: Submit ββββββΆβ May modify β
βββββββββ¬βββββββββ β or block β
β ββββββββββββββββββ
βΌ
ββββββββββββββββββ
β Query Loop β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β LLM Provider β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Tool Execution βββββββ Hooks: Pre/Post
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Response β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β CLI Output β
ββββββββββββββββββTool Execution Flow
Tool Call (from LLM)
β
βΌ
ββββββββββββββββββ
β Resolve Tool β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Parse Input β β Pydantic validation
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β PreToolUse β β Hook can block/modify
β Hook β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Permission β β May prompt user
β Check β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β Execute Tool β β Yields progress/result
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββββββββ
β PostToolUse β β Hook can add context
β Hook β
ββββββββββββββββββKey Modules
ripperdoc/cli/
cli.py- Main entry pointui/- Terminal UI componentscommands/- Slash command implementations
ripperdoc/core/
query.py- Main query looptool.py- Tool base classpermissions.py- Permission checkingconfig.py- Configuration managementproviders/- LLM provider implementationshooks/- Hook system
ripperdoc/tools/
23 tool implementations for file operations, search, execution, etc.
ripperdoc/utils/
file_watch.py- File change detectionsession_*.py- Session managementconversation_compaction.py- Context compactionpermissions/- Permission utilities
Extension Points
Adding Providers
- Create
ripperdoc/core/providers/my_provider.py - Implement
ProviderClientinterface - Register in provider factory
Adding Tools
- Create
ripperdoc/tools/my_tool.py - Extend
Toolbase class - Register in
default_tools.py
Adding Hooks
- Define hook event in
hooks/events.py - Implement handler in
hooks/executor.py - Integrate in query loop
Performance Considerations
- Streaming: All LLM responses stream for responsiveness
- Caching: File contents cached to avoid re-reading
- Compaction: Automatic context compaction for long sessions
- Concurrency: Safe tools run in parallel