frame-host 0.2.1

Frame host server and embedding seam — boots an application's frame-core component tree with an embedded liminal bus, announces the host's real application events on the bus, and serves the built frame page
Documentation
//! Declaration of the demo component this host registers and supervises.
//!
//! The component is `demo-graph`: the class-(b) client-native graph view
//! (`GraphCanvas`, rendered by `GraphMother` over WebGPU in the browser) under
//! the `frame:graph-view@v1` contract (D10 — two component classes, one
//! subscription contract). Its rendering substrate is client-local, so its
//! server side is one supervised presence process and no host-mediated
//! capability needs. Declarations never grant authority (F-1b); this manifest
//! declares, the host's facade alone grants.

use std::time::Duration;

use frame_core::component::{
    ChildArgument, ChildSpec, ComponentId, ComponentMeta, ServiceCapability, SupervisionPolicy,
};

/// Compiled BEAM bytecode for the presence child, committed beside its
/// source per the frame-core fixture convention (`component/graph_view_presence.erl`).
pub const PRESENCE_BYTECODE: &[u8] = include_bytes!("../component/graph_view_presence.beam");

/// Publisher namespace the demo component identity derives from.
pub const COMPONENT_PUBLISHER: &str = "frame.demo";

/// Wire-visible component instance name, matching the demo page's
/// `DEMO_COMPONENT_ID` (`examples/frame-demo/src/protocol.ts`).
pub const COMPONENT_NAME: &str = "demo-graph";

/// The subscription contract both component classes share (D10).
pub const CONTRACT_ID: &str = "frame:graph-view@v1";

/// Child key for the supervised server-side presence process.
pub const PRESENCE_CHILD: &str = "presence";

/// Mailbox integer the presence child answers liveness probes on.
pub const LIVENESS_MESSAGE: i64 = 0;

/// Mailbox integer requesting the presence child's orderly normal exit.
pub const STOP_MESSAGE: i64 = 2;

/// A news mailbox integer: any integer that is neither [`LIVENESS_MESSAGE`]
/// nor [`STOP_MESSAGE`] increments the child's observed counter (real
/// `erlang:'+'/2` arithmetic), so a fresh or restarted incarnation answers
/// liveness probes with 0 and each news message raises the answer by one.
pub const NEWS_MESSAGE: i64 = 7;

/// Restart intensity this component's author declares (registration refuses
/// manifests without one). A fresh incarnation answers probe value 0, so
/// restarts stay observable through the probe path.
const MAX_RESTARTS: usize = 3;

/// Rolling window the restart intensity is counted over.
const RESTART_WINDOW: Duration = Duration::from_secs(30);

/// Stable identity of the demo component.
#[must_use]
pub fn component_id() -> ComponentId {
    ComponentId::derive(COMPONENT_PUBLISHER, COMPONENT_NAME)
}

/// Full manifest for the demo component.
///
/// `needs` is empty by design: class-(b) rendering is client-native and the
/// presence process consumes no host-mediated authority, so the honest
/// declaration is none — the capability table simply holds zero grants for it.
#[must_use]
pub fn component_meta() -> ComponentMeta {
    ComponentMeta {
        id: component_id(),
        name: "GraphCanvas (GraphMother) — class-(b) client-native graph view".to_owned(),
        version: "0.1.0".to_owned(),
        requires: Vec::new(),
        provides: vec![ServiceCapability {
            id: CONTRACT_ID.to_owned(),
            description: "graph view fragments under the frame:graph-view@v1 \
                          subscription contract, rendered client-natively"
                .to_owned(),
        }],
        needs: Vec::new(),
        children: vec![ChildSpec {
            name: PRESENCE_CHILD.to_owned(),
            module: "graph_view_presence".to_owned(),
            function: "run".to_owned(),
            arguments: vec![ChildArgument::SupervisorPid],
            liveness_message: LIVENESS_MESSAGE,
            stop_message: STOP_MESSAGE,
        }],
        supervision: Some(SupervisionPolicy {
            max_restarts: MAX_RESTARTS,
            window: RESTART_WINDOW,
        }),
    }
}