Skip to main content

ralph/session/
progress.rs

1//! Session loop-progress mutation helpers.
2//!
3//! Responsibilities:
4//! - Increment persisted loop progress without exposing persistence details to callers.
5//!
6//! Not handled here:
7//! - Session validation.
8//! - Recovery prompting.
9//!
10//! Invariants/assumptions:
11//! - Missing session files are a no-op.
12//! - Progress updates reuse the same persistence path as session recovery.
13
14use std::path::Path;
15
16use anyhow::Result;
17
18use super::persistence::{load_session, save_session};
19
20/// Increment the session's tasks_completed_in_loop counter and persist.
21pub fn increment_session_progress(cache_dir: &Path) -> Result<()> {
22    let mut session = match load_session(cache_dir)? {
23        Some(session) => session,
24        None => {
25            log::debug!("No session to increment progress for");
26            return Ok(());
27        }
28    };
29
30    let now = crate::timeutil::now_utc_rfc3339_or_fallback();
31    session.mark_task_complete(now);
32    save_session(cache_dir, &session)
33}