Extension System Architecture
This document describes the technical architecture of the Radium extension system.
Overviewβ
The extension system is implemented in crates/radium-core/src/extensions/ and consists of seven core modules:
- manifest.rs - Manifest parsing and validation
- structure.rs - Extension directory structure and validation
- installer.rs - Installation from multiple sources with dependency resolution
- discovery.rs - Extension discovery and search
- integration.rs - Integration helpers for system components
- conflict.rs - Conflict detection for file and component overlaps
- validator.rs - Extension validation logic
Module Breakdownβ
Manifest Module (manifest.rs)β
The manifest module handles parsing and validation of radium-extension.json files.
Key Types:
ExtensionManifest- Main manifest structureExtensionComponents- Component path definitionsExtensionManifestError- Manifest-specific errors
Validation Rules:
- Name must be alphanumeric with dashes/underscores, starting with a letter
- Version must follow semantic versioning (semver)
- Component paths cannot be empty
- All required fields must be present
Example:
let manifest = ExtensionManifest::load(&manifest_path)?;
manifest.validate()?;
Structure Module (structure.rs)β
The structure module defines extension directory organization and provides path resolution.
Key Types:
Extension- Represents an installed extensionExtensionStructureError- Structure-specific errors
Directory Constants:
COMPONENT_PROMPTS- "prompts"COMPONENT_MCP- "mcp"COMPONENT_COMMANDS- "commands"COMPONENT_HOOKS- "hooks"MANIFEST_FILE- "radium-extension.json"
Path Resolution:
prompts_dir()- Returns path to prompts directorymcp_dir()- Returns path to MCP directorycommands_dir()- Returns path to commands directoryhooks_dir()- Returns path to hooks directory
Installation Locations:
- User-level:
~/.radium/extensions/ - Workspace-level:
.radium/extensions/(project root)
Installer Module (installer.rs)β
The installer module handles installation from multiple sources with dependency resolution.
Key Types:
ExtensionManager- Main installation managerInstallOptions- Installation configurationExtensionInstallerError- Installer-specific errors
Installation Sources:
- Local directories
- Archive files (
.tar.gz,.zip) - URLs (HTTP/HTTPS)
Installation Flow:
- Validate source and manifest
- Check for conflicts
- Resolve dependencies (if
install_dependenciesis true) - Copy files to extensions directory
- Validate structure (if
validate_after_installis true)
Dependency Resolution:
- Recursively installs declared dependencies
- Detects dependency cycles
- Validates dependency versions (future enhancement)
Discovery Module (discovery.rs)β
The discovery module finds and loads installed extensions.
Key Types:
ExtensionDiscovery- Discovery serviceDiscoveryOptions- Discovery configurationExtensionDiscoveryError- Discovery-specific errors
Discovery Methods:
discover_all()- Discovers all extensions in search pathsdiscover_in_directory()- Discovers extensions in specific directoryget()- Gets extension by namesearch()- Searches extensions by query
Search Paths:
- Default:
~/.radium/extensions/ - Custom: Can be configured via
DiscoveryOptions
Integration Module (integration.rs)β
The integration module provides helper functions for integrating extension components into system components.
Integration Functions:
get_extension_prompt_dirs()- Returns prompt directories from all extensionsget_extension_command_dirs()- Returns command directories from all extensionsget_extension_mcp_configs()- Returns MCP config paths from all extensionsget_extension_hook_paths()- Returns hook file paths from all extensionsget_all_extensions()- Returns all installed extensions
Usage Pattern:
let prompt_dirs = get_extension_prompt_dirs()?;
for dir in prompt_dirs {
// Load prompts from directory
}
Conflict Module (conflict.rs)β
The conflict module detects conflicts between extension components and existing components.
Key Types:
ConflictDetector- Conflict detection serviceConflictError- Conflict-specific errors
Conflict Checks:
- Agent ID conflicts
- Template name conflicts
- Command name conflicts
- Dependency cycles
Conflict Detection Flow:
- Discover existing components (agents, templates, commands)
- Scan extension package for components
- Compare names/IDs
- Report conflicts before installation
Validator Module (validator.rs)β
The validator module provides comprehensive extension validation.
Validation Checks:
- Manifest validity
- Structure correctness
- Component file existence
- Path resolution
- Dependency availability
Integration Pointsβ
Agent Discovery Integrationβ
Location: crates/radium-core/src/agents/discovery.rs
Agent discovery should call get_extension_prompt_dirs() to include extension prompts in the search paths. Extension prompts are discovered with lower precedence than built-in prompts.
Integration Pattern:
let mut search_paths = default_search_paths();
let extension_dirs = get_extension_prompt_dirs()?;
search_paths.extend(extension_dirs);
MCP System Integrationβ
Location: crates/radium-core/src/mcp/config.rs
The MCP config manager should call get_extension_mcp_configs() during initialization to load extension-provided MCP server configurations. Extension configs are merged with workspace configs.
Integration Pattern:
let mut servers = load_workspace_configs()?;
let extension_configs = get_extension_mcp_configs()?;
for config_path in extension_configs {
let config = load_mcp_config(&config_path)?;
servers.push(config);
}
Command Registry Integrationβ
Location: crates/radium-core/src/commands/custom.rs
The command registry already integrates with extensions via get_extension_command_dirs(). Extension commands are discovered with lower precedence than user/project commands.
Current Implementation:
- Extension commands are loaded first (lowest precedence)
- User commands override extension commands
- Project commands override both (highest precedence)
- Extension commands are namespaced with extension name
Conflict Detection Mechanismβ
The conflict detection system prevents installation of extensions that would conflict with existing components.
Conflict Typesβ
- Agent Conflicts: Extension agent IDs match existing agent IDs
- Template Conflicts: Extension template names match existing templates
- Command Conflicts: Extension command names match existing commands
- Dependency Cycles: Circular dependencies between extensions
Detection Flowβ
- Before installation,
ConflictDetector::check_conflicts()is called - System discovers existing components
- Extension package is scanned for components
- Names/IDs are compared
- Conflicts are reported as errors
Resolutionβ
- Conflicts prevent installation by default
- Use
--overwriteflag to allow overwriting (future: may allow selective overwrite) - Dependency cycles are always errors
Dependency Resolution Flowβ
When installing an extension with dependencies:
- Parse manifest and extract dependencies
- Check if dependencies are already installed
- For each missing dependency:
- Resolve dependency source (if provided)
- Install dependency recursively
- Validate dependency installation
- Check for dependency cycles
- Install main extension
Dependency Cycle Detectionβ
The system detects cycles by:
- Building dependency graph
- Performing depth-first search
- Detecting back edges (cycles)
Extension Discovery Orderβ
Extensions are discovered in the following order (precedence from highest to lowest):
- Project-level extensions (
.radium/extensions/) - User-level extensions (
~/.radium/extensions/)
Within each level, extensions are processed in alphabetical order by name.
Component Discovery Orderβ
Promptsβ
- Built-in prompts (from
prompts/directory) - Project-level extension prompts
- User-level extension prompts
MCP Serversβ
- Workspace MCP config (
.radium/mcp-servers.toml) - Extension MCP configs (merged)
Commandsβ
- Extension commands (lowest precedence)
- User commands
- Project commands (highest precedence)
Extension commands are namespaced: extension-name:command-name
Error Handlingβ
All extension operations use structured error types:
ExtensionManifestError- Manifest parsing/validation errorsExtensionStructureError- Structure validation errorsExtensionInstallerError- Installation errorsExtensionDiscoveryError- Discovery errorsConflictError- Conflict detection errorsExtensionValidationError- Validation errors
These are unified into ExtensionError for public API.
Testingβ
Comprehensive test coverage includes:
- Unit tests for each module
- Integration tests for installation workflows
- Edge case tests for validation
- Security tests for path traversal prevention
- Conflict detection tests
- Archive handling tests
- Benchmark tests for performance
Test files are located in crates/radium-core/tests/extension_*_test.rs.
Future Enhancementsβ
Potential future enhancements (out of scope for REQ-102):
- Extension marketplace
- Extension versioning system
- Extension signing and verification
- Extension update mechanism
- Extension metadata search
- Extension ratings/reviews