Module Loader
Handles module installation, loading, and management.
ModuleManifest
Pydantic model for module.json validation.
python
class ModuleManifest(BaseModel):
id: str
name: str
version: str
description: str = ""
entrypoint: str = "main.py"
inputs: list[ModuleInput] = []
settings: list[ModuleSetting] = []
capabilities: list[str] = []ModuleLoader
Methods
install
python
async def install(self, source_path: str) -> ModuleManifestInstall a module from a local directory.
- Validates
module.jsonexists - Copies directory to modules dir
- Installs
requirements.txtif present - Registers module in database
Returns: Parsed module manifest
install_from_git
python
async def install_from_git(
self,
repo_url: str,
module_name: Optional[str] = None,
) -> ModuleManifestInstall a module from a git repository.
Parameters:
repo_url— Git repository URL (HTTPS, SSH, or git@ format)module_name— Subdirectory containing the module (for monorepos)
Process:
- Clone repository to temp directory (depth 1)
- Locate module.json in root or specified subdirectory
- Call
install()with the module path
Raises:
ValueError— Invalid URL or git operation failedFileNotFoundError— module.json not found
uninstall
python
async def uninstall(self, module_id: str) -> boolUninstall a module. Removes files and database entry.
get
python
async def get(self, module_id: str) -> Optional[dict]Get module information from database.
list
python
async def list(self) -> list[dict]List all installed modules.
load_class
python
async def load_class(self, module_id: str) -> AnyDynamically load and return the Module subclass from a module’s entrypoint.
Process:
- Check cache for already-loaded modules
- Load module info from database
- Import entrypoint file using
importlib - Find first class that subclasses
Module - Cache and return the class
discover_modules
python
async def discover_modules(self) -> intScan modules directory for unregistered modules and auto-install them.
Useful for manually-placed modules or post-restore scenarios.
Returns: Number of newly discovered modules.
validate_inputs
python
def validate_inputs(
self,
manifest: ModuleManifest,
inputs: dict[str, Any],
) -> dict[str, Any]Validate and normalize inputs against manifest.
- Applies default values
- Converts types (number, integer, boolean)
- Raises
ValueErrorfor missing required inputs
sync_modules
python
async def sync_modules(self) -> dict[str, Any]Sync modules from configured sources in modules.yaml.
Process:
- Load
module_sourcesfrom config - For each source, clone repo and install specified modules
- Continue on errors, collect results
Returns:
python
{
"installed": [...], # Successfully installed
"failed": [...], # Failed with errors
"skipped": [...] # Skipped (already up to date)
}Module Discovery Flow
On daemon startup:
ModuleLoader.discover_modules()scans modules directory- Finds subdirectories with
module.json - Auto-installs any not registered in database
- Logs discovered modules