magi-code 0.96.1

Repository-aware CLI coding agent for terminal work
Documentation
use super::*;

fn prompt_cache_key_for_session_id(session_id: &str) -> String {
    crate::providers::conversation_id_for_session(session_id)
}

fn prompt_cache_key_for_subagent(provider_id: &str, model: &str, agent_id: &str) -> String {
    let material = format!("provider={provider_id}\nmodel={model}\nidentity={agent_id}");
    let digest = Sha256::digest(material.as_bytes());
    format!("magi-code-session-{}", lower_hex(digest))
        .chars()
        .take("magi-code-session-".len() + 32)
        .collect()
}

pub(super) fn prompt_cache_key_for_run(
    run: &AgentRunRequest<'_, '_>,
    provider_id: &str,
    model: &str,
) -> Option<String> {
    match run.invocation_mode {
        InvocationMode::Subagent => run
            .agent_id
            .as_deref()
            .map(|agent_id| prompt_cache_key_for_subagent(provider_id, model, agent_id))
            .or_else(|| {
                run.session
                    .map(|session| prompt_cache_key_for_session_id(session.id()))
            }),
        InvocationMode::Print
        | InvocationMode::MissionControl
        | InvocationMode::LocalAgent
        | InvocationMode::Side => run
            .session
            .map(|session| prompt_cache_key_for_session_id(session.id())),
    }
}