pub use zagens_core::turn::{TurnContext, TurnToolCall};
use crate::snapshot::SnapshotRepo;
use std::path::Path;
pub fn pre_turn_snapshot(workspace: &Path, turn_seq: u64, max_workspace_gb: f64) -> Option<String> {
snapshot_with_label(workspace, &format!("pre-turn:{turn_seq}"), max_workspace_gb)
}
pub fn pre_tool_snapshot(workspace: &Path, call_id: &str, max_workspace_gb: f64) -> Option<String> {
snapshot_with_label(workspace, &format!("tool:{call_id}"), max_workspace_gb)
}
pub fn post_turn_snapshot(
workspace: &Path,
turn_seq: u64,
max_workspace_gb: f64,
) -> Option<String> {
snapshot_with_label(
workspace,
&format!("post-turn:{turn_seq}"),
max_workspace_gb,
)
}
fn snapshot_with_label(workspace: &Path, label: &str, max_workspace_gb: f64) -> Option<String> {
match SnapshotRepo::open_or_init_with_max_gb(workspace, max_workspace_gb) {
Ok(repo) => match repo.snapshot(label) {
Ok(id) => Some(id.0),
Err(e) => {
tracing::warn!(target: "snapshot", "snapshot '{label}' failed: {e}");
None
}
},
Err(e) => {
tracing::warn!(target: "snapshot", "snapshot repo init failed: {e}");
None
}
}
}