Skip to main content

cvkg_cli/
dev_runtime.rs

1//! Dev Runtime Controller
2//! Responsible for launching runtime, maintaining connection, and coordinating updates
3
4use serde::{Deserialize, Serialize};
5use std::sync::Arc;
6
7use crate::patch_engine::{CompiledArtifact, PatchEngine, RuntimePatch};
8
9/// Abstract runtime handle trait
10pub trait RuntimeHandle: Send + Sync {
11    /// Send a patch to the runtime
12    fn send_patch(&self, patch: RuntimePatch);
13    
14    /// Request current state from the runtime
15    fn request_state(&self) -> RuntimeStateSnapshot;
16    
17    /// Send an event to the runtime
18    fn send_event(&self, event: RuntimeEvent);
19}
20
21/// DevRuntimeController manages the connection to the runtime
22pub struct DevRuntimeController {
23    runtime: Arc<dyn RuntimeHandle>,
24    patch_engine: PatchEngine,
25}
26
27impl DevRuntimeController {
28    /// Create a new DevRuntimeController
29    pub fn new(runtime: Arc<dyn RuntimeHandle>) -> Self {
30        Self {
31            runtime,
32            patch_engine: PatchEngine::new(),
33        }
34    }
35    
36    /// Apply a code update by generating and sending a patch
37    pub fn apply_code_update(&mut self, compiled_artifact: CompiledArtifact) {
38        let patch = self.patch_engine.generate_patch(compiled_artifact);
39        self.runtime.send_patch(patch);
40    }
41    
42    /// Inject an agent stream into the runtime
43    pub fn inject_agent_stream(&self, stream: Vec<RuntimeEvent>) {
44        for event in stream {
45            self.runtime.send_event(event);
46        }
47    }
48}
49
50/// Runtime event types
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub enum RuntimeEvent {
53    Agent(AgentEvent),
54    // Add other event types as needed
55}
56
57/// Agent event types
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub enum AgentEvent {
60    Token(String),
61    ToolCall(String),
62    StateChange(String),
63    Error(String),
64}
65
66/// Runtime state snapshot
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct RuntimeStateSnapshot {
69    // In a full implementation, this would contain the serialized state graph
70    pub data: String,
71}
72
73impl RuntimeStateSnapshot {
74    pub fn new(data: String) -> Self {
75        Self { data }
76    }
77}