byteor_runtime/
registry.rs

1use byteor_app_kit::capabilities::{
2    runtime_capability_document, stable_stage_catalog_entry, ExecutionTarget, PolicyClassId,
3    ReplaySupport, RuntimeCapabilityDocument, RuntimeEnvironment, StageCatalogEntry,
4};
5
6/// Default stage registry: resolves only `identity`.
7pub fn default_stage_registry() -> byteor_pipeline_exec::SliceStageRegistry {
8    byteor_pipeline_exec::SliceStageRegistry::new(DEFAULT_STAGES)
9}
10
11/// Default stage catalog entries exported alongside the base runtime registry.
12pub fn default_stage_catalog_entries() -> Vec<StageCatalogEntry> {
13    vec![stable_stage_catalog_entry(
14        "identity",
15        "Built-in identity stage",
16        vec![ExecutionTarget::SingleRing, ExecutionTarget::LaneGraph],
17        PolicyClassId::PureTransform,
18        ReplaySupport::Allowed,
19        vec![
20            RuntimeEnvironment::Dev,
21            RuntimeEnvironment::Staging,
22            RuntimeEnvironment::Prod,
23        ],
24        Vec::new(),
25    )]
26}
27
28/// Default capability document for the base runtime binary.
29pub fn default_runtime_capability_document(product: &str) -> RuntimeCapabilityDocument {
30    runtime_capability_document(product, default_stage_catalog_entries())
31}
32
33/// Minimal app hooks for wiring product binaries to the runtime.
34///
35/// Today the executor bring-up path is SingleRing `StageOpV1`-based, but this trait preserves the
36/// intended layering for the eventual stage-resolver based runners.
37pub trait RuntimeApp {
38    /// Extra per-run configuration parsed from app-specific flags.
39    type RunExt: Default;
40
41    /// Build the stage resolver used for execution.
42    fn build_stage_resolver(&self, _ext: &Self::RunExt) -> Box<dyn crate::stage::StageResolver>;
43}
44
45/// Default app hooks: only resolves `identity`.
46pub struct DefaultApp;
47
48impl RuntimeApp for DefaultApp {
49    type RunExt = ();
50
51    fn build_stage_resolver(&self, _ext: &Self::RunExt) -> Box<dyn crate::stage::StageResolver> {
52        Box::new(default_stage_registry())
53    }
54}
55
56fn identity(input: &[u8], output: &mut [u8]) -> usize {
57    let n = input.len().min(output.len());
58    output[..n].copy_from_slice(&input[..n]);
59    n
60}
61
62fn identity_factory() -> byteor_pipeline_exec::ResolvedStage {
63    byteor_pipeline_exec::ResolvedStage::MapOk(identity)
64}
65
66static DEFAULT_STAGES: &[byteor_pipeline_exec::StageEntry] = &[byteor_pipeline_exec::StageEntry {
67    name: "identity",
68    factory: identity_factory,
69}];