Skip to main content

open_episodes

Function open_episodes 

Source
pub fn open_episodes(root: &Path) -> Vec<Episode>
Expand description

The open episodes of one checkout, as the store holds them.

Read from .ai/local/state/sessions-open/, which is a file per provider session rather than a singleton: an episode used to be one session-current.yaml per checkout, and a second provider session opening one was folded into the first. Measured in this repository on 2026-09-09: seven concurrent sessions, one record between them.

last_sign_of_life is the later of the episode’s started_at and the newest ledger line it stamped, which is what makes “nobody has been here for a day” a measurement rather than an inference from the open record’s own age.

use majordomus_cli::session::open_episodes;

let dir = tempfile::tempdir().unwrap();
let open = dir.path().join(".ai/local/state/sessions-open");
std::fs::create_dir_all(&open).unwrap();
std::fs::write(
    open.join("01Bv2gJsf.yaml"),
    "session_id: s-20260910205542-e2a6\nstarted_at: 2026-09-10T20:55:42Z\nowner: \"korczis\"\n\
     provider: \"claude-code\"\nprovider_session: \"01Bv2gJsf\"\nbranch: master\nstart_head: 9f3a2a0\n",
).unwrap();

let episodes = open_episodes(dir.path());
assert_eq!(episodes.len(), 1);
assert_eq!(episodes[0].id.as_str(), "s-20260910205542-e2a6");
assert!(episodes[0].task.is_none(), "an episode without a task is ordinary");
assert_eq!(episodes[0].provider_session.as_ref().map(|p| p.as_str()), Some("01Bv2gJsf"));
assert_eq!(episodes[0].last_sign_of_life, Some(1_789_073_742));