Skip to main content

cvkg_cli/
agent_replay.rs

1//! Agent Replay Module
2//! Load and replays agent traces for debugging
3
4use crate::dev_runtime::AgentEvent;
5
6/// Load an agent trace from a JSON file.
7///
8/// # Errors
9/// Returns an error if the file cannot be read or the JSON is invalid.
10pub fn load_agent_trace(path: &str) -> anyhow::Result<Vec<AgentEvent>> {
11    let data = std::fs::read_to_string(path)
12        .map_err(|e| anyhow::anyhow!("Failed to read agent trace file '{}': {}", path, e))?;
13    let events = serde_json::from_str(&data)
14        .map_err(|e| anyhow::anyhow!("Failed to parse agent trace JSON from '{}': {}", path, e))?;
15    Ok(events)
16}
17
18/// Replay an agent trace by sending events to the runtime.
19///
20/// # Arguments
21/// * `events` -- The agent events to replay.
22/// * `inject_event` -- Callback invoked for each event.
23pub fn replay_agent_trace<F>(events: Vec<AgentEvent>, mut inject_event: F)
24where
25    F: FnMut(AgentEvent),
26{
27    for event in events {
28        inject_event(event);
29    }
30}