lucem_ml
lucem-ml: how lucem talks to machine-learning models, without containing any.
Models come as plugins: separate programs named lucem-ml-<family> (as dsp-kitchen’s
sorters), each built from one crate per upstream model family under models/, each under its
upstream’s licence, with its own runtime (ONNX Runtime, Burn, …). The app and the command line
never link them, so a model never adds weight, licences or a runtime to lucem itself, and a
plugin can be installed, updated or removed on its own.
manifest: what a plugin offers — its models, their task (interactive segmentation, segmentation, detection, classification), weights, licence and provenance — as data.protocol: the requests and events, JSON lines over the program’s stdin and stdout; images and masks travel as raw files in a scratch folder.discover: finding the plugin programs ($LUCEM_PLUGINS, the user’s plugin folder, next to the app) and asking each for its manifest.client: a plugin running in server mode (<program> serve), kept alive between requests so a model stays loaded (and SAM keeps its image embedding between clicks).
Workspace layout (see .tasks/2026-11-10_round5-tasks.md):
crates/lucem-ml this contract (the app depends on it; serde only)hub/lucem-hub verified downloads and the model cache (all network access)models/<family> one crate per upstream family (models/sam: SAM 2, Apache-2.0)plugins/ml/lucem-ml-<fam> the program the app runs, over the protocolPluginProcess
Section titled “PluginProcess”pub struct PluginProcessFields
program: String
Methods
pub fn start(program: &str) -> Result<Self, String>Starts program serve.
pub fn alive(&mut self) -> boolWhether the program is still running.
pub fn request( &mut self, req: &Request, progress: &mut dyn FnMut(&str, Option<f32>),) -> Result<Value, String>Sends a request and reads events until its answer; progress sees the progress events.
Implements Drop.
Weight
Section titled “Weight”pub struct WeightA file a model needs, verified by hash before use.
Fields
file: Stringurl: Stringsha256: String: Lowercase hex SHA-256 (a file without one is refused).bytes: u64
Implements Clone, Debug, Deserialize, Eq, PartialEq, Serialize.
ModelInfo
Section titled “ModelInfo”pub struct ModelInfoOne model of a plugin.
Fields
id: String: Unique among all plugins (sam2-hiera-tiny).name: Stringfamily: String: The upstream family (sam,stardist, …).task: Taskdomains: Vec<String>: The images it is made for (histology,fluorescence,natural): the app lists a histology model where histology is analysed.description: Stringlicence: String: The licence of the model and its weights (SPDX).paper: Option<String>: Whom to credit: the paper and the upstream code.code: Option<String>weights: Vec<Weight>installed: bool: Its weights are downloaded and verified.default: bool: The plugin’s suggestion when the user has not chosen.channels: u32: Channels its images have: 3 (RGB, e.g. H&E) or 1 (one fluorescence channel); 0: not said (RGB).
Methods
pub fn download_bytes(&self) -> u64Implements Clone, Debug, Deserialize, PartialEq, Serialize.
RuntimeStatus
Section titled “RuntimeStatus”pub struct RuntimeStatusWhether the plugin’s runtime can run here, and why not.
Fields
ready: booldetail: String: What runs the models (ONNX Runtime 1.22.1 (CUDA, CPU)), or what is missing and how to get it.gpu: Option<GpuRuntime>: A GPU build of the runtime the plugin can install (install runtime-cuda), when it has one.
Implements Clone, Debug, Deserialize, Eq, PartialEq, Serialize.
GpuRuntime
Section titled “GpuRuntime”pub struct GpuRuntimeA plugin’s optional GPU runtime.
Fields
installed: boolusable: bool: Installed and everything it needs is there (a driver, libraries such as cuDNN).bytes: u64detail: String: What it is, or what it still needs.
Implements Clone, Debug, Deserialize, Eq, PartialEq, Serialize.
PluginInfo
Section titled “PluginInfo”pub struct PluginInfoA plugin program and what it offers.
Fields
name: Stringversion: Stringlicence: String: The program’s licence (it may differ from lucem’s).runtime: RuntimeStatusmodels: Vec<ModelInfo>program: String: Where it was found (set bycrate::discover, not by the plugin).
Methods
pub fn model(&self, id: &str) -> Option<&ModelInfo>Implements Clone, Debug, Deserialize, PartialEq, Serialize.
RasterRef
Section titled “RasterRef”pub struct RasterRefA raster in a file: width × height × channels bytes, row by row (RGB for images, one byte
per pixel for masks).
Fields
path: Stringwidth: u32height: u32channels: u32
Methods
pub fn len(&self) -> usizepub fn is_empty(&self) -> boolImplements Clone, Debug, Deserialize, Eq, PartialEq, Serialize.
InstanceClass
Section titled “InstanceClass”pub struct InstanceClassA label’s class, when the model classifies what it finds (Neoplastic, Inflammatory).
Fields
label: u32class: Stringscore: Option<f32>
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
InstancesResult
Section titled “InstancesResult”pub struct InstancesResultThe answer to Request::Instances: the labels (channels 1, 4 bytes per pixel,
little-endian u32) and the classes of those it classified.
Fields
labels: RasterRefclasses: Vec<InstanceClass>ms: f64
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
MaskOut
Section titled “MaskOut”pub struct MaskOutA mask the plugin wrote, and how sure it is.
Fields
raster: RasterRefscore: f32
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
SegmentResult
Section titled “SegmentResult”pub struct SegmentResultThe answer to Request::Segment, best first.
Fields
masks: Vec<MaskOut>encode_ms: f64: Milliseconds spent encoding the image (0 when reused) and decoding the prompts.decode_ms: f64
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
pub enum TaskWhat a model does.
Variants
InteractiveSegmentation: A mask from prompts (points, boxes): SAM.Segmentation: Every object of a region as labels: nuclei, cells.Detection: Points or boxes of objects.Classification: A class per object or region.Embedding: A feature vector per patch (a foundation model’s embedding), for classifiers downstream.
Methods
pub fn title(self) -> &'static strImplements Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize.
Prompt
Section titled “Prompt”pub enum PromptA prompt, in pixels of the image sent.
Variants
Point { x: f32, y: f32, positive: bool }: A point on (positive) or off the object.Box { x0: f32, y0: f32, x1: f32, y1: f32 }: A box around the object.
Implements Clone, Copy, Debug, Deserialize, PartialEq, Serialize.
Request
Section titled “Request”pub enum RequestVariants
Info: The plugin’s manifest (as<program> info).Install { model: String }: Downloads and verifies a model’s weights.Segment { model: String, image: RasterRef, image_key: String, prompts: Vec<Prompt>, multimask: bool, out_dir: String }: Masks of the object the prompts point at.image_keynames the image’s content: the same key lets the plugin reuse what it computed for that image (SAM’s embedding).Instances { model: String, image: RasterRef, pixel_um: Option<f64>, out_dir: String }: Every object of an image as labels (nuclei, cells): au32raster,0background.pixel_umlets the model work at the scale it was trained for.Quit: Ends a server.
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
pub enum EventVariants
Progress { stage: String, fraction: Option<f32> }Done { result: Value }: The request’s answer (its JSON depends on the request).Error { message: String }
Methods
pub fn line(&self) -> StringOne line of the protocol.
Implements Clone, Debug, Deserialize, PartialEq, Serialize.
Functions
Section titled “Functions”plugin_dirs
Section titled “plugin_dirs”pub fn plugin_dirs() -> Vec<PathBuf>The folders searched, in order.
discover
Section titled “discover”pub fn discover() -> Vec<Result<PluginInfo, String>>Every plugin found and its manifest; a program that does not answer is reported as an error (its name and why), not left out silently.
Constants
Section titled “Constants”PROGRAM_PREFIX
Section titled “PROGRAM_PREFIX”pub const PROGRAM_PREFIX: &str = "lucem-ml-";Plugin programs start with this.
RUNTIME_ID
Section titled “RUNTIME_ID”pub const RUNTIME_ID: &str = "runtime";The id install takes (and Request::Install carries) for a plugin’s runtime itself rather
than a model: a plugin whose runtime is not ready installs it under this id.
RUNTIME_CUDA_ID
Section titled “RUNTIME_CUDA_ID”pub const RUNTIME_CUDA_ID: &str = "runtime-cuda";The id for a plugin’s GPU build of its runtime (see manifest::GpuRuntime).
lucem_ml::discover
Section titled “lucem_ml::discover”Finding the plugin programs: every executable named lucem-ml-* in, in order,
$LUCEM_PLUGINS (folders separated as in PATH), the user’s plugin folder
($XDG_DATA_HOME/lucem/plugins or ~/.local/share/lucem/plugins), the folder of the running
program (an installed app with its plugins beside it, or target/<profile> in development)
and PATH. The first program of each name wins; each is asked for its manifest
(<program> info).
programs
Section titled “programs”pub fn programs() -> BTreeMap<String, PathBuf>The plugin programs found, by name.