open_loops/sessions/mod.rs
1//! AI session sources. Each harness (Claude Code, and future ones like Codex,
2//! OpenCode) becomes an adapter of this trait — the rest of the code does not
3//! know the session format or location.
4use anyhow::Result;
5use chrono::{DateTime, Utc};
6use std::path::Path;
7
8pub mod claude_code;
9
10#[derive(Debug, Clone)]
11pub struct SessionExcerpt {
12 /// Session file name (shown in the Sources section).
13 pub source: String,
14 pub modified: DateTime<Utc>,
15 /// Extracted text (user/assistant messages), already truncated.
16 pub text: String,
17 /// Session mtime falls within the branch commit window (±7 days).
18 pub in_window: bool,
19 /// Session content mentions the branch name.
20 pub mentions_branch: bool,
21}
22
23pub trait SessionSource {
24 /// Excerpts of the sessions most relevant to the branch.
25 /// `window`: commit time range of the branch (sessions outside it that do
26 /// not mention the branch are discarded).
27 ///
28 /// # Errors
29 ///
30 /// Returns an error if the projects directory cannot be read.
31 fn excerpts(
32 &self,
33 repo_path: &Path,
34 branch: &str,
35 window: (DateTime<Utc>, DateTime<Utc>),
36 max_sessions: usize,
37 max_kb: u64,
38 ) -> Result<Vec<SessionExcerpt>>;
39}