Skip to main content

agx_core/
loader.rs

1//! Session-loading front door. Takes a path, detects the format, calls
2//! the right parser, returns `Vec<Step>`. Lives in its own module so both
3//! the single-session TUI/summary path (in `main.rs`) and the corpus
4//! subcommand (in `corpus.rs`) dispatch through the same function.
5
6use crate::format::{self, Format};
7use crate::timeline::Step;
8use crate::{
9    codex, gemini, generic, langchain, otel_json, otel_proto, session, timeline, vercel_ai,
10};
11use anyhow::Result;
12use std::path::Path;
13
14/// Detect the format of a session file and load it into a timeline of
15/// steps. This is the canonical entry point — every code path that
16/// consumes a single session should go through here so new formats only
17/// need to be registered in one place (here + [`Format`] + [`format::detect`]).
18pub fn load_session(path: &Path) -> Result<Vec<Step>> {
19    let fmt = format::detect(path)?;
20    let steps = match fmt {
21        Format::ClaudeCode => {
22            let entries = session::load(path)?;
23            timeline::build(&entries)
24        }
25        Format::Codex => codex::load(path)?,
26        Format::Gemini => gemini::load(path)?,
27        Format::Generic => generic::load(path)?,
28        Format::Langchain => langchain::load(path)?,
29        Format::OtelJson => otel_json::load(path)?,
30        Format::OtelProto => otel_proto::load(path)?,
31        Format::VercelAi => vercel_ai::load(path)?,
32    };
33    Ok(steps)
34}