Why configuration, context and lifecycle are separate
A translator combines three kinds of information: validated configuration, mutable workflow state, and operations on that state. Keeping those responsibilities separate lets a hook be tested without launching the CLI or loading a real model dataset.
Configuration describes intent
Section titled “Configuration describes intent”PluginConfig is a Pydantic model. Its fields describe settings, while a
PluginContext carries systems, file stores, rules and metadata between hooks.
A class plugin receives this context through from_context() and accesses
public properties such as config, system and store.
It does not need to override those properties or read _ctx.
Hooks make ordering explicit
Section titled “Hooks make ordering explicit”on_build() returns the system for a later on_transform() or on_export().
Only implemented hooks run. This ordering makes dependencies visible, but it does
not provide rollback: changes made before a failed hook may remain.
The lifecycle tutorial checks success and
failure paths with a complete implementation. The reference
records the exact hook order and result contracts.
Class plugins and function transforms
Section titled “Class plugins and function transforms”A class is useful when several lifecycle stages share context. An exposed function is useful for a single transform with explicit system and configuration arguments. This complete example shows that the function changes a supplied system:
>>> from r2x_core import PluginConfig, System, expose_plugin>>> from rust_ok import Ok, Result>>> class RenameConfig(PluginConfig):... name: str = "renamed">>> @expose_plugin... def rename(system: System, config: RenameConfig) -> Result[System, str]:... system.name = config.name... return Ok(system)>>> system = System(name="original")>>> result = rename(system, RenameConfig())>>> # Expected: a successful Result contains the same changed system.>>> result.unwrap().name# 'renamed'>>> assert result.unwrap() is systemDiscovery belongs to the installed package boundary
Section titled “Discovery belongs to the installed package boundary”The Rust CLI discovers registered entry points and manages its own Python environment. Adding core to a separate project does not install a translator there. See plugin discovery and the CLI guide to managing plugins. Installing a plugin runs Python code with the host process’s permissions. It is not a sandbox.