cvkg-core 0.1.4

Cyberpunk Viking Knowledge Graph (CVKG) - High-fidelity agentic UI framework
Documentation
use serde::{Serialize, Deserialize};

/// A patch instruction to apply to the running CVKG application.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RuntimePatch {
    /// Replaces an entire view subgraph.
    ReplaceView {
        /// ID of the node to replace.
        node_id: u64,
        /// The new serialized view state.
        new_view: serde_json::Value,
    },
    /// Updates a single state property of a node.
    UpdateState {
        /// ID of the node containing the state.
        node_id: u64,
        /// The field name.
        field: String,
        /// The new value.
        value: serde_json::Value,
    },
    /// A batch of sequential patches.
    Batch(Vec<RuntimePatch>),
}

/// A serialized snapshot of the runtime state graph.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(dead_code)]
pub struct RuntimeStateSnapshot {
    /// Serialized node states.
    pub nodes: Vec<NodeStateSnapshot>,
}

/// A snapshot for a specific node.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(dead_code)]
pub struct NodeStateSnapshot {
    /// Node identifier.
    pub id: u64,
    /// Key-value state properties.
    pub state: serde_json::Value,
}

/// Internal application event.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(dead_code)]
pub struct RuntimeEvent {
    /// E.g., "Agent", "Input"
    pub kind: String,
    /// Serialized event payload.
    pub payload: serde_json::Value,
}

/// Applies a `RuntimePatch` to the active application.
/// 
/// This integrates directly with the scheduler to execute safe mutations 
/// during the frame lifecycle.
pub fn apply_patch(patch: RuntimePatch) {
    match patch {
        RuntimePatch::ReplaceView { node_id: _, new_view: _ } => {
            // TODO: integrate with scene graph (Phase 5 placeholder)
            println!("Runtime: ReplaceView patch received.");
        }
        RuntimePatch::UpdateState { node_id: _, field: _, value: _ } => {
            // TODO: mutate state via scheduler
            println!("Runtime: UpdateState patch received.");
        }
        RuntimePatch::Batch(patches) => {
            for p in patches {
                apply_patch(p);
            }
        }
    }
}

/// Captures and returns the current state of the application.
pub fn snapshot_state() -> RuntimeStateSnapshot {
    // TODO: Actually serialize the state graph
    RuntimeStateSnapshot { nodes: Vec::new() }
}