use anyhow::Result;
use rusqlite::Connection;
use crate::context::load_session_start_candidates;
use crate::retrieval_router::{plan, RetrievalPlan};
use super::domain::{ContextBundle, ContextIntent, ContextRequest};
use super::executor::{blocked_before_load, execute, ExecutorInputs};
pub fn compile_session_start_bundle(
conn: &Connection,
request: &ContextRequest,
cwd: &str,
current_branch: Option<&str>,
enrichment_available: bool,
) -> Result<ContextBundle> {
let compiled = plan(request, Some(ContextIntent::SessionStart))?;
Ok(bundle_for_plan(
conn,
&compiled,
&request.project.key,
cwd,
current_branch,
enrichment_available,
))
}
#[allow(clippy::too_many_arguments)]
fn bundle_for_plan(
conn: &Connection,
compiled: &RetrievalPlan,
project: &str,
cwd: &str,
current_branch: Option<&str>,
enrichment_available: bool,
) -> ContextBundle {
match load_session_start_candidates(conn, project, cwd, current_branch) {
Ok(candidates) => execute(
compiled,
&ExecutorInputs {
candidates,
enrichment_available,
},
),
Err(error) => blocked_before_load(compiled, &error.to_string()),
}
}